]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.5-201310162041.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.5-201310162041.patch
CommitLineData
c53997ee
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,19 +101,24 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 7f9d4f5..6d1afd6 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -1932,6 +1936,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 noexec=on: enable non-executable mappings (default)
248 noexec=off: disable non-executable mappings
249
250+ nopcid [X86-64]
251+ Disable PCID (Process-Context IDentifier) even if it
252+ is supported by the processor.
253+
254 nosmap [X86]
255 Disable SMAP (Supervisor Mode Access Prevention)
256 even if it is supported by processor.
257@@ -2199,6 +2207,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
258 the specified number of seconds. This is to be used if
259 your oopses keep scrolling off the screen.
260
261+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
262+ virtualization environments that don't cope well with the
263+ expand down segment used by UDEREF on X86-32 or the frequent
264+ page table updates on X86-64.
265+
266+ pax_sanitize_slab=
267+ 0/1 to disable/enable slab object sanitization (enabled by
268+ default).
269+
270+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
271+
272+ pax_extra_latent_entropy
273+ Enable a very simple form of latent entropy extraction
274+ from the first 4GB of memory as the bootmem allocator
275+ passes the memory pages to the buddy allocator.
276+
277+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
278+ when the processor supports PCID.
279+
280 pcbit= [HW,ISDN]
281
282 pcd. [PARIDE]
283diff --git a/Makefile b/Makefile
284index 83121b7..ce1a267 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELEASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1224,6 +1290,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1363,17 +1431,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1383,11 +1455,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 43594d5..da71e62 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1791,7 +1791,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index 04aeb02..73b70dd 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
2095index f1d96d4..73ddd72 100644
2096--- a/arch/arm/include/asm/syscall.h
2097+++ b/arch/arm/include/asm/syscall.h
2098@@ -57,6 +57,9 @@ static inline void syscall_get_arguments(struct task_struct *task,
2099 unsigned int i, unsigned int n,
2100 unsigned long *args)
2101 {
2102+ if (n == 0)
2103+ return;
2104+
2105 if (i + n > SYSCALL_MAX_ARGS) {
2106 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
2107 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
2108@@ -81,6 +84,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
2109 unsigned int i, unsigned int n,
2110 const unsigned long *args)
2111 {
2112+ if (n == 0)
2113+ return;
2114+
2115 if (i + n > SYSCALL_MAX_ARGS) {
2116 pr_warning("%s called with max args %d, handling only %d\n",
2117 __func__, i + n, SYSCALL_MAX_ARGS);
2118diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2119index 2b8114f..8fe9bcf 100644
2120--- a/arch/arm/include/asm/thread_info.h
2121+++ b/arch/arm/include/asm/thread_info.h
2122@@ -77,9 +77,9 @@ struct thread_info {
2123 .flags = 0, \
2124 .preempt_count = INIT_PREEMPT_COUNT, \
2125 .addr_limit = KERNEL_DS, \
2126- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2127- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2128- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2129+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2130+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2131+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2132 .restart_block = { \
2133 .fn = do_no_restart_syscall, \
2134 }, \
2135@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2136 #define TIF_SYSCALL_AUDIT 9
2137 #define TIF_SYSCALL_TRACEPOINT 10
2138 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2139-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2140+/* within 8 bits of TIF_SYSCALL_TRACE
2141+ * to meet flexible second operand requirements
2142+ */
2143+#define TIF_GRSEC_SETXID 12
2144+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2145 #define TIF_USING_IWMMXT 17
2146 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2147 #define TIF_RESTORE_SIGMASK 20
2148@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2149 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2150 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2151 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2152+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2153
2154 /* Checks for any syscall work in entry-common.S */
2155 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2156- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2157+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2158
2159 /*
2160 * Change these and you break ASM code in entry-common.S
2161diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2162index 7e1f760..de33b13 100644
2163--- a/arch/arm/include/asm/uaccess.h
2164+++ b/arch/arm/include/asm/uaccess.h
2165@@ -18,6 +18,7 @@
2166 #include <asm/domain.h>
2167 #include <asm/unified.h>
2168 #include <asm/compiler.h>
2169+#include <asm/pgtable.h>
2170
2171 #define VERIFY_READ 0
2172 #define VERIFY_WRITE 1
2173@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2174 static inline void set_fs(mm_segment_t fs)
2175 {
2176 current_thread_info()->addr_limit = fs;
2177- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2178+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2179 }
2180
2181 #define segment_eq(a,b) ((a) == (b))
2182
2183+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2184+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2185+
2186+static inline void pax_open_userland(void)
2187+{
2188+
2189+#ifdef CONFIG_PAX_MEMORY_UDEREF
2190+ if (segment_eq(get_fs(), USER_DS)) {
2191+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2192+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2193+ }
2194+#endif
2195+
2196+}
2197+
2198+static inline void pax_close_userland(void)
2199+{
2200+
2201+#ifdef CONFIG_PAX_MEMORY_UDEREF
2202+ if (segment_eq(get_fs(), USER_DS)) {
2203+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2204+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2205+ }
2206+#endif
2207+
2208+}
2209+
2210 #define __addr_ok(addr) ({ \
2211 unsigned long flag; \
2212 __asm__("cmp %2, %0; movlo %0, #0" \
2213@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2214
2215 #define get_user(x,p) \
2216 ({ \
2217+ int __e; \
2218 might_fault(); \
2219- __get_user_check(x,p); \
2220+ pax_open_userland(); \
2221+ __e = __get_user_check(x,p); \
2222+ pax_close_userland(); \
2223+ __e; \
2224 })
2225
2226 extern int __put_user_1(void *, unsigned int);
2227@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2228
2229 #define put_user(x,p) \
2230 ({ \
2231+ int __e; \
2232 might_fault(); \
2233- __put_user_check(x,p); \
2234+ pax_open_userland(); \
2235+ __e = __put_user_check(x,p); \
2236+ pax_close_userland(); \
2237+ __e; \
2238 })
2239
2240 #else /* CONFIG_MMU */
2241@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2242 #define __get_user(x,ptr) \
2243 ({ \
2244 long __gu_err = 0; \
2245+ pax_open_userland(); \
2246 __get_user_err((x),(ptr),__gu_err); \
2247+ pax_close_userland(); \
2248 __gu_err; \
2249 })
2250
2251 #define __get_user_error(x,ptr,err) \
2252 ({ \
2253+ pax_open_userland(); \
2254 __get_user_err((x),(ptr),err); \
2255+ pax_close_userland(); \
2256 (void) 0; \
2257 })
2258
2259@@ -312,13 +352,17 @@ do { \
2260 #define __put_user(x,ptr) \
2261 ({ \
2262 long __pu_err = 0; \
2263+ pax_open_userland(); \
2264 __put_user_err((x),(ptr),__pu_err); \
2265+ pax_close_userland(); \
2266 __pu_err; \
2267 })
2268
2269 #define __put_user_error(x,ptr,err) \
2270 ({ \
2271+ pax_open_userland(); \
2272 __put_user_err((x),(ptr),err); \
2273+ pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277@@ -418,11 +462,44 @@ do { \
2278
2279
2280 #ifdef CONFIG_MMU
2281-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2282-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2283+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2284+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2285+
2286+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2287+{
2288+ unsigned long ret;
2289+
2290+ check_object_size(to, n, false);
2291+ pax_open_userland();
2292+ ret = ___copy_from_user(to, from, n);
2293+ pax_close_userland();
2294+ return ret;
2295+}
2296+
2297+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2298+{
2299+ unsigned long ret;
2300+
2301+ check_object_size(from, n, true);
2302+ pax_open_userland();
2303+ ret = ___copy_to_user(to, from, n);
2304+ pax_close_userland();
2305+ return ret;
2306+}
2307+
2308 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2309-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2310+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2311 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2312+
2313+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2314+{
2315+ unsigned long ret;
2316+ pax_open_userland();
2317+ ret = ___clear_user(addr, n);
2318+ pax_close_userland();
2319+ return ret;
2320+}
2321+
2322 #else
2323 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2324 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2325@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2326
2327 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2328 {
2329+ if ((long)n < 0)
2330+ return n;
2331+
2332 if (access_ok(VERIFY_READ, from, n))
2333 n = __copy_from_user(to, from, n);
2334 else /* security hole - plug it */
2335@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2336
2337 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2338 {
2339+ if ((long)n < 0)
2340+ return n;
2341+
2342 if (access_ok(VERIFY_WRITE, to, n))
2343 n = __copy_to_user(to, from, n);
2344 return n;
2345diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2346index 5af0ed1..cea83883 100644
2347--- a/arch/arm/include/uapi/asm/ptrace.h
2348+++ b/arch/arm/include/uapi/asm/ptrace.h
2349@@ -92,7 +92,7 @@
2350 * ARMv7 groups of PSR bits
2351 */
2352 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2353-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2354+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2355 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2356 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2357
2358diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2359index 60d3b73..e5a0f22 100644
2360--- a/arch/arm/kernel/armksyms.c
2361+++ b/arch/arm/kernel/armksyms.c
2362@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2363
2364 /* networking */
2365 EXPORT_SYMBOL(csum_partial);
2366-EXPORT_SYMBOL(csum_partial_copy_from_user);
2367+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2368 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2369 EXPORT_SYMBOL(__csum_ipv6_magic);
2370
2371@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2372 #ifdef CONFIG_MMU
2373 EXPORT_SYMBOL(copy_page);
2374
2375-EXPORT_SYMBOL(__copy_from_user);
2376-EXPORT_SYMBOL(__copy_to_user);
2377-EXPORT_SYMBOL(__clear_user);
2378+EXPORT_SYMBOL(___copy_from_user);
2379+EXPORT_SYMBOL(___copy_to_user);
2380+EXPORT_SYMBOL(___clear_user);
2381
2382 EXPORT_SYMBOL(__get_user_1);
2383 EXPORT_SYMBOL(__get_user_2);
2384diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2385index 9cbe70c..a7b5e34 100644
2386--- a/arch/arm/kernel/entry-armv.S
2387+++ b/arch/arm/kernel/entry-armv.S
2388@@ -47,6 +47,87 @@
2389 9997:
2390 .endm
2391
2392+ .macro pax_enter_kernel
2393+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2394+ @ make aligned space for saved DACR
2395+ sub sp, sp, #8
2396+ @ save regs
2397+ stmdb sp!, {r1, r2}
2398+ @ read DACR from cpu_domain into r1
2399+ mov r2, sp
2400+ @ assume 8K pages, since we have to split the immediate in two
2401+ bic r2, r2, #(0x1fc0)
2402+ bic r2, r2, #(0x3f)
2403+ ldr r1, [r2, #TI_CPU_DOMAIN]
2404+ @ store old DACR on stack
2405+ str r1, [sp, #8]
2406+#ifdef CONFIG_PAX_KERNEXEC
2407+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2408+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2409+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2410+#endif
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+#endif
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r2, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r1, r2}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_open_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2439+ @ write r1 to current_thread_info()->cpu_domain
2440+ str r1, [r0, #TI_CPU_DOMAIN]
2441+ @ write r1 to DACR
2442+ mcr p15, 0, r1, c3, c0, 0
2443+ @ instruction sync
2444+ instr_sync
2445+ @ restore regs
2446+ ldmia sp!, {r0, r1}
2447+#endif
2448+ .endm
2449+
2450+ .macro pax_close_userland
2451+#ifdef CONFIG_PAX_MEMORY_UDEREF
2452+ @ save regs
2453+ stmdb sp!, {r0, r1}
2454+ @ read DACR from cpu_domain into r1
2455+ mov r0, sp
2456+ @ assume 8K pages, since we have to split the immediate in two
2457+ bic r0, r0, #(0x1fc0)
2458+ bic r0, r0, #(0x3f)
2459+ ldr r1, [r0, #TI_CPU_DOMAIN]
2460+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2461+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2462+ @ write r1 to current_thread_info()->cpu_domain
2463+ str r1, [r0, #TI_CPU_DOMAIN]
2464+ @ write r1 to DACR
2465+ mcr p15, 0, r1, c3, c0, 0
2466+ @ instruction sync
2467+ instr_sync
2468+ @ restore regs
2469+ ldmia sp!, {r0, r1}
2470+#endif
2471+ .endm
2472+
2473 .macro pabt_helper
2474 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2475 #ifdef MULTI_PABORT
2476@@ -89,11 +170,15 @@
2477 * Invalid mode handlers
2478 */
2479 .macro inv_entry, reason
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #S_FRAME_SIZE
2484 ARM( stmib sp, {r1 - lr} )
2485 THUMB( stmia sp, {r0 - r12} )
2486 THUMB( str sp, [sp, #S_SP] )
2487 THUMB( str lr, [sp, #S_LR] )
2488+
2489 mov r1, #\reason
2490 .endm
2491
2492@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2493 .macro svc_entry, stack_hole=0
2494 UNWIND(.fnstart )
2495 UNWIND(.save {r0 - pc} )
2496+
2497+ pax_enter_kernel
2498+
2499 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2500+
2501 #ifdef CONFIG_THUMB2_KERNEL
2502 SPFIX( str r0, [sp] ) @ temporarily saved
2503 SPFIX( mov r0, sp )
2504@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2505 ldmia r0, {r3 - r5}
2506 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2507 mov r6, #-1 @ "" "" "" ""
2508+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2509+ @ offset sp by 8 as done in pax_enter_kernel
2510+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2511+#else
2512 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2513+#endif
2514 SPFIX( addeq r2, r2, #4 )
2515 str r3, [sp, #-4]! @ save the "real" r0 copied
2516 @ from the exception stack
2517@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2518 .macro usr_entry
2519 UNWIND(.fnstart )
2520 UNWIND(.cantunwind ) @ don't unwind the user space
2521+
2522+ pax_enter_kernel_user
2523+
2524 sub sp, sp, #S_FRAME_SIZE
2525 ARM( stmib sp, {r1 - r12} )
2526 THUMB( stmia sp, {r0 - r12} )
2527@@ -415,7 +512,9 @@ __und_usr:
2528 tst r3, #PSR_T_BIT @ Thumb mode?
2529 bne __und_usr_thumb
2530 sub r4, r2, #4 @ ARM instr at LR - 4
2531+ pax_open_userland
2532 1: ldrt r0, [r4]
2533+ pax_close_userland
2534 #ifdef CONFIG_CPU_ENDIAN_BE8
2535 rev r0, r0 @ little endian instruction
2536 #endif
2537@@ -450,10 +549,14 @@ __und_usr_thumb:
2538 */
2539 .arch armv6t2
2540 #endif
2541+ pax_open_userland
2542 2: ldrht r5, [r4]
2543+ pax_close_userland
2544 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2545 blo __und_usr_fault_16 @ 16bit undefined instruction
2546+ pax_open_userland
2547 3: ldrht r0, [r2]
2548+ pax_close_userland
2549 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2550 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2551 orr r0, r0, r5, lsl #16
2552@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2553 */
2554 .pushsection .fixup, "ax"
2555 .align 2
2556-4: mov pc, r9
2557+4: pax_close_userland
2558+ mov pc, r9
2559 .popsection
2560 .pushsection __ex_table,"a"
2561 .long 1b, 4b
2562@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2563 THUMB( str lr, [ip], #4 )
2564 ldr r4, [r2, #TI_TP_VALUE]
2565 ldr r5, [r2, #TI_TP_VALUE + 4]
2566-#ifdef CONFIG_CPU_USE_DOMAINS
2567+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2568 ldr r6, [r2, #TI_CPU_DOMAIN]
2569 #endif
2570 switch_tls r1, r4, r5, r3, r7
2571@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2572 ldr r8, =__stack_chk_guard
2573 ldr r7, [r7, #TSK_STACK_CANARY]
2574 #endif
2575-#ifdef CONFIG_CPU_USE_DOMAINS
2576+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2577 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2578 #endif
2579 mov r5, r0
2580diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2581index 94104bf..e425391 100644
2582--- a/arch/arm/kernel/entry-common.S
2583+++ b/arch/arm/kernel/entry-common.S
2584@@ -10,18 +10,46 @@
2585
2586 #include <asm/unistd.h>
2587 #include <asm/ftrace.h>
2588+#include <asm/domain.h>
2589 #include <asm/unwind.h>
2590
2591+#include "entry-header.S"
2592+
2593 #ifdef CONFIG_NEED_RET_TO_USER
2594 #include <mach/entry-macro.S>
2595 #else
2596 .macro arch_ret_to_user, tmp1, tmp2
2597+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2598+ @ save regs
2599+ stmdb sp!, {r1, r2}
2600+ @ read DACR from cpu_domain into r1
2601+ mov r2, sp
2602+ @ assume 8K pages, since we have to split the immediate in two
2603+ bic r2, r2, #(0x1fc0)
2604+ bic r2, r2, #(0x3f)
2605+ ldr r1, [r2, #TI_CPU_DOMAIN]
2606+#ifdef CONFIG_PAX_KERNEXEC
2607+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2608+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2609+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2610+#endif
2611+#ifdef CONFIG_PAX_MEMORY_UDEREF
2612+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2613+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2614+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2615+#endif
2616+ @ write r1 to current_thread_info()->cpu_domain
2617+ str r1, [r2, #TI_CPU_DOMAIN]
2618+ @ write r1 to DACR
2619+ mcr p15, 0, r1, c3, c0, 0
2620+ @ instruction sync
2621+ instr_sync
2622+ @ restore regs
2623+ ldmia sp!, {r1, r2}
2624+#endif
2625 .endm
2626 #endif
2627
2628-#include "entry-header.S"
2629-
2630-
2631 .align 5
2632 /*
2633 * This is the fast syscall return path. We do as little as
2634@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2635 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2636 #endif
2637
2638+ /*
2639+ * do this here to avoid a performance hit of wrapping the code above
2640+ * that directly dereferences userland to parse the SWI instruction
2641+ */
2642+ pax_enter_kernel_user
2643+
2644 adr tbl, sys_call_table @ load syscall table pointer
2645
2646 #if defined(CONFIG_OABI_COMPAT)
2647diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2648index de23a9b..94c37c4 100644
2649--- a/arch/arm/kernel/entry-header.S
2650+++ b/arch/arm/kernel/entry-header.S
2651@@ -184,6 +184,60 @@
2652 msr cpsr_c, \rtemp @ switch back to the SVC mode
2653 .endm
2654
2655+ .macro pax_enter_kernel_user
2656+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2657+ @ save regs
2658+ stmdb sp!, {r0, r1}
2659+ @ read DACR from cpu_domain into r1
2660+ mov r0, sp
2661+ @ assume 8K pages, since we have to split the immediate in two
2662+ bic r0, r0, #(0x1fc0)
2663+ bic r0, r0, #(0x3f)
2664+ ldr r1, [r0, #TI_CPU_DOMAIN]
2665+#ifdef CONFIG_PAX_MEMORY_UDEREF
2666+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2667+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2668+#endif
2669+#ifdef CONFIG_PAX_KERNEXEC
2670+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2671+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2672+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2673+#endif
2674+ @ write r1 to current_thread_info()->cpu_domain
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685+ .macro pax_exit_kernel
2686+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2687+ @ save regs
2688+ stmdb sp!, {r0, r1}
2689+ @ read old DACR from stack into r1
2690+ ldr r1, [sp, #(8 + S_SP)]
2691+ sub r1, r1, #8
2692+ ldr r1, [r1]
2693+
2694+ @ write r1 to current_thread_info()->cpu_domain
2695+ mov r0, sp
2696+ @ assume 8K pages, since we have to split the immediate in two
2697+ bic r0, r0, #(0x1fc0)
2698+ bic r0, r0, #(0x3f)
2699+ str r1, [r0, #TI_CPU_DOMAIN]
2700+ @ write r1 to DACR
2701+ mcr p15, 0, r1, c3, c0, 0
2702+ @ instruction sync
2703+ instr_sync
2704+ @ restore regs
2705+ ldmia sp!, {r0, r1}
2706+#endif
2707+ .endm
2708+
2709 #ifndef CONFIG_THUMB2_KERNEL
2710 .macro svc_exit, rpsr, irq = 0
2711 .if \irq != 0
2712@@ -203,6 +257,9 @@
2713 blne trace_hardirqs_off
2714 #endif
2715 .endif
2716+
2717+ pax_exit_kernel
2718+
2719 msr spsr_cxsf, \rpsr
2720 #if defined(CONFIG_CPU_V6)
2721 ldr r0, [sp]
2722@@ -266,6 +323,9 @@
2723 blne trace_hardirqs_off
2724 #endif
2725 .endif
2726+
2727+ pax_exit_kernel
2728+
2729 ldr lr, [sp, #S_SP] @ top of the stack
2730 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2731 clrex @ clear the exclusive monitor
2732diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2733index 918875d..cd5fa27 100644
2734--- a/arch/arm/kernel/fiq.c
2735+++ b/arch/arm/kernel/fiq.c
2736@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2737 void *base = vectors_page;
2738 unsigned offset = FIQ_OFFSET;
2739
2740+ pax_open_kernel();
2741 memcpy(base + offset, start, length);
2742+ pax_close_kernel();
2743+
2744 if (!cache_is_vipt_nonaliasing())
2745 flush_icache_range((unsigned long)base + offset, offset +
2746 length);
2747diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2748index 2c7cc1e..ab2e911 100644
2749--- a/arch/arm/kernel/head.S
2750+++ b/arch/arm/kernel/head.S
2751@@ -52,7 +52,9 @@
2752 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2753
2754 .macro pgtbl, rd, phys
2755- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2756+ mov \rd, #TEXT_OFFSET
2757+ sub \rd, #PG_DIR_SIZE
2758+ add \rd, \rd, \phys
2759 .endm
2760
2761 /*
2762@@ -432,7 +434,7 @@ __enable_mmu:
2763 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2764 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2765 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2766- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2767+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2768 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2769 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2770 #endif
2771diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2772index 85c3fb6..054c2dc 100644
2773--- a/arch/arm/kernel/module.c
2774+++ b/arch/arm/kernel/module.c
2775@@ -37,12 +37,39 @@
2776 #endif
2777
2778 #ifdef CONFIG_MMU
2779-void *module_alloc(unsigned long size)
2780+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2781 {
2782+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2783+ return NULL;
2784 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2785- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2786+ GFP_KERNEL, prot, -1,
2787 __builtin_return_address(0));
2788 }
2789+
2790+void *module_alloc(unsigned long size)
2791+{
2792+
2793+#ifdef CONFIG_PAX_KERNEXEC
2794+ return __module_alloc(size, PAGE_KERNEL);
2795+#else
2796+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2797+#endif
2798+
2799+}
2800+
2801+#ifdef CONFIG_PAX_KERNEXEC
2802+void module_free_exec(struct module *mod, void *module_region)
2803+{
2804+ module_free(mod, module_region);
2805+}
2806+EXPORT_SYMBOL(module_free_exec);
2807+
2808+void *module_alloc_exec(unsigned long size)
2809+{
2810+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2811+}
2812+EXPORT_SYMBOL(module_alloc_exec);
2813+#endif
2814 #endif
2815
2816 int
2817diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2818index 07314af..c46655c 100644
2819--- a/arch/arm/kernel/patch.c
2820+++ b/arch/arm/kernel/patch.c
2821@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2822 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2823 int size;
2824
2825+ pax_open_kernel();
2826 if (thumb2 && __opcode_is_thumb16(insn)) {
2827 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2828 size = sizeof(u16);
2829@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2830 *(u32 *)addr = insn;
2831 size = sizeof(u32);
2832 }
2833+ pax_close_kernel();
2834
2835 flush_icache_range((uintptr_t)(addr),
2836 (uintptr_t)(addr) + size);
2837diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2838index 94f6b05..efd7312 100644
2839--- a/arch/arm/kernel/process.c
2840+++ b/arch/arm/kernel/process.c
2841@@ -217,6 +217,7 @@ void machine_power_off(void)
2842
2843 if (pm_power_off)
2844 pm_power_off();
2845+ BUG();
2846 }
2847
2848 /*
2849@@ -230,7 +231,7 @@ void machine_power_off(void)
2850 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2851 * to use. Implementing such co-ordination would be essentially impossible.
2852 */
2853-void machine_restart(char *cmd)
2854+__noreturn void machine_restart(char *cmd)
2855 {
2856 local_irq_disable();
2857 smp_send_stop();
2858@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2859
2860 show_regs_print_info(KERN_DEFAULT);
2861
2862- print_symbol("PC is at %s\n", instruction_pointer(regs));
2863- print_symbol("LR is at %s\n", regs->ARM_lr);
2864+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2865+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2866 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2867 "sp : %08lx ip : %08lx fp : %08lx\n",
2868 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2869@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2870 return 0;
2871 }
2872
2873-unsigned long arch_randomize_brk(struct mm_struct *mm)
2874-{
2875- unsigned long range_end = mm->brk + 0x02000000;
2876- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2877-}
2878-
2879 #ifdef CONFIG_MMU
2880 #ifdef CONFIG_KUSER_HELPERS
2881 /*
2882@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2883
2884 static int __init gate_vma_init(void)
2885 {
2886- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2887+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2888 return 0;
2889 }
2890 arch_initcall(gate_vma_init);
2891@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2892
2893 const char *arch_vma_name(struct vm_area_struct *vma)
2894 {
2895- return is_gate_vma(vma) ? "[vectors]" :
2896- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2897- "[sigpage]" : NULL;
2898+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2899 }
2900
2901-static struct page *signal_page;
2902-extern struct page *get_signal_page(void);
2903-
2904 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2905 {
2906 struct mm_struct *mm = current->mm;
2907- unsigned long addr;
2908- int ret;
2909-
2910- if (!signal_page)
2911- signal_page = get_signal_page();
2912- if (!signal_page)
2913- return -ENOMEM;
2914
2915 down_write(&mm->mmap_sem);
2916- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2917- if (IS_ERR_VALUE(addr)) {
2918- ret = addr;
2919- goto up_fail;
2920- }
2921-
2922- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2923- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2924- &signal_page);
2925-
2926- if (ret == 0)
2927- mm->context.sigpage = addr;
2928-
2929- up_fail:
2930+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2931 up_write(&mm->mmap_sem);
2932- return ret;
2933+ return 0;
2934 }
2935 #endif
2936diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2937index 4693188..4596c5e 100644
2938--- a/arch/arm/kernel/psci.c
2939+++ b/arch/arm/kernel/psci.c
2940@@ -24,7 +24,7 @@
2941 #include <asm/opcodes-virt.h>
2942 #include <asm/psci.h>
2943
2944-struct psci_operations psci_ops;
2945+struct psci_operations psci_ops __read_only;
2946
2947 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2948
2949diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2950index 0dd3b79..e018f64 100644
2951--- a/arch/arm/kernel/ptrace.c
2952+++ b/arch/arm/kernel/ptrace.c
2953@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2954 return current_thread_info()->syscall;
2955 }
2956
2957+#ifdef CONFIG_GRKERNSEC_SETXID
2958+extern void gr_delayed_cred_worker(void);
2959+#endif
2960+
2961 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2962 {
2963 current_thread_info()->syscall = scno;
2964
2965+#ifdef CONFIG_GRKERNSEC_SETXID
2966+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2967+ gr_delayed_cred_worker();
2968+#endif
2969+
2970 /* Do the secure computing check first; failures should be fast. */
2971 if (secure_computing(scno) == -1)
2972 return -1;
2973diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2974index afc2489..6372bc8 100644
2975--- a/arch/arm/kernel/setup.c
2976+++ b/arch/arm/kernel/setup.c
2977@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2978 unsigned int elf_hwcap __read_mostly;
2979 EXPORT_SYMBOL(elf_hwcap);
2980
2981+pteval_t __supported_pte_mask __read_only;
2982+pmdval_t __supported_pmd_mask __read_only;
2983
2984 #ifdef MULTI_CPU
2985-struct processor processor __read_mostly;
2986+struct processor processor;
2987 #endif
2988 #ifdef MULTI_TLB
2989-struct cpu_tlb_fns cpu_tlb __read_mostly;
2990+struct cpu_tlb_fns cpu_tlb __read_only;
2991 #endif
2992 #ifdef MULTI_USER
2993-struct cpu_user_fns cpu_user __read_mostly;
2994+struct cpu_user_fns cpu_user __read_only;
2995 #endif
2996 #ifdef MULTI_CACHE
2997-struct cpu_cache_fns cpu_cache __read_mostly;
2998+struct cpu_cache_fns cpu_cache __read_only;
2999 #endif
3000 #ifdef CONFIG_OUTER_CACHE
3001-struct outer_cache_fns outer_cache __read_mostly;
3002+struct outer_cache_fns outer_cache __read_only;
3003 EXPORT_SYMBOL(outer_cache);
3004 #endif
3005
3006@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
3007 asm("mrc p15, 0, %0, c0, c1, 4"
3008 : "=r" (mmfr0));
3009 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3010- (mmfr0 & 0x000000f0) >= 0x00000030)
3011+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3012 cpu_arch = CPU_ARCH_ARMv7;
3013- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3014+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3015+ __supported_pte_mask |= L_PTE_PXN;
3016+ __supported_pmd_mask |= PMD_PXNTABLE;
3017+ }
3018+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3019 (mmfr0 & 0x000000f0) == 0x00000020)
3020 cpu_arch = CPU_ARCH_ARMv6;
3021 else
3022@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3023 __cpu_architecture = __get_cpu_architecture();
3024
3025 #ifdef MULTI_CPU
3026- processor = *list->proc;
3027+ memcpy((void *)&processor, list->proc, sizeof processor);
3028 #endif
3029 #ifdef MULTI_TLB
3030 cpu_tlb = *list->tlb;
3031diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3032index ab33042..11248a8 100644
3033--- a/arch/arm/kernel/signal.c
3034+++ b/arch/arm/kernel/signal.c
3035@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3036 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3037 };
3038
3039-static unsigned long signal_return_offset;
3040-
3041 #ifdef CONFIG_CRUNCH
3042 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3043 {
3044@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3045 * except when the MPU has protected the vectors
3046 * page from PL0
3047 */
3048- retcode = mm->context.sigpage + signal_return_offset +
3049- (idx << 2) + thumb;
3050+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3051 } else
3052 #endif
3053 {
3054@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3055 } while (thread_flags & _TIF_WORK_MASK);
3056 return 0;
3057 }
3058-
3059-struct page *get_signal_page(void)
3060-{
3061- unsigned long ptr;
3062- unsigned offset;
3063- struct page *page;
3064- void *addr;
3065-
3066- page = alloc_pages(GFP_KERNEL, 0);
3067-
3068- if (!page)
3069- return NULL;
3070-
3071- addr = page_address(page);
3072-
3073- /* Give the signal return code some randomness */
3074- offset = 0x200 + (get_random_int() & 0x7fc);
3075- signal_return_offset = offset;
3076-
3077- /*
3078- * Copy signal return handlers into the vector page, and
3079- * set sigreturn to be a pointer to these.
3080- */
3081- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3082-
3083- ptr = (unsigned long)addr + offset;
3084- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3085-
3086- return page;
3087-}
3088diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3089index 2dc1934..ecf0e21 100644
3090--- a/arch/arm/kernel/smp.c
3091+++ b/arch/arm/kernel/smp.c
3092@@ -71,7 +71,7 @@ enum ipi_msg_type {
3093
3094 static DECLARE_COMPLETION(cpu_running);
3095
3096-static struct smp_operations smp_ops;
3097+static struct smp_operations smp_ops __read_only;
3098
3099 void __init smp_set_ops(struct smp_operations *ops)
3100 {
3101diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3102index ab517fc..9adf2fa 100644
3103--- a/arch/arm/kernel/traps.c
3104+++ b/arch/arm/kernel/traps.c
3105@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3106 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3107 {
3108 #ifdef CONFIG_KALLSYMS
3109- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3110+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3111 #else
3112 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3113 #endif
3114@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3115 static int die_owner = -1;
3116 static unsigned int die_nest_count;
3117
3118+extern void gr_handle_kernel_exploit(void);
3119+
3120 static unsigned long oops_begin(void)
3121 {
3122 int cpu;
3123@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3124 panic("Fatal exception in interrupt");
3125 if (panic_on_oops)
3126 panic("Fatal exception");
3127+
3128+ gr_handle_kernel_exploit();
3129+
3130 if (signr)
3131 do_exit(signr);
3132 }
3133@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3134 * The user helper at 0xffff0fe0 must be used instead.
3135 * (see entry-armv.S for details)
3136 */
3137+ pax_open_kernel();
3138 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3139+ pax_close_kernel();
3140 }
3141 return 0;
3142
3143@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3144 kuser_init(vectors_base);
3145
3146 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3147- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3148+
3149+#ifndef CONFIG_PAX_MEMORY_UDEREF
3150+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3151+#endif
3152+
3153 #else /* ifndef CONFIG_CPU_V7M */
3154 /*
3155 * on V7-M there is no need to copy the vector table to a dedicated
3156diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3157index 7bcee5c..e2f3249 100644
3158--- a/arch/arm/kernel/vmlinux.lds.S
3159+++ b/arch/arm/kernel/vmlinux.lds.S
3160@@ -8,7 +8,11 @@
3161 #include <asm/thread_info.h>
3162 #include <asm/memory.h>
3163 #include <asm/page.h>
3164-
3165+
3166+#ifdef CONFIG_PAX_KERNEXEC
3167+#include <asm/pgtable.h>
3168+#endif
3169+
3170 #define PROC_INFO \
3171 . = ALIGN(4); \
3172 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3173@@ -34,7 +38,7 @@
3174 #endif
3175
3176 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3177- defined(CONFIG_GENERIC_BUG)
3178+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3179 #define ARM_EXIT_KEEP(x) x
3180 #define ARM_EXIT_DISCARD(x)
3181 #else
3182@@ -90,6 +94,11 @@ SECTIONS
3183 _text = .;
3184 HEAD_TEXT
3185 }
3186+
3187+#ifdef CONFIG_PAX_KERNEXEC
3188+ . = ALIGN(1<<SECTION_SHIFT);
3189+#endif
3190+
3191 .text : { /* Real text segment */
3192 _stext = .; /* Text and read-only data */
3193 __exception_text_start = .;
3194@@ -112,6 +121,8 @@ SECTIONS
3195 ARM_CPU_KEEP(PROC_INFO)
3196 }
3197
3198+ _etext = .; /* End of text section */
3199+
3200 RO_DATA(PAGE_SIZE)
3201
3202 . = ALIGN(4);
3203@@ -142,7 +153,9 @@ SECTIONS
3204
3205 NOTES
3206
3207- _etext = .; /* End of text and rodata section */
3208+#ifdef CONFIG_PAX_KERNEXEC
3209+ . = ALIGN(1<<SECTION_SHIFT);
3210+#endif
3211
3212 #ifndef CONFIG_XIP_KERNEL
3213 . = ALIGN(PAGE_SIZE);
3214@@ -220,6 +233,11 @@ SECTIONS
3215 . = PAGE_OFFSET + TEXT_OFFSET;
3216 #else
3217 __init_end = .;
3218+
3219+#ifdef CONFIG_PAX_KERNEXEC
3220+ . = ALIGN(1<<SECTION_SHIFT);
3221+#endif
3222+
3223 . = ALIGN(THREAD_SIZE);
3224 __data_loc = .;
3225 #endif
3226diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3227index 741f66a..8a5615c 100644
3228--- a/arch/arm/kvm/arm.c
3229+++ b/arch/arm/kvm/arm.c
3230@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3231 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3232
3233 /* The VMID used in the VTTBR */
3234-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3235+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3236 static u8 kvm_next_vmid;
3237 static DEFINE_SPINLOCK(kvm_vmid_lock);
3238
3239@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3240 */
3241 static bool need_new_vmid_gen(struct kvm *kvm)
3242 {
3243- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3244+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3245 }
3246
3247 /**
3248@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3249
3250 /* First user of a new VMID generation? */
3251 if (unlikely(kvm_next_vmid == 0)) {
3252- atomic64_inc(&kvm_vmid_gen);
3253+ atomic64_inc_unchecked(&kvm_vmid_gen);
3254 kvm_next_vmid = 1;
3255
3256 /*
3257@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3258 kvm_call_hyp(__kvm_flush_vm_context);
3259 }
3260
3261- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3262+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3263 kvm->arch.vmid = kvm_next_vmid;
3264 kvm_next_vmid++;
3265
3266diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3267index 14a0d98..7771a7d 100644
3268--- a/arch/arm/lib/clear_user.S
3269+++ b/arch/arm/lib/clear_user.S
3270@@ -12,14 +12,14 @@
3271
3272 .text
3273
3274-/* Prototype: int __clear_user(void *addr, size_t sz)
3275+/* Prototype: int ___clear_user(void *addr, size_t sz)
3276 * Purpose : clear some user memory
3277 * Params : addr - user memory address to clear
3278 * : sz - number of bytes to clear
3279 * Returns : number of bytes NOT cleared
3280 */
3281 ENTRY(__clear_user_std)
3282-WEAK(__clear_user)
3283+WEAK(___clear_user)
3284 stmfd sp!, {r1, lr}
3285 mov r2, #0
3286 cmp r1, #4
3287@@ -44,7 +44,7 @@ WEAK(__clear_user)
3288 USER( strnebt r2, [r0])
3289 mov r0, #0
3290 ldmfd sp!, {r1, pc}
3291-ENDPROC(__clear_user)
3292+ENDPROC(___clear_user)
3293 ENDPROC(__clear_user_std)
3294
3295 .pushsection .fixup,"ax"
3296diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3297index 66a477a..bee61d3 100644
3298--- a/arch/arm/lib/copy_from_user.S
3299+++ b/arch/arm/lib/copy_from_user.S
3300@@ -16,7 +16,7 @@
3301 /*
3302 * Prototype:
3303 *
3304- * size_t __copy_from_user(void *to, const void *from, size_t n)
3305+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3306 *
3307 * Purpose:
3308 *
3309@@ -84,11 +84,11 @@
3310
3311 .text
3312
3313-ENTRY(__copy_from_user)
3314+ENTRY(___copy_from_user)
3315
3316 #include "copy_template.S"
3317
3318-ENDPROC(__copy_from_user)
3319+ENDPROC(___copy_from_user)
3320
3321 .pushsection .fixup,"ax"
3322 .align 0
3323diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3324index 6ee2f67..d1cce76 100644
3325--- a/arch/arm/lib/copy_page.S
3326+++ b/arch/arm/lib/copy_page.S
3327@@ -10,6 +10,7 @@
3328 * ASM optimised string functions
3329 */
3330 #include <linux/linkage.h>
3331+#include <linux/const.h>
3332 #include <asm/assembler.h>
3333 #include <asm/asm-offsets.h>
3334 #include <asm/cache.h>
3335diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3336index d066df6..df28194 100644
3337--- a/arch/arm/lib/copy_to_user.S
3338+++ b/arch/arm/lib/copy_to_user.S
3339@@ -16,7 +16,7 @@
3340 /*
3341 * Prototype:
3342 *
3343- * size_t __copy_to_user(void *to, const void *from, size_t n)
3344+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3345 *
3346 * Purpose:
3347 *
3348@@ -88,11 +88,11 @@
3349 .text
3350
3351 ENTRY(__copy_to_user_std)
3352-WEAK(__copy_to_user)
3353+WEAK(___copy_to_user)
3354
3355 #include "copy_template.S"
3356
3357-ENDPROC(__copy_to_user)
3358+ENDPROC(___copy_to_user)
3359 ENDPROC(__copy_to_user_std)
3360
3361 .pushsection .fixup,"ax"
3362diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3363index 7d08b43..f7ca7ea 100644
3364--- a/arch/arm/lib/csumpartialcopyuser.S
3365+++ b/arch/arm/lib/csumpartialcopyuser.S
3366@@ -57,8 +57,8 @@
3367 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3368 */
3369
3370-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3371-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3372+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3373+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3374
3375 #include "csumpartialcopygeneric.S"
3376
3377diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3378index 5306de3..aed6d03 100644
3379--- a/arch/arm/lib/delay.c
3380+++ b/arch/arm/lib/delay.c
3381@@ -28,7 +28,7 @@
3382 /*
3383 * Default to the loop-based delay implementation.
3384 */
3385-struct arm_delay_ops arm_delay_ops = {
3386+struct arm_delay_ops arm_delay_ops __read_only = {
3387 .delay = __loop_delay,
3388 .const_udelay = __loop_const_udelay,
3389 .udelay = __loop_udelay,
3390diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3391index 025f742..a9e5b3b 100644
3392--- a/arch/arm/lib/uaccess_with_memcpy.c
3393+++ b/arch/arm/lib/uaccess_with_memcpy.c
3394@@ -104,7 +104,7 @@ out:
3395 }
3396
3397 unsigned long
3398-__copy_to_user(void __user *to, const void *from, unsigned long n)
3399+___copy_to_user(void __user *to, const void *from, unsigned long n)
3400 {
3401 /*
3402 * This test is stubbed out of the main function above to keep
3403@@ -155,7 +155,7 @@ out:
3404 return n;
3405 }
3406
3407-unsigned long __clear_user(void __user *addr, unsigned long n)
3408+unsigned long ___clear_user(void __user *addr, unsigned long n)
3409 {
3410 /* See rational for this in __copy_to_user() above. */
3411 if (n < 64)
3412diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3413index e9238b5..6ed904a 100644
3414--- a/arch/arm/mach-kirkwood/common.c
3415+++ b/arch/arm/mach-kirkwood/common.c
3416@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3417 clk_gate_ops.disable(hw);
3418 }
3419
3420-static struct clk_ops clk_gate_fn_ops;
3421+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3422+{
3423+ return clk_gate_ops.is_enabled(hw);
3424+}
3425+
3426+static struct clk_ops clk_gate_fn_ops = {
3427+ .enable = clk_gate_fn_enable,
3428+ .disable = clk_gate_fn_disable,
3429+ .is_enabled = clk_gate_fn_is_enabled,
3430+};
3431
3432 static struct clk __init *clk_register_gate_fn(struct device *dev,
3433 const char *name,
3434@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3435 gate_fn->fn_en = fn_en;
3436 gate_fn->fn_dis = fn_dis;
3437
3438- /* ops is the gate ops, but with our enable/disable functions */
3439- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3440- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3441- clk_gate_fn_ops = clk_gate_ops;
3442- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3443- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3444- }
3445-
3446 clk = clk_register(dev, &gate_fn->gate.hw);
3447
3448 if (IS_ERR(clk))
3449diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3450index 827d1500..2885dc6 100644
3451--- a/arch/arm/mach-omap2/board-n8x0.c
3452+++ b/arch/arm/mach-omap2/board-n8x0.c
3453@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3454 }
3455 #endif
3456
3457-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3458+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3459 .late_init = n8x0_menelaus_late_init,
3460 };
3461
3462diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3463index f3fdd6a..3564800 100644
3464--- a/arch/arm/mach-omap2/gpmc.c
3465+++ b/arch/arm/mach-omap2/gpmc.c
3466@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3467 };
3468
3469 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3470-static struct irq_chip gpmc_irq_chip;
3471 static unsigned gpmc_irq_start;
3472
3473 static struct resource gpmc_mem_root;
3474@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3475
3476 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3477
3478+static struct irq_chip gpmc_irq_chip = {
3479+ .name = "gpmc",
3480+ .irq_startup = gpmc_irq_noop_ret,
3481+ .irq_enable = gpmc_irq_enable,
3482+ .irq_disable = gpmc_irq_disable,
3483+ .irq_shutdown = gpmc_irq_noop,
3484+ .irq_ack = gpmc_irq_noop,
3485+ .irq_mask = gpmc_irq_noop,
3486+ .irq_unmask = gpmc_irq_noop,
3487+
3488+};
3489+
3490 static int gpmc_setup_irq(void)
3491 {
3492 int i;
3493@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3494 return gpmc_irq_start;
3495 }
3496
3497- gpmc_irq_chip.name = "gpmc";
3498- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3499- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3500- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3501- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3502- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3503- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3504- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3505-
3506 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3507 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3508
3509diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3510index f991016..145ebeb 100644
3511--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3512+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3513@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3514 int (*finish_suspend)(unsigned long cpu_state);
3515 void (*resume)(void);
3516 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3517-};
3518+} __no_const;
3519
3520 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3521 static struct powerdomain *mpuss_pd;
3522@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3523 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3524 {}
3525
3526-struct cpu_pm_ops omap_pm_ops = {
3527+static struct cpu_pm_ops omap_pm_ops __read_only = {
3528 .finish_suspend = default_finish_suspend,
3529 .resume = dummy_cpu_resume,
3530 .scu_prepare = dummy_scu_prepare,
3531diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3532index 813c615..ce467c6 100644
3533--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3534+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3535@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3536 return NOTIFY_OK;
3537 }
3538
3539-static struct notifier_block __refdata irq_hotplug_notifier = {
3540+static struct notifier_block irq_hotplug_notifier = {
3541 .notifier_call = irq_cpu_hotplug_notify,
3542 };
3543
3544diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3545index f99f68e..e573e20 100644
3546--- a/arch/arm/mach-omap2/omap_device.c
3547+++ b/arch/arm/mach-omap2/omap_device.c
3548@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3549 struct platform_device __init *omap_device_build(const char *pdev_name,
3550 int pdev_id,
3551 struct omap_hwmod *oh,
3552- void *pdata, int pdata_len)
3553+ const void *pdata, int pdata_len)
3554 {
3555 struct omap_hwmod *ohs[] = { oh };
3556
3557@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3558 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3559 int pdev_id,
3560 struct omap_hwmod **ohs,
3561- int oh_cnt, void *pdata,
3562+ int oh_cnt, const void *pdata,
3563 int pdata_len)
3564 {
3565 int ret = -ENOMEM;
3566diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3567index 17ca1ae..beba869 100644
3568--- a/arch/arm/mach-omap2/omap_device.h
3569+++ b/arch/arm/mach-omap2/omap_device.h
3570@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3571 /* Core code interface */
3572
3573 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3574- struct omap_hwmod *oh, void *pdata,
3575+ struct omap_hwmod *oh, const void *pdata,
3576 int pdata_len);
3577
3578 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3579 struct omap_hwmod **oh, int oh_cnt,
3580- void *pdata, int pdata_len);
3581+ const void *pdata, int pdata_len);
3582
3583 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3584 struct omap_hwmod **ohs, int oh_cnt);
3585diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3586index 7f4db12..0243012 100644
3587--- a/arch/arm/mach-omap2/omap_hwmod.c
3588+++ b/arch/arm/mach-omap2/omap_hwmod.c
3589@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3590 int (*init_clkdm)(struct omap_hwmod *oh);
3591 void (*update_context_lost)(struct omap_hwmod *oh);
3592 int (*get_context_lost)(struct omap_hwmod *oh);
3593-};
3594+} __no_const;
3595
3596 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3597-static struct omap_hwmod_soc_ops soc_ops;
3598+static struct omap_hwmod_soc_ops soc_ops __read_only;
3599
3600 /* omap_hwmod_list contains all registered struct omap_hwmods */
3601 static LIST_HEAD(omap_hwmod_list);
3602diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3603index d15c7bb..b2d1f0c 100644
3604--- a/arch/arm/mach-omap2/wd_timer.c
3605+++ b/arch/arm/mach-omap2/wd_timer.c
3606@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3607 struct omap_hwmod *oh;
3608 char *oh_name = "wd_timer2";
3609 char *dev_name = "omap_wdt";
3610- struct omap_wd_timer_platform_data pdata;
3611+ static struct omap_wd_timer_platform_data pdata = {
3612+ .read_reset_sources = prm_read_reset_sources
3613+ };
3614
3615 if (!cpu_class_is_omap2() || of_have_populated_dt())
3616 return 0;
3617@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3618 return -EINVAL;
3619 }
3620
3621- pdata.read_reset_sources = prm_read_reset_sources;
3622-
3623 pdev = omap_device_build(dev_name, id, oh, &pdata,
3624 sizeof(struct omap_wd_timer_platform_data));
3625 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3626diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3627index 706aa42..f85e9131 100644
3628--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3629+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3630@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3631 bool entered_lp2 = false;
3632
3633 if (tegra_pending_sgi())
3634- ACCESS_ONCE(abort_flag) = true;
3635+ ACCESS_ONCE_RW(abort_flag) = true;
3636
3637 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3638
3639diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3640index cad3ca86..1d79e0f 100644
3641--- a/arch/arm/mach-ux500/setup.h
3642+++ b/arch/arm/mach-ux500/setup.h
3643@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3644 .type = MT_DEVICE, \
3645 }
3646
3647-#define __MEM_DEV_DESC(x, sz) { \
3648- .virtual = IO_ADDRESS(x), \
3649- .pfn = __phys_to_pfn(x), \
3650- .length = sz, \
3651- .type = MT_MEMORY, \
3652-}
3653-
3654 extern struct smp_operations ux500_smp_ops;
3655 extern void ux500_cpu_die(unsigned int cpu);
3656
3657diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3658index cd2c88e..7430282 100644
3659--- a/arch/arm/mm/Kconfig
3660+++ b/arch/arm/mm/Kconfig
3661@@ -446,7 +446,7 @@ config CPU_32v5
3662
3663 config CPU_32v6
3664 bool
3665- select CPU_USE_DOMAINS if CPU_V6 && MMU
3666+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3667 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3668
3669 config CPU_32v6K
3670@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3671
3672 config CPU_USE_DOMAINS
3673 bool
3674+ depends on !ARM_LPAE && !PAX_KERNEXEC
3675 help
3676 This option enables or disables the use of domain switching
3677 via the set_fs() function.
3678@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3679 config KUSER_HELPERS
3680 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3681 default y
3682+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3683 help
3684 Warning: disabling this option may break user programs.
3685
3686@@ -812,7 +814,7 @@ config KUSER_HELPERS
3687 See Documentation/arm/kernel_user_helpers.txt for details.
3688
3689 However, the fixed address nature of these helpers can be used
3690- by ROP (return orientated programming) authors when creating
3691+ by ROP (Return Oriented Programming) authors when creating
3692 exploits.
3693
3694 If all of the binaries and libraries which run on your platform
3695diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3696index 6f4585b..7b6f52b 100644
3697--- a/arch/arm/mm/alignment.c
3698+++ b/arch/arm/mm/alignment.c
3699@@ -211,10 +211,12 @@ union offset_union {
3700 #define __get16_unaligned_check(ins,val,addr) \
3701 do { \
3702 unsigned int err = 0, v, a = addr; \
3703+ pax_open_userland(); \
3704 __get8_unaligned_check(ins,v,a,err); \
3705 val = v << ((BE) ? 8 : 0); \
3706 __get8_unaligned_check(ins,v,a,err); \
3707 val |= v << ((BE) ? 0 : 8); \
3708+ pax_close_userland(); \
3709 if (err) \
3710 goto fault; \
3711 } while (0)
3712@@ -228,6 +230,7 @@ union offset_union {
3713 #define __get32_unaligned_check(ins,val,addr) \
3714 do { \
3715 unsigned int err = 0, v, a = addr; \
3716+ pax_open_userland(); \
3717 __get8_unaligned_check(ins,v,a,err); \
3718 val = v << ((BE) ? 24 : 0); \
3719 __get8_unaligned_check(ins,v,a,err); \
3720@@ -236,6 +239,7 @@ union offset_union {
3721 val |= v << ((BE) ? 8 : 16); \
3722 __get8_unaligned_check(ins,v,a,err); \
3723 val |= v << ((BE) ? 0 : 24); \
3724+ pax_close_userland(); \
3725 if (err) \
3726 goto fault; \
3727 } while (0)
3728@@ -249,6 +253,7 @@ union offset_union {
3729 #define __put16_unaligned_check(ins,val,addr) \
3730 do { \
3731 unsigned int err = 0, v = val, a = addr; \
3732+ pax_open_userland(); \
3733 __asm__( FIRST_BYTE_16 \
3734 ARM( "1: "ins" %1, [%2], #1\n" ) \
3735 THUMB( "1: "ins" %1, [%2]\n" ) \
3736@@ -268,6 +273,7 @@ union offset_union {
3737 " .popsection\n" \
3738 : "=r" (err), "=&r" (v), "=&r" (a) \
3739 : "0" (err), "1" (v), "2" (a)); \
3740+ pax_close_userland(); \
3741 if (err) \
3742 goto fault; \
3743 } while (0)
3744@@ -281,6 +287,7 @@ union offset_union {
3745 #define __put32_unaligned_check(ins,val,addr) \
3746 do { \
3747 unsigned int err = 0, v = val, a = addr; \
3748+ pax_open_userland(); \
3749 __asm__( FIRST_BYTE_32 \
3750 ARM( "1: "ins" %1, [%2], #1\n" ) \
3751 THUMB( "1: "ins" %1, [%2]\n" ) \
3752@@ -310,6 +317,7 @@ union offset_union {
3753 " .popsection\n" \
3754 : "=r" (err), "=&r" (v), "=&r" (a) \
3755 : "0" (err), "1" (v), "2" (a)); \
3756+ pax_close_userland(); \
3757 if (err) \
3758 goto fault; \
3759 } while (0)
3760diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3761index 4a05444..d21968c 100644
3762--- a/arch/arm/mm/context.c
3763+++ b/arch/arm/mm/context.c
3764@@ -43,7 +43,7 @@
3765 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3766
3767 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3768-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3769+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3770 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3771
3772 static DEFINE_PER_CPU(atomic64_t, active_asids);
3773@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3774 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3775 {
3776 u64 asid = atomic64_read(&mm->context.id);
3777- u64 generation = atomic64_read(&asid_generation);
3778+ u64 generation = atomic64_read_unchecked(&asid_generation);
3779
3780 if (asid != 0 && is_reserved_asid(asid)) {
3781 /*
3782@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3783 */
3784 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3785 if (asid == NUM_USER_ASIDS) {
3786- generation = atomic64_add_return(ASID_FIRST_VERSION,
3787+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3788 &asid_generation);
3789 flush_context(cpu);
3790 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3791@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3792 cpu_set_reserved_ttbr0();
3793
3794 asid = atomic64_read(&mm->context.id);
3795- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3796+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3797 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3798 goto switch_mm_fastpath;
3799
3800 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3801 /* Check that our ASID belongs to the current generation. */
3802 asid = atomic64_read(&mm->context.id);
3803- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3804+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3805 asid = new_context(mm, cpu);
3806 atomic64_set(&mm->context.id, asid);
3807 }
3808diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3809index c97f794..6461880 100644
3810--- a/arch/arm/mm/fault.c
3811+++ b/arch/arm/mm/fault.c
3812@@ -25,6 +25,7 @@
3813 #include <asm/system_misc.h>
3814 #include <asm/system_info.h>
3815 #include <asm/tlbflush.h>
3816+#include <asm/sections.h>
3817
3818 #include "fault.h"
3819
3820@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3821 if (fixup_exception(regs))
3822 return;
3823
3824+#ifdef CONFIG_PAX_KERNEXEC
3825+ if ((fsr & FSR_WRITE) &&
3826+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3827+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3828+ {
3829+ if (current->signal->curr_ip)
3830+ 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),
3831+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3832+ else
3833+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3834+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3835+ }
3836+#endif
3837+
3838 /*
3839 * No handler, we'll have to terminate things with extreme prejudice.
3840 */
3841@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3842 }
3843 #endif
3844
3845+#ifdef CONFIG_PAX_PAGEEXEC
3846+ if (fsr & FSR_LNX_PF) {
3847+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3848+ do_group_exit(SIGKILL);
3849+ }
3850+#endif
3851+
3852 tsk->thread.address = addr;
3853 tsk->thread.error_code = fsr;
3854 tsk->thread.trap_no = 14;
3855@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3856 }
3857 #endif /* CONFIG_MMU */
3858
3859+#ifdef CONFIG_PAX_PAGEEXEC
3860+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3861+{
3862+ long i;
3863+
3864+ printk(KERN_ERR "PAX: bytes at PC: ");
3865+ for (i = 0; i < 20; i++) {
3866+ unsigned char c;
3867+ if (get_user(c, (__force unsigned char __user *)pc+i))
3868+ printk(KERN_CONT "?? ");
3869+ else
3870+ printk(KERN_CONT "%02x ", c);
3871+ }
3872+ printk("\n");
3873+
3874+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3875+ for (i = -1; i < 20; i++) {
3876+ unsigned long c;
3877+ if (get_user(c, (__force unsigned long __user *)sp+i))
3878+ printk(KERN_CONT "???????? ");
3879+ else
3880+ printk(KERN_CONT "%08lx ", c);
3881+ }
3882+ printk("\n");
3883+}
3884+#endif
3885+
3886 /*
3887 * First Level Translation Fault Handler
3888 *
3889@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3890 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3891 struct siginfo info;
3892
3893+#ifdef CONFIG_PAX_MEMORY_UDEREF
3894+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3895+ if (current->signal->curr_ip)
3896+ 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),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3898+ else
3899+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3900+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3901+ goto die;
3902+ }
3903+#endif
3904+
3905 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3906 return;
3907
3908+die:
3909 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3910 inf->name, fsr, addr);
3911
3912@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3913 ifsr_info[nr].name = name;
3914 }
3915
3916+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3917+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3918+
3919 asmlinkage void __exception
3920 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3921 {
3922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3923 struct siginfo info;
3924+ unsigned long pc = instruction_pointer(regs);
3925+
3926+ if (user_mode(regs)) {
3927+ unsigned long sigpage = current->mm->context.sigpage;
3928+
3929+ if (sigpage <= pc && pc < sigpage + 7*4) {
3930+ if (pc < sigpage + 3*4)
3931+ sys_sigreturn(regs);
3932+ else
3933+ sys_rt_sigreturn(regs);
3934+ return;
3935+ }
3936+ if (pc == 0xffff0f60UL) {
3937+ /*
3938+ * PaX: __kuser_cmpxchg64 emulation
3939+ */
3940+ // TODO
3941+ //regs->ARM_pc = regs->ARM_lr;
3942+ //return;
3943+ }
3944+ if (pc == 0xffff0fa0UL) {
3945+ /*
3946+ * PaX: __kuser_memory_barrier emulation
3947+ */
3948+ // dmb(); implied by the exception
3949+ regs->ARM_pc = regs->ARM_lr;
3950+ return;
3951+ }
3952+ if (pc == 0xffff0fc0UL) {
3953+ /*
3954+ * PaX: __kuser_cmpxchg emulation
3955+ */
3956+ // TODO
3957+ //regs->ARM_pc = regs->ARM_lr;
3958+ //return;
3959+ }
3960+ if (pc == 0xffff0fe0UL) {
3961+ /*
3962+ * PaX: __kuser_get_tls emulation
3963+ */
3964+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3965+ regs->ARM_pc = regs->ARM_lr;
3966+ return;
3967+ }
3968+ }
3969+
3970+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3971+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3972+ if (current->signal->curr_ip)
3973+ 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),
3974+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3975+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3976+ else
3977+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3978+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3979+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3980+ goto die;
3981+ }
3982+#endif
3983+
3984+#ifdef CONFIG_PAX_REFCOUNT
3985+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3986+ unsigned int bkpt;
3987+
3988+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3989+ current->thread.error_code = ifsr;
3990+ current->thread.trap_no = 0;
3991+ pax_report_refcount_overflow(regs);
3992+ fixup_exception(regs);
3993+ return;
3994+ }
3995+ }
3996+#endif
3997
3998 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3999 return;
4000
4001+die:
4002 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4003 inf->name, ifsr, addr);
4004
4005diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4006index cf08bdf..772656c 100644
4007--- a/arch/arm/mm/fault.h
4008+++ b/arch/arm/mm/fault.h
4009@@ -3,6 +3,7 @@
4010
4011 /*
4012 * Fault status register encodings. We steal bit 31 for our own purposes.
4013+ * Set when the FSR value is from an instruction fault.
4014 */
4015 #define FSR_LNX_PF (1 << 31)
4016 #define FSR_WRITE (1 << 11)
4017@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4018 }
4019 #endif
4020
4021+/* valid for LPAE and !LPAE */
4022+static inline int is_xn_fault(unsigned int fsr)
4023+{
4024+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4025+}
4026+
4027+static inline int is_domain_fault(unsigned int fsr)
4028+{
4029+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4030+}
4031+
4032 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4033 unsigned long search_exception_table(unsigned long addr);
4034
4035diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4036index 15225d8..25e2e3c 100644
4037--- a/arch/arm/mm/init.c
4038+++ b/arch/arm/mm/init.c
4039@@ -30,6 +30,8 @@
4040 #include <asm/setup.h>
4041 #include <asm/tlb.h>
4042 #include <asm/fixmap.h>
4043+#include <asm/system_info.h>
4044+#include <asm/cp15.h>
4045
4046 #include <asm/mach/arch.h>
4047 #include <asm/mach/map.h>
4048@@ -683,7 +685,46 @@ void free_initmem(void)
4049 {
4050 #ifdef CONFIG_HAVE_TCM
4051 extern char __tcm_start, __tcm_end;
4052+#endif
4053
4054+#ifdef CONFIG_PAX_KERNEXEC
4055+ unsigned long addr;
4056+ pgd_t *pgd;
4057+ pud_t *pud;
4058+ pmd_t *pmd;
4059+ int cpu_arch = cpu_architecture();
4060+ unsigned int cr = get_cr();
4061+
4062+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4063+ /* make pages tables, etc before .text NX */
4064+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; 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 init NX */
4071+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4072+ pgd = pgd_offset_k(addr);
4073+ pud = pud_offset(pgd, addr);
4074+ pmd = pmd_offset(pud, addr);
4075+ __section_update(pmd, addr, PMD_SECT_XN);
4076+ }
4077+ /* make kernel code/rodata RX */
4078+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4079+ pgd = pgd_offset_k(addr);
4080+ pud = pud_offset(pgd, addr);
4081+ pmd = pmd_offset(pud, addr);
4082+#ifdef CONFIG_ARM_LPAE
4083+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4084+#else
4085+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4086+#endif
4087+ }
4088+ }
4089+#endif
4090+
4091+#ifdef CONFIG_HAVE_TCM
4092 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4093 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4094 #endif
4095diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4096index f123d6e..04bf569 100644
4097--- a/arch/arm/mm/ioremap.c
4098+++ b/arch/arm/mm/ioremap.c
4099@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4100 unsigned int mtype;
4101
4102 if (cached)
4103- mtype = MT_MEMORY;
4104+ mtype = MT_MEMORY_RX;
4105 else
4106- mtype = MT_MEMORY_NONCACHED;
4107+ mtype = MT_MEMORY_NONCACHED_RX;
4108
4109 return __arm_ioremap_caller(phys_addr, size, mtype,
4110 __builtin_return_address(0));
4111diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4112index 0c63562..7128a90 100644
4113--- a/arch/arm/mm/mmap.c
4114+++ b/arch/arm/mm/mmap.c
4115@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4116 struct vm_area_struct *vma;
4117 int do_align = 0;
4118 int aliasing = cache_is_vipt_aliasing();
4119+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4120 struct vm_unmapped_area_info info;
4121
4122 /*
4123@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4124 if (len > TASK_SIZE)
4125 return -ENOMEM;
4126
4127+#ifdef CONFIG_PAX_RANDMMAP
4128+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4129+#endif
4130+
4131 if (addr) {
4132 if (do_align)
4133 addr = COLOUR_ALIGN(addr, pgoff);
4134@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4135 addr = PAGE_ALIGN(addr);
4136
4137 vma = find_vma(mm, addr);
4138- if (TASK_SIZE - len >= addr &&
4139- (!vma || addr + len <= vma->vm_start))
4140+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4141 return addr;
4142 }
4143
4144@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4145 info.high_limit = TASK_SIZE;
4146 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4147 info.align_offset = pgoff << PAGE_SHIFT;
4148+ info.threadstack_offset = offset;
4149 return vm_unmapped_area(&info);
4150 }
4151
4152@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4153 unsigned long addr = addr0;
4154 int do_align = 0;
4155 int aliasing = cache_is_vipt_aliasing();
4156+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4157 struct vm_unmapped_area_info info;
4158
4159 /*
4160@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4161 return addr;
4162 }
4163
4164+#ifdef CONFIG_PAX_RANDMMAP
4165+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4166+#endif
4167+
4168 /* requesting a specific address */
4169 if (addr) {
4170 if (do_align)
4171@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4172 else
4173 addr = PAGE_ALIGN(addr);
4174 vma = find_vma(mm, addr);
4175- if (TASK_SIZE - len >= addr &&
4176- (!vma || addr + len <= vma->vm_start))
4177+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4178 return addr;
4179 }
4180
4181@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4182 info.high_limit = mm->mmap_base;
4183 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4184 info.align_offset = pgoff << PAGE_SHIFT;
4185+ info.threadstack_offset = offset;
4186 addr = vm_unmapped_area(&info);
4187
4188 /*
4189@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4190 {
4191 unsigned long random_factor = 0UL;
4192
4193+#ifdef CONFIG_PAX_RANDMMAP
4194+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4195+#endif
4196+
4197 /* 8 bits of randomness in 20 address space bits */
4198 if ((current->flags & PF_RANDOMIZE) &&
4199 !(current->personality & ADDR_NO_RANDOMIZE))
4200@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4201
4202 if (mmap_is_legacy()) {
4203 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4204+
4205+#ifdef CONFIG_PAX_RANDMMAP
4206+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4207+ mm->mmap_base += mm->delta_mmap;
4208+#endif
4209+
4210 mm->get_unmapped_area = arch_get_unmapped_area;
4211 } else {
4212 mm->mmap_base = mmap_base(random_factor);
4213+
4214+#ifdef CONFIG_PAX_RANDMMAP
4215+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4216+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4217+#endif
4218+
4219 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4220 }
4221 }
4222diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4223index 53cdbd3..670f177 100644
4224--- a/arch/arm/mm/mmu.c
4225+++ b/arch/arm/mm/mmu.c
4226@@ -36,6 +36,22 @@
4227 #include "mm.h"
4228 #include "tcm.h"
4229
4230+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4231+void modify_domain(unsigned int dom, unsigned int type)
4232+{
4233+ struct thread_info *thread = current_thread_info();
4234+ unsigned int domain = thread->cpu_domain;
4235+ /*
4236+ * DOMAIN_MANAGER might be defined to some other value,
4237+ * use the arch-defined constant
4238+ */
4239+ domain &= ~domain_val(dom, 3);
4240+ thread->cpu_domain = domain | domain_val(dom, type);
4241+ set_domain(thread->cpu_domain);
4242+}
4243+EXPORT_SYMBOL(modify_domain);
4244+#endif
4245+
4246 /*
4247 * empty_zero_page is a special page that is used for
4248 * zero-initialized data and COW.
4249@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4250
4251 #endif /* ifdef CONFIG_CPU_CP15 / else */
4252
4253-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4254+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4255 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4256
4257-static struct mem_type mem_types[] = {
4258+#ifdef CONFIG_PAX_KERNEXEC
4259+#define L_PTE_KERNEXEC L_PTE_RDONLY
4260+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4261+#else
4262+#define L_PTE_KERNEXEC L_PTE_DIRTY
4263+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4264+#endif
4265+
4266+static struct mem_type mem_types[] __read_only = {
4267 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4268 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4269 L_PTE_SHARED,
4270@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4271 [MT_UNCACHED] = {
4272 .prot_pte = PROT_PTE_DEVICE,
4273 .prot_l1 = PMD_TYPE_TABLE,
4274- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4275+ .prot_sect = PROT_SECT_DEVICE,
4276 .domain = DOMAIN_IO,
4277 },
4278 [MT_CACHECLEAN] = {
4279- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4280+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4281 .domain = DOMAIN_KERNEL,
4282 },
4283 #ifndef CONFIG_ARM_LPAE
4284 [MT_MINICLEAN] = {
4285- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4286+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4287 .domain = DOMAIN_KERNEL,
4288 },
4289 #endif
4290@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4291 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4292 L_PTE_RDONLY,
4293 .prot_l1 = PMD_TYPE_TABLE,
4294- .domain = DOMAIN_USER,
4295+ .domain = DOMAIN_VECTORS,
4296 },
4297 [MT_HIGH_VECTORS] = {
4298 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4299 L_PTE_USER | L_PTE_RDONLY,
4300 .prot_l1 = PMD_TYPE_TABLE,
4301- .domain = DOMAIN_USER,
4302+ .domain = DOMAIN_VECTORS,
4303 },
4304- [MT_MEMORY] = {
4305+ [MT_MEMORY_RWX] = {
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_RW] = {
4312+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4313+ .prot_l1 = PMD_TYPE_TABLE,
4314+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4315+ .domain = DOMAIN_KERNEL,
4316+ },
4317+ [MT_MEMORY_RX] = {
4318+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4319+ .prot_l1 = PMD_TYPE_TABLE,
4320+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4321+ .domain = DOMAIN_KERNEL,
4322+ },
4323 [MT_ROM] = {
4324- .prot_sect = PMD_TYPE_SECT,
4325+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4326 .domain = DOMAIN_KERNEL,
4327 },
4328- [MT_MEMORY_NONCACHED] = {
4329+ [MT_MEMORY_NONCACHED_RW] = {
4330 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4331 L_PTE_MT_BUFFERABLE,
4332 .prot_l1 = PMD_TYPE_TABLE,
4333 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4334 .domain = DOMAIN_KERNEL,
4335 },
4336+ [MT_MEMORY_NONCACHED_RX] = {
4337+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4338+ L_PTE_MT_BUFFERABLE,
4339+ .prot_l1 = PMD_TYPE_TABLE,
4340+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4341+ .domain = DOMAIN_KERNEL,
4342+ },
4343 [MT_MEMORY_DTCM] = {
4344- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4345- L_PTE_XN,
4346+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4347 .prot_l1 = PMD_TYPE_TABLE,
4348- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4349+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4350 .domain = DOMAIN_KERNEL,
4351 },
4352 [MT_MEMORY_ITCM] = {
4353@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4354 },
4355 [MT_MEMORY_SO] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357- L_PTE_MT_UNCACHED | L_PTE_XN,
4358+ L_PTE_MT_UNCACHED,
4359 .prot_l1 = PMD_TYPE_TABLE,
4360 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4361- PMD_SECT_UNCACHED | PMD_SECT_XN,
4362+ PMD_SECT_UNCACHED,
4363 .domain = DOMAIN_KERNEL,
4364 },
4365 [MT_MEMORY_DMA_READY] = {
4366@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4367 * to prevent speculative instruction fetches.
4368 */
4369 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4371 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4372+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4373 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4374+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4375 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4376+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4377+
4378+ /* Mark other regions on ARMv6+ as execute-never */
4379+
4380+#ifdef CONFIG_PAX_KERNEXEC
4381+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4382+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4383+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4385+#ifndef CONFIG_ARM_LPAE
4386+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4387+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4388+#endif
4389+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4390+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4391+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4392+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4393+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4394+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4395+#endif
4396+
4397+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4398+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4399 }
4400 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4401 /*
4402@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4403 * from SVC mode and no access from userspace.
4404 */
4405 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4406+#ifdef CONFIG_PAX_KERNEXEC
4407+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4408+#endif
4409 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4410 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4411 #endif
4412@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4413 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4414 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4415 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4416- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4417- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4418+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4419+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4420+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4421+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4422+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4423+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4424 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4425- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4426- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4427+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4428+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4429+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4431 }
4432 }
4433
4434@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4435 if (cpu_arch >= CPU_ARCH_ARMv6) {
4436 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4437 /* Non-cacheable Normal is XCB = 001 */
4438- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4439+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4440+ PMD_SECT_BUFFERED;
4441+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4442 PMD_SECT_BUFFERED;
4443 } else {
4444 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4445- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4446+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4447+ PMD_SECT_TEX(1);
4448+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4449 PMD_SECT_TEX(1);
4450 }
4451 } else {
4452- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4453+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4454+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4455 }
4456
4457 #ifdef CONFIG_ARM_LPAE
4458@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4459 vecs_pgprot |= PTE_EXT_AF;
4460 #endif
4461
4462+ user_pgprot |= __supported_pte_mask;
4463+
4464 for (i = 0; i < 16; i++) {
4465 pteval_t v = pgprot_val(protection_map[i]);
4466 protection_map[i] = __pgprot(v | user_pgprot);
4467@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4468
4469 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4470 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4471- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4472- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4473+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4474+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4475+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4476+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4477+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4478+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4479 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4480- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4481+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4482+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4483 mem_types[MT_ROM].prot_sect |= cp->pmd;
4484
4485 switch (cp->pmd) {
4486@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4487 * called function. This means you can't use any function or debugging
4488 * method which may touch any device, otherwise the kernel _will_ crash.
4489 */
4490+
4491+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4492+
4493 static void __init devicemaps_init(struct machine_desc *mdesc)
4494 {
4495 struct map_desc map;
4496 unsigned long addr;
4497- void *vectors;
4498
4499- /*
4500- * Allocate the vector page early.
4501- */
4502- vectors = early_alloc(PAGE_SIZE * 2);
4503-
4504- early_trap_init(vectors);
4505+ early_trap_init(&vectors);
4506
4507 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4508 pmd_clear(pmd_off_k(addr));
4509@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4510 * location (0xffff0000). If we aren't using high-vectors, also
4511 * create a mapping at the low-vectors virtual address.
4512 */
4513- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4514+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4515 map.virtual = 0xffff0000;
4516 map.length = PAGE_SIZE;
4517 #ifdef CONFIG_KUSER_HELPERS
4518@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4519 map.pfn = __phys_to_pfn(start);
4520 map.virtual = __phys_to_virt(start);
4521 map.length = end - start;
4522- map.type = MT_MEMORY;
4523
4524+#ifdef CONFIG_PAX_KERNEXEC
4525+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4526+ struct map_desc kernel;
4527+ struct map_desc initmap;
4528+
4529+ /* when freeing initmem we will make this RW */
4530+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4531+ initmap.virtual = (unsigned long)__init_begin;
4532+ initmap.length = _sdata - __init_begin;
4533+ initmap.type = MT_MEMORY_RWX;
4534+ create_mapping(&initmap);
4535+
4536+ /* when freeing initmem we will make this RX */
4537+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4538+ kernel.virtual = (unsigned long)_stext;
4539+ kernel.length = __init_begin - _stext;
4540+ kernel.type = MT_MEMORY_RWX;
4541+ create_mapping(&kernel);
4542+
4543+ if (map.virtual < (unsigned long)_stext) {
4544+ map.length = (unsigned long)_stext - map.virtual;
4545+ map.type = MT_MEMORY_RWX;
4546+ create_mapping(&map);
4547+ }
4548+
4549+ map.pfn = __phys_to_pfn(__pa(_sdata));
4550+ map.virtual = (unsigned long)_sdata;
4551+ map.length = end - __pa(_sdata);
4552+ }
4553+#endif
4554+
4555+ map.type = MT_MEMORY_RW;
4556 create_mapping(&map);
4557 }
4558 }
4559diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4560index a5bc92d..0bb4730 100644
4561--- a/arch/arm/plat-omap/sram.c
4562+++ b/arch/arm/plat-omap/sram.c
4563@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4564 * Looks like we need to preserve some bootloader code at the
4565 * beginning of SRAM for jumping to flash for reboot to work...
4566 */
4567+ pax_open_kernel();
4568 memset_io(omap_sram_base + omap_sram_skip, 0,
4569 omap_sram_size - omap_sram_skip);
4570+ pax_close_kernel();
4571 }
4572diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4573index ce6d763..cfea917 100644
4574--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4575+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4576@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4577 int (*started)(unsigned ch);
4578 int (*flush)(unsigned ch);
4579 int (*stop)(unsigned ch);
4580-};
4581+} __no_const;
4582
4583 extern void *samsung_dmadev_get_ops(void);
4584 extern void *s3c_dma_get_ops(void);
4585diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4586index c3a58a1..78fbf54 100644
4587--- a/arch/avr32/include/asm/cache.h
4588+++ b/arch/avr32/include/asm/cache.h
4589@@ -1,8 +1,10 @@
4590 #ifndef __ASM_AVR32_CACHE_H
4591 #define __ASM_AVR32_CACHE_H
4592
4593+#include <linux/const.h>
4594+
4595 #define L1_CACHE_SHIFT 5
4596-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4597+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4598
4599 /*
4600 * Memory returned by kmalloc() may be used for DMA, so we must make
4601diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4602index d232888..87c8df1 100644
4603--- a/arch/avr32/include/asm/elf.h
4604+++ b/arch/avr32/include/asm/elf.h
4605@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4606 the loader. We need to make sure that it is out of the way of the program
4607 that it will "exec", and that there is sufficient room for the brk. */
4608
4609-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4610+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4611
4612+#ifdef CONFIG_PAX_ASLR
4613+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4614+
4615+#define PAX_DELTA_MMAP_LEN 15
4616+#define PAX_DELTA_STACK_LEN 15
4617+#endif
4618
4619 /* This yields a mask that user programs can use to figure out what
4620 instruction set this CPU supports. This could be done in user space,
4621diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4622index 479330b..53717a8 100644
4623--- a/arch/avr32/include/asm/kmap_types.h
4624+++ b/arch/avr32/include/asm/kmap_types.h
4625@@ -2,9 +2,9 @@
4626 #define __ASM_AVR32_KMAP_TYPES_H
4627
4628 #ifdef CONFIG_DEBUG_HIGHMEM
4629-# define KM_TYPE_NR 29
4630+# define KM_TYPE_NR 30
4631 #else
4632-# define KM_TYPE_NR 14
4633+# define KM_TYPE_NR 15
4634 #endif
4635
4636 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4637diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4638index b2f2d2d..d1c85cb 100644
4639--- a/arch/avr32/mm/fault.c
4640+++ b/arch/avr32/mm/fault.c
4641@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4642
4643 int exception_trace = 1;
4644
4645+#ifdef CONFIG_PAX_PAGEEXEC
4646+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4647+{
4648+ unsigned long i;
4649+
4650+ printk(KERN_ERR "PAX: bytes at PC: ");
4651+ for (i = 0; i < 20; i++) {
4652+ unsigned char c;
4653+ if (get_user(c, (unsigned char *)pc+i))
4654+ printk(KERN_CONT "???????? ");
4655+ else
4656+ printk(KERN_CONT "%02x ", c);
4657+ }
4658+ printk("\n");
4659+}
4660+#endif
4661+
4662 /*
4663 * This routine handles page faults. It determines the address and the
4664 * problem, and then passes it off to one of the appropriate routines.
4665@@ -174,6 +191,16 @@ bad_area:
4666 up_read(&mm->mmap_sem);
4667
4668 if (user_mode(regs)) {
4669+
4670+#ifdef CONFIG_PAX_PAGEEXEC
4671+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4672+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4673+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4674+ do_group_exit(SIGKILL);
4675+ }
4676+ }
4677+#endif
4678+
4679 if (exception_trace && printk_ratelimit())
4680 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4681 "sp %08lx ecr %lu\n",
4682diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4683index 568885a..f8008df 100644
4684--- a/arch/blackfin/include/asm/cache.h
4685+++ b/arch/blackfin/include/asm/cache.h
4686@@ -7,6 +7,7 @@
4687 #ifndef __ARCH_BLACKFIN_CACHE_H
4688 #define __ARCH_BLACKFIN_CACHE_H
4689
4690+#include <linux/const.h>
4691 #include <linux/linkage.h> /* for asmlinkage */
4692
4693 /*
4694@@ -14,7 +15,7 @@
4695 * Blackfin loads 32 bytes for cache
4696 */
4697 #define L1_CACHE_SHIFT 5
4698-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4699+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4700 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4701
4702 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4703diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4704index aea2718..3639a60 100644
4705--- a/arch/cris/include/arch-v10/arch/cache.h
4706+++ b/arch/cris/include/arch-v10/arch/cache.h
4707@@ -1,8 +1,9 @@
4708 #ifndef _ASM_ARCH_CACHE_H
4709 #define _ASM_ARCH_CACHE_H
4710
4711+#include <linux/const.h>
4712 /* Etrax 100LX have 32-byte cache-lines. */
4713-#define L1_CACHE_BYTES 32
4714 #define L1_CACHE_SHIFT 5
4715+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4716
4717 #endif /* _ASM_ARCH_CACHE_H */
4718diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4719index 7caf25d..ee65ac5 100644
4720--- a/arch/cris/include/arch-v32/arch/cache.h
4721+++ b/arch/cris/include/arch-v32/arch/cache.h
4722@@ -1,11 +1,12 @@
4723 #ifndef _ASM_CRIS_ARCH_CACHE_H
4724 #define _ASM_CRIS_ARCH_CACHE_H
4725
4726+#include <linux/const.h>
4727 #include <arch/hwregs/dma.h>
4728
4729 /* A cache-line is 32 bytes. */
4730-#define L1_CACHE_BYTES 32
4731 #define L1_CACHE_SHIFT 5
4732+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4733
4734 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4735
4736diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4737index b86329d..6709906 100644
4738--- a/arch/frv/include/asm/atomic.h
4739+++ b/arch/frv/include/asm/atomic.h
4740@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4741 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4742 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4743
4744+#define atomic64_read_unchecked(v) atomic64_read(v)
4745+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4746+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4747+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4748+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4749+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4750+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4751+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4752+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4753+
4754 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4755 {
4756 int c, old;
4757diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4758index 2797163..c2a401d 100644
4759--- a/arch/frv/include/asm/cache.h
4760+++ b/arch/frv/include/asm/cache.h
4761@@ -12,10 +12,11 @@
4762 #ifndef __ASM_CACHE_H
4763 #define __ASM_CACHE_H
4764
4765+#include <linux/const.h>
4766
4767 /* bytes per L1 cache line */
4768 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771
4772 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4773 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4774diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4775index 43901f2..0d8b865 100644
4776--- a/arch/frv/include/asm/kmap_types.h
4777+++ b/arch/frv/include/asm/kmap_types.h
4778@@ -2,6 +2,6 @@
4779 #ifndef _ASM_KMAP_TYPES_H
4780 #define _ASM_KMAP_TYPES_H
4781
4782-#define KM_TYPE_NR 17
4783+#define KM_TYPE_NR 18
4784
4785 #endif
4786diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4787index 836f147..4cf23f5 100644
4788--- a/arch/frv/mm/elf-fdpic.c
4789+++ b/arch/frv/mm/elf-fdpic.c
4790@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4791 {
4792 struct vm_area_struct *vma;
4793 struct vm_unmapped_area_info info;
4794+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4795
4796 if (len > TASK_SIZE)
4797 return -ENOMEM;
4798@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4799 if (addr) {
4800 addr = PAGE_ALIGN(addr);
4801 vma = find_vma(current->mm, addr);
4802- if (TASK_SIZE - len >= addr &&
4803- (!vma || addr + len <= vma->vm_start))
4804+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4805 goto success;
4806 }
4807
4808@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4809 info.high_limit = (current->mm->start_stack - 0x00200000);
4810 info.align_mask = 0;
4811 info.align_offset = 0;
4812+ info.threadstack_offset = offset;
4813 addr = vm_unmapped_area(&info);
4814 if (!(addr & ~PAGE_MASK))
4815 goto success;
4816diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4817index f4ca594..adc72fd6 100644
4818--- a/arch/hexagon/include/asm/cache.h
4819+++ b/arch/hexagon/include/asm/cache.h
4820@@ -21,9 +21,11 @@
4821 #ifndef __ASM_CACHE_H
4822 #define __ASM_CACHE_H
4823
4824+#include <linux/const.h>
4825+
4826 /* Bytes per L1 cache line */
4827-#define L1_CACHE_SHIFT (5)
4828-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4829+#define L1_CACHE_SHIFT 5
4830+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4831
4832 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4833 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4834diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4835index 6e6fe18..a6ae668 100644
4836--- a/arch/ia64/include/asm/atomic.h
4837+++ b/arch/ia64/include/asm/atomic.h
4838@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4839 #define atomic64_inc(v) atomic64_add(1, (v))
4840 #define atomic64_dec(v) atomic64_sub(1, (v))
4841
4842+#define atomic64_read_unchecked(v) atomic64_read(v)
4843+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4844+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4845+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4846+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4847+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4848+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4849+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4850+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4851+
4852 /* Atomic operations are already serializing */
4853 #define smp_mb__before_atomic_dec() barrier()
4854 #define smp_mb__after_atomic_dec() barrier()
4855diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4856index 988254a..e1ee885 100644
4857--- a/arch/ia64/include/asm/cache.h
4858+++ b/arch/ia64/include/asm/cache.h
4859@@ -1,6 +1,7 @@
4860 #ifndef _ASM_IA64_CACHE_H
4861 #define _ASM_IA64_CACHE_H
4862
4863+#include <linux/const.h>
4864
4865 /*
4866 * Copyright (C) 1998-2000 Hewlett-Packard Co
4867@@ -9,7 +10,7 @@
4868
4869 /* Bytes per L1 (data) cache line. */
4870 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4871-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4873
4874 #ifdef CONFIG_SMP
4875 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4876diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4877index 5a83c5c..4d7f553 100644
4878--- a/arch/ia64/include/asm/elf.h
4879+++ b/arch/ia64/include/asm/elf.h
4880@@ -42,6 +42,13 @@
4881 */
4882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4883
4884+#ifdef CONFIG_PAX_ASLR
4885+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4886+
4887+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4888+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4889+#endif
4890+
4891 #define PT_IA_64_UNWIND 0x70000001
4892
4893 /* IA-64 relocations: */
4894diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4895index 96a8d92..617a1cf 100644
4896--- a/arch/ia64/include/asm/pgalloc.h
4897+++ b/arch/ia64/include/asm/pgalloc.h
4898@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4899 pgd_val(*pgd_entry) = __pa(pud);
4900 }
4901
4902+static inline void
4903+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4904+{
4905+ pgd_populate(mm, pgd_entry, pud);
4906+}
4907+
4908 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4909 {
4910 return quicklist_alloc(0, GFP_KERNEL, NULL);
4911@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4912 pud_val(*pud_entry) = __pa(pmd);
4913 }
4914
4915+static inline void
4916+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4917+{
4918+ pud_populate(mm, pud_entry, pmd);
4919+}
4920+
4921 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4922 {
4923 return quicklist_alloc(0, GFP_KERNEL, NULL);
4924diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4925index 7935115..c0eca6a 100644
4926--- a/arch/ia64/include/asm/pgtable.h
4927+++ b/arch/ia64/include/asm/pgtable.h
4928@@ -12,7 +12,7 @@
4929 * David Mosberger-Tang <davidm@hpl.hp.com>
4930 */
4931
4932-
4933+#include <linux/const.h>
4934 #include <asm/mman.h>
4935 #include <asm/page.h>
4936 #include <asm/processor.h>
4937@@ -142,6 +142,17 @@
4938 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4939 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4940 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4941+
4942+#ifdef CONFIG_PAX_PAGEEXEC
4943+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4944+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4945+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4946+#else
4947+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4948+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4949+# define PAGE_COPY_NOEXEC PAGE_COPY
4950+#endif
4951+
4952 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4953 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4954 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4955diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4956index 54ff557..70c88b7 100644
4957--- a/arch/ia64/include/asm/spinlock.h
4958+++ b/arch/ia64/include/asm/spinlock.h
4959@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4960 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4961
4962 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4963- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4964+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4965 }
4966
4967 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4968diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4969index 449c8c0..18965fb 100644
4970--- a/arch/ia64/include/asm/uaccess.h
4971+++ b/arch/ia64/include/asm/uaccess.h
4972@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4973 static inline unsigned long
4974 __copy_to_user (void __user *to, const void *from, unsigned long count)
4975 {
4976+ if (count > INT_MAX)
4977+ return count;
4978+
4979+ if (!__builtin_constant_p(count))
4980+ check_object_size(from, count, true);
4981+
4982 return __copy_user(to, (__force void __user *) from, count);
4983 }
4984
4985 static inline unsigned long
4986 __copy_from_user (void *to, const void __user *from, unsigned long count)
4987 {
4988+ if (count > INT_MAX)
4989+ return count;
4990+
4991+ if (!__builtin_constant_p(count))
4992+ check_object_size(to, count, false);
4993+
4994 return __copy_user((__force void __user *) to, from, count);
4995 }
4996
4997@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4998 ({ \
4999 void __user *__cu_to = (to); \
5000 const void *__cu_from = (from); \
5001- long __cu_len = (n); \
5002+ unsigned long __cu_len = (n); \
5003 \
5004- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5005+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5006+ if (!__builtin_constant_p(n)) \
5007+ check_object_size(__cu_from, __cu_len, true); \
5008 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5009+ } \
5010 __cu_len; \
5011 })
5012
5013@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5014 ({ \
5015 void *__cu_to = (to); \
5016 const void __user *__cu_from = (from); \
5017- long __cu_len = (n); \
5018+ unsigned long __cu_len = (n); \
5019 \
5020 __chk_user_ptr(__cu_from); \
5021- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5022+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5023+ if (!__builtin_constant_p(n)) \
5024+ check_object_size(__cu_to, __cu_len, false); \
5025 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5026+ } \
5027 __cu_len; \
5028 })
5029
5030diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5031index 24603be..948052d 100644
5032--- a/arch/ia64/kernel/module.c
5033+++ b/arch/ia64/kernel/module.c
5034@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5035 void
5036 module_free (struct module *mod, void *module_region)
5037 {
5038- if (mod && mod->arch.init_unw_table &&
5039- module_region == mod->module_init) {
5040+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5041 unw_remove_unwind_table(mod->arch.init_unw_table);
5042 mod->arch.init_unw_table = NULL;
5043 }
5044@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5045 }
5046
5047 static inline int
5048+in_init_rx (const struct module *mod, uint64_t addr)
5049+{
5050+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5051+}
5052+
5053+static inline int
5054+in_init_rw (const struct module *mod, uint64_t addr)
5055+{
5056+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5057+}
5058+
5059+static inline int
5060 in_init (const struct module *mod, uint64_t addr)
5061 {
5062- return addr - (uint64_t) mod->module_init < mod->init_size;
5063+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5064+}
5065+
5066+static inline int
5067+in_core_rx (const struct module *mod, uint64_t addr)
5068+{
5069+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5070+}
5071+
5072+static inline int
5073+in_core_rw (const struct module *mod, uint64_t addr)
5074+{
5075+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5076 }
5077
5078 static inline int
5079 in_core (const struct module *mod, uint64_t addr)
5080 {
5081- return addr - (uint64_t) mod->module_core < mod->core_size;
5082+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5083 }
5084
5085 static inline int
5086@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5087 break;
5088
5089 case RV_BDREL:
5090- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5091+ if (in_init_rx(mod, val))
5092+ val -= (uint64_t) mod->module_init_rx;
5093+ else if (in_init_rw(mod, val))
5094+ val -= (uint64_t) mod->module_init_rw;
5095+ else if (in_core_rx(mod, val))
5096+ val -= (uint64_t) mod->module_core_rx;
5097+ else if (in_core_rw(mod, val))
5098+ val -= (uint64_t) mod->module_core_rw;
5099 break;
5100
5101 case RV_LTV:
5102@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5103 * addresses have been selected...
5104 */
5105 uint64_t gp;
5106- if (mod->core_size > MAX_LTOFF)
5107+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5108 /*
5109 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5110 * at the end of the module.
5111 */
5112- gp = mod->core_size - MAX_LTOFF / 2;
5113+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5114 else
5115- gp = mod->core_size / 2;
5116- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5117+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5118+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5119 mod->arch.gp = gp;
5120 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5121 }
5122diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5123index ab33328..f39506c 100644
5124--- a/arch/ia64/kernel/palinfo.c
5125+++ b/arch/ia64/kernel/palinfo.c
5126@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5127 return NOTIFY_OK;
5128 }
5129
5130-static struct notifier_block __refdata palinfo_cpu_notifier =
5131+static struct notifier_block palinfo_cpu_notifier =
5132 {
5133 .notifier_call = palinfo_cpu_callback,
5134 .priority = 0,
5135diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5136index 41e33f8..65180b2 100644
5137--- a/arch/ia64/kernel/sys_ia64.c
5138+++ b/arch/ia64/kernel/sys_ia64.c
5139@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5140 unsigned long align_mask = 0;
5141 struct mm_struct *mm = current->mm;
5142 struct vm_unmapped_area_info info;
5143+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5144
5145 if (len > RGN_MAP_LIMIT)
5146 return -ENOMEM;
5147@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5148 if (REGION_NUMBER(addr) == RGN_HPAGE)
5149 addr = 0;
5150 #endif
5151+
5152+#ifdef CONFIG_PAX_RANDMMAP
5153+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5154+ addr = mm->free_area_cache;
5155+ else
5156+#endif
5157+
5158 if (!addr)
5159 addr = TASK_UNMAPPED_BASE;
5160
5161@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5162 info.high_limit = TASK_SIZE;
5163 info.align_mask = align_mask;
5164 info.align_offset = 0;
5165+ info.threadstack_offset = offset;
5166 return vm_unmapped_area(&info);
5167 }
5168
5169diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5170index 0ccb28f..8992469 100644
5171--- a/arch/ia64/kernel/vmlinux.lds.S
5172+++ b/arch/ia64/kernel/vmlinux.lds.S
5173@@ -198,7 +198,7 @@ SECTIONS {
5174 /* Per-cpu data: */
5175 . = ALIGN(PERCPU_PAGE_SIZE);
5176 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5177- __phys_per_cpu_start = __per_cpu_load;
5178+ __phys_per_cpu_start = per_cpu_load;
5179 /*
5180 * ensure percpu data fits
5181 * into percpu page size
5182diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5183index 6cf0341..d352594 100644
5184--- a/arch/ia64/mm/fault.c
5185+++ b/arch/ia64/mm/fault.c
5186@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5187 return pte_present(pte);
5188 }
5189
5190+#ifdef CONFIG_PAX_PAGEEXEC
5191+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5192+{
5193+ unsigned long i;
5194+
5195+ printk(KERN_ERR "PAX: bytes at PC: ");
5196+ for (i = 0; i < 8; i++) {
5197+ unsigned int c;
5198+ if (get_user(c, (unsigned int *)pc+i))
5199+ printk(KERN_CONT "???????? ");
5200+ else
5201+ printk(KERN_CONT "%08x ", c);
5202+ }
5203+ printk("\n");
5204+}
5205+#endif
5206+
5207 # define VM_READ_BIT 0
5208 # define VM_WRITE_BIT 1
5209 # define VM_EXEC_BIT 2
5210@@ -149,8 +166,21 @@ retry:
5211 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5212 goto bad_area;
5213
5214- if ((vma->vm_flags & mask) != mask)
5215+ if ((vma->vm_flags & mask) != mask) {
5216+
5217+#ifdef CONFIG_PAX_PAGEEXEC
5218+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5219+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5220+ goto bad_area;
5221+
5222+ up_read(&mm->mmap_sem);
5223+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5224+ do_group_exit(SIGKILL);
5225+ }
5226+#endif
5227+
5228 goto bad_area;
5229+ }
5230
5231 /*
5232 * If for any reason at all we couldn't handle the fault, make
5233diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5234index 76069c1..c2aa816 100644
5235--- a/arch/ia64/mm/hugetlbpage.c
5236+++ b/arch/ia64/mm/hugetlbpage.c
5237@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5238 unsigned long pgoff, unsigned long flags)
5239 {
5240 struct vm_unmapped_area_info info;
5241+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5242
5243 if (len > RGN_MAP_LIMIT)
5244 return -ENOMEM;
5245@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5246 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5247 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5248 info.align_offset = 0;
5249+ info.threadstack_offset = offset;
5250 return vm_unmapped_area(&info);
5251 }
5252
5253diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5254index b6f7f43..c04320d 100644
5255--- a/arch/ia64/mm/init.c
5256+++ b/arch/ia64/mm/init.c
5257@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5258 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5259 vma->vm_end = vma->vm_start + PAGE_SIZE;
5260 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5261+
5262+#ifdef CONFIG_PAX_PAGEEXEC
5263+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5264+ vma->vm_flags &= ~VM_EXEC;
5265+
5266+#ifdef CONFIG_PAX_MPROTECT
5267+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5268+ vma->vm_flags &= ~VM_MAYEXEC;
5269+#endif
5270+
5271+ }
5272+#endif
5273+
5274 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5275 down_write(&current->mm->mmap_sem);
5276 if (insert_vm_struct(current->mm, vma)) {
5277diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5278index 40b3ee9..8c2c112 100644
5279--- a/arch/m32r/include/asm/cache.h
5280+++ b/arch/m32r/include/asm/cache.h
5281@@ -1,8 +1,10 @@
5282 #ifndef _ASM_M32R_CACHE_H
5283 #define _ASM_M32R_CACHE_H
5284
5285+#include <linux/const.h>
5286+
5287 /* L1 cache line size */
5288 #define L1_CACHE_SHIFT 4
5289-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5290+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5291
5292 #endif /* _ASM_M32R_CACHE_H */
5293diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5294index 82abd15..d95ae5d 100644
5295--- a/arch/m32r/lib/usercopy.c
5296+++ b/arch/m32r/lib/usercopy.c
5297@@ -14,6 +14,9 @@
5298 unsigned long
5299 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5300 {
5301+ if ((long)n < 0)
5302+ return n;
5303+
5304 prefetch(from);
5305 if (access_ok(VERIFY_WRITE, to, n))
5306 __copy_user(to,from,n);
5307@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5308 unsigned long
5309 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5310 {
5311+ if ((long)n < 0)
5312+ return n;
5313+
5314 prefetchw(to);
5315 if (access_ok(VERIFY_READ, from, n))
5316 __copy_user_zeroing(to,from,n);
5317diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5318index 0395c51..5f26031 100644
5319--- a/arch/m68k/include/asm/cache.h
5320+++ b/arch/m68k/include/asm/cache.h
5321@@ -4,9 +4,11 @@
5322 #ifndef __ARCH_M68K_CACHE_H
5323 #define __ARCH_M68K_CACHE_H
5324
5325+#include <linux/const.h>
5326+
5327 /* bytes per L1 cache line */
5328 #define L1_CACHE_SHIFT 4
5329-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5330+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5331
5332 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5333
5334diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5335index 3c52fa6..11b2ad8 100644
5336--- a/arch/metag/mm/hugetlbpage.c
5337+++ b/arch/metag/mm/hugetlbpage.c
5338@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5339 info.high_limit = TASK_SIZE;
5340 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5341 info.align_offset = 0;
5342+ info.threadstack_offset = 0;
5343 return vm_unmapped_area(&info);
5344 }
5345
5346diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5347index 4efe96a..60e8699 100644
5348--- a/arch/microblaze/include/asm/cache.h
5349+++ b/arch/microblaze/include/asm/cache.h
5350@@ -13,11 +13,12 @@
5351 #ifndef _ASM_MICROBLAZE_CACHE_H
5352 #define _ASM_MICROBLAZE_CACHE_H
5353
5354+#include <linux/const.h>
5355 #include <asm/registers.h>
5356
5357 #define L1_CACHE_SHIFT 5
5358 /* word-granular cache in microblaze */
5359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5361
5362 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5363
5364diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5365index 08b6079..8b554d2 100644
5366--- a/arch/mips/include/asm/atomic.h
5367+++ b/arch/mips/include/asm/atomic.h
5368@@ -21,15 +21,39 @@
5369 #include <asm/cmpxchg.h>
5370 #include <asm/war.h>
5371
5372+#ifdef CONFIG_GENERIC_ATOMIC64
5373+#include <asm-generic/atomic64.h>
5374+#endif
5375+
5376 #define ATOMIC_INIT(i) { (i) }
5377
5378+#ifdef CONFIG_64BIT
5379+#define _ASM_EXTABLE(from, to) \
5380+" .section __ex_table,\"a\"\n" \
5381+" .dword " #from ", " #to"\n" \
5382+" .previous\n"
5383+#else
5384+#define _ASM_EXTABLE(from, to) \
5385+" .section __ex_table,\"a\"\n" \
5386+" .word " #from ", " #to"\n" \
5387+" .previous\n"
5388+#endif
5389+
5390 /*
5391 * atomic_read - read atomic variable
5392 * @v: pointer of type atomic_t
5393 *
5394 * Atomically reads the value of @v.
5395 */
5396-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5397+static inline int atomic_read(const atomic_t *v)
5398+{
5399+ return (*(volatile const int *) &v->counter);
5400+}
5401+
5402+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5403+{
5404+ return (*(volatile const int *) &v->counter);
5405+}
5406
5407 /*
5408 * atomic_set - set atomic variable
5409@@ -38,7 +62,15 @@
5410 *
5411 * Atomically sets the value of @v to @i.
5412 */
5413-#define atomic_set(v, i) ((v)->counter = (i))
5414+static inline void atomic_set(atomic_t *v, int i)
5415+{
5416+ v->counter = i;
5417+}
5418+
5419+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5420+{
5421+ v->counter = i;
5422+}
5423
5424 /*
5425 * atomic_add - add integer to atomic variable
5426@@ -47,7 +79,67 @@
5427 *
5428 * Atomically adds @i to @v.
5429 */
5430-static __inline__ void atomic_add(int i, atomic_t * v)
5431+static __inline__ void atomic_add(int i, atomic_t *v)
5432+{
5433+ int temp;
5434+
5435+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5436+ __asm__ __volatile__(
5437+ " .set mips3 \n"
5438+ "1: ll %0, %1 # atomic_add \n"
5439+#ifdef CONFIG_PAX_REFCOUNT
5440+ /* Exception on overflow. */
5441+ "2: add %0, %2 \n"
5442+#else
5443+ " addu %0, %2 \n"
5444+#endif
5445+ " sc %0, %1 \n"
5446+ " beqzl %0, 1b \n"
5447+#ifdef CONFIG_PAX_REFCOUNT
5448+ "3: \n"
5449+ _ASM_EXTABLE(2b, 3b)
5450+#endif
5451+ " .set mips0 \n"
5452+ : "=&r" (temp), "+m" (v->counter)
5453+ : "Ir" (i));
5454+ } else if (kernel_uses_llsc) {
5455+ __asm__ __volatile__(
5456+ " .set mips3 \n"
5457+ "1: ll %0, %1 # atomic_add \n"
5458+#ifdef CONFIG_PAX_REFCOUNT
5459+ /* Exception on overflow. */
5460+ "2: add %0, %2 \n"
5461+#else
5462+ " addu %0, %2 \n"
5463+#endif
5464+ " sc %0, %1 \n"
5465+ " beqz %0, 1b \n"
5466+#ifdef CONFIG_PAX_REFCOUNT
5467+ "3: \n"
5468+ _ASM_EXTABLE(2b, 3b)
5469+#endif
5470+ " .set mips0 \n"
5471+ : "=&r" (temp), "+m" (v->counter)
5472+ : "Ir" (i));
5473+ } else {
5474+ unsigned long flags;
5475+
5476+ raw_local_irq_save(flags);
5477+ __asm__ __volatile__(
5478+#ifdef CONFIG_PAX_REFCOUNT
5479+ /* Exception on overflow. */
5480+ "1: add %0, %1 \n"
5481+ "2: \n"
5482+ _ASM_EXTABLE(1b, 2b)
5483+#else
5484+ " addu %0, %1 \n"
5485+#endif
5486+ : "+r" (v->counter) : "Ir" (i));
5487+ raw_local_irq_restore(flags);
5488+ }
5489+}
5490+
5491+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5492 {
5493 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5494 int temp;
5495@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5496 *
5497 * Atomically subtracts @i from @v.
5498 */
5499-static __inline__ void atomic_sub(int i, atomic_t * v)
5500+static __inline__ void atomic_sub(int i, atomic_t *v)
5501+{
5502+ int temp;
5503+
5504+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5505+ __asm__ __volatile__(
5506+ " .set mips3 \n"
5507+ "1: ll %0, %1 # atomic64_sub \n"
5508+#ifdef CONFIG_PAX_REFCOUNT
5509+ /* Exception on overflow. */
5510+ "2: sub %0, %2 \n"
5511+#else
5512+ " subu %0, %2 \n"
5513+#endif
5514+ " sc %0, %1 \n"
5515+ " beqzl %0, 1b \n"
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ "3: \n"
5518+ _ASM_EXTABLE(2b, 3b)
5519+#endif
5520+ " .set mips0 \n"
5521+ : "=&r" (temp), "+m" (v->counter)
5522+ : "Ir" (i));
5523+ } else if (kernel_uses_llsc) {
5524+ __asm__ __volatile__(
5525+ " .set mips3 \n"
5526+ "1: ll %0, %1 # atomic64_sub \n"
5527+#ifdef CONFIG_PAX_REFCOUNT
5528+ /* Exception on overflow. */
5529+ "2: sub %0, %2 \n"
5530+#else
5531+ " subu %0, %2 \n"
5532+#endif
5533+ " sc %0, %1 \n"
5534+ " beqz %0, 1b \n"
5535+#ifdef CONFIG_PAX_REFCOUNT
5536+ "3: \n"
5537+ _ASM_EXTABLE(2b, 3b)
5538+#endif
5539+ " .set mips0 \n"
5540+ : "=&r" (temp), "+m" (v->counter)
5541+ : "Ir" (i));
5542+ } else {
5543+ unsigned long flags;
5544+
5545+ raw_local_irq_save(flags);
5546+ __asm__ __volatile__(
5547+#ifdef CONFIG_PAX_REFCOUNT
5548+ /* Exception on overflow. */
5549+ "1: sub %0, %1 \n"
5550+ "2: \n"
5551+ _ASM_EXTABLE(1b, 2b)
5552+#else
5553+ " subu %0, %1 \n"
5554+#endif
5555+ : "+r" (v->counter) : "Ir" (i));
5556+ raw_local_irq_restore(flags);
5557+ }
5558+}
5559+
5560+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5561 {
5562 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5563 int temp;
5564@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5565 /*
5566 * Same as above, but return the result value
5567 */
5568-static __inline__ int atomic_add_return(int i, atomic_t * v)
5569+static __inline__ int atomic_add_return(int i, atomic_t *v)
5570+{
5571+ int result;
5572+ int temp;
5573+
5574+ smp_mb__before_llsc();
5575+
5576+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5577+ __asm__ __volatile__(
5578+ " .set mips3 \n"
5579+ "1: ll %1, %2 # atomic_add_return \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ "2: add %0, %1, %3 \n"
5582+#else
5583+ " addu %0, %1, %3 \n"
5584+#endif
5585+ " sc %0, %2 \n"
5586+ " beqzl %0, 1b \n"
5587+#ifdef CONFIG_PAX_REFCOUNT
5588+ " b 4f \n"
5589+ " .set noreorder \n"
5590+ "3: b 5f \n"
5591+ " move %0, %1 \n"
5592+ " .set reorder \n"
5593+ _ASM_EXTABLE(2b, 3b)
5594+#endif
5595+ "4: addu %0, %1, %3 \n"
5596+#ifdef CONFIG_PAX_REFCOUNT
5597+ "5: \n"
5598+#endif
5599+ " .set mips0 \n"
5600+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5601+ : "Ir" (i));
5602+ } else if (kernel_uses_llsc) {
5603+ __asm__ __volatile__(
5604+ " .set mips3 \n"
5605+ "1: ll %1, %2 # atomic_add_return \n"
5606+#ifdef CONFIG_PAX_REFCOUNT
5607+ "2: add %0, %1, %3 \n"
5608+#else
5609+ " addu %0, %1, %3 \n"
5610+#endif
5611+ " sc %0, %2 \n"
5612+ " bnez %0, 4f \n"
5613+ " b 1b \n"
5614+#ifdef CONFIG_PAX_REFCOUNT
5615+ " .set noreorder \n"
5616+ "3: b 5f \n"
5617+ " move %0, %1 \n"
5618+ " .set reorder \n"
5619+ _ASM_EXTABLE(2b, 3b)
5620+#endif
5621+ "4: addu %0, %1, %3 \n"
5622+#ifdef CONFIG_PAX_REFCOUNT
5623+ "5: \n"
5624+#endif
5625+ " .set mips0 \n"
5626+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5627+ : "Ir" (i));
5628+ } else {
5629+ unsigned long flags;
5630+
5631+ raw_local_irq_save(flags);
5632+ __asm__ __volatile__(
5633+ " lw %0, %1 \n"
5634+#ifdef CONFIG_PAX_REFCOUNT
5635+ /* Exception on overflow. */
5636+ "1: add %0, %2 \n"
5637+#else
5638+ " addu %0, %2 \n"
5639+#endif
5640+ " sw %0, %1 \n"
5641+#ifdef CONFIG_PAX_REFCOUNT
5642+ /* Note: Dest reg is not modified on overflow */
5643+ "2: \n"
5644+ _ASM_EXTABLE(1b, 2b)
5645+#endif
5646+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5647+ raw_local_irq_restore(flags);
5648+ }
5649+
5650+ smp_llsc_mb();
5651+
5652+ return result;
5653+}
5654+
5655+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5656 {
5657 int result;
5658
5659@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5660 return result;
5661 }
5662
5663-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5664+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5665+{
5666+ int result;
5667+ int temp;
5668+
5669+ smp_mb__before_llsc();
5670+
5671+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5672+ __asm__ __volatile__(
5673+ " .set mips3 \n"
5674+ "1: ll %1, %2 # atomic_sub_return \n"
5675+#ifdef CONFIG_PAX_REFCOUNT
5676+ "2: sub %0, %1, %3 \n"
5677+#else
5678+ " subu %0, %1, %3 \n"
5679+#endif
5680+ " sc %0, %2 \n"
5681+ " beqzl %0, 1b \n"
5682+#ifdef CONFIG_PAX_REFCOUNT
5683+ " b 4f \n"
5684+ " .set noreorder \n"
5685+ "3: b 5f \n"
5686+ " move %0, %1 \n"
5687+ " .set reorder \n"
5688+ _ASM_EXTABLE(2b, 3b)
5689+#endif
5690+ "4: subu %0, %1, %3 \n"
5691+#ifdef CONFIG_PAX_REFCOUNT
5692+ "5: \n"
5693+#endif
5694+ " .set mips0 \n"
5695+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5696+ : "Ir" (i), "m" (v->counter)
5697+ : "memory");
5698+ } else if (kernel_uses_llsc) {
5699+ __asm__ __volatile__(
5700+ " .set mips3 \n"
5701+ "1: ll %1, %2 # atomic_sub_return \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ "2: sub %0, %1, %3 \n"
5704+#else
5705+ " subu %0, %1, %3 \n"
5706+#endif
5707+ " sc %0, %2 \n"
5708+ " bnez %0, 4f \n"
5709+ " b 1b \n"
5710+#ifdef CONFIG_PAX_REFCOUNT
5711+ " .set noreorder \n"
5712+ "3: b 5f \n"
5713+ " move %0, %1 \n"
5714+ " .set reorder \n"
5715+ _ASM_EXTABLE(2b, 3b)
5716+#endif
5717+ "4: subu %0, %1, %3 \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ "5: \n"
5720+#endif
5721+ " .set mips0 \n"
5722+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723+ : "Ir" (i));
5724+ } else {
5725+ unsigned long flags;
5726+
5727+ raw_local_irq_save(flags);
5728+ __asm__ __volatile__(
5729+ " lw %0, %1 \n"
5730+#ifdef CONFIG_PAX_REFCOUNT
5731+ /* Exception on overflow. */
5732+ "1: sub %0, %2 \n"
5733+#else
5734+ " subu %0, %2 \n"
5735+#endif
5736+ " sw %0, %1 \n"
5737+#ifdef CONFIG_PAX_REFCOUNT
5738+ /* Note: Dest reg is not modified on overflow */
5739+ "2: \n"
5740+ _ASM_EXTABLE(1b, 2b)
5741+#endif
5742+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5743+ raw_local_irq_restore(flags);
5744+ }
5745+
5746+ smp_llsc_mb();
5747+
5748+ return result;
5749+}
5750+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5751 {
5752 int result;
5753
5754@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5755 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5756 * The function returns the old value of @v minus @i.
5757 */
5758-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5759+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5760 {
5761 int result;
5762
5763@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5764 return result;
5765 }
5766
5767-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5768-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5769+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5770+{
5771+ return cmpxchg(&v->counter, old, new);
5772+}
5773+
5774+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5775+ int new)
5776+{
5777+ return cmpxchg(&(v->counter), old, new);
5778+}
5779+
5780+static inline int atomic_xchg(atomic_t *v, int new)
5781+{
5782+ return xchg(&v->counter, new);
5783+}
5784+
5785+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5786+{
5787+ return xchg(&(v->counter), new);
5788+}
5789
5790 /**
5791 * __atomic_add_unless - add unless the number is a given value
5792@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5793
5794 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5795 #define atomic_inc_return(v) atomic_add_return(1, (v))
5796+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5797+{
5798+ return atomic_add_return_unchecked(1, v);
5799+}
5800
5801 /*
5802 * atomic_sub_and_test - subtract value from variable and test result
5803@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5804 * other cases.
5805 */
5806 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5807+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5808+{
5809+ return atomic_add_return_unchecked(1, v) == 0;
5810+}
5811
5812 /*
5813 * atomic_dec_and_test - decrement by 1 and test
5814@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5815 * Atomically increments @v by 1.
5816 */
5817 #define atomic_inc(v) atomic_add(1, (v))
5818+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5819+{
5820+ atomic_add_unchecked(1, v);
5821+}
5822
5823 /*
5824 * atomic_dec - decrement and test
5825@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5826 * Atomically decrements @v by 1.
5827 */
5828 #define atomic_dec(v) atomic_sub(1, (v))
5829+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5830+{
5831+ atomic_sub_unchecked(1, v);
5832+}
5833
5834 /*
5835 * atomic_add_negative - add and test if negative
5836@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5837 * @v: pointer of type atomic64_t
5838 *
5839 */
5840-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5841+static inline long atomic64_read(const atomic64_t *v)
5842+{
5843+ return (*(volatile const long *) &v->counter);
5844+}
5845+
5846+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5847+{
5848+ return (*(volatile const long *) &v->counter);
5849+}
5850
5851 /*
5852 * atomic64_set - set atomic variable
5853 * @v: pointer of type atomic64_t
5854 * @i: required value
5855 */
5856-#define atomic64_set(v, i) ((v)->counter = (i))
5857+static inline void atomic64_set(atomic64_t *v, long i)
5858+{
5859+ v->counter = i;
5860+}
5861+
5862+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5863+{
5864+ v->counter = i;
5865+}
5866
5867 /*
5868 * atomic64_add - add integer to atomic variable
5869@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5870 *
5871 * Atomically adds @i to @v.
5872 */
5873-static __inline__ void atomic64_add(long i, atomic64_t * v)
5874+static __inline__ void atomic64_add(long i, atomic64_t *v)
5875+{
5876+ long temp;
5877+
5878+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5879+ __asm__ __volatile__(
5880+ " .set mips3 \n"
5881+ "1: lld %0, %1 # atomic64_add \n"
5882+#ifdef CONFIG_PAX_REFCOUNT
5883+ /* Exception on overflow. */
5884+ "2: dadd %0, %2 \n"
5885+#else
5886+ " daddu %0, %2 \n"
5887+#endif
5888+ " scd %0, %1 \n"
5889+ " beqzl %0, 1b \n"
5890+#ifdef CONFIG_PAX_REFCOUNT
5891+ "3: \n"
5892+ _ASM_EXTABLE(2b, 3b)
5893+#endif
5894+ " .set mips0 \n"
5895+ : "=&r" (temp), "+m" (v->counter)
5896+ : "Ir" (i));
5897+ } else if (kernel_uses_llsc) {
5898+ __asm__ __volatile__(
5899+ " .set mips3 \n"
5900+ "1: lld %0, %1 # atomic64_add \n"
5901+#ifdef CONFIG_PAX_REFCOUNT
5902+ /* Exception on overflow. */
5903+ "2: dadd %0, %2 \n"
5904+#else
5905+ " daddu %0, %2 \n"
5906+#endif
5907+ " scd %0, %1 \n"
5908+ " beqz %0, 1b \n"
5909+#ifdef CONFIG_PAX_REFCOUNT
5910+ "3: \n"
5911+ _ASM_EXTABLE(2b, 3b)
5912+#endif
5913+ " .set mips0 \n"
5914+ : "=&r" (temp), "+m" (v->counter)
5915+ : "Ir" (i));
5916+ } else {
5917+ unsigned long flags;
5918+
5919+ raw_local_irq_save(flags);
5920+ __asm__ __volatile__(
5921+#ifdef CONFIG_PAX_REFCOUNT
5922+ /* Exception on overflow. */
5923+ "1: dadd %0, %1 \n"
5924+ "2: \n"
5925+ _ASM_EXTABLE(1b, 2b)
5926+#else
5927+ " daddu %0, %1 \n"
5928+#endif
5929+ : "+r" (v->counter) : "Ir" (i));
5930+ raw_local_irq_restore(flags);
5931+ }
5932+}
5933+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5934 {
5935 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5936 long temp;
5937@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5938 *
5939 * Atomically subtracts @i from @v.
5940 */
5941-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5942+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5943+{
5944+ long temp;
5945+
5946+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5947+ __asm__ __volatile__(
5948+ " .set mips3 \n"
5949+ "1: lld %0, %1 # atomic64_sub \n"
5950+#ifdef CONFIG_PAX_REFCOUNT
5951+ /* Exception on overflow. */
5952+ "2: dsub %0, %2 \n"
5953+#else
5954+ " dsubu %0, %2 \n"
5955+#endif
5956+ " scd %0, %1 \n"
5957+ " beqzl %0, 1b \n"
5958+#ifdef CONFIG_PAX_REFCOUNT
5959+ "3: \n"
5960+ _ASM_EXTABLE(2b, 3b)
5961+#endif
5962+ " .set mips0 \n"
5963+ : "=&r" (temp), "+m" (v->counter)
5964+ : "Ir" (i));
5965+ } else if (kernel_uses_llsc) {
5966+ __asm__ __volatile__(
5967+ " .set mips3 \n"
5968+ "1: lld %0, %1 # atomic64_sub \n"
5969+#ifdef CONFIG_PAX_REFCOUNT
5970+ /* Exception on overflow. */
5971+ "2: dsub %0, %2 \n"
5972+#else
5973+ " dsubu %0, %2 \n"
5974+#endif
5975+ " scd %0, %1 \n"
5976+ " beqz %0, 1b \n"
5977+#ifdef CONFIG_PAX_REFCOUNT
5978+ "3: \n"
5979+ _ASM_EXTABLE(2b, 3b)
5980+#endif
5981+ " .set mips0 \n"
5982+ : "=&r" (temp), "+m" (v->counter)
5983+ : "Ir" (i));
5984+ } else {
5985+ unsigned long flags;
5986+
5987+ raw_local_irq_save(flags);
5988+ __asm__ __volatile__(
5989+#ifdef CONFIG_PAX_REFCOUNT
5990+ /* Exception on overflow. */
5991+ "1: dsub %0, %1 \n"
5992+ "2: \n"
5993+ _ASM_EXTABLE(1b, 2b)
5994+#else
5995+ " dsubu %0, %1 \n"
5996+#endif
5997+ : "+r" (v->counter) : "Ir" (i));
5998+ raw_local_irq_restore(flags);
5999+ }
6000+}
6001+
6002+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6003 {
6004 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6005 long temp;
6006@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6007 /*
6008 * Same as above, but return the result value
6009 */
6010-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6011+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6012+{
6013+ long result;
6014+ long temp;
6015+
6016+ smp_mb__before_llsc();
6017+
6018+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6019+ __asm__ __volatile__(
6020+ " .set mips3 \n"
6021+ "1: lld %1, %2 # atomic64_add_return \n"
6022+#ifdef CONFIG_PAX_REFCOUNT
6023+ "2: dadd %0, %1, %3 \n"
6024+#else
6025+ " daddu %0, %1, %3 \n"
6026+#endif
6027+ " scd %0, %2 \n"
6028+ " beqzl %0, 1b \n"
6029+#ifdef CONFIG_PAX_REFCOUNT
6030+ " b 4f \n"
6031+ " .set noreorder \n"
6032+ "3: b 5f \n"
6033+ " move %0, %1 \n"
6034+ " .set reorder \n"
6035+ _ASM_EXTABLE(2b, 3b)
6036+#endif
6037+ "4: daddu %0, %1, %3 \n"
6038+#ifdef CONFIG_PAX_REFCOUNT
6039+ "5: \n"
6040+#endif
6041+ " .set mips0 \n"
6042+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6043+ : "Ir" (i));
6044+ } else if (kernel_uses_llsc) {
6045+ __asm__ __volatile__(
6046+ " .set mips3 \n"
6047+ "1: lld %1, %2 # atomic64_add_return \n"
6048+#ifdef CONFIG_PAX_REFCOUNT
6049+ "2: dadd %0, %1, %3 \n"
6050+#else
6051+ " daddu %0, %1, %3 \n"
6052+#endif
6053+ " scd %0, %2 \n"
6054+ " bnez %0, 4f \n"
6055+ " b 1b \n"
6056+#ifdef CONFIG_PAX_REFCOUNT
6057+ " .set noreorder \n"
6058+ "3: b 5f \n"
6059+ " move %0, %1 \n"
6060+ " .set reorder \n"
6061+ _ASM_EXTABLE(2b, 3b)
6062+#endif
6063+ "4: daddu %0, %1, %3 \n"
6064+#ifdef CONFIG_PAX_REFCOUNT
6065+ "5: \n"
6066+#endif
6067+ " .set mips0 \n"
6068+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6069+ : "Ir" (i), "m" (v->counter)
6070+ : "memory");
6071+ } else {
6072+ unsigned long flags;
6073+
6074+ raw_local_irq_save(flags);
6075+ __asm__ __volatile__(
6076+ " ld %0, %1 \n"
6077+#ifdef CONFIG_PAX_REFCOUNT
6078+ /* Exception on overflow. */
6079+ "1: dadd %0, %2 \n"
6080+#else
6081+ " daddu %0, %2 \n"
6082+#endif
6083+ " sd %0, %1 \n"
6084+#ifdef CONFIG_PAX_REFCOUNT
6085+ /* Note: Dest reg is not modified on overflow */
6086+ "2: \n"
6087+ _ASM_EXTABLE(1b, 2b)
6088+#endif
6089+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6090+ raw_local_irq_restore(flags);
6091+ }
6092+
6093+ smp_llsc_mb();
6094+
6095+ return result;
6096+}
6097+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6098 {
6099 long result;
6100
6101@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6102 return result;
6103 }
6104
6105-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6106+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6107+{
6108+ long result;
6109+ long temp;
6110+
6111+ smp_mb__before_llsc();
6112+
6113+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6114+ long temp;
6115+
6116+ __asm__ __volatile__(
6117+ " .set mips3 \n"
6118+ "1: lld %1, %2 # atomic64_sub_return \n"
6119+#ifdef CONFIG_PAX_REFCOUNT
6120+ "2: dsub %0, %1, %3 \n"
6121+#else
6122+ " dsubu %0, %1, %3 \n"
6123+#endif
6124+ " scd %0, %2 \n"
6125+ " beqzl %0, 1b \n"
6126+#ifdef CONFIG_PAX_REFCOUNT
6127+ " b 4f \n"
6128+ " .set noreorder \n"
6129+ "3: b 5f \n"
6130+ " move %0, %1 \n"
6131+ " .set reorder \n"
6132+ _ASM_EXTABLE(2b, 3b)
6133+#endif
6134+ "4: dsubu %0, %1, %3 \n"
6135+#ifdef CONFIG_PAX_REFCOUNT
6136+ "5: \n"
6137+#endif
6138+ " .set mips0 \n"
6139+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6140+ : "Ir" (i), "m" (v->counter)
6141+ : "memory");
6142+ } else if (kernel_uses_llsc) {
6143+ __asm__ __volatile__(
6144+ " .set mips3 \n"
6145+ "1: lld %1, %2 # atomic64_sub_return \n"
6146+#ifdef CONFIG_PAX_REFCOUNT
6147+ "2: dsub %0, %1, %3 \n"
6148+#else
6149+ " dsubu %0, %1, %3 \n"
6150+#endif
6151+ " scd %0, %2 \n"
6152+ " bnez %0, 4f \n"
6153+ " b 1b \n"
6154+#ifdef CONFIG_PAX_REFCOUNT
6155+ " .set noreorder \n"
6156+ "3: b 5f \n"
6157+ " move %0, %1 \n"
6158+ " .set reorder \n"
6159+ _ASM_EXTABLE(2b, 3b)
6160+#endif
6161+ "4: dsubu %0, %1, %3 \n"
6162+#ifdef CONFIG_PAX_REFCOUNT
6163+ "5: \n"
6164+#endif
6165+ " .set mips0 \n"
6166+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6167+ : "Ir" (i), "m" (v->counter)
6168+ : "memory");
6169+ } else {
6170+ unsigned long flags;
6171+
6172+ raw_local_irq_save(flags);
6173+ __asm__ __volatile__(
6174+ " ld %0, %1 \n"
6175+#ifdef CONFIG_PAX_REFCOUNT
6176+ /* Exception on overflow. */
6177+ "1: dsub %0, %2 \n"
6178+#else
6179+ " dsubu %0, %2 \n"
6180+#endif
6181+ " sd %0, %1 \n"
6182+#ifdef CONFIG_PAX_REFCOUNT
6183+ /* Note: Dest reg is not modified on overflow */
6184+ "2: \n"
6185+ _ASM_EXTABLE(1b, 2b)
6186+#endif
6187+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6188+ raw_local_irq_restore(flags);
6189+ }
6190+
6191+ smp_llsc_mb();
6192+
6193+ return result;
6194+}
6195+
6196+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6197 {
6198 long result;
6199
6200@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6201 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6202 * The function returns the old value of @v minus @i.
6203 */
6204-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6205+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6206 {
6207 long result;
6208
6209@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6210 return result;
6211 }
6212
6213-#define atomic64_cmpxchg(v, o, n) \
6214- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6215-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6216+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6217+{
6218+ return cmpxchg(&v->counter, old, new);
6219+}
6220+
6221+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6222+ long new)
6223+{
6224+ return cmpxchg(&(v->counter), old, new);
6225+}
6226+
6227+static inline long atomic64_xchg(atomic64_t *v, long new)
6228+{
6229+ return xchg(&v->counter, new);
6230+}
6231+
6232+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6233+{
6234+ return xchg(&(v->counter), new);
6235+}
6236
6237 /**
6238 * atomic64_add_unless - add unless the number is a given value
6239@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6240
6241 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6242 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6243+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6244
6245 /*
6246 * atomic64_sub_and_test - subtract value from variable and test result
6247@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6248 * other cases.
6249 */
6250 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6251+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6252
6253 /*
6254 * atomic64_dec_and_test - decrement by 1 and test
6255@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6256 * Atomically increments @v by 1.
6257 */
6258 #define atomic64_inc(v) atomic64_add(1, (v))
6259+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6260
6261 /*
6262 * atomic64_dec - decrement and test
6263@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6264 * Atomically decrements @v by 1.
6265 */
6266 #define atomic64_dec(v) atomic64_sub(1, (v))
6267+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6268
6269 /*
6270 * atomic64_add_negative - add and test if negative
6271diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6272index b4db69f..8f3b093 100644
6273--- a/arch/mips/include/asm/cache.h
6274+++ b/arch/mips/include/asm/cache.h
6275@@ -9,10 +9,11 @@
6276 #ifndef _ASM_CACHE_H
6277 #define _ASM_CACHE_H
6278
6279+#include <linux/const.h>
6280 #include <kmalloc.h>
6281
6282 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6283-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6284+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6285
6286 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6287 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6288diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6289index cf3ae24..238d22f 100644
6290--- a/arch/mips/include/asm/elf.h
6291+++ b/arch/mips/include/asm/elf.h
6292@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6293 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6294 #endif
6295
6296+#ifdef CONFIG_PAX_ASLR
6297+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6298+
6299+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6300+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6301+#endif
6302+
6303 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6304 struct linux_binprm;
6305 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6306 int uses_interp);
6307
6308-struct mm_struct;
6309-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6310-#define arch_randomize_brk arch_randomize_brk
6311-
6312 #endif /* _ASM_ELF_H */
6313diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6314index c1f6afa..38cc6e9 100644
6315--- a/arch/mips/include/asm/exec.h
6316+++ b/arch/mips/include/asm/exec.h
6317@@ -12,6 +12,6 @@
6318 #ifndef _ASM_EXEC_H
6319 #define _ASM_EXEC_H
6320
6321-extern unsigned long arch_align_stack(unsigned long sp);
6322+#define arch_align_stack(x) ((x) & ~0xfUL)
6323
6324 #endif /* _ASM_EXEC_H */
6325diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6326index d44622c..64990d2 100644
6327--- a/arch/mips/include/asm/local.h
6328+++ b/arch/mips/include/asm/local.h
6329@@ -12,15 +12,25 @@ typedef struct
6330 atomic_long_t a;
6331 } local_t;
6332
6333+typedef struct {
6334+ atomic_long_unchecked_t a;
6335+} local_unchecked_t;
6336+
6337 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6338
6339 #define local_read(l) atomic_long_read(&(l)->a)
6340+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6341 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6342+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6343
6344 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6345+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6346 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6347+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6348 #define local_inc(l) atomic_long_inc(&(l)->a)
6349+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6350 #define local_dec(l) atomic_long_dec(&(l)->a)
6351+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6352
6353 /*
6354 * Same as above, but return the result value
6355@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6356 return result;
6357 }
6358
6359+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6360+{
6361+ unsigned long result;
6362+
6363+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6364+ unsigned long temp;
6365+
6366+ __asm__ __volatile__(
6367+ " .set mips3 \n"
6368+ "1:" __LL "%1, %2 # local_add_return \n"
6369+ " addu %0, %1, %3 \n"
6370+ __SC "%0, %2 \n"
6371+ " beqzl %0, 1b \n"
6372+ " addu %0, %1, %3 \n"
6373+ " .set mips0 \n"
6374+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6375+ : "Ir" (i), "m" (l->a.counter)
6376+ : "memory");
6377+ } else if (kernel_uses_llsc) {
6378+ unsigned long temp;
6379+
6380+ __asm__ __volatile__(
6381+ " .set mips3 \n"
6382+ "1:" __LL "%1, %2 # local_add_return \n"
6383+ " addu %0, %1, %3 \n"
6384+ __SC "%0, %2 \n"
6385+ " beqz %0, 1b \n"
6386+ " addu %0, %1, %3 \n"
6387+ " .set mips0 \n"
6388+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6389+ : "Ir" (i), "m" (l->a.counter)
6390+ : "memory");
6391+ } else {
6392+ unsigned long flags;
6393+
6394+ local_irq_save(flags);
6395+ result = l->a.counter;
6396+ result += i;
6397+ l->a.counter = result;
6398+ local_irq_restore(flags);
6399+ }
6400+
6401+ return result;
6402+}
6403+
6404 static __inline__ long local_sub_return(long i, local_t * l)
6405 {
6406 unsigned long result;
6407@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6408
6409 #define local_cmpxchg(l, o, n) \
6410 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6411+#define local_cmpxchg_unchecked(l, o, n) \
6412+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6413 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6414
6415 /**
6416diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6417index f6be474..12ad554 100644
6418--- a/arch/mips/include/asm/page.h
6419+++ b/arch/mips/include/asm/page.h
6420@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6421 #ifdef CONFIG_CPU_MIPS32
6422 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6423 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6424- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6425+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6426 #else
6427 typedef struct { unsigned long long pte; } pte_t;
6428 #define pte_val(x) ((x).pte)
6429diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6430index 881d18b..cea38bc 100644
6431--- a/arch/mips/include/asm/pgalloc.h
6432+++ b/arch/mips/include/asm/pgalloc.h
6433@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6434 {
6435 set_pud(pud, __pud((unsigned long)pmd));
6436 }
6437+
6438+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6439+{
6440+ pud_populate(mm, pud, pmd);
6441+}
6442 #endif
6443
6444 /*
6445diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6446index 25da651..ae2a259 100644
6447--- a/arch/mips/include/asm/smtc_proc.h
6448+++ b/arch/mips/include/asm/smtc_proc.h
6449@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6450
6451 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6452
6453-extern atomic_t smtc_fpu_recoveries;
6454+extern atomic_unchecked_t smtc_fpu_recoveries;
6455
6456 #endif /* __ASM_SMTC_PROC_H */
6457diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6458index 61215a3..213ee0e 100644
6459--- a/arch/mips/include/asm/thread_info.h
6460+++ b/arch/mips/include/asm/thread_info.h
6461@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6462 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6463 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6464 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6465+/* li takes a 32bit immediate */
6466+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6467 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6468
6469 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6470@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6471 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6472 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6473 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6474+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6475
6476-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6477- _TIF_SYSCALL_AUDIT)
6478+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6479
6480 /* work to do in syscall_trace_leave() */
6481-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6482- _TIF_SYSCALL_AUDIT)
6483+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6484
6485 /* work to do on interrupt/exception return */
6486 #define _TIF_WORK_MASK \
6487 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6488 /* work to do on any return to u-space */
6489-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6490- _TIF_WORK_SYSCALL_EXIT)
6491+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6492
6493 #endif /* __KERNEL__ */
6494
6495diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6496index 1188e00..41cf144 100644
6497--- a/arch/mips/kernel/binfmt_elfn32.c
6498+++ b/arch/mips/kernel/binfmt_elfn32.c
6499@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6500 #undef ELF_ET_DYN_BASE
6501 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6502
6503+#ifdef CONFIG_PAX_ASLR
6504+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6505+
6506+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6507+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6508+#endif
6509+
6510 #include <asm/processor.h>
6511 #include <linux/module.h>
6512 #include <linux/elfcore.h>
6513diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6514index 202e581..689ca79 100644
6515--- a/arch/mips/kernel/binfmt_elfo32.c
6516+++ b/arch/mips/kernel/binfmt_elfo32.c
6517@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6518 #undef ELF_ET_DYN_BASE
6519 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6520
6521+#ifdef CONFIG_PAX_ASLR
6522+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6523+
6524+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6525+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6526+#endif
6527+
6528 #include <asm/processor.h>
6529
6530 /*
6531diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6532index d1fea7a..45602ea 100644
6533--- a/arch/mips/kernel/irq.c
6534+++ b/arch/mips/kernel/irq.c
6535@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6536 printk("unexpected IRQ # %d\n", irq);
6537 }
6538
6539-atomic_t irq_err_count;
6540+atomic_unchecked_t irq_err_count;
6541
6542 int arch_show_interrupts(struct seq_file *p, int prec)
6543 {
6544- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6545+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6546 return 0;
6547 }
6548
6549 asmlinkage void spurious_interrupt(void)
6550 {
6551- atomic_inc(&irq_err_count);
6552+ atomic_inc_unchecked(&irq_err_count);
6553 }
6554
6555 void __init init_IRQ(void)
6556diff --git a/arch/mips/kernel/octeon_switch.S b/arch/mips/kernel/octeon_switch.S
6557index 4204d76..029e002 100644
6558--- a/arch/mips/kernel/octeon_switch.S
6559+++ b/arch/mips/kernel/octeon_switch.S
6560@@ -73,7 +73,7 @@
6561 3:
6562
6563 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
6564- PTR_L t8, __stack_chk_guard
6565+ PTR_LA t8, __stack_chk_guard
6566 LONG_L t9, TASK_STACK_CANARY(a1)
6567 LONG_S t9, 0(t8)
6568 #endif
6569diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6570index ddc7610..8c58f17 100644
6571--- a/arch/mips/kernel/process.c
6572+++ b/arch/mips/kernel/process.c
6573@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6574 out:
6575 return pc;
6576 }
6577-
6578-/*
6579- * Don't forget that the stack pointer must be aligned on a 8 bytes
6580- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6581- */
6582-unsigned long arch_align_stack(unsigned long sp)
6583-{
6584- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6585- sp -= get_random_int() & ~PAGE_MASK;
6586-
6587- return sp & ALMASK;
6588-}
6589diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6590index 8ae1ebe..1bcbf47 100644
6591--- a/arch/mips/kernel/ptrace.c
6592+++ b/arch/mips/kernel/ptrace.c
6593@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6594 return arch;
6595 }
6596
6597+#ifdef CONFIG_GRKERNSEC_SETXID
6598+extern void gr_delayed_cred_worker(void);
6599+#endif
6600+
6601 /*
6602 * Notification of system call entry/exit
6603 * - triggered by current->work.syscall_trace
6604@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6605 /* do the secure computing check first */
6606 secure_computing_strict(regs->regs[2]);
6607
6608+#ifdef CONFIG_GRKERNSEC_SETXID
6609+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6610+ gr_delayed_cred_worker();
6611+#endif
6612+
6613 if (!(current->ptrace & PT_PTRACED))
6614 goto out;
6615
6616diff --git a/arch/mips/kernel/r2300_switch.S b/arch/mips/kernel/r2300_switch.S
6617index 38af83f..20b7b04 100644
6618--- a/arch/mips/kernel/r2300_switch.S
6619+++ b/arch/mips/kernel/r2300_switch.S
6620@@ -67,7 +67,7 @@ LEAF(resume)
6621 1:
6622
6623 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
6624- PTR_L t8, __stack_chk_guard
6625+ PTR_LA t8, __stack_chk_guard
6626 LONG_L t9, TASK_STACK_CANARY(a1)
6627 LONG_S t9, 0(t8)
6628 #endif
6629diff --git a/arch/mips/kernel/r4k_switch.S b/arch/mips/kernel/r4k_switch.S
6630index 921238a..078de5e 100644
6631--- a/arch/mips/kernel/r4k_switch.S
6632+++ b/arch/mips/kernel/r4k_switch.S
6633@@ -69,7 +69,7 @@
6634 1:
6635
6636 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
6637- PTR_L t8, __stack_chk_guard
6638+ PTR_LA t8, __stack_chk_guard
6639 LONG_L t9, TASK_STACK_CANARY(a1)
6640 LONG_S t9, 0(t8)
6641 #endif
6642diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6643index c10aa84..9ec2e60 100644
6644--- a/arch/mips/kernel/smtc-proc.c
6645+++ b/arch/mips/kernel/smtc-proc.c
6646@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6647
6648 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6649
6650-atomic_t smtc_fpu_recoveries;
6651+atomic_unchecked_t smtc_fpu_recoveries;
6652
6653 static int smtc_proc_show(struct seq_file *m, void *v)
6654 {
6655@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6656 for(i = 0; i < NR_CPUS; i++)
6657 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6658 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6659- atomic_read(&smtc_fpu_recoveries));
6660+ atomic_read_unchecked(&smtc_fpu_recoveries));
6661 return 0;
6662 }
6663
6664@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6665 smtc_cpu_stats[i].selfipis = 0;
6666 }
6667
6668- atomic_set(&smtc_fpu_recoveries, 0);
6669+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6670
6671 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6672 }
6673diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6674index dfc1b91..11a2c07 100644
6675--- a/arch/mips/kernel/smtc.c
6676+++ b/arch/mips/kernel/smtc.c
6677@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6678 }
6679 smtc_ipi_qdump();
6680 printk("%d Recoveries of \"stolen\" FPU\n",
6681- atomic_read(&smtc_fpu_recoveries));
6682+ atomic_read_unchecked(&smtc_fpu_recoveries));
6683 }
6684
6685
6686diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6687index 84536bf..79caa4d 100644
6688--- a/arch/mips/kernel/sync-r4k.c
6689+++ b/arch/mips/kernel/sync-r4k.c
6690@@ -21,8 +21,8 @@
6691 #include <asm/mipsregs.h>
6692
6693 static atomic_t count_start_flag = ATOMIC_INIT(0);
6694-static atomic_t count_count_start = ATOMIC_INIT(0);
6695-static atomic_t count_count_stop = ATOMIC_INIT(0);
6696+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6697+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6698 static atomic_t count_reference = ATOMIC_INIT(0);
6699
6700 #define COUNTON 100
6701@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6702
6703 for (i = 0; i < NR_LOOPS; i++) {
6704 /* slaves loop on '!= 2' */
6705- while (atomic_read(&count_count_start) != 1)
6706+ while (atomic_read_unchecked(&count_count_start) != 1)
6707 mb();
6708- atomic_set(&count_count_stop, 0);
6709+ atomic_set_unchecked(&count_count_stop, 0);
6710 smp_wmb();
6711
6712 /* this lets the slaves write their count register */
6713- atomic_inc(&count_count_start);
6714+ atomic_inc_unchecked(&count_count_start);
6715
6716 /*
6717 * Everyone initialises count in the last loop:
6718@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6719 /*
6720 * Wait for all slaves to leave the synchronization point:
6721 */
6722- while (atomic_read(&count_count_stop) != 1)
6723+ while (atomic_read_unchecked(&count_count_stop) != 1)
6724 mb();
6725- atomic_set(&count_count_start, 0);
6726+ atomic_set_unchecked(&count_count_start, 0);
6727 smp_wmb();
6728- atomic_inc(&count_count_stop);
6729+ atomic_inc_unchecked(&count_count_stop);
6730 }
6731 /* Arrange for an interrupt in a short while */
6732 write_c0_compare(read_c0_count() + COUNTON);
6733@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6734 initcount = atomic_read(&count_reference);
6735
6736 for (i = 0; i < NR_LOOPS; i++) {
6737- atomic_inc(&count_count_start);
6738- while (atomic_read(&count_count_start) != 2)
6739+ atomic_inc_unchecked(&count_count_start);
6740+ while (atomic_read_unchecked(&count_count_start) != 2)
6741 mb();
6742
6743 /*
6744@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6745 if (i == NR_LOOPS-1)
6746 write_c0_count(initcount);
6747
6748- atomic_inc(&count_count_stop);
6749- while (atomic_read(&count_count_stop) != 2)
6750+ atomic_inc_unchecked(&count_count_stop);
6751+ while (atomic_read_unchecked(&count_count_stop) != 2)
6752 mb();
6753 }
6754 /* Arrange for an interrupt in a short while */
6755diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6756index aec3408..74d79d3 100644
6757--- a/arch/mips/kernel/traps.c
6758+++ b/arch/mips/kernel/traps.c
6759@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6760 siginfo_t info;
6761
6762 prev_state = exception_enter();
6763- die_if_kernel("Integer overflow", regs);
6764+ if (unlikely(!user_mode(regs))) {
6765+
6766+#ifdef CONFIG_PAX_REFCOUNT
6767+ if (fixup_exception(regs)) {
6768+ pax_report_refcount_overflow(regs);
6769+ exception_exit(prev_state);
6770+ return;
6771+ }
6772+#endif
6773+
6774+ die("Integer overflow", regs);
6775+ }
6776
6777 info.si_code = FPE_INTOVF;
6778 info.si_signo = SIGFPE;
6779diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6780index 85df1cd..4f0a4de 100644
6781--- a/arch/mips/mm/fault.c
6782+++ b/arch/mips/mm/fault.c
6783@@ -28,6 +28,23 @@
6784 #include <asm/highmem.h> /* For VMALLOC_END */
6785 #include <linux/kdebug.h>
6786
6787+#ifdef CONFIG_PAX_PAGEEXEC
6788+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6789+{
6790+ unsigned long i;
6791+
6792+ printk(KERN_ERR "PAX: bytes at PC: ");
6793+ for (i = 0; i < 5; i++) {
6794+ unsigned int c;
6795+ if (get_user(c, (unsigned int *)pc+i))
6796+ printk(KERN_CONT "???????? ");
6797+ else
6798+ printk(KERN_CONT "%08x ", c);
6799+ }
6800+ printk("\n");
6801+}
6802+#endif
6803+
6804 /*
6805 * This routine handles page faults. It determines the address,
6806 * and the problem, and then passes it off to one of the appropriate
6807@@ -197,6 +214,14 @@ bad_area:
6808 bad_area_nosemaphore:
6809 /* User mode accesses just cause a SIGSEGV */
6810 if (user_mode(regs)) {
6811+
6812+#ifdef CONFIG_PAX_PAGEEXEC
6813+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6814+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6815+ do_group_exit(SIGKILL);
6816+ }
6817+#endif
6818+
6819 tsk->thread.cp0_badvaddr = address;
6820 tsk->thread.error_code = write;
6821 #if 0
6822diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6823index f1baadd..8537544 100644
6824--- a/arch/mips/mm/mmap.c
6825+++ b/arch/mips/mm/mmap.c
6826@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6827 struct vm_area_struct *vma;
6828 unsigned long addr = addr0;
6829 int do_color_align;
6830+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6831 struct vm_unmapped_area_info info;
6832
6833 if (unlikely(len > TASK_SIZE))
6834@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6835 do_color_align = 1;
6836
6837 /* requesting a specific address */
6838+
6839+#ifdef CONFIG_PAX_RANDMMAP
6840+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6841+#endif
6842+
6843 if (addr) {
6844 if (do_color_align)
6845 addr = COLOUR_ALIGN(addr, pgoff);
6846@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6847 addr = PAGE_ALIGN(addr);
6848
6849 vma = find_vma(mm, addr);
6850- if (TASK_SIZE - len >= addr &&
6851- (!vma || addr + len <= vma->vm_start))
6852+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6853 return addr;
6854 }
6855
6856 info.length = len;
6857 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6858 info.align_offset = pgoff << PAGE_SHIFT;
6859+ info.threadstack_offset = offset;
6860
6861 if (dir == DOWN) {
6862 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6863@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6864 {
6865 unsigned long random_factor = 0UL;
6866
6867+#ifdef CONFIG_PAX_RANDMMAP
6868+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6869+#endif
6870+
6871 if (current->flags & PF_RANDOMIZE) {
6872 random_factor = get_random_int();
6873 random_factor = random_factor << PAGE_SHIFT;
6874@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6875
6876 if (mmap_is_legacy()) {
6877 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6878+
6879+#ifdef CONFIG_PAX_RANDMMAP
6880+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6881+ mm->mmap_base += mm->delta_mmap;
6882+#endif
6883+
6884 mm->get_unmapped_area = arch_get_unmapped_area;
6885 } else {
6886 mm->mmap_base = mmap_base(random_factor);
6887+
6888+#ifdef CONFIG_PAX_RANDMMAP
6889+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6890+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6891+#endif
6892+
6893 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6894 }
6895 }
6896
6897-static inline unsigned long brk_rnd(void)
6898-{
6899- unsigned long rnd = get_random_int();
6900-
6901- rnd = rnd << PAGE_SHIFT;
6902- /* 8MB for 32bit, 256MB for 64bit */
6903- if (TASK_IS_32BIT_ADDR)
6904- rnd = rnd & 0x7ffffful;
6905- else
6906- rnd = rnd & 0xffffffful;
6907-
6908- return rnd;
6909-}
6910-
6911-unsigned long arch_randomize_brk(struct mm_struct *mm)
6912-{
6913- unsigned long base = mm->brk;
6914- unsigned long ret;
6915-
6916- ret = PAGE_ALIGN(base + brk_rnd());
6917-
6918- if (ret < mm->brk)
6919- return mm->brk;
6920-
6921- return ret;
6922-}
6923-
6924 int __virt_addr_valid(const volatile void *kaddr)
6925 {
6926 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6927diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6928index a2358b4..7cead4f 100644
6929--- a/arch/mips/sgi-ip27/ip27-nmi.c
6930+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6931@@ -187,9 +187,9 @@ void
6932 cont_nmi_dump(void)
6933 {
6934 #ifndef REAL_NMI_SIGNAL
6935- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6936+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6937
6938- atomic_inc(&nmied_cpus);
6939+ atomic_inc_unchecked(&nmied_cpus);
6940 #endif
6941 /*
6942 * Only allow 1 cpu to proceed
6943@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6944 udelay(10000);
6945 }
6946 #else
6947- while (atomic_read(&nmied_cpus) != num_online_cpus());
6948+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6949 #endif
6950
6951 /*
6952diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6953index 967d144..db12197 100644
6954--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6955+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6956@@ -11,12 +11,14 @@
6957 #ifndef _ASM_PROC_CACHE_H
6958 #define _ASM_PROC_CACHE_H
6959
6960+#include <linux/const.h>
6961+
6962 /* L1 cache */
6963
6964 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6965 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6966-#define L1_CACHE_BYTES 16 /* bytes per entry */
6967 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6968+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6969 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6970
6971 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6972diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6973index bcb5df2..84fabd2 100644
6974--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6975+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6976@@ -16,13 +16,15 @@
6977 #ifndef _ASM_PROC_CACHE_H
6978 #define _ASM_PROC_CACHE_H
6979
6980+#include <linux/const.h>
6981+
6982 /*
6983 * L1 cache
6984 */
6985 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6986 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6987-#define L1_CACHE_BYTES 32 /* bytes per entry */
6988 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6989+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6990 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6991
6992 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6993diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6994index 4ce7a01..449202a 100644
6995--- a/arch/openrisc/include/asm/cache.h
6996+++ b/arch/openrisc/include/asm/cache.h
6997@@ -19,11 +19,13 @@
6998 #ifndef __ASM_OPENRISC_CACHE_H
6999 #define __ASM_OPENRISC_CACHE_H
7000
7001+#include <linux/const.h>
7002+
7003 /* FIXME: How can we replace these with values from the CPU...
7004 * they shouldn't be hard-coded!
7005 */
7006
7007-#define L1_CACHE_BYTES 16
7008 #define L1_CACHE_SHIFT 4
7009+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7010
7011 #endif /* __ASM_OPENRISC_CACHE_H */
7012diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7013index 472886c..00e7df9 100644
7014--- a/arch/parisc/include/asm/atomic.h
7015+++ b/arch/parisc/include/asm/atomic.h
7016@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7017 return dec;
7018 }
7019
7020+#define atomic64_read_unchecked(v) atomic64_read(v)
7021+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7022+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7023+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7024+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7025+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7026+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7027+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7028+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7029+
7030 #endif /* !CONFIG_64BIT */
7031
7032
7033diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7034index 47f11c7..3420df2 100644
7035--- a/arch/parisc/include/asm/cache.h
7036+++ b/arch/parisc/include/asm/cache.h
7037@@ -5,6 +5,7 @@
7038 #ifndef __ARCH_PARISC_CACHE_H
7039 #define __ARCH_PARISC_CACHE_H
7040
7041+#include <linux/const.h>
7042
7043 /*
7044 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7045@@ -15,13 +16,13 @@
7046 * just ruin performance.
7047 */
7048 #ifdef CONFIG_PA20
7049-#define L1_CACHE_BYTES 64
7050 #define L1_CACHE_SHIFT 6
7051 #else
7052-#define L1_CACHE_BYTES 32
7053 #define L1_CACHE_SHIFT 5
7054 #endif
7055
7056+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7057+
7058 #ifndef __ASSEMBLY__
7059
7060 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7061diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7062index ad2b503..bdf1651 100644
7063--- a/arch/parisc/include/asm/elf.h
7064+++ b/arch/parisc/include/asm/elf.h
7065@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7066
7067 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7068
7069+#ifdef CONFIG_PAX_ASLR
7070+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7071+
7072+#define PAX_DELTA_MMAP_LEN 16
7073+#define PAX_DELTA_STACK_LEN 16
7074+#endif
7075+
7076 /* This yields a mask that user programs can use to figure out what
7077 instruction set this CPU supports. This could be done in user space,
7078 but it's not easy, and we've already done it here. */
7079diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7080index fc987a1..6e068ef 100644
7081--- a/arch/parisc/include/asm/pgalloc.h
7082+++ b/arch/parisc/include/asm/pgalloc.h
7083@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7084 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7085 }
7086
7087+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7088+{
7089+ pgd_populate(mm, pgd, pmd);
7090+}
7091+
7092 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7093 {
7094 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7095@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7096 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7097 #define pmd_free(mm, x) do { } while (0)
7098 #define pgd_populate(mm, pmd, pte) BUG()
7099+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7100
7101 #endif
7102
7103diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7104index 34899b5..02dd060 100644
7105--- a/arch/parisc/include/asm/pgtable.h
7106+++ b/arch/parisc/include/asm/pgtable.h
7107@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7108 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7109 #define PAGE_COPY PAGE_EXECREAD
7110 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7111+
7112+#ifdef CONFIG_PAX_PAGEEXEC
7113+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7114+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7115+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7116+#else
7117+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7118+# define PAGE_COPY_NOEXEC PAGE_COPY
7119+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7120+#endif
7121+
7122 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7123 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7124 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7125diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7126index e0a8235..ce2f1e1 100644
7127--- a/arch/parisc/include/asm/uaccess.h
7128+++ b/arch/parisc/include/asm/uaccess.h
7129@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7130 const void __user *from,
7131 unsigned long n)
7132 {
7133- int sz = __compiletime_object_size(to);
7134+ size_t sz = __compiletime_object_size(to);
7135 int ret = -EFAULT;
7136
7137- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7138+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7139 ret = __copy_from_user(to, from, n);
7140 else
7141 copy_from_user_overflow();
7142diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7143index 2a625fb..9908930 100644
7144--- a/arch/parisc/kernel/module.c
7145+++ b/arch/parisc/kernel/module.c
7146@@ -98,16 +98,38 @@
7147
7148 /* three functions to determine where in the module core
7149 * or init pieces the location is */
7150+static inline int in_init_rx(struct module *me, void *loc)
7151+{
7152+ return (loc >= me->module_init_rx &&
7153+ loc < (me->module_init_rx + me->init_size_rx));
7154+}
7155+
7156+static inline int in_init_rw(struct module *me, void *loc)
7157+{
7158+ return (loc >= me->module_init_rw &&
7159+ loc < (me->module_init_rw + me->init_size_rw));
7160+}
7161+
7162 static inline int in_init(struct module *me, void *loc)
7163 {
7164- return (loc >= me->module_init &&
7165- loc <= (me->module_init + me->init_size));
7166+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7167+}
7168+
7169+static inline int in_core_rx(struct module *me, void *loc)
7170+{
7171+ return (loc >= me->module_core_rx &&
7172+ loc < (me->module_core_rx + me->core_size_rx));
7173+}
7174+
7175+static inline int in_core_rw(struct module *me, void *loc)
7176+{
7177+ return (loc >= me->module_core_rw &&
7178+ loc < (me->module_core_rw + me->core_size_rw));
7179 }
7180
7181 static inline int in_core(struct module *me, void *loc)
7182 {
7183- return (loc >= me->module_core &&
7184- loc <= (me->module_core + me->core_size));
7185+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7186 }
7187
7188 static inline int in_local(struct module *me, void *loc)
7189@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7190 }
7191
7192 /* align things a bit */
7193- me->core_size = ALIGN(me->core_size, 16);
7194- me->arch.got_offset = me->core_size;
7195- me->core_size += gots * sizeof(struct got_entry);
7196+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7197+ me->arch.got_offset = me->core_size_rw;
7198+ me->core_size_rw += gots * sizeof(struct got_entry);
7199
7200- me->core_size = ALIGN(me->core_size, 16);
7201- me->arch.fdesc_offset = me->core_size;
7202- me->core_size += fdescs * sizeof(Elf_Fdesc);
7203+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7204+ me->arch.fdesc_offset = me->core_size_rw;
7205+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7206
7207 me->arch.got_max = gots;
7208 me->arch.fdesc_max = fdescs;
7209@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7210
7211 BUG_ON(value == 0);
7212
7213- got = me->module_core + me->arch.got_offset;
7214+ got = me->module_core_rw + me->arch.got_offset;
7215 for (i = 0; got[i].addr; i++)
7216 if (got[i].addr == value)
7217 goto out;
7218@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7219 #ifdef CONFIG_64BIT
7220 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7221 {
7222- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7223+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7224
7225 if (!value) {
7226 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7227@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7228
7229 /* Create new one */
7230 fdesc->addr = value;
7231- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7232+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7233 return (Elf_Addr)fdesc;
7234 }
7235 #endif /* CONFIG_64BIT */
7236@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7237
7238 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7239 end = table + sechdrs[me->arch.unwind_section].sh_size;
7240- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7241+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7242
7243 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7244 me->arch.unwind_section, table, end, gp);
7245diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7246index 5dfd248..64914ac 100644
7247--- a/arch/parisc/kernel/sys_parisc.c
7248+++ b/arch/parisc/kernel/sys_parisc.c
7249@@ -33,9 +33,11 @@
7250 #include <linux/utsname.h>
7251 #include <linux/personality.h>
7252
7253-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7254+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7255+ unsigned long flags)
7256 {
7257 struct vm_unmapped_area_info info;
7258+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7259
7260 info.flags = 0;
7261 info.length = len;
7262@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7263 info.high_limit = TASK_SIZE;
7264 info.align_mask = 0;
7265 info.align_offset = 0;
7266+ info.threadstack_offset = offset;
7267 return vm_unmapped_area(&info);
7268 }
7269
7270@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7271 return (unsigned long) mapping >> 8;
7272 }
7273
7274-static unsigned long get_shared_area(struct address_space *mapping,
7275- unsigned long addr, unsigned long len, unsigned long pgoff)
7276+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7277+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7278 {
7279 struct vm_unmapped_area_info info;
7280+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7281
7282 info.flags = 0;
7283 info.length = len;
7284@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7285 info.high_limit = TASK_SIZE;
7286 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7287 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7288+ info.threadstack_offset = offset;
7289 return vm_unmapped_area(&info);
7290 }
7291
7292@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7293 return -EINVAL;
7294 return addr;
7295 }
7296- if (!addr)
7297+ if (!addr) {
7298 addr = TASK_UNMAPPED_BASE;
7299
7300+#ifdef CONFIG_PAX_RANDMMAP
7301+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7302+ addr += current->mm->delta_mmap;
7303+#endif
7304+
7305+ }
7306+
7307 if (filp) {
7308- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7309+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7310 } else if(flags & MAP_SHARED) {
7311- addr = get_shared_area(NULL, addr, len, pgoff);
7312+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7313 } else {
7314- addr = get_unshared_area(addr, len);
7315+ addr = get_unshared_area(filp, addr, len, flags);
7316 }
7317 return addr;
7318 }
7319diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7320index 04e47c6..7a8faf6 100644
7321--- a/arch/parisc/kernel/traps.c
7322+++ b/arch/parisc/kernel/traps.c
7323@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7324
7325 down_read(&current->mm->mmap_sem);
7326 vma = find_vma(current->mm,regs->iaoq[0]);
7327- if (vma && (regs->iaoq[0] >= vma->vm_start)
7328- && (vma->vm_flags & VM_EXEC)) {
7329-
7330+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7331 fault_address = regs->iaoq[0];
7332 fault_space = regs->iasq[0];
7333
7334diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7335index f247a34..dc0f219 100644
7336--- a/arch/parisc/mm/fault.c
7337+++ b/arch/parisc/mm/fault.c
7338@@ -15,6 +15,7 @@
7339 #include <linux/sched.h>
7340 #include <linux/interrupt.h>
7341 #include <linux/module.h>
7342+#include <linux/unistd.h>
7343
7344 #include <asm/uaccess.h>
7345 #include <asm/traps.h>
7346@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7347 static unsigned long
7348 parisc_acctyp(unsigned long code, unsigned int inst)
7349 {
7350- if (code == 6 || code == 16)
7351+ if (code == 6 || code == 7 || code == 16)
7352 return VM_EXEC;
7353
7354 switch (inst & 0xf0000000) {
7355@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7356 }
7357 #endif
7358
7359+#ifdef CONFIG_PAX_PAGEEXEC
7360+/*
7361+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7362+ *
7363+ * returns 1 when task should be killed
7364+ * 2 when rt_sigreturn trampoline was detected
7365+ * 3 when unpatched PLT trampoline was detected
7366+ */
7367+static int pax_handle_fetch_fault(struct pt_regs *regs)
7368+{
7369+
7370+#ifdef CONFIG_PAX_EMUPLT
7371+ int err;
7372+
7373+ do { /* PaX: unpatched PLT emulation */
7374+ unsigned int bl, depwi;
7375+
7376+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7377+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7378+
7379+ if (err)
7380+ break;
7381+
7382+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7383+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7384+
7385+ err = get_user(ldw, (unsigned int *)addr);
7386+ err |= get_user(bv, (unsigned int *)(addr+4));
7387+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7388+
7389+ if (err)
7390+ break;
7391+
7392+ if (ldw == 0x0E801096U &&
7393+ bv == 0xEAC0C000U &&
7394+ ldw2 == 0x0E881095U)
7395+ {
7396+ unsigned int resolver, map;
7397+
7398+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7399+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7400+ if (err)
7401+ break;
7402+
7403+ regs->gr[20] = instruction_pointer(regs)+8;
7404+ regs->gr[21] = map;
7405+ regs->gr[22] = resolver;
7406+ regs->iaoq[0] = resolver | 3UL;
7407+ regs->iaoq[1] = regs->iaoq[0] + 4;
7408+ return 3;
7409+ }
7410+ }
7411+ } while (0);
7412+#endif
7413+
7414+#ifdef CONFIG_PAX_EMUTRAMP
7415+
7416+#ifndef CONFIG_PAX_EMUSIGRT
7417+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7418+ return 1;
7419+#endif
7420+
7421+ do { /* PaX: rt_sigreturn emulation */
7422+ unsigned int ldi1, ldi2, bel, nop;
7423+
7424+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7425+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7426+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7427+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7428+
7429+ if (err)
7430+ break;
7431+
7432+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7433+ ldi2 == 0x3414015AU &&
7434+ bel == 0xE4008200U &&
7435+ nop == 0x08000240U)
7436+ {
7437+ regs->gr[25] = (ldi1 & 2) >> 1;
7438+ regs->gr[20] = __NR_rt_sigreturn;
7439+ regs->gr[31] = regs->iaoq[1] + 16;
7440+ regs->sr[0] = regs->iasq[1];
7441+ regs->iaoq[0] = 0x100UL;
7442+ regs->iaoq[1] = regs->iaoq[0] + 4;
7443+ regs->iasq[0] = regs->sr[2];
7444+ regs->iasq[1] = regs->sr[2];
7445+ return 2;
7446+ }
7447+ } while (0);
7448+#endif
7449+
7450+ return 1;
7451+}
7452+
7453+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7454+{
7455+ unsigned long i;
7456+
7457+ printk(KERN_ERR "PAX: bytes at PC: ");
7458+ for (i = 0; i < 5; i++) {
7459+ unsigned int c;
7460+ if (get_user(c, (unsigned int *)pc+i))
7461+ printk(KERN_CONT "???????? ");
7462+ else
7463+ printk(KERN_CONT "%08x ", c);
7464+ }
7465+ printk("\n");
7466+}
7467+#endif
7468+
7469 int fixup_exception(struct pt_regs *regs)
7470 {
7471 const struct exception_table_entry *fix;
7472@@ -194,8 +305,33 @@ good_area:
7473
7474 acc_type = parisc_acctyp(code,regs->iir);
7475
7476- if ((vma->vm_flags & acc_type) != acc_type)
7477+ if ((vma->vm_flags & acc_type) != acc_type) {
7478+
7479+#ifdef CONFIG_PAX_PAGEEXEC
7480+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7481+ (address & ~3UL) == instruction_pointer(regs))
7482+ {
7483+ up_read(&mm->mmap_sem);
7484+ switch (pax_handle_fetch_fault(regs)) {
7485+
7486+#ifdef CONFIG_PAX_EMUPLT
7487+ case 3:
7488+ return;
7489+#endif
7490+
7491+#ifdef CONFIG_PAX_EMUTRAMP
7492+ case 2:
7493+ return;
7494+#endif
7495+
7496+ }
7497+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7498+ do_group_exit(SIGKILL);
7499+ }
7500+#endif
7501+
7502 goto bad_area;
7503+ }
7504
7505 /*
7506 * If for any reason at all we couldn't handle the fault, make
7507diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7508index e3b1d41..8e81edf 100644
7509--- a/arch/powerpc/include/asm/atomic.h
7510+++ b/arch/powerpc/include/asm/atomic.h
7511@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7512 return t1;
7513 }
7514
7515+#define atomic64_read_unchecked(v) atomic64_read(v)
7516+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7517+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7518+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7519+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7520+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7521+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7522+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7523+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7524+
7525 #endif /* __powerpc64__ */
7526
7527 #endif /* __KERNEL__ */
7528diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7529index 9e495c9..b6878e5 100644
7530--- a/arch/powerpc/include/asm/cache.h
7531+++ b/arch/powerpc/include/asm/cache.h
7532@@ -3,6 +3,7 @@
7533
7534 #ifdef __KERNEL__
7535
7536+#include <linux/const.h>
7537
7538 /* bytes per L1 cache line */
7539 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7540@@ -22,7 +23,7 @@
7541 #define L1_CACHE_SHIFT 7
7542 #endif
7543
7544-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7545+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7546
7547 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7548
7549diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7550index cc0655a..13eac2e 100644
7551--- a/arch/powerpc/include/asm/elf.h
7552+++ b/arch/powerpc/include/asm/elf.h
7553@@ -28,8 +28,19 @@
7554 the loader. We need to make sure that it is out of the way of the program
7555 that it will "exec", and that there is sufficient room for the brk. */
7556
7557-extern unsigned long randomize_et_dyn(unsigned long base);
7558-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7559+#define ELF_ET_DYN_BASE (0x20000000)
7560+
7561+#ifdef CONFIG_PAX_ASLR
7562+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7563+
7564+#ifdef __powerpc64__
7565+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7566+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7567+#else
7568+#define PAX_DELTA_MMAP_LEN 15
7569+#define PAX_DELTA_STACK_LEN 15
7570+#endif
7571+#endif
7572
7573 /*
7574 * Our registers are always unsigned longs, whether we're a 32 bit
7575@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7576 (0x7ff >> (PAGE_SHIFT - 12)) : \
7577 (0x3ffff >> (PAGE_SHIFT - 12)))
7578
7579-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7580-#define arch_randomize_brk arch_randomize_brk
7581-
7582-
7583 #ifdef CONFIG_SPU_BASE
7584 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7585 #define NT_SPU 1
7586diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7587index 8196e9c..d83a9f3 100644
7588--- a/arch/powerpc/include/asm/exec.h
7589+++ b/arch/powerpc/include/asm/exec.h
7590@@ -4,6 +4,6 @@
7591 #ifndef _ASM_POWERPC_EXEC_H
7592 #define _ASM_POWERPC_EXEC_H
7593
7594-extern unsigned long arch_align_stack(unsigned long sp);
7595+#define arch_align_stack(x) ((x) & ~0xfUL)
7596
7597 #endif /* _ASM_POWERPC_EXEC_H */
7598diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7599index 5acabbd..7ea14fa 100644
7600--- a/arch/powerpc/include/asm/kmap_types.h
7601+++ b/arch/powerpc/include/asm/kmap_types.h
7602@@ -10,7 +10,7 @@
7603 * 2 of the License, or (at your option) any later version.
7604 */
7605
7606-#define KM_TYPE_NR 16
7607+#define KM_TYPE_NR 17
7608
7609 #endif /* __KERNEL__ */
7610 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7611diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7612index 8565c25..2865190 100644
7613--- a/arch/powerpc/include/asm/mman.h
7614+++ b/arch/powerpc/include/asm/mman.h
7615@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7616 }
7617 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7618
7619-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7620+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7621 {
7622 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7623 }
7624diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7625index b9f4262..dcf04f7 100644
7626--- a/arch/powerpc/include/asm/page.h
7627+++ b/arch/powerpc/include/asm/page.h
7628@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7629 * and needs to be executable. This means the whole heap ends
7630 * up being executable.
7631 */
7632-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7633- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7634+#define VM_DATA_DEFAULT_FLAGS32 \
7635+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7636+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7637
7638 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7639 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7640@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7641 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7642 #endif
7643
7644+#define ktla_ktva(addr) (addr)
7645+#define ktva_ktla(addr) (addr)
7646+
7647 #ifndef CONFIG_PPC_BOOK3S_64
7648 /*
7649 * Use the top bit of the higher-level page table entries to indicate whether
7650diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7651index 88693ce..ac6f9ab 100644
7652--- a/arch/powerpc/include/asm/page_64.h
7653+++ b/arch/powerpc/include/asm/page_64.h
7654@@ -153,15 +153,18 @@ do { \
7655 * stack by default, so in the absence of a PT_GNU_STACK program header
7656 * we turn execute permission off.
7657 */
7658-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7659- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7660+#define VM_STACK_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_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7665 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7666
7667+#ifndef CONFIG_PAX_PAGEEXEC
7668 #define VM_STACK_DEFAULT_FLAGS \
7669 (is_32bit_task() ? \
7670 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7671+#endif
7672
7673 #include <asm-generic/getorder.h>
7674
7675diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7676index f65e27b..23ffb5b 100644
7677--- a/arch/powerpc/include/asm/pgalloc-64.h
7678+++ b/arch/powerpc/include/asm/pgalloc-64.h
7679@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7680 #ifndef CONFIG_PPC_64K_PAGES
7681
7682 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7683+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7684
7685 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7686 {
7687@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7688 pud_set(pud, (unsigned long)pmd);
7689 }
7690
7691+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7692+{
7693+ pud_populate(mm, pud, pmd);
7694+}
7695+
7696 #define pmd_populate(mm, pmd, pte_page) \
7697 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7698 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7699@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7700 #endif
7701
7702 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7703+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7704
7705 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7706 pte_t *pte)
7707diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7708index 7d6eacf..14c0240 100644
7709--- a/arch/powerpc/include/asm/pgtable.h
7710+++ b/arch/powerpc/include/asm/pgtable.h
7711@@ -2,6 +2,7 @@
7712 #define _ASM_POWERPC_PGTABLE_H
7713 #ifdef __KERNEL__
7714
7715+#include <linux/const.h>
7716 #ifndef __ASSEMBLY__
7717 #include <asm/processor.h> /* For TASK_SIZE */
7718 #include <asm/mmu.h>
7719diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7720index 4aad413..85d86bf 100644
7721--- a/arch/powerpc/include/asm/pte-hash32.h
7722+++ b/arch/powerpc/include/asm/pte-hash32.h
7723@@ -21,6 +21,7 @@
7724 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7725 #define _PAGE_USER 0x004 /* usermode access allowed */
7726 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7727+#define _PAGE_EXEC _PAGE_GUARDED
7728 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7729 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7730 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7731diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7732index 99222e2..f629aef 100644
7733--- a/arch/powerpc/include/asm/reg.h
7734+++ b/arch/powerpc/include/asm/reg.h
7735@@ -234,6 +234,7 @@
7736 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7737 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7738 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7739+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7740 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7741 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7742 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7743diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7744index 48cfc85..891382f 100644
7745--- a/arch/powerpc/include/asm/smp.h
7746+++ b/arch/powerpc/include/asm/smp.h
7747@@ -50,7 +50,7 @@ struct smp_ops_t {
7748 int (*cpu_disable)(void);
7749 void (*cpu_die)(unsigned int nr);
7750 int (*cpu_bootable)(unsigned int nr);
7751-};
7752+} __no_const;
7753
7754 extern void smp_send_debugger_break(void);
7755 extern void start_secondary_resume(void);
7756diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7757index ba7b197..d292e26 100644
7758--- a/arch/powerpc/include/asm/thread_info.h
7759+++ b/arch/powerpc/include/asm/thread_info.h
7760@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7761 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7762 TIF_NEED_RESCHED */
7763 #define TIF_32BIT 4 /* 32 bit binary */
7764-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7765 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7766 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7767 #define TIF_SINGLESTEP 8 /* singlestepping active */
7768@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7769 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7770 for stack store? */
7771 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7772+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7773+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7774+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7775
7776 /* as above, but as bit values */
7777 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7778@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7779 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7780 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7781 #define _TIF_NOHZ (1<<TIF_NOHZ)
7782+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7783 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7784 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7785- _TIF_NOHZ)
7786+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7787
7788 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7789 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7790diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7791index 9485b43..4718d50 100644
7792--- a/arch/powerpc/include/asm/uaccess.h
7793+++ b/arch/powerpc/include/asm/uaccess.h
7794@@ -318,52 +318,6 @@ do { \
7795 extern unsigned long __copy_tofrom_user(void __user *to,
7796 const void __user *from, unsigned long size);
7797
7798-#ifndef __powerpc64__
7799-
7800-static inline unsigned long copy_from_user(void *to,
7801- const void __user *from, unsigned long n)
7802-{
7803- unsigned long over;
7804-
7805- if (access_ok(VERIFY_READ, from, n))
7806- return __copy_tofrom_user((__force void __user *)to, from, n);
7807- if ((unsigned long)from < TASK_SIZE) {
7808- over = (unsigned long)from + n - TASK_SIZE;
7809- return __copy_tofrom_user((__force void __user *)to, from,
7810- n - over) + over;
7811- }
7812- return n;
7813-}
7814-
7815-static inline unsigned long copy_to_user(void __user *to,
7816- const void *from, unsigned long n)
7817-{
7818- unsigned long over;
7819-
7820- if (access_ok(VERIFY_WRITE, to, n))
7821- return __copy_tofrom_user(to, (__force void __user *)from, n);
7822- if ((unsigned long)to < TASK_SIZE) {
7823- over = (unsigned long)to + n - TASK_SIZE;
7824- return __copy_tofrom_user(to, (__force void __user *)from,
7825- n - over) + over;
7826- }
7827- return n;
7828-}
7829-
7830-#else /* __powerpc64__ */
7831-
7832-#define __copy_in_user(to, from, size) \
7833- __copy_tofrom_user((to), (from), (size))
7834-
7835-extern unsigned long copy_from_user(void *to, const void __user *from,
7836- unsigned long n);
7837-extern unsigned long copy_to_user(void __user *to, const void *from,
7838- unsigned long n);
7839-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7840- unsigned long n);
7841-
7842-#endif /* __powerpc64__ */
7843-
7844 static inline unsigned long __copy_from_user_inatomic(void *to,
7845 const void __user *from, unsigned long n)
7846 {
7847@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7848 if (ret == 0)
7849 return 0;
7850 }
7851+
7852+ if (!__builtin_constant_p(n))
7853+ check_object_size(to, n, false);
7854+
7855 return __copy_tofrom_user((__force void __user *)to, from, n);
7856 }
7857
7858@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7859 if (ret == 0)
7860 return 0;
7861 }
7862+
7863+ if (!__builtin_constant_p(n))
7864+ check_object_size(from, n, true);
7865+
7866 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7867 }
7868
7869@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7870 return __copy_to_user_inatomic(to, from, size);
7871 }
7872
7873+#ifndef __powerpc64__
7874+
7875+static inline unsigned long __must_check copy_from_user(void *to,
7876+ const void __user *from, unsigned long n)
7877+{
7878+ unsigned long over;
7879+
7880+ if ((long)n < 0)
7881+ return n;
7882+
7883+ if (access_ok(VERIFY_READ, from, n)) {
7884+ if (!__builtin_constant_p(n))
7885+ check_object_size(to, n, false);
7886+ return __copy_tofrom_user((__force void __user *)to, from, n);
7887+ }
7888+ if ((unsigned long)from < TASK_SIZE) {
7889+ over = (unsigned long)from + n - TASK_SIZE;
7890+ if (!__builtin_constant_p(n - over))
7891+ check_object_size(to, n - over, false);
7892+ return __copy_tofrom_user((__force void __user *)to, from,
7893+ n - over) + over;
7894+ }
7895+ return n;
7896+}
7897+
7898+static inline unsigned long __must_check copy_to_user(void __user *to,
7899+ const void *from, unsigned long n)
7900+{
7901+ unsigned long over;
7902+
7903+ if ((long)n < 0)
7904+ return n;
7905+
7906+ if (access_ok(VERIFY_WRITE, to, n)) {
7907+ if (!__builtin_constant_p(n))
7908+ check_object_size(from, n, true);
7909+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7910+ }
7911+ if ((unsigned long)to < TASK_SIZE) {
7912+ over = (unsigned long)to + n - TASK_SIZE;
7913+ if (!__builtin_constant_p(n))
7914+ check_object_size(from, n - over, true);
7915+ return __copy_tofrom_user(to, (__force void __user *)from,
7916+ n - over) + over;
7917+ }
7918+ return n;
7919+}
7920+
7921+#else /* __powerpc64__ */
7922+
7923+#define __copy_in_user(to, from, size) \
7924+ __copy_tofrom_user((to), (from), (size))
7925+
7926+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7927+{
7928+ if ((long)n < 0 || n > INT_MAX)
7929+ return n;
7930+
7931+ if (!__builtin_constant_p(n))
7932+ check_object_size(to, n, false);
7933+
7934+ if (likely(access_ok(VERIFY_READ, from, n)))
7935+ n = __copy_from_user(to, from, n);
7936+ else
7937+ memset(to, 0, n);
7938+ return n;
7939+}
7940+
7941+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7942+{
7943+ if ((long)n < 0 || n > INT_MAX)
7944+ return n;
7945+
7946+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7947+ if (!__builtin_constant_p(n))
7948+ check_object_size(from, n, true);
7949+ n = __copy_to_user(to, from, n);
7950+ }
7951+ return n;
7952+}
7953+
7954+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7955+ unsigned long n);
7956+
7957+#endif /* __powerpc64__ */
7958+
7959 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7960
7961 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7962diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7963index 645170a..6cf0271 100644
7964--- a/arch/powerpc/kernel/exceptions-64e.S
7965+++ b/arch/powerpc/kernel/exceptions-64e.S
7966@@ -757,6 +757,7 @@ storage_fault_common:
7967 std r14,_DAR(r1)
7968 std r15,_DSISR(r1)
7969 addi r3,r1,STACK_FRAME_OVERHEAD
7970+ bl .save_nvgprs
7971 mr r4,r14
7972 mr r5,r15
7973 ld r14,PACA_EXGEN+EX_R14(r13)
7974@@ -765,8 +766,7 @@ storage_fault_common:
7975 cmpdi r3,0
7976 bne- 1f
7977 b .ret_from_except_lite
7978-1: bl .save_nvgprs
7979- mr r5,r3
7980+1: mr r5,r3
7981 addi r3,r1,STACK_FRAME_OVERHEAD
7982 ld r4,_DAR(r1)
7983 bl .bad_page_fault
7984diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7985index 902ca3c..e942155 100644
7986--- a/arch/powerpc/kernel/exceptions-64s.S
7987+++ b/arch/powerpc/kernel/exceptions-64s.S
7988@@ -1357,10 +1357,10 @@ handle_page_fault:
7989 11: ld r4,_DAR(r1)
7990 ld r5,_DSISR(r1)
7991 addi r3,r1,STACK_FRAME_OVERHEAD
7992+ bl .save_nvgprs
7993 bl .do_page_fault
7994 cmpdi r3,0
7995 beq+ 12f
7996- bl .save_nvgprs
7997 mr r5,r3
7998 addi r3,r1,STACK_FRAME_OVERHEAD
7999 lwz r4,_DAR(r1)
8000diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8001index 2e3200c..72095ce 100644
8002--- a/arch/powerpc/kernel/module_32.c
8003+++ b/arch/powerpc/kernel/module_32.c
8004@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8005 me->arch.core_plt_section = i;
8006 }
8007 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8008- printk("Module doesn't contain .plt or .init.plt sections.\n");
8009+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8010 return -ENOEXEC;
8011 }
8012
8013@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8014
8015 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8016 /* Init, or core PLT? */
8017- if (location >= mod->module_core
8018- && location < mod->module_core + mod->core_size)
8019+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8020+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8021 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8022- else
8023+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8024+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8025 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8026+ else {
8027+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8028+ return ~0UL;
8029+ }
8030
8031 /* Find this entry, or if that fails, the next avail. entry */
8032 while (entry->jump[0]) {
8033diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8034index 8083be2..10aa352 100644
8035--- a/arch/powerpc/kernel/process.c
8036+++ b/arch/powerpc/kernel/process.c
8037@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
8038 * Lookup NIP late so we have the best change of getting the
8039 * above info out without failing
8040 */
8041- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8042- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8043+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8044+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8045 #endif
8046 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8047 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8048@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8049 newsp = stack[0];
8050 ip = stack[STACK_FRAME_LR_SAVE];
8051 if (!firstframe || ip != lr) {
8052- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8053+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8054 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8055 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8056- printk(" (%pS)",
8057+ printk(" (%pA)",
8058 (void *)current->ret_stack[curr_frame].ret);
8059 curr_frame--;
8060 }
8061@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8062 struct pt_regs *regs = (struct pt_regs *)
8063 (sp + STACK_FRAME_OVERHEAD);
8064 lr = regs->link;
8065- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8066+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8067 regs->trap, (void *)regs->nip, (void *)lr);
8068 firstframe = 1;
8069 }
8070@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
8071 mtspr(SPRN_CTRLT, ctrl);
8072 }
8073 #endif /* CONFIG_PPC64 */
8074-
8075-unsigned long arch_align_stack(unsigned long sp)
8076-{
8077- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8078- sp -= get_random_int() & ~PAGE_MASK;
8079- return sp & ~0xf;
8080-}
8081-
8082-static inline unsigned long brk_rnd(void)
8083-{
8084- unsigned long rnd = 0;
8085-
8086- /* 8MB for 32bit, 1GB for 64bit */
8087- if (is_32bit_task())
8088- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8089- else
8090- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8091-
8092- return rnd << PAGE_SHIFT;
8093-}
8094-
8095-unsigned long arch_randomize_brk(struct mm_struct *mm)
8096-{
8097- unsigned long base = mm->brk;
8098- unsigned long ret;
8099-
8100-#ifdef CONFIG_PPC_STD_MMU_64
8101- /*
8102- * If we are using 1TB segments and we are allowed to randomise
8103- * the heap, we can put it above 1TB so it is backed by a 1TB
8104- * segment. Otherwise the heap will be in the bottom 1TB
8105- * which always uses 256MB segments and this may result in a
8106- * performance penalty.
8107- */
8108- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8109- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8110-#endif
8111-
8112- ret = PAGE_ALIGN(base + brk_rnd());
8113-
8114- if (ret < mm->brk)
8115- return mm->brk;
8116-
8117- return ret;
8118-}
8119-
8120-unsigned long randomize_et_dyn(unsigned long base)
8121-{
8122- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8123-
8124- if (ret < base)
8125- return base;
8126-
8127- return ret;
8128-}
8129diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8130index 9a0d24c..e7fbedf 100644
8131--- a/arch/powerpc/kernel/ptrace.c
8132+++ b/arch/powerpc/kernel/ptrace.c
8133@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8134 return ret;
8135 }
8136
8137+#ifdef CONFIG_GRKERNSEC_SETXID
8138+extern void gr_delayed_cred_worker(void);
8139+#endif
8140+
8141 /*
8142 * We must return the syscall number to actually look up in the table.
8143 * This can be -1L to skip running any syscall at all.
8144@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8145
8146 secure_computing_strict(regs->gpr[0]);
8147
8148+#ifdef CONFIG_GRKERNSEC_SETXID
8149+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8150+ gr_delayed_cred_worker();
8151+#endif
8152+
8153 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8154 tracehook_report_syscall_entry(regs))
8155 /*
8156@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8157 {
8158 int step;
8159
8160+#ifdef CONFIG_GRKERNSEC_SETXID
8161+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8162+ gr_delayed_cred_worker();
8163+#endif
8164+
8165 audit_syscall_exit(regs);
8166
8167 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8168diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8169index 0f83122..c0aca6a 100644
8170--- a/arch/powerpc/kernel/signal_32.c
8171+++ b/arch/powerpc/kernel/signal_32.c
8172@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8173 /* Save user registers on the stack */
8174 frame = &rt_sf->uc.uc_mcontext;
8175 addr = frame;
8176- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8177+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8178 sigret = 0;
8179 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8180 } else {
8181diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8182index 887e99d..310bc11 100644
8183--- a/arch/powerpc/kernel/signal_64.c
8184+++ b/arch/powerpc/kernel/signal_64.c
8185@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8186 #endif
8187
8188 /* Set up to return from userspace. */
8189- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8190+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8191 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8192 } else {
8193 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8194diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8195index e435bc0..41c2964 100644
8196--- a/arch/powerpc/kernel/traps.c
8197+++ b/arch/powerpc/kernel/traps.c
8198@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8199 return flags;
8200 }
8201
8202+extern void gr_handle_kernel_exploit(void);
8203+
8204 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8205 int signr)
8206 {
8207@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8208 panic("Fatal exception in interrupt");
8209 if (panic_on_oops)
8210 panic("Fatal exception");
8211+
8212+ gr_handle_kernel_exploit();
8213+
8214 do_exit(signr);
8215 }
8216
8217diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8218index 1d9c926..25f4741 100644
8219--- a/arch/powerpc/kernel/vdso.c
8220+++ b/arch/powerpc/kernel/vdso.c
8221@@ -34,6 +34,7 @@
8222 #include <asm/firmware.h>
8223 #include <asm/vdso.h>
8224 #include <asm/vdso_datapage.h>
8225+#include <asm/mman.h>
8226
8227 #include "setup.h"
8228
8229@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8230 vdso_base = VDSO32_MBASE;
8231 #endif
8232
8233- current->mm->context.vdso_base = 0;
8234+ current->mm->context.vdso_base = ~0UL;
8235
8236 /* vDSO has a problem and was disabled, just don't "enable" it for the
8237 * process
8238@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8239 vdso_base = get_unmapped_area(NULL, vdso_base,
8240 (vdso_pages << PAGE_SHIFT) +
8241 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8242- 0, 0);
8243+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8244 if (IS_ERR_VALUE(vdso_base)) {
8245 rc = vdso_base;
8246 goto fail_mmapsem;
8247diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8248index 5eea6f3..5d10396 100644
8249--- a/arch/powerpc/lib/usercopy_64.c
8250+++ b/arch/powerpc/lib/usercopy_64.c
8251@@ -9,22 +9,6 @@
8252 #include <linux/module.h>
8253 #include <asm/uaccess.h>
8254
8255-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8256-{
8257- if (likely(access_ok(VERIFY_READ, from, n)))
8258- n = __copy_from_user(to, from, n);
8259- else
8260- memset(to, 0, n);
8261- return n;
8262-}
8263-
8264-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8265-{
8266- if (likely(access_ok(VERIFY_WRITE, to, n)))
8267- n = __copy_to_user(to, from, n);
8268- return n;
8269-}
8270-
8271 unsigned long copy_in_user(void __user *to, const void __user *from,
8272 unsigned long n)
8273 {
8274@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8275 return n;
8276 }
8277
8278-EXPORT_SYMBOL(copy_from_user);
8279-EXPORT_SYMBOL(copy_to_user);
8280 EXPORT_SYMBOL(copy_in_user);
8281
8282diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8283index 8726779..a33c512 100644
8284--- a/arch/powerpc/mm/fault.c
8285+++ b/arch/powerpc/mm/fault.c
8286@@ -33,6 +33,10 @@
8287 #include <linux/magic.h>
8288 #include <linux/ratelimit.h>
8289 #include <linux/context_tracking.h>
8290+#include <linux/slab.h>
8291+#include <linux/pagemap.h>
8292+#include <linux/compiler.h>
8293+#include <linux/unistd.h>
8294
8295 #include <asm/firmware.h>
8296 #include <asm/page.h>
8297@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8298 }
8299 #endif
8300
8301+#ifdef CONFIG_PAX_PAGEEXEC
8302+/*
8303+ * PaX: decide what to do with offenders (regs->nip = fault address)
8304+ *
8305+ * returns 1 when task should be killed
8306+ */
8307+static int pax_handle_fetch_fault(struct pt_regs *regs)
8308+{
8309+ return 1;
8310+}
8311+
8312+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8313+{
8314+ unsigned long i;
8315+
8316+ printk(KERN_ERR "PAX: bytes at PC: ");
8317+ for (i = 0; i < 5; i++) {
8318+ unsigned int c;
8319+ if (get_user(c, (unsigned int __user *)pc+i))
8320+ printk(KERN_CONT "???????? ");
8321+ else
8322+ printk(KERN_CONT "%08x ", c);
8323+ }
8324+ printk("\n");
8325+}
8326+#endif
8327+
8328 /*
8329 * Check whether the instruction at regs->nip is a store using
8330 * an update addressing form which will update r1.
8331@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8332 * indicate errors in DSISR but can validly be set in SRR1.
8333 */
8334 if (trap == 0x400)
8335- error_code &= 0x48200000;
8336+ error_code &= 0x58200000;
8337 else
8338 is_write = error_code & DSISR_ISSTORE;
8339 #else
8340@@ -371,7 +402,7 @@ good_area:
8341 * "undefined". Of those that can be set, this is the only
8342 * one which seems bad.
8343 */
8344- if (error_code & 0x10000000)
8345+ if (error_code & DSISR_GUARDED)
8346 /* Guarded storage error. */
8347 goto bad_area;
8348 #endif /* CONFIG_8xx */
8349@@ -386,7 +417,7 @@ good_area:
8350 * processors use the same I/D cache coherency mechanism
8351 * as embedded.
8352 */
8353- if (error_code & DSISR_PROTFAULT)
8354+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8355 goto bad_area;
8356 #endif /* CONFIG_PPC_STD_MMU */
8357
8358@@ -471,6 +502,23 @@ bad_area:
8359 bad_area_nosemaphore:
8360 /* User mode accesses cause a SIGSEGV */
8361 if (user_mode(regs)) {
8362+
8363+#ifdef CONFIG_PAX_PAGEEXEC
8364+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8365+#ifdef CONFIG_PPC_STD_MMU
8366+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8367+#else
8368+ if (is_exec && regs->nip == address) {
8369+#endif
8370+ switch (pax_handle_fetch_fault(regs)) {
8371+ }
8372+
8373+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8374+ do_group_exit(SIGKILL);
8375+ }
8376+ }
8377+#endif
8378+
8379 _exception(SIGSEGV, regs, code, address);
8380 goto bail;
8381 }
8382diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8383index cb8bdbe..d770680 100644
8384--- a/arch/powerpc/mm/mmap.c
8385+++ b/arch/powerpc/mm/mmap.c
8386@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8387 {
8388 unsigned long rnd = 0;
8389
8390+#ifdef CONFIG_PAX_RANDMMAP
8391+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8392+#endif
8393+
8394 if (current->flags & PF_RANDOMIZE) {
8395 /* 8MB for 32bit, 1GB for 64bit */
8396 if (is_32bit_task())
8397@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8398 */
8399 if (mmap_is_legacy()) {
8400 mm->mmap_base = TASK_UNMAPPED_BASE;
8401+
8402+#ifdef CONFIG_PAX_RANDMMAP
8403+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8404+ mm->mmap_base += mm->delta_mmap;
8405+#endif
8406+
8407 mm->get_unmapped_area = arch_get_unmapped_area;
8408 } else {
8409 mm->mmap_base = mmap_base();
8410+
8411+#ifdef CONFIG_PAX_RANDMMAP
8412+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8413+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8414+#endif
8415+
8416 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8417 }
8418 }
8419diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8420index 3e99c14..f00953c 100644
8421--- a/arch/powerpc/mm/slice.c
8422+++ b/arch/powerpc/mm/slice.c
8423@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8424 if ((mm->task_size - len) < addr)
8425 return 0;
8426 vma = find_vma(mm, addr);
8427- return (!vma || (addr + len) <= vma->vm_start);
8428+ return check_heap_stack_gap(vma, addr, len, 0);
8429 }
8430
8431 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8432@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8433 info.align_offset = 0;
8434
8435 addr = TASK_UNMAPPED_BASE;
8436+
8437+#ifdef CONFIG_PAX_RANDMMAP
8438+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8439+ addr += mm->delta_mmap;
8440+#endif
8441+
8442 while (addr < TASK_SIZE) {
8443 info.low_limit = addr;
8444 if (!slice_scan_available(addr, available, 1, &addr))
8445@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8446 if (fixed && addr > (mm->task_size - len))
8447 return -EINVAL;
8448
8449+#ifdef CONFIG_PAX_RANDMMAP
8450+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8451+ addr = 0;
8452+#endif
8453+
8454 /* If hint, make sure it matches our alignment restrictions */
8455 if (!fixed && addr) {
8456 addr = _ALIGN_UP(addr, 1ul << pshift);
8457diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8458index 9098692..3d54cd1 100644
8459--- a/arch/powerpc/platforms/cell/spufs/file.c
8460+++ b/arch/powerpc/platforms/cell/spufs/file.c
8461@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8462 return VM_FAULT_NOPAGE;
8463 }
8464
8465-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8466+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8467 unsigned long address,
8468- void *buf, int len, int write)
8469+ void *buf, size_t len, int write)
8470 {
8471 struct spu_context *ctx = vma->vm_file->private_data;
8472 unsigned long offset = address - vma->vm_start;
8473diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8474index c797832..ce575c8 100644
8475--- a/arch/s390/include/asm/atomic.h
8476+++ b/arch/s390/include/asm/atomic.h
8477@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8478 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8479 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8480
8481+#define atomic64_read_unchecked(v) atomic64_read(v)
8482+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8483+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8484+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8485+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8486+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8487+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8488+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8489+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8490+
8491 #define smp_mb__before_atomic_dec() smp_mb()
8492 #define smp_mb__after_atomic_dec() smp_mb()
8493 #define smp_mb__before_atomic_inc() smp_mb()
8494diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8495index 4d7ccac..d03d0ad 100644
8496--- a/arch/s390/include/asm/cache.h
8497+++ b/arch/s390/include/asm/cache.h
8498@@ -9,8 +9,10 @@
8499 #ifndef __ARCH_S390_CACHE_H
8500 #define __ARCH_S390_CACHE_H
8501
8502-#define L1_CACHE_BYTES 256
8503+#include <linux/const.h>
8504+
8505 #define L1_CACHE_SHIFT 8
8506+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8507 #define NET_SKB_PAD 32
8508
8509 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8510diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8511index 78f4f87..598ce39 100644
8512--- a/arch/s390/include/asm/elf.h
8513+++ b/arch/s390/include/asm/elf.h
8514@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8515 the loader. We need to make sure that it is out of the way of the program
8516 that it will "exec", and that there is sufficient room for the brk. */
8517
8518-extern unsigned long randomize_et_dyn(unsigned long base);
8519-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8520+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8521+
8522+#ifdef CONFIG_PAX_ASLR
8523+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8524+
8525+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8526+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8527+#endif
8528
8529 /* This yields a mask that user programs can use to figure out what
8530 instruction set this CPU supports. */
8531@@ -222,9 +228,6 @@ struct linux_binprm;
8532 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8533 int arch_setup_additional_pages(struct linux_binprm *, int);
8534
8535-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8536-#define arch_randomize_brk arch_randomize_brk
8537-
8538 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8539
8540 #endif
8541diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8542index c4a93d6..4d2a9b4 100644
8543--- a/arch/s390/include/asm/exec.h
8544+++ b/arch/s390/include/asm/exec.h
8545@@ -7,6 +7,6 @@
8546 #ifndef __ASM_EXEC_H
8547 #define __ASM_EXEC_H
8548
8549-extern unsigned long arch_align_stack(unsigned long sp);
8550+#define arch_align_stack(x) ((x) & ~0xfUL)
8551
8552 #endif /* __ASM_EXEC_H */
8553diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8554index 9c33ed4..e40cbef 100644
8555--- a/arch/s390/include/asm/uaccess.h
8556+++ b/arch/s390/include/asm/uaccess.h
8557@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8558 copy_to_user(void __user *to, const void *from, unsigned long n)
8559 {
8560 might_fault();
8561+
8562+ if ((long)n < 0)
8563+ return n;
8564+
8565 return __copy_to_user(to, from, n);
8566 }
8567
8568@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8569 static inline unsigned long __must_check
8570 __copy_from_user(void *to, const void __user *from, unsigned long n)
8571 {
8572+ if ((long)n < 0)
8573+ return n;
8574+
8575 if (__builtin_constant_p(n) && (n <= 256))
8576 return uaccess.copy_from_user_small(n, from, to);
8577 else
8578@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8579 static inline unsigned long __must_check
8580 copy_from_user(void *to, const void __user *from, unsigned long n)
8581 {
8582- unsigned int sz = __compiletime_object_size(to);
8583+ size_t sz = __compiletime_object_size(to);
8584
8585 might_fault();
8586- if (unlikely(sz != -1 && sz < n)) {
8587+
8588+ if ((long)n < 0)
8589+ return n;
8590+
8591+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8592 copy_from_user_overflow();
8593 return n;
8594 }
8595diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8596index 7845e15..59c4353 100644
8597--- a/arch/s390/kernel/module.c
8598+++ b/arch/s390/kernel/module.c
8599@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8600
8601 /* Increase core size by size of got & plt and set start
8602 offsets for got and plt. */
8603- me->core_size = ALIGN(me->core_size, 4);
8604- me->arch.got_offset = me->core_size;
8605- me->core_size += me->arch.got_size;
8606- me->arch.plt_offset = me->core_size;
8607- me->core_size += me->arch.plt_size;
8608+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8609+ me->arch.got_offset = me->core_size_rw;
8610+ me->core_size_rw += me->arch.got_size;
8611+ me->arch.plt_offset = me->core_size_rx;
8612+ me->core_size_rx += me->arch.plt_size;
8613 return 0;
8614 }
8615
8616@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8617 if (info->got_initialized == 0) {
8618 Elf_Addr *gotent;
8619
8620- gotent = me->module_core + me->arch.got_offset +
8621+ gotent = me->module_core_rw + me->arch.got_offset +
8622 info->got_offset;
8623 *gotent = val;
8624 info->got_initialized = 1;
8625@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8626 rc = apply_rela_bits(loc, val, 0, 64, 0);
8627 else if (r_type == R_390_GOTENT ||
8628 r_type == R_390_GOTPLTENT) {
8629- val += (Elf_Addr) me->module_core - loc;
8630+ val += (Elf_Addr) me->module_core_rw - loc;
8631 rc = apply_rela_bits(loc, val, 1, 32, 1);
8632 }
8633 break;
8634@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8635 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8636 if (info->plt_initialized == 0) {
8637 unsigned int *ip;
8638- ip = me->module_core + me->arch.plt_offset +
8639+ ip = me->module_core_rx + me->arch.plt_offset +
8640 info->plt_offset;
8641 #ifndef CONFIG_64BIT
8642 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8643@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8644 val - loc + 0xffffUL < 0x1ffffeUL) ||
8645 (r_type == R_390_PLT32DBL &&
8646 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8647- val = (Elf_Addr) me->module_core +
8648+ val = (Elf_Addr) me->module_core_rx +
8649 me->arch.plt_offset +
8650 info->plt_offset;
8651 val += rela->r_addend - loc;
8652@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8653 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8654 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8655 val = val + rela->r_addend -
8656- ((Elf_Addr) me->module_core + me->arch.got_offset);
8657+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8658 if (r_type == R_390_GOTOFF16)
8659 rc = apply_rela_bits(loc, val, 0, 16, 0);
8660 else if (r_type == R_390_GOTOFF32)
8661@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8662 break;
8663 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8664 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8665- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8666+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8667 rela->r_addend - loc;
8668 if (r_type == R_390_GOTPC)
8669 rc = apply_rela_bits(loc, val, 1, 32, 0);
8670diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8671index 2bc3edd..ab9d598 100644
8672--- a/arch/s390/kernel/process.c
8673+++ b/arch/s390/kernel/process.c
8674@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8675 }
8676 return 0;
8677 }
8678-
8679-unsigned long arch_align_stack(unsigned long sp)
8680-{
8681- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8682- sp -= get_random_int() & ~PAGE_MASK;
8683- return sp & ~0xf;
8684-}
8685-
8686-static inline unsigned long brk_rnd(void)
8687-{
8688- /* 8MB for 32bit, 1GB for 64bit */
8689- if (is_32bit_task())
8690- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8691- else
8692- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8693-}
8694-
8695-unsigned long arch_randomize_brk(struct mm_struct *mm)
8696-{
8697- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8698-
8699- if (ret < mm->brk)
8700- return mm->brk;
8701- return ret;
8702-}
8703-
8704-unsigned long randomize_et_dyn(unsigned long base)
8705-{
8706- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8707-
8708- if (!(current->flags & PF_RANDOMIZE))
8709- return base;
8710- if (ret < base)
8711- return base;
8712- return ret;
8713-}
8714diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8715index 4002329..99b67cb 100644
8716--- a/arch/s390/mm/mmap.c
8717+++ b/arch/s390/mm/mmap.c
8718@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8719 */
8720 if (mmap_is_legacy()) {
8721 mm->mmap_base = TASK_UNMAPPED_BASE;
8722+
8723+#ifdef CONFIG_PAX_RANDMMAP
8724+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8725+ mm->mmap_base += mm->delta_mmap;
8726+#endif
8727+
8728 mm->get_unmapped_area = arch_get_unmapped_area;
8729 } else {
8730 mm->mmap_base = mmap_base();
8731+
8732+#ifdef CONFIG_PAX_RANDMMAP
8733+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8734+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8735+#endif
8736+
8737 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8738 }
8739 }
8740@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8741 */
8742 if (mmap_is_legacy()) {
8743 mm->mmap_base = TASK_UNMAPPED_BASE;
8744+
8745+#ifdef CONFIG_PAX_RANDMMAP
8746+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8747+ mm->mmap_base += mm->delta_mmap;
8748+#endif
8749+
8750 mm->get_unmapped_area = s390_get_unmapped_area;
8751 } else {
8752 mm->mmap_base = mmap_base();
8753+
8754+#ifdef CONFIG_PAX_RANDMMAP
8755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8756+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8757+#endif
8758+
8759 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8760 }
8761 }
8762diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8763index ae3d59f..f65f075 100644
8764--- a/arch/score/include/asm/cache.h
8765+++ b/arch/score/include/asm/cache.h
8766@@ -1,7 +1,9 @@
8767 #ifndef _ASM_SCORE_CACHE_H
8768 #define _ASM_SCORE_CACHE_H
8769
8770+#include <linux/const.h>
8771+
8772 #define L1_CACHE_SHIFT 4
8773-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8774+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8775
8776 #endif /* _ASM_SCORE_CACHE_H */
8777diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8778index f9f3cd5..58ff438 100644
8779--- a/arch/score/include/asm/exec.h
8780+++ b/arch/score/include/asm/exec.h
8781@@ -1,6 +1,6 @@
8782 #ifndef _ASM_SCORE_EXEC_H
8783 #define _ASM_SCORE_EXEC_H
8784
8785-extern unsigned long arch_align_stack(unsigned long sp);
8786+#define arch_align_stack(x) (x)
8787
8788 #endif /* _ASM_SCORE_EXEC_H */
8789diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8790index f4c6d02..e9355c3 100644
8791--- a/arch/score/kernel/process.c
8792+++ b/arch/score/kernel/process.c
8793@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8794
8795 return task_pt_regs(task)->cp0_epc;
8796 }
8797-
8798-unsigned long arch_align_stack(unsigned long sp)
8799-{
8800- return sp;
8801-}
8802diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8803index ef9e555..331bd29 100644
8804--- a/arch/sh/include/asm/cache.h
8805+++ b/arch/sh/include/asm/cache.h
8806@@ -9,10 +9,11 @@
8807 #define __ASM_SH_CACHE_H
8808 #ifdef __KERNEL__
8809
8810+#include <linux/const.h>
8811 #include <linux/init.h>
8812 #include <cpu/cache.h>
8813
8814-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8815+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8816
8817 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8818
8819diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8820index 6777177..cb5e44f 100644
8821--- a/arch/sh/mm/mmap.c
8822+++ b/arch/sh/mm/mmap.c
8823@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8824 struct mm_struct *mm = current->mm;
8825 struct vm_area_struct *vma;
8826 int do_colour_align;
8827+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8828 struct vm_unmapped_area_info info;
8829
8830 if (flags & MAP_FIXED) {
8831@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8832 if (filp || (flags & MAP_SHARED))
8833 do_colour_align = 1;
8834
8835+#ifdef CONFIG_PAX_RANDMMAP
8836+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8837+#endif
8838+
8839 if (addr) {
8840 if (do_colour_align)
8841 addr = COLOUR_ALIGN(addr, pgoff);
8842@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8843 addr = PAGE_ALIGN(addr);
8844
8845 vma = find_vma(mm, addr);
8846- if (TASK_SIZE - len >= addr &&
8847- (!vma || addr + len <= vma->vm_start))
8848+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8849 return addr;
8850 }
8851
8852 info.flags = 0;
8853 info.length = len;
8854- info.low_limit = TASK_UNMAPPED_BASE;
8855+ info.low_limit = mm->mmap_base;
8856 info.high_limit = TASK_SIZE;
8857 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8858 info.align_offset = pgoff << PAGE_SHIFT;
8859@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8860 struct mm_struct *mm = current->mm;
8861 unsigned long addr = addr0;
8862 int do_colour_align;
8863+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8864 struct vm_unmapped_area_info info;
8865
8866 if (flags & MAP_FIXED) {
8867@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8868 if (filp || (flags & MAP_SHARED))
8869 do_colour_align = 1;
8870
8871+#ifdef CONFIG_PAX_RANDMMAP
8872+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8873+#endif
8874+
8875 /* requesting a specific address */
8876 if (addr) {
8877 if (do_colour_align)
8878@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8879 addr = PAGE_ALIGN(addr);
8880
8881 vma = find_vma(mm, addr);
8882- if (TASK_SIZE - len >= addr &&
8883- (!vma || addr + len <= vma->vm_start))
8884+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8885 return addr;
8886 }
8887
8888@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8889 VM_BUG_ON(addr != -ENOMEM);
8890 info.flags = 0;
8891 info.low_limit = TASK_UNMAPPED_BASE;
8892+
8893+#ifdef CONFIG_PAX_RANDMMAP
8894+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8895+ info.low_limit += mm->delta_mmap;
8896+#endif
8897+
8898 info.high_limit = TASK_SIZE;
8899 addr = vm_unmapped_area(&info);
8900 }
8901diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8902index be56a24..443328f 100644
8903--- a/arch/sparc/include/asm/atomic_64.h
8904+++ b/arch/sparc/include/asm/atomic_64.h
8905@@ -14,18 +14,40 @@
8906 #define ATOMIC64_INIT(i) { (i) }
8907
8908 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8909+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8910+{
8911+ return v->counter;
8912+}
8913 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8914+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8915+{
8916+ return v->counter;
8917+}
8918
8919 #define atomic_set(v, i) (((v)->counter) = i)
8920+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8921+{
8922+ v->counter = i;
8923+}
8924 #define atomic64_set(v, i) (((v)->counter) = i)
8925+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8926+{
8927+ v->counter = i;
8928+}
8929
8930 extern void atomic_add(int, atomic_t *);
8931+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8932 extern void atomic64_add(long, atomic64_t *);
8933+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8934 extern void atomic_sub(int, atomic_t *);
8935+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8936 extern void atomic64_sub(long, atomic64_t *);
8937+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8938
8939 extern int atomic_add_ret(int, atomic_t *);
8940+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8941 extern long atomic64_add_ret(long, atomic64_t *);
8942+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8943 extern int atomic_sub_ret(int, atomic_t *);
8944 extern long atomic64_sub_ret(long, atomic64_t *);
8945
8946@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8947 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8948
8949 #define atomic_inc_return(v) atomic_add_ret(1, v)
8950+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8951+{
8952+ return atomic_add_ret_unchecked(1, v);
8953+}
8954 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8955+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8956+{
8957+ return atomic64_add_ret_unchecked(1, v);
8958+}
8959
8960 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8961 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8962
8963 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8964+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8965+{
8966+ return atomic_add_ret_unchecked(i, v);
8967+}
8968 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8969+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8970+{
8971+ return atomic64_add_ret_unchecked(i, v);
8972+}
8973
8974 /*
8975 * atomic_inc_and_test - increment and test
8976@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8977 * other cases.
8978 */
8979 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8980+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8981+{
8982+ return atomic_inc_return_unchecked(v) == 0;
8983+}
8984 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8985
8986 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8987@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8988 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8989
8990 #define atomic_inc(v) atomic_add(1, v)
8991+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8992+{
8993+ atomic_add_unchecked(1, v);
8994+}
8995 #define atomic64_inc(v) atomic64_add(1, v)
8996+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8997+{
8998+ atomic64_add_unchecked(1, v);
8999+}
9000
9001 #define atomic_dec(v) atomic_sub(1, v)
9002+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9003+{
9004+ atomic_sub_unchecked(1, v);
9005+}
9006 #define atomic64_dec(v) atomic64_sub(1, v)
9007+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9008+{
9009+ atomic64_sub_unchecked(1, v);
9010+}
9011
9012 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9013 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9014
9015 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9016+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9017+{
9018+ return cmpxchg(&v->counter, old, new);
9019+}
9020 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9021+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9022+{
9023+ return xchg(&v->counter, new);
9024+}
9025
9026 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9027 {
9028- int c, old;
9029+ int c, old, new;
9030 c = atomic_read(v);
9031 for (;;) {
9032- if (unlikely(c == (u)))
9033+ if (unlikely(c == u))
9034 break;
9035- old = atomic_cmpxchg((v), c, c + (a));
9036+
9037+ asm volatile("addcc %2, %0, %0\n"
9038+
9039+#ifdef CONFIG_PAX_REFCOUNT
9040+ "tvs %%icc, 6\n"
9041+#endif
9042+
9043+ : "=r" (new)
9044+ : "0" (c), "ir" (a)
9045+ : "cc");
9046+
9047+ old = atomic_cmpxchg(v, c, new);
9048 if (likely(old == c))
9049 break;
9050 c = old;
9051@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9052 #define atomic64_cmpxchg(v, o, n) \
9053 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9054 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9055+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9056+{
9057+ return xchg(&v->counter, new);
9058+}
9059
9060 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9061 {
9062- long c, old;
9063+ long c, old, new;
9064 c = atomic64_read(v);
9065 for (;;) {
9066- if (unlikely(c == (u)))
9067+ if (unlikely(c == u))
9068 break;
9069- old = atomic64_cmpxchg((v), c, c + (a));
9070+
9071+ asm volatile("addcc %2, %0, %0\n"
9072+
9073+#ifdef CONFIG_PAX_REFCOUNT
9074+ "tvs %%xcc, 6\n"
9075+#endif
9076+
9077+ : "=r" (new)
9078+ : "0" (c), "ir" (a)
9079+ : "cc");
9080+
9081+ old = atomic64_cmpxchg(v, c, new);
9082 if (likely(old == c))
9083 break;
9084 c = old;
9085 }
9086- return c != (u);
9087+ return c != u;
9088 }
9089
9090 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9091diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9092index 5bb6991..5c2132e 100644
9093--- a/arch/sparc/include/asm/cache.h
9094+++ b/arch/sparc/include/asm/cache.h
9095@@ -7,10 +7,12 @@
9096 #ifndef _SPARC_CACHE_H
9097 #define _SPARC_CACHE_H
9098
9099+#include <linux/const.h>
9100+
9101 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9102
9103 #define L1_CACHE_SHIFT 5
9104-#define L1_CACHE_BYTES 32
9105+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9106
9107 #ifdef CONFIG_SPARC32
9108 #define SMP_CACHE_BYTES_SHIFT 5
9109diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9110index a24e41f..47677ff 100644
9111--- a/arch/sparc/include/asm/elf_32.h
9112+++ b/arch/sparc/include/asm/elf_32.h
9113@@ -114,6 +114,13 @@ typedef struct {
9114
9115 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9116
9117+#ifdef CONFIG_PAX_ASLR
9118+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9119+
9120+#define PAX_DELTA_MMAP_LEN 16
9121+#define PAX_DELTA_STACK_LEN 16
9122+#endif
9123+
9124 /* This yields a mask that user programs can use to figure out what
9125 instruction set this cpu supports. This can NOT be done in userspace
9126 on Sparc. */
9127diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9128index 370ca1e..d4f4a98 100644
9129--- a/arch/sparc/include/asm/elf_64.h
9130+++ b/arch/sparc/include/asm/elf_64.h
9131@@ -189,6 +189,13 @@ typedef struct {
9132 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9133 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9134
9135+#ifdef CONFIG_PAX_ASLR
9136+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9137+
9138+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9139+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9140+#endif
9141+
9142 extern unsigned long sparc64_elf_hwcap;
9143 #define ELF_HWCAP sparc64_elf_hwcap
9144
9145diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9146index 9b1c36d..209298b 100644
9147--- a/arch/sparc/include/asm/pgalloc_32.h
9148+++ b/arch/sparc/include/asm/pgalloc_32.h
9149@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9150 }
9151
9152 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9153+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9154
9155 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9156 unsigned long address)
9157diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9158index bcfe063..b333142 100644
9159--- a/arch/sparc/include/asm/pgalloc_64.h
9160+++ b/arch/sparc/include/asm/pgalloc_64.h
9161@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9162 }
9163
9164 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9165+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9166
9167 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9168 {
9169diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9170index 502f632..da1917f 100644
9171--- a/arch/sparc/include/asm/pgtable_32.h
9172+++ b/arch/sparc/include/asm/pgtable_32.h
9173@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9174 #define PAGE_SHARED SRMMU_PAGE_SHARED
9175 #define PAGE_COPY SRMMU_PAGE_COPY
9176 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9177+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9178+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9179+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9180 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9181
9182 /* Top-level page directory - dummy used by init-mm.
9183@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9184
9185 /* xwr */
9186 #define __P000 PAGE_NONE
9187-#define __P001 PAGE_READONLY
9188-#define __P010 PAGE_COPY
9189-#define __P011 PAGE_COPY
9190+#define __P001 PAGE_READONLY_NOEXEC
9191+#define __P010 PAGE_COPY_NOEXEC
9192+#define __P011 PAGE_COPY_NOEXEC
9193 #define __P100 PAGE_READONLY
9194 #define __P101 PAGE_READONLY
9195 #define __P110 PAGE_COPY
9196 #define __P111 PAGE_COPY
9197
9198 #define __S000 PAGE_NONE
9199-#define __S001 PAGE_READONLY
9200-#define __S010 PAGE_SHARED
9201-#define __S011 PAGE_SHARED
9202+#define __S001 PAGE_READONLY_NOEXEC
9203+#define __S010 PAGE_SHARED_NOEXEC
9204+#define __S011 PAGE_SHARED_NOEXEC
9205 #define __S100 PAGE_READONLY
9206 #define __S101 PAGE_READONLY
9207 #define __S110 PAGE_SHARED
9208diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9209index 79da178..c2eede8 100644
9210--- a/arch/sparc/include/asm/pgtsrmmu.h
9211+++ b/arch/sparc/include/asm/pgtsrmmu.h
9212@@ -115,6 +115,11 @@
9213 SRMMU_EXEC | SRMMU_REF)
9214 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9215 SRMMU_EXEC | SRMMU_REF)
9216+
9217+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9218+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9219+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9220+
9221 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9222 SRMMU_DIRTY | SRMMU_REF)
9223
9224diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9225index 9689176..63c18ea 100644
9226--- a/arch/sparc/include/asm/spinlock_64.h
9227+++ b/arch/sparc/include/asm/spinlock_64.h
9228@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9229
9230 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9231
9232-static void inline arch_read_lock(arch_rwlock_t *lock)
9233+static inline void arch_read_lock(arch_rwlock_t *lock)
9234 {
9235 unsigned long tmp1, tmp2;
9236
9237 __asm__ __volatile__ (
9238 "1: ldsw [%2], %0\n"
9239 " brlz,pn %0, 2f\n"
9240-"4: add %0, 1, %1\n"
9241+"4: addcc %0, 1, %1\n"
9242+
9243+#ifdef CONFIG_PAX_REFCOUNT
9244+" tvs %%icc, 6\n"
9245+#endif
9246+
9247 " cas [%2], %0, %1\n"
9248 " cmp %0, %1\n"
9249 " bne,pn %%icc, 1b\n"
9250@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9251 " .previous"
9252 : "=&r" (tmp1), "=&r" (tmp2)
9253 : "r" (lock)
9254- : "memory");
9255+ : "memory", "cc");
9256 }
9257
9258-static int inline arch_read_trylock(arch_rwlock_t *lock)
9259+static inline int arch_read_trylock(arch_rwlock_t *lock)
9260 {
9261 int tmp1, tmp2;
9262
9263@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9264 "1: ldsw [%2], %0\n"
9265 " brlz,a,pn %0, 2f\n"
9266 " mov 0, %0\n"
9267-" add %0, 1, %1\n"
9268+" addcc %0, 1, %1\n"
9269+
9270+#ifdef CONFIG_PAX_REFCOUNT
9271+" tvs %%icc, 6\n"
9272+#endif
9273+
9274 " cas [%2], %0, %1\n"
9275 " cmp %0, %1\n"
9276 " bne,pn %%icc, 1b\n"
9277@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9278 return tmp1;
9279 }
9280
9281-static void inline arch_read_unlock(arch_rwlock_t *lock)
9282+static inline void arch_read_unlock(arch_rwlock_t *lock)
9283 {
9284 unsigned long tmp1, tmp2;
9285
9286 __asm__ __volatile__(
9287 "1: lduw [%2], %0\n"
9288-" sub %0, 1, %1\n"
9289+" subcc %0, 1, %1\n"
9290+
9291+#ifdef CONFIG_PAX_REFCOUNT
9292+" tvs %%icc, 6\n"
9293+#endif
9294+
9295 " cas [%2], %0, %1\n"
9296 " cmp %0, %1\n"
9297 " bne,pn %%xcc, 1b\n"
9298@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9299 : "memory");
9300 }
9301
9302-static void inline arch_write_lock(arch_rwlock_t *lock)
9303+static inline void arch_write_lock(arch_rwlock_t *lock)
9304 {
9305 unsigned long mask, tmp1, tmp2;
9306
9307@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9308 : "memory");
9309 }
9310
9311-static void inline arch_write_unlock(arch_rwlock_t *lock)
9312+static inline void arch_write_unlock(arch_rwlock_t *lock)
9313 {
9314 __asm__ __volatile__(
9315 " stw %%g0, [%0]"
9316@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9317 : "memory");
9318 }
9319
9320-static int inline arch_write_trylock(arch_rwlock_t *lock)
9321+static inline int arch_write_trylock(arch_rwlock_t *lock)
9322 {
9323 unsigned long mask, tmp1, tmp2, result;
9324
9325diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9326index dd38075..e7cac83 100644
9327--- a/arch/sparc/include/asm/thread_info_32.h
9328+++ b/arch/sparc/include/asm/thread_info_32.h
9329@@ -49,6 +49,8 @@ struct thread_info {
9330 unsigned long w_saved;
9331
9332 struct restart_block restart_block;
9333+
9334+ unsigned long lowest_stack;
9335 };
9336
9337 /*
9338diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9339index d5e5042..9bfee76 100644
9340--- a/arch/sparc/include/asm/thread_info_64.h
9341+++ b/arch/sparc/include/asm/thread_info_64.h
9342@@ -63,6 +63,8 @@ struct thread_info {
9343 struct pt_regs *kern_una_regs;
9344 unsigned int kern_una_insn;
9345
9346+ unsigned long lowest_stack;
9347+
9348 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9349 };
9350
9351@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9352 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9353 /* flag bit 6 is available */
9354 #define TIF_32BIT 7 /* 32-bit binary */
9355-/* flag bit 8 is available */
9356+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9357 #define TIF_SECCOMP 9 /* secure computing */
9358 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9359 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9360+
9361 /* NOTE: Thread flags >= 12 should be ones we have no interest
9362 * in using in assembly, else we can't use the mask as
9363 * an immediate value in instructions such as andcc.
9364@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9365 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9366 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9367 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9368+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9369
9370 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9371 _TIF_DO_NOTIFY_RESUME_MASK | \
9372 _TIF_NEED_RESCHED)
9373 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9374
9375+#define _TIF_WORK_SYSCALL \
9376+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9377+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9378+
9379+
9380 /*
9381 * Thread-synchronous status.
9382 *
9383diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9384index 0167d26..767bb0c 100644
9385--- a/arch/sparc/include/asm/uaccess.h
9386+++ b/arch/sparc/include/asm/uaccess.h
9387@@ -1,5 +1,6 @@
9388 #ifndef ___ASM_SPARC_UACCESS_H
9389 #define ___ASM_SPARC_UACCESS_H
9390+
9391 #if defined(__sparc__) && defined(__arch64__)
9392 #include <asm/uaccess_64.h>
9393 #else
9394diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9395index 53a28dd..50c38c3 100644
9396--- a/arch/sparc/include/asm/uaccess_32.h
9397+++ b/arch/sparc/include/asm/uaccess_32.h
9398@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9399
9400 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9401 {
9402- if (n && __access_ok((unsigned long) to, n))
9403+ if ((long)n < 0)
9404+ return n;
9405+
9406+ if (n && __access_ok((unsigned long) to, n)) {
9407+ if (!__builtin_constant_p(n))
9408+ check_object_size(from, n, true);
9409 return __copy_user(to, (__force void __user *) from, n);
9410- else
9411+ } else
9412 return n;
9413 }
9414
9415 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9416 {
9417+ if ((long)n < 0)
9418+ return n;
9419+
9420+ if (!__builtin_constant_p(n))
9421+ check_object_size(from, n, true);
9422+
9423 return __copy_user(to, (__force void __user *) from, n);
9424 }
9425
9426 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9427 {
9428- if (n && __access_ok((unsigned long) from, n))
9429+ if ((long)n < 0)
9430+ return n;
9431+
9432+ if (n && __access_ok((unsigned long) from, n)) {
9433+ if (!__builtin_constant_p(n))
9434+ check_object_size(to, n, false);
9435 return __copy_user((__force void __user *) to, from, n);
9436- else
9437+ } else
9438 return n;
9439 }
9440
9441 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9442 {
9443+ if ((long)n < 0)
9444+ return n;
9445+
9446 return __copy_user((__force void __user *) to, from, n);
9447 }
9448
9449diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9450index e562d3c..191f176 100644
9451--- a/arch/sparc/include/asm/uaccess_64.h
9452+++ b/arch/sparc/include/asm/uaccess_64.h
9453@@ -10,6 +10,7 @@
9454 #include <linux/compiler.h>
9455 #include <linux/string.h>
9456 #include <linux/thread_info.h>
9457+#include <linux/kernel.h>
9458 #include <asm/asi.h>
9459 #include <asm/spitfire.h>
9460 #include <asm-generic/uaccess-unaligned.h>
9461@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9462 static inline unsigned long __must_check
9463 copy_from_user(void *to, const void __user *from, unsigned long size)
9464 {
9465- unsigned long ret = ___copy_from_user(to, from, size);
9466+ unsigned long ret;
9467
9468+ if ((long)size < 0 || size > INT_MAX)
9469+ return size;
9470+
9471+ if (!__builtin_constant_p(size))
9472+ check_object_size(to, size, false);
9473+
9474+ ret = ___copy_from_user(to, from, size);
9475 if (unlikely(ret))
9476 ret = copy_from_user_fixup(to, from, size);
9477
9478@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9479 static inline unsigned long __must_check
9480 copy_to_user(void __user *to, const void *from, unsigned long size)
9481 {
9482- unsigned long ret = ___copy_to_user(to, from, size);
9483+ unsigned long ret;
9484
9485+ if ((long)size < 0 || size > INT_MAX)
9486+ return size;
9487+
9488+ if (!__builtin_constant_p(size))
9489+ check_object_size(from, size, true);
9490+
9491+ ret = ___copy_to_user(to, from, size);
9492 if (unlikely(ret))
9493 ret = copy_to_user_fixup(to, from, size);
9494 return ret;
9495diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9496index d432fb2..6056af1 100644
9497--- a/arch/sparc/kernel/Makefile
9498+++ b/arch/sparc/kernel/Makefile
9499@@ -3,7 +3,7 @@
9500 #
9501
9502 asflags-y := -ansi
9503-ccflags-y := -Werror
9504+#ccflags-y := -Werror
9505
9506 extra-y := head_$(BITS).o
9507
9508diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9509index fdd819d..5af08c8 100644
9510--- a/arch/sparc/kernel/process_32.c
9511+++ b/arch/sparc/kernel/process_32.c
9512@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9513
9514 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9515 r->psr, r->pc, r->npc, r->y, print_tainted());
9516- printk("PC: <%pS>\n", (void *) r->pc);
9517+ printk("PC: <%pA>\n", (void *) r->pc);
9518 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9519 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9520 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9521 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9522 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9523 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9524- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9525+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9526
9527 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9528 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9529@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9530 rw = (struct reg_window32 *) fp;
9531 pc = rw->ins[7];
9532 printk("[%08lx : ", pc);
9533- printk("%pS ] ", (void *) pc);
9534+ printk("%pA ] ", (void *) pc);
9535 fp = rw->ins[6];
9536 } while (++count < 16);
9537 printk("\n");
9538diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9539index baebab2..9cd13b1 100644
9540--- a/arch/sparc/kernel/process_64.c
9541+++ b/arch/sparc/kernel/process_64.c
9542@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9543 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9544 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9545 if (regs->tstate & TSTATE_PRIV)
9546- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9547+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9548 }
9549
9550 void show_regs(struct pt_regs *regs)
9551@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9552
9553 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9554 regs->tpc, regs->tnpc, regs->y, print_tainted());
9555- printk("TPC: <%pS>\n", (void *) regs->tpc);
9556+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9557 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9558 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9559 regs->u_regs[3]);
9560@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9561 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9562 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9563 regs->u_regs[15]);
9564- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9565+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9566 show_regwindow(regs);
9567 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9568 }
9569@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9570 ((tp && tp->task) ? tp->task->pid : -1));
9571
9572 if (gp->tstate & TSTATE_PRIV) {
9573- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9574+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9575 (void *) gp->tpc,
9576 (void *) gp->o7,
9577 (void *) gp->i7,
9578diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9579index 79cc0d1..ec62734 100644
9580--- a/arch/sparc/kernel/prom_common.c
9581+++ b/arch/sparc/kernel/prom_common.c
9582@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9583
9584 unsigned int prom_early_allocated __initdata;
9585
9586-static struct of_pdt_ops prom_sparc_ops __initdata = {
9587+static struct of_pdt_ops prom_sparc_ops __initconst = {
9588 .nextprop = prom_common_nextprop,
9589 .getproplen = prom_getproplen,
9590 .getproperty = prom_getproperty,
9591diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9592index 7ff45e4..a58f271 100644
9593--- a/arch/sparc/kernel/ptrace_64.c
9594+++ b/arch/sparc/kernel/ptrace_64.c
9595@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9596 return ret;
9597 }
9598
9599+#ifdef CONFIG_GRKERNSEC_SETXID
9600+extern void gr_delayed_cred_worker(void);
9601+#endif
9602+
9603 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9604 {
9605 int ret = 0;
9606@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9607 /* do the secure computing check first */
9608 secure_computing_strict(regs->u_regs[UREG_G1]);
9609
9610+#ifdef CONFIG_GRKERNSEC_SETXID
9611+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9612+ gr_delayed_cred_worker();
9613+#endif
9614+
9615 if (test_thread_flag(TIF_SYSCALL_TRACE))
9616 ret = tracehook_report_syscall_entry(regs);
9617
9618@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9619
9620 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9621 {
9622+#ifdef CONFIG_GRKERNSEC_SETXID
9623+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9624+ gr_delayed_cred_worker();
9625+#endif
9626+
9627 audit_syscall_exit(regs);
9628
9629 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9630diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9631index e142545..fd29654 100644
9632--- a/arch/sparc/kernel/smp_64.c
9633+++ b/arch/sparc/kernel/smp_64.c
9634@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9635 extern unsigned long xcall_flush_dcache_page_spitfire;
9636
9637 #ifdef CONFIG_DEBUG_DCFLUSH
9638-extern atomic_t dcpage_flushes;
9639-extern atomic_t dcpage_flushes_xcall;
9640+extern atomic_unchecked_t dcpage_flushes;
9641+extern atomic_unchecked_t dcpage_flushes_xcall;
9642 #endif
9643
9644 static inline void __local_flush_dcache_page(struct page *page)
9645@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9646 return;
9647
9648 #ifdef CONFIG_DEBUG_DCFLUSH
9649- atomic_inc(&dcpage_flushes);
9650+ atomic_inc_unchecked(&dcpage_flushes);
9651 #endif
9652
9653 this_cpu = get_cpu();
9654@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9655 xcall_deliver(data0, __pa(pg_addr),
9656 (u64) pg_addr, cpumask_of(cpu));
9657 #ifdef CONFIG_DEBUG_DCFLUSH
9658- atomic_inc(&dcpage_flushes_xcall);
9659+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9660 #endif
9661 }
9662 }
9663@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9664 preempt_disable();
9665
9666 #ifdef CONFIG_DEBUG_DCFLUSH
9667- atomic_inc(&dcpage_flushes);
9668+ atomic_inc_unchecked(&dcpage_flushes);
9669 #endif
9670 data0 = 0;
9671 pg_addr = page_address(page);
9672@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9673 xcall_deliver(data0, __pa(pg_addr),
9674 (u64) pg_addr, cpu_online_mask);
9675 #ifdef CONFIG_DEBUG_DCFLUSH
9676- atomic_inc(&dcpage_flushes_xcall);
9677+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9678 #endif
9679 }
9680 __local_flush_dcache_page(page);
9681diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9682index 3a8d184..49498a8 100644
9683--- a/arch/sparc/kernel/sys_sparc_32.c
9684+++ b/arch/sparc/kernel/sys_sparc_32.c
9685@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9686 if (len > TASK_SIZE - PAGE_SIZE)
9687 return -ENOMEM;
9688 if (!addr)
9689- addr = TASK_UNMAPPED_BASE;
9690+ addr = current->mm->mmap_base;
9691
9692 info.flags = 0;
9693 info.length = len;
9694diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9695index 51561b8..8256764 100644
9696--- a/arch/sparc/kernel/sys_sparc_64.c
9697+++ b/arch/sparc/kernel/sys_sparc_64.c
9698@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9699 struct vm_area_struct * vma;
9700 unsigned long task_size = TASK_SIZE;
9701 int do_color_align;
9702+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9703 struct vm_unmapped_area_info info;
9704
9705 if (flags & MAP_FIXED) {
9706 /* We do not accept a shared mapping if it would violate
9707 * cache aliasing constraints.
9708 */
9709- if ((flags & MAP_SHARED) &&
9710+ if ((filp || (flags & MAP_SHARED)) &&
9711 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9712 return -EINVAL;
9713 return addr;
9714@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9715 if (filp || (flags & MAP_SHARED))
9716 do_color_align = 1;
9717
9718+#ifdef CONFIG_PAX_RANDMMAP
9719+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9720+#endif
9721+
9722 if (addr) {
9723 if (do_color_align)
9724 addr = COLOR_ALIGN(addr, pgoff);
9725@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9726 addr = PAGE_ALIGN(addr);
9727
9728 vma = find_vma(mm, addr);
9729- if (task_size - len >= addr &&
9730- (!vma || addr + len <= vma->vm_start))
9731+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9732 return addr;
9733 }
9734
9735 info.flags = 0;
9736 info.length = len;
9737- info.low_limit = TASK_UNMAPPED_BASE;
9738+ info.low_limit = mm->mmap_base;
9739 info.high_limit = min(task_size, VA_EXCLUDE_START);
9740 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9741 info.align_offset = pgoff << PAGE_SHIFT;
9742+ info.threadstack_offset = offset;
9743 addr = vm_unmapped_area(&info);
9744
9745 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9746 VM_BUG_ON(addr != -ENOMEM);
9747 info.low_limit = VA_EXCLUDE_END;
9748+
9749+#ifdef CONFIG_PAX_RANDMMAP
9750+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9751+ info.low_limit += mm->delta_mmap;
9752+#endif
9753+
9754 info.high_limit = task_size;
9755 addr = vm_unmapped_area(&info);
9756 }
9757@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9758 unsigned long task_size = STACK_TOP32;
9759 unsigned long addr = addr0;
9760 int do_color_align;
9761+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9762 struct vm_unmapped_area_info info;
9763
9764 /* This should only ever run for 32-bit processes. */
9765@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9766 /* We do not accept a shared mapping if it would violate
9767 * cache aliasing constraints.
9768 */
9769- if ((flags & MAP_SHARED) &&
9770+ if ((filp || (flags & MAP_SHARED)) &&
9771 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9772 return -EINVAL;
9773 return addr;
9774@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9775 if (filp || (flags & MAP_SHARED))
9776 do_color_align = 1;
9777
9778+#ifdef CONFIG_PAX_RANDMMAP
9779+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9780+#endif
9781+
9782 /* requesting a specific address */
9783 if (addr) {
9784 if (do_color_align)
9785@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9786 addr = PAGE_ALIGN(addr);
9787
9788 vma = find_vma(mm, addr);
9789- if (task_size - len >= addr &&
9790- (!vma || addr + len <= vma->vm_start))
9791+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9792 return addr;
9793 }
9794
9795@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9796 info.high_limit = mm->mmap_base;
9797 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9798 info.align_offset = pgoff << PAGE_SHIFT;
9799+ info.threadstack_offset = offset;
9800 addr = vm_unmapped_area(&info);
9801
9802 /*
9803@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9804 VM_BUG_ON(addr != -ENOMEM);
9805 info.flags = 0;
9806 info.low_limit = TASK_UNMAPPED_BASE;
9807+
9808+#ifdef CONFIG_PAX_RANDMMAP
9809+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9810+ info.low_limit += mm->delta_mmap;
9811+#endif
9812+
9813 info.high_limit = STACK_TOP32;
9814 addr = vm_unmapped_area(&info);
9815 }
9816@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9817 EXPORT_SYMBOL(get_fb_unmapped_area);
9818
9819 /* Essentially the same as PowerPC. */
9820-static unsigned long mmap_rnd(void)
9821+static unsigned long mmap_rnd(struct mm_struct *mm)
9822 {
9823 unsigned long rnd = 0UL;
9824
9825+#ifdef CONFIG_PAX_RANDMMAP
9826+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9827+#endif
9828+
9829 if (current->flags & PF_RANDOMIZE) {
9830 unsigned long val = get_random_int();
9831 if (test_thread_flag(TIF_32BIT))
9832@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9833
9834 void arch_pick_mmap_layout(struct mm_struct *mm)
9835 {
9836- unsigned long random_factor = mmap_rnd();
9837+ unsigned long random_factor = mmap_rnd(mm);
9838 unsigned long gap;
9839
9840 /*
9841@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9842 gap == RLIM_INFINITY ||
9843 sysctl_legacy_va_layout) {
9844 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9845+
9846+#ifdef CONFIG_PAX_RANDMMAP
9847+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9848+ mm->mmap_base += mm->delta_mmap;
9849+#endif
9850+
9851 mm->get_unmapped_area = arch_get_unmapped_area;
9852 } else {
9853 /* We know it's 32-bit */
9854@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9855 gap = (task_size / 6 * 5);
9856
9857 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9858+
9859+#ifdef CONFIG_PAX_RANDMMAP
9860+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9861+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9862+#endif
9863+
9864 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9865 }
9866 }
9867diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9868index 73ec8a7..4611979 100644
9869--- a/arch/sparc/kernel/syscalls.S
9870+++ b/arch/sparc/kernel/syscalls.S
9871@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9872 #endif
9873 .align 32
9874 1: ldx [%g6 + TI_FLAGS], %l5
9875- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9876+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9877 be,pt %icc, rtrap
9878 nop
9879 call syscall_trace_leave
9880@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9881
9882 srl %i3, 0, %o3 ! IEU0
9883 srl %i2, 0, %o2 ! IEU0 Group
9884- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9885+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9886 bne,pn %icc, linux_syscall_trace32 ! CTI
9887 mov %i0, %l5 ! IEU1
9888 5: call %l7 ! CTI Group brk forced
9889@@ -207,7 +207,7 @@ linux_sparc_syscall:
9890
9891 mov %i3, %o3 ! IEU1
9892 mov %i4, %o4 ! IEU0 Group
9893- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9894+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9895 bne,pn %icc, linux_syscall_trace ! CTI Group
9896 mov %i0, %l5 ! IEU0
9897 2: call %l7 ! CTI Group brk forced
9898@@ -223,7 +223,7 @@ ret_sys_call:
9899
9900 cmp %o0, -ERESTART_RESTARTBLOCK
9901 bgeu,pn %xcc, 1f
9902- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9903+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9904 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9905
9906 2:
9907diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9908index 6629829..036032d 100644
9909--- a/arch/sparc/kernel/traps_32.c
9910+++ b/arch/sparc/kernel/traps_32.c
9911@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9912 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9913 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9914
9915+extern void gr_handle_kernel_exploit(void);
9916+
9917 void die_if_kernel(char *str, struct pt_regs *regs)
9918 {
9919 static int die_counter;
9920@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9921 count++ < 30 &&
9922 (((unsigned long) rw) >= PAGE_OFFSET) &&
9923 !(((unsigned long) rw) & 0x7)) {
9924- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9925+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9926 (void *) rw->ins[7]);
9927 rw = (struct reg_window32 *)rw->ins[6];
9928 }
9929 }
9930 printk("Instruction DUMP:");
9931 instruction_dump ((unsigned long *) regs->pc);
9932- if(regs->psr & PSR_PS)
9933+ if(regs->psr & PSR_PS) {
9934+ gr_handle_kernel_exploit();
9935 do_exit(SIGKILL);
9936+ }
9937 do_exit(SIGSEGV);
9938 }
9939
9940diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9941index b3f833a..f485f80 100644
9942--- a/arch/sparc/kernel/traps_64.c
9943+++ b/arch/sparc/kernel/traps_64.c
9944@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9945 i + 1,
9946 p->trapstack[i].tstate, p->trapstack[i].tpc,
9947 p->trapstack[i].tnpc, p->trapstack[i].tt);
9948- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9949+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9950 }
9951 }
9952
9953@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9954
9955 lvl -= 0x100;
9956 if (regs->tstate & TSTATE_PRIV) {
9957+
9958+#ifdef CONFIG_PAX_REFCOUNT
9959+ if (lvl == 6)
9960+ pax_report_refcount_overflow(regs);
9961+#endif
9962+
9963 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9964 die_if_kernel(buffer, regs);
9965 }
9966@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9967 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9968 {
9969 char buffer[32];
9970-
9971+
9972 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9973 0, lvl, SIGTRAP) == NOTIFY_STOP)
9974 return;
9975
9976+#ifdef CONFIG_PAX_REFCOUNT
9977+ if (lvl == 6)
9978+ pax_report_refcount_overflow(regs);
9979+#endif
9980+
9981 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9982
9983 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9984@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9985 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9986 printk("%s" "ERROR(%d): ",
9987 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9988- printk("TPC<%pS>\n", (void *) regs->tpc);
9989+ printk("TPC<%pA>\n", (void *) regs->tpc);
9990 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9991 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9992 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9993@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9994 smp_processor_id(),
9995 (type & 0x1) ? 'I' : 'D',
9996 regs->tpc);
9997- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9998+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9999 panic("Irrecoverable Cheetah+ parity error.");
10000 }
10001
10002@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10003 smp_processor_id(),
10004 (type & 0x1) ? 'I' : 'D',
10005 regs->tpc);
10006- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10007+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10008 }
10009
10010 struct sun4v_error_entry {
10011@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10012 /*0x38*/u64 reserved_5;
10013 };
10014
10015-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10016-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10017+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10018+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10019
10020 static const char *sun4v_err_type_to_str(u8 type)
10021 {
10022@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10023 }
10024
10025 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10026- int cpu, const char *pfx, atomic_t *ocnt)
10027+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10028 {
10029 u64 *raw_ptr = (u64 *) ent;
10030 u32 attrs;
10031@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10032
10033 show_regs(regs);
10034
10035- if ((cnt = atomic_read(ocnt)) != 0) {
10036- atomic_set(ocnt, 0);
10037+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10038+ atomic_set_unchecked(ocnt, 0);
10039 wmb();
10040 printk("%s: Queue overflowed %d times.\n",
10041 pfx, cnt);
10042@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10043 */
10044 void sun4v_resum_overflow(struct pt_regs *regs)
10045 {
10046- atomic_inc(&sun4v_resum_oflow_cnt);
10047+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10048 }
10049
10050 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10051@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10052 /* XXX Actually even this can make not that much sense. Perhaps
10053 * XXX we should just pull the plug and panic directly from here?
10054 */
10055- atomic_inc(&sun4v_nonresum_oflow_cnt);
10056+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10057 }
10058
10059 unsigned long sun4v_err_itlb_vaddr;
10060@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10061
10062 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10063 regs->tpc, tl);
10064- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10065+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10066 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10067- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10068+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10069 (void *) regs->u_regs[UREG_I7]);
10070 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10071 "pte[%lx] error[%lx]\n",
10072@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10073
10074 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10075 regs->tpc, tl);
10076- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10077+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10078 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10079- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10080+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10081 (void *) regs->u_regs[UREG_I7]);
10082 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10083 "pte[%lx] error[%lx]\n",
10084@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10085 fp = (unsigned long)sf->fp + STACK_BIAS;
10086 }
10087
10088- printk(" [%016lx] %pS\n", pc, (void *) pc);
10089+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10090 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10091 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10092 int index = tsk->curr_ret_stack;
10093 if (tsk->ret_stack && index >= graph) {
10094 pc = tsk->ret_stack[index - graph].ret;
10095- printk(" [%016lx] %pS\n", pc, (void *) pc);
10096+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10097 graph++;
10098 }
10099 }
10100@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10101 return (struct reg_window *) (fp + STACK_BIAS);
10102 }
10103
10104+extern void gr_handle_kernel_exploit(void);
10105+
10106 void die_if_kernel(char *str, struct pt_regs *regs)
10107 {
10108 static int die_counter;
10109@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10110 while (rw &&
10111 count++ < 30 &&
10112 kstack_valid(tp, (unsigned long) rw)) {
10113- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10114+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10115 (void *) rw->ins[7]);
10116
10117 rw = kernel_stack_up(rw);
10118@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10119 }
10120 user_instruction_dump ((unsigned int __user *) regs->tpc);
10121 }
10122- if (regs->tstate & TSTATE_PRIV)
10123+ if (regs->tstate & TSTATE_PRIV) {
10124+ gr_handle_kernel_exploit();
10125 do_exit(SIGKILL);
10126+ }
10127 do_exit(SIGSEGV);
10128 }
10129 EXPORT_SYMBOL(die_if_kernel);
10130diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10131index 8201c25e..072a2a7 100644
10132--- a/arch/sparc/kernel/unaligned_64.c
10133+++ b/arch/sparc/kernel/unaligned_64.c
10134@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10135 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10136
10137 if (__ratelimit(&ratelimit)) {
10138- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10139+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10140 regs->tpc, (void *) regs->tpc);
10141 }
10142 }
10143diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10144index dbe119b..089c7c1 100644
10145--- a/arch/sparc/lib/Makefile
10146+++ b/arch/sparc/lib/Makefile
10147@@ -2,7 +2,7 @@
10148 #
10149
10150 asflags-y := -ansi -DST_DIV0=0x02
10151-ccflags-y := -Werror
10152+#ccflags-y := -Werror
10153
10154 lib-$(CONFIG_SPARC32) += ashrdi3.o
10155 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10156diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10157index 85c233d..68500e0 100644
10158--- a/arch/sparc/lib/atomic_64.S
10159+++ b/arch/sparc/lib/atomic_64.S
10160@@ -17,7 +17,12 @@
10161 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10162 BACKOFF_SETUP(%o2)
10163 1: lduw [%o1], %g1
10164- add %g1, %o0, %g7
10165+ addcc %g1, %o0, %g7
10166+
10167+#ifdef CONFIG_PAX_REFCOUNT
10168+ tvs %icc, 6
10169+#endif
10170+
10171 cas [%o1], %g1, %g7
10172 cmp %g1, %g7
10173 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10174@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10175 2: BACKOFF_SPIN(%o2, %o3, 1b)
10176 ENDPROC(atomic_add)
10177
10178+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10179+ BACKOFF_SETUP(%o2)
10180+1: lduw [%o1], %g1
10181+ add %g1, %o0, %g7
10182+ cas [%o1], %g1, %g7
10183+ cmp %g1, %g7
10184+ bne,pn %icc, 2f
10185+ nop
10186+ retl
10187+ nop
10188+2: BACKOFF_SPIN(%o2, %o3, 1b)
10189+ENDPROC(atomic_add_unchecked)
10190+
10191 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10192 BACKOFF_SETUP(%o2)
10193 1: lduw [%o1], %g1
10194- sub %g1, %o0, %g7
10195+ subcc %g1, %o0, %g7
10196+
10197+#ifdef CONFIG_PAX_REFCOUNT
10198+ tvs %icc, 6
10199+#endif
10200+
10201 cas [%o1], %g1, %g7
10202 cmp %g1, %g7
10203 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10204@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10205 2: BACKOFF_SPIN(%o2, %o3, 1b)
10206 ENDPROC(atomic_sub)
10207
10208+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10209+ BACKOFF_SETUP(%o2)
10210+1: lduw [%o1], %g1
10211+ sub %g1, %o0, %g7
10212+ cas [%o1], %g1, %g7
10213+ cmp %g1, %g7
10214+ bne,pn %icc, 2f
10215+ nop
10216+ retl
10217+ nop
10218+2: BACKOFF_SPIN(%o2, %o3, 1b)
10219+ENDPROC(atomic_sub_unchecked)
10220+
10221 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10222 BACKOFF_SETUP(%o2)
10223 1: lduw [%o1], %g1
10224- add %g1, %o0, %g7
10225+ addcc %g1, %o0, %g7
10226+
10227+#ifdef CONFIG_PAX_REFCOUNT
10228+ tvs %icc, 6
10229+#endif
10230+
10231 cas [%o1], %g1, %g7
10232 cmp %g1, %g7
10233 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10234@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10235 2: BACKOFF_SPIN(%o2, %o3, 1b)
10236 ENDPROC(atomic_add_ret)
10237
10238+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10239+ BACKOFF_SETUP(%o2)
10240+1: lduw [%o1], %g1
10241+ addcc %g1, %o0, %g7
10242+ cas [%o1], %g1, %g7
10243+ cmp %g1, %g7
10244+ bne,pn %icc, 2f
10245+ add %g7, %o0, %g7
10246+ sra %g7, 0, %o0
10247+ retl
10248+ nop
10249+2: BACKOFF_SPIN(%o2, %o3, 1b)
10250+ENDPROC(atomic_add_ret_unchecked)
10251+
10252 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10253 BACKOFF_SETUP(%o2)
10254 1: lduw [%o1], %g1
10255- sub %g1, %o0, %g7
10256+ subcc %g1, %o0, %g7
10257+
10258+#ifdef CONFIG_PAX_REFCOUNT
10259+ tvs %icc, 6
10260+#endif
10261+
10262 cas [%o1], %g1, %g7
10263 cmp %g1, %g7
10264 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10265@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10266 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10267 BACKOFF_SETUP(%o2)
10268 1: ldx [%o1], %g1
10269- add %g1, %o0, %g7
10270+ addcc %g1, %o0, %g7
10271+
10272+#ifdef CONFIG_PAX_REFCOUNT
10273+ tvs %xcc, 6
10274+#endif
10275+
10276 casx [%o1], %g1, %g7
10277 cmp %g1, %g7
10278 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10279@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10280 2: BACKOFF_SPIN(%o2, %o3, 1b)
10281 ENDPROC(atomic64_add)
10282
10283+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10284+ BACKOFF_SETUP(%o2)
10285+1: ldx [%o1], %g1
10286+ addcc %g1, %o0, %g7
10287+ casx [%o1], %g1, %g7
10288+ cmp %g1, %g7
10289+ bne,pn %xcc, 2f
10290+ nop
10291+ retl
10292+ nop
10293+2: BACKOFF_SPIN(%o2, %o3, 1b)
10294+ENDPROC(atomic64_add_unchecked)
10295+
10296 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10297 BACKOFF_SETUP(%o2)
10298 1: ldx [%o1], %g1
10299- sub %g1, %o0, %g7
10300+ subcc %g1, %o0, %g7
10301+
10302+#ifdef CONFIG_PAX_REFCOUNT
10303+ tvs %xcc, 6
10304+#endif
10305+
10306 casx [%o1], %g1, %g7
10307 cmp %g1, %g7
10308 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10309@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10310 2: BACKOFF_SPIN(%o2, %o3, 1b)
10311 ENDPROC(atomic64_sub)
10312
10313+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10314+ BACKOFF_SETUP(%o2)
10315+1: ldx [%o1], %g1
10316+ subcc %g1, %o0, %g7
10317+ casx [%o1], %g1, %g7
10318+ cmp %g1, %g7
10319+ bne,pn %xcc, 2f
10320+ nop
10321+ retl
10322+ nop
10323+2: BACKOFF_SPIN(%o2, %o3, 1b)
10324+ENDPROC(atomic64_sub_unchecked)
10325+
10326 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10327 BACKOFF_SETUP(%o2)
10328 1: ldx [%o1], %g1
10329- add %g1, %o0, %g7
10330+ addcc %g1, %o0, %g7
10331+
10332+#ifdef CONFIG_PAX_REFCOUNT
10333+ tvs %xcc, 6
10334+#endif
10335+
10336 casx [%o1], %g1, %g7
10337 cmp %g1, %g7
10338 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10339@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10340 2: BACKOFF_SPIN(%o2, %o3, 1b)
10341 ENDPROC(atomic64_add_ret)
10342
10343+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10344+ BACKOFF_SETUP(%o2)
10345+1: ldx [%o1], %g1
10346+ addcc %g1, %o0, %g7
10347+ casx [%o1], %g1, %g7
10348+ cmp %g1, %g7
10349+ bne,pn %xcc, 2f
10350+ add %g7, %o0, %g7
10351+ mov %g7, %o0
10352+ retl
10353+ nop
10354+2: BACKOFF_SPIN(%o2, %o3, 1b)
10355+ENDPROC(atomic64_add_ret_unchecked)
10356+
10357 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10358 BACKOFF_SETUP(%o2)
10359 1: ldx [%o1], %g1
10360- sub %g1, %o0, %g7
10361+ subcc %g1, %o0, %g7
10362+
10363+#ifdef CONFIG_PAX_REFCOUNT
10364+ tvs %xcc, 6
10365+#endif
10366+
10367 casx [%o1], %g1, %g7
10368 cmp %g1, %g7
10369 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10370diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10371index 323335b..ed85ea2 100644
10372--- a/arch/sparc/lib/ksyms.c
10373+++ b/arch/sparc/lib/ksyms.c
10374@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10375
10376 /* Atomic counter implementation. */
10377 EXPORT_SYMBOL(atomic_add);
10378+EXPORT_SYMBOL(atomic_add_unchecked);
10379 EXPORT_SYMBOL(atomic_add_ret);
10380+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10381 EXPORT_SYMBOL(atomic_sub);
10382+EXPORT_SYMBOL(atomic_sub_unchecked);
10383 EXPORT_SYMBOL(atomic_sub_ret);
10384 EXPORT_SYMBOL(atomic64_add);
10385+EXPORT_SYMBOL(atomic64_add_unchecked);
10386 EXPORT_SYMBOL(atomic64_add_ret);
10387+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10388 EXPORT_SYMBOL(atomic64_sub);
10389+EXPORT_SYMBOL(atomic64_sub_unchecked);
10390 EXPORT_SYMBOL(atomic64_sub_ret);
10391 EXPORT_SYMBOL(atomic64_dec_if_positive);
10392
10393diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10394index 30c3ecc..736f015 100644
10395--- a/arch/sparc/mm/Makefile
10396+++ b/arch/sparc/mm/Makefile
10397@@ -2,7 +2,7 @@
10398 #
10399
10400 asflags-y := -ansi
10401-ccflags-y := -Werror
10402+#ccflags-y := -Werror
10403
10404 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10405 obj-y += fault_$(BITS).o
10406diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10407index e98bfda..ea8d221 100644
10408--- a/arch/sparc/mm/fault_32.c
10409+++ b/arch/sparc/mm/fault_32.c
10410@@ -21,6 +21,9 @@
10411 #include <linux/perf_event.h>
10412 #include <linux/interrupt.h>
10413 #include <linux/kdebug.h>
10414+#include <linux/slab.h>
10415+#include <linux/pagemap.h>
10416+#include <linux/compiler.h>
10417
10418 #include <asm/page.h>
10419 #include <asm/pgtable.h>
10420@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10421 return safe_compute_effective_address(regs, insn);
10422 }
10423
10424+#ifdef CONFIG_PAX_PAGEEXEC
10425+#ifdef CONFIG_PAX_DLRESOLVE
10426+static void pax_emuplt_close(struct vm_area_struct *vma)
10427+{
10428+ vma->vm_mm->call_dl_resolve = 0UL;
10429+}
10430+
10431+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10432+{
10433+ unsigned int *kaddr;
10434+
10435+ vmf->page = alloc_page(GFP_HIGHUSER);
10436+ if (!vmf->page)
10437+ return VM_FAULT_OOM;
10438+
10439+ kaddr = kmap(vmf->page);
10440+ memset(kaddr, 0, PAGE_SIZE);
10441+ kaddr[0] = 0x9DE3BFA8U; /* save */
10442+ flush_dcache_page(vmf->page);
10443+ kunmap(vmf->page);
10444+ return VM_FAULT_MAJOR;
10445+}
10446+
10447+static const struct vm_operations_struct pax_vm_ops = {
10448+ .close = pax_emuplt_close,
10449+ .fault = pax_emuplt_fault
10450+};
10451+
10452+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10453+{
10454+ int ret;
10455+
10456+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10457+ vma->vm_mm = current->mm;
10458+ vma->vm_start = addr;
10459+ vma->vm_end = addr + PAGE_SIZE;
10460+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10461+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10462+ vma->vm_ops = &pax_vm_ops;
10463+
10464+ ret = insert_vm_struct(current->mm, vma);
10465+ if (ret)
10466+ return ret;
10467+
10468+ ++current->mm->total_vm;
10469+ return 0;
10470+}
10471+#endif
10472+
10473+/*
10474+ * PaX: decide what to do with offenders (regs->pc = fault address)
10475+ *
10476+ * returns 1 when task should be killed
10477+ * 2 when patched PLT trampoline was detected
10478+ * 3 when unpatched PLT trampoline was detected
10479+ */
10480+static int pax_handle_fetch_fault(struct pt_regs *regs)
10481+{
10482+
10483+#ifdef CONFIG_PAX_EMUPLT
10484+ int err;
10485+
10486+ do { /* PaX: patched PLT emulation #1 */
10487+ unsigned int sethi1, sethi2, jmpl;
10488+
10489+ err = get_user(sethi1, (unsigned int *)regs->pc);
10490+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10491+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10492+
10493+ if (err)
10494+ break;
10495+
10496+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10497+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10498+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10499+ {
10500+ unsigned int addr;
10501+
10502+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10503+ addr = regs->u_regs[UREG_G1];
10504+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10505+ regs->pc = addr;
10506+ regs->npc = addr+4;
10507+ return 2;
10508+ }
10509+ } while (0);
10510+
10511+ do { /* PaX: patched PLT emulation #2 */
10512+ unsigned int ba;
10513+
10514+ err = get_user(ba, (unsigned int *)regs->pc);
10515+
10516+ if (err)
10517+ break;
10518+
10519+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10520+ unsigned int addr;
10521+
10522+ if ((ba & 0xFFC00000U) == 0x30800000U)
10523+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10524+ else
10525+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10526+ regs->pc = addr;
10527+ regs->npc = addr+4;
10528+ return 2;
10529+ }
10530+ } while (0);
10531+
10532+ do { /* PaX: patched PLT emulation #3 */
10533+ unsigned int sethi, bajmpl, nop;
10534+
10535+ err = get_user(sethi, (unsigned int *)regs->pc);
10536+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10537+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10538+
10539+ if (err)
10540+ break;
10541+
10542+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10543+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10544+ nop == 0x01000000U)
10545+ {
10546+ unsigned int addr;
10547+
10548+ addr = (sethi & 0x003FFFFFU) << 10;
10549+ regs->u_regs[UREG_G1] = addr;
10550+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10551+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10552+ else
10553+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10554+ regs->pc = addr;
10555+ regs->npc = addr+4;
10556+ return 2;
10557+ }
10558+ } while (0);
10559+
10560+ do { /* PaX: unpatched PLT emulation step 1 */
10561+ unsigned int sethi, ba, nop;
10562+
10563+ err = get_user(sethi, (unsigned int *)regs->pc);
10564+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10565+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10566+
10567+ if (err)
10568+ break;
10569+
10570+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10571+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10572+ nop == 0x01000000U)
10573+ {
10574+ unsigned int addr, save, call;
10575+
10576+ if ((ba & 0xFFC00000U) == 0x30800000U)
10577+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10578+ else
10579+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10580+
10581+ err = get_user(save, (unsigned int *)addr);
10582+ err |= get_user(call, (unsigned int *)(addr+4));
10583+ err |= get_user(nop, (unsigned int *)(addr+8));
10584+ if (err)
10585+ break;
10586+
10587+#ifdef CONFIG_PAX_DLRESOLVE
10588+ if (save == 0x9DE3BFA8U &&
10589+ (call & 0xC0000000U) == 0x40000000U &&
10590+ nop == 0x01000000U)
10591+ {
10592+ struct vm_area_struct *vma;
10593+ unsigned long call_dl_resolve;
10594+
10595+ down_read(&current->mm->mmap_sem);
10596+ call_dl_resolve = current->mm->call_dl_resolve;
10597+ up_read(&current->mm->mmap_sem);
10598+ if (likely(call_dl_resolve))
10599+ goto emulate;
10600+
10601+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10602+
10603+ down_write(&current->mm->mmap_sem);
10604+ if (current->mm->call_dl_resolve) {
10605+ call_dl_resolve = current->mm->call_dl_resolve;
10606+ up_write(&current->mm->mmap_sem);
10607+ if (vma)
10608+ kmem_cache_free(vm_area_cachep, vma);
10609+ goto emulate;
10610+ }
10611+
10612+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10613+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10614+ up_write(&current->mm->mmap_sem);
10615+ if (vma)
10616+ kmem_cache_free(vm_area_cachep, vma);
10617+ return 1;
10618+ }
10619+
10620+ if (pax_insert_vma(vma, call_dl_resolve)) {
10621+ up_write(&current->mm->mmap_sem);
10622+ kmem_cache_free(vm_area_cachep, vma);
10623+ return 1;
10624+ }
10625+
10626+ current->mm->call_dl_resolve = call_dl_resolve;
10627+ up_write(&current->mm->mmap_sem);
10628+
10629+emulate:
10630+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10631+ regs->pc = call_dl_resolve;
10632+ regs->npc = addr+4;
10633+ return 3;
10634+ }
10635+#endif
10636+
10637+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10638+ if ((save & 0xFFC00000U) == 0x05000000U &&
10639+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10640+ nop == 0x01000000U)
10641+ {
10642+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10643+ regs->u_regs[UREG_G2] = addr + 4;
10644+ addr = (save & 0x003FFFFFU) << 10;
10645+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10646+ regs->pc = addr;
10647+ regs->npc = addr+4;
10648+ return 3;
10649+ }
10650+ }
10651+ } while (0);
10652+
10653+ do { /* PaX: unpatched PLT emulation step 2 */
10654+ unsigned int save, call, nop;
10655+
10656+ err = get_user(save, (unsigned int *)(regs->pc-4));
10657+ err |= get_user(call, (unsigned int *)regs->pc);
10658+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10659+ if (err)
10660+ break;
10661+
10662+ if (save == 0x9DE3BFA8U &&
10663+ (call & 0xC0000000U) == 0x40000000U &&
10664+ nop == 0x01000000U)
10665+ {
10666+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10667+
10668+ regs->u_regs[UREG_RETPC] = regs->pc;
10669+ regs->pc = dl_resolve;
10670+ regs->npc = dl_resolve+4;
10671+ return 3;
10672+ }
10673+ } while (0);
10674+#endif
10675+
10676+ return 1;
10677+}
10678+
10679+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10680+{
10681+ unsigned long i;
10682+
10683+ printk(KERN_ERR "PAX: bytes at PC: ");
10684+ for (i = 0; i < 8; i++) {
10685+ unsigned int c;
10686+ if (get_user(c, (unsigned int *)pc+i))
10687+ printk(KERN_CONT "???????? ");
10688+ else
10689+ printk(KERN_CONT "%08x ", c);
10690+ }
10691+ printk("\n");
10692+}
10693+#endif
10694+
10695 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10696 int text_fault)
10697 {
10698@@ -230,6 +504,24 @@ good_area:
10699 if (!(vma->vm_flags & VM_WRITE))
10700 goto bad_area;
10701 } else {
10702+
10703+#ifdef CONFIG_PAX_PAGEEXEC
10704+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10705+ up_read(&mm->mmap_sem);
10706+ switch (pax_handle_fetch_fault(regs)) {
10707+
10708+#ifdef CONFIG_PAX_EMUPLT
10709+ case 2:
10710+ case 3:
10711+ return;
10712+#endif
10713+
10714+ }
10715+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10716+ do_group_exit(SIGKILL);
10717+ }
10718+#endif
10719+
10720 /* Allow reads even for write-only mappings */
10721 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10722 goto bad_area;
10723diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10724index 5062ff3..e0b75f3 100644
10725--- a/arch/sparc/mm/fault_64.c
10726+++ b/arch/sparc/mm/fault_64.c
10727@@ -21,6 +21,9 @@
10728 #include <linux/kprobes.h>
10729 #include <linux/kdebug.h>
10730 #include <linux/percpu.h>
10731+#include <linux/slab.h>
10732+#include <linux/pagemap.h>
10733+#include <linux/compiler.h>
10734
10735 #include <asm/page.h>
10736 #include <asm/pgtable.h>
10737@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10738 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10739 regs->tpc);
10740 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10741- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10742+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10743 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10744 dump_stack();
10745 unhandled_fault(regs->tpc, current, regs);
10746@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10747 show_regs(regs);
10748 }
10749
10750+#ifdef CONFIG_PAX_PAGEEXEC
10751+#ifdef CONFIG_PAX_DLRESOLVE
10752+static void pax_emuplt_close(struct vm_area_struct *vma)
10753+{
10754+ vma->vm_mm->call_dl_resolve = 0UL;
10755+}
10756+
10757+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10758+{
10759+ unsigned int *kaddr;
10760+
10761+ vmf->page = alloc_page(GFP_HIGHUSER);
10762+ if (!vmf->page)
10763+ return VM_FAULT_OOM;
10764+
10765+ kaddr = kmap(vmf->page);
10766+ memset(kaddr, 0, PAGE_SIZE);
10767+ kaddr[0] = 0x9DE3BFA8U; /* save */
10768+ flush_dcache_page(vmf->page);
10769+ kunmap(vmf->page);
10770+ return VM_FAULT_MAJOR;
10771+}
10772+
10773+static const struct vm_operations_struct pax_vm_ops = {
10774+ .close = pax_emuplt_close,
10775+ .fault = pax_emuplt_fault
10776+};
10777+
10778+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10779+{
10780+ int ret;
10781+
10782+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10783+ vma->vm_mm = current->mm;
10784+ vma->vm_start = addr;
10785+ vma->vm_end = addr + PAGE_SIZE;
10786+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10787+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10788+ vma->vm_ops = &pax_vm_ops;
10789+
10790+ ret = insert_vm_struct(current->mm, vma);
10791+ if (ret)
10792+ return ret;
10793+
10794+ ++current->mm->total_vm;
10795+ return 0;
10796+}
10797+#endif
10798+
10799+/*
10800+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10801+ *
10802+ * returns 1 when task should be killed
10803+ * 2 when patched PLT trampoline was detected
10804+ * 3 when unpatched PLT trampoline was detected
10805+ */
10806+static int pax_handle_fetch_fault(struct pt_regs *regs)
10807+{
10808+
10809+#ifdef CONFIG_PAX_EMUPLT
10810+ int err;
10811+
10812+ do { /* PaX: patched PLT emulation #1 */
10813+ unsigned int sethi1, sethi2, jmpl;
10814+
10815+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10816+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10817+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10818+
10819+ if (err)
10820+ break;
10821+
10822+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10823+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10824+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10825+ {
10826+ unsigned long addr;
10827+
10828+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10829+ addr = regs->u_regs[UREG_G1];
10830+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10831+
10832+ if (test_thread_flag(TIF_32BIT))
10833+ addr &= 0xFFFFFFFFUL;
10834+
10835+ regs->tpc = addr;
10836+ regs->tnpc = addr+4;
10837+ return 2;
10838+ }
10839+ } while (0);
10840+
10841+ do { /* PaX: patched PLT emulation #2 */
10842+ unsigned int ba;
10843+
10844+ err = get_user(ba, (unsigned int *)regs->tpc);
10845+
10846+ if (err)
10847+ break;
10848+
10849+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10850+ unsigned long addr;
10851+
10852+ if ((ba & 0xFFC00000U) == 0x30800000U)
10853+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10854+ else
10855+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10856+
10857+ if (test_thread_flag(TIF_32BIT))
10858+ addr &= 0xFFFFFFFFUL;
10859+
10860+ regs->tpc = addr;
10861+ regs->tnpc = addr+4;
10862+ return 2;
10863+ }
10864+ } while (0);
10865+
10866+ do { /* PaX: patched PLT emulation #3 */
10867+ unsigned int sethi, bajmpl, nop;
10868+
10869+ err = get_user(sethi, (unsigned int *)regs->tpc);
10870+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10871+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10872+
10873+ if (err)
10874+ break;
10875+
10876+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10877+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10878+ nop == 0x01000000U)
10879+ {
10880+ unsigned long addr;
10881+
10882+ addr = (sethi & 0x003FFFFFU) << 10;
10883+ regs->u_regs[UREG_G1] = addr;
10884+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10885+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10886+ else
10887+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10888+
10889+ if (test_thread_flag(TIF_32BIT))
10890+ addr &= 0xFFFFFFFFUL;
10891+
10892+ regs->tpc = addr;
10893+ regs->tnpc = addr+4;
10894+ return 2;
10895+ }
10896+ } while (0);
10897+
10898+ do { /* PaX: patched PLT emulation #4 */
10899+ unsigned int sethi, mov1, call, mov2;
10900+
10901+ err = get_user(sethi, (unsigned int *)regs->tpc);
10902+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10903+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10904+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10905+
10906+ if (err)
10907+ break;
10908+
10909+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10910+ mov1 == 0x8210000FU &&
10911+ (call & 0xC0000000U) == 0x40000000U &&
10912+ mov2 == 0x9E100001U)
10913+ {
10914+ unsigned long addr;
10915+
10916+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10917+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10918+
10919+ if (test_thread_flag(TIF_32BIT))
10920+ addr &= 0xFFFFFFFFUL;
10921+
10922+ regs->tpc = addr;
10923+ regs->tnpc = addr+4;
10924+ return 2;
10925+ }
10926+ } while (0);
10927+
10928+ do { /* PaX: patched PLT emulation #5 */
10929+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10930+
10931+ err = get_user(sethi, (unsigned int *)regs->tpc);
10932+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10933+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10934+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10935+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10936+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10937+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10938+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10939+
10940+ if (err)
10941+ break;
10942+
10943+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10944+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10945+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10946+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10947+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10948+ sllx == 0x83287020U &&
10949+ jmpl == 0x81C04005U &&
10950+ nop == 0x01000000U)
10951+ {
10952+ unsigned long addr;
10953+
10954+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10955+ regs->u_regs[UREG_G1] <<= 32;
10956+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10957+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10958+ regs->tpc = addr;
10959+ regs->tnpc = addr+4;
10960+ return 2;
10961+ }
10962+ } while (0);
10963+
10964+ do { /* PaX: patched PLT emulation #6 */
10965+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10966+
10967+ err = get_user(sethi, (unsigned int *)regs->tpc);
10968+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10969+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10970+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10971+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10972+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10973+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10974+
10975+ if (err)
10976+ break;
10977+
10978+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10979+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10980+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10981+ sllx == 0x83287020U &&
10982+ (or & 0xFFFFE000U) == 0x8A116000U &&
10983+ jmpl == 0x81C04005U &&
10984+ nop == 0x01000000U)
10985+ {
10986+ unsigned long addr;
10987+
10988+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10989+ regs->u_regs[UREG_G1] <<= 32;
10990+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10991+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10992+ regs->tpc = addr;
10993+ regs->tnpc = addr+4;
10994+ return 2;
10995+ }
10996+ } while (0);
10997+
10998+ do { /* PaX: unpatched PLT emulation step 1 */
10999+ unsigned int sethi, ba, nop;
11000+
11001+ err = get_user(sethi, (unsigned int *)regs->tpc);
11002+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11003+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11004+
11005+ if (err)
11006+ break;
11007+
11008+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11009+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11010+ nop == 0x01000000U)
11011+ {
11012+ unsigned long addr;
11013+ unsigned int save, call;
11014+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11015+
11016+ if ((ba & 0xFFC00000U) == 0x30800000U)
11017+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11018+ else
11019+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11020+
11021+ if (test_thread_flag(TIF_32BIT))
11022+ addr &= 0xFFFFFFFFUL;
11023+
11024+ err = get_user(save, (unsigned int *)addr);
11025+ err |= get_user(call, (unsigned int *)(addr+4));
11026+ err |= get_user(nop, (unsigned int *)(addr+8));
11027+ if (err)
11028+ break;
11029+
11030+#ifdef CONFIG_PAX_DLRESOLVE
11031+ if (save == 0x9DE3BFA8U &&
11032+ (call & 0xC0000000U) == 0x40000000U &&
11033+ nop == 0x01000000U)
11034+ {
11035+ struct vm_area_struct *vma;
11036+ unsigned long call_dl_resolve;
11037+
11038+ down_read(&current->mm->mmap_sem);
11039+ call_dl_resolve = current->mm->call_dl_resolve;
11040+ up_read(&current->mm->mmap_sem);
11041+ if (likely(call_dl_resolve))
11042+ goto emulate;
11043+
11044+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11045+
11046+ down_write(&current->mm->mmap_sem);
11047+ if (current->mm->call_dl_resolve) {
11048+ call_dl_resolve = current->mm->call_dl_resolve;
11049+ up_write(&current->mm->mmap_sem);
11050+ if (vma)
11051+ kmem_cache_free(vm_area_cachep, vma);
11052+ goto emulate;
11053+ }
11054+
11055+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11056+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11057+ up_write(&current->mm->mmap_sem);
11058+ if (vma)
11059+ kmem_cache_free(vm_area_cachep, vma);
11060+ return 1;
11061+ }
11062+
11063+ if (pax_insert_vma(vma, call_dl_resolve)) {
11064+ up_write(&current->mm->mmap_sem);
11065+ kmem_cache_free(vm_area_cachep, vma);
11066+ return 1;
11067+ }
11068+
11069+ current->mm->call_dl_resolve = call_dl_resolve;
11070+ up_write(&current->mm->mmap_sem);
11071+
11072+emulate:
11073+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11074+ regs->tpc = call_dl_resolve;
11075+ regs->tnpc = addr+4;
11076+ return 3;
11077+ }
11078+#endif
11079+
11080+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11081+ if ((save & 0xFFC00000U) == 0x05000000U &&
11082+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11083+ nop == 0x01000000U)
11084+ {
11085+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11086+ regs->u_regs[UREG_G2] = addr + 4;
11087+ addr = (save & 0x003FFFFFU) << 10;
11088+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11089+
11090+ if (test_thread_flag(TIF_32BIT))
11091+ addr &= 0xFFFFFFFFUL;
11092+
11093+ regs->tpc = addr;
11094+ regs->tnpc = addr+4;
11095+ return 3;
11096+ }
11097+
11098+ /* PaX: 64-bit PLT stub */
11099+ err = get_user(sethi1, (unsigned int *)addr);
11100+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11101+ err |= get_user(or1, (unsigned int *)(addr+8));
11102+ err |= get_user(or2, (unsigned int *)(addr+12));
11103+ err |= get_user(sllx, (unsigned int *)(addr+16));
11104+ err |= get_user(add, (unsigned int *)(addr+20));
11105+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11106+ err |= get_user(nop, (unsigned int *)(addr+28));
11107+ if (err)
11108+ break;
11109+
11110+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11111+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11112+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11113+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11114+ sllx == 0x89293020U &&
11115+ add == 0x8A010005U &&
11116+ jmpl == 0x89C14000U &&
11117+ nop == 0x01000000U)
11118+ {
11119+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11120+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11121+ regs->u_regs[UREG_G4] <<= 32;
11122+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11123+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11124+ regs->u_regs[UREG_G4] = addr + 24;
11125+ addr = regs->u_regs[UREG_G5];
11126+ regs->tpc = addr;
11127+ regs->tnpc = addr+4;
11128+ return 3;
11129+ }
11130+ }
11131+ } while (0);
11132+
11133+#ifdef CONFIG_PAX_DLRESOLVE
11134+ do { /* PaX: unpatched PLT emulation step 2 */
11135+ unsigned int save, call, nop;
11136+
11137+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11138+ err |= get_user(call, (unsigned int *)regs->tpc);
11139+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11140+ if (err)
11141+ break;
11142+
11143+ if (save == 0x9DE3BFA8U &&
11144+ (call & 0xC0000000U) == 0x40000000U &&
11145+ nop == 0x01000000U)
11146+ {
11147+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11148+
11149+ if (test_thread_flag(TIF_32BIT))
11150+ dl_resolve &= 0xFFFFFFFFUL;
11151+
11152+ regs->u_regs[UREG_RETPC] = regs->tpc;
11153+ regs->tpc = dl_resolve;
11154+ regs->tnpc = dl_resolve+4;
11155+ return 3;
11156+ }
11157+ } while (0);
11158+#endif
11159+
11160+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11161+ unsigned int sethi, ba, nop;
11162+
11163+ err = get_user(sethi, (unsigned int *)regs->tpc);
11164+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11165+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11166+
11167+ if (err)
11168+ break;
11169+
11170+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11171+ (ba & 0xFFF00000U) == 0x30600000U &&
11172+ nop == 0x01000000U)
11173+ {
11174+ unsigned long addr;
11175+
11176+ addr = (sethi & 0x003FFFFFU) << 10;
11177+ regs->u_regs[UREG_G1] = addr;
11178+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11179+
11180+ if (test_thread_flag(TIF_32BIT))
11181+ addr &= 0xFFFFFFFFUL;
11182+
11183+ regs->tpc = addr;
11184+ regs->tnpc = addr+4;
11185+ return 2;
11186+ }
11187+ } while (0);
11188+
11189+#endif
11190+
11191+ return 1;
11192+}
11193+
11194+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11195+{
11196+ unsigned long i;
11197+
11198+ printk(KERN_ERR "PAX: bytes at PC: ");
11199+ for (i = 0; i < 8; i++) {
11200+ unsigned int c;
11201+ if (get_user(c, (unsigned int *)pc+i))
11202+ printk(KERN_CONT "???????? ");
11203+ else
11204+ printk(KERN_CONT "%08x ", c);
11205+ }
11206+ printk("\n");
11207+}
11208+#endif
11209+
11210 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11211 {
11212 struct mm_struct *mm = current->mm;
11213@@ -341,6 +804,29 @@ retry:
11214 if (!vma)
11215 goto bad_area;
11216
11217+#ifdef CONFIG_PAX_PAGEEXEC
11218+ /* PaX: detect ITLB misses on non-exec pages */
11219+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11220+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11221+ {
11222+ if (address != regs->tpc)
11223+ goto good_area;
11224+
11225+ up_read(&mm->mmap_sem);
11226+ switch (pax_handle_fetch_fault(regs)) {
11227+
11228+#ifdef CONFIG_PAX_EMUPLT
11229+ case 2:
11230+ case 3:
11231+ return;
11232+#endif
11233+
11234+ }
11235+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11236+ do_group_exit(SIGKILL);
11237+ }
11238+#endif
11239+
11240 /* Pure DTLB misses do not tell us whether the fault causing
11241 * load/store/atomic was a write or not, it only says that there
11242 * was no match. So in such a case we (carefully) read the
11243diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11244index d2b5944..d878f3c 100644
11245--- a/arch/sparc/mm/hugetlbpage.c
11246+++ b/arch/sparc/mm/hugetlbpage.c
11247@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11248 unsigned long addr,
11249 unsigned long len,
11250 unsigned long pgoff,
11251- unsigned long flags)
11252+ unsigned long flags,
11253+ unsigned long offset)
11254 {
11255 unsigned long task_size = TASK_SIZE;
11256 struct vm_unmapped_area_info info;
11257@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11258
11259 info.flags = 0;
11260 info.length = len;
11261- info.low_limit = TASK_UNMAPPED_BASE;
11262+ info.low_limit = mm->mmap_base;
11263 info.high_limit = min(task_size, VA_EXCLUDE_START);
11264 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11265 info.align_offset = 0;
11266+ info.threadstack_offset = offset;
11267 addr = vm_unmapped_area(&info);
11268
11269 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11270 VM_BUG_ON(addr != -ENOMEM);
11271 info.low_limit = VA_EXCLUDE_END;
11272+
11273+#ifdef CONFIG_PAX_RANDMMAP
11274+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11275+ info.low_limit += mm->delta_mmap;
11276+#endif
11277+
11278 info.high_limit = task_size;
11279 addr = vm_unmapped_area(&info);
11280 }
11281@@ -58,7 +66,8 @@ static unsigned long
11282 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11283 const unsigned long len,
11284 const unsigned long pgoff,
11285- const unsigned long flags)
11286+ const unsigned long flags,
11287+ const unsigned long offset)
11288 {
11289 struct mm_struct *mm = current->mm;
11290 unsigned long addr = addr0;
11291@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11292 info.high_limit = mm->mmap_base;
11293 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11294 info.align_offset = 0;
11295+ info.threadstack_offset = offset;
11296 addr = vm_unmapped_area(&info);
11297
11298 /*
11299@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11300 VM_BUG_ON(addr != -ENOMEM);
11301 info.flags = 0;
11302 info.low_limit = TASK_UNMAPPED_BASE;
11303+
11304+#ifdef CONFIG_PAX_RANDMMAP
11305+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11306+ info.low_limit += mm->delta_mmap;
11307+#endif
11308+
11309 info.high_limit = STACK_TOP32;
11310 addr = vm_unmapped_area(&info);
11311 }
11312@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11313 struct mm_struct *mm = current->mm;
11314 struct vm_area_struct *vma;
11315 unsigned long task_size = TASK_SIZE;
11316+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11317
11318 if (test_thread_flag(TIF_32BIT))
11319 task_size = STACK_TOP32;
11320@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11321 return addr;
11322 }
11323
11324+#ifdef CONFIG_PAX_RANDMMAP
11325+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11326+#endif
11327+
11328 if (addr) {
11329 addr = ALIGN(addr, HPAGE_SIZE);
11330 vma = find_vma(mm, addr);
11331- if (task_size - len >= addr &&
11332- (!vma || addr + len <= vma->vm_start))
11333+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11334 return addr;
11335 }
11336 if (mm->get_unmapped_area == arch_get_unmapped_area)
11337 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11338- pgoff, flags);
11339+ pgoff, flags, offset);
11340 else
11341 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11342- pgoff, flags);
11343+ pgoff, flags, offset);
11344 }
11345
11346 pte_t *huge_pte_alloc(struct mm_struct *mm,
11347diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11348index ed82eda..0d80e77 100644
11349--- a/arch/sparc/mm/init_64.c
11350+++ b/arch/sparc/mm/init_64.c
11351@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11352 int num_kernel_image_mappings;
11353
11354 #ifdef CONFIG_DEBUG_DCFLUSH
11355-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11356+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11357 #ifdef CONFIG_SMP
11358-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11359+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11360 #endif
11361 #endif
11362
11363@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11364 {
11365 BUG_ON(tlb_type == hypervisor);
11366 #ifdef CONFIG_DEBUG_DCFLUSH
11367- atomic_inc(&dcpage_flushes);
11368+ atomic_inc_unchecked(&dcpage_flushes);
11369 #endif
11370
11371 #ifdef DCACHE_ALIASING_POSSIBLE
11372@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11373
11374 #ifdef CONFIG_DEBUG_DCFLUSH
11375 seq_printf(m, "DCPageFlushes\t: %d\n",
11376- atomic_read(&dcpage_flushes));
11377+ atomic_read_unchecked(&dcpage_flushes));
11378 #ifdef CONFIG_SMP
11379 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11380- atomic_read(&dcpage_flushes_xcall));
11381+ atomic_read_unchecked(&dcpage_flushes_xcall));
11382 #endif /* CONFIG_SMP */
11383 #endif /* CONFIG_DEBUG_DCFLUSH */
11384 }
11385diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11386index f4500c6..889656c 100644
11387--- a/arch/tile/include/asm/atomic_64.h
11388+++ b/arch/tile/include/asm/atomic_64.h
11389@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11390
11391 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11392
11393+#define atomic64_read_unchecked(v) atomic64_read(v)
11394+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11395+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11396+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11397+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11398+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11399+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11400+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11401+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11402+
11403 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11404 #define smp_mb__before_atomic_dec() smp_mb()
11405 #define smp_mb__after_atomic_dec() smp_mb()
11406diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11407index a9a5299..0fce79e 100644
11408--- a/arch/tile/include/asm/cache.h
11409+++ b/arch/tile/include/asm/cache.h
11410@@ -15,11 +15,12 @@
11411 #ifndef _ASM_TILE_CACHE_H
11412 #define _ASM_TILE_CACHE_H
11413
11414+#include <linux/const.h>
11415 #include <arch/chip.h>
11416
11417 /* bytes per L1 data cache line */
11418 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11419-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11420+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11421
11422 /* bytes per L2 cache line */
11423 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11424diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11425index e4d44bd..99927a3 100644
11426--- a/arch/tile/include/asm/uaccess.h
11427+++ b/arch/tile/include/asm/uaccess.h
11428@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11429 const void __user *from,
11430 unsigned long n)
11431 {
11432- int sz = __compiletime_object_size(to);
11433+ size_t sz = __compiletime_object_size(to);
11434
11435- if (likely(sz == -1 || sz >= n))
11436+ if (likely(sz == (size_t)-1 || sz >= n))
11437 n = _copy_from_user(to, from, n);
11438 else
11439 copy_from_user_overflow();
11440diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11441index 650ccff..45fe2d6 100644
11442--- a/arch/tile/mm/hugetlbpage.c
11443+++ b/arch/tile/mm/hugetlbpage.c
11444@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11445 info.high_limit = TASK_SIZE;
11446 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11447 info.align_offset = 0;
11448+ info.threadstack_offset = 0;
11449 return vm_unmapped_area(&info);
11450 }
11451
11452@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11453 info.high_limit = current->mm->mmap_base;
11454 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11455 info.align_offset = 0;
11456+ info.threadstack_offset = 0;
11457 addr = vm_unmapped_area(&info);
11458
11459 /*
11460diff --git a/arch/um/Makefile b/arch/um/Makefile
11461index 133f7de..1d6f2f1 100644
11462--- a/arch/um/Makefile
11463+++ b/arch/um/Makefile
11464@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11465 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11466 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11467
11468+ifdef CONSTIFY_PLUGIN
11469+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11470+endif
11471+
11472 #This will adjust *FLAGS accordingly to the platform.
11473 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11474
11475diff --git a/arch/um/defconfig b/arch/um/defconfig
11476index 08107a7..ab22afe 100644
11477--- a/arch/um/defconfig
11478+++ b/arch/um/defconfig
11479@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11480 CONFIG_X86_L1_CACHE_SHIFT=5
11481 CONFIG_X86_XADD=y
11482 CONFIG_X86_PPRO_FENCE=y
11483-CONFIG_X86_WP_WORKS_OK=y
11484 CONFIG_X86_INVLPG=y
11485 CONFIG_X86_BSWAP=y
11486 CONFIG_X86_POPAD_OK=y
11487diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11488index 19e1bdd..3665b77 100644
11489--- a/arch/um/include/asm/cache.h
11490+++ b/arch/um/include/asm/cache.h
11491@@ -1,6 +1,7 @@
11492 #ifndef __UM_CACHE_H
11493 #define __UM_CACHE_H
11494
11495+#include <linux/const.h>
11496
11497 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11498 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11499@@ -12,6 +13,6 @@
11500 # define L1_CACHE_SHIFT 5
11501 #endif
11502
11503-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11504+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11505
11506 #endif
11507diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11508index 2e0a6b1..a64d0f5 100644
11509--- a/arch/um/include/asm/kmap_types.h
11510+++ b/arch/um/include/asm/kmap_types.h
11511@@ -8,6 +8,6 @@
11512
11513 /* No more #include "asm/arch/kmap_types.h" ! */
11514
11515-#define KM_TYPE_NR 14
11516+#define KM_TYPE_NR 15
11517
11518 #endif
11519diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11520index 5ff53d9..5850cdf 100644
11521--- a/arch/um/include/asm/page.h
11522+++ b/arch/um/include/asm/page.h
11523@@ -14,6 +14,9 @@
11524 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11525 #define PAGE_MASK (~(PAGE_SIZE-1))
11526
11527+#define ktla_ktva(addr) (addr)
11528+#define ktva_ktla(addr) (addr)
11529+
11530 #ifndef __ASSEMBLY__
11531
11532 struct page;
11533diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11534index 0032f92..cd151e0 100644
11535--- a/arch/um/include/asm/pgtable-3level.h
11536+++ b/arch/um/include/asm/pgtable-3level.h
11537@@ -58,6 +58,7 @@
11538 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11539 #define pud_populate(mm, pud, pmd) \
11540 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11541+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11542
11543 #ifdef CONFIG_64BIT
11544 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11545diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11546index bbcef52..6a2a483 100644
11547--- a/arch/um/kernel/process.c
11548+++ b/arch/um/kernel/process.c
11549@@ -367,22 +367,6 @@ int singlestepping(void * t)
11550 return 2;
11551 }
11552
11553-/*
11554- * Only x86 and x86_64 have an arch_align_stack().
11555- * All other arches have "#define arch_align_stack(x) (x)"
11556- * in their asm/system.h
11557- * As this is included in UML from asm-um/system-generic.h,
11558- * we can use it to behave as the subarch does.
11559- */
11560-#ifndef arch_align_stack
11561-unsigned long arch_align_stack(unsigned long sp)
11562-{
11563- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11564- sp -= get_random_int() % 8192;
11565- return sp & ~0xf;
11566-}
11567-#endif
11568-
11569 unsigned long get_wchan(struct task_struct *p)
11570 {
11571 unsigned long stack_page, sp, ip;
11572diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11573index ad8f795..2c7eec6 100644
11574--- a/arch/unicore32/include/asm/cache.h
11575+++ b/arch/unicore32/include/asm/cache.h
11576@@ -12,8 +12,10 @@
11577 #ifndef __UNICORE_CACHE_H__
11578 #define __UNICORE_CACHE_H__
11579
11580-#define L1_CACHE_SHIFT (5)
11581-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11582+#include <linux/const.h>
11583+
11584+#define L1_CACHE_SHIFT 5
11585+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11586
11587 /*
11588 * Memory returned by kmalloc() may be used for DMA, so we must make
11589diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11590index b32ebf9..5704f98 100644
11591--- a/arch/x86/Kconfig
11592+++ b/arch/x86/Kconfig
11593@@ -248,7 +248,7 @@ config X86_HT
11594
11595 config X86_32_LAZY_GS
11596 def_bool y
11597- depends on X86_32 && !CC_STACKPROTECTOR
11598+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11599
11600 config ARCH_HWEIGHT_CFLAGS
11601 string
11602@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11603
11604 config X86_MSR
11605 tristate "/dev/cpu/*/msr - Model-specific register support"
11606+ depends on !GRKERNSEC_KMEM
11607 ---help---
11608 This device gives privileged processes access to the x86
11609 Model-Specific Registers (MSRs). It is a character device with
11610@@ -1111,7 +1112,7 @@ choice
11611
11612 config NOHIGHMEM
11613 bool "off"
11614- depends on !X86_NUMAQ
11615+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11616 ---help---
11617 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11618 However, the address space of 32-bit x86 processors is only 4
11619@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11620
11621 config HIGHMEM4G
11622 bool "4GB"
11623- depends on !X86_NUMAQ
11624+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11625 ---help---
11626 Select this if you have a 32-bit processor and between 1 and 4
11627 gigabytes of physical RAM.
11628@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11629 hex
11630 default 0xB0000000 if VMSPLIT_3G_OPT
11631 default 0x80000000 if VMSPLIT_2G
11632- default 0x78000000 if VMSPLIT_2G_OPT
11633+ default 0x70000000 if VMSPLIT_2G_OPT
11634 default 0x40000000 if VMSPLIT_1G
11635 default 0xC0000000
11636 depends on X86_32
11637@@ -1599,6 +1600,7 @@ config SECCOMP
11638
11639 config CC_STACKPROTECTOR
11640 bool "Enable -fstack-protector buffer overflow detection"
11641+ depends on X86_64 || !PAX_MEMORY_UDEREF
11642 ---help---
11643 This option turns on the -fstack-protector GCC feature. This
11644 feature puts, at the beginning of functions, a canary value on
11645@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11646 config PHYSICAL_ALIGN
11647 hex "Alignment value to which kernel should be aligned" if X86_32
11648 default "0x1000000"
11649+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11650+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11651 range 0x2000 0x1000000
11652 ---help---
11653 This value puts the alignment restrictions on physical address
11654@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11655 If unsure, say N.
11656
11657 config COMPAT_VDSO
11658- def_bool y
11659+ def_bool n
11660 prompt "Compat VDSO support"
11661 depends on X86_32 || IA32_EMULATION
11662+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11663 ---help---
11664 Map the 32-bit VDSO to the predictable old-style address too.
11665
11666diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11667index c026cca..14657ae 100644
11668--- a/arch/x86/Kconfig.cpu
11669+++ b/arch/x86/Kconfig.cpu
11670@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11671
11672 config X86_F00F_BUG
11673 def_bool y
11674- depends on M586MMX || M586TSC || M586 || M486
11675+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11676
11677 config X86_INVD_BUG
11678 def_bool y
11679@@ -327,7 +327,7 @@ config X86_INVD_BUG
11680
11681 config X86_ALIGNMENT_16
11682 def_bool y
11683- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11684+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11685
11686 config X86_INTEL_USERCOPY
11687 def_bool y
11688@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11689 # generates cmov.
11690 config X86_CMOV
11691 def_bool y
11692- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11693+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11694
11695 config X86_MINIMUM_CPU_FAMILY
11696 int
11697diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11698index 78d91af..8ceb94b 100644
11699--- a/arch/x86/Kconfig.debug
11700+++ b/arch/x86/Kconfig.debug
11701@@ -74,7 +74,7 @@ config X86_PTDUMP
11702 config DEBUG_RODATA
11703 bool "Write protect kernel read-only data structures"
11704 default y
11705- depends on DEBUG_KERNEL
11706+ depends on DEBUG_KERNEL && BROKEN
11707 ---help---
11708 Mark the kernel read-only data as write-protected in the pagetables,
11709 in order to catch accidental (and incorrect) writes to such const
11710@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11711
11712 config DEBUG_SET_MODULE_RONX
11713 bool "Set loadable kernel module data as NX and text as RO"
11714- depends on MODULES
11715+ depends on MODULES && BROKEN
11716 ---help---
11717 This option helps catch unintended modifications to loadable
11718 kernel module's text and read-only data. It also prevents execution
11719diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11720index 07639c6..6f2c901 100644
11721--- a/arch/x86/Makefile
11722+++ b/arch/x86/Makefile
11723@@ -54,6 +54,7 @@ else
11724 UTS_MACHINE := x86_64
11725 CHECKFLAGS += -D__x86_64__ -m64
11726
11727+ biarch := $(call cc-option,-m64)
11728 KBUILD_AFLAGS += -m64
11729 KBUILD_CFLAGS += -m64
11730
11731@@ -241,3 +242,12 @@ define archhelp
11732 echo ' FDINITRD=file initrd for the booted kernel'
11733 echo ' kvmconfig - Enable additional options for guest kernel support'
11734 endef
11735+
11736+define OLD_LD
11737+
11738+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11739+*** Please upgrade your binutils to 2.18 or newer
11740+endef
11741+
11742+archprepare:
11743+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11744diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11745index 379814b..add62ce 100644
11746--- a/arch/x86/boot/Makefile
11747+++ b/arch/x86/boot/Makefile
11748@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11749 $(call cc-option, -fno-stack-protector) \
11750 $(call cc-option, -mpreferred-stack-boundary=2)
11751 KBUILD_CFLAGS += $(call cc-option, -m32)
11752+ifdef CONSTIFY_PLUGIN
11753+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11754+endif
11755 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11756 GCOV_PROFILE := n
11757
11758diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11759index 878e4b9..20537ab 100644
11760--- a/arch/x86/boot/bitops.h
11761+++ b/arch/x86/boot/bitops.h
11762@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11763 u8 v;
11764 const u32 *p = (const u32 *)addr;
11765
11766- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11767+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11768 return v;
11769 }
11770
11771@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11772
11773 static inline void set_bit(int nr, void *addr)
11774 {
11775- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11776+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11777 }
11778
11779 #endif /* BOOT_BITOPS_H */
11780diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11781index 5b75319..331a4ca 100644
11782--- a/arch/x86/boot/boot.h
11783+++ b/arch/x86/boot/boot.h
11784@@ -85,7 +85,7 @@ static inline void io_delay(void)
11785 static inline u16 ds(void)
11786 {
11787 u16 seg;
11788- asm("movw %%ds,%0" : "=rm" (seg));
11789+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11790 return seg;
11791 }
11792
11793@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11794 static inline int memcmp(const void *s1, const void *s2, size_t len)
11795 {
11796 u8 diff;
11797- asm("repe; cmpsb; setnz %0"
11798+ asm volatile("repe; cmpsb; setnz %0"
11799 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11800 return diff;
11801 }
11802diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11803index dcd90df..c830d7d 100644
11804--- a/arch/x86/boot/compressed/Makefile
11805+++ b/arch/x86/boot/compressed/Makefile
11806@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11807 KBUILD_CFLAGS += $(cflags-y)
11808 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11809 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11810+ifdef CONSTIFY_PLUGIN
11811+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11812+endif
11813
11814 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11815 GCOV_PROFILE := n
11816diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11817index b7388a4..03844ec 100644
11818--- a/arch/x86/boot/compressed/eboot.c
11819+++ b/arch/x86/boot/compressed/eboot.c
11820@@ -150,7 +150,6 @@ again:
11821 *addr = max_addr;
11822 }
11823
11824-free_pool:
11825 efi_call_phys1(sys_table->boottime->free_pool, map);
11826
11827 fail:
11828@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11829 if (i == map_size / desc_size)
11830 status = EFI_NOT_FOUND;
11831
11832-free_pool:
11833 efi_call_phys1(sys_table->boottime->free_pool, map);
11834 fail:
11835 return status;
11836diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11837index a53440e..c3dbf1e 100644
11838--- a/arch/x86/boot/compressed/efi_stub_32.S
11839+++ b/arch/x86/boot/compressed/efi_stub_32.S
11840@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11841 * parameter 2, ..., param n. To make things easy, we save the return
11842 * address of efi_call_phys in a global variable.
11843 */
11844- popl %ecx
11845- movl %ecx, saved_return_addr(%edx)
11846- /* get the function pointer into ECX*/
11847- popl %ecx
11848- movl %ecx, efi_rt_function_ptr(%edx)
11849+ popl saved_return_addr(%edx)
11850+ popl efi_rt_function_ptr(%edx)
11851
11852 /*
11853 * 3. Call the physical function.
11854 */
11855- call *%ecx
11856+ call *efi_rt_function_ptr(%edx)
11857
11858 /*
11859 * 4. Balance the stack. And because EAX contain the return value,
11860@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11861 1: popl %edx
11862 subl $1b, %edx
11863
11864- movl efi_rt_function_ptr(%edx), %ecx
11865- pushl %ecx
11866+ pushl efi_rt_function_ptr(%edx)
11867
11868 /*
11869 * 10. Push the saved return address onto the stack and return.
11870 */
11871- movl saved_return_addr(%edx), %ecx
11872- pushl %ecx
11873- ret
11874+ jmpl *saved_return_addr(%edx)
11875 ENDPROC(efi_call_phys)
11876 .previous
11877
11878diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11879index 1e3184f..0d11e2e 100644
11880--- a/arch/x86/boot/compressed/head_32.S
11881+++ b/arch/x86/boot/compressed/head_32.S
11882@@ -118,7 +118,7 @@ preferred_addr:
11883 notl %eax
11884 andl %eax, %ebx
11885 #else
11886- movl $LOAD_PHYSICAL_ADDR, %ebx
11887+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11888 #endif
11889
11890 /* Target address to relocate to for decompression */
11891@@ -204,7 +204,7 @@ relocated:
11892 * and where it was actually loaded.
11893 */
11894 movl %ebp, %ebx
11895- subl $LOAD_PHYSICAL_ADDR, %ebx
11896+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11897 jz 2f /* Nothing to be done if loaded at compiled addr. */
11898 /*
11899 * Process relocations.
11900@@ -212,8 +212,7 @@ relocated:
11901
11902 1: subl $4, %edi
11903 movl (%edi), %ecx
11904- testl %ecx, %ecx
11905- jz 2f
11906+ jecxz 2f
11907 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11908 jmp 1b
11909 2:
11910diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11911index 06e71c2..88a98264 100644
11912--- a/arch/x86/boot/compressed/head_64.S
11913+++ b/arch/x86/boot/compressed/head_64.S
11914@@ -95,7 +95,7 @@ ENTRY(startup_32)
11915 notl %eax
11916 andl %eax, %ebx
11917 #else
11918- movl $LOAD_PHYSICAL_ADDR, %ebx
11919+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11920 #endif
11921
11922 /* Target address to relocate to for decompression */
11923@@ -270,7 +270,7 @@ preferred_addr:
11924 notq %rax
11925 andq %rax, %rbp
11926 #else
11927- movq $LOAD_PHYSICAL_ADDR, %rbp
11928+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11929 #endif
11930
11931 /* Target address to relocate to for decompression */
11932@@ -361,8 +361,8 @@ gdt:
11933 .long gdt
11934 .word 0
11935 .quad 0x0000000000000000 /* NULL descriptor */
11936- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11937- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11938+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11939+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11940 .quad 0x0080890000000000 /* TS descriptor */
11941 .quad 0x0000000000000000 /* TS continued */
11942 gdt_end:
11943diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11944index 0319c88..7c1931f 100644
11945--- a/arch/x86/boot/compressed/misc.c
11946+++ b/arch/x86/boot/compressed/misc.c
11947@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11948 case PT_LOAD:
11949 #ifdef CONFIG_RELOCATABLE
11950 dest = output;
11951- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11952+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11953 #else
11954 dest = (void *)(phdr->p_paddr);
11955 #endif
11956@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11957 error("Destination address too large");
11958 #endif
11959 #ifndef CONFIG_RELOCATABLE
11960- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11961+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11962 error("Wrong destination address");
11963 #endif
11964
11965diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11966index 4d3ff03..e4972ff 100644
11967--- a/arch/x86/boot/cpucheck.c
11968+++ b/arch/x86/boot/cpucheck.c
11969@@ -74,7 +74,7 @@ static int has_fpu(void)
11970 u16 fcw = -1, fsw = -1;
11971 u32 cr0;
11972
11973- asm("movl %%cr0,%0" : "=r" (cr0));
11974+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11975 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11976 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11977 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11978@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11979 {
11980 u32 f0, f1;
11981
11982- asm("pushfl ; "
11983+ asm volatile("pushfl ; "
11984 "pushfl ; "
11985 "popl %0 ; "
11986 "movl %0,%1 ; "
11987@@ -115,7 +115,7 @@ static void get_flags(void)
11988 set_bit(X86_FEATURE_FPU, cpu.flags);
11989
11990 if (has_eflag(X86_EFLAGS_ID)) {
11991- asm("cpuid"
11992+ asm volatile("cpuid"
11993 : "=a" (max_intel_level),
11994 "=b" (cpu_vendor[0]),
11995 "=d" (cpu_vendor[1]),
11996@@ -124,7 +124,7 @@ static void get_flags(void)
11997
11998 if (max_intel_level >= 0x00000001 &&
11999 max_intel_level <= 0x0000ffff) {
12000- asm("cpuid"
12001+ asm volatile("cpuid"
12002 : "=a" (tfms),
12003 "=c" (cpu.flags[4]),
12004 "=d" (cpu.flags[0])
12005@@ -136,7 +136,7 @@ static void get_flags(void)
12006 cpu.model += ((tfms >> 16) & 0xf) << 4;
12007 }
12008
12009- asm("cpuid"
12010+ asm volatile("cpuid"
12011 : "=a" (max_amd_level)
12012 : "a" (0x80000000)
12013 : "ebx", "ecx", "edx");
12014@@ -144,7 +144,7 @@ static void get_flags(void)
12015 if (max_amd_level >= 0x80000001 &&
12016 max_amd_level <= 0x8000ffff) {
12017 u32 eax = 0x80000001;
12018- asm("cpuid"
12019+ asm volatile("cpuid"
12020 : "+a" (eax),
12021 "=c" (cpu.flags[6]),
12022 "=d" (cpu.flags[1])
12023@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12024 u32 ecx = MSR_K7_HWCR;
12025 u32 eax, edx;
12026
12027- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12028+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12029 eax &= ~(1 << 15);
12030- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12031+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12032
12033 get_flags(); /* Make sure it really did something */
12034 err = check_flags();
12035@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12036 u32 ecx = MSR_VIA_FCR;
12037 u32 eax, edx;
12038
12039- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12040+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12041 eax |= (1<<1)|(1<<7);
12042- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12043+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12044
12045 set_bit(X86_FEATURE_CX8, cpu.flags);
12046 err = check_flags();
12047@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12048 u32 eax, edx;
12049 u32 level = 1;
12050
12051- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12052- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12053- asm("cpuid"
12054+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12055+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12056+ asm volatile("cpuid"
12057 : "+a" (level), "=d" (cpu.flags[0])
12058 : : "ecx", "ebx");
12059- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12060+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12061
12062 err = check_flags();
12063 }
12064diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12065index 9ec06a1..2c25e79 100644
12066--- a/arch/x86/boot/header.S
12067+++ b/arch/x86/boot/header.S
12068@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12069 # single linked list of
12070 # struct setup_data
12071
12072-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12073+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12074
12075 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12076+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12077+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12078+#else
12079 #define VO_INIT_SIZE (VO__end - VO__text)
12080+#endif
12081 #if ZO_INIT_SIZE > VO_INIT_SIZE
12082 #define INIT_SIZE ZO_INIT_SIZE
12083 #else
12084diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12085index db75d07..8e6d0af 100644
12086--- a/arch/x86/boot/memory.c
12087+++ b/arch/x86/boot/memory.c
12088@@ -19,7 +19,7 @@
12089
12090 static int detect_memory_e820(void)
12091 {
12092- int count = 0;
12093+ unsigned int count = 0;
12094 struct biosregs ireg, oreg;
12095 struct e820entry *desc = boot_params.e820_map;
12096 static struct e820entry buf; /* static so it is zeroed */
12097diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12098index 11e8c6e..fdbb1ed 100644
12099--- a/arch/x86/boot/video-vesa.c
12100+++ b/arch/x86/boot/video-vesa.c
12101@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12102
12103 boot_params.screen_info.vesapm_seg = oreg.es;
12104 boot_params.screen_info.vesapm_off = oreg.di;
12105+ boot_params.screen_info.vesapm_size = oreg.cx;
12106 }
12107
12108 /*
12109diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12110index 43eda28..5ab5fdb 100644
12111--- a/arch/x86/boot/video.c
12112+++ b/arch/x86/boot/video.c
12113@@ -96,7 +96,7 @@ static void store_mode_params(void)
12114 static unsigned int get_entry(void)
12115 {
12116 char entry_buf[4];
12117- int i, len = 0;
12118+ unsigned int i, len = 0;
12119 int key;
12120 unsigned int v;
12121
12122diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12123index 9105655..5e37f27 100644
12124--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12125+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12126@@ -8,6 +8,8 @@
12127 * including this sentence is retained in full.
12128 */
12129
12130+#include <asm/alternative-asm.h>
12131+
12132 .extern crypto_ft_tab
12133 .extern crypto_it_tab
12134 .extern crypto_fl_tab
12135@@ -70,6 +72,8 @@
12136 je B192; \
12137 leaq 32(r9),r9;
12138
12139+#define ret pax_force_retaddr 0, 1; ret
12140+
12141 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12142 movq r1,r2; \
12143 movq r3,r4; \
12144diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12145index 477e9d7..3ab339f 100644
12146--- a/arch/x86/crypto/aesni-intel_asm.S
12147+++ b/arch/x86/crypto/aesni-intel_asm.S
12148@@ -31,6 +31,7 @@
12149
12150 #include <linux/linkage.h>
12151 #include <asm/inst.h>
12152+#include <asm/alternative-asm.h>
12153
12154 #ifdef __x86_64__
12155 .data
12156@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12157 pop %r14
12158 pop %r13
12159 pop %r12
12160+ pax_force_retaddr 0, 1
12161 ret
12162 ENDPROC(aesni_gcm_dec)
12163
12164@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12165 pop %r14
12166 pop %r13
12167 pop %r12
12168+ pax_force_retaddr 0, 1
12169 ret
12170 ENDPROC(aesni_gcm_enc)
12171
12172@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12173 pxor %xmm1, %xmm0
12174 movaps %xmm0, (TKEYP)
12175 add $0x10, TKEYP
12176+ pax_force_retaddr_bts
12177 ret
12178 ENDPROC(_key_expansion_128)
12179 ENDPROC(_key_expansion_256a)
12180@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12181 shufps $0b01001110, %xmm2, %xmm1
12182 movaps %xmm1, 0x10(TKEYP)
12183 add $0x20, TKEYP
12184+ pax_force_retaddr_bts
12185 ret
12186 ENDPROC(_key_expansion_192a)
12187
12188@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12189
12190 movaps %xmm0, (TKEYP)
12191 add $0x10, TKEYP
12192+ pax_force_retaddr_bts
12193 ret
12194 ENDPROC(_key_expansion_192b)
12195
12196@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12197 pxor %xmm1, %xmm2
12198 movaps %xmm2, (TKEYP)
12199 add $0x10, TKEYP
12200+ pax_force_retaddr_bts
12201 ret
12202 ENDPROC(_key_expansion_256b)
12203
12204@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12205 #ifndef __x86_64__
12206 popl KEYP
12207 #endif
12208+ pax_force_retaddr 0, 1
12209 ret
12210 ENDPROC(aesni_set_key)
12211
12212@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12213 popl KLEN
12214 popl KEYP
12215 #endif
12216+ pax_force_retaddr 0, 1
12217 ret
12218 ENDPROC(aesni_enc)
12219
12220@@ -1974,6 +1983,7 @@ _aesni_enc1:
12221 AESENC KEY STATE
12222 movaps 0x70(TKEYP), KEY
12223 AESENCLAST KEY STATE
12224+ pax_force_retaddr_bts
12225 ret
12226 ENDPROC(_aesni_enc1)
12227
12228@@ -2083,6 +2093,7 @@ _aesni_enc4:
12229 AESENCLAST KEY STATE2
12230 AESENCLAST KEY STATE3
12231 AESENCLAST KEY STATE4
12232+ pax_force_retaddr_bts
12233 ret
12234 ENDPROC(_aesni_enc4)
12235
12236@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12237 popl KLEN
12238 popl KEYP
12239 #endif
12240+ pax_force_retaddr 0, 1
12241 ret
12242 ENDPROC(aesni_dec)
12243
12244@@ -2164,6 +2176,7 @@ _aesni_dec1:
12245 AESDEC KEY STATE
12246 movaps 0x70(TKEYP), KEY
12247 AESDECLAST KEY STATE
12248+ pax_force_retaddr_bts
12249 ret
12250 ENDPROC(_aesni_dec1)
12251
12252@@ -2273,6 +2286,7 @@ _aesni_dec4:
12253 AESDECLAST KEY STATE2
12254 AESDECLAST KEY STATE3
12255 AESDECLAST KEY STATE4
12256+ pax_force_retaddr_bts
12257 ret
12258 ENDPROC(_aesni_dec4)
12259
12260@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12261 popl KEYP
12262 popl LEN
12263 #endif
12264+ pax_force_retaddr 0, 1
12265 ret
12266 ENDPROC(aesni_ecb_enc)
12267
12268@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12269 popl KEYP
12270 popl LEN
12271 #endif
12272+ pax_force_retaddr 0, 1
12273 ret
12274 ENDPROC(aesni_ecb_dec)
12275
12276@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12277 popl LEN
12278 popl IVP
12279 #endif
12280+ pax_force_retaddr 0, 1
12281 ret
12282 ENDPROC(aesni_cbc_enc)
12283
12284@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12285 popl LEN
12286 popl IVP
12287 #endif
12288+ pax_force_retaddr 0, 1
12289 ret
12290 ENDPROC(aesni_cbc_dec)
12291
12292@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12293 mov $1, TCTR_LOW
12294 MOVQ_R64_XMM TCTR_LOW INC
12295 MOVQ_R64_XMM CTR TCTR_LOW
12296+ pax_force_retaddr_bts
12297 ret
12298 ENDPROC(_aesni_inc_init)
12299
12300@@ -2579,6 +2598,7 @@ _aesni_inc:
12301 .Linc_low:
12302 movaps CTR, IV
12303 PSHUFB_XMM BSWAP_MASK IV
12304+ pax_force_retaddr_bts
12305 ret
12306 ENDPROC(_aesni_inc)
12307
12308@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12309 .Lctr_enc_ret:
12310 movups IV, (IVP)
12311 .Lctr_enc_just_ret:
12312+ pax_force_retaddr 0, 1
12313 ret
12314 ENDPROC(aesni_ctr_enc)
12315
12316@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12317 pxor INC, STATE4
12318 movdqu STATE4, 0x70(OUTP)
12319
12320+ pax_force_retaddr 0, 1
12321 ret
12322 ENDPROC(aesni_xts_crypt8)
12323
12324diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12325index 246c670..4d1ed00 100644
12326--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12327+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12328@@ -21,6 +21,7 @@
12329 */
12330
12331 #include <linux/linkage.h>
12332+#include <asm/alternative-asm.h>
12333
12334 .file "blowfish-x86_64-asm.S"
12335 .text
12336@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12337 jnz .L__enc_xor;
12338
12339 write_block();
12340+ pax_force_retaddr 0, 1
12341 ret;
12342 .L__enc_xor:
12343 xor_block();
12344+ pax_force_retaddr 0, 1
12345 ret;
12346 ENDPROC(__blowfish_enc_blk)
12347
12348@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12349
12350 movq %r11, %rbp;
12351
12352+ pax_force_retaddr 0, 1
12353 ret;
12354 ENDPROC(blowfish_dec_blk)
12355
12356@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12357
12358 popq %rbx;
12359 popq %rbp;
12360+ pax_force_retaddr 0, 1
12361 ret;
12362
12363 .L__enc_xor4:
12364@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12365
12366 popq %rbx;
12367 popq %rbp;
12368+ pax_force_retaddr 0, 1
12369 ret;
12370 ENDPROC(__blowfish_enc_blk_4way)
12371
12372@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12373 popq %rbx;
12374 popq %rbp;
12375
12376+ pax_force_retaddr 0, 1
12377 ret;
12378 ENDPROC(blowfish_dec_blk_4way)
12379diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12380index ce71f92..2dd5b1e 100644
12381--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12382+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12383@@ -16,6 +16,7 @@
12384 */
12385
12386 #include <linux/linkage.h>
12387+#include <asm/alternative-asm.h>
12388
12389 #define CAMELLIA_TABLE_BYTE_LEN 272
12390
12391@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12392 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12393 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12394 %rcx, (%r9));
12395+ pax_force_retaddr_bts
12396 ret;
12397 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12398
12399@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12400 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12401 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12402 %rax, (%r9));
12403+ pax_force_retaddr_bts
12404 ret;
12405 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12406
12407@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12408 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12409 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12410
12411+ pax_force_retaddr_bts
12412 ret;
12413
12414 .align 8
12415@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12416 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12417 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12418
12419+ pax_force_retaddr_bts
12420 ret;
12421
12422 .align 8
12423@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12424 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12425 %xmm8, %rsi);
12426
12427+ pax_force_retaddr 0, 1
12428 ret;
12429 ENDPROC(camellia_ecb_enc_16way)
12430
12431@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12432 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12433 %xmm8, %rsi);
12434
12435+ pax_force_retaddr 0, 1
12436 ret;
12437 ENDPROC(camellia_ecb_dec_16way)
12438
12439@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12440 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12441 %xmm8, %rsi);
12442
12443+ pax_force_retaddr 0, 1
12444 ret;
12445 ENDPROC(camellia_cbc_dec_16way)
12446
12447@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12448 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12449 %xmm8, %rsi);
12450
12451+ pax_force_retaddr 0, 1
12452 ret;
12453 ENDPROC(camellia_ctr_16way)
12454
12455@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12456 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12457 %xmm8, %rsi);
12458
12459+ pax_force_retaddr 0, 1
12460 ret;
12461 ENDPROC(camellia_xts_crypt_16way)
12462
12463diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12464index 0e0b886..8fc756a 100644
12465--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12466+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12467@@ -11,6 +11,7 @@
12468 */
12469
12470 #include <linux/linkage.h>
12471+#include <asm/alternative-asm.h>
12472
12473 #define CAMELLIA_TABLE_BYTE_LEN 272
12474
12475@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12476 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12477 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12478 %rcx, (%r9));
12479+ pax_force_retaddr_bts
12480 ret;
12481 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12482
12483@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12484 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12485 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12486 %rax, (%r9));
12487+ pax_force_retaddr_bts
12488 ret;
12489 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12490
12491@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12492 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12493 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12494
12495+ pax_force_retaddr_bts
12496 ret;
12497
12498 .align 8
12499@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12500 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12501 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12502
12503+ pax_force_retaddr_bts
12504 ret;
12505
12506 .align 8
12507@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12508
12509 vzeroupper;
12510
12511+ pax_force_retaddr 0, 1
12512 ret;
12513 ENDPROC(camellia_ecb_enc_32way)
12514
12515@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12516
12517 vzeroupper;
12518
12519+ pax_force_retaddr 0, 1
12520 ret;
12521 ENDPROC(camellia_ecb_dec_32way)
12522
12523@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12524
12525 vzeroupper;
12526
12527+ pax_force_retaddr 0, 1
12528 ret;
12529 ENDPROC(camellia_cbc_dec_32way)
12530
12531@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12532
12533 vzeroupper;
12534
12535+ pax_force_retaddr 0, 1
12536 ret;
12537 ENDPROC(camellia_ctr_32way)
12538
12539@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12540
12541 vzeroupper;
12542
12543+ pax_force_retaddr 0, 1
12544 ret;
12545 ENDPROC(camellia_xts_crypt_32way)
12546
12547diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12548index 310319c..ce174a4 100644
12549--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12550+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12551@@ -21,6 +21,7 @@
12552 */
12553
12554 #include <linux/linkage.h>
12555+#include <asm/alternative-asm.h>
12556
12557 .file "camellia-x86_64-asm_64.S"
12558 .text
12559@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12560 enc_outunpack(mov, RT1);
12561
12562 movq RRBP, %rbp;
12563+ pax_force_retaddr 0, 1
12564 ret;
12565
12566 .L__enc_xor:
12567 enc_outunpack(xor, RT1);
12568
12569 movq RRBP, %rbp;
12570+ pax_force_retaddr 0, 1
12571 ret;
12572 ENDPROC(__camellia_enc_blk)
12573
12574@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12575 dec_outunpack();
12576
12577 movq RRBP, %rbp;
12578+ pax_force_retaddr 0, 1
12579 ret;
12580 ENDPROC(camellia_dec_blk)
12581
12582@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12583
12584 movq RRBP, %rbp;
12585 popq %rbx;
12586+ pax_force_retaddr 0, 1
12587 ret;
12588
12589 .L__enc2_xor:
12590@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12591
12592 movq RRBP, %rbp;
12593 popq %rbx;
12594+ pax_force_retaddr 0, 1
12595 ret;
12596 ENDPROC(__camellia_enc_blk_2way)
12597
12598@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12599
12600 movq RRBP, %rbp;
12601 movq RXOR, %rbx;
12602+ pax_force_retaddr 0, 1
12603 ret;
12604 ENDPROC(camellia_dec_blk_2way)
12605diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12606index c35fd5d..c1ee236 100644
12607--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12608+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12609@@ -24,6 +24,7 @@
12610 */
12611
12612 #include <linux/linkage.h>
12613+#include <asm/alternative-asm.h>
12614
12615 .file "cast5-avx-x86_64-asm_64.S"
12616
12617@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12618 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12619 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12620
12621+ pax_force_retaddr 0, 1
12622 ret;
12623 ENDPROC(__cast5_enc_blk16)
12624
12625@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12626 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12627 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12628
12629+ pax_force_retaddr 0, 1
12630 ret;
12631
12632 .L__skip_dec:
12633@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12634 vmovdqu RR4, (6*4*4)(%r11);
12635 vmovdqu RL4, (7*4*4)(%r11);
12636
12637+ pax_force_retaddr
12638 ret;
12639 ENDPROC(cast5_ecb_enc_16way)
12640
12641@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12642 vmovdqu RR4, (6*4*4)(%r11);
12643 vmovdqu RL4, (7*4*4)(%r11);
12644
12645+ pax_force_retaddr
12646 ret;
12647 ENDPROC(cast5_ecb_dec_16way)
12648
12649@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12650
12651 popq %r12;
12652
12653+ pax_force_retaddr
12654 ret;
12655 ENDPROC(cast5_cbc_dec_16way)
12656
12657@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12658
12659 popq %r12;
12660
12661+ pax_force_retaddr
12662 ret;
12663 ENDPROC(cast5_ctr_16way)
12664diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12665index e3531f8..18ded3a 100644
12666--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12667+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12668@@ -24,6 +24,7 @@
12669 */
12670
12671 #include <linux/linkage.h>
12672+#include <asm/alternative-asm.h>
12673 #include "glue_helper-asm-avx.S"
12674
12675 .file "cast6-avx-x86_64-asm_64.S"
12676@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12677 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12678 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12679
12680+ pax_force_retaddr 0, 1
12681 ret;
12682 ENDPROC(__cast6_enc_blk8)
12683
12684@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12685 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12686 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12687
12688+ pax_force_retaddr 0, 1
12689 ret;
12690 ENDPROC(__cast6_dec_blk8)
12691
12692@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12693
12694 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12695
12696+ pax_force_retaddr
12697 ret;
12698 ENDPROC(cast6_ecb_enc_8way)
12699
12700@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12701
12702 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12703
12704+ pax_force_retaddr
12705 ret;
12706 ENDPROC(cast6_ecb_dec_8way)
12707
12708@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12709
12710 popq %r12;
12711
12712+ pax_force_retaddr
12713 ret;
12714 ENDPROC(cast6_cbc_dec_8way)
12715
12716@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12717
12718 popq %r12;
12719
12720+ pax_force_retaddr
12721 ret;
12722 ENDPROC(cast6_ctr_8way)
12723
12724@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12725 /* dst <= regs xor IVs(in dst) */
12726 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12727
12728+ pax_force_retaddr
12729 ret;
12730 ENDPROC(cast6_xts_enc_8way)
12731
12732@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12733 /* dst <= regs xor IVs(in dst) */
12734 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12735
12736+ pax_force_retaddr
12737 ret;
12738 ENDPROC(cast6_xts_dec_8way)
12739diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12740index dbc4339..3d868c5 100644
12741--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12742+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12743@@ -45,6 +45,7 @@
12744
12745 #include <asm/inst.h>
12746 #include <linux/linkage.h>
12747+#include <asm/alternative-asm.h>
12748
12749 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12750
12751@@ -312,6 +313,7 @@ do_return:
12752 popq %rsi
12753 popq %rdi
12754 popq %rbx
12755+ pax_force_retaddr 0, 1
12756 ret
12757
12758 ################################################################
12759diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12760index 586f41a..d02851e 100644
12761--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12762+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12763@@ -18,6 +18,7 @@
12764
12765 #include <linux/linkage.h>
12766 #include <asm/inst.h>
12767+#include <asm/alternative-asm.h>
12768
12769 .data
12770
12771@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12772 psrlq $1, T2
12773 pxor T2, T1
12774 pxor T1, DATA
12775+ pax_force_retaddr
12776 ret
12777 ENDPROC(__clmul_gf128mul_ble)
12778
12779@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12780 call __clmul_gf128mul_ble
12781 PSHUFB_XMM BSWAP DATA
12782 movups DATA, (%rdi)
12783+ pax_force_retaddr
12784 ret
12785 ENDPROC(clmul_ghash_mul)
12786
12787@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12788 PSHUFB_XMM BSWAP DATA
12789 movups DATA, (%rdi)
12790 .Lupdate_just_ret:
12791+ pax_force_retaddr
12792 ret
12793 ENDPROC(clmul_ghash_update)
12794
12795@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12796 pand .Lpoly, %xmm1
12797 pxor %xmm1, %xmm0
12798 movups %xmm0, (%rdi)
12799+ pax_force_retaddr
12800 ret
12801 ENDPROC(clmul_ghash_setkey)
12802diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12803index 9279e0b..9270820 100644
12804--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12805+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12806@@ -1,4 +1,5 @@
12807 #include <linux/linkage.h>
12808+#include <asm/alternative-asm.h>
12809
12810 # enter salsa20_encrypt_bytes
12811 ENTRY(salsa20_encrypt_bytes)
12812@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12813 add %r11,%rsp
12814 mov %rdi,%rax
12815 mov %rsi,%rdx
12816+ pax_force_retaddr 0, 1
12817 ret
12818 # bytesatleast65:
12819 ._bytesatleast65:
12820@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12821 add %r11,%rsp
12822 mov %rdi,%rax
12823 mov %rsi,%rdx
12824+ pax_force_retaddr
12825 ret
12826 ENDPROC(salsa20_keysetup)
12827
12828@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12829 add %r11,%rsp
12830 mov %rdi,%rax
12831 mov %rsi,%rdx
12832+ pax_force_retaddr
12833 ret
12834 ENDPROC(salsa20_ivsetup)
12835diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12836index 2f202f4..d9164d6 100644
12837--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12838+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12839@@ -24,6 +24,7 @@
12840 */
12841
12842 #include <linux/linkage.h>
12843+#include <asm/alternative-asm.h>
12844 #include "glue_helper-asm-avx.S"
12845
12846 .file "serpent-avx-x86_64-asm_64.S"
12847@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12848 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12849 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12850
12851+ pax_force_retaddr
12852 ret;
12853 ENDPROC(__serpent_enc_blk8_avx)
12854
12855@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12856 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12857 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12858
12859+ pax_force_retaddr
12860 ret;
12861 ENDPROC(__serpent_dec_blk8_avx)
12862
12863@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12864
12865 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12866
12867+ pax_force_retaddr
12868 ret;
12869 ENDPROC(serpent_ecb_enc_8way_avx)
12870
12871@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12872
12873 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12874
12875+ pax_force_retaddr
12876 ret;
12877 ENDPROC(serpent_ecb_dec_8way_avx)
12878
12879@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12880
12881 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12882
12883+ pax_force_retaddr
12884 ret;
12885 ENDPROC(serpent_cbc_dec_8way_avx)
12886
12887@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12888
12889 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12890
12891+ pax_force_retaddr
12892 ret;
12893 ENDPROC(serpent_ctr_8way_avx)
12894
12895@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12896 /* dst <= regs xor IVs(in dst) */
12897 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12898
12899+ pax_force_retaddr
12900 ret;
12901 ENDPROC(serpent_xts_enc_8way_avx)
12902
12903@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12904 /* dst <= regs xor IVs(in dst) */
12905 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12906
12907+ pax_force_retaddr
12908 ret;
12909 ENDPROC(serpent_xts_dec_8way_avx)
12910diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12911index b222085..abd483c 100644
12912--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12913+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12914@@ -15,6 +15,7 @@
12915 */
12916
12917 #include <linux/linkage.h>
12918+#include <asm/alternative-asm.h>
12919 #include "glue_helper-asm-avx2.S"
12920
12921 .file "serpent-avx2-asm_64.S"
12922@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12923 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12924 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12925
12926+ pax_force_retaddr
12927 ret;
12928 ENDPROC(__serpent_enc_blk16)
12929
12930@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12931 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12932 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12933
12934+ pax_force_retaddr
12935 ret;
12936 ENDPROC(__serpent_dec_blk16)
12937
12938@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12939
12940 vzeroupper;
12941
12942+ pax_force_retaddr
12943 ret;
12944 ENDPROC(serpent_ecb_enc_16way)
12945
12946@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12947
12948 vzeroupper;
12949
12950+ pax_force_retaddr
12951 ret;
12952 ENDPROC(serpent_ecb_dec_16way)
12953
12954@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12955
12956 vzeroupper;
12957
12958+ pax_force_retaddr
12959 ret;
12960 ENDPROC(serpent_cbc_dec_16way)
12961
12962@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12963
12964 vzeroupper;
12965
12966+ pax_force_retaddr
12967 ret;
12968 ENDPROC(serpent_ctr_16way)
12969
12970@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12971
12972 vzeroupper;
12973
12974+ pax_force_retaddr
12975 ret;
12976 ENDPROC(serpent_xts_enc_16way)
12977
12978@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12979
12980 vzeroupper;
12981
12982+ pax_force_retaddr
12983 ret;
12984 ENDPROC(serpent_xts_dec_16way)
12985diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12986index acc066c..1559cc4 100644
12987--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12988+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12989@@ -25,6 +25,7 @@
12990 */
12991
12992 #include <linux/linkage.h>
12993+#include <asm/alternative-asm.h>
12994
12995 .file "serpent-sse2-x86_64-asm_64.S"
12996 .text
12997@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12998 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12999 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13000
13001+ pax_force_retaddr
13002 ret;
13003
13004 .L__enc_xor8:
13005 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13006 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13007
13008+ pax_force_retaddr
13009 ret;
13010 ENDPROC(__serpent_enc_blk_8way)
13011
13012@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13013 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13014 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13015
13016+ pax_force_retaddr
13017 ret;
13018 ENDPROC(serpent_dec_blk_8way)
13019diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13020index a410950..3356d42 100644
13021--- a/arch/x86/crypto/sha1_ssse3_asm.S
13022+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13023@@ -29,6 +29,7 @@
13024 */
13025
13026 #include <linux/linkage.h>
13027+#include <asm/alternative-asm.h>
13028
13029 #define CTX %rdi // arg1
13030 #define BUF %rsi // arg2
13031@@ -104,6 +105,7 @@
13032 pop %r12
13033 pop %rbp
13034 pop %rbx
13035+ pax_force_retaddr 0, 1
13036 ret
13037
13038 ENDPROC(\name)
13039diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13040index 642f156..4ab07b9 100644
13041--- a/arch/x86/crypto/sha256-avx-asm.S
13042+++ b/arch/x86/crypto/sha256-avx-asm.S
13043@@ -49,6 +49,7 @@
13044
13045 #ifdef CONFIG_AS_AVX
13046 #include <linux/linkage.h>
13047+#include <asm/alternative-asm.h>
13048
13049 ## assume buffers not aligned
13050 #define VMOVDQ vmovdqu
13051@@ -460,6 +461,7 @@ done_hash:
13052 popq %r13
13053 popq %rbp
13054 popq %rbx
13055+ pax_force_retaddr 0, 1
13056 ret
13057 ENDPROC(sha256_transform_avx)
13058
13059diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13060index 9e86944..2e7f95a 100644
13061--- a/arch/x86/crypto/sha256-avx2-asm.S
13062+++ b/arch/x86/crypto/sha256-avx2-asm.S
13063@@ -50,6 +50,7 @@
13064
13065 #ifdef CONFIG_AS_AVX2
13066 #include <linux/linkage.h>
13067+#include <asm/alternative-asm.h>
13068
13069 ## assume buffers not aligned
13070 #define VMOVDQ vmovdqu
13071@@ -720,6 +721,7 @@ done_hash:
13072 popq %r12
13073 popq %rbp
13074 popq %rbx
13075+ pax_force_retaddr 0, 1
13076 ret
13077 ENDPROC(sha256_transform_rorx)
13078
13079diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13080index f833b74..c36ed14 100644
13081--- a/arch/x86/crypto/sha256-ssse3-asm.S
13082+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13083@@ -47,6 +47,7 @@
13084 ########################################################################
13085
13086 #include <linux/linkage.h>
13087+#include <asm/alternative-asm.h>
13088
13089 ## assume buffers not aligned
13090 #define MOVDQ movdqu
13091@@ -471,6 +472,7 @@ done_hash:
13092 popq %rbp
13093 popq %rbx
13094
13095+ pax_force_retaddr 0, 1
13096 ret
13097 ENDPROC(sha256_transform_ssse3)
13098
13099diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13100index 974dde9..4533d34 100644
13101--- a/arch/x86/crypto/sha512-avx-asm.S
13102+++ b/arch/x86/crypto/sha512-avx-asm.S
13103@@ -49,6 +49,7 @@
13104
13105 #ifdef CONFIG_AS_AVX
13106 #include <linux/linkage.h>
13107+#include <asm/alternative-asm.h>
13108
13109 .text
13110
13111@@ -364,6 +365,7 @@ updateblock:
13112 mov frame_RSPSAVE(%rsp), %rsp
13113
13114 nowork:
13115+ pax_force_retaddr 0, 1
13116 ret
13117 ENDPROC(sha512_transform_avx)
13118
13119diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13120index 568b961..061ef1d 100644
13121--- a/arch/x86/crypto/sha512-avx2-asm.S
13122+++ b/arch/x86/crypto/sha512-avx2-asm.S
13123@@ -51,6 +51,7 @@
13124
13125 #ifdef CONFIG_AS_AVX2
13126 #include <linux/linkage.h>
13127+#include <asm/alternative-asm.h>
13128
13129 .text
13130
13131@@ -678,6 +679,7 @@ done_hash:
13132
13133 # Restore Stack Pointer
13134 mov frame_RSPSAVE(%rsp), %rsp
13135+ pax_force_retaddr 0, 1
13136 ret
13137 ENDPROC(sha512_transform_rorx)
13138
13139diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13140index fb56855..e23914f 100644
13141--- a/arch/x86/crypto/sha512-ssse3-asm.S
13142+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13143@@ -48,6 +48,7 @@
13144 ########################################################################
13145
13146 #include <linux/linkage.h>
13147+#include <asm/alternative-asm.h>
13148
13149 .text
13150
13151@@ -363,6 +364,7 @@ updateblock:
13152 mov frame_RSPSAVE(%rsp), %rsp
13153
13154 nowork:
13155+ pax_force_retaddr 0, 1
13156 ret
13157 ENDPROC(sha512_transform_ssse3)
13158
13159diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13160index 0505813..63b1d00 100644
13161--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13162+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13163@@ -24,6 +24,7 @@
13164 */
13165
13166 #include <linux/linkage.h>
13167+#include <asm/alternative-asm.h>
13168 #include "glue_helper-asm-avx.S"
13169
13170 .file "twofish-avx-x86_64-asm_64.S"
13171@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13172 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13173 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13174
13175+ pax_force_retaddr 0, 1
13176 ret;
13177 ENDPROC(__twofish_enc_blk8)
13178
13179@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13180 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13181 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13182
13183+ pax_force_retaddr 0, 1
13184 ret;
13185 ENDPROC(__twofish_dec_blk8)
13186
13187@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13188
13189 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13190
13191+ pax_force_retaddr 0, 1
13192 ret;
13193 ENDPROC(twofish_ecb_enc_8way)
13194
13195@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13196
13197 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13198
13199+ pax_force_retaddr 0, 1
13200 ret;
13201 ENDPROC(twofish_ecb_dec_8way)
13202
13203@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13204
13205 popq %r12;
13206
13207+ pax_force_retaddr 0, 1
13208 ret;
13209 ENDPROC(twofish_cbc_dec_8way)
13210
13211@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13212
13213 popq %r12;
13214
13215+ pax_force_retaddr 0, 1
13216 ret;
13217 ENDPROC(twofish_ctr_8way)
13218
13219@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13220 /* dst <= regs xor IVs(in dst) */
13221 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13222
13223+ pax_force_retaddr 0, 1
13224 ret;
13225 ENDPROC(twofish_xts_enc_8way)
13226
13227@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13228 /* dst <= regs xor IVs(in dst) */
13229 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13230
13231+ pax_force_retaddr 0, 1
13232 ret;
13233 ENDPROC(twofish_xts_dec_8way)
13234diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13235index 1c3b7ce..b365c5e 100644
13236--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13237+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13238@@ -21,6 +21,7 @@
13239 */
13240
13241 #include <linux/linkage.h>
13242+#include <asm/alternative-asm.h>
13243
13244 .file "twofish-x86_64-asm-3way.S"
13245 .text
13246@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13247 popq %r13;
13248 popq %r14;
13249 popq %r15;
13250+ pax_force_retaddr 0, 1
13251 ret;
13252
13253 .L__enc_xor3:
13254@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13255 popq %r13;
13256 popq %r14;
13257 popq %r15;
13258+ pax_force_retaddr 0, 1
13259 ret;
13260 ENDPROC(__twofish_enc_blk_3way)
13261
13262@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13263 popq %r13;
13264 popq %r14;
13265 popq %r15;
13266+ pax_force_retaddr 0, 1
13267 ret;
13268 ENDPROC(twofish_dec_blk_3way)
13269diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13270index a039d21..29e7615 100644
13271--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13272+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13273@@ -22,6 +22,7 @@
13274
13275 #include <linux/linkage.h>
13276 #include <asm/asm-offsets.h>
13277+#include <asm/alternative-asm.h>
13278
13279 #define a_offset 0
13280 #define b_offset 4
13281@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13282
13283 popq R1
13284 movq $1,%rax
13285+ pax_force_retaddr 0, 1
13286 ret
13287 ENDPROC(twofish_enc_blk)
13288
13289@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13290
13291 popq R1
13292 movq $1,%rax
13293+ pax_force_retaddr 0, 1
13294 ret
13295 ENDPROC(twofish_dec_blk)
13296diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13297index bae3aba..c1788c1 100644
13298--- a/arch/x86/ia32/ia32_aout.c
13299+++ b/arch/x86/ia32/ia32_aout.c
13300@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13301 unsigned long dump_start, dump_size;
13302 struct user32 dump;
13303
13304+ memset(&dump, 0, sizeof(dump));
13305+
13306 fs = get_fs();
13307 set_fs(KERNEL_DS);
13308 has_dumped = 1;
13309diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13310index 665a730..8e7a67a 100644
13311--- a/arch/x86/ia32/ia32_signal.c
13312+++ b/arch/x86/ia32/ia32_signal.c
13313@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13314 sp -= frame_size;
13315 /* Align the stack pointer according to the i386 ABI,
13316 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13317- sp = ((sp + 4) & -16ul) - 4;
13318+ sp = ((sp - 12) & -16ul) - 4;
13319 return (void __user *) sp;
13320 }
13321
13322@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13323 * These are actually not used anymore, but left because some
13324 * gdb versions depend on them as a marker.
13325 */
13326- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13327+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13328 } put_user_catch(err);
13329
13330 if (err)
13331@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13332 0xb8,
13333 __NR_ia32_rt_sigreturn,
13334 0x80cd,
13335- 0,
13336+ 0
13337 };
13338
13339 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13340@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13341
13342 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13343 restorer = ksig->ka.sa.sa_restorer;
13344+ else if (current->mm->context.vdso)
13345+ /* Return stub is in 32bit vsyscall page */
13346+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13347 else
13348- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13349- rt_sigreturn);
13350+ restorer = &frame->retcode;
13351 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13352
13353 /*
13354 * Not actually used anymore, but left because some gdb
13355 * versions need it.
13356 */
13357- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13358+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13359 } put_user_catch(err);
13360
13361 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13362diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13363index 474dc1b..9297c58 100644
13364--- a/arch/x86/ia32/ia32entry.S
13365+++ b/arch/x86/ia32/ia32entry.S
13366@@ -15,8 +15,10 @@
13367 #include <asm/irqflags.h>
13368 #include <asm/asm.h>
13369 #include <asm/smap.h>
13370+#include <asm/pgtable.h>
13371 #include <linux/linkage.h>
13372 #include <linux/err.h>
13373+#include <asm/alternative-asm.h>
13374
13375 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13376 #include <linux/elf-em.h>
13377@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13378 ENDPROC(native_irq_enable_sysexit)
13379 #endif
13380
13381+ .macro pax_enter_kernel_user
13382+ pax_set_fptr_mask
13383+#ifdef CONFIG_PAX_MEMORY_UDEREF
13384+ call pax_enter_kernel_user
13385+#endif
13386+ .endm
13387+
13388+ .macro pax_exit_kernel_user
13389+#ifdef CONFIG_PAX_MEMORY_UDEREF
13390+ call pax_exit_kernel_user
13391+#endif
13392+#ifdef CONFIG_PAX_RANDKSTACK
13393+ pushq %rax
13394+ pushq %r11
13395+ call pax_randomize_kstack
13396+ popq %r11
13397+ popq %rax
13398+#endif
13399+ .endm
13400+
13401+ .macro pax_erase_kstack
13402+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13403+ call pax_erase_kstack
13404+#endif
13405+ .endm
13406+
13407 /*
13408 * 32bit SYSENTER instruction entry.
13409 *
13410@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13411 CFI_REGISTER rsp,rbp
13412 SWAPGS_UNSAFE_STACK
13413 movq PER_CPU_VAR(kernel_stack), %rsp
13414- addq $(KERNEL_STACK_OFFSET),%rsp
13415- /*
13416- * No need to follow this irqs on/off section: the syscall
13417- * disabled irqs, here we enable it straight after entry:
13418- */
13419- ENABLE_INTERRUPTS(CLBR_NONE)
13420 movl %ebp,%ebp /* zero extension */
13421 pushq_cfi $__USER32_DS
13422 /*CFI_REL_OFFSET ss,0*/
13423@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13424 CFI_REL_OFFSET rsp,0
13425 pushfq_cfi
13426 /*CFI_REL_OFFSET rflags,0*/
13427- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13428- CFI_REGISTER rip,r10
13429+ orl $X86_EFLAGS_IF,(%rsp)
13430+ GET_THREAD_INFO(%r11)
13431+ movl TI_sysenter_return(%r11), %r11d
13432+ CFI_REGISTER rip,r11
13433 pushq_cfi $__USER32_CS
13434 /*CFI_REL_OFFSET cs,0*/
13435 movl %eax, %eax
13436- pushq_cfi %r10
13437+ pushq_cfi %r11
13438 CFI_REL_OFFSET rip,0
13439 pushq_cfi %rax
13440 cld
13441 SAVE_ARGS 0,1,0
13442+ pax_enter_kernel_user
13443+
13444+#ifdef CONFIG_PAX_RANDKSTACK
13445+ pax_erase_kstack
13446+#endif
13447+
13448+ /*
13449+ * No need to follow this irqs on/off section: the syscall
13450+ * disabled irqs, here we enable it straight after entry:
13451+ */
13452+ ENABLE_INTERRUPTS(CLBR_NONE)
13453 /* no need to do an access_ok check here because rbp has been
13454 32bit zero extended */
13455+
13456+#ifdef CONFIG_PAX_MEMORY_UDEREF
13457+ addq pax_user_shadow_base,%rbp
13458+ ASM_PAX_OPEN_USERLAND
13459+#endif
13460+
13461 ASM_STAC
13462 1: movl (%rbp),%ebp
13463 _ASM_EXTABLE(1b,ia32_badarg)
13464 ASM_CLAC
13465- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13466- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13467+
13468+#ifdef CONFIG_PAX_MEMORY_UDEREF
13469+ ASM_PAX_CLOSE_USERLAND
13470+#endif
13471+
13472+ GET_THREAD_INFO(%r11)
13473+ orl $TS_COMPAT,TI_status(%r11)
13474+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13475 CFI_REMEMBER_STATE
13476 jnz sysenter_tracesys
13477 cmpq $(IA32_NR_syscalls-1),%rax
13478@@ -162,12 +209,15 @@ sysenter_do_call:
13479 sysenter_dispatch:
13480 call *ia32_sys_call_table(,%rax,8)
13481 movq %rax,RAX-ARGOFFSET(%rsp)
13482+ GET_THREAD_INFO(%r11)
13483 DISABLE_INTERRUPTS(CLBR_NONE)
13484 TRACE_IRQS_OFF
13485- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13486+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13487 jnz sysexit_audit
13488 sysexit_from_sys_call:
13489- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13490+ pax_exit_kernel_user
13491+ pax_erase_kstack
13492+ andl $~TS_COMPAT,TI_status(%r11)
13493 /* clear IF, that popfq doesn't enable interrupts early */
13494 andl $~0x200,EFLAGS-R11(%rsp)
13495 movl RIP-R11(%rsp),%edx /* User %eip */
13496@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13497 movl %eax,%esi /* 2nd arg: syscall number */
13498 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13499 call __audit_syscall_entry
13500+
13501+ pax_erase_kstack
13502+
13503 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13504 cmpq $(IA32_NR_syscalls-1),%rax
13505 ja ia32_badsys
13506@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13507 .endm
13508
13509 .macro auditsys_exit exit
13510- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13511+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13512 jnz ia32_ret_from_sys_call
13513 TRACE_IRQS_ON
13514 ENABLE_INTERRUPTS(CLBR_NONE)
13515@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13516 1: setbe %al /* 1 if error, 0 if not */
13517 movzbl %al,%edi /* zero-extend that into %edi */
13518 call __audit_syscall_exit
13519+ GET_THREAD_INFO(%r11)
13520 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13521 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13522 DISABLE_INTERRUPTS(CLBR_NONE)
13523 TRACE_IRQS_OFF
13524- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13525+ testl %edi,TI_flags(%r11)
13526 jz \exit
13527 CLEAR_RREGS -ARGOFFSET
13528 jmp int_with_check
13529@@ -237,7 +291,7 @@ sysexit_audit:
13530
13531 sysenter_tracesys:
13532 #ifdef CONFIG_AUDITSYSCALL
13533- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13534+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13535 jz sysenter_auditsys
13536 #endif
13537 SAVE_REST
13538@@ -249,6 +303,9 @@ sysenter_tracesys:
13539 RESTORE_REST
13540 cmpq $(IA32_NR_syscalls-1),%rax
13541 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13542+
13543+ pax_erase_kstack
13544+
13545 jmp sysenter_do_call
13546 CFI_ENDPROC
13547 ENDPROC(ia32_sysenter_target)
13548@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13549 ENTRY(ia32_cstar_target)
13550 CFI_STARTPROC32 simple
13551 CFI_SIGNAL_FRAME
13552- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13553+ CFI_DEF_CFA rsp,0
13554 CFI_REGISTER rip,rcx
13555 /*CFI_REGISTER rflags,r11*/
13556 SWAPGS_UNSAFE_STACK
13557 movl %esp,%r8d
13558 CFI_REGISTER rsp,r8
13559 movq PER_CPU_VAR(kernel_stack),%rsp
13560+ SAVE_ARGS 8*6,0,0
13561+ pax_enter_kernel_user
13562+
13563+#ifdef CONFIG_PAX_RANDKSTACK
13564+ pax_erase_kstack
13565+#endif
13566+
13567 /*
13568 * No need to follow this irqs on/off section: the syscall
13569 * disabled irqs and here we enable it straight after entry:
13570 */
13571 ENABLE_INTERRUPTS(CLBR_NONE)
13572- SAVE_ARGS 8,0,0
13573 movl %eax,%eax /* zero extension */
13574 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13575 movq %rcx,RIP-ARGOFFSET(%rsp)
13576@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13577 /* no need to do an access_ok check here because r8 has been
13578 32bit zero extended */
13579 /* hardware stack frame is complete now */
13580+
13581+#ifdef CONFIG_PAX_MEMORY_UDEREF
13582+ ASM_PAX_OPEN_USERLAND
13583+ movq pax_user_shadow_base,%r8
13584+ addq RSP-ARGOFFSET(%rsp),%r8
13585+#endif
13586+
13587 ASM_STAC
13588 1: movl (%r8),%r9d
13589 _ASM_EXTABLE(1b,ia32_badarg)
13590 ASM_CLAC
13591- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13592- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13593+
13594+#ifdef CONFIG_PAX_MEMORY_UDEREF
13595+ ASM_PAX_CLOSE_USERLAND
13596+#endif
13597+
13598+ GET_THREAD_INFO(%r11)
13599+ orl $TS_COMPAT,TI_status(%r11)
13600+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13601 CFI_REMEMBER_STATE
13602 jnz cstar_tracesys
13603 cmpq $IA32_NR_syscalls-1,%rax
13604@@ -319,12 +395,15 @@ cstar_do_call:
13605 cstar_dispatch:
13606 call *ia32_sys_call_table(,%rax,8)
13607 movq %rax,RAX-ARGOFFSET(%rsp)
13608+ GET_THREAD_INFO(%r11)
13609 DISABLE_INTERRUPTS(CLBR_NONE)
13610 TRACE_IRQS_OFF
13611- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13612+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13613 jnz sysretl_audit
13614 sysretl_from_sys_call:
13615- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13616+ pax_exit_kernel_user
13617+ pax_erase_kstack
13618+ andl $~TS_COMPAT,TI_status(%r11)
13619 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13620 movl RIP-ARGOFFSET(%rsp),%ecx
13621 CFI_REGISTER rip,rcx
13622@@ -352,7 +431,7 @@ sysretl_audit:
13623
13624 cstar_tracesys:
13625 #ifdef CONFIG_AUDITSYSCALL
13626- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13627+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13628 jz cstar_auditsys
13629 #endif
13630 xchgl %r9d,%ebp
13631@@ -366,11 +445,19 @@ cstar_tracesys:
13632 xchgl %ebp,%r9d
13633 cmpq $(IA32_NR_syscalls-1),%rax
13634 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13635+
13636+ pax_erase_kstack
13637+
13638 jmp cstar_do_call
13639 END(ia32_cstar_target)
13640
13641 ia32_badarg:
13642 ASM_CLAC
13643+
13644+#ifdef CONFIG_PAX_MEMORY_UDEREF
13645+ ASM_PAX_CLOSE_USERLAND
13646+#endif
13647+
13648 movq $-EFAULT,%rax
13649 jmp ia32_sysret
13650 CFI_ENDPROC
13651@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13652 CFI_REL_OFFSET rip,RIP-RIP
13653 PARAVIRT_ADJUST_EXCEPTION_FRAME
13654 SWAPGS
13655- /*
13656- * No need to follow this irqs on/off section: the syscall
13657- * disabled irqs and here we enable it straight after entry:
13658- */
13659- ENABLE_INTERRUPTS(CLBR_NONE)
13660 movl %eax,%eax
13661 pushq_cfi %rax
13662 cld
13663 /* note the registers are not zero extended to the sf.
13664 this could be a problem. */
13665 SAVE_ARGS 0,1,0
13666- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13667- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13668+ pax_enter_kernel_user
13669+
13670+#ifdef CONFIG_PAX_RANDKSTACK
13671+ pax_erase_kstack
13672+#endif
13673+
13674+ /*
13675+ * No need to follow this irqs on/off section: the syscall
13676+ * disabled irqs and here we enable it straight after entry:
13677+ */
13678+ ENABLE_INTERRUPTS(CLBR_NONE)
13679+ GET_THREAD_INFO(%r11)
13680+ orl $TS_COMPAT,TI_status(%r11)
13681+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13682 jnz ia32_tracesys
13683 cmpq $(IA32_NR_syscalls-1),%rax
13684 ja ia32_badsys
13685@@ -442,6 +536,9 @@ ia32_tracesys:
13686 RESTORE_REST
13687 cmpq $(IA32_NR_syscalls-1),%rax
13688 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13689+
13690+ pax_erase_kstack
13691+
13692 jmp ia32_do_call
13693 END(ia32_syscall)
13694
13695diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13696index 8e0ceec..af13504 100644
13697--- a/arch/x86/ia32/sys_ia32.c
13698+++ b/arch/x86/ia32/sys_ia32.c
13699@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13700 */
13701 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13702 {
13703- typeof(ubuf->st_uid) uid = 0;
13704- typeof(ubuf->st_gid) gid = 0;
13705+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13706+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13707 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13708 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13709 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13710diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13711index 372231c..a5aa1a1 100644
13712--- a/arch/x86/include/asm/alternative-asm.h
13713+++ b/arch/x86/include/asm/alternative-asm.h
13714@@ -18,6 +18,45 @@
13715 .endm
13716 #endif
13717
13718+#ifdef KERNEXEC_PLUGIN
13719+ .macro pax_force_retaddr_bts rip=0
13720+ btsq $63,\rip(%rsp)
13721+ .endm
13722+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13723+ .macro pax_force_retaddr rip=0, reload=0
13724+ btsq $63,\rip(%rsp)
13725+ .endm
13726+ .macro pax_force_fptr ptr
13727+ btsq $63,\ptr
13728+ .endm
13729+ .macro pax_set_fptr_mask
13730+ .endm
13731+#endif
13732+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13733+ .macro pax_force_retaddr rip=0, reload=0
13734+ .if \reload
13735+ pax_set_fptr_mask
13736+ .endif
13737+ orq %r10,\rip(%rsp)
13738+ .endm
13739+ .macro pax_force_fptr ptr
13740+ orq %r10,\ptr
13741+ .endm
13742+ .macro pax_set_fptr_mask
13743+ movabs $0x8000000000000000,%r10
13744+ .endm
13745+#endif
13746+#else
13747+ .macro pax_force_retaddr rip=0, reload=0
13748+ .endm
13749+ .macro pax_force_fptr ptr
13750+ .endm
13751+ .macro pax_force_retaddr_bts rip=0
13752+ .endm
13753+ .macro pax_set_fptr_mask
13754+ .endm
13755+#endif
13756+
13757 .macro altinstruction_entry orig alt feature orig_len alt_len
13758 .long \orig - .
13759 .long \alt - .
13760diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13761index 58ed6d9..f1cbe58 100644
13762--- a/arch/x86/include/asm/alternative.h
13763+++ b/arch/x86/include/asm/alternative.h
13764@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13765 ".pushsection .discard,\"aw\",@progbits\n" \
13766 DISCARD_ENTRY(1) \
13767 ".popsection\n" \
13768- ".pushsection .altinstr_replacement, \"ax\"\n" \
13769+ ".pushsection .altinstr_replacement, \"a\"\n" \
13770 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13771 ".popsection"
13772
13773@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13774 DISCARD_ENTRY(1) \
13775 DISCARD_ENTRY(2) \
13776 ".popsection\n" \
13777- ".pushsection .altinstr_replacement, \"ax\"\n" \
13778+ ".pushsection .altinstr_replacement, \"a\"\n" \
13779 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13780 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13781 ".popsection"
13782diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13783index f8119b5..7209d5b 100644
13784--- a/arch/x86/include/asm/apic.h
13785+++ b/arch/x86/include/asm/apic.h
13786@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13787
13788 #ifdef CONFIG_X86_LOCAL_APIC
13789
13790-extern unsigned int apic_verbosity;
13791+extern int apic_verbosity;
13792 extern int local_apic_timer_c2_ok;
13793
13794 extern int disable_apic;
13795diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13796index 20370c6..a2eb9b0 100644
13797--- a/arch/x86/include/asm/apm.h
13798+++ b/arch/x86/include/asm/apm.h
13799@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13800 __asm__ __volatile__(APM_DO_ZERO_SEGS
13801 "pushl %%edi\n\t"
13802 "pushl %%ebp\n\t"
13803- "lcall *%%cs:apm_bios_entry\n\t"
13804+ "lcall *%%ss:apm_bios_entry\n\t"
13805 "setc %%al\n\t"
13806 "popl %%ebp\n\t"
13807 "popl %%edi\n\t"
13808@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13809 __asm__ __volatile__(APM_DO_ZERO_SEGS
13810 "pushl %%edi\n\t"
13811 "pushl %%ebp\n\t"
13812- "lcall *%%cs:apm_bios_entry\n\t"
13813+ "lcall *%%ss:apm_bios_entry\n\t"
13814 "setc %%bl\n\t"
13815 "popl %%ebp\n\t"
13816 "popl %%edi\n\t"
13817diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13818index 722aa3b..3a0bb27 100644
13819--- a/arch/x86/include/asm/atomic.h
13820+++ b/arch/x86/include/asm/atomic.h
13821@@ -22,7 +22,18 @@
13822 */
13823 static inline int atomic_read(const atomic_t *v)
13824 {
13825- return (*(volatile int *)&(v)->counter);
13826+ return (*(volatile const int *)&(v)->counter);
13827+}
13828+
13829+/**
13830+ * atomic_read_unchecked - read atomic variable
13831+ * @v: pointer of type atomic_unchecked_t
13832+ *
13833+ * Atomically reads the value of @v.
13834+ */
13835+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13836+{
13837+ return (*(volatile const int *)&(v)->counter);
13838 }
13839
13840 /**
13841@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13842 }
13843
13844 /**
13845+ * atomic_set_unchecked - set atomic variable
13846+ * @v: pointer of type atomic_unchecked_t
13847+ * @i: required value
13848+ *
13849+ * Atomically sets the value of @v to @i.
13850+ */
13851+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13852+{
13853+ v->counter = i;
13854+}
13855+
13856+/**
13857 * atomic_add - add integer to atomic variable
13858 * @i: integer value to add
13859 * @v: pointer of type atomic_t
13860@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13861 */
13862 static inline void atomic_add(int i, atomic_t *v)
13863 {
13864- asm volatile(LOCK_PREFIX "addl %1,%0"
13865+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13866+
13867+#ifdef CONFIG_PAX_REFCOUNT
13868+ "jno 0f\n"
13869+ LOCK_PREFIX "subl %1,%0\n"
13870+ "int $4\n0:\n"
13871+ _ASM_EXTABLE(0b, 0b)
13872+#endif
13873+
13874+ : "+m" (v->counter)
13875+ : "ir" (i));
13876+}
13877+
13878+/**
13879+ * atomic_add_unchecked - add integer to atomic variable
13880+ * @i: integer value to add
13881+ * @v: pointer of type atomic_unchecked_t
13882+ *
13883+ * Atomically adds @i to @v.
13884+ */
13885+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13886+{
13887+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13888 : "+m" (v->counter)
13889 : "ir" (i));
13890 }
13891@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13892 */
13893 static inline void atomic_sub(int i, atomic_t *v)
13894 {
13895- asm volatile(LOCK_PREFIX "subl %1,%0"
13896+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13897+
13898+#ifdef CONFIG_PAX_REFCOUNT
13899+ "jno 0f\n"
13900+ LOCK_PREFIX "addl %1,%0\n"
13901+ "int $4\n0:\n"
13902+ _ASM_EXTABLE(0b, 0b)
13903+#endif
13904+
13905+ : "+m" (v->counter)
13906+ : "ir" (i));
13907+}
13908+
13909+/**
13910+ * atomic_sub_unchecked - subtract integer from atomic variable
13911+ * @i: integer value to subtract
13912+ * @v: pointer of type atomic_unchecked_t
13913+ *
13914+ * Atomically subtracts @i from @v.
13915+ */
13916+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13917+{
13918+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13919 : "+m" (v->counter)
13920 : "ir" (i));
13921 }
13922@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13923 {
13924 unsigned char c;
13925
13926- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13927+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13928+
13929+#ifdef CONFIG_PAX_REFCOUNT
13930+ "jno 0f\n"
13931+ LOCK_PREFIX "addl %2,%0\n"
13932+ "int $4\n0:\n"
13933+ _ASM_EXTABLE(0b, 0b)
13934+#endif
13935+
13936+ "sete %1\n"
13937 : "+m" (v->counter), "=qm" (c)
13938 : "ir" (i) : "memory");
13939 return c;
13940@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13941 */
13942 static inline void atomic_inc(atomic_t *v)
13943 {
13944- asm volatile(LOCK_PREFIX "incl %0"
13945+ asm volatile(LOCK_PREFIX "incl %0\n"
13946+
13947+#ifdef CONFIG_PAX_REFCOUNT
13948+ "jno 0f\n"
13949+ LOCK_PREFIX "decl %0\n"
13950+ "int $4\n0:\n"
13951+ _ASM_EXTABLE(0b, 0b)
13952+#endif
13953+
13954+ : "+m" (v->counter));
13955+}
13956+
13957+/**
13958+ * atomic_inc_unchecked - increment atomic variable
13959+ * @v: pointer of type atomic_unchecked_t
13960+ *
13961+ * Atomically increments @v by 1.
13962+ */
13963+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13964+{
13965+ asm volatile(LOCK_PREFIX "incl %0\n"
13966 : "+m" (v->counter));
13967 }
13968
13969@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13970 */
13971 static inline void atomic_dec(atomic_t *v)
13972 {
13973- asm volatile(LOCK_PREFIX "decl %0"
13974+ asm volatile(LOCK_PREFIX "decl %0\n"
13975+
13976+#ifdef CONFIG_PAX_REFCOUNT
13977+ "jno 0f\n"
13978+ LOCK_PREFIX "incl %0\n"
13979+ "int $4\n0:\n"
13980+ _ASM_EXTABLE(0b, 0b)
13981+#endif
13982+
13983+ : "+m" (v->counter));
13984+}
13985+
13986+/**
13987+ * atomic_dec_unchecked - decrement atomic variable
13988+ * @v: pointer of type atomic_unchecked_t
13989+ *
13990+ * Atomically decrements @v by 1.
13991+ */
13992+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13993+{
13994+ asm volatile(LOCK_PREFIX "decl %0\n"
13995 : "+m" (v->counter));
13996 }
13997
13998@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13999 {
14000 unsigned char c;
14001
14002- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14003+ asm volatile(LOCK_PREFIX "decl %0\n"
14004+
14005+#ifdef CONFIG_PAX_REFCOUNT
14006+ "jno 0f\n"
14007+ LOCK_PREFIX "incl %0\n"
14008+ "int $4\n0:\n"
14009+ _ASM_EXTABLE(0b, 0b)
14010+#endif
14011+
14012+ "sete %1\n"
14013 : "+m" (v->counter), "=qm" (c)
14014 : : "memory");
14015 return c != 0;
14016@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14017 {
14018 unsigned char c;
14019
14020- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14021+ asm volatile(LOCK_PREFIX "incl %0\n"
14022+
14023+#ifdef CONFIG_PAX_REFCOUNT
14024+ "jno 0f\n"
14025+ LOCK_PREFIX "decl %0\n"
14026+ "int $4\n0:\n"
14027+ _ASM_EXTABLE(0b, 0b)
14028+#endif
14029+
14030+ "sete %1\n"
14031+ : "+m" (v->counter), "=qm" (c)
14032+ : : "memory");
14033+ return c != 0;
14034+}
14035+
14036+/**
14037+ * atomic_inc_and_test_unchecked - increment and test
14038+ * @v: pointer of type atomic_unchecked_t
14039+ *
14040+ * Atomically increments @v by 1
14041+ * and returns true if the result is zero, or false for all
14042+ * other cases.
14043+ */
14044+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14045+{
14046+ unsigned char c;
14047+
14048+ asm volatile(LOCK_PREFIX "incl %0\n"
14049+ "sete %1\n"
14050 : "+m" (v->counter), "=qm" (c)
14051 : : "memory");
14052 return c != 0;
14053@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14054 {
14055 unsigned char c;
14056
14057- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14058+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14059+
14060+#ifdef CONFIG_PAX_REFCOUNT
14061+ "jno 0f\n"
14062+ LOCK_PREFIX "subl %2,%0\n"
14063+ "int $4\n0:\n"
14064+ _ASM_EXTABLE(0b, 0b)
14065+#endif
14066+
14067+ "sets %1\n"
14068 : "+m" (v->counter), "=qm" (c)
14069 : "ir" (i) : "memory");
14070 return c;
14071@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14072 */
14073 static inline int atomic_add_return(int i, atomic_t *v)
14074 {
14075+ return i + xadd_check_overflow(&v->counter, i);
14076+}
14077+
14078+/**
14079+ * atomic_add_return_unchecked - add integer and return
14080+ * @i: integer value to add
14081+ * @v: pointer of type atomic_unchecked_t
14082+ *
14083+ * Atomically adds @i to @v and returns @i + @v
14084+ */
14085+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14086+{
14087 return i + xadd(&v->counter, i);
14088 }
14089
14090@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14091 }
14092
14093 #define atomic_inc_return(v) (atomic_add_return(1, v))
14094+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14095+{
14096+ return atomic_add_return_unchecked(1, v);
14097+}
14098 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14099
14100 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14101@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14102 return cmpxchg(&v->counter, old, new);
14103 }
14104
14105+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14106+{
14107+ return cmpxchg(&v->counter, old, new);
14108+}
14109+
14110 static inline int atomic_xchg(atomic_t *v, int new)
14111 {
14112 return xchg(&v->counter, new);
14113 }
14114
14115+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14116+{
14117+ return xchg(&v->counter, new);
14118+}
14119+
14120 /**
14121 * __atomic_add_unless - add unless the number is already a given value
14122 * @v: pointer of type atomic_t
14123@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14124 */
14125 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14126 {
14127- int c, old;
14128+ int c, old, new;
14129 c = atomic_read(v);
14130 for (;;) {
14131- if (unlikely(c == (u)))
14132+ if (unlikely(c == u))
14133 break;
14134- old = atomic_cmpxchg((v), c, c + (a));
14135+
14136+ asm volatile("addl %2,%0\n"
14137+
14138+#ifdef CONFIG_PAX_REFCOUNT
14139+ "jno 0f\n"
14140+ "subl %2,%0\n"
14141+ "int $4\n0:\n"
14142+ _ASM_EXTABLE(0b, 0b)
14143+#endif
14144+
14145+ : "=r" (new)
14146+ : "0" (c), "ir" (a));
14147+
14148+ old = atomic_cmpxchg(v, c, new);
14149 if (likely(old == c))
14150 break;
14151 c = old;
14152@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14153 }
14154
14155 /**
14156+ * atomic_inc_not_zero_hint - increment if not null
14157+ * @v: pointer of type atomic_t
14158+ * @hint: probable value of the atomic before the increment
14159+ *
14160+ * This version of atomic_inc_not_zero() gives a hint of probable
14161+ * value of the atomic. This helps processor to not read the memory
14162+ * before doing the atomic read/modify/write cycle, lowering
14163+ * number of bus transactions on some arches.
14164+ *
14165+ * Returns: 0 if increment was not done, 1 otherwise.
14166+ */
14167+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14168+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14169+{
14170+ int val, c = hint, new;
14171+
14172+ /* sanity test, should be removed by compiler if hint is a constant */
14173+ if (!hint)
14174+ return __atomic_add_unless(v, 1, 0);
14175+
14176+ do {
14177+ asm volatile("incl %0\n"
14178+
14179+#ifdef CONFIG_PAX_REFCOUNT
14180+ "jno 0f\n"
14181+ "decl %0\n"
14182+ "int $4\n0:\n"
14183+ _ASM_EXTABLE(0b, 0b)
14184+#endif
14185+
14186+ : "=r" (new)
14187+ : "0" (c));
14188+
14189+ val = atomic_cmpxchg(v, c, new);
14190+ if (val == c)
14191+ return 1;
14192+ c = val;
14193+ } while (c);
14194+
14195+ return 0;
14196+}
14197+
14198+/**
14199 * atomic_inc_short - increment of a short integer
14200 * @v: pointer to type int
14201 *
14202@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14203 #endif
14204
14205 /* These are x86-specific, used by some header files */
14206-#define atomic_clear_mask(mask, addr) \
14207- asm volatile(LOCK_PREFIX "andl %0,%1" \
14208- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14209+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14210+{
14211+ asm volatile(LOCK_PREFIX "andl %1,%0"
14212+ : "+m" (v->counter)
14213+ : "r" (~(mask))
14214+ : "memory");
14215+}
14216
14217-#define atomic_set_mask(mask, addr) \
14218- asm volatile(LOCK_PREFIX "orl %0,%1" \
14219- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14220- : "memory")
14221+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14222+{
14223+ asm volatile(LOCK_PREFIX "andl %1,%0"
14224+ : "+m" (v->counter)
14225+ : "r" (~(mask))
14226+ : "memory");
14227+}
14228+
14229+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14230+{
14231+ asm volatile(LOCK_PREFIX "orl %1,%0"
14232+ : "+m" (v->counter)
14233+ : "r" (mask)
14234+ : "memory");
14235+}
14236+
14237+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14238+{
14239+ asm volatile(LOCK_PREFIX "orl %1,%0"
14240+ : "+m" (v->counter)
14241+ : "r" (mask)
14242+ : "memory");
14243+}
14244
14245 /* Atomic operations are already serializing on x86 */
14246 #define smp_mb__before_atomic_dec() barrier()
14247diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14248index b154de7..aadebd8 100644
14249--- a/arch/x86/include/asm/atomic64_32.h
14250+++ b/arch/x86/include/asm/atomic64_32.h
14251@@ -12,6 +12,14 @@ typedef struct {
14252 u64 __aligned(8) counter;
14253 } atomic64_t;
14254
14255+#ifdef CONFIG_PAX_REFCOUNT
14256+typedef struct {
14257+ u64 __aligned(8) counter;
14258+} atomic64_unchecked_t;
14259+#else
14260+typedef atomic64_t atomic64_unchecked_t;
14261+#endif
14262+
14263 #define ATOMIC64_INIT(val) { (val) }
14264
14265 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14266@@ -37,21 +45,31 @@ typedef struct {
14267 ATOMIC64_DECL_ONE(sym##_386)
14268
14269 ATOMIC64_DECL_ONE(add_386);
14270+ATOMIC64_DECL_ONE(add_unchecked_386);
14271 ATOMIC64_DECL_ONE(sub_386);
14272+ATOMIC64_DECL_ONE(sub_unchecked_386);
14273 ATOMIC64_DECL_ONE(inc_386);
14274+ATOMIC64_DECL_ONE(inc_unchecked_386);
14275 ATOMIC64_DECL_ONE(dec_386);
14276+ATOMIC64_DECL_ONE(dec_unchecked_386);
14277 #endif
14278
14279 #define alternative_atomic64(f, out, in...) \
14280 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14281
14282 ATOMIC64_DECL(read);
14283+ATOMIC64_DECL(read_unchecked);
14284 ATOMIC64_DECL(set);
14285+ATOMIC64_DECL(set_unchecked);
14286 ATOMIC64_DECL(xchg);
14287 ATOMIC64_DECL(add_return);
14288+ATOMIC64_DECL(add_return_unchecked);
14289 ATOMIC64_DECL(sub_return);
14290+ATOMIC64_DECL(sub_return_unchecked);
14291 ATOMIC64_DECL(inc_return);
14292+ATOMIC64_DECL(inc_return_unchecked);
14293 ATOMIC64_DECL(dec_return);
14294+ATOMIC64_DECL(dec_return_unchecked);
14295 ATOMIC64_DECL(dec_if_positive);
14296 ATOMIC64_DECL(inc_not_zero);
14297 ATOMIC64_DECL(add_unless);
14298@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14299 }
14300
14301 /**
14302+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14303+ * @p: pointer to type atomic64_unchecked_t
14304+ * @o: expected value
14305+ * @n: new value
14306+ *
14307+ * Atomically sets @v to @n if it was equal to @o and returns
14308+ * the old value.
14309+ */
14310+
14311+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14312+{
14313+ return cmpxchg64(&v->counter, o, n);
14314+}
14315+
14316+/**
14317 * atomic64_xchg - xchg atomic64 variable
14318 * @v: pointer to type atomic64_t
14319 * @n: value to assign
14320@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14321 }
14322
14323 /**
14324+ * atomic64_set_unchecked - set atomic64 variable
14325+ * @v: pointer to type atomic64_unchecked_t
14326+ * @n: value to assign
14327+ *
14328+ * Atomically sets the value of @v to @n.
14329+ */
14330+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14331+{
14332+ unsigned high = (unsigned)(i >> 32);
14333+ unsigned low = (unsigned)i;
14334+ alternative_atomic64(set, /* no output */,
14335+ "S" (v), "b" (low), "c" (high)
14336+ : "eax", "edx", "memory");
14337+}
14338+
14339+/**
14340 * atomic64_read - read atomic64 variable
14341 * @v: pointer to type atomic64_t
14342 *
14343@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14344 }
14345
14346 /**
14347+ * atomic64_read_unchecked - read atomic64 variable
14348+ * @v: pointer to type atomic64_unchecked_t
14349+ *
14350+ * Atomically reads the value of @v and returns it.
14351+ */
14352+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14353+{
14354+ long long r;
14355+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14356+ return r;
14357+ }
14358+
14359+/**
14360 * atomic64_add_return - add and return
14361 * @i: integer value to add
14362 * @v: pointer to type atomic64_t
14363@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14364 return i;
14365 }
14366
14367+/**
14368+ * atomic64_add_return_unchecked - add and return
14369+ * @i: integer value to add
14370+ * @v: pointer to type atomic64_unchecked_t
14371+ *
14372+ * Atomically adds @i to @v and returns @i + *@v
14373+ */
14374+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14375+{
14376+ alternative_atomic64(add_return_unchecked,
14377+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14378+ ASM_NO_INPUT_CLOBBER("memory"));
14379+ return i;
14380+}
14381+
14382 /*
14383 * Other variants with different arithmetic operators:
14384 */
14385@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14386 return a;
14387 }
14388
14389+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14390+{
14391+ long long a;
14392+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14393+ "S" (v) : "memory", "ecx");
14394+ return a;
14395+}
14396+
14397 static inline long long atomic64_dec_return(atomic64_t *v)
14398 {
14399 long long a;
14400@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14401 }
14402
14403 /**
14404+ * atomic64_add_unchecked - add integer to atomic64 variable
14405+ * @i: integer value to add
14406+ * @v: pointer to type atomic64_unchecked_t
14407+ *
14408+ * Atomically adds @i to @v.
14409+ */
14410+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14411+{
14412+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14413+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14414+ ASM_NO_INPUT_CLOBBER("memory"));
14415+ return i;
14416+}
14417+
14418+/**
14419 * atomic64_sub - subtract the atomic64 variable
14420 * @i: integer value to subtract
14421 * @v: pointer to type atomic64_t
14422diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14423index 0e1cbfc..5623683 100644
14424--- a/arch/x86/include/asm/atomic64_64.h
14425+++ b/arch/x86/include/asm/atomic64_64.h
14426@@ -18,7 +18,19 @@
14427 */
14428 static inline long atomic64_read(const atomic64_t *v)
14429 {
14430- return (*(volatile long *)&(v)->counter);
14431+ return (*(volatile const long *)&(v)->counter);
14432+}
14433+
14434+/**
14435+ * atomic64_read_unchecked - read atomic64 variable
14436+ * @v: pointer of type atomic64_unchecked_t
14437+ *
14438+ * Atomically reads the value of @v.
14439+ * Doesn't imply a read memory barrier.
14440+ */
14441+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14442+{
14443+ return (*(volatile const long *)&(v)->counter);
14444 }
14445
14446 /**
14447@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14448 }
14449
14450 /**
14451+ * atomic64_set_unchecked - set atomic64 variable
14452+ * @v: pointer to type atomic64_unchecked_t
14453+ * @i: required value
14454+ *
14455+ * Atomically sets the value of @v to @i.
14456+ */
14457+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14458+{
14459+ v->counter = i;
14460+}
14461+
14462+/**
14463 * atomic64_add - add integer to atomic64 variable
14464 * @i: integer value to add
14465 * @v: pointer to type atomic64_t
14466@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14467 */
14468 static inline void atomic64_add(long i, atomic64_t *v)
14469 {
14470+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14471+
14472+#ifdef CONFIG_PAX_REFCOUNT
14473+ "jno 0f\n"
14474+ LOCK_PREFIX "subq %1,%0\n"
14475+ "int $4\n0:\n"
14476+ _ASM_EXTABLE(0b, 0b)
14477+#endif
14478+
14479+ : "=m" (v->counter)
14480+ : "er" (i), "m" (v->counter));
14481+}
14482+
14483+/**
14484+ * atomic64_add_unchecked - add integer to atomic64 variable
14485+ * @i: integer value to add
14486+ * @v: pointer to type atomic64_unchecked_t
14487+ *
14488+ * Atomically adds @i to @v.
14489+ */
14490+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14491+{
14492 asm volatile(LOCK_PREFIX "addq %1,%0"
14493 : "=m" (v->counter)
14494 : "er" (i), "m" (v->counter));
14495@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14496 */
14497 static inline void atomic64_sub(long i, atomic64_t *v)
14498 {
14499- asm volatile(LOCK_PREFIX "subq %1,%0"
14500+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14501+
14502+#ifdef CONFIG_PAX_REFCOUNT
14503+ "jno 0f\n"
14504+ LOCK_PREFIX "addq %1,%0\n"
14505+ "int $4\n0:\n"
14506+ _ASM_EXTABLE(0b, 0b)
14507+#endif
14508+
14509+ : "=m" (v->counter)
14510+ : "er" (i), "m" (v->counter));
14511+}
14512+
14513+/**
14514+ * atomic64_sub_unchecked - subtract the atomic64 variable
14515+ * @i: integer value to subtract
14516+ * @v: pointer to type atomic64_unchecked_t
14517+ *
14518+ * Atomically subtracts @i from @v.
14519+ */
14520+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14521+{
14522+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14523 : "=m" (v->counter)
14524 : "er" (i), "m" (v->counter));
14525 }
14526@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14527 {
14528 unsigned char c;
14529
14530- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14531+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14532+
14533+#ifdef CONFIG_PAX_REFCOUNT
14534+ "jno 0f\n"
14535+ LOCK_PREFIX "addq %2,%0\n"
14536+ "int $4\n0:\n"
14537+ _ASM_EXTABLE(0b, 0b)
14538+#endif
14539+
14540+ "sete %1\n"
14541 : "=m" (v->counter), "=qm" (c)
14542 : "er" (i), "m" (v->counter) : "memory");
14543 return c;
14544@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14545 */
14546 static inline void atomic64_inc(atomic64_t *v)
14547 {
14548+ asm volatile(LOCK_PREFIX "incq %0\n"
14549+
14550+#ifdef CONFIG_PAX_REFCOUNT
14551+ "jno 0f\n"
14552+ LOCK_PREFIX "decq %0\n"
14553+ "int $4\n0:\n"
14554+ _ASM_EXTABLE(0b, 0b)
14555+#endif
14556+
14557+ : "=m" (v->counter)
14558+ : "m" (v->counter));
14559+}
14560+
14561+/**
14562+ * atomic64_inc_unchecked - increment atomic64 variable
14563+ * @v: pointer to type atomic64_unchecked_t
14564+ *
14565+ * Atomically increments @v by 1.
14566+ */
14567+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14568+{
14569 asm volatile(LOCK_PREFIX "incq %0"
14570 : "=m" (v->counter)
14571 : "m" (v->counter));
14572@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14573 */
14574 static inline void atomic64_dec(atomic64_t *v)
14575 {
14576- asm volatile(LOCK_PREFIX "decq %0"
14577+ asm volatile(LOCK_PREFIX "decq %0\n"
14578+
14579+#ifdef CONFIG_PAX_REFCOUNT
14580+ "jno 0f\n"
14581+ LOCK_PREFIX "incq %0\n"
14582+ "int $4\n0:\n"
14583+ _ASM_EXTABLE(0b, 0b)
14584+#endif
14585+
14586+ : "=m" (v->counter)
14587+ : "m" (v->counter));
14588+}
14589+
14590+/**
14591+ * atomic64_dec_unchecked - decrement atomic64 variable
14592+ * @v: pointer to type atomic64_t
14593+ *
14594+ * Atomically decrements @v by 1.
14595+ */
14596+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14597+{
14598+ asm volatile(LOCK_PREFIX "decq %0\n"
14599 : "=m" (v->counter)
14600 : "m" (v->counter));
14601 }
14602@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14603 {
14604 unsigned char c;
14605
14606- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14607+ asm volatile(LOCK_PREFIX "decq %0\n"
14608+
14609+#ifdef CONFIG_PAX_REFCOUNT
14610+ "jno 0f\n"
14611+ LOCK_PREFIX "incq %0\n"
14612+ "int $4\n0:\n"
14613+ _ASM_EXTABLE(0b, 0b)
14614+#endif
14615+
14616+ "sete %1\n"
14617 : "=m" (v->counter), "=qm" (c)
14618 : "m" (v->counter) : "memory");
14619 return c != 0;
14620@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14621 {
14622 unsigned char c;
14623
14624- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14625+ asm volatile(LOCK_PREFIX "incq %0\n"
14626+
14627+#ifdef CONFIG_PAX_REFCOUNT
14628+ "jno 0f\n"
14629+ LOCK_PREFIX "decq %0\n"
14630+ "int $4\n0:\n"
14631+ _ASM_EXTABLE(0b, 0b)
14632+#endif
14633+
14634+ "sete %1\n"
14635 : "=m" (v->counter), "=qm" (c)
14636 : "m" (v->counter) : "memory");
14637 return c != 0;
14638@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14639 {
14640 unsigned char c;
14641
14642- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14643+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14644+
14645+#ifdef CONFIG_PAX_REFCOUNT
14646+ "jno 0f\n"
14647+ LOCK_PREFIX "subq %2,%0\n"
14648+ "int $4\n0:\n"
14649+ _ASM_EXTABLE(0b, 0b)
14650+#endif
14651+
14652+ "sets %1\n"
14653 : "=m" (v->counter), "=qm" (c)
14654 : "er" (i), "m" (v->counter) : "memory");
14655 return c;
14656@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14657 */
14658 static inline long atomic64_add_return(long i, atomic64_t *v)
14659 {
14660+ return i + xadd_check_overflow(&v->counter, i);
14661+}
14662+
14663+/**
14664+ * atomic64_add_return_unchecked - add and return
14665+ * @i: integer value to add
14666+ * @v: pointer to type atomic64_unchecked_t
14667+ *
14668+ * Atomically adds @i to @v and returns @i + @v
14669+ */
14670+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14671+{
14672 return i + xadd(&v->counter, i);
14673 }
14674
14675@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14676 }
14677
14678 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14679+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14680+{
14681+ return atomic64_add_return_unchecked(1, v);
14682+}
14683 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14684
14685 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14686@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14687 return cmpxchg(&v->counter, old, new);
14688 }
14689
14690+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14691+{
14692+ return cmpxchg(&v->counter, old, new);
14693+}
14694+
14695 static inline long atomic64_xchg(atomic64_t *v, long new)
14696 {
14697 return xchg(&v->counter, new);
14698@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14699 */
14700 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14701 {
14702- long c, old;
14703+ long c, old, new;
14704 c = atomic64_read(v);
14705 for (;;) {
14706- if (unlikely(c == (u)))
14707+ if (unlikely(c == u))
14708 break;
14709- old = atomic64_cmpxchg((v), c, c + (a));
14710+
14711+ asm volatile("add %2,%0\n"
14712+
14713+#ifdef CONFIG_PAX_REFCOUNT
14714+ "jno 0f\n"
14715+ "sub %2,%0\n"
14716+ "int $4\n0:\n"
14717+ _ASM_EXTABLE(0b, 0b)
14718+#endif
14719+
14720+ : "=r" (new)
14721+ : "0" (c), "ir" (a));
14722+
14723+ old = atomic64_cmpxchg(v, c, new);
14724 if (likely(old == c))
14725 break;
14726 c = old;
14727 }
14728- return c != (u);
14729+ return c != u;
14730 }
14731
14732 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14733diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14734index 6dfd019..28e188d 100644
14735--- a/arch/x86/include/asm/bitops.h
14736+++ b/arch/x86/include/asm/bitops.h
14737@@ -40,7 +40,7 @@
14738 * a mask operation on a byte.
14739 */
14740 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14741-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14742+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14743 #define CONST_MASK(nr) (1 << ((nr) & 7))
14744
14745 /**
14746@@ -486,7 +486,7 @@ static inline int fls(int x)
14747 * at position 64.
14748 */
14749 #ifdef CONFIG_X86_64
14750-static __always_inline int fls64(__u64 x)
14751+static __always_inline long fls64(__u64 x)
14752 {
14753 int bitpos = -1;
14754 /*
14755diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14756index 4fa687a..60f2d39 100644
14757--- a/arch/x86/include/asm/boot.h
14758+++ b/arch/x86/include/asm/boot.h
14759@@ -6,10 +6,15 @@
14760 #include <uapi/asm/boot.h>
14761
14762 /* Physical address where kernel should be loaded. */
14763-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14764+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14765 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14766 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14767
14768+#ifndef __ASSEMBLY__
14769+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14770+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14771+#endif
14772+
14773 /* Minimum kernel alignment, as a power of two */
14774 #ifdef CONFIG_X86_64
14775 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14776diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14777index 48f99f1..d78ebf9 100644
14778--- a/arch/x86/include/asm/cache.h
14779+++ b/arch/x86/include/asm/cache.h
14780@@ -5,12 +5,13 @@
14781
14782 /* L1 cache line size */
14783 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14784-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14785+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14786
14787 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14788+#define __read_only __attribute__((__section__(".data..read_only")))
14789
14790 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14791-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14792+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14793
14794 #ifdef CONFIG_X86_VSMP
14795 #ifdef CONFIG_SMP
14796diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14797index 9863ee3..4a1f8e1 100644
14798--- a/arch/x86/include/asm/cacheflush.h
14799+++ b/arch/x86/include/asm/cacheflush.h
14800@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14801 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14802
14803 if (pg_flags == _PGMT_DEFAULT)
14804- return -1;
14805+ return ~0UL;
14806 else if (pg_flags == _PGMT_WC)
14807 return _PAGE_CACHE_WC;
14808 else if (pg_flags == _PGMT_UC_MINUS)
14809diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14810index f50de69..2b0a458 100644
14811--- a/arch/x86/include/asm/checksum_32.h
14812+++ b/arch/x86/include/asm/checksum_32.h
14813@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14814 int len, __wsum sum,
14815 int *src_err_ptr, int *dst_err_ptr);
14816
14817+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14818+ int len, __wsum sum,
14819+ int *src_err_ptr, int *dst_err_ptr);
14820+
14821+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14822+ int len, __wsum sum,
14823+ int *src_err_ptr, int *dst_err_ptr);
14824+
14825 /*
14826 * Note: when you get a NULL pointer exception here this means someone
14827 * passed in an incorrect kernel address to one of these functions.
14828@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14829
14830 might_sleep();
14831 stac();
14832- ret = csum_partial_copy_generic((__force void *)src, dst,
14833+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14834 len, sum, err_ptr, NULL);
14835 clac();
14836
14837@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14838 might_sleep();
14839 if (access_ok(VERIFY_WRITE, dst, len)) {
14840 stac();
14841- ret = csum_partial_copy_generic(src, (__force void *)dst,
14842+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14843 len, sum, NULL, err_ptr);
14844 clac();
14845 return ret;
14846diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14847index d47786a..ce1b05d 100644
14848--- a/arch/x86/include/asm/cmpxchg.h
14849+++ b/arch/x86/include/asm/cmpxchg.h
14850@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14851 __compiletime_error("Bad argument size for cmpxchg");
14852 extern void __xadd_wrong_size(void)
14853 __compiletime_error("Bad argument size for xadd");
14854+extern void __xadd_check_overflow_wrong_size(void)
14855+ __compiletime_error("Bad argument size for xadd_check_overflow");
14856 extern void __add_wrong_size(void)
14857 __compiletime_error("Bad argument size for add");
14858+extern void __add_check_overflow_wrong_size(void)
14859+ __compiletime_error("Bad argument size for add_check_overflow");
14860
14861 /*
14862 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14863@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14864 __ret; \
14865 })
14866
14867+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14868+ ({ \
14869+ __typeof__ (*(ptr)) __ret = (arg); \
14870+ switch (sizeof(*(ptr))) { \
14871+ case __X86_CASE_L: \
14872+ asm volatile (lock #op "l %0, %1\n" \
14873+ "jno 0f\n" \
14874+ "mov %0,%1\n" \
14875+ "int $4\n0:\n" \
14876+ _ASM_EXTABLE(0b, 0b) \
14877+ : "+r" (__ret), "+m" (*(ptr)) \
14878+ : : "memory", "cc"); \
14879+ break; \
14880+ case __X86_CASE_Q: \
14881+ asm volatile (lock #op "q %q0, %1\n" \
14882+ "jno 0f\n" \
14883+ "mov %0,%1\n" \
14884+ "int $4\n0:\n" \
14885+ _ASM_EXTABLE(0b, 0b) \
14886+ : "+r" (__ret), "+m" (*(ptr)) \
14887+ : : "memory", "cc"); \
14888+ break; \
14889+ default: \
14890+ __ ## op ## _check_overflow_wrong_size(); \
14891+ } \
14892+ __ret; \
14893+ })
14894+
14895 /*
14896 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14897 * Since this is generally used to protect other memory information, we
14898@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14899 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14900 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14901
14902+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14903+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14904+
14905 #define __add(ptr, inc, lock) \
14906 ({ \
14907 __typeof__ (*(ptr)) __ret = (inc); \
14908diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14909index 59c6c40..5e0b22c 100644
14910--- a/arch/x86/include/asm/compat.h
14911+++ b/arch/x86/include/asm/compat.h
14912@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14913 typedef u32 compat_uint_t;
14914 typedef u32 compat_ulong_t;
14915 typedef u64 __attribute__((aligned(4))) compat_u64;
14916-typedef u32 compat_uptr_t;
14917+typedef u32 __user compat_uptr_t;
14918
14919 struct compat_timespec {
14920 compat_time_t tv_sec;
14921diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14922index 47538a6..44902d1 100644
14923--- a/arch/x86/include/asm/cpufeature.h
14924+++ b/arch/x86/include/asm/cpufeature.h
14925@@ -203,7 +203,7 @@
14926 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14927 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14928 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14929-
14930+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14931
14932 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14933 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14934@@ -211,7 +211,7 @@
14935 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14936 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14937 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14938-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14939+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14940 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14941 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14942 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14943@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14944 #undef cpu_has_centaur_mcr
14945 #define cpu_has_centaur_mcr 0
14946
14947+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14948 #endif /* CONFIG_X86_64 */
14949
14950 #if __GNUC__ >= 4
14951@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14952
14953 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14954 t_warn:
14955- warn_pre_alternatives();
14956+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14957+ warn_pre_alternatives();
14958 return false;
14959 #endif
14960 #else /* GCC_VERSION >= 40500 */
14961@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14962 ".section .discard,\"aw\",@progbits\n"
14963 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14964 ".previous\n"
14965- ".section .altinstr_replacement,\"ax\"\n"
14966+ ".section .altinstr_replacement,\"a\"\n"
14967 "3: movb $1,%0\n"
14968 "4:\n"
14969 ".previous\n"
14970@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14971 " .byte 2b - 1b\n" /* src len */
14972 " .byte 4f - 3f\n" /* repl len */
14973 ".previous\n"
14974- ".section .altinstr_replacement,\"ax\"\n"
14975+ ".section .altinstr_replacement,\"a\"\n"
14976 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14977 "4:\n"
14978 ".previous\n"
14979@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14980 ".section .discard,\"aw\",@progbits\n"
14981 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14982 ".previous\n"
14983- ".section .altinstr_replacement,\"ax\"\n"
14984+ ".section .altinstr_replacement,\"a\"\n"
14985 "3: movb $0,%0\n"
14986 "4:\n"
14987 ".previous\n"
14988@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14989 ".section .discard,\"aw\",@progbits\n"
14990 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14991 ".previous\n"
14992- ".section .altinstr_replacement,\"ax\"\n"
14993+ ".section .altinstr_replacement,\"a\"\n"
14994 "5: movb $1,%0\n"
14995 "6:\n"
14996 ".previous\n"
14997diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14998index b90e5df..b462c91 100644
14999--- a/arch/x86/include/asm/desc.h
15000+++ b/arch/x86/include/asm/desc.h
15001@@ -4,6 +4,7 @@
15002 #include <asm/desc_defs.h>
15003 #include <asm/ldt.h>
15004 #include <asm/mmu.h>
15005+#include <asm/pgtable.h>
15006
15007 #include <linux/smp.h>
15008 #include <linux/percpu.h>
15009@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15010
15011 desc->type = (info->read_exec_only ^ 1) << 1;
15012 desc->type |= info->contents << 2;
15013+ desc->type |= info->seg_not_present ^ 1;
15014
15015 desc->s = 1;
15016 desc->dpl = 0x3;
15017@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15018 }
15019
15020 extern struct desc_ptr idt_descr;
15021-extern gate_desc idt_table[];
15022-extern struct desc_ptr debug_idt_descr;
15023-extern gate_desc debug_idt_table[];
15024-
15025-struct gdt_page {
15026- struct desc_struct gdt[GDT_ENTRIES];
15027-} __attribute__((aligned(PAGE_SIZE)));
15028-
15029-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15030+extern gate_desc idt_table[IDT_ENTRIES];
15031+extern const struct desc_ptr debug_idt_descr;
15032+extern gate_desc debug_idt_table[IDT_ENTRIES];
15033
15034+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15035 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15036 {
15037- return per_cpu(gdt_page, cpu).gdt;
15038+ return cpu_gdt_table[cpu];
15039 }
15040
15041 #ifdef CONFIG_X86_64
15042@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15043 unsigned long base, unsigned dpl, unsigned flags,
15044 unsigned short seg)
15045 {
15046- gate->a = (seg << 16) | (base & 0xffff);
15047- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15048+ gate->gate.offset_low = base;
15049+ gate->gate.seg = seg;
15050+ gate->gate.reserved = 0;
15051+ gate->gate.type = type;
15052+ gate->gate.s = 0;
15053+ gate->gate.dpl = dpl;
15054+ gate->gate.p = 1;
15055+ gate->gate.offset_high = base >> 16;
15056 }
15057
15058 #endif
15059@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15060
15061 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15062 {
15063+ pax_open_kernel();
15064 memcpy(&idt[entry], gate, sizeof(*gate));
15065+ pax_close_kernel();
15066 }
15067
15068 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15069 {
15070+ pax_open_kernel();
15071 memcpy(&ldt[entry], desc, 8);
15072+ pax_close_kernel();
15073 }
15074
15075 static inline void
15076@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15077 default: size = sizeof(*gdt); break;
15078 }
15079
15080+ pax_open_kernel();
15081 memcpy(&gdt[entry], desc, size);
15082+ pax_close_kernel();
15083 }
15084
15085 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15086@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15087
15088 static inline void native_load_tr_desc(void)
15089 {
15090+ pax_open_kernel();
15091 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15092+ pax_close_kernel();
15093 }
15094
15095 static inline void native_load_gdt(const struct desc_ptr *dtr)
15096@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15097 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15098 unsigned int i;
15099
15100+ pax_open_kernel();
15101 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15102 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15103+ pax_close_kernel();
15104 }
15105
15106 #define _LDT_empty(info) \
15107@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15108 preempt_enable();
15109 }
15110
15111-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15112+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15113 {
15114 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15115 }
15116@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15117 }
15118
15119 #ifdef CONFIG_X86_64
15120-static inline void set_nmi_gate(int gate, void *addr)
15121+static inline void set_nmi_gate(int gate, const void *addr)
15122 {
15123 gate_desc s;
15124
15125@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15126 #endif
15127
15128 #ifdef CONFIG_TRACING
15129-extern struct desc_ptr trace_idt_descr;
15130-extern gate_desc trace_idt_table[];
15131+extern const struct desc_ptr trace_idt_descr;
15132+extern gate_desc trace_idt_table[IDT_ENTRIES];
15133 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15134 {
15135 write_idt_entry(trace_idt_table, entry, gate);
15136@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15137 }
15138 #endif
15139
15140-static inline void _set_gate(int gate, unsigned type, void *addr,
15141+static inline void _set_gate(int gate, unsigned type, const void *addr,
15142 unsigned dpl, unsigned ist, unsigned seg)
15143 {
15144 gate_desc s;
15145@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15146 * Pentium F0 0F bugfix can have resulted in the mapped
15147 * IDT being write-protected.
15148 */
15149-static inline void set_intr_gate(unsigned int n, void *addr)
15150+static inline void set_intr_gate(unsigned int n, const void *addr)
15151 {
15152 BUG_ON((unsigned)n > 0xFF);
15153 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15154@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15155 /*
15156 * This routine sets up an interrupt gate at directory privilege level 3.
15157 */
15158-static inline void set_system_intr_gate(unsigned int n, void *addr)
15159+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15160 {
15161 BUG_ON((unsigned)n > 0xFF);
15162 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15163 }
15164
15165-static inline void set_system_trap_gate(unsigned int n, void *addr)
15166+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15167 {
15168 BUG_ON((unsigned)n > 0xFF);
15169 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15170 }
15171
15172-static inline void set_trap_gate(unsigned int n, void *addr)
15173+static inline void set_trap_gate(unsigned int n, const void *addr)
15174 {
15175 BUG_ON((unsigned)n > 0xFF);
15176 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15177@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15178 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15179 {
15180 BUG_ON((unsigned)n > 0xFF);
15181- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15182+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15183 }
15184
15185-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15186+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15187 {
15188 BUG_ON((unsigned)n > 0xFF);
15189 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15190 }
15191
15192-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15193+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15194 {
15195 BUG_ON((unsigned)n > 0xFF);
15196 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15197@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15198 else
15199 load_idt((const struct desc_ptr *)&idt_descr);
15200 }
15201+
15202+#ifdef CONFIG_X86_32
15203+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15204+{
15205+ struct desc_struct d;
15206+
15207+ if (likely(limit))
15208+ limit = (limit - 1UL) >> PAGE_SHIFT;
15209+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15210+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15211+}
15212+#endif
15213+
15214 #endif /* _ASM_X86_DESC_H */
15215diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15216index 278441f..b95a174 100644
15217--- a/arch/x86/include/asm/desc_defs.h
15218+++ b/arch/x86/include/asm/desc_defs.h
15219@@ -31,6 +31,12 @@ struct desc_struct {
15220 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15221 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15222 };
15223+ struct {
15224+ u16 offset_low;
15225+ u16 seg;
15226+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15227+ unsigned offset_high: 16;
15228+ } gate;
15229 };
15230 } __attribute__((packed));
15231
15232diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15233index ced283a..ffe04cc 100644
15234--- a/arch/x86/include/asm/div64.h
15235+++ b/arch/x86/include/asm/div64.h
15236@@ -39,7 +39,7 @@
15237 __mod; \
15238 })
15239
15240-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15241+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15242 {
15243 union {
15244 u64 v64;
15245diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15246index 9c999c1..3860cb8 100644
15247--- a/arch/x86/include/asm/elf.h
15248+++ b/arch/x86/include/asm/elf.h
15249@@ -243,7 +243,25 @@ extern int force_personality32;
15250 the loader. We need to make sure that it is out of the way of the program
15251 that it will "exec", and that there is sufficient room for the brk. */
15252
15253+#ifdef CONFIG_PAX_SEGMEXEC
15254+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15255+#else
15256 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15257+#endif
15258+
15259+#ifdef CONFIG_PAX_ASLR
15260+#ifdef CONFIG_X86_32
15261+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15262+
15263+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15264+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15265+#else
15266+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15267+
15268+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15269+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15270+#endif
15271+#endif
15272
15273 /* This yields a mask that user programs can use to figure out what
15274 instruction set this CPU supports. This could be done in user space,
15275@@ -296,16 +314,12 @@ do { \
15276
15277 #define ARCH_DLINFO \
15278 do { \
15279- if (vdso_enabled) \
15280- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15281- (unsigned long)current->mm->context.vdso); \
15282+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15283 } while (0)
15284
15285 #define ARCH_DLINFO_X32 \
15286 do { \
15287- if (vdso_enabled) \
15288- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15289- (unsigned long)current->mm->context.vdso); \
15290+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15291 } while (0)
15292
15293 #define AT_SYSINFO 32
15294@@ -320,7 +334,7 @@ else \
15295
15296 #endif /* !CONFIG_X86_32 */
15297
15298-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15299+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15300
15301 #define VDSO_ENTRY \
15302 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15303@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15304 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15305 #define compat_arch_setup_additional_pages syscall32_setup_pages
15306
15307-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15308-#define arch_randomize_brk arch_randomize_brk
15309-
15310 /*
15311 * True on X86_32 or when emulating IA32 on X86_64
15312 */
15313diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15314index 77a99ac..39ff7f5 100644
15315--- a/arch/x86/include/asm/emergency-restart.h
15316+++ b/arch/x86/include/asm/emergency-restart.h
15317@@ -1,6 +1,6 @@
15318 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15319 #define _ASM_X86_EMERGENCY_RESTART_H
15320
15321-extern void machine_emergency_restart(void);
15322+extern void machine_emergency_restart(void) __noreturn;
15323
15324 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15325diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15326index 4d0bda7..221da4d 100644
15327--- a/arch/x86/include/asm/fpu-internal.h
15328+++ b/arch/x86/include/asm/fpu-internal.h
15329@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15330 #define user_insn(insn, output, input...) \
15331 ({ \
15332 int err; \
15333+ pax_open_userland(); \
15334 asm volatile(ASM_STAC "\n" \
15335- "1:" #insn "\n\t" \
15336+ "1:" \
15337+ __copyuser_seg \
15338+ #insn "\n\t" \
15339 "2: " ASM_CLAC "\n" \
15340 ".section .fixup,\"ax\"\n" \
15341 "3: movl $-1,%[err]\n" \
15342@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15343 _ASM_EXTABLE(1b, 3b) \
15344 : [err] "=r" (err), output \
15345 : "0"(0), input); \
15346+ pax_close_userland(); \
15347 err; \
15348 })
15349
15350@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15351 "emms\n\t" /* clear stack tags */
15352 "fildl %P[addr]", /* set F?P to defined value */
15353 X86_FEATURE_FXSAVE_LEAK,
15354- [addr] "m" (tsk->thread.fpu.has_fpu));
15355+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15356
15357 return fpu_restore_checking(&tsk->thread.fpu);
15358 }
15359diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15360index be27ba1..04a8801 100644
15361--- a/arch/x86/include/asm/futex.h
15362+++ b/arch/x86/include/asm/futex.h
15363@@ -12,6 +12,7 @@
15364 #include <asm/smap.h>
15365
15366 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15367+ typecheck(u32 __user *, uaddr); \
15368 asm volatile("\t" ASM_STAC "\n" \
15369 "1:\t" insn "\n" \
15370 "2:\t" ASM_CLAC "\n" \
15371@@ -20,15 +21,16 @@
15372 "\tjmp\t2b\n" \
15373 "\t.previous\n" \
15374 _ASM_EXTABLE(1b, 3b) \
15375- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15376+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15377 : "i" (-EFAULT), "0" (oparg), "1" (0))
15378
15379 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15380+ typecheck(u32 __user *, uaddr); \
15381 asm volatile("\t" ASM_STAC "\n" \
15382 "1:\tmovl %2, %0\n" \
15383 "\tmovl\t%0, %3\n" \
15384 "\t" insn "\n" \
15385- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15386+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15387 "\tjnz\t1b\n" \
15388 "3:\t" ASM_CLAC "\n" \
15389 "\t.section .fixup,\"ax\"\n" \
15390@@ -38,7 +40,7 @@
15391 _ASM_EXTABLE(1b, 4b) \
15392 _ASM_EXTABLE(2b, 4b) \
15393 : "=&a" (oldval), "=&r" (ret), \
15394- "+m" (*uaddr), "=&r" (tem) \
15395+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15396 : "r" (oparg), "i" (-EFAULT), "1" (0))
15397
15398 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15399@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15400
15401 pagefault_disable();
15402
15403+ pax_open_userland();
15404 switch (op) {
15405 case FUTEX_OP_SET:
15406- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15407+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15408 break;
15409 case FUTEX_OP_ADD:
15410- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15411+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15412 uaddr, oparg);
15413 break;
15414 case FUTEX_OP_OR:
15415@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15416 default:
15417 ret = -ENOSYS;
15418 }
15419+ pax_close_userland();
15420
15421 pagefault_enable();
15422
15423@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15424 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15425 return -EFAULT;
15426
15427+ pax_open_userland();
15428 asm volatile("\t" ASM_STAC "\n"
15429- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15430+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15431 "2:\t" ASM_CLAC "\n"
15432 "\t.section .fixup, \"ax\"\n"
15433 "3:\tmov %3, %0\n"
15434 "\tjmp 2b\n"
15435 "\t.previous\n"
15436 _ASM_EXTABLE(1b, 3b)
15437- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15438+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15439 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15440 : "memory"
15441 );
15442+ pax_close_userland();
15443
15444 *uval = oldval;
15445 return ret;
15446diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15447index e4ac559..c1c0c87 100644
15448--- a/arch/x86/include/asm/hw_irq.h
15449+++ b/arch/x86/include/asm/hw_irq.h
15450@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15451 extern void enable_IO_APIC(void);
15452
15453 /* Statistics */
15454-extern atomic_t irq_err_count;
15455-extern atomic_t irq_mis_count;
15456+extern atomic_unchecked_t irq_err_count;
15457+extern atomic_unchecked_t irq_mis_count;
15458
15459 /* EISA */
15460 extern void eisa_set_level_irq(unsigned int irq);
15461diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15462index a203659..9889f1c 100644
15463--- a/arch/x86/include/asm/i8259.h
15464+++ b/arch/x86/include/asm/i8259.h
15465@@ -62,7 +62,7 @@ struct legacy_pic {
15466 void (*init)(int auto_eoi);
15467 int (*irq_pending)(unsigned int irq);
15468 void (*make_irq)(unsigned int irq);
15469-};
15470+} __do_const;
15471
15472 extern struct legacy_pic *legacy_pic;
15473 extern struct legacy_pic null_legacy_pic;
15474diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15475index 34f69cb..6d95446 100644
15476--- a/arch/x86/include/asm/io.h
15477+++ b/arch/x86/include/asm/io.h
15478@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15479 "m" (*(volatile type __force *)addr) barrier); }
15480
15481 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15482-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15483-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15484+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15485+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15486
15487 build_mmio_read(__readb, "b", unsigned char, "=q", )
15488-build_mmio_read(__readw, "w", unsigned short, "=r", )
15489-build_mmio_read(__readl, "l", unsigned int, "=r", )
15490+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15491+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15492
15493 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15494 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15495@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15496 return ioremap_nocache(offset, size);
15497 }
15498
15499-extern void iounmap(volatile void __iomem *addr);
15500+extern void iounmap(const volatile void __iomem *addr);
15501
15502 extern void set_iounmap_nonlazy(void);
15503
15504@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15505
15506 #include <linux/vmalloc.h>
15507
15508+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15509+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15510+{
15511+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15512+}
15513+
15514+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15515+{
15516+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15517+}
15518+
15519 /*
15520 * Convert a virtual cached pointer to an uncached pointer
15521 */
15522diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15523index bba3cf8..06bc8da 100644
15524--- a/arch/x86/include/asm/irqflags.h
15525+++ b/arch/x86/include/asm/irqflags.h
15526@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15527 sti; \
15528 sysexit
15529
15530+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15531+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15532+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15533+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15534+
15535 #else
15536 #define INTERRUPT_RETURN iret
15537 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15538diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15539index 5a6d287..f815789 100644
15540--- a/arch/x86/include/asm/kprobes.h
15541+++ b/arch/x86/include/asm/kprobes.h
15542@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15543 #define RELATIVEJUMP_SIZE 5
15544 #define RELATIVECALL_OPCODE 0xe8
15545 #define RELATIVE_ADDR_SIZE 4
15546-#define MAX_STACK_SIZE 64
15547-#define MIN_STACK_SIZE(ADDR) \
15548- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15549- THREAD_SIZE - (unsigned long)(ADDR))) \
15550- ? (MAX_STACK_SIZE) \
15551- : (((unsigned long)current_thread_info()) + \
15552- THREAD_SIZE - (unsigned long)(ADDR)))
15553+#define MAX_STACK_SIZE 64UL
15554+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15555
15556 #define flush_insn_slot(p) do { } while (0)
15557
15558diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15559index 2d89e39..baee879 100644
15560--- a/arch/x86/include/asm/local.h
15561+++ b/arch/x86/include/asm/local.h
15562@@ -10,33 +10,97 @@ typedef struct {
15563 atomic_long_t a;
15564 } local_t;
15565
15566+typedef struct {
15567+ atomic_long_unchecked_t a;
15568+} local_unchecked_t;
15569+
15570 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15571
15572 #define local_read(l) atomic_long_read(&(l)->a)
15573+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15574 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15575+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15576
15577 static inline void local_inc(local_t *l)
15578 {
15579- asm volatile(_ASM_INC "%0"
15580+ asm volatile(_ASM_INC "%0\n"
15581+
15582+#ifdef CONFIG_PAX_REFCOUNT
15583+ "jno 0f\n"
15584+ _ASM_DEC "%0\n"
15585+ "int $4\n0:\n"
15586+ _ASM_EXTABLE(0b, 0b)
15587+#endif
15588+
15589+ : "+m" (l->a.counter));
15590+}
15591+
15592+static inline void local_inc_unchecked(local_unchecked_t *l)
15593+{
15594+ asm volatile(_ASM_INC "%0\n"
15595 : "+m" (l->a.counter));
15596 }
15597
15598 static inline void local_dec(local_t *l)
15599 {
15600- asm volatile(_ASM_DEC "%0"
15601+ asm volatile(_ASM_DEC "%0\n"
15602+
15603+#ifdef CONFIG_PAX_REFCOUNT
15604+ "jno 0f\n"
15605+ _ASM_INC "%0\n"
15606+ "int $4\n0:\n"
15607+ _ASM_EXTABLE(0b, 0b)
15608+#endif
15609+
15610+ : "+m" (l->a.counter));
15611+}
15612+
15613+static inline void local_dec_unchecked(local_unchecked_t *l)
15614+{
15615+ asm volatile(_ASM_DEC "%0\n"
15616 : "+m" (l->a.counter));
15617 }
15618
15619 static inline void local_add(long i, local_t *l)
15620 {
15621- asm volatile(_ASM_ADD "%1,%0"
15622+ asm volatile(_ASM_ADD "%1,%0\n"
15623+
15624+#ifdef CONFIG_PAX_REFCOUNT
15625+ "jno 0f\n"
15626+ _ASM_SUB "%1,%0\n"
15627+ "int $4\n0:\n"
15628+ _ASM_EXTABLE(0b, 0b)
15629+#endif
15630+
15631+ : "+m" (l->a.counter)
15632+ : "ir" (i));
15633+}
15634+
15635+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15636+{
15637+ asm volatile(_ASM_ADD "%1,%0\n"
15638 : "+m" (l->a.counter)
15639 : "ir" (i));
15640 }
15641
15642 static inline void local_sub(long i, local_t *l)
15643 {
15644- asm volatile(_ASM_SUB "%1,%0"
15645+ asm volatile(_ASM_SUB "%1,%0\n"
15646+
15647+#ifdef CONFIG_PAX_REFCOUNT
15648+ "jno 0f\n"
15649+ _ASM_ADD "%1,%0\n"
15650+ "int $4\n0:\n"
15651+ _ASM_EXTABLE(0b, 0b)
15652+#endif
15653+
15654+ : "+m" (l->a.counter)
15655+ : "ir" (i));
15656+}
15657+
15658+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15659+{
15660+ asm volatile(_ASM_SUB "%1,%0\n"
15661 : "+m" (l->a.counter)
15662 : "ir" (i));
15663 }
15664@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15665 {
15666 unsigned char c;
15667
15668- asm volatile(_ASM_SUB "%2,%0; sete %1"
15669+ asm volatile(_ASM_SUB "%2,%0\n"
15670+
15671+#ifdef CONFIG_PAX_REFCOUNT
15672+ "jno 0f\n"
15673+ _ASM_ADD "%2,%0\n"
15674+ "int $4\n0:\n"
15675+ _ASM_EXTABLE(0b, 0b)
15676+#endif
15677+
15678+ "sete %1\n"
15679 : "+m" (l->a.counter), "=qm" (c)
15680 : "ir" (i) : "memory");
15681 return c;
15682@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15683 {
15684 unsigned char c;
15685
15686- asm volatile(_ASM_DEC "%0; sete %1"
15687+ asm volatile(_ASM_DEC "%0\n"
15688+
15689+#ifdef CONFIG_PAX_REFCOUNT
15690+ "jno 0f\n"
15691+ _ASM_INC "%0\n"
15692+ "int $4\n0:\n"
15693+ _ASM_EXTABLE(0b, 0b)
15694+#endif
15695+
15696+ "sete %1\n"
15697 : "+m" (l->a.counter), "=qm" (c)
15698 : : "memory");
15699 return c != 0;
15700@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15701 {
15702 unsigned char c;
15703
15704- asm volatile(_ASM_INC "%0; sete %1"
15705+ asm volatile(_ASM_INC "%0\n"
15706+
15707+#ifdef CONFIG_PAX_REFCOUNT
15708+ "jno 0f\n"
15709+ _ASM_DEC "%0\n"
15710+ "int $4\n0:\n"
15711+ _ASM_EXTABLE(0b, 0b)
15712+#endif
15713+
15714+ "sete %1\n"
15715 : "+m" (l->a.counter), "=qm" (c)
15716 : : "memory");
15717 return c != 0;
15718@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15719 {
15720 unsigned char c;
15721
15722- asm volatile(_ASM_ADD "%2,%0; sets %1"
15723+ asm volatile(_ASM_ADD "%2,%0\n"
15724+
15725+#ifdef CONFIG_PAX_REFCOUNT
15726+ "jno 0f\n"
15727+ _ASM_SUB "%2,%0\n"
15728+ "int $4\n0:\n"
15729+ _ASM_EXTABLE(0b, 0b)
15730+#endif
15731+
15732+ "sets %1\n"
15733 : "+m" (l->a.counter), "=qm" (c)
15734 : "ir" (i) : "memory");
15735 return c;
15736@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15737 static inline long local_add_return(long i, local_t *l)
15738 {
15739 long __i = i;
15740+ asm volatile(_ASM_XADD "%0, %1\n"
15741+
15742+#ifdef CONFIG_PAX_REFCOUNT
15743+ "jno 0f\n"
15744+ _ASM_MOV "%0,%1\n"
15745+ "int $4\n0:\n"
15746+ _ASM_EXTABLE(0b, 0b)
15747+#endif
15748+
15749+ : "+r" (i), "+m" (l->a.counter)
15750+ : : "memory");
15751+ return i + __i;
15752+}
15753+
15754+/**
15755+ * local_add_return_unchecked - add and return
15756+ * @i: integer value to add
15757+ * @l: pointer to type local_unchecked_t
15758+ *
15759+ * Atomically adds @i to @l and returns @i + @l
15760+ */
15761+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15762+{
15763+ long __i = i;
15764 asm volatile(_ASM_XADD "%0, %1;"
15765 : "+r" (i), "+m" (l->a.counter)
15766 : : "memory");
15767@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15768
15769 #define local_cmpxchg(l, o, n) \
15770 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15771+#define local_cmpxchg_unchecked(l, o, n) \
15772+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15773 /* Always has a lock prefix */
15774 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15775
15776diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15777new file mode 100644
15778index 0000000..2bfd3ba
15779--- /dev/null
15780+++ b/arch/x86/include/asm/mman.h
15781@@ -0,0 +1,15 @@
15782+#ifndef _X86_MMAN_H
15783+#define _X86_MMAN_H
15784+
15785+#include <uapi/asm/mman.h>
15786+
15787+#ifdef __KERNEL__
15788+#ifndef __ASSEMBLY__
15789+#ifdef CONFIG_X86_32
15790+#define arch_mmap_check i386_mmap_check
15791+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15792+#endif
15793+#endif
15794+#endif
15795+
15796+#endif /* X86_MMAN_H */
15797diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15798index 5f55e69..e20bfb1 100644
15799--- a/arch/x86/include/asm/mmu.h
15800+++ b/arch/x86/include/asm/mmu.h
15801@@ -9,7 +9,7 @@
15802 * we put the segment information here.
15803 */
15804 typedef struct {
15805- void *ldt;
15806+ struct desc_struct *ldt;
15807 int size;
15808
15809 #ifdef CONFIG_X86_64
15810@@ -18,7 +18,19 @@ typedef struct {
15811 #endif
15812
15813 struct mutex lock;
15814- void *vdso;
15815+ unsigned long vdso;
15816+
15817+#ifdef CONFIG_X86_32
15818+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15819+ unsigned long user_cs_base;
15820+ unsigned long user_cs_limit;
15821+
15822+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15823+ cpumask_t cpu_user_cs_mask;
15824+#endif
15825+
15826+#endif
15827+#endif
15828 } mm_context_t;
15829
15830 #ifdef CONFIG_SMP
15831diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15832index be12c53..2124e35 100644
15833--- a/arch/x86/include/asm/mmu_context.h
15834+++ b/arch/x86/include/asm/mmu_context.h
15835@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15836
15837 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15838 {
15839+
15840+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15841+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15842+ unsigned int i;
15843+ pgd_t *pgd;
15844+
15845+ pax_open_kernel();
15846+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15847+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15848+ set_pgd_batched(pgd+i, native_make_pgd(0));
15849+ pax_close_kernel();
15850+ }
15851+#endif
15852+
15853 #ifdef CONFIG_SMP
15854 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15855 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15856@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15857 struct task_struct *tsk)
15858 {
15859 unsigned cpu = smp_processor_id();
15860+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15861+ int tlbstate = TLBSTATE_OK;
15862+#endif
15863
15864 if (likely(prev != next)) {
15865 #ifdef CONFIG_SMP
15866+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15867+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15868+#endif
15869 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15870 this_cpu_write(cpu_tlbstate.active_mm, next);
15871 #endif
15872 cpumask_set_cpu(cpu, mm_cpumask(next));
15873
15874 /* Re-load page tables */
15875+#ifdef CONFIG_PAX_PER_CPU_PGD
15876+ pax_open_kernel();
15877+
15878+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15879+ if (static_cpu_has(X86_FEATURE_PCID))
15880+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15881+ else
15882+#endif
15883+
15884+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15885+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15886+ pax_close_kernel();
15887+ 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));
15888+
15889+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15890+ if (static_cpu_has(X86_FEATURE_PCID)) {
15891+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15892+ u64 descriptor[2];
15893+ descriptor[0] = PCID_USER;
15894+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15895+ } else {
15896+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15897+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15898+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15899+ else
15900+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15901+ }
15902+ } else
15903+#endif
15904+
15905+ load_cr3(get_cpu_pgd(cpu, kernel));
15906+#else
15907 load_cr3(next->pgd);
15908+#endif
15909
15910 /* Stop flush ipis for the previous mm */
15911 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15912@@ -51,9 +104,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15913 /* Load the LDT, if the LDT is different: */
15914 if (unlikely(prev->context.ldt != next->context.ldt))
15915 load_LDT_nolock(&next->context);
15916+
15917+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15918+ if (!(__supported_pte_mask & _PAGE_NX)) {
15919+ smp_mb__before_clear_bit();
15920+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15921+ smp_mb__after_clear_bit();
15922+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15923+ }
15924+#endif
15925+
15926+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15927+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15928+ prev->context.user_cs_limit != next->context.user_cs_limit))
15929+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15930+#ifdef CONFIG_SMP
15931+ else if (unlikely(tlbstate != TLBSTATE_OK))
15932+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15933+#endif
15934+#endif
15935+
15936 }
15937+ else {
15938+
15939+#ifdef CONFIG_PAX_PER_CPU_PGD
15940+ pax_open_kernel();
15941+
15942+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15943+ if (static_cpu_has(X86_FEATURE_PCID))
15944+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15945+ else
15946+#endif
15947+
15948+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15949+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15950+ pax_close_kernel();
15951+ 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));
15952+
15953+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15954+ if (static_cpu_has(X86_FEATURE_PCID)) {
15955+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15956+ u64 descriptor[2];
15957+ descriptor[0] = PCID_USER;
15958+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15959+ } else {
15960+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15961+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15962+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15963+ else
15964+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15965+ }
15966+ } else
15967+#endif
15968+
15969+ load_cr3(get_cpu_pgd(cpu, kernel));
15970+#endif
15971+
15972 #ifdef CONFIG_SMP
15973- else {
15974 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15975 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15976
15977@@ -70,11 +177,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15978 * tlb flush IPI delivery. We must reload CR3
15979 * to make sure to use no freed page tables.
15980 */
15981+
15982+#ifndef CONFIG_PAX_PER_CPU_PGD
15983 load_cr3(next->pgd);
15984+#endif
15985+
15986 load_LDT_nolock(&next->context);
15987+
15988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15989+ if (!(__supported_pte_mask & _PAGE_NX))
15990+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15991+#endif
15992+
15993+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15994+#ifdef CONFIG_PAX_PAGEEXEC
15995+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15996+#endif
15997+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15998+#endif
15999+
16000 }
16001+#endif
16002 }
16003-#endif
16004 }
16005
16006 #define activate_mm(prev, next) \
16007diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16008index e3b7819..b257c64 100644
16009--- a/arch/x86/include/asm/module.h
16010+++ b/arch/x86/include/asm/module.h
16011@@ -5,6 +5,7 @@
16012
16013 #ifdef CONFIG_X86_64
16014 /* X86_64 does not define MODULE_PROC_FAMILY */
16015+#define MODULE_PROC_FAMILY ""
16016 #elif defined CONFIG_M486
16017 #define MODULE_PROC_FAMILY "486 "
16018 #elif defined CONFIG_M586
16019@@ -57,8 +58,20 @@
16020 #error unknown processor family
16021 #endif
16022
16023-#ifdef CONFIG_X86_32
16024-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16025+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16026+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16027+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16028+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16029+#else
16030+#define MODULE_PAX_KERNEXEC ""
16031 #endif
16032
16033+#ifdef CONFIG_PAX_MEMORY_UDEREF
16034+#define MODULE_PAX_UDEREF "UDEREF "
16035+#else
16036+#define MODULE_PAX_UDEREF ""
16037+#endif
16038+
16039+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16040+
16041 #endif /* _ASM_X86_MODULE_H */
16042diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16043index 86f9301..b365cda 100644
16044--- a/arch/x86/include/asm/nmi.h
16045+++ b/arch/x86/include/asm/nmi.h
16046@@ -40,11 +40,11 @@ struct nmiaction {
16047 nmi_handler_t handler;
16048 unsigned long flags;
16049 const char *name;
16050-};
16051+} __do_const;
16052
16053 #define register_nmi_handler(t, fn, fg, n, init...) \
16054 ({ \
16055- static struct nmiaction init fn##_na = { \
16056+ static const struct nmiaction init fn##_na = { \
16057 .handler = (fn), \
16058 .name = (n), \
16059 .flags = (fg), \
16060@@ -52,7 +52,7 @@ struct nmiaction {
16061 __register_nmi_handler((t), &fn##_na); \
16062 })
16063
16064-int __register_nmi_handler(unsigned int, struct nmiaction *);
16065+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16066
16067 void unregister_nmi_handler(unsigned int, const char *);
16068
16069diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16070index c878924..21f4889 100644
16071--- a/arch/x86/include/asm/page.h
16072+++ b/arch/x86/include/asm/page.h
16073@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16074 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16075
16076 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16077+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16078
16079 #define __boot_va(x) __va(x)
16080 #define __boot_pa(x) __pa(x)
16081diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16082index 0f1ddee..e2fc3d1 100644
16083--- a/arch/x86/include/asm/page_64.h
16084+++ b/arch/x86/include/asm/page_64.h
16085@@ -7,9 +7,9 @@
16086
16087 /* duplicated to the one in bootmem.h */
16088 extern unsigned long max_pfn;
16089-extern unsigned long phys_base;
16090+extern const unsigned long phys_base;
16091
16092-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16093+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16094 {
16095 unsigned long y = x - __START_KERNEL_map;
16096
16097diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16098index cfdc9ee..3f7b5d6 100644
16099--- a/arch/x86/include/asm/paravirt.h
16100+++ b/arch/x86/include/asm/paravirt.h
16101@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16102 return (pmd_t) { ret };
16103 }
16104
16105-static inline pmdval_t pmd_val(pmd_t pmd)
16106+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16107 {
16108 pmdval_t ret;
16109
16110@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16111 val);
16112 }
16113
16114+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16115+{
16116+ pgdval_t val = native_pgd_val(pgd);
16117+
16118+ if (sizeof(pgdval_t) > sizeof(long))
16119+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16120+ val, (u64)val >> 32);
16121+ else
16122+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16123+ val);
16124+}
16125+
16126 static inline void pgd_clear(pgd_t *pgdp)
16127 {
16128 set_pgd(pgdp, __pgd(0));
16129@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16130 pv_mmu_ops.set_fixmap(idx, phys, flags);
16131 }
16132
16133+#ifdef CONFIG_PAX_KERNEXEC
16134+static inline unsigned long pax_open_kernel(void)
16135+{
16136+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16137+}
16138+
16139+static inline unsigned long pax_close_kernel(void)
16140+{
16141+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16142+}
16143+#else
16144+static inline unsigned long pax_open_kernel(void) { return 0; }
16145+static inline unsigned long pax_close_kernel(void) { return 0; }
16146+#endif
16147+
16148 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16149
16150 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16151@@ -926,7 +953,7 @@ extern void default_banner(void);
16152
16153 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16154 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16155-#define PARA_INDIRECT(addr) *%cs:addr
16156+#define PARA_INDIRECT(addr) *%ss:addr
16157 #endif
16158
16159 #define INTERRUPT_RETURN \
16160@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16161 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16162 CLBR_NONE, \
16163 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16164+
16165+#define GET_CR0_INTO_RDI \
16166+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16167+ mov %rax,%rdi
16168+
16169+#define SET_RDI_INTO_CR0 \
16170+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16171+
16172+#define GET_CR3_INTO_RDI \
16173+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16174+ mov %rax,%rdi
16175+
16176+#define SET_RDI_INTO_CR3 \
16177+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16178+
16179 #endif /* CONFIG_X86_32 */
16180
16181 #endif /* __ASSEMBLY__ */
16182diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16183index 0db1fca..52310cc 100644
16184--- a/arch/x86/include/asm/paravirt_types.h
16185+++ b/arch/x86/include/asm/paravirt_types.h
16186@@ -84,7 +84,7 @@ struct pv_init_ops {
16187 */
16188 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16189 unsigned long addr, unsigned len);
16190-};
16191+} __no_const;
16192
16193
16194 struct pv_lazy_ops {
16195@@ -98,7 +98,7 @@ struct pv_time_ops {
16196 unsigned long long (*sched_clock)(void);
16197 unsigned long long (*steal_clock)(int cpu);
16198 unsigned long (*get_tsc_khz)(void);
16199-};
16200+} __no_const;
16201
16202 struct pv_cpu_ops {
16203 /* hooks for various privileged instructions */
16204@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16205
16206 void (*start_context_switch)(struct task_struct *prev);
16207 void (*end_context_switch)(struct task_struct *next);
16208-};
16209+} __no_const;
16210
16211 struct pv_irq_ops {
16212 /*
16213@@ -223,7 +223,7 @@ struct pv_apic_ops {
16214 unsigned long start_eip,
16215 unsigned long start_esp);
16216 #endif
16217-};
16218+} __no_const;
16219
16220 struct pv_mmu_ops {
16221 unsigned long (*read_cr2)(void);
16222@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16223 struct paravirt_callee_save make_pud;
16224
16225 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16226+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16227 #endif /* PAGETABLE_LEVELS == 4 */
16228 #endif /* PAGETABLE_LEVELS >= 3 */
16229
16230@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16231 an mfn. We can tell which is which from the index. */
16232 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16233 phys_addr_t phys, pgprot_t flags);
16234+
16235+#ifdef CONFIG_PAX_KERNEXEC
16236+ unsigned long (*pax_open_kernel)(void);
16237+ unsigned long (*pax_close_kernel)(void);
16238+#endif
16239+
16240 };
16241
16242 struct arch_spinlock;
16243@@ -334,7 +341,7 @@ struct pv_lock_ops {
16244 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16245 int (*spin_trylock)(struct arch_spinlock *lock);
16246 void (*spin_unlock)(struct arch_spinlock *lock);
16247-};
16248+} __no_const;
16249
16250 /* This contains all the paravirt structures: we get a convenient
16251 * number for each function using the offset which we use to indicate
16252diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16253index b4389a4..7024269 100644
16254--- a/arch/x86/include/asm/pgalloc.h
16255+++ b/arch/x86/include/asm/pgalloc.h
16256@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16257 pmd_t *pmd, pte_t *pte)
16258 {
16259 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16260+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16261+}
16262+
16263+static inline void pmd_populate_user(struct mm_struct *mm,
16264+ pmd_t *pmd, pte_t *pte)
16265+{
16266+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16267 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16268 }
16269
16270@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16271
16272 #ifdef CONFIG_X86_PAE
16273 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16274+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16275+{
16276+ pud_populate(mm, pudp, pmd);
16277+}
16278 #else /* !CONFIG_X86_PAE */
16279 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16280 {
16281 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16282 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16283 }
16284+
16285+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16286+{
16287+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16288+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16289+}
16290 #endif /* CONFIG_X86_PAE */
16291
16292 #if PAGETABLE_LEVELS > 3
16293@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16294 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16295 }
16296
16297+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16298+{
16299+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16300+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16301+}
16302+
16303 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16304 {
16305 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16306diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16307index 3bf2dd0..23d2a9f 100644
16308--- a/arch/x86/include/asm/pgtable-2level.h
16309+++ b/arch/x86/include/asm/pgtable-2level.h
16310@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16311
16312 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16313 {
16314+ pax_open_kernel();
16315 *pmdp = pmd;
16316+ pax_close_kernel();
16317 }
16318
16319 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16320diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16321index 81bb91b..9392125 100644
16322--- a/arch/x86/include/asm/pgtable-3level.h
16323+++ b/arch/x86/include/asm/pgtable-3level.h
16324@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16325
16326 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16327 {
16328+ pax_open_kernel();
16329 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16330+ pax_close_kernel();
16331 }
16332
16333 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16334 {
16335+ pax_open_kernel();
16336 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16337+ pax_close_kernel();
16338 }
16339
16340 /*
16341diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16342index 1c00631..845f898 100644
16343--- a/arch/x86/include/asm/pgtable.h
16344+++ b/arch/x86/include/asm/pgtable.h
16345@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16346
16347 #ifndef __PAGETABLE_PUD_FOLDED
16348 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16349+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16350 #define pgd_clear(pgd) native_pgd_clear(pgd)
16351 #endif
16352
16353@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16354
16355 #define arch_end_context_switch(prev) do {} while(0)
16356
16357+#define pax_open_kernel() native_pax_open_kernel()
16358+#define pax_close_kernel() native_pax_close_kernel()
16359 #endif /* CONFIG_PARAVIRT */
16360
16361+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16362+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16363+
16364+#ifdef CONFIG_PAX_KERNEXEC
16365+static inline unsigned long native_pax_open_kernel(void)
16366+{
16367+ unsigned long cr0;
16368+
16369+ preempt_disable();
16370+ barrier();
16371+ cr0 = read_cr0() ^ X86_CR0_WP;
16372+ BUG_ON(cr0 & X86_CR0_WP);
16373+ write_cr0(cr0);
16374+ return cr0 ^ X86_CR0_WP;
16375+}
16376+
16377+static inline unsigned long native_pax_close_kernel(void)
16378+{
16379+ unsigned long cr0;
16380+
16381+ cr0 = read_cr0() ^ X86_CR0_WP;
16382+ BUG_ON(!(cr0 & X86_CR0_WP));
16383+ write_cr0(cr0);
16384+ barrier();
16385+ preempt_enable_no_resched();
16386+ return cr0 ^ X86_CR0_WP;
16387+}
16388+#else
16389+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16390+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16391+#endif
16392+
16393 /*
16394 * The following only work if pte_present() is true.
16395 * Undefined behaviour if not..
16396 */
16397+static inline int pte_user(pte_t pte)
16398+{
16399+ return pte_val(pte) & _PAGE_USER;
16400+}
16401+
16402 static inline int pte_dirty(pte_t pte)
16403 {
16404 return pte_flags(pte) & _PAGE_DIRTY;
16405@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16406 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16407 }
16408
16409+static inline unsigned long pgd_pfn(pgd_t pgd)
16410+{
16411+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16412+}
16413+
16414 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16415
16416 static inline int pmd_large(pmd_t pte)
16417@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16418 return pte_clear_flags(pte, _PAGE_RW);
16419 }
16420
16421+static inline pte_t pte_mkread(pte_t pte)
16422+{
16423+ return __pte(pte_val(pte) | _PAGE_USER);
16424+}
16425+
16426 static inline pte_t pte_mkexec(pte_t pte)
16427 {
16428- return pte_clear_flags(pte, _PAGE_NX);
16429+#ifdef CONFIG_X86_PAE
16430+ if (__supported_pte_mask & _PAGE_NX)
16431+ return pte_clear_flags(pte, _PAGE_NX);
16432+ else
16433+#endif
16434+ return pte_set_flags(pte, _PAGE_USER);
16435+}
16436+
16437+static inline pte_t pte_exprotect(pte_t pte)
16438+{
16439+#ifdef CONFIG_X86_PAE
16440+ if (__supported_pte_mask & _PAGE_NX)
16441+ return pte_set_flags(pte, _PAGE_NX);
16442+ else
16443+#endif
16444+ return pte_clear_flags(pte, _PAGE_USER);
16445 }
16446
16447 static inline pte_t pte_mkdirty(pte_t pte)
16448@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16449 #endif
16450
16451 #ifndef __ASSEMBLY__
16452+
16453+#ifdef CONFIG_PAX_PER_CPU_PGD
16454+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16455+enum cpu_pgd_type {kernel = 0, user = 1};
16456+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16457+{
16458+ return cpu_pgd[cpu][type];
16459+}
16460+#endif
16461+
16462 #include <linux/mm_types.h>
16463 #include <linux/log2.h>
16464
16465@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16466 * Currently stuck as a macro due to indirect forward reference to
16467 * linux/mmzone.h's __section_mem_map_addr() definition:
16468 */
16469-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16470+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16471
16472 /* Find an entry in the second-level page table.. */
16473 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16474@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16475 * Currently stuck as a macro due to indirect forward reference to
16476 * linux/mmzone.h's __section_mem_map_addr() definition:
16477 */
16478-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16479+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16480
16481 /* to find an entry in a page-table-directory. */
16482 static inline unsigned long pud_index(unsigned long address)
16483@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16484
16485 static inline int pgd_bad(pgd_t pgd)
16486 {
16487- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16488+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16489 }
16490
16491 static inline int pgd_none(pgd_t pgd)
16492@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16493 * pgd_offset() returns a (pgd_t *)
16494 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16495 */
16496-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16497+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16498+
16499+#ifdef CONFIG_PAX_PER_CPU_PGD
16500+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16501+#endif
16502+
16503 /*
16504 * a shortcut which implies the use of the kernel's pgd, instead
16505 * of a process's
16506@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16507 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16508 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16509
16510+#ifdef CONFIG_X86_32
16511+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16512+#else
16513+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16514+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16515+
16516+#ifdef CONFIG_PAX_MEMORY_UDEREF
16517+#ifdef __ASSEMBLY__
16518+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16519+#else
16520+extern unsigned long pax_user_shadow_base;
16521+extern pgdval_t clone_pgd_mask;
16522+#endif
16523+#endif
16524+
16525+#endif
16526+
16527 #ifndef __ASSEMBLY__
16528
16529 extern int direct_gbpages;
16530@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16531 * dst and src can be on the same page, but the range must not overlap,
16532 * and must not cross a page boundary.
16533 */
16534-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16535+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16536 {
16537- memcpy(dst, src, count * sizeof(pgd_t));
16538+ pax_open_kernel();
16539+ while (count--)
16540+ *dst++ = *src++;
16541+ pax_close_kernel();
16542 }
16543
16544+#ifdef CONFIG_PAX_PER_CPU_PGD
16545+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16546+#endif
16547+
16548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16549+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16550+#else
16551+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16552+#endif
16553+
16554 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16555 static inline int page_level_shift(enum pg_level level)
16556 {
16557diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16558index 9ee3221..b979c6b 100644
16559--- a/arch/x86/include/asm/pgtable_32.h
16560+++ b/arch/x86/include/asm/pgtable_32.h
16561@@ -25,9 +25,6 @@
16562 struct mm_struct;
16563 struct vm_area_struct;
16564
16565-extern pgd_t swapper_pg_dir[1024];
16566-extern pgd_t initial_page_table[1024];
16567-
16568 static inline void pgtable_cache_init(void) { }
16569 static inline void check_pgt_cache(void) { }
16570 void paging_init(void);
16571@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16572 # include <asm/pgtable-2level.h>
16573 #endif
16574
16575+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16576+extern pgd_t initial_page_table[PTRS_PER_PGD];
16577+#ifdef CONFIG_X86_PAE
16578+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16579+#endif
16580+
16581 #if defined(CONFIG_HIGHPTE)
16582 #define pte_offset_map(dir, address) \
16583 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16584@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16585 /* Clear a kernel PTE and flush it from the TLB */
16586 #define kpte_clear_flush(ptep, vaddr) \
16587 do { \
16588+ pax_open_kernel(); \
16589 pte_clear(&init_mm, (vaddr), (ptep)); \
16590+ pax_close_kernel(); \
16591 __flush_tlb_one((vaddr)); \
16592 } while (0)
16593
16594 #endif /* !__ASSEMBLY__ */
16595
16596+#define HAVE_ARCH_UNMAPPED_AREA
16597+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16598+
16599 /*
16600 * kern_addr_valid() is (1) for FLATMEM and (0) for
16601 * SPARSEMEM and DISCONTIGMEM
16602diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16603index ed5903b..c7fe163 100644
16604--- a/arch/x86/include/asm/pgtable_32_types.h
16605+++ b/arch/x86/include/asm/pgtable_32_types.h
16606@@ -8,7 +8,7 @@
16607 */
16608 #ifdef CONFIG_X86_PAE
16609 # include <asm/pgtable-3level_types.h>
16610-# define PMD_SIZE (1UL << PMD_SHIFT)
16611+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16612 # define PMD_MASK (~(PMD_SIZE - 1))
16613 #else
16614 # include <asm/pgtable-2level_types.h>
16615@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16616 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16617 #endif
16618
16619+#ifdef CONFIG_PAX_KERNEXEC
16620+#ifndef __ASSEMBLY__
16621+extern unsigned char MODULES_EXEC_VADDR[];
16622+extern unsigned char MODULES_EXEC_END[];
16623+#endif
16624+#include <asm/boot.h>
16625+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16626+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16627+#else
16628+#define ktla_ktva(addr) (addr)
16629+#define ktva_ktla(addr) (addr)
16630+#endif
16631+
16632 #define MODULES_VADDR VMALLOC_START
16633 #define MODULES_END VMALLOC_END
16634 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16635diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16636index e22c1db..23a625a 100644
16637--- a/arch/x86/include/asm/pgtable_64.h
16638+++ b/arch/x86/include/asm/pgtable_64.h
16639@@ -16,10 +16,14 @@
16640
16641 extern pud_t level3_kernel_pgt[512];
16642 extern pud_t level3_ident_pgt[512];
16643+extern pud_t level3_vmalloc_start_pgt[512];
16644+extern pud_t level3_vmalloc_end_pgt[512];
16645+extern pud_t level3_vmemmap_pgt[512];
16646+extern pud_t level2_vmemmap_pgt[512];
16647 extern pmd_t level2_kernel_pgt[512];
16648 extern pmd_t level2_fixmap_pgt[512];
16649-extern pmd_t level2_ident_pgt[512];
16650-extern pgd_t init_level4_pgt[];
16651+extern pmd_t level2_ident_pgt[512*2];
16652+extern pgd_t init_level4_pgt[512];
16653
16654 #define swapper_pg_dir init_level4_pgt
16655
16656@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16657
16658 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16659 {
16660+ pax_open_kernel();
16661 *pmdp = pmd;
16662+ pax_close_kernel();
16663 }
16664
16665 static inline void native_pmd_clear(pmd_t *pmd)
16666@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16667
16668 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16669 {
16670+ pax_open_kernel();
16671 *pudp = pud;
16672+ pax_close_kernel();
16673 }
16674
16675 static inline void native_pud_clear(pud_t *pud)
16676@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16677
16678 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16679 {
16680+ pax_open_kernel();
16681+ *pgdp = pgd;
16682+ pax_close_kernel();
16683+}
16684+
16685+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16686+{
16687 *pgdp = pgd;
16688 }
16689
16690diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16691index 2d88344..4679fc3 100644
16692--- a/arch/x86/include/asm/pgtable_64_types.h
16693+++ b/arch/x86/include/asm/pgtable_64_types.h
16694@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16695 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16696 #define MODULES_END _AC(0xffffffffff000000, UL)
16697 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16698+#define MODULES_EXEC_VADDR MODULES_VADDR
16699+#define MODULES_EXEC_END MODULES_END
16700+
16701+#define ktla_ktva(addr) (addr)
16702+#define ktva_ktla(addr) (addr)
16703
16704 #define EARLY_DYNAMIC_PAGE_TABLES 64
16705
16706diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16707index f4843e0..a2526f8 100644
16708--- a/arch/x86/include/asm/pgtable_types.h
16709+++ b/arch/x86/include/asm/pgtable_types.h
16710@@ -16,13 +16,12 @@
16711 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16712 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16713 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16714-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16715+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16716 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16717 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16718 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16719-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16720-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16721-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16722+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16723+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16724 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16725
16726 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16727@@ -40,7 +39,6 @@
16728 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16729 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16730 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16731-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16732 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16733 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16734 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16735@@ -84,8 +82,10 @@
16736
16737 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16738 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16739-#else
16740+#elif defined(CONFIG_KMEMCHECK)
16741 #define _PAGE_NX (_AT(pteval_t, 0))
16742+#else
16743+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16744 #endif
16745
16746 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16747@@ -143,6 +143,9 @@
16748 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16749 _PAGE_ACCESSED)
16750
16751+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16752+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16753+
16754 #define __PAGE_KERNEL_EXEC \
16755 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16756 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16757@@ -153,7 +156,7 @@
16758 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16759 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16760 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16761-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16762+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16763 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16764 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16765 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16766@@ -215,8 +218,8 @@
16767 * bits are combined, this will alow user to access the high address mapped
16768 * VDSO in the presence of CONFIG_COMPAT_VDSO
16769 */
16770-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16771-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16772+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16773+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16774 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16775 #endif
16776
16777@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16778 {
16779 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16780 }
16781+#endif
16782
16783+#if PAGETABLE_LEVELS == 3
16784+#include <asm-generic/pgtable-nopud.h>
16785+#endif
16786+
16787+#if PAGETABLE_LEVELS == 2
16788+#include <asm-generic/pgtable-nopmd.h>
16789+#endif
16790+
16791+#ifndef __ASSEMBLY__
16792 #if PAGETABLE_LEVELS > 3
16793 typedef struct { pudval_t pud; } pud_t;
16794
16795@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16796 return pud.pud;
16797 }
16798 #else
16799-#include <asm-generic/pgtable-nopud.h>
16800-
16801 static inline pudval_t native_pud_val(pud_t pud)
16802 {
16803 return native_pgd_val(pud.pgd);
16804@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16805 return pmd.pmd;
16806 }
16807 #else
16808-#include <asm-generic/pgtable-nopmd.h>
16809-
16810 static inline pmdval_t native_pmd_val(pmd_t pmd)
16811 {
16812 return native_pgd_val(pmd.pud.pgd);
16813@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16814
16815 extern pteval_t __supported_pte_mask;
16816 extern void set_nx(void);
16817-extern int nx_enabled;
16818
16819 #define pgprot_writecombine pgprot_writecombine
16820 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16821diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16822index 24cf5ae..4d9fa2d 100644
16823--- a/arch/x86/include/asm/processor.h
16824+++ b/arch/x86/include/asm/processor.h
16825@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16826 : "memory");
16827 }
16828
16829+/* invpcid (%rdx),%rax */
16830+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16831+
16832+#define INVPCID_SINGLE_ADDRESS 0UL
16833+#define INVPCID_SINGLE_CONTEXT 1UL
16834+#define INVPCID_ALL_GLOBAL 2UL
16835+#define INVPCID_ALL_MONGLOBAL 3UL
16836+
16837+#define PCID_KERNEL 0UL
16838+#define PCID_USER 1UL
16839+#define PCID_NOFLUSH (1UL << 63)
16840+
16841 static inline void load_cr3(pgd_t *pgdir)
16842 {
16843- write_cr3(__pa(pgdir));
16844+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16845 }
16846
16847 #ifdef CONFIG_X86_32
16848@@ -283,7 +295,7 @@ struct tss_struct {
16849
16850 } ____cacheline_aligned;
16851
16852-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16853+extern struct tss_struct init_tss[NR_CPUS];
16854
16855 /*
16856 * Save the original ist values for checking stack pointers during debugging
16857@@ -453,6 +465,7 @@ struct thread_struct {
16858 unsigned short ds;
16859 unsigned short fsindex;
16860 unsigned short gsindex;
16861+ unsigned short ss;
16862 #endif
16863 #ifdef CONFIG_X86_32
16864 unsigned long ip;
16865@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16866 extern unsigned long mmu_cr4_features;
16867 extern u32 *trampoline_cr4_features;
16868
16869-static inline void set_in_cr4(unsigned long mask)
16870-{
16871- unsigned long cr4;
16872-
16873- mmu_cr4_features |= mask;
16874- if (trampoline_cr4_features)
16875- *trampoline_cr4_features = mmu_cr4_features;
16876- cr4 = read_cr4();
16877- cr4 |= mask;
16878- write_cr4(cr4);
16879-}
16880-
16881-static inline void clear_in_cr4(unsigned long mask)
16882-{
16883- unsigned long cr4;
16884-
16885- mmu_cr4_features &= ~mask;
16886- if (trampoline_cr4_features)
16887- *trampoline_cr4_features = mmu_cr4_features;
16888- cr4 = read_cr4();
16889- cr4 &= ~mask;
16890- write_cr4(cr4);
16891-}
16892+extern void set_in_cr4(unsigned long mask);
16893+extern void clear_in_cr4(unsigned long mask);
16894
16895 typedef struct {
16896 unsigned long seg;
16897@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16898 */
16899 #define TASK_SIZE PAGE_OFFSET
16900 #define TASK_SIZE_MAX TASK_SIZE
16901+
16902+#ifdef CONFIG_PAX_SEGMEXEC
16903+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16904+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16905+#else
16906 #define STACK_TOP TASK_SIZE
16907-#define STACK_TOP_MAX STACK_TOP
16908+#endif
16909+
16910+#define STACK_TOP_MAX TASK_SIZE
16911
16912 #define INIT_THREAD { \
16913- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16914+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16915 .vm86_info = NULL, \
16916 .sysenter_cs = __KERNEL_CS, \
16917 .io_bitmap_ptr = NULL, \
16918@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16919 */
16920 #define INIT_TSS { \
16921 .x86_tss = { \
16922- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16923+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16924 .ss0 = __KERNEL_DS, \
16925 .ss1 = __KERNEL_CS, \
16926 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16927@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16928 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16929
16930 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16931-#define KSTK_TOP(info) \
16932-({ \
16933- unsigned long *__ptr = (unsigned long *)(info); \
16934- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16935-})
16936+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16937
16938 /*
16939 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16940@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16941 #define task_pt_regs(task) \
16942 ({ \
16943 struct pt_regs *__regs__; \
16944- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16945+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16946 __regs__ - 1; \
16947 })
16948
16949@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16950 /*
16951 * User space process size. 47bits minus one guard page.
16952 */
16953-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16954+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16955
16956 /* This decides where the kernel will search for a free chunk of vm
16957 * space during mmap's.
16958 */
16959 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16960- 0xc0000000 : 0xFFFFe000)
16961+ 0xc0000000 : 0xFFFFf000)
16962
16963 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16964 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16965@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16966 #define STACK_TOP_MAX TASK_SIZE_MAX
16967
16968 #define INIT_THREAD { \
16969- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16970+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16971 }
16972
16973 #define INIT_TSS { \
16974- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16975+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16976 }
16977
16978 /*
16979@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16980 */
16981 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16982
16983+#ifdef CONFIG_PAX_SEGMEXEC
16984+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16985+#endif
16986+
16987 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16988
16989 /* Get/set a process' ability to use the timestamp counter instruction */
16990@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16991 extern u16 amd_get_nb_id(int cpu);
16992
16993 struct aperfmperf {
16994- u64 aperf, mperf;
16995+ u64 aperf __intentional_overflow(0);
16996+ u64 mperf __intentional_overflow(0);
16997 };
16998
16999 static inline void get_aperfmperf(struct aperfmperf *am)
17000@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
17001 return ratio;
17002 }
17003
17004-extern unsigned long arch_align_stack(unsigned long sp);
17005+#define arch_align_stack(x) ((x) & ~0xfUL)
17006 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17007
17008 void default_idle(void);
17009@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
17010 #define xen_set_default_idle 0
17011 #endif
17012
17013-void stop_this_cpu(void *dummy);
17014+void stop_this_cpu(void *dummy) __noreturn;
17015 void df_debug(struct pt_regs *regs, long error_code);
17016 #endif /* _ASM_X86_PROCESSOR_H */
17017diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17018index 942a086..6c26446 100644
17019--- a/arch/x86/include/asm/ptrace.h
17020+++ b/arch/x86/include/asm/ptrace.h
17021@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17022 }
17023
17024 /*
17025- * user_mode_vm(regs) determines whether a register set came from user mode.
17026+ * user_mode(regs) determines whether a register set came from user mode.
17027 * This is true if V8086 mode was enabled OR if the register set was from
17028 * protected mode with RPL-3 CS value. This tricky test checks that with
17029 * one comparison. Many places in the kernel can bypass this full check
17030- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17031+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17032+ * be used.
17033 */
17034-static inline int user_mode(struct pt_regs *regs)
17035+static inline int user_mode_novm(struct pt_regs *regs)
17036 {
17037 #ifdef CONFIG_X86_32
17038 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17039 #else
17040- return !!(regs->cs & 3);
17041+ return !!(regs->cs & SEGMENT_RPL_MASK);
17042 #endif
17043 }
17044
17045-static inline int user_mode_vm(struct pt_regs *regs)
17046+static inline int user_mode(struct pt_regs *regs)
17047 {
17048 #ifdef CONFIG_X86_32
17049 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17050 USER_RPL;
17051 #else
17052- return user_mode(regs);
17053+ return user_mode_novm(regs);
17054 #endif
17055 }
17056
17057@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17058 #ifdef CONFIG_X86_64
17059 static inline bool user_64bit_mode(struct pt_regs *regs)
17060 {
17061+ unsigned long cs = regs->cs & 0xffff;
17062 #ifndef CONFIG_PARAVIRT
17063 /*
17064 * On non-paravirt systems, this is the only long mode CPL 3
17065 * selector. We do not allow long mode selectors in the LDT.
17066 */
17067- return regs->cs == __USER_CS;
17068+ return cs == __USER_CS;
17069 #else
17070 /* Headers are too twisted for this to go in paravirt.h. */
17071- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17072+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17073 #endif
17074 }
17075
17076@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17077 * Traps from the kernel do not save sp and ss.
17078 * Use the helper function to retrieve sp.
17079 */
17080- if (offset == offsetof(struct pt_regs, sp) &&
17081- regs->cs == __KERNEL_CS)
17082- return kernel_stack_pointer(regs);
17083+ if (offset == offsetof(struct pt_regs, sp)) {
17084+ unsigned long cs = regs->cs & 0xffff;
17085+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17086+ return kernel_stack_pointer(regs);
17087+ }
17088 #endif
17089 return *(unsigned long *)((unsigned long)regs + offset);
17090 }
17091diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17092index 9c6b890..5305f53 100644
17093--- a/arch/x86/include/asm/realmode.h
17094+++ b/arch/x86/include/asm/realmode.h
17095@@ -22,16 +22,14 @@ struct real_mode_header {
17096 #endif
17097 /* APM/BIOS reboot */
17098 u32 machine_real_restart_asm;
17099-#ifdef CONFIG_X86_64
17100 u32 machine_real_restart_seg;
17101-#endif
17102 };
17103
17104 /* This must match data at trampoline_32/64.S */
17105 struct trampoline_header {
17106 #ifdef CONFIG_X86_32
17107 u32 start;
17108- u16 gdt_pad;
17109+ u16 boot_cs;
17110 u16 gdt_limit;
17111 u32 gdt_base;
17112 #else
17113diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17114index a82c4f1..ac45053 100644
17115--- a/arch/x86/include/asm/reboot.h
17116+++ b/arch/x86/include/asm/reboot.h
17117@@ -6,13 +6,13 @@
17118 struct pt_regs;
17119
17120 struct machine_ops {
17121- void (*restart)(char *cmd);
17122- void (*halt)(void);
17123- void (*power_off)(void);
17124+ void (* __noreturn restart)(char *cmd);
17125+ void (* __noreturn halt)(void);
17126+ void (* __noreturn power_off)(void);
17127 void (*shutdown)(void);
17128 void (*crash_shutdown)(struct pt_regs *);
17129- void (*emergency_restart)(void);
17130-};
17131+ void (* __noreturn emergency_restart)(void);
17132+} __no_const;
17133
17134 extern struct machine_ops machine_ops;
17135
17136diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17137index cad82c9..2e5c5c1 100644
17138--- a/arch/x86/include/asm/rwsem.h
17139+++ b/arch/x86/include/asm/rwsem.h
17140@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17141 {
17142 asm volatile("# beginning down_read\n\t"
17143 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17144+
17145+#ifdef CONFIG_PAX_REFCOUNT
17146+ "jno 0f\n"
17147+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17148+ "int $4\n0:\n"
17149+ _ASM_EXTABLE(0b, 0b)
17150+#endif
17151+
17152 /* adds 0x00000001 */
17153 " jns 1f\n"
17154 " call call_rwsem_down_read_failed\n"
17155@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17156 "1:\n\t"
17157 " mov %1,%2\n\t"
17158 " add %3,%2\n\t"
17159+
17160+#ifdef CONFIG_PAX_REFCOUNT
17161+ "jno 0f\n"
17162+ "sub %3,%2\n"
17163+ "int $4\n0:\n"
17164+ _ASM_EXTABLE(0b, 0b)
17165+#endif
17166+
17167 " jle 2f\n\t"
17168 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17169 " jnz 1b\n\t"
17170@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17171 long tmp;
17172 asm volatile("# beginning down_write\n\t"
17173 LOCK_PREFIX " xadd %1,(%2)\n\t"
17174+
17175+#ifdef CONFIG_PAX_REFCOUNT
17176+ "jno 0f\n"
17177+ "mov %1,(%2)\n"
17178+ "int $4\n0:\n"
17179+ _ASM_EXTABLE(0b, 0b)
17180+#endif
17181+
17182 /* adds 0xffff0001, returns the old value */
17183 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17184 /* was the active mask 0 before? */
17185@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17186 long tmp;
17187 asm volatile("# beginning __up_read\n\t"
17188 LOCK_PREFIX " xadd %1,(%2)\n\t"
17189+
17190+#ifdef CONFIG_PAX_REFCOUNT
17191+ "jno 0f\n"
17192+ "mov %1,(%2)\n"
17193+ "int $4\n0:\n"
17194+ _ASM_EXTABLE(0b, 0b)
17195+#endif
17196+
17197 /* subtracts 1, returns the old value */
17198 " jns 1f\n\t"
17199 " call call_rwsem_wake\n" /* expects old value in %edx */
17200@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17201 long tmp;
17202 asm volatile("# beginning __up_write\n\t"
17203 LOCK_PREFIX " xadd %1,(%2)\n\t"
17204+
17205+#ifdef CONFIG_PAX_REFCOUNT
17206+ "jno 0f\n"
17207+ "mov %1,(%2)\n"
17208+ "int $4\n0:\n"
17209+ _ASM_EXTABLE(0b, 0b)
17210+#endif
17211+
17212 /* subtracts 0xffff0001, returns the old value */
17213 " jns 1f\n\t"
17214 " call call_rwsem_wake\n" /* expects old value in %edx */
17215@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17216 {
17217 asm volatile("# beginning __downgrade_write\n\t"
17218 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17219+
17220+#ifdef CONFIG_PAX_REFCOUNT
17221+ "jno 0f\n"
17222+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17223+ "int $4\n0:\n"
17224+ _ASM_EXTABLE(0b, 0b)
17225+#endif
17226+
17227 /*
17228 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17229 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17230@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17231 */
17232 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17233 {
17234- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17235+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17236+
17237+#ifdef CONFIG_PAX_REFCOUNT
17238+ "jno 0f\n"
17239+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17240+ "int $4\n0:\n"
17241+ _ASM_EXTABLE(0b, 0b)
17242+#endif
17243+
17244 : "+m" (sem->count)
17245 : "er" (delta));
17246 }
17247@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17248 */
17249 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17250 {
17251- return delta + xadd(&sem->count, delta);
17252+ return delta + xadd_check_overflow(&sem->count, delta);
17253 }
17254
17255 #endif /* __KERNEL__ */
17256diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17257index c48a950..bc40804 100644
17258--- a/arch/x86/include/asm/segment.h
17259+++ b/arch/x86/include/asm/segment.h
17260@@ -64,10 +64,15 @@
17261 * 26 - ESPFIX small SS
17262 * 27 - per-cpu [ offset to per-cpu data area ]
17263 * 28 - stack_canary-20 [ for stack protector ]
17264- * 29 - unused
17265- * 30 - unused
17266+ * 29 - PCI BIOS CS
17267+ * 30 - PCI BIOS DS
17268 * 31 - TSS for double fault handler
17269 */
17270+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17271+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17272+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17273+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17274+
17275 #define GDT_ENTRY_TLS_MIN 6
17276 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17277
17278@@ -79,6 +84,8 @@
17279
17280 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17281
17282+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17283+
17284 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17285
17286 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17287@@ -104,6 +111,12 @@
17288 #define __KERNEL_STACK_CANARY 0
17289 #endif
17290
17291+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17292+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17293+
17294+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17295+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17296+
17297 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17298
17299 /*
17300@@ -141,7 +154,7 @@
17301 */
17302
17303 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17304-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17305+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17306
17307
17308 #else
17309@@ -165,6 +178,8 @@
17310 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17311 #define __USER32_DS __USER_DS
17312
17313+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17314+
17315 #define GDT_ENTRY_TSS 8 /* needs two entries */
17316 #define GDT_ENTRY_LDT 10 /* needs two entries */
17317 #define GDT_ENTRY_TLS_MIN 12
17318@@ -173,6 +188,8 @@
17319 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17320 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17321
17322+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17323+
17324 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17325 #define FS_TLS 0
17326 #define GS_TLS 1
17327@@ -180,12 +197,14 @@
17328 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17329 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17330
17331-#define GDT_ENTRIES 16
17332+#define GDT_ENTRIES 17
17333
17334 #endif
17335
17336 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17337+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17338 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17339+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17340 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17341 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17342 #ifndef CONFIG_PARAVIRT
17343@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17344 {
17345 unsigned long __limit;
17346 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17347- return __limit + 1;
17348+ return __limit;
17349 }
17350
17351 #endif /* !__ASSEMBLY__ */
17352diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17353index 8d3120f..352b440 100644
17354--- a/arch/x86/include/asm/smap.h
17355+++ b/arch/x86/include/asm/smap.h
17356@@ -25,11 +25,40 @@
17357
17358 #include <asm/alternative-asm.h>
17359
17360+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17361+#define ASM_PAX_OPEN_USERLAND \
17362+ 661: jmp 663f; \
17363+ .pushsection .altinstr_replacement, "a" ; \
17364+ 662: pushq %rax; nop; \
17365+ .popsection ; \
17366+ .pushsection .altinstructions, "a" ; \
17367+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17368+ .popsection ; \
17369+ call __pax_open_userland; \
17370+ popq %rax; \
17371+ 663:
17372+
17373+#define ASM_PAX_CLOSE_USERLAND \
17374+ 661: jmp 663f; \
17375+ .pushsection .altinstr_replacement, "a" ; \
17376+ 662: pushq %rax; nop; \
17377+ .popsection; \
17378+ .pushsection .altinstructions, "a" ; \
17379+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17380+ .popsection; \
17381+ call __pax_close_userland; \
17382+ popq %rax; \
17383+ 663:
17384+#else
17385+#define ASM_PAX_OPEN_USERLAND
17386+#define ASM_PAX_CLOSE_USERLAND
17387+#endif
17388+
17389 #ifdef CONFIG_X86_SMAP
17390
17391 #define ASM_CLAC \
17392 661: ASM_NOP3 ; \
17393- .pushsection .altinstr_replacement, "ax" ; \
17394+ .pushsection .altinstr_replacement, "a" ; \
17395 662: __ASM_CLAC ; \
17396 .popsection ; \
17397 .pushsection .altinstructions, "a" ; \
17398@@ -38,7 +67,7 @@
17399
17400 #define ASM_STAC \
17401 661: ASM_NOP3 ; \
17402- .pushsection .altinstr_replacement, "ax" ; \
17403+ .pushsection .altinstr_replacement, "a" ; \
17404 662: __ASM_STAC ; \
17405 .popsection ; \
17406 .pushsection .altinstructions, "a" ; \
17407@@ -56,6 +85,37 @@
17408
17409 #include <asm/alternative.h>
17410
17411+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17412+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17413+
17414+extern void __pax_open_userland(void);
17415+static __always_inline unsigned long pax_open_userland(void)
17416+{
17417+
17418+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17419+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17420+ :
17421+ : [open] "i" (__pax_open_userland)
17422+ : "memory", "rax");
17423+#endif
17424+
17425+ return 0;
17426+}
17427+
17428+extern void __pax_close_userland(void);
17429+static __always_inline unsigned long pax_close_userland(void)
17430+{
17431+
17432+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17433+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17434+ :
17435+ : [close] "i" (__pax_close_userland)
17436+ : "memory", "rax");
17437+#endif
17438+
17439+ return 0;
17440+}
17441+
17442 #ifdef CONFIG_X86_SMAP
17443
17444 static __always_inline void clac(void)
17445diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17446index 4137890..03fa172 100644
17447--- a/arch/x86/include/asm/smp.h
17448+++ b/arch/x86/include/asm/smp.h
17449@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17450 /* cpus sharing the last level cache: */
17451 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17452 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17453-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17454+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17455
17456 static inline struct cpumask *cpu_sibling_mask(int cpu)
17457 {
17458@@ -79,7 +79,7 @@ struct smp_ops {
17459
17460 void (*send_call_func_ipi)(const struct cpumask *mask);
17461 void (*send_call_func_single_ipi)(int cpu);
17462-};
17463+} __no_const;
17464
17465 /* Globals due to paravirt */
17466 extern void set_cpu_sibling_map(int cpu);
17467@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17468 extern int safe_smp_processor_id(void);
17469
17470 #elif defined(CONFIG_X86_64_SMP)
17471-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17472-
17473-#define stack_smp_processor_id() \
17474-({ \
17475- struct thread_info *ti; \
17476- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17477- ti->cpu; \
17478-})
17479+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17480+#define stack_smp_processor_id() raw_smp_processor_id()
17481 #define safe_smp_processor_id() smp_processor_id()
17482
17483 #endif
17484diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17485index e3ddd7d..3611fce 100644
17486--- a/arch/x86/include/asm/spinlock.h
17487+++ b/arch/x86/include/asm/spinlock.h
17488@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17489 static inline void arch_read_lock(arch_rwlock_t *rw)
17490 {
17491 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17492+
17493+#ifdef CONFIG_PAX_REFCOUNT
17494+ "jno 0f\n"
17495+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17496+ "int $4\n0:\n"
17497+ _ASM_EXTABLE(0b, 0b)
17498+#endif
17499+
17500 "jns 1f\n"
17501 "call __read_lock_failed\n\t"
17502 "1:\n"
17503@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17504 static inline void arch_write_lock(arch_rwlock_t *rw)
17505 {
17506 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17507+
17508+#ifdef CONFIG_PAX_REFCOUNT
17509+ "jno 0f\n"
17510+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17511+ "int $4\n0:\n"
17512+ _ASM_EXTABLE(0b, 0b)
17513+#endif
17514+
17515 "jz 1f\n"
17516 "call __write_lock_failed\n\t"
17517 "1:\n"
17518@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17519
17520 static inline void arch_read_unlock(arch_rwlock_t *rw)
17521 {
17522- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17523+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17524+
17525+#ifdef CONFIG_PAX_REFCOUNT
17526+ "jno 0f\n"
17527+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17528+ "int $4\n0:\n"
17529+ _ASM_EXTABLE(0b, 0b)
17530+#endif
17531+
17532 :"+m" (rw->lock) : : "memory");
17533 }
17534
17535 static inline void arch_write_unlock(arch_rwlock_t *rw)
17536 {
17537- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17538+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17539+
17540+#ifdef CONFIG_PAX_REFCOUNT
17541+ "jno 0f\n"
17542+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17543+ "int $4\n0:\n"
17544+ _ASM_EXTABLE(0b, 0b)
17545+#endif
17546+
17547 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17548 }
17549
17550diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17551index 6a99859..03cb807 100644
17552--- a/arch/x86/include/asm/stackprotector.h
17553+++ b/arch/x86/include/asm/stackprotector.h
17554@@ -47,7 +47,7 @@
17555 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17556 */
17557 #define GDT_STACK_CANARY_INIT \
17558- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17559+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17560
17561 /*
17562 * Initialize the stackprotector canary value.
17563@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17564
17565 static inline void load_stack_canary_segment(void)
17566 {
17567-#ifdef CONFIG_X86_32
17568+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17569 asm volatile ("mov %0, %%gs" : : "r" (0));
17570 #endif
17571 }
17572diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17573index 70bbe39..4ae2bd4 100644
17574--- a/arch/x86/include/asm/stacktrace.h
17575+++ b/arch/x86/include/asm/stacktrace.h
17576@@ -11,28 +11,20 @@
17577
17578 extern int kstack_depth_to_print;
17579
17580-struct thread_info;
17581+struct task_struct;
17582 struct stacktrace_ops;
17583
17584-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17585- unsigned long *stack,
17586- unsigned long bp,
17587- const struct stacktrace_ops *ops,
17588- void *data,
17589- unsigned long *end,
17590- int *graph);
17591+typedef unsigned long walk_stack_t(struct task_struct *task,
17592+ void *stack_start,
17593+ unsigned long *stack,
17594+ unsigned long bp,
17595+ const struct stacktrace_ops *ops,
17596+ void *data,
17597+ unsigned long *end,
17598+ int *graph);
17599
17600-extern unsigned long
17601-print_context_stack(struct thread_info *tinfo,
17602- unsigned long *stack, unsigned long bp,
17603- const struct stacktrace_ops *ops, void *data,
17604- unsigned long *end, int *graph);
17605-
17606-extern unsigned long
17607-print_context_stack_bp(struct thread_info *tinfo,
17608- unsigned long *stack, unsigned long bp,
17609- const struct stacktrace_ops *ops, void *data,
17610- unsigned long *end, int *graph);
17611+extern walk_stack_t print_context_stack;
17612+extern walk_stack_t print_context_stack_bp;
17613
17614 /* Generic stack tracer with callbacks */
17615
17616@@ -40,7 +32,7 @@ struct stacktrace_ops {
17617 void (*address)(void *data, unsigned long address, int reliable);
17618 /* On negative return stop dumping */
17619 int (*stack)(void *data, char *name);
17620- walk_stack_t walk_stack;
17621+ walk_stack_t *walk_stack;
17622 };
17623
17624 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17625diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17626index 4ec45b3..a4f0a8a 100644
17627--- a/arch/x86/include/asm/switch_to.h
17628+++ b/arch/x86/include/asm/switch_to.h
17629@@ -108,7 +108,7 @@ do { \
17630 "call __switch_to\n\t" \
17631 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17632 __switch_canary \
17633- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17634+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17635 "movq %%rax,%%rdi\n\t" \
17636 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17637 "jnz ret_from_fork\n\t" \
17638@@ -119,7 +119,7 @@ do { \
17639 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17640 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17641 [_tif_fork] "i" (_TIF_FORK), \
17642- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17643+ [thread_info] "m" (current_tinfo), \
17644 [current_task] "m" (current_task) \
17645 __switch_canary_iparam \
17646 : "memory", "cc" __EXTRA_CLOBBER)
17647diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17648index 2781119..618b59b 100644
17649--- a/arch/x86/include/asm/thread_info.h
17650+++ b/arch/x86/include/asm/thread_info.h
17651@@ -10,6 +10,7 @@
17652 #include <linux/compiler.h>
17653 #include <asm/page.h>
17654 #include <asm/types.h>
17655+#include <asm/percpu.h>
17656
17657 /*
17658 * low level task data that entry.S needs immediate access to
17659@@ -23,7 +24,6 @@ struct exec_domain;
17660 #include <linux/atomic.h>
17661
17662 struct thread_info {
17663- struct task_struct *task; /* main task structure */
17664 struct exec_domain *exec_domain; /* execution domain */
17665 __u32 flags; /* low level flags */
17666 __u32 status; /* thread synchronous flags */
17667@@ -33,19 +33,13 @@ struct thread_info {
17668 mm_segment_t addr_limit;
17669 struct restart_block restart_block;
17670 void __user *sysenter_return;
17671-#ifdef CONFIG_X86_32
17672- unsigned long previous_esp; /* ESP of the previous stack in
17673- case of nested (IRQ) stacks
17674- */
17675- __u8 supervisor_stack[0];
17676-#endif
17677+ unsigned long lowest_stack;
17678 unsigned int sig_on_uaccess_error:1;
17679 unsigned int uaccess_err:1; /* uaccess failed */
17680 };
17681
17682-#define INIT_THREAD_INFO(tsk) \
17683+#define INIT_THREAD_INFO \
17684 { \
17685- .task = &tsk, \
17686 .exec_domain = &default_exec_domain, \
17687 .flags = 0, \
17688 .cpu = 0, \
17689@@ -56,7 +50,7 @@ struct thread_info {
17690 }, \
17691 }
17692
17693-#define init_thread_info (init_thread_union.thread_info)
17694+#define init_thread_info (init_thread_union.stack)
17695 #define init_stack (init_thread_union.stack)
17696
17697 #else /* !__ASSEMBLY__ */
17698@@ -96,6 +90,7 @@ struct thread_info {
17699 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17700 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17701 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17702+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17703
17704 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17705 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17706@@ -119,17 +114,18 @@ struct thread_info {
17707 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17708 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17709 #define _TIF_X32 (1 << TIF_X32)
17710+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17711
17712 /* work to do in syscall_trace_enter() */
17713 #define _TIF_WORK_SYSCALL_ENTRY \
17714 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17715 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17716- _TIF_NOHZ)
17717+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17718
17719 /* work to do in syscall_trace_leave() */
17720 #define _TIF_WORK_SYSCALL_EXIT \
17721 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17722- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17723+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17724
17725 /* work to do on interrupt/exception return */
17726 #define _TIF_WORK_MASK \
17727@@ -140,7 +136,7 @@ struct thread_info {
17728 /* work to do on any return to user space */
17729 #define _TIF_ALLWORK_MASK \
17730 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17731- _TIF_NOHZ)
17732+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17733
17734 /* Only used for 64 bit */
17735 #define _TIF_DO_NOTIFY_MASK \
17736@@ -156,45 +152,40 @@ struct thread_info {
17737
17738 #define PREEMPT_ACTIVE 0x10000000
17739
17740-#ifdef CONFIG_X86_32
17741-
17742-#define STACK_WARN (THREAD_SIZE/8)
17743-/*
17744- * macros/functions for gaining access to the thread information structure
17745- *
17746- * preempt_count needs to be 1 initially, until the scheduler is functional.
17747- */
17748-#ifndef __ASSEMBLY__
17749-
17750-
17751-/* how to get the current stack pointer from C */
17752-register unsigned long current_stack_pointer asm("esp") __used;
17753-
17754-/* how to get the thread information struct from C */
17755-static inline struct thread_info *current_thread_info(void)
17756-{
17757- return (struct thread_info *)
17758- (current_stack_pointer & ~(THREAD_SIZE - 1));
17759-}
17760-
17761-#else /* !__ASSEMBLY__ */
17762-
17763+#ifdef __ASSEMBLY__
17764 /* how to get the thread information struct from ASM */
17765 #define GET_THREAD_INFO(reg) \
17766- movl $-THREAD_SIZE, reg; \
17767- andl %esp, reg
17768+ mov PER_CPU_VAR(current_tinfo), reg
17769
17770 /* use this one if reg already contains %esp */
17771-#define GET_THREAD_INFO_WITH_ESP(reg) \
17772- andl $-THREAD_SIZE, reg
17773+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17774+#else
17775+/* how to get the thread information struct from C */
17776+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17777+
17778+static __always_inline struct thread_info *current_thread_info(void)
17779+{
17780+ return this_cpu_read_stable(current_tinfo);
17781+}
17782+#endif
17783+
17784+#ifdef CONFIG_X86_32
17785+
17786+#define STACK_WARN (THREAD_SIZE/8)
17787+/*
17788+ * macros/functions for gaining access to the thread information structure
17789+ *
17790+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17791+ */
17792+#ifndef __ASSEMBLY__
17793+
17794+/* how to get the current stack pointer from C */
17795+register unsigned long current_stack_pointer asm("esp") __used;
17796
17797 #endif
17798
17799 #else /* X86_32 */
17800
17801-#include <asm/percpu.h>
17802-#define KERNEL_STACK_OFFSET (5*8)
17803-
17804 /*
17805 * macros/functions for gaining access to the thread information structure
17806 * preempt_count needs to be 1 initially, until the scheduler is functional.
17807@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17808 #ifndef __ASSEMBLY__
17809 DECLARE_PER_CPU(unsigned long, kernel_stack);
17810
17811-static inline struct thread_info *current_thread_info(void)
17812-{
17813- struct thread_info *ti;
17814- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17815- KERNEL_STACK_OFFSET - THREAD_SIZE);
17816- return ti;
17817-}
17818-
17819-#else /* !__ASSEMBLY__ */
17820-
17821-/* how to get the thread information struct from ASM */
17822-#define GET_THREAD_INFO(reg) \
17823- movq PER_CPU_VAR(kernel_stack),reg ; \
17824- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17825-
17826-/*
17827- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17828- * a certain register (to be used in assembler memory operands).
17829- */
17830-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17831-
17832+/* how to get the current stack pointer from C */
17833+register unsigned long current_stack_pointer asm("rsp") __used;
17834 #endif
17835
17836 #endif /* !X86_32 */
17837@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17838 extern void arch_task_cache_init(void);
17839 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17840 extern void arch_release_task_struct(struct task_struct *tsk);
17841+
17842+#define __HAVE_THREAD_FUNCTIONS
17843+#define task_thread_info(task) (&(task)->tinfo)
17844+#define task_stack_page(task) ((task)->stack)
17845+#define setup_thread_stack(p, org) do {} while (0)
17846+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17847+
17848 #endif
17849 #endif /* _ASM_X86_THREAD_INFO_H */
17850diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17851index cf51200..63ff068 100644
17852--- a/arch/x86/include/asm/tlbflush.h
17853+++ b/arch/x86/include/asm/tlbflush.h
17854@@ -17,18 +17,44 @@
17855
17856 static inline void __native_flush_tlb(void)
17857 {
17858+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17859+ u64 descriptor[2];
17860+
17861+ descriptor[0] = PCID_KERNEL;
17862+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17863+ return;
17864+ }
17865+
17866+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17867+ if (static_cpu_has(X86_FEATURE_PCID)) {
17868+ unsigned int cpu = raw_get_cpu();
17869+
17870+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17871+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17872+ raw_put_cpu_no_resched();
17873+ return;
17874+ }
17875+#endif
17876+
17877 native_write_cr3(native_read_cr3());
17878 }
17879
17880 static inline void __native_flush_tlb_global_irq_disabled(void)
17881 {
17882- unsigned long cr4;
17883+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17884+ u64 descriptor[2];
17885
17886- cr4 = native_read_cr4();
17887- /* clear PGE */
17888- native_write_cr4(cr4 & ~X86_CR4_PGE);
17889- /* write old PGE again and flush TLBs */
17890- native_write_cr4(cr4);
17891+ descriptor[0] = PCID_KERNEL;
17892+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17893+ } else {
17894+ unsigned long cr4;
17895+
17896+ cr4 = native_read_cr4();
17897+ /* clear PGE */
17898+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17899+ /* write old PGE again and flush TLBs */
17900+ native_write_cr4(cr4);
17901+ }
17902 }
17903
17904 static inline void __native_flush_tlb_global(void)
17905@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17906
17907 static inline void __native_flush_tlb_single(unsigned long addr)
17908 {
17909+
17910+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17911+ u64 descriptor[2];
17912+
17913+ descriptor[0] = PCID_KERNEL;
17914+ descriptor[1] = addr;
17915+
17916+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17917+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17918+ if (addr < TASK_SIZE_MAX)
17919+ descriptor[1] += pax_user_shadow_base;
17920+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17921+ }
17922+
17923+ descriptor[0] = PCID_USER;
17924+ descriptor[1] = addr;
17925+#endif
17926+
17927+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17928+ return;
17929+ }
17930+
17931+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17932+ if (static_cpu_has(X86_FEATURE_PCID)) {
17933+ unsigned int cpu = raw_get_cpu();
17934+
17935+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17936+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17937+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17938+ raw_put_cpu_no_resched();
17939+
17940+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17941+ addr += pax_user_shadow_base;
17942+ }
17943+#endif
17944+
17945 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17946 }
17947
17948diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17949index 5ee2687..74590b9 100644
17950--- a/arch/x86/include/asm/uaccess.h
17951+++ b/arch/x86/include/asm/uaccess.h
17952@@ -7,6 +7,7 @@
17953 #include <linux/compiler.h>
17954 #include <linux/thread_info.h>
17955 #include <linux/string.h>
17956+#include <linux/sched.h>
17957 #include <asm/asm.h>
17958 #include <asm/page.h>
17959 #include <asm/smap.h>
17960@@ -29,7 +30,12 @@
17961
17962 #define get_ds() (KERNEL_DS)
17963 #define get_fs() (current_thread_info()->addr_limit)
17964+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17965+void __set_fs(mm_segment_t x);
17966+void set_fs(mm_segment_t x);
17967+#else
17968 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17969+#endif
17970
17971 #define segment_eq(a, b) ((a).seg == (b).seg)
17972
17973@@ -77,8 +83,33 @@
17974 * checks that the pointer is in the user space range - after calling
17975 * this function, memory access functions may still return -EFAULT.
17976 */
17977-#define access_ok(type, addr, size) \
17978- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17979+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17980+#define access_ok(type, addr, size) \
17981+({ \
17982+ long __size = size; \
17983+ unsigned long __addr = (unsigned long)addr; \
17984+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17985+ unsigned long __end_ao = __addr + __size - 1; \
17986+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17987+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17988+ while(__addr_ao <= __end_ao) { \
17989+ char __c_ao; \
17990+ __addr_ao += PAGE_SIZE; \
17991+ if (__size > PAGE_SIZE) \
17992+ cond_resched(); \
17993+ if (__get_user(__c_ao, (char __user *)__addr)) \
17994+ break; \
17995+ if (type != VERIFY_WRITE) { \
17996+ __addr = __addr_ao; \
17997+ continue; \
17998+ } \
17999+ if (__put_user(__c_ao, (char __user *)__addr)) \
18000+ break; \
18001+ __addr = __addr_ao; \
18002+ } \
18003+ } \
18004+ __ret_ao; \
18005+})
18006
18007 /*
18008 * The exception table consists of pairs of addresses relative to the
18009@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18010 register __inttype(*(ptr)) __val_gu asm("%edx"); \
18011 __chk_user_ptr(ptr); \
18012 might_fault(); \
18013+ pax_open_userland(); \
18014 asm volatile("call __get_user_%P3" \
18015 : "=a" (__ret_gu), "=r" (__val_gu) \
18016 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18017 (x) = (__typeof__(*(ptr))) __val_gu; \
18018+ pax_close_userland(); \
18019 __ret_gu; \
18020 })
18021
18022@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18023 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18024 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18025
18026-
18027+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18028+#define __copyuser_seg "gs;"
18029+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18030+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18031+#else
18032+#define __copyuser_seg
18033+#define __COPYUSER_SET_ES
18034+#define __COPYUSER_RESTORE_ES
18035+#endif
18036
18037 #ifdef CONFIG_X86_32
18038 #define __put_user_asm_u64(x, addr, err, errret) \
18039 asm volatile(ASM_STAC "\n" \
18040- "1: movl %%eax,0(%2)\n" \
18041- "2: movl %%edx,4(%2)\n" \
18042+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18043+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18044 "3: " ASM_CLAC "\n" \
18045 ".section .fixup,\"ax\"\n" \
18046 "4: movl %3,%0\n" \
18047@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18048
18049 #define __put_user_asm_ex_u64(x, addr) \
18050 asm volatile(ASM_STAC "\n" \
18051- "1: movl %%eax,0(%1)\n" \
18052- "2: movl %%edx,4(%1)\n" \
18053+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18054+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18055 "3: " ASM_CLAC "\n" \
18056 _ASM_EXTABLE_EX(1b, 2b) \
18057 _ASM_EXTABLE_EX(2b, 3b) \
18058@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18059 __typeof__(*(ptr)) __pu_val; \
18060 __chk_user_ptr(ptr); \
18061 might_fault(); \
18062- __pu_val = x; \
18063+ __pu_val = (x); \
18064+ pax_open_userland(); \
18065 switch (sizeof(*(ptr))) { \
18066 case 1: \
18067 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18068@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18069 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18070 break; \
18071 } \
18072+ pax_close_userland(); \
18073 __ret_pu; \
18074 })
18075
18076@@ -344,8 +387,10 @@ do { \
18077 } while (0)
18078
18079 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18080+do { \
18081+ pax_open_userland(); \
18082 asm volatile(ASM_STAC "\n" \
18083- "1: mov"itype" %2,%"rtype"1\n" \
18084+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18085 "2: " ASM_CLAC "\n" \
18086 ".section .fixup,\"ax\"\n" \
18087 "3: mov %3,%0\n" \
18088@@ -353,8 +398,10 @@ do { \
18089 " jmp 2b\n" \
18090 ".previous\n" \
18091 _ASM_EXTABLE(1b, 3b) \
18092- : "=r" (err), ltype(x) \
18093- : "m" (__m(addr)), "i" (errret), "0" (err))
18094+ : "=r" (err), ltype (x) \
18095+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18096+ pax_close_userland(); \
18097+} while (0)
18098
18099 #define __get_user_size_ex(x, ptr, size) \
18100 do { \
18101@@ -378,7 +425,7 @@ do { \
18102 } while (0)
18103
18104 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18105- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18106+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18107 "2:\n" \
18108 _ASM_EXTABLE_EX(1b, 2b) \
18109 : ltype(x) : "m" (__m(addr)))
18110@@ -395,13 +442,24 @@ do { \
18111 int __gu_err; \
18112 unsigned long __gu_val; \
18113 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18114- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18115+ (x) = (__typeof__(*(ptr)))__gu_val; \
18116 __gu_err; \
18117 })
18118
18119 /* FIXME: this hack is definitely wrong -AK */
18120 struct __large_struct { unsigned long buf[100]; };
18121-#define __m(x) (*(struct __large_struct __user *)(x))
18122+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18123+#define ____m(x) \
18124+({ \
18125+ unsigned long ____x = (unsigned long)(x); \
18126+ if (____x < pax_user_shadow_base) \
18127+ ____x += pax_user_shadow_base; \
18128+ (typeof(x))____x; \
18129+})
18130+#else
18131+#define ____m(x) (x)
18132+#endif
18133+#define __m(x) (*(struct __large_struct __user *)____m(x))
18134
18135 /*
18136 * Tell gcc we read from memory instead of writing: this is because
18137@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18138 * aliasing issues.
18139 */
18140 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18141+do { \
18142+ pax_open_userland(); \
18143 asm volatile(ASM_STAC "\n" \
18144- "1: mov"itype" %"rtype"1,%2\n" \
18145+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18146 "2: " ASM_CLAC "\n" \
18147 ".section .fixup,\"ax\"\n" \
18148 "3: mov %3,%0\n" \
18149@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18150 ".previous\n" \
18151 _ASM_EXTABLE(1b, 3b) \
18152 : "=r"(err) \
18153- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18154+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18155+ pax_close_userland(); \
18156+} while (0)
18157
18158 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18159- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18160+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18161 "2:\n" \
18162 _ASM_EXTABLE_EX(1b, 2b) \
18163 : : ltype(x), "m" (__m(addr)))
18164@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18165 */
18166 #define uaccess_try do { \
18167 current_thread_info()->uaccess_err = 0; \
18168+ pax_open_userland(); \
18169 stac(); \
18170 barrier();
18171
18172 #define uaccess_catch(err) \
18173 clac(); \
18174+ pax_close_userland(); \
18175 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18176 } while (0)
18177
18178@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18179 * On error, the variable @x is set to zero.
18180 */
18181
18182+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18183+#define __get_user(x, ptr) get_user((x), (ptr))
18184+#else
18185 #define __get_user(x, ptr) \
18186 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18187+#endif
18188
18189 /**
18190 * __put_user: - Write a simple value into user space, with less checking.
18191@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18192 * Returns zero on success, or -EFAULT on error.
18193 */
18194
18195+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18196+#define __put_user(x, ptr) put_user((x), (ptr))
18197+#else
18198 #define __put_user(x, ptr) \
18199 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18200+#endif
18201
18202 #define __get_user_unaligned __get_user
18203 #define __put_user_unaligned __put_user
18204@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18205 #define get_user_ex(x, ptr) do { \
18206 unsigned long __gue_val; \
18207 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18208- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18209+ (x) = (__typeof__(*(ptr)))__gue_val; \
18210 } while (0)
18211
18212 #define put_user_try uaccess_try
18213@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18214 extern __must_check long strlen_user(const char __user *str);
18215 extern __must_check long strnlen_user(const char __user *str, long n);
18216
18217-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18218-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18219+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18220+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18221
18222 /*
18223 * movsl can be slow when source and dest are not both 8-byte aligned
18224diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18225index 7f760a9..04b1c65 100644
18226--- a/arch/x86/include/asm/uaccess_32.h
18227+++ b/arch/x86/include/asm/uaccess_32.h
18228@@ -11,15 +11,15 @@
18229 #include <asm/page.h>
18230
18231 unsigned long __must_check __copy_to_user_ll
18232- (void __user *to, const void *from, unsigned long n);
18233+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18234 unsigned long __must_check __copy_from_user_ll
18235- (void *to, const void __user *from, unsigned long n);
18236+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18237 unsigned long __must_check __copy_from_user_ll_nozero
18238- (void *to, const void __user *from, unsigned long n);
18239+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18240 unsigned long __must_check __copy_from_user_ll_nocache
18241- (void *to, const void __user *from, unsigned long n);
18242+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18243 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18244- (void *to, const void __user *from, unsigned long n);
18245+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18246
18247 /**
18248 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18249@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18250 static __always_inline unsigned long __must_check
18251 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18252 {
18253+ if ((long)n < 0)
18254+ return n;
18255+
18256+ check_object_size(from, n, true);
18257+
18258 if (__builtin_constant_p(n)) {
18259 unsigned long ret;
18260
18261@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18262 __copy_to_user(void __user *to, const void *from, unsigned long n)
18263 {
18264 might_fault();
18265+
18266 return __copy_to_user_inatomic(to, from, n);
18267 }
18268
18269 static __always_inline unsigned long
18270 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18271 {
18272+ if ((long)n < 0)
18273+ return n;
18274+
18275 /* Avoid zeroing the tail if the copy fails..
18276 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18277 * but as the zeroing behaviour is only significant when n is not
18278@@ -137,6 +146,12 @@ static __always_inline unsigned long
18279 __copy_from_user(void *to, const void __user *from, unsigned long n)
18280 {
18281 might_fault();
18282+
18283+ if ((long)n < 0)
18284+ return n;
18285+
18286+ check_object_size(to, n, false);
18287+
18288 if (__builtin_constant_p(n)) {
18289 unsigned long ret;
18290
18291@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18292 const void __user *from, unsigned long n)
18293 {
18294 might_fault();
18295+
18296+ if ((long)n < 0)
18297+ return n;
18298+
18299 if (__builtin_constant_p(n)) {
18300 unsigned long ret;
18301
18302@@ -181,15 +200,19 @@ static __always_inline unsigned long
18303 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18304 unsigned long n)
18305 {
18306- return __copy_from_user_ll_nocache_nozero(to, from, n);
18307+ if ((long)n < 0)
18308+ return n;
18309+
18310+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18311 }
18312
18313-unsigned long __must_check copy_to_user(void __user *to,
18314- const void *from, unsigned long n);
18315-unsigned long __must_check _copy_from_user(void *to,
18316- const void __user *from,
18317- unsigned long n);
18318-
18319+extern void copy_to_user_overflow(void)
18320+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18321+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18322+#else
18323+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18324+#endif
18325+;
18326
18327 extern void copy_from_user_overflow(void)
18328 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18329@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18330 #endif
18331 ;
18332
18333-static inline unsigned long __must_check copy_from_user(void *to,
18334- const void __user *from,
18335- unsigned long n)
18336+/**
18337+ * copy_to_user: - Copy a block of data into user space.
18338+ * @to: Destination address, in user space.
18339+ * @from: Source address, in kernel space.
18340+ * @n: Number of bytes to copy.
18341+ *
18342+ * Context: User context only. This function may sleep.
18343+ *
18344+ * Copy data from kernel space to user space.
18345+ *
18346+ * Returns number of bytes that could not be copied.
18347+ * On success, this will be zero.
18348+ */
18349+static inline unsigned long __must_check
18350+copy_to_user(void __user *to, const void *from, unsigned long n)
18351 {
18352- int sz = __compiletime_object_size(to);
18353+ size_t sz = __compiletime_object_size(from);
18354
18355- if (likely(sz == -1 || sz >= n))
18356- n = _copy_from_user(to, from, n);
18357- else
18358+ if (unlikely(sz != (size_t)-1 && sz < n))
18359+ copy_to_user_overflow();
18360+ else if (access_ok(VERIFY_WRITE, to, n))
18361+ n = __copy_to_user(to, from, n);
18362+ return n;
18363+}
18364+
18365+/**
18366+ * copy_from_user: - Copy a block of data from user space.
18367+ * @to: Destination address, in kernel space.
18368+ * @from: Source address, in user space.
18369+ * @n: Number of bytes to copy.
18370+ *
18371+ * Context: User context only. This function may sleep.
18372+ *
18373+ * Copy data from user space to kernel space.
18374+ *
18375+ * Returns number of bytes that could not be copied.
18376+ * On success, this will be zero.
18377+ *
18378+ * If some data could not be copied, this function will pad the copied
18379+ * data to the requested size using zero bytes.
18380+ */
18381+static inline unsigned long __must_check
18382+copy_from_user(void *to, const void __user *from, unsigned long n)
18383+{
18384+ size_t sz = __compiletime_object_size(to);
18385+
18386+ check_object_size(to, n, false);
18387+
18388+ if (unlikely(sz != (size_t)-1 && sz < n))
18389 copy_from_user_overflow();
18390-
18391+ else if (access_ok(VERIFY_READ, from, n))
18392+ n = __copy_from_user(to, from, n);
18393+ else if ((long)n > 0)
18394+ memset(to, 0, n);
18395 return n;
18396 }
18397
18398diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18399index 4f7923d..20cb24e 100644
18400--- a/arch/x86/include/asm/uaccess_64.h
18401+++ b/arch/x86/include/asm/uaccess_64.h
18402@@ -10,6 +10,9 @@
18403 #include <asm/alternative.h>
18404 #include <asm/cpufeature.h>
18405 #include <asm/page.h>
18406+#include <asm/pgtable.h>
18407+
18408+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18409
18410 /*
18411 * Copy To/From Userspace
18412@@ -17,13 +20,13 @@
18413
18414 /* Handles exceptions in both to and from, but doesn't do access_ok */
18415 __must_check unsigned long
18416-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18417+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18418 __must_check unsigned long
18419-copy_user_generic_string(void *to, const void *from, unsigned len);
18420+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18421 __must_check unsigned long
18422-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18423+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18424
18425-static __always_inline __must_check unsigned long
18426+static __always_inline __must_check __size_overflow(3) unsigned long
18427 copy_user_generic(void *to, const void *from, unsigned len)
18428 {
18429 unsigned ret;
18430@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18431 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18432 "=d" (len)),
18433 "1" (to), "2" (from), "3" (len)
18434- : "memory", "rcx", "r8", "r9", "r10", "r11");
18435+ : "memory", "rcx", "r8", "r9", "r11");
18436 return ret;
18437 }
18438
18439+static __always_inline __must_check unsigned long
18440+__copy_to_user(void __user *to, const void *from, unsigned long len);
18441+static __always_inline __must_check unsigned long
18442+__copy_from_user(void *to, const void __user *from, unsigned long len);
18443 __must_check unsigned long
18444-_copy_to_user(void __user *to, const void *from, unsigned len);
18445-__must_check unsigned long
18446-_copy_from_user(void *to, const void __user *from, unsigned len);
18447-__must_check unsigned long
18448-copy_in_user(void __user *to, const void __user *from, unsigned len);
18449+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18450+
18451+extern void copy_to_user_overflow(void)
18452+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18453+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18454+#else
18455+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18456+#endif
18457+;
18458+
18459+extern void copy_from_user_overflow(void)
18460+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18461+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18462+#else
18463+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18464+#endif
18465+;
18466
18467 static inline unsigned long __must_check copy_from_user(void *to,
18468 const void __user *from,
18469 unsigned long n)
18470 {
18471- int sz = __compiletime_object_size(to);
18472-
18473 might_fault();
18474- if (likely(sz == -1 || sz >= n))
18475- n = _copy_from_user(to, from, n);
18476-#ifdef CONFIG_DEBUG_VM
18477- else
18478- WARN(1, "Buffer overflow detected!\n");
18479-#endif
18480+
18481+ check_object_size(to, n, false);
18482+
18483+ if (access_ok(VERIFY_READ, from, n))
18484+ n = __copy_from_user(to, from, n);
18485+ else if (n < INT_MAX)
18486+ memset(to, 0, n);
18487 return n;
18488 }
18489
18490 static __always_inline __must_check
18491-int copy_to_user(void __user *dst, const void *src, unsigned size)
18492+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18493 {
18494 might_fault();
18495
18496- return _copy_to_user(dst, src, size);
18497+ if (access_ok(VERIFY_WRITE, dst, size))
18498+ size = __copy_to_user(dst, src, size);
18499+ return size;
18500 }
18501
18502 static __always_inline __must_check
18503-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18504+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18505 {
18506- int ret = 0;
18507+ size_t sz = __compiletime_object_size(dst);
18508+ unsigned ret = 0;
18509
18510 might_fault();
18511+
18512+ if (size > INT_MAX)
18513+ return size;
18514+
18515+ check_object_size(dst, size, false);
18516+
18517+#ifdef CONFIG_PAX_MEMORY_UDEREF
18518+ if (!__access_ok(VERIFY_READ, src, size))
18519+ return size;
18520+#endif
18521+
18522+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18523+ copy_from_user_overflow();
18524+ return size;
18525+ }
18526+
18527 if (!__builtin_constant_p(size))
18528- return copy_user_generic(dst, (__force void *)src, size);
18529+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18530 switch (size) {
18531- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18532+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18533 ret, "b", "b", "=q", 1);
18534 return ret;
18535- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18536+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18537 ret, "w", "w", "=r", 2);
18538 return ret;
18539- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18540+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18541 ret, "l", "k", "=r", 4);
18542 return ret;
18543- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18544+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18545 ret, "q", "", "=r", 8);
18546 return ret;
18547 case 10:
18548- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18549+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18550 ret, "q", "", "=r", 10);
18551 if (unlikely(ret))
18552 return ret;
18553 __get_user_asm(*(u16 *)(8 + (char *)dst),
18554- (u16 __user *)(8 + (char __user *)src),
18555+ (const u16 __user *)(8 + (const char __user *)src),
18556 ret, "w", "w", "=r", 2);
18557 return ret;
18558 case 16:
18559- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18560+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18561 ret, "q", "", "=r", 16);
18562 if (unlikely(ret))
18563 return ret;
18564 __get_user_asm(*(u64 *)(8 + (char *)dst),
18565- (u64 __user *)(8 + (char __user *)src),
18566+ (const u64 __user *)(8 + (const char __user *)src),
18567 ret, "q", "", "=r", 8);
18568 return ret;
18569 default:
18570- return copy_user_generic(dst, (__force void *)src, size);
18571+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18572 }
18573 }
18574
18575 static __always_inline __must_check
18576-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18577+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18578 {
18579- int ret = 0;
18580+ size_t sz = __compiletime_object_size(src);
18581+ unsigned ret = 0;
18582
18583 might_fault();
18584+
18585+ if (size > INT_MAX)
18586+ return size;
18587+
18588+ check_object_size(src, size, true);
18589+
18590+#ifdef CONFIG_PAX_MEMORY_UDEREF
18591+ if (!__access_ok(VERIFY_WRITE, dst, size))
18592+ return size;
18593+#endif
18594+
18595+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18596+ copy_to_user_overflow();
18597+ return size;
18598+ }
18599+
18600 if (!__builtin_constant_p(size))
18601- return copy_user_generic((__force void *)dst, src, size);
18602+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18603 switch (size) {
18604- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18605+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18606 ret, "b", "b", "iq", 1);
18607 return ret;
18608- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18609+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18610 ret, "w", "w", "ir", 2);
18611 return ret;
18612- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18613+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18614 ret, "l", "k", "ir", 4);
18615 return ret;
18616- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18617+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18618 ret, "q", "", "er", 8);
18619 return ret;
18620 case 10:
18621- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18622+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18623 ret, "q", "", "er", 10);
18624 if (unlikely(ret))
18625 return ret;
18626 asm("":::"memory");
18627- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18628+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18629 ret, "w", "w", "ir", 2);
18630 return ret;
18631 case 16:
18632- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18633+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18634 ret, "q", "", "er", 16);
18635 if (unlikely(ret))
18636 return ret;
18637 asm("":::"memory");
18638- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18639+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18640 ret, "q", "", "er", 8);
18641 return ret;
18642 default:
18643- return copy_user_generic((__force void *)dst, src, size);
18644+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18645 }
18646 }
18647
18648 static __always_inline __must_check
18649-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18650+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18651 {
18652- int ret = 0;
18653+ unsigned ret = 0;
18654
18655 might_fault();
18656+
18657+ if (size > INT_MAX)
18658+ return size;
18659+
18660+#ifdef CONFIG_PAX_MEMORY_UDEREF
18661+ if (!__access_ok(VERIFY_READ, src, size))
18662+ return size;
18663+ if (!__access_ok(VERIFY_WRITE, dst, size))
18664+ return size;
18665+#endif
18666+
18667 if (!__builtin_constant_p(size))
18668- return copy_user_generic((__force void *)dst,
18669- (__force void *)src, size);
18670+ return copy_user_generic((__force_kernel void *)____m(dst),
18671+ (__force_kernel const void *)____m(src), size);
18672 switch (size) {
18673 case 1: {
18674 u8 tmp;
18675- __get_user_asm(tmp, (u8 __user *)src,
18676+ __get_user_asm(tmp, (const u8 __user *)src,
18677 ret, "b", "b", "=q", 1);
18678 if (likely(!ret))
18679 __put_user_asm(tmp, (u8 __user *)dst,
18680@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18681 }
18682 case 2: {
18683 u16 tmp;
18684- __get_user_asm(tmp, (u16 __user *)src,
18685+ __get_user_asm(tmp, (const u16 __user *)src,
18686 ret, "w", "w", "=r", 2);
18687 if (likely(!ret))
18688 __put_user_asm(tmp, (u16 __user *)dst,
18689@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18690
18691 case 4: {
18692 u32 tmp;
18693- __get_user_asm(tmp, (u32 __user *)src,
18694+ __get_user_asm(tmp, (const u32 __user *)src,
18695 ret, "l", "k", "=r", 4);
18696 if (likely(!ret))
18697 __put_user_asm(tmp, (u32 __user *)dst,
18698@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18699 }
18700 case 8: {
18701 u64 tmp;
18702- __get_user_asm(tmp, (u64 __user *)src,
18703+ __get_user_asm(tmp, (const u64 __user *)src,
18704 ret, "q", "", "=r", 8);
18705 if (likely(!ret))
18706 __put_user_asm(tmp, (u64 __user *)dst,
18707@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18708 return ret;
18709 }
18710 default:
18711- return copy_user_generic((__force void *)dst,
18712- (__force void *)src, size);
18713+ return copy_user_generic((__force_kernel void *)____m(dst),
18714+ (__force_kernel const void *)____m(src), size);
18715 }
18716 }
18717
18718-static __must_check __always_inline int
18719-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18720+static __must_check __always_inline unsigned long
18721+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18722 {
18723- return copy_user_generic(dst, (__force const void *)src, size);
18724+ if (size > INT_MAX)
18725+ return size;
18726+
18727+#ifdef CONFIG_PAX_MEMORY_UDEREF
18728+ if (!__access_ok(VERIFY_READ, src, size))
18729+ return size;
18730+#endif
18731+
18732+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18733 }
18734
18735-static __must_check __always_inline int
18736-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18737+static __must_check __always_inline unsigned long
18738+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18739 {
18740- return copy_user_generic((__force void *)dst, src, size);
18741+ if (size > INT_MAX)
18742+ return size;
18743+
18744+#ifdef CONFIG_PAX_MEMORY_UDEREF
18745+ if (!__access_ok(VERIFY_WRITE, dst, size))
18746+ return size;
18747+#endif
18748+
18749+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18750 }
18751
18752-extern long __copy_user_nocache(void *dst, const void __user *src,
18753- unsigned size, int zerorest);
18754+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18755+ unsigned long size, int zerorest) __size_overflow(3);
18756
18757-static inline int
18758-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18759+static inline unsigned long
18760+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18761 {
18762 might_fault();
18763+
18764+ if (size > INT_MAX)
18765+ return size;
18766+
18767+#ifdef CONFIG_PAX_MEMORY_UDEREF
18768+ if (!__access_ok(VERIFY_READ, src, size))
18769+ return size;
18770+#endif
18771+
18772 return __copy_user_nocache(dst, src, size, 1);
18773 }
18774
18775-static inline int
18776+static inline unsigned long
18777 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18778- unsigned size)
18779+ unsigned long size)
18780 {
18781+ if (size > INT_MAX)
18782+ return size;
18783+
18784+#ifdef CONFIG_PAX_MEMORY_UDEREF
18785+ if (!__access_ok(VERIFY_READ, src, size))
18786+ return size;
18787+#endif
18788+
18789 return __copy_user_nocache(dst, src, size, 0);
18790 }
18791
18792 unsigned long
18793-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18794+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18795
18796 #endif /* _ASM_X86_UACCESS_64_H */
18797diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18798index 5b238981..77fdd78 100644
18799--- a/arch/x86/include/asm/word-at-a-time.h
18800+++ b/arch/x86/include/asm/word-at-a-time.h
18801@@ -11,7 +11,7 @@
18802 * and shift, for example.
18803 */
18804 struct word_at_a_time {
18805- const unsigned long one_bits, high_bits;
18806+ unsigned long one_bits, high_bits;
18807 };
18808
18809 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18810diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18811index 828a156..650e625 100644
18812--- a/arch/x86/include/asm/x86_init.h
18813+++ b/arch/x86/include/asm/x86_init.h
18814@@ -129,7 +129,7 @@ struct x86_init_ops {
18815 struct x86_init_timers timers;
18816 struct x86_init_iommu iommu;
18817 struct x86_init_pci pci;
18818-};
18819+} __no_const;
18820
18821 /**
18822 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18823@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18824 void (*setup_percpu_clockev)(void);
18825 void (*early_percpu_clock_init)(void);
18826 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18827-};
18828+} __no_const;
18829
18830 struct timespec;
18831
18832@@ -168,7 +168,7 @@ struct x86_platform_ops {
18833 void (*save_sched_clock_state)(void);
18834 void (*restore_sched_clock_state)(void);
18835 void (*apic_post_init)(void);
18836-};
18837+} __no_const;
18838
18839 struct pci_dev;
18840 struct msi_msg;
18841@@ -182,7 +182,7 @@ struct x86_msi_ops {
18842 void (*teardown_msi_irqs)(struct pci_dev *dev);
18843 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18844 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18845-};
18846+} __no_const;
18847
18848 struct IO_APIC_route_entry;
18849 struct io_apic_irq_attr;
18850@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18851 unsigned int destination, int vector,
18852 struct io_apic_irq_attr *attr);
18853 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18854-};
18855+} __no_const;
18856
18857 extern struct x86_init_ops x86_init;
18858 extern struct x86_cpuinit_ops x86_cpuinit;
18859diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18860index 0415cda..3b22adc 100644
18861--- a/arch/x86/include/asm/xsave.h
18862+++ b/arch/x86/include/asm/xsave.h
18863@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18864 if (unlikely(err))
18865 return -EFAULT;
18866
18867+ pax_open_userland();
18868 __asm__ __volatile__(ASM_STAC "\n"
18869- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18870+ "1:"
18871+ __copyuser_seg
18872+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18873 "2: " ASM_CLAC "\n"
18874 ".section .fixup,\"ax\"\n"
18875 "3: movl $-1,%[err]\n"
18876@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18877 : [err] "=r" (err)
18878 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18879 : "memory");
18880+ pax_close_userland();
18881 return err;
18882 }
18883
18884 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18885 {
18886 int err;
18887- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18888+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18889 u32 lmask = mask;
18890 u32 hmask = mask >> 32;
18891
18892+ pax_open_userland();
18893 __asm__ __volatile__(ASM_STAC "\n"
18894- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18895+ "1:"
18896+ __copyuser_seg
18897+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18898 "2: " ASM_CLAC "\n"
18899 ".section .fixup,\"ax\"\n"
18900 "3: movl $-1,%[err]\n"
18901@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18902 : [err] "=r" (err)
18903 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18904 : "memory"); /* memory required? */
18905+ pax_close_userland();
18906 return err;
18907 }
18908
18909diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18910index bbae024..e1528f9 100644
18911--- a/arch/x86/include/uapi/asm/e820.h
18912+++ b/arch/x86/include/uapi/asm/e820.h
18913@@ -63,7 +63,7 @@ struct e820map {
18914 #define ISA_START_ADDRESS 0xa0000
18915 #define ISA_END_ADDRESS 0x100000
18916
18917-#define BIOS_BEGIN 0x000a0000
18918+#define BIOS_BEGIN 0x000c0000
18919 #define BIOS_END 0x00100000
18920
18921 #define BIOS_ROM_BASE 0xffe00000
18922diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18923index 88d99ea..9fc7e17 100644
18924--- a/arch/x86/kernel/Makefile
18925+++ b/arch/x86/kernel/Makefile
18926@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18927 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18928 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18929 obj-y += probe_roms.o
18930-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18931+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18932 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18933 obj-y += syscall_$(BITS).o
18934 obj-$(CONFIG_X86_64) += vsyscall_64.o
18935diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18936index 2627a81..cd8325e 100644
18937--- a/arch/x86/kernel/acpi/boot.c
18938+++ b/arch/x86/kernel/acpi/boot.c
18939@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18940 * If your system is blacklisted here, but you find that acpi=force
18941 * works for you, please contact linux-acpi@vger.kernel.org
18942 */
18943-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18944+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18945 /*
18946 * Boxes that need ACPI disabled
18947 */
18948@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18949 };
18950
18951 /* second table for DMI checks that should run after early-quirks */
18952-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18953+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18954 /*
18955 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18956 * which includes some code which overrides all temperature
18957diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18958index 3312010..a65ca7b 100644
18959--- a/arch/x86/kernel/acpi/sleep.c
18960+++ b/arch/x86/kernel/acpi/sleep.c
18961@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18962 #else /* CONFIG_64BIT */
18963 #ifdef CONFIG_SMP
18964 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18965+
18966+ pax_open_kernel();
18967 early_gdt_descr.address =
18968 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18969+ pax_close_kernel();
18970+
18971 initial_gs = per_cpu_offset(smp_processor_id());
18972 #endif
18973 initial_code = (unsigned long)wakeup_long64;
18974diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18975index d1daa66..59fecba 100644
18976--- a/arch/x86/kernel/acpi/wakeup_32.S
18977+++ b/arch/x86/kernel/acpi/wakeup_32.S
18978@@ -29,13 +29,11 @@ wakeup_pmode_return:
18979 # and restore the stack ... but you need gdt for this to work
18980 movl saved_context_esp, %esp
18981
18982- movl %cs:saved_magic, %eax
18983- cmpl $0x12345678, %eax
18984+ cmpl $0x12345678, saved_magic
18985 jne bogus_magic
18986
18987 # jump to place where we left off
18988- movl saved_eip, %eax
18989- jmp *%eax
18990+ jmp *(saved_eip)
18991
18992 bogus_magic:
18993 jmp bogus_magic
18994diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18995index c15cf9a..0e63558 100644
18996--- a/arch/x86/kernel/alternative.c
18997+++ b/arch/x86/kernel/alternative.c
18998@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18999 */
19000 for (a = start; a < end; a++) {
19001 instr = (u8 *)&a->instr_offset + a->instr_offset;
19002+
19003+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19004+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19005+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19006+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19007+#endif
19008+
19009 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19010 BUG_ON(a->replacementlen > a->instrlen);
19011 BUG_ON(a->instrlen > sizeof(insnbuf));
19012@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19013 for (poff = start; poff < end; poff++) {
19014 u8 *ptr = (u8 *)poff + *poff;
19015
19016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19017+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19018+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19019+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19020+#endif
19021+
19022 if (!*poff || ptr < text || ptr >= text_end)
19023 continue;
19024 /* turn DS segment override prefix into lock prefix */
19025- if (*ptr == 0x3e)
19026+ if (*ktla_ktva(ptr) == 0x3e)
19027 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19028 }
19029 mutex_unlock(&text_mutex);
19030@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19031 for (poff = start; poff < end; poff++) {
19032 u8 *ptr = (u8 *)poff + *poff;
19033
19034+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19035+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19036+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19037+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19038+#endif
19039+
19040 if (!*poff || ptr < text || ptr >= text_end)
19041 continue;
19042 /* turn lock prefix into DS segment override prefix */
19043- if (*ptr == 0xf0)
19044+ if (*ktla_ktva(ptr) == 0xf0)
19045 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19046 }
19047 mutex_unlock(&text_mutex);
19048@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19049
19050 BUG_ON(p->len > MAX_PATCH_LEN);
19051 /* prep the buffer with the original instructions */
19052- memcpy(insnbuf, p->instr, p->len);
19053+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19054 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19055 (unsigned long)p->instr, p->len);
19056
19057@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19058 if (!uniproc_patched || num_possible_cpus() == 1)
19059 free_init_pages("SMP alternatives",
19060 (unsigned long)__smp_locks,
19061- (unsigned long)__smp_locks_end);
19062+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19063 #endif
19064
19065 apply_paravirt(__parainstructions, __parainstructions_end);
19066@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19067 * instructions. And on the local CPU you need to be protected again NMI or MCE
19068 * handlers seeing an inconsistent instruction while you patch.
19069 */
19070-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19071+void *__kprobes text_poke_early(void *addr, const void *opcode,
19072 size_t len)
19073 {
19074 unsigned long flags;
19075 local_irq_save(flags);
19076- memcpy(addr, opcode, len);
19077+
19078+ pax_open_kernel();
19079+ memcpy(ktla_ktva(addr), opcode, len);
19080 sync_core();
19081+ pax_close_kernel();
19082+
19083 local_irq_restore(flags);
19084 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19085 that causes hangs on some VIA CPUs. */
19086@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19087 */
19088 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19089 {
19090- unsigned long flags;
19091- char *vaddr;
19092+ unsigned char *vaddr = ktla_ktva(addr);
19093 struct page *pages[2];
19094- int i;
19095+ size_t i;
19096
19097 if (!core_kernel_text((unsigned long)addr)) {
19098- pages[0] = vmalloc_to_page(addr);
19099- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19100+ pages[0] = vmalloc_to_page(vaddr);
19101+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19102 } else {
19103- pages[0] = virt_to_page(addr);
19104+ pages[0] = virt_to_page(vaddr);
19105 WARN_ON(!PageReserved(pages[0]));
19106- pages[1] = virt_to_page(addr + PAGE_SIZE);
19107+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19108 }
19109 BUG_ON(!pages[0]);
19110- local_irq_save(flags);
19111- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19112- if (pages[1])
19113- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19114- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19115- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19116- clear_fixmap(FIX_TEXT_POKE0);
19117- if (pages[1])
19118- clear_fixmap(FIX_TEXT_POKE1);
19119- local_flush_tlb();
19120- sync_core();
19121- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19122- that causes hangs on some VIA CPUs. */
19123+ text_poke_early(addr, opcode, len);
19124 for (i = 0; i < len; i++)
19125- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19126- local_irq_restore(flags);
19127+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19128 return addr;
19129 }
19130
19131diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19132index eca89c5..d566b78 100644
19133--- a/arch/x86/kernel/apic/apic.c
19134+++ b/arch/x86/kernel/apic/apic.c
19135@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19136 /*
19137 * Debug level, exported for io_apic.c
19138 */
19139-unsigned int apic_verbosity;
19140+int apic_verbosity;
19141
19142 int pic_mode;
19143
19144@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19145 apic_write(APIC_ESR, 0);
19146 v1 = apic_read(APIC_ESR);
19147 ack_APIC_irq();
19148- atomic_inc(&irq_err_count);
19149+ atomic_inc_unchecked(&irq_err_count);
19150
19151 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19152 smp_processor_id(), v0 , v1);
19153diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19154index 00c77cf..2dc6a2d 100644
19155--- a/arch/x86/kernel/apic/apic_flat_64.c
19156+++ b/arch/x86/kernel/apic/apic_flat_64.c
19157@@ -157,7 +157,7 @@ static int flat_probe(void)
19158 return 1;
19159 }
19160
19161-static struct apic apic_flat = {
19162+static struct apic apic_flat __read_only = {
19163 .name = "flat",
19164 .probe = flat_probe,
19165 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19166@@ -271,7 +271,7 @@ static int physflat_probe(void)
19167 return 0;
19168 }
19169
19170-static struct apic apic_physflat = {
19171+static struct apic apic_physflat __read_only = {
19172
19173 .name = "physical flat",
19174 .probe = physflat_probe,
19175diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19176index e145f28..2752888 100644
19177--- a/arch/x86/kernel/apic/apic_noop.c
19178+++ b/arch/x86/kernel/apic/apic_noop.c
19179@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19180 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19181 }
19182
19183-struct apic apic_noop = {
19184+struct apic apic_noop __read_only = {
19185 .name = "noop",
19186 .probe = noop_probe,
19187 .acpi_madt_oem_check = NULL,
19188diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19189index d50e364..543bee3 100644
19190--- a/arch/x86/kernel/apic/bigsmp_32.c
19191+++ b/arch/x86/kernel/apic/bigsmp_32.c
19192@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19193 return dmi_bigsmp;
19194 }
19195
19196-static struct apic apic_bigsmp = {
19197+static struct apic apic_bigsmp __read_only = {
19198
19199 .name = "bigsmp",
19200 .probe = probe_bigsmp,
19201diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19202index c552247..587a316 100644
19203--- a/arch/x86/kernel/apic/es7000_32.c
19204+++ b/arch/x86/kernel/apic/es7000_32.c
19205@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19206 return ret && es7000_apic_is_cluster();
19207 }
19208
19209-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19210-static struct apic __refdata apic_es7000_cluster = {
19211+static struct apic apic_es7000_cluster __read_only = {
19212
19213 .name = "es7000",
19214 .probe = probe_es7000,
19215@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19216 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19217 };
19218
19219-static struct apic __refdata apic_es7000 = {
19220+static struct apic apic_es7000 __read_only = {
19221
19222 .name = "es7000",
19223 .probe = probe_es7000,
19224diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19225index 9ed796c..e930fe4 100644
19226--- a/arch/x86/kernel/apic/io_apic.c
19227+++ b/arch/x86/kernel/apic/io_apic.c
19228@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19229 }
19230 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19231
19232-void lock_vector_lock(void)
19233+void lock_vector_lock(void) __acquires(vector_lock)
19234 {
19235 /* Used to the online set of cpus does not change
19236 * during assign_irq_vector.
19237@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19238 raw_spin_lock(&vector_lock);
19239 }
19240
19241-void unlock_vector_lock(void)
19242+void unlock_vector_lock(void) __releases(vector_lock)
19243 {
19244 raw_spin_unlock(&vector_lock);
19245 }
19246@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19247 ack_APIC_irq();
19248 }
19249
19250-atomic_t irq_mis_count;
19251+atomic_unchecked_t irq_mis_count;
19252
19253 #ifdef CONFIG_GENERIC_PENDING_IRQ
19254 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19255@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19256 * at the cpu.
19257 */
19258 if (!(v & (1 << (i & 0x1f)))) {
19259- atomic_inc(&irq_mis_count);
19260+ atomic_inc_unchecked(&irq_mis_count);
19261
19262 eoi_ioapic_irq(irq, cfg);
19263 }
19264diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19265index 1e42e8f..daacf44 100644
19266--- a/arch/x86/kernel/apic/numaq_32.c
19267+++ b/arch/x86/kernel/apic/numaq_32.c
19268@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19269 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19270 }
19271
19272-/* Use __refdata to keep false positive warning calm. */
19273-static struct apic __refdata apic_numaq = {
19274+static struct apic apic_numaq __read_only = {
19275
19276 .name = "NUMAQ",
19277 .probe = probe_numaq,
19278diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19279index eb35ef9..f184a21 100644
19280--- a/arch/x86/kernel/apic/probe_32.c
19281+++ b/arch/x86/kernel/apic/probe_32.c
19282@@ -72,7 +72,7 @@ static int probe_default(void)
19283 return 1;
19284 }
19285
19286-static struct apic apic_default = {
19287+static struct apic apic_default __read_only = {
19288
19289 .name = "default",
19290 .probe = probe_default,
19291diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19292index 77c95c0..434f8a4 100644
19293--- a/arch/x86/kernel/apic/summit_32.c
19294+++ b/arch/x86/kernel/apic/summit_32.c
19295@@ -486,7 +486,7 @@ void setup_summit(void)
19296 }
19297 #endif
19298
19299-static struct apic apic_summit = {
19300+static struct apic apic_summit __read_only = {
19301
19302 .name = "summit",
19303 .probe = probe_summit,
19304diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19305index 140e29d..d88bc95 100644
19306--- a/arch/x86/kernel/apic/x2apic_cluster.c
19307+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19308@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19309 return notifier_from_errno(err);
19310 }
19311
19312-static struct notifier_block __refdata x2apic_cpu_notifier = {
19313+static struct notifier_block x2apic_cpu_notifier = {
19314 .notifier_call = update_clusterinfo,
19315 };
19316
19317@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19318 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19319 }
19320
19321-static struct apic apic_x2apic_cluster = {
19322+static struct apic apic_x2apic_cluster __read_only = {
19323
19324 .name = "cluster x2apic",
19325 .probe = x2apic_cluster_probe,
19326diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19327index 562a76d..a003c0f 100644
19328--- a/arch/x86/kernel/apic/x2apic_phys.c
19329+++ b/arch/x86/kernel/apic/x2apic_phys.c
19330@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19331 return apic == &apic_x2apic_phys;
19332 }
19333
19334-static struct apic apic_x2apic_phys = {
19335+static struct apic apic_x2apic_phys __read_only = {
19336
19337 .name = "physical x2apic",
19338 .probe = x2apic_phys_probe,
19339diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19340index 1191ac1..2335fa4 100644
19341--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19342+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19343@@ -357,7 +357,7 @@ static int uv_probe(void)
19344 return apic == &apic_x2apic_uv_x;
19345 }
19346
19347-static struct apic __refdata apic_x2apic_uv_x = {
19348+static struct apic apic_x2apic_uv_x __read_only = {
19349
19350 .name = "UV large system",
19351 .probe = uv_probe,
19352diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19353index 53a4e27..038760a 100644
19354--- a/arch/x86/kernel/apm_32.c
19355+++ b/arch/x86/kernel/apm_32.c
19356@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19357 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19358 * even though they are called in protected mode.
19359 */
19360-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19361+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19362 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19363
19364 static const char driver_version[] = "1.16ac"; /* no spaces */
19365@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19366 BUG_ON(cpu != 0);
19367 gdt = get_cpu_gdt_table(cpu);
19368 save_desc_40 = gdt[0x40 / 8];
19369+
19370+ pax_open_kernel();
19371 gdt[0x40 / 8] = bad_bios_desc;
19372+ pax_close_kernel();
19373
19374 apm_irq_save(flags);
19375 APM_DO_SAVE_SEGS;
19376@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19377 &call->esi);
19378 APM_DO_RESTORE_SEGS;
19379 apm_irq_restore(flags);
19380+
19381+ pax_open_kernel();
19382 gdt[0x40 / 8] = save_desc_40;
19383+ pax_close_kernel();
19384+
19385 put_cpu();
19386
19387 return call->eax & 0xff;
19388@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19389 BUG_ON(cpu != 0);
19390 gdt = get_cpu_gdt_table(cpu);
19391 save_desc_40 = gdt[0x40 / 8];
19392+
19393+ pax_open_kernel();
19394 gdt[0x40 / 8] = bad_bios_desc;
19395+ pax_close_kernel();
19396
19397 apm_irq_save(flags);
19398 APM_DO_SAVE_SEGS;
19399@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19400 &call->eax);
19401 APM_DO_RESTORE_SEGS;
19402 apm_irq_restore(flags);
19403+
19404+ pax_open_kernel();
19405 gdt[0x40 / 8] = save_desc_40;
19406+ pax_close_kernel();
19407+
19408 put_cpu();
19409 return error;
19410 }
19411@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19412 * code to that CPU.
19413 */
19414 gdt = get_cpu_gdt_table(0);
19415+
19416+ pax_open_kernel();
19417 set_desc_base(&gdt[APM_CS >> 3],
19418 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19419 set_desc_base(&gdt[APM_CS_16 >> 3],
19420 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19421 set_desc_base(&gdt[APM_DS >> 3],
19422 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19423+ pax_close_kernel();
19424
19425 proc_create("apm", 0, NULL, &apm_file_ops);
19426
19427diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19428index 2861082..6d4718e 100644
19429--- a/arch/x86/kernel/asm-offsets.c
19430+++ b/arch/x86/kernel/asm-offsets.c
19431@@ -33,6 +33,8 @@ void common(void) {
19432 OFFSET(TI_status, thread_info, status);
19433 OFFSET(TI_addr_limit, thread_info, addr_limit);
19434 OFFSET(TI_preempt_count, thread_info, preempt_count);
19435+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19436+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19437
19438 BLANK();
19439 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19440@@ -53,8 +55,26 @@ void common(void) {
19441 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19442 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19443 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19444+
19445+#ifdef CONFIG_PAX_KERNEXEC
19446+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19447 #endif
19448
19449+#ifdef CONFIG_PAX_MEMORY_UDEREF
19450+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19451+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19452+#ifdef CONFIG_X86_64
19453+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19454+#endif
19455+#endif
19456+
19457+#endif
19458+
19459+ BLANK();
19460+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19461+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19462+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19463+
19464 #ifdef CONFIG_XEN
19465 BLANK();
19466 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19467diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19468index e7c798b..2b2019b 100644
19469--- a/arch/x86/kernel/asm-offsets_64.c
19470+++ b/arch/x86/kernel/asm-offsets_64.c
19471@@ -77,6 +77,7 @@ int main(void)
19472 BLANK();
19473 #undef ENTRY
19474
19475+ DEFINE(TSS_size, sizeof(struct tss_struct));
19476 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19477 BLANK();
19478
19479diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19480index 47b56a7..efc2bc6 100644
19481--- a/arch/x86/kernel/cpu/Makefile
19482+++ b/arch/x86/kernel/cpu/Makefile
19483@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19484 CFLAGS_REMOVE_perf_event.o = -pg
19485 endif
19486
19487-# Make sure load_percpu_segment has no stackprotector
19488-nostackp := $(call cc-option, -fno-stack-protector)
19489-CFLAGS_common.o := $(nostackp)
19490-
19491 obj-y := intel_cacheinfo.o scattered.o topology.o
19492 obj-y += proc.o capflags.o powerflags.o common.o
19493 obj-y += rdrand.o
19494diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19495index 08a0890..e557865 100644
19496--- a/arch/x86/kernel/cpu/amd.c
19497+++ b/arch/x86/kernel/cpu/amd.c
19498@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19499 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19500 {
19501 /* AMD errata T13 (order #21922) */
19502- if ((c->x86 == 6)) {
19503+ if (c->x86 == 6) {
19504 /* Duron Rev A0 */
19505 if (c->x86_model == 3 && c->x86_mask == 0)
19506 size = 64;
19507diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19508index 25eb274..3a92d93 100644
19509--- a/arch/x86/kernel/cpu/common.c
19510+++ b/arch/x86/kernel/cpu/common.c
19511@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19512
19513 static const struct cpu_dev *this_cpu = &default_cpu;
19514
19515-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19516-#ifdef CONFIG_X86_64
19517- /*
19518- * We need valid kernel segments for data and code in long mode too
19519- * IRET will check the segment types kkeil 2000/10/28
19520- * Also sysret mandates a special GDT layout
19521- *
19522- * TLS descriptors are currently at a different place compared to i386.
19523- * Hopefully nobody expects them at a fixed place (Wine?)
19524- */
19525- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19526- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19527- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19528- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19529- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19530- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19531-#else
19532- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19533- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19534- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19535- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19536- /*
19537- * Segments used for calling PnP BIOS have byte granularity.
19538- * They code segments and data segments have fixed 64k limits,
19539- * the transfer segment sizes are set at run time.
19540- */
19541- /* 32-bit code */
19542- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19543- /* 16-bit code */
19544- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19545- /* 16-bit data */
19546- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19547- /* 16-bit data */
19548- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19549- /* 16-bit data */
19550- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19551- /*
19552- * The APM segments have byte granularity and their bases
19553- * are set at run time. All have 64k limits.
19554- */
19555- /* 32-bit code */
19556- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19557- /* 16-bit code */
19558- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19559- /* data */
19560- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19561-
19562- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19563- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19564- GDT_STACK_CANARY_INIT
19565-#endif
19566-} };
19567-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19568-
19569 static int __init x86_xsave_setup(char *s)
19570 {
19571 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19572@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19573 set_in_cr4(X86_CR4_SMAP);
19574 }
19575
19576+#ifdef CONFIG_X86_64
19577+static __init int setup_disable_pcid(char *arg)
19578+{
19579+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19580+
19581+#ifdef CONFIG_PAX_MEMORY_UDEREF
19582+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19583+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19584+#endif
19585+
19586+ return 1;
19587+}
19588+__setup("nopcid", setup_disable_pcid);
19589+
19590+static void setup_pcid(struct cpuinfo_x86 *c)
19591+{
19592+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19593+
19594+#ifdef CONFIG_PAX_MEMORY_UDEREF
19595+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19596+ pax_open_kernel();
19597+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19598+ pax_close_kernel();
19599+ printk("PAX: slow and weak UDEREF enabled\n");
19600+ } else
19601+ printk("PAX: UDEREF disabled\n");
19602+#endif
19603+
19604+ return;
19605+ }
19606+
19607+ printk("PAX: PCID detected\n");
19608+ set_in_cr4(X86_CR4_PCIDE);
19609+
19610+#ifdef CONFIG_PAX_MEMORY_UDEREF
19611+ pax_open_kernel();
19612+ clone_pgd_mask = ~(pgdval_t)0UL;
19613+ pax_close_kernel();
19614+ if (pax_user_shadow_base)
19615+ printk("PAX: weak UDEREF enabled\n");
19616+ else {
19617+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19618+ printk("PAX: strong UDEREF enabled\n");
19619+ }
19620+#endif
19621+
19622+ if (cpu_has(c, X86_FEATURE_INVPCID))
19623+ printk("PAX: INVPCID detected\n");
19624+}
19625+#endif
19626+
19627 /*
19628 * Some CPU features depend on higher CPUID levels, which may not always
19629 * be available due to CPUID level capping or broken virtualization
19630@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19631 {
19632 struct desc_ptr gdt_descr;
19633
19634- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19635+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19636 gdt_descr.size = GDT_SIZE - 1;
19637 load_gdt(&gdt_descr);
19638 /* Reload the per-cpu base */
19639@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19640 setup_smep(c);
19641 setup_smap(c);
19642
19643+#ifdef CONFIG_X86_64
19644+ setup_pcid(c);
19645+#endif
19646+
19647 /*
19648 * The vendor-specific functions might have changed features.
19649 * Now we do "generic changes."
19650@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19651 /* Filter out anything that depends on CPUID levels we don't have */
19652 filter_cpuid_features(c, true);
19653
19654+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19655+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19656+#endif
19657+
19658 /* If the model name is still unset, do table lookup. */
19659 if (!c->x86_model_id[0]) {
19660 const char *p;
19661@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19662 }
19663 __setup("clearcpuid=", setup_disablecpuid);
19664
19665+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19666+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19667+
19668 #ifdef CONFIG_X86_64
19669-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19670-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19671- (unsigned long) debug_idt_table };
19672+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19673+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19674
19675 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19676 irq_stack_union) __aligned(PAGE_SIZE);
19677@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19678 EXPORT_PER_CPU_SYMBOL(current_task);
19679
19680 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19681- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19682+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19683 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19684
19685 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19686@@ -1232,7 +1239,7 @@ void cpu_init(void)
19687 load_ucode_ap();
19688
19689 cpu = stack_smp_processor_id();
19690- t = &per_cpu(init_tss, cpu);
19691+ t = init_tss + cpu;
19692 oist = &per_cpu(orig_ist, cpu);
19693
19694 #ifdef CONFIG_NUMA
19695@@ -1267,7 +1274,6 @@ void cpu_init(void)
19696 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19697 barrier();
19698
19699- x86_configure_nx();
19700 enable_x2apic();
19701
19702 /*
19703@@ -1319,7 +1325,7 @@ void cpu_init(void)
19704 {
19705 int cpu = smp_processor_id();
19706 struct task_struct *curr = current;
19707- struct tss_struct *t = &per_cpu(init_tss, cpu);
19708+ struct tss_struct *t = init_tss + cpu;
19709 struct thread_struct *thread = &curr->thread;
19710
19711 show_ucode_info_early();
19712diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19713index 1414c90..1159406 100644
19714--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19715+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19716@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19717 };
19718
19719 #ifdef CONFIG_AMD_NB
19720+static struct attribute *default_attrs_amd_nb[] = {
19721+ &type.attr,
19722+ &level.attr,
19723+ &coherency_line_size.attr,
19724+ &physical_line_partition.attr,
19725+ &ways_of_associativity.attr,
19726+ &number_of_sets.attr,
19727+ &size.attr,
19728+ &shared_cpu_map.attr,
19729+ &shared_cpu_list.attr,
19730+ NULL,
19731+ NULL,
19732+ NULL,
19733+ NULL
19734+};
19735+
19736 static struct attribute **amd_l3_attrs(void)
19737 {
19738 static struct attribute **attrs;
19739@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19740
19741 n = ARRAY_SIZE(default_attrs);
19742
19743- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19744- n += 2;
19745-
19746- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19747- n += 1;
19748-
19749- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19750- if (attrs == NULL)
19751- return attrs = default_attrs;
19752-
19753- for (n = 0; default_attrs[n]; n++)
19754- attrs[n] = default_attrs[n];
19755+ attrs = default_attrs_amd_nb;
19756
19757 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19758 attrs[n++] = &cache_disable_0.attr;
19759@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19760 .default_attrs = default_attrs,
19761 };
19762
19763+#ifdef CONFIG_AMD_NB
19764+static struct kobj_type ktype_cache_amd_nb = {
19765+ .sysfs_ops = &sysfs_ops,
19766+ .default_attrs = default_attrs_amd_nb,
19767+};
19768+#endif
19769+
19770 static struct kobj_type ktype_percpu_entry = {
19771 .sysfs_ops = &sysfs_ops,
19772 };
19773@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19774 return retval;
19775 }
19776
19777+#ifdef CONFIG_AMD_NB
19778+ amd_l3_attrs();
19779+#endif
19780+
19781 for (i = 0; i < num_cache_leaves; i++) {
19782+ struct kobj_type *ktype;
19783+
19784 this_object = INDEX_KOBJECT_PTR(cpu, i);
19785 this_object->cpu = cpu;
19786 this_object->index = i;
19787
19788 this_leaf = CPUID4_INFO_IDX(cpu, i);
19789
19790- ktype_cache.default_attrs = default_attrs;
19791+ ktype = &ktype_cache;
19792 #ifdef CONFIG_AMD_NB
19793 if (this_leaf->base.nb)
19794- ktype_cache.default_attrs = amd_l3_attrs();
19795+ ktype = &ktype_cache_amd_nb;
19796 #endif
19797 retval = kobject_init_and_add(&(this_object->kobj),
19798- &ktype_cache,
19799+ ktype,
19800 per_cpu(ici_cache_kobject, cpu),
19801 "index%1lu", i);
19802 if (unlikely(retval)) {
19803diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19804index 87a65c9..92fcce6 100644
19805--- a/arch/x86/kernel/cpu/mcheck/mce.c
19806+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19807@@ -45,6 +45,7 @@
19808 #include <asm/processor.h>
19809 #include <asm/mce.h>
19810 #include <asm/msr.h>
19811+#include <asm/local.h>
19812
19813 #include "mce-internal.h"
19814
19815@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19816 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19817 m->cs, m->ip);
19818
19819- if (m->cs == __KERNEL_CS)
19820+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19821 print_symbol("{%s}", m->ip);
19822 pr_cont("\n");
19823 }
19824@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19825
19826 #define PANIC_TIMEOUT 5 /* 5 seconds */
19827
19828-static atomic_t mce_paniced;
19829+static atomic_unchecked_t mce_paniced;
19830
19831 static int fake_panic;
19832-static atomic_t mce_fake_paniced;
19833+static atomic_unchecked_t mce_fake_paniced;
19834
19835 /* Panic in progress. Enable interrupts and wait for final IPI */
19836 static void wait_for_panic(void)
19837@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19838 /*
19839 * Make sure only one CPU runs in machine check panic
19840 */
19841- if (atomic_inc_return(&mce_paniced) > 1)
19842+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19843 wait_for_panic();
19844 barrier();
19845
19846@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19847 console_verbose();
19848 } else {
19849 /* Don't log too much for fake panic */
19850- if (atomic_inc_return(&mce_fake_paniced) > 1)
19851+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19852 return;
19853 }
19854 /* First print corrected ones that are still unlogged */
19855@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19856 if (!fake_panic) {
19857 if (panic_timeout == 0)
19858 panic_timeout = mca_cfg.panic_timeout;
19859- panic(msg);
19860+ panic("%s", msg);
19861 } else
19862 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19863 }
19864@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19865 * might have been modified by someone else.
19866 */
19867 rmb();
19868- if (atomic_read(&mce_paniced))
19869+ if (atomic_read_unchecked(&mce_paniced))
19870 wait_for_panic();
19871 if (!mca_cfg.monarch_timeout)
19872 goto out;
19873@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19874 }
19875
19876 /* Call the installed machine check handler for this CPU setup. */
19877-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19878+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19879 unexpected_machine_check;
19880
19881 /*
19882@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19883 return;
19884 }
19885
19886+ pax_open_kernel();
19887 machine_check_vector = do_machine_check;
19888+ pax_close_kernel();
19889
19890 __mcheck_cpu_init_generic();
19891 __mcheck_cpu_init_vendor(c);
19892@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19893 */
19894
19895 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19896-static int mce_chrdev_open_count; /* #times opened */
19897+static local_t mce_chrdev_open_count; /* #times opened */
19898 static int mce_chrdev_open_exclu; /* already open exclusive? */
19899
19900 static int mce_chrdev_open(struct inode *inode, struct file *file)
19901@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19902 spin_lock(&mce_chrdev_state_lock);
19903
19904 if (mce_chrdev_open_exclu ||
19905- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19906+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19907 spin_unlock(&mce_chrdev_state_lock);
19908
19909 return -EBUSY;
19910@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19911
19912 if (file->f_flags & O_EXCL)
19913 mce_chrdev_open_exclu = 1;
19914- mce_chrdev_open_count++;
19915+ local_inc(&mce_chrdev_open_count);
19916
19917 spin_unlock(&mce_chrdev_state_lock);
19918
19919@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19920 {
19921 spin_lock(&mce_chrdev_state_lock);
19922
19923- mce_chrdev_open_count--;
19924+ local_dec(&mce_chrdev_open_count);
19925 mce_chrdev_open_exclu = 0;
19926
19927 spin_unlock(&mce_chrdev_state_lock);
19928@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19929
19930 for (i = 0; i < mca_cfg.banks; i++) {
19931 struct mce_bank *b = &mce_banks[i];
19932- struct device_attribute *a = &b->attr;
19933+ device_attribute_no_const *a = &b->attr;
19934
19935 sysfs_attr_init(&a->attr);
19936 a->attr.name = b->attrname;
19937@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19938 static void mce_reset(void)
19939 {
19940 cpu_missing = 0;
19941- atomic_set(&mce_fake_paniced, 0);
19942+ atomic_set_unchecked(&mce_fake_paniced, 0);
19943 atomic_set(&mce_executing, 0);
19944 atomic_set(&mce_callin, 0);
19945 atomic_set(&global_nwo, 0);
19946diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19947index 1c044b1..37a2a43 100644
19948--- a/arch/x86/kernel/cpu/mcheck/p5.c
19949+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19950@@ -11,6 +11,7 @@
19951 #include <asm/processor.h>
19952 #include <asm/mce.h>
19953 #include <asm/msr.h>
19954+#include <asm/pgtable.h>
19955
19956 /* By default disabled */
19957 int mce_p5_enabled __read_mostly;
19958@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19959 if (!cpu_has(c, X86_FEATURE_MCE))
19960 return;
19961
19962+ pax_open_kernel();
19963 machine_check_vector = pentium_machine_check;
19964+ pax_close_kernel();
19965 /* Make sure the vector pointer is visible before we enable MCEs: */
19966 wmb();
19967
19968diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19969index e9a701a..35317d6 100644
19970--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19971+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19972@@ -10,6 +10,7 @@
19973 #include <asm/processor.h>
19974 #include <asm/mce.h>
19975 #include <asm/msr.h>
19976+#include <asm/pgtable.h>
19977
19978 /* Machine check handler for WinChip C6: */
19979 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19980@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19981 {
19982 u32 lo, hi;
19983
19984+ pax_open_kernel();
19985 machine_check_vector = winchip_machine_check;
19986+ pax_close_kernel();
19987 /* Make sure the vector pointer is visible before we enable MCEs: */
19988 wmb();
19989
19990diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19991index f961de9..8a9d332 100644
19992--- a/arch/x86/kernel/cpu/mtrr/main.c
19993+++ b/arch/x86/kernel/cpu/mtrr/main.c
19994@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19995 u64 size_or_mask, size_and_mask;
19996 static bool mtrr_aps_delayed_init;
19997
19998-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19999+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20000
20001 const struct mtrr_ops *mtrr_if;
20002
20003diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20004index df5e41f..816c719 100644
20005--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20006+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20007@@ -25,7 +25,7 @@ struct mtrr_ops {
20008 int (*validate_add_page)(unsigned long base, unsigned long size,
20009 unsigned int type);
20010 int (*have_wrcomb)(void);
20011-};
20012+} __do_const;
20013
20014 extern int generic_get_free_region(unsigned long base, unsigned long size,
20015 int replace_reg);
20016diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20017index a7c7305..b9705ab 100644
20018--- a/arch/x86/kernel/cpu/perf_event.c
20019+++ b/arch/x86/kernel/cpu/perf_event.c
20020@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20021 pr_info("no hardware sampling interrupt available.\n");
20022 }
20023
20024-static struct attribute_group x86_pmu_format_group = {
20025+static attribute_group_no_const x86_pmu_format_group = {
20026 .name = "format",
20027 .attrs = NULL,
20028 };
20029@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20030 NULL,
20031 };
20032
20033-static struct attribute_group x86_pmu_events_group = {
20034+static attribute_group_no_const x86_pmu_events_group = {
20035 .name = "events",
20036 .attrs = events_attr,
20037 };
20038@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
20039 if (idx > GDT_ENTRIES)
20040 return 0;
20041
20042- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20043+ desc = get_cpu_gdt_table(smp_processor_id());
20044 }
20045
20046 return get_desc_base(desc + idx);
20047@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20048 break;
20049
20050 perf_callchain_store(entry, frame.return_address);
20051- fp = frame.next_frame;
20052+ fp = (const void __force_user *)frame.next_frame;
20053 }
20054 }
20055
20056diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20057index 639d128..e92d7e5 100644
20058--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20059+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20060@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20061 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20062 {
20063 struct attribute **attrs;
20064- struct attribute_group *attr_group;
20065+ attribute_group_no_const *attr_group;
20066 int i = 0, j;
20067
20068 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20069diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20070index a45d8d4..8abd32c 100644
20071--- a/arch/x86/kernel/cpu/perf_event_intel.c
20072+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20073@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20074 * v2 and above have a perf capabilities MSR
20075 */
20076 if (version > 1) {
20077- u64 capabilities;
20078+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20079
20080- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20081- x86_pmu.intel_cap.capabilities = capabilities;
20082+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20083+ x86_pmu.intel_cap.capabilities = capabilities;
20084 }
20085
20086 intel_ds_init();
20087diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20088index 1fb6c72..f5fa2a3 100644
20089--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20090+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20091@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20092 static int __init uncore_type_init(struct intel_uncore_type *type)
20093 {
20094 struct intel_uncore_pmu *pmus;
20095- struct attribute_group *attr_group;
20096+ attribute_group_no_const *attr_group;
20097 struct attribute **attrs;
20098 int i, j;
20099
20100diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20101index 47b3d00c..2cf1751 100644
20102--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20103+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20104@@ -488,7 +488,7 @@ struct intel_uncore_box {
20105 struct uncore_event_desc {
20106 struct kobj_attribute attr;
20107 const char *config;
20108-};
20109+} __do_const;
20110
20111 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20112 { \
20113diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20114index 7d9481c..99c7e4b 100644
20115--- a/arch/x86/kernel/cpuid.c
20116+++ b/arch/x86/kernel/cpuid.c
20117@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20118 return notifier_from_errno(err);
20119 }
20120
20121-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20122+static struct notifier_block cpuid_class_cpu_notifier =
20123 {
20124 .notifier_call = cpuid_class_cpu_callback,
20125 };
20126diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20127index 74467fe..18793d5 100644
20128--- a/arch/x86/kernel/crash.c
20129+++ b/arch/x86/kernel/crash.c
20130@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20131 {
20132 #ifdef CONFIG_X86_32
20133 struct pt_regs fixed_regs;
20134-#endif
20135
20136-#ifdef CONFIG_X86_32
20137- if (!user_mode_vm(regs)) {
20138+ if (!user_mode(regs)) {
20139 crash_fixup_ss_esp(&fixed_regs, regs);
20140 regs = &fixed_regs;
20141 }
20142diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20143index afa64ad..dce67dd 100644
20144--- a/arch/x86/kernel/crash_dump_64.c
20145+++ b/arch/x86/kernel/crash_dump_64.c
20146@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20147 return -ENOMEM;
20148
20149 if (userbuf) {
20150- if (copy_to_user(buf, vaddr + offset, csize)) {
20151+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20152 iounmap(vaddr);
20153 return -EFAULT;
20154 }
20155diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20156index 5d3fe8d..02e1429 100644
20157--- a/arch/x86/kernel/doublefault.c
20158+++ b/arch/x86/kernel/doublefault.c
20159@@ -13,7 +13,7 @@
20160
20161 #define DOUBLEFAULT_STACKSIZE (1024)
20162 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20163-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20164+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20165
20166 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20167
20168@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20169 unsigned long gdt, tss;
20170
20171 native_store_gdt(&gdt_desc);
20172- gdt = gdt_desc.address;
20173+ gdt = (unsigned long)gdt_desc.address;
20174
20175 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20176
20177@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20178 /* 0x2 bit is always set */
20179 .flags = X86_EFLAGS_SF | 0x2,
20180 .sp = STACK_START,
20181- .es = __USER_DS,
20182+ .es = __KERNEL_DS,
20183 .cs = __KERNEL_CS,
20184 .ss = __KERNEL_DS,
20185- .ds = __USER_DS,
20186+ .ds = __KERNEL_DS,
20187 .fs = __KERNEL_PERCPU,
20188
20189 .__cr3 = __pa_nodebug(swapper_pg_dir),
20190diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20191index deb6421..76bbc12 100644
20192--- a/arch/x86/kernel/dumpstack.c
20193+++ b/arch/x86/kernel/dumpstack.c
20194@@ -2,6 +2,9 @@
20195 * Copyright (C) 1991, 1992 Linus Torvalds
20196 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20197 */
20198+#ifdef CONFIG_GRKERNSEC_HIDESYM
20199+#define __INCLUDED_BY_HIDESYM 1
20200+#endif
20201 #include <linux/kallsyms.h>
20202 #include <linux/kprobes.h>
20203 #include <linux/uaccess.h>
20204@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20205 static void
20206 print_ftrace_graph_addr(unsigned long addr, void *data,
20207 const struct stacktrace_ops *ops,
20208- struct thread_info *tinfo, int *graph)
20209+ struct task_struct *task, int *graph)
20210 {
20211- struct task_struct *task;
20212 unsigned long ret_addr;
20213 int index;
20214
20215 if (addr != (unsigned long)return_to_handler)
20216 return;
20217
20218- task = tinfo->task;
20219 index = task->curr_ret_stack;
20220
20221 if (!task->ret_stack || index < *graph)
20222@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20223 static inline void
20224 print_ftrace_graph_addr(unsigned long addr, void *data,
20225 const struct stacktrace_ops *ops,
20226- struct thread_info *tinfo, int *graph)
20227+ struct task_struct *task, int *graph)
20228 { }
20229 #endif
20230
20231@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20232 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20233 */
20234
20235-static inline int valid_stack_ptr(struct thread_info *tinfo,
20236- void *p, unsigned int size, void *end)
20237+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20238 {
20239- void *t = tinfo;
20240 if (end) {
20241 if (p < end && p >= (end-THREAD_SIZE))
20242 return 1;
20243@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20244 }
20245
20246 unsigned long
20247-print_context_stack(struct thread_info *tinfo,
20248+print_context_stack(struct task_struct *task, void *stack_start,
20249 unsigned long *stack, unsigned long bp,
20250 const struct stacktrace_ops *ops, void *data,
20251 unsigned long *end, int *graph)
20252 {
20253 struct stack_frame *frame = (struct stack_frame *)bp;
20254
20255- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20256+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20257 unsigned long addr;
20258
20259 addr = *stack;
20260@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20261 } else {
20262 ops->address(data, addr, 0);
20263 }
20264- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20265+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20266 }
20267 stack++;
20268 }
20269@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20270 EXPORT_SYMBOL_GPL(print_context_stack);
20271
20272 unsigned long
20273-print_context_stack_bp(struct thread_info *tinfo,
20274+print_context_stack_bp(struct task_struct *task, void *stack_start,
20275 unsigned long *stack, unsigned long bp,
20276 const struct stacktrace_ops *ops, void *data,
20277 unsigned long *end, int *graph)
20278@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20279 struct stack_frame *frame = (struct stack_frame *)bp;
20280 unsigned long *ret_addr = &frame->return_address;
20281
20282- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20283+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20284 unsigned long addr = *ret_addr;
20285
20286 if (!__kernel_text_address(addr))
20287@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20288 ops->address(data, addr, 1);
20289 frame = frame->next_frame;
20290 ret_addr = &frame->return_address;
20291- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20292+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20293 }
20294
20295 return (unsigned long)frame;
20296@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20297 static void print_trace_address(void *data, unsigned long addr, int reliable)
20298 {
20299 touch_nmi_watchdog();
20300- printk(data);
20301+ printk("%s", (char *)data);
20302 printk_address(addr, reliable);
20303 }
20304
20305@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20306 }
20307 EXPORT_SYMBOL_GPL(oops_begin);
20308
20309+extern void gr_handle_kernel_exploit(void);
20310+
20311 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20312 {
20313 if (regs && kexec_should_crash(current))
20314@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20315 panic("Fatal exception in interrupt");
20316 if (panic_on_oops)
20317 panic("Fatal exception");
20318- do_exit(signr);
20319+
20320+ gr_handle_kernel_exploit();
20321+
20322+ do_group_exit(signr);
20323 }
20324
20325 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20326@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20327 print_modules();
20328 show_regs(regs);
20329 #ifdef CONFIG_X86_32
20330- if (user_mode_vm(regs)) {
20331+ if (user_mode(regs)) {
20332 sp = regs->sp;
20333 ss = regs->ss & 0xffff;
20334 } else {
20335@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20336 unsigned long flags = oops_begin();
20337 int sig = SIGSEGV;
20338
20339- if (!user_mode_vm(regs))
20340+ if (!user_mode(regs))
20341 report_bug(regs->ip, regs);
20342
20343 if (__die(str, regs, err))
20344diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20345index f2a1770..540657f 100644
20346--- a/arch/x86/kernel/dumpstack_32.c
20347+++ b/arch/x86/kernel/dumpstack_32.c
20348@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20349 bp = stack_frame(task, regs);
20350
20351 for (;;) {
20352- struct thread_info *context;
20353+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20354
20355- context = (struct thread_info *)
20356- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20357- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20358+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20359
20360- stack = (unsigned long *)context->previous_esp;
20361- if (!stack)
20362+ if (stack_start == task_stack_page(task))
20363 break;
20364+ stack = *(unsigned long **)stack_start;
20365 if (ops->stack(data, "IRQ") < 0)
20366 break;
20367 touch_nmi_watchdog();
20368@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20369 int i;
20370
20371 show_regs_print_info(KERN_EMERG);
20372- __show_regs(regs, !user_mode_vm(regs));
20373+ __show_regs(regs, !user_mode(regs));
20374
20375 /*
20376 * When in-kernel, we also print out the stack and code at the
20377 * time of the fault..
20378 */
20379- if (!user_mode_vm(regs)) {
20380+ if (!user_mode(regs)) {
20381 unsigned int code_prologue = code_bytes * 43 / 64;
20382 unsigned int code_len = code_bytes;
20383 unsigned char c;
20384 u8 *ip;
20385+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20386
20387 pr_emerg("Stack:\n");
20388 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20389
20390 pr_emerg("Code:");
20391
20392- ip = (u8 *)regs->ip - code_prologue;
20393+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20394 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20395 /* try starting at IP */
20396- ip = (u8 *)regs->ip;
20397+ ip = (u8 *)regs->ip + cs_base;
20398 code_len = code_len - code_prologue + 1;
20399 }
20400 for (i = 0; i < code_len; i++, ip++) {
20401@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20402 pr_cont(" Bad EIP value.");
20403 break;
20404 }
20405- if (ip == (u8 *)regs->ip)
20406+ if (ip == (u8 *)regs->ip + cs_base)
20407 pr_cont(" <%02x>", c);
20408 else
20409 pr_cont(" %02x", c);
20410@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20411 {
20412 unsigned short ud2;
20413
20414+ ip = ktla_ktva(ip);
20415 if (ip < PAGE_OFFSET)
20416 return 0;
20417 if (probe_kernel_address((unsigned short *)ip, ud2))
20418@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20419
20420 return ud2 == 0x0b0f;
20421 }
20422+
20423+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20424+void pax_check_alloca(unsigned long size)
20425+{
20426+ unsigned long sp = (unsigned long)&sp, stack_left;
20427+
20428+ /* all kernel stacks are of the same size */
20429+ stack_left = sp & (THREAD_SIZE - 1);
20430+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20431+}
20432+EXPORT_SYMBOL(pax_check_alloca);
20433+#endif
20434diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20435index addb207..99635fa 100644
20436--- a/arch/x86/kernel/dumpstack_64.c
20437+++ b/arch/x86/kernel/dumpstack_64.c
20438@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20439 unsigned long *irq_stack_end =
20440 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20441 unsigned used = 0;
20442- struct thread_info *tinfo;
20443 int graph = 0;
20444 unsigned long dummy;
20445+ void *stack_start;
20446
20447 if (!task)
20448 task = current;
20449@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20450 * current stack address. If the stacks consist of nested
20451 * exceptions
20452 */
20453- tinfo = task_thread_info(task);
20454 for (;;) {
20455 char *id;
20456 unsigned long *estack_end;
20457+
20458 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20459 &used, &id);
20460
20461@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20462 if (ops->stack(data, id) < 0)
20463 break;
20464
20465- bp = ops->walk_stack(tinfo, stack, bp, ops,
20466+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20467 data, estack_end, &graph);
20468 ops->stack(data, "<EOE>");
20469 /*
20470@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20471 * second-to-last pointer (index -2 to end) in the
20472 * exception stack:
20473 */
20474+ if ((u16)estack_end[-1] != __KERNEL_DS)
20475+ goto out;
20476 stack = (unsigned long *) estack_end[-2];
20477 continue;
20478 }
20479@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20480 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20481 if (ops->stack(data, "IRQ") < 0)
20482 break;
20483- bp = ops->walk_stack(tinfo, stack, bp,
20484+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20485 ops, data, irq_stack_end, &graph);
20486 /*
20487 * We link to the next stack (which would be
20488@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20489 /*
20490 * This handles the process stack:
20491 */
20492- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20493+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20494+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20495+out:
20496 put_cpu();
20497 }
20498 EXPORT_SYMBOL(dump_trace);
20499@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20500
20501 return ud2 == 0x0b0f;
20502 }
20503+
20504+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20505+void pax_check_alloca(unsigned long size)
20506+{
20507+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20508+ unsigned cpu, used;
20509+ char *id;
20510+
20511+ /* check the process stack first */
20512+ stack_start = (unsigned long)task_stack_page(current);
20513+ stack_end = stack_start + THREAD_SIZE;
20514+ if (likely(stack_start <= sp && sp < stack_end)) {
20515+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20516+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20517+ return;
20518+ }
20519+
20520+ cpu = get_cpu();
20521+
20522+ /* check the irq stacks */
20523+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20524+ stack_start = stack_end - IRQ_STACK_SIZE;
20525+ if (stack_start <= sp && sp < stack_end) {
20526+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20527+ put_cpu();
20528+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20529+ return;
20530+ }
20531+
20532+ /* check the exception stacks */
20533+ used = 0;
20534+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20535+ stack_start = stack_end - EXCEPTION_STKSZ;
20536+ if (stack_end && stack_start <= sp && sp < stack_end) {
20537+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20538+ put_cpu();
20539+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20540+ return;
20541+ }
20542+
20543+ put_cpu();
20544+
20545+ /* unknown stack */
20546+ BUG();
20547+}
20548+EXPORT_SYMBOL(pax_check_alloca);
20549+#endif
20550diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20551index d32abea..74daf4f 100644
20552--- a/arch/x86/kernel/e820.c
20553+++ b/arch/x86/kernel/e820.c
20554@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20555
20556 static void early_panic(char *msg)
20557 {
20558- early_printk(msg);
20559- panic(msg);
20560+ early_printk("%s", msg);
20561+ panic("%s", msg);
20562 }
20563
20564 static int userdef __initdata;
20565diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20566index d15f575..d692043 100644
20567--- a/arch/x86/kernel/early_printk.c
20568+++ b/arch/x86/kernel/early_printk.c
20569@@ -7,6 +7,7 @@
20570 #include <linux/pci_regs.h>
20571 #include <linux/pci_ids.h>
20572 #include <linux/errno.h>
20573+#include <linux/sched.h>
20574 #include <asm/io.h>
20575 #include <asm/processor.h>
20576 #include <asm/fcntl.h>
20577diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20578index 2cfbc3a..b756682 100644
20579--- a/arch/x86/kernel/entry_32.S
20580+++ b/arch/x86/kernel/entry_32.S
20581@@ -177,13 +177,153 @@
20582 /*CFI_REL_OFFSET gs, PT_GS*/
20583 .endm
20584 .macro SET_KERNEL_GS reg
20585+
20586+#ifdef CONFIG_CC_STACKPROTECTOR
20587 movl $(__KERNEL_STACK_CANARY), \reg
20588+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20589+ movl $(__USER_DS), \reg
20590+#else
20591+ xorl \reg, \reg
20592+#endif
20593+
20594 movl \reg, %gs
20595 .endm
20596
20597 #endif /* CONFIG_X86_32_LAZY_GS */
20598
20599-.macro SAVE_ALL
20600+.macro pax_enter_kernel
20601+#ifdef CONFIG_PAX_KERNEXEC
20602+ call pax_enter_kernel
20603+#endif
20604+.endm
20605+
20606+.macro pax_exit_kernel
20607+#ifdef CONFIG_PAX_KERNEXEC
20608+ call pax_exit_kernel
20609+#endif
20610+.endm
20611+
20612+#ifdef CONFIG_PAX_KERNEXEC
20613+ENTRY(pax_enter_kernel)
20614+#ifdef CONFIG_PARAVIRT
20615+ pushl %eax
20616+ pushl %ecx
20617+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20618+ mov %eax, %esi
20619+#else
20620+ mov %cr0, %esi
20621+#endif
20622+ bts $16, %esi
20623+ jnc 1f
20624+ mov %cs, %esi
20625+ cmp $__KERNEL_CS, %esi
20626+ jz 3f
20627+ ljmp $__KERNEL_CS, $3f
20628+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20629+2:
20630+#ifdef CONFIG_PARAVIRT
20631+ mov %esi, %eax
20632+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20633+#else
20634+ mov %esi, %cr0
20635+#endif
20636+3:
20637+#ifdef CONFIG_PARAVIRT
20638+ popl %ecx
20639+ popl %eax
20640+#endif
20641+ ret
20642+ENDPROC(pax_enter_kernel)
20643+
20644+ENTRY(pax_exit_kernel)
20645+#ifdef CONFIG_PARAVIRT
20646+ pushl %eax
20647+ pushl %ecx
20648+#endif
20649+ mov %cs, %esi
20650+ cmp $__KERNEXEC_KERNEL_CS, %esi
20651+ jnz 2f
20652+#ifdef CONFIG_PARAVIRT
20653+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20654+ mov %eax, %esi
20655+#else
20656+ mov %cr0, %esi
20657+#endif
20658+ btr $16, %esi
20659+ ljmp $__KERNEL_CS, $1f
20660+1:
20661+#ifdef CONFIG_PARAVIRT
20662+ mov %esi, %eax
20663+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20664+#else
20665+ mov %esi, %cr0
20666+#endif
20667+2:
20668+#ifdef CONFIG_PARAVIRT
20669+ popl %ecx
20670+ popl %eax
20671+#endif
20672+ ret
20673+ENDPROC(pax_exit_kernel)
20674+#endif
20675+
20676+ .macro pax_erase_kstack
20677+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20678+ call pax_erase_kstack
20679+#endif
20680+ .endm
20681+
20682+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20683+/*
20684+ * ebp: thread_info
20685+ */
20686+ENTRY(pax_erase_kstack)
20687+ pushl %edi
20688+ pushl %ecx
20689+ pushl %eax
20690+
20691+ mov TI_lowest_stack(%ebp), %edi
20692+ mov $-0xBEEF, %eax
20693+ std
20694+
20695+1: mov %edi, %ecx
20696+ and $THREAD_SIZE_asm - 1, %ecx
20697+ shr $2, %ecx
20698+ repne scasl
20699+ jecxz 2f
20700+
20701+ cmp $2*16, %ecx
20702+ jc 2f
20703+
20704+ mov $2*16, %ecx
20705+ repe scasl
20706+ jecxz 2f
20707+ jne 1b
20708+
20709+2: cld
20710+ mov %esp, %ecx
20711+ sub %edi, %ecx
20712+
20713+ cmp $THREAD_SIZE_asm, %ecx
20714+ jb 3f
20715+ ud2
20716+3:
20717+
20718+ shr $2, %ecx
20719+ rep stosl
20720+
20721+ mov TI_task_thread_sp0(%ebp), %edi
20722+ sub $128, %edi
20723+ mov %edi, TI_lowest_stack(%ebp)
20724+
20725+ popl %eax
20726+ popl %ecx
20727+ popl %edi
20728+ ret
20729+ENDPROC(pax_erase_kstack)
20730+#endif
20731+
20732+.macro __SAVE_ALL _DS
20733 cld
20734 PUSH_GS
20735 pushl_cfi %fs
20736@@ -206,7 +346,7 @@
20737 CFI_REL_OFFSET ecx, 0
20738 pushl_cfi %ebx
20739 CFI_REL_OFFSET ebx, 0
20740- movl $(__USER_DS), %edx
20741+ movl $\_DS, %edx
20742 movl %edx, %ds
20743 movl %edx, %es
20744 movl $(__KERNEL_PERCPU), %edx
20745@@ -214,6 +354,15 @@
20746 SET_KERNEL_GS %edx
20747 .endm
20748
20749+.macro SAVE_ALL
20750+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20751+ __SAVE_ALL __KERNEL_DS
20752+ pax_enter_kernel
20753+#else
20754+ __SAVE_ALL __USER_DS
20755+#endif
20756+.endm
20757+
20758 .macro RESTORE_INT_REGS
20759 popl_cfi %ebx
20760 CFI_RESTORE ebx
20761@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20762 popfl_cfi
20763 jmp syscall_exit
20764 CFI_ENDPROC
20765-END(ret_from_fork)
20766+ENDPROC(ret_from_fork)
20767
20768 ENTRY(ret_from_kernel_thread)
20769 CFI_STARTPROC
20770@@ -344,7 +493,15 @@ ret_from_intr:
20771 andl $SEGMENT_RPL_MASK, %eax
20772 #endif
20773 cmpl $USER_RPL, %eax
20774+
20775+#ifdef CONFIG_PAX_KERNEXEC
20776+ jae resume_userspace
20777+
20778+ pax_exit_kernel
20779+ jmp resume_kernel
20780+#else
20781 jb resume_kernel # not returning to v8086 or userspace
20782+#endif
20783
20784 ENTRY(resume_userspace)
20785 LOCKDEP_SYS_EXIT
20786@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20787 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20788 # int/exception return?
20789 jne work_pending
20790- jmp restore_all
20791-END(ret_from_exception)
20792+ jmp restore_all_pax
20793+ENDPROC(ret_from_exception)
20794
20795 #ifdef CONFIG_PREEMPT
20796 ENTRY(resume_kernel)
20797@@ -372,7 +529,7 @@ need_resched:
20798 jz restore_all
20799 call preempt_schedule_irq
20800 jmp need_resched
20801-END(resume_kernel)
20802+ENDPROC(resume_kernel)
20803 #endif
20804 CFI_ENDPROC
20805 /*
20806@@ -406,30 +563,45 @@ sysenter_past_esp:
20807 /*CFI_REL_OFFSET cs, 0*/
20808 /*
20809 * Push current_thread_info()->sysenter_return to the stack.
20810- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20811- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20812 */
20813- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20814+ pushl_cfi $0
20815 CFI_REL_OFFSET eip, 0
20816
20817 pushl_cfi %eax
20818 SAVE_ALL
20819+ GET_THREAD_INFO(%ebp)
20820+ movl TI_sysenter_return(%ebp),%ebp
20821+ movl %ebp,PT_EIP(%esp)
20822 ENABLE_INTERRUPTS(CLBR_NONE)
20823
20824 /*
20825 * Load the potential sixth argument from user stack.
20826 * Careful about security.
20827 */
20828+ movl PT_OLDESP(%esp),%ebp
20829+
20830+#ifdef CONFIG_PAX_MEMORY_UDEREF
20831+ mov PT_OLDSS(%esp),%ds
20832+1: movl %ds:(%ebp),%ebp
20833+ push %ss
20834+ pop %ds
20835+#else
20836 cmpl $__PAGE_OFFSET-3,%ebp
20837 jae syscall_fault
20838 ASM_STAC
20839 1: movl (%ebp),%ebp
20840 ASM_CLAC
20841+#endif
20842+
20843 movl %ebp,PT_EBP(%esp)
20844 _ASM_EXTABLE(1b,syscall_fault)
20845
20846 GET_THREAD_INFO(%ebp)
20847
20848+#ifdef CONFIG_PAX_RANDKSTACK
20849+ pax_erase_kstack
20850+#endif
20851+
20852 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20853 jnz sysenter_audit
20854 sysenter_do_call:
20855@@ -444,12 +616,24 @@ sysenter_do_call:
20856 testl $_TIF_ALLWORK_MASK, %ecx
20857 jne sysexit_audit
20858 sysenter_exit:
20859+
20860+#ifdef CONFIG_PAX_RANDKSTACK
20861+ pushl_cfi %eax
20862+ movl %esp, %eax
20863+ call pax_randomize_kstack
20864+ popl_cfi %eax
20865+#endif
20866+
20867+ pax_erase_kstack
20868+
20869 /* if something modifies registers it must also disable sysexit */
20870 movl PT_EIP(%esp), %edx
20871 movl PT_OLDESP(%esp), %ecx
20872 xorl %ebp,%ebp
20873 TRACE_IRQS_ON
20874 1: mov PT_FS(%esp), %fs
20875+2: mov PT_DS(%esp), %ds
20876+3: mov PT_ES(%esp), %es
20877 PTGS_TO_GS
20878 ENABLE_INTERRUPTS_SYSEXIT
20879
20880@@ -466,6 +650,9 @@ sysenter_audit:
20881 movl %eax,%edx /* 2nd arg: syscall number */
20882 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20883 call __audit_syscall_entry
20884+
20885+ pax_erase_kstack
20886+
20887 pushl_cfi %ebx
20888 movl PT_EAX(%esp),%eax /* reload syscall number */
20889 jmp sysenter_do_call
20890@@ -491,10 +678,16 @@ sysexit_audit:
20891
20892 CFI_ENDPROC
20893 .pushsection .fixup,"ax"
20894-2: movl $0,PT_FS(%esp)
20895+4: movl $0,PT_FS(%esp)
20896+ jmp 1b
20897+5: movl $0,PT_DS(%esp)
20898+ jmp 1b
20899+6: movl $0,PT_ES(%esp)
20900 jmp 1b
20901 .popsection
20902- _ASM_EXTABLE(1b,2b)
20903+ _ASM_EXTABLE(1b,4b)
20904+ _ASM_EXTABLE(2b,5b)
20905+ _ASM_EXTABLE(3b,6b)
20906 PTGS_TO_GS_EX
20907 ENDPROC(ia32_sysenter_target)
20908
20909@@ -509,6 +702,11 @@ ENTRY(system_call)
20910 pushl_cfi %eax # save orig_eax
20911 SAVE_ALL
20912 GET_THREAD_INFO(%ebp)
20913+
20914+#ifdef CONFIG_PAX_RANDKSTACK
20915+ pax_erase_kstack
20916+#endif
20917+
20918 # system call tracing in operation / emulation
20919 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20920 jnz syscall_trace_entry
20921@@ -527,6 +725,15 @@ syscall_exit:
20922 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20923 jne syscall_exit_work
20924
20925+restore_all_pax:
20926+
20927+#ifdef CONFIG_PAX_RANDKSTACK
20928+ movl %esp, %eax
20929+ call pax_randomize_kstack
20930+#endif
20931+
20932+ pax_erase_kstack
20933+
20934 restore_all:
20935 TRACE_IRQS_IRET
20936 restore_all_notrace:
20937@@ -583,14 +790,34 @@ ldt_ss:
20938 * compensating for the offset by changing to the ESPFIX segment with
20939 * a base address that matches for the difference.
20940 */
20941-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20942+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20943 mov %esp, %edx /* load kernel esp */
20944 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20945 mov %dx, %ax /* eax: new kernel esp */
20946 sub %eax, %edx /* offset (low word is 0) */
20947+#ifdef CONFIG_SMP
20948+ movl PER_CPU_VAR(cpu_number), %ebx
20949+ shll $PAGE_SHIFT_asm, %ebx
20950+ addl $cpu_gdt_table, %ebx
20951+#else
20952+ movl $cpu_gdt_table, %ebx
20953+#endif
20954 shr $16, %edx
20955- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20956- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20957+
20958+#ifdef CONFIG_PAX_KERNEXEC
20959+ mov %cr0, %esi
20960+ btr $16, %esi
20961+ mov %esi, %cr0
20962+#endif
20963+
20964+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20965+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20966+
20967+#ifdef CONFIG_PAX_KERNEXEC
20968+ bts $16, %esi
20969+ mov %esi, %cr0
20970+#endif
20971+
20972 pushl_cfi $__ESPFIX_SS
20973 pushl_cfi %eax /* new kernel esp */
20974 /* Disable interrupts, but do not irqtrace this section: we
20975@@ -619,20 +846,18 @@ work_resched:
20976 movl TI_flags(%ebp), %ecx
20977 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20978 # than syscall tracing?
20979- jz restore_all
20980+ jz restore_all_pax
20981 testb $_TIF_NEED_RESCHED, %cl
20982 jnz work_resched
20983
20984 work_notifysig: # deal with pending signals and
20985 # notify-resume requests
20986+ movl %esp, %eax
20987 #ifdef CONFIG_VM86
20988 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20989- movl %esp, %eax
20990 jne work_notifysig_v86 # returning to kernel-space or
20991 # vm86-space
20992 1:
20993-#else
20994- movl %esp, %eax
20995 #endif
20996 TRACE_IRQS_ON
20997 ENABLE_INTERRUPTS(CLBR_NONE)
20998@@ -653,7 +878,7 @@ work_notifysig_v86:
20999 movl %eax, %esp
21000 jmp 1b
21001 #endif
21002-END(work_pending)
21003+ENDPROC(work_pending)
21004
21005 # perform syscall exit tracing
21006 ALIGN
21007@@ -661,11 +886,14 @@ syscall_trace_entry:
21008 movl $-ENOSYS,PT_EAX(%esp)
21009 movl %esp, %eax
21010 call syscall_trace_enter
21011+
21012+ pax_erase_kstack
21013+
21014 /* What it returned is what we'll actually use. */
21015 cmpl $(NR_syscalls), %eax
21016 jnae syscall_call
21017 jmp syscall_exit
21018-END(syscall_trace_entry)
21019+ENDPROC(syscall_trace_entry)
21020
21021 # perform syscall exit tracing
21022 ALIGN
21023@@ -678,21 +906,25 @@ syscall_exit_work:
21024 movl %esp, %eax
21025 call syscall_trace_leave
21026 jmp resume_userspace
21027-END(syscall_exit_work)
21028+ENDPROC(syscall_exit_work)
21029 CFI_ENDPROC
21030
21031 RING0_INT_FRAME # can't unwind into user space anyway
21032 syscall_fault:
21033+#ifdef CONFIG_PAX_MEMORY_UDEREF
21034+ push %ss
21035+ pop %ds
21036+#endif
21037 ASM_CLAC
21038 GET_THREAD_INFO(%ebp)
21039 movl $-EFAULT,PT_EAX(%esp)
21040 jmp resume_userspace
21041-END(syscall_fault)
21042+ENDPROC(syscall_fault)
21043
21044 syscall_badsys:
21045 movl $-ENOSYS,PT_EAX(%esp)
21046 jmp resume_userspace
21047-END(syscall_badsys)
21048+ENDPROC(syscall_badsys)
21049 CFI_ENDPROC
21050 /*
21051 * End of kprobes section
21052@@ -708,8 +940,15 @@ END(syscall_badsys)
21053 * normal stack and adjusts ESP with the matching offset.
21054 */
21055 /* fixup the stack */
21056- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21057- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21058+#ifdef CONFIG_SMP
21059+ movl PER_CPU_VAR(cpu_number), %ebx
21060+ shll $PAGE_SHIFT_asm, %ebx
21061+ addl $cpu_gdt_table, %ebx
21062+#else
21063+ movl $cpu_gdt_table, %ebx
21064+#endif
21065+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21066+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21067 shl $16, %eax
21068 addl %esp, %eax /* the adjusted stack pointer */
21069 pushl_cfi $__KERNEL_DS
21070@@ -762,7 +1001,7 @@ vector=vector+1
21071 .endr
21072 2: jmp common_interrupt
21073 .endr
21074-END(irq_entries_start)
21075+ENDPROC(irq_entries_start)
21076
21077 .previous
21078 END(interrupt)
21079@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21080 pushl_cfi $do_coprocessor_error
21081 jmp error_code
21082 CFI_ENDPROC
21083-END(coprocessor_error)
21084+ENDPROC(coprocessor_error)
21085
21086 ENTRY(simd_coprocessor_error)
21087 RING0_INT_FRAME
21088@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21089 .section .altinstructions,"a"
21090 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21091 .previous
21092-.section .altinstr_replacement,"ax"
21093+.section .altinstr_replacement,"a"
21094 663: pushl $do_simd_coprocessor_error
21095 664:
21096 .previous
21097@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21098 #endif
21099 jmp error_code
21100 CFI_ENDPROC
21101-END(simd_coprocessor_error)
21102+ENDPROC(simd_coprocessor_error)
21103
21104 ENTRY(device_not_available)
21105 RING0_INT_FRAME
21106@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21107 pushl_cfi $do_device_not_available
21108 jmp error_code
21109 CFI_ENDPROC
21110-END(device_not_available)
21111+ENDPROC(device_not_available)
21112
21113 #ifdef CONFIG_PARAVIRT
21114 ENTRY(native_iret)
21115 iret
21116 _ASM_EXTABLE(native_iret, iret_exc)
21117-END(native_iret)
21118+ENDPROC(native_iret)
21119
21120 ENTRY(native_irq_enable_sysexit)
21121 sti
21122 sysexit
21123-END(native_irq_enable_sysexit)
21124+ENDPROC(native_irq_enable_sysexit)
21125 #endif
21126
21127 ENTRY(overflow)
21128@@ -875,7 +1114,7 @@ ENTRY(overflow)
21129 pushl_cfi $do_overflow
21130 jmp error_code
21131 CFI_ENDPROC
21132-END(overflow)
21133+ENDPROC(overflow)
21134
21135 ENTRY(bounds)
21136 RING0_INT_FRAME
21137@@ -884,7 +1123,7 @@ ENTRY(bounds)
21138 pushl_cfi $do_bounds
21139 jmp error_code
21140 CFI_ENDPROC
21141-END(bounds)
21142+ENDPROC(bounds)
21143
21144 ENTRY(invalid_op)
21145 RING0_INT_FRAME
21146@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21147 pushl_cfi $do_invalid_op
21148 jmp error_code
21149 CFI_ENDPROC
21150-END(invalid_op)
21151+ENDPROC(invalid_op)
21152
21153 ENTRY(coprocessor_segment_overrun)
21154 RING0_INT_FRAME
21155@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21156 pushl_cfi $do_coprocessor_segment_overrun
21157 jmp error_code
21158 CFI_ENDPROC
21159-END(coprocessor_segment_overrun)
21160+ENDPROC(coprocessor_segment_overrun)
21161
21162 ENTRY(invalid_TSS)
21163 RING0_EC_FRAME
21164@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21165 pushl_cfi $do_invalid_TSS
21166 jmp error_code
21167 CFI_ENDPROC
21168-END(invalid_TSS)
21169+ENDPROC(invalid_TSS)
21170
21171 ENTRY(segment_not_present)
21172 RING0_EC_FRAME
21173@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21174 pushl_cfi $do_segment_not_present
21175 jmp error_code
21176 CFI_ENDPROC
21177-END(segment_not_present)
21178+ENDPROC(segment_not_present)
21179
21180 ENTRY(stack_segment)
21181 RING0_EC_FRAME
21182@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21183 pushl_cfi $do_stack_segment
21184 jmp error_code
21185 CFI_ENDPROC
21186-END(stack_segment)
21187+ENDPROC(stack_segment)
21188
21189 ENTRY(alignment_check)
21190 RING0_EC_FRAME
21191@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21192 pushl_cfi $do_alignment_check
21193 jmp error_code
21194 CFI_ENDPROC
21195-END(alignment_check)
21196+ENDPROC(alignment_check)
21197
21198 ENTRY(divide_error)
21199 RING0_INT_FRAME
21200@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21201 pushl_cfi $do_divide_error
21202 jmp error_code
21203 CFI_ENDPROC
21204-END(divide_error)
21205+ENDPROC(divide_error)
21206
21207 #ifdef CONFIG_X86_MCE
21208 ENTRY(machine_check)
21209@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21210 pushl_cfi machine_check_vector
21211 jmp error_code
21212 CFI_ENDPROC
21213-END(machine_check)
21214+ENDPROC(machine_check)
21215 #endif
21216
21217 ENTRY(spurious_interrupt_bug)
21218@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21219 pushl_cfi $do_spurious_interrupt_bug
21220 jmp error_code
21221 CFI_ENDPROC
21222-END(spurious_interrupt_bug)
21223+ENDPROC(spurious_interrupt_bug)
21224 /*
21225 * End of kprobes section
21226 */
21227@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21228
21229 ENTRY(mcount)
21230 ret
21231-END(mcount)
21232+ENDPROC(mcount)
21233
21234 ENTRY(ftrace_caller)
21235 cmpl $0, function_trace_stop
21236@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21237 .globl ftrace_stub
21238 ftrace_stub:
21239 ret
21240-END(ftrace_caller)
21241+ENDPROC(ftrace_caller)
21242
21243 ENTRY(ftrace_regs_caller)
21244 pushf /* push flags before compare (in cs location) */
21245@@ -1207,7 +1446,7 @@ trace:
21246 popl %ecx
21247 popl %eax
21248 jmp ftrace_stub
21249-END(mcount)
21250+ENDPROC(mcount)
21251 #endif /* CONFIG_DYNAMIC_FTRACE */
21252 #endif /* CONFIG_FUNCTION_TRACER */
21253
21254@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21255 popl %ecx
21256 popl %eax
21257 ret
21258-END(ftrace_graph_caller)
21259+ENDPROC(ftrace_graph_caller)
21260
21261 .globl return_to_handler
21262 return_to_handler:
21263@@ -1281,15 +1520,18 @@ error_code:
21264 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21265 REG_TO_PTGS %ecx
21266 SET_KERNEL_GS %ecx
21267- movl $(__USER_DS), %ecx
21268+ movl $(__KERNEL_DS), %ecx
21269 movl %ecx, %ds
21270 movl %ecx, %es
21271+
21272+ pax_enter_kernel
21273+
21274 TRACE_IRQS_OFF
21275 movl %esp,%eax # pt_regs pointer
21276 call *%edi
21277 jmp ret_from_exception
21278 CFI_ENDPROC
21279-END(page_fault)
21280+ENDPROC(page_fault)
21281
21282 /*
21283 * Debug traps and NMI can happen at the one SYSENTER instruction
21284@@ -1332,7 +1574,7 @@ debug_stack_correct:
21285 call do_debug
21286 jmp ret_from_exception
21287 CFI_ENDPROC
21288-END(debug)
21289+ENDPROC(debug)
21290
21291 /*
21292 * NMI is doubly nasty. It can happen _while_ we're handling
21293@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21294 xorl %edx,%edx # zero error code
21295 movl %esp,%eax # pt_regs pointer
21296 call do_nmi
21297+
21298+ pax_exit_kernel
21299+
21300 jmp restore_all_notrace
21301 CFI_ENDPROC
21302
21303@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21304 FIXUP_ESPFIX_STACK # %eax == %esp
21305 xorl %edx,%edx # zero error code
21306 call do_nmi
21307+
21308+ pax_exit_kernel
21309+
21310 RESTORE_REGS
21311 lss 12+4(%esp), %esp # back to espfix stack
21312 CFI_ADJUST_CFA_OFFSET -24
21313 jmp irq_return
21314 CFI_ENDPROC
21315-END(nmi)
21316+ENDPROC(nmi)
21317
21318 ENTRY(int3)
21319 RING0_INT_FRAME
21320@@ -1424,14 +1672,14 @@ ENTRY(int3)
21321 call do_int3
21322 jmp ret_from_exception
21323 CFI_ENDPROC
21324-END(int3)
21325+ENDPROC(int3)
21326
21327 ENTRY(general_protection)
21328 RING0_EC_FRAME
21329 pushl_cfi $do_general_protection
21330 jmp error_code
21331 CFI_ENDPROC
21332-END(general_protection)
21333+ENDPROC(general_protection)
21334
21335 #ifdef CONFIG_KVM_GUEST
21336 ENTRY(async_page_fault)
21337@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21338 pushl_cfi $do_async_page_fault
21339 jmp error_code
21340 CFI_ENDPROC
21341-END(async_page_fault)
21342+ENDPROC(async_page_fault)
21343 #endif
21344
21345 /*
21346diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21347index 1b69951..8430a6d 100644
21348--- a/arch/x86/kernel/entry_64.S
21349+++ b/arch/x86/kernel/entry_64.S
21350@@ -59,6 +59,8 @@
21351 #include <asm/context_tracking.h>
21352 #include <asm/smap.h>
21353 #include <linux/err.h>
21354+#include <asm/pgtable.h>
21355+#include <asm/alternative-asm.h>
21356
21357 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21358 #include <linux/elf-em.h>
21359@@ -80,8 +82,9 @@
21360 #ifdef CONFIG_DYNAMIC_FTRACE
21361
21362 ENTRY(function_hook)
21363+ pax_force_retaddr
21364 retq
21365-END(function_hook)
21366+ENDPROC(function_hook)
21367
21368 /* skip is set if stack has been adjusted */
21369 .macro ftrace_caller_setup skip=0
21370@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21371 #endif
21372
21373 GLOBAL(ftrace_stub)
21374+ pax_force_retaddr
21375 retq
21376-END(ftrace_caller)
21377+ENDPROC(ftrace_caller)
21378
21379 ENTRY(ftrace_regs_caller)
21380 /* Save the current flags before compare (in SS location)*/
21381@@ -191,7 +195,7 @@ ftrace_restore_flags:
21382 popfq
21383 jmp ftrace_stub
21384
21385-END(ftrace_regs_caller)
21386+ENDPROC(ftrace_regs_caller)
21387
21388
21389 #else /* ! CONFIG_DYNAMIC_FTRACE */
21390@@ -212,6 +216,7 @@ ENTRY(function_hook)
21391 #endif
21392
21393 GLOBAL(ftrace_stub)
21394+ pax_force_retaddr
21395 retq
21396
21397 trace:
21398@@ -225,12 +230,13 @@ trace:
21399 #endif
21400 subq $MCOUNT_INSN_SIZE, %rdi
21401
21402+ pax_force_fptr ftrace_trace_function
21403 call *ftrace_trace_function
21404
21405 MCOUNT_RESTORE_FRAME
21406
21407 jmp ftrace_stub
21408-END(function_hook)
21409+ENDPROC(function_hook)
21410 #endif /* CONFIG_DYNAMIC_FTRACE */
21411 #endif /* CONFIG_FUNCTION_TRACER */
21412
21413@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21414
21415 MCOUNT_RESTORE_FRAME
21416
21417+ pax_force_retaddr
21418 retq
21419-END(ftrace_graph_caller)
21420+ENDPROC(ftrace_graph_caller)
21421
21422 GLOBAL(return_to_handler)
21423 subq $24, %rsp
21424@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21425 movq 8(%rsp), %rdx
21426 movq (%rsp), %rax
21427 addq $24, %rsp
21428+ pax_force_fptr %rdi
21429 jmp *%rdi
21430+ENDPROC(return_to_handler)
21431 #endif
21432
21433
21434@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21435 ENDPROC(native_usergs_sysret64)
21436 #endif /* CONFIG_PARAVIRT */
21437
21438+ .macro ljmpq sel, off
21439+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21440+ .byte 0x48; ljmp *1234f(%rip)
21441+ .pushsection .rodata
21442+ .align 16
21443+ 1234: .quad \off; .word \sel
21444+ .popsection
21445+#else
21446+ pushq $\sel
21447+ pushq $\off
21448+ lretq
21449+#endif
21450+ .endm
21451+
21452+ .macro pax_enter_kernel
21453+ pax_set_fptr_mask
21454+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21455+ call pax_enter_kernel
21456+#endif
21457+ .endm
21458+
21459+ .macro pax_exit_kernel
21460+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21461+ call pax_exit_kernel
21462+#endif
21463+
21464+ .endm
21465+
21466+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21467+ENTRY(pax_enter_kernel)
21468+ pushq %rdi
21469+
21470+#ifdef CONFIG_PARAVIRT
21471+ PV_SAVE_REGS(CLBR_RDI)
21472+#endif
21473+
21474+#ifdef CONFIG_PAX_KERNEXEC
21475+ GET_CR0_INTO_RDI
21476+ bts $16,%rdi
21477+ jnc 3f
21478+ mov %cs,%edi
21479+ cmp $__KERNEL_CS,%edi
21480+ jnz 2f
21481+1:
21482+#endif
21483+
21484+#ifdef CONFIG_PAX_MEMORY_UDEREF
21485+ 661: jmp 111f
21486+ .pushsection .altinstr_replacement, "a"
21487+ 662: ASM_NOP2
21488+ .popsection
21489+ .pushsection .altinstructions, "a"
21490+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21491+ .popsection
21492+ GET_CR3_INTO_RDI
21493+ cmp $0,%dil
21494+ jnz 112f
21495+ mov $__KERNEL_DS,%edi
21496+ mov %edi,%ss
21497+ jmp 111f
21498+112: cmp $1,%dil
21499+ jz 113f
21500+ ud2
21501+113: sub $4097,%rdi
21502+ bts $63,%rdi
21503+ SET_RDI_INTO_CR3
21504+ mov $__UDEREF_KERNEL_DS,%edi
21505+ mov %edi,%ss
21506+111:
21507+#endif
21508+
21509+#ifdef CONFIG_PARAVIRT
21510+ PV_RESTORE_REGS(CLBR_RDI)
21511+#endif
21512+
21513+ popq %rdi
21514+ pax_force_retaddr
21515+ retq
21516+
21517+#ifdef CONFIG_PAX_KERNEXEC
21518+2: ljmpq __KERNEL_CS,1b
21519+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21520+4: SET_RDI_INTO_CR0
21521+ jmp 1b
21522+#endif
21523+ENDPROC(pax_enter_kernel)
21524+
21525+ENTRY(pax_exit_kernel)
21526+ pushq %rdi
21527+
21528+#ifdef CONFIG_PARAVIRT
21529+ PV_SAVE_REGS(CLBR_RDI)
21530+#endif
21531+
21532+#ifdef CONFIG_PAX_KERNEXEC
21533+ mov %cs,%rdi
21534+ cmp $__KERNEXEC_KERNEL_CS,%edi
21535+ jz 2f
21536+ GET_CR0_INTO_RDI
21537+ bts $16,%rdi
21538+ jnc 4f
21539+1:
21540+#endif
21541+
21542+#ifdef CONFIG_PAX_MEMORY_UDEREF
21543+ 661: jmp 111f
21544+ .pushsection .altinstr_replacement, "a"
21545+ 662: ASM_NOP2
21546+ .popsection
21547+ .pushsection .altinstructions, "a"
21548+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21549+ .popsection
21550+ mov %ss,%edi
21551+ cmp $__UDEREF_KERNEL_DS,%edi
21552+ jnz 111f
21553+ GET_CR3_INTO_RDI
21554+ cmp $0,%dil
21555+ jz 112f
21556+ ud2
21557+112: add $4097,%rdi
21558+ bts $63,%rdi
21559+ SET_RDI_INTO_CR3
21560+ mov $__KERNEL_DS,%edi
21561+ mov %edi,%ss
21562+111:
21563+#endif
21564+
21565+#ifdef CONFIG_PARAVIRT
21566+ PV_RESTORE_REGS(CLBR_RDI);
21567+#endif
21568+
21569+ popq %rdi
21570+ pax_force_retaddr
21571+ retq
21572+
21573+#ifdef CONFIG_PAX_KERNEXEC
21574+2: GET_CR0_INTO_RDI
21575+ btr $16,%rdi
21576+ jnc 4f
21577+ ljmpq __KERNEL_CS,3f
21578+3: SET_RDI_INTO_CR0
21579+ jmp 1b
21580+4: ud2
21581+ jmp 4b
21582+#endif
21583+ENDPROC(pax_exit_kernel)
21584+#endif
21585+
21586+ .macro pax_enter_kernel_user
21587+ pax_set_fptr_mask
21588+#ifdef CONFIG_PAX_MEMORY_UDEREF
21589+ call pax_enter_kernel_user
21590+#endif
21591+ .endm
21592+
21593+ .macro pax_exit_kernel_user
21594+#ifdef CONFIG_PAX_MEMORY_UDEREF
21595+ call pax_exit_kernel_user
21596+#endif
21597+#ifdef CONFIG_PAX_RANDKSTACK
21598+ pushq %rax
21599+ pushq %r11
21600+ call pax_randomize_kstack
21601+ popq %r11
21602+ popq %rax
21603+#endif
21604+ .endm
21605+
21606+#ifdef CONFIG_PAX_MEMORY_UDEREF
21607+ENTRY(pax_enter_kernel_user)
21608+ pushq %rdi
21609+ pushq %rbx
21610+
21611+#ifdef CONFIG_PARAVIRT
21612+ PV_SAVE_REGS(CLBR_RDI)
21613+#endif
21614+
21615+ 661: jmp 111f
21616+ .pushsection .altinstr_replacement, "a"
21617+ 662: ASM_NOP2
21618+ .popsection
21619+ .pushsection .altinstructions, "a"
21620+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21621+ .popsection
21622+ GET_CR3_INTO_RDI
21623+ cmp $1,%dil
21624+ jnz 4f
21625+ sub $4097,%rdi
21626+ bts $63,%rdi
21627+ SET_RDI_INTO_CR3
21628+ jmp 3f
21629+111:
21630+
21631+ GET_CR3_INTO_RDI
21632+ mov %rdi,%rbx
21633+ add $__START_KERNEL_map,%rbx
21634+ sub phys_base(%rip),%rbx
21635+
21636+#ifdef CONFIG_PARAVIRT
21637+ cmpl $0, pv_info+PARAVIRT_enabled
21638+ jz 1f
21639+ pushq %rdi
21640+ i = 0
21641+ .rept USER_PGD_PTRS
21642+ mov i*8(%rbx),%rsi
21643+ mov $0,%sil
21644+ lea i*8(%rbx),%rdi
21645+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21646+ i = i + 1
21647+ .endr
21648+ popq %rdi
21649+ jmp 2f
21650+1:
21651+#endif
21652+
21653+ i = 0
21654+ .rept USER_PGD_PTRS
21655+ movb $0,i*8(%rbx)
21656+ i = i + 1
21657+ .endr
21658+
21659+2: SET_RDI_INTO_CR3
21660+
21661+#ifdef CONFIG_PAX_KERNEXEC
21662+ GET_CR0_INTO_RDI
21663+ bts $16,%rdi
21664+ SET_RDI_INTO_CR0
21665+#endif
21666+
21667+3:
21668+
21669+#ifdef CONFIG_PARAVIRT
21670+ PV_RESTORE_REGS(CLBR_RDI)
21671+#endif
21672+
21673+ popq %rbx
21674+ popq %rdi
21675+ pax_force_retaddr
21676+ retq
21677+4: ud2
21678+ENDPROC(pax_enter_kernel_user)
21679+
21680+ENTRY(pax_exit_kernel_user)
21681+ pushq %rdi
21682+ pushq %rbx
21683+
21684+#ifdef CONFIG_PARAVIRT
21685+ PV_SAVE_REGS(CLBR_RDI)
21686+#endif
21687+
21688+ GET_CR3_INTO_RDI
21689+ 661: jmp 1f
21690+ .pushsection .altinstr_replacement, "a"
21691+ 662: ASM_NOP2
21692+ .popsection
21693+ .pushsection .altinstructions, "a"
21694+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21695+ .popsection
21696+ cmp $0,%dil
21697+ jnz 3f
21698+ add $4097,%rdi
21699+ bts $63,%rdi
21700+ SET_RDI_INTO_CR3
21701+ jmp 2f
21702+1:
21703+
21704+ mov %rdi,%rbx
21705+
21706+#ifdef CONFIG_PAX_KERNEXEC
21707+ GET_CR0_INTO_RDI
21708+ btr $16,%rdi
21709+ jnc 3f
21710+ SET_RDI_INTO_CR0
21711+#endif
21712+
21713+ add $__START_KERNEL_map,%rbx
21714+ sub phys_base(%rip),%rbx
21715+
21716+#ifdef CONFIG_PARAVIRT
21717+ cmpl $0, pv_info+PARAVIRT_enabled
21718+ jz 1f
21719+ i = 0
21720+ .rept USER_PGD_PTRS
21721+ mov i*8(%rbx),%rsi
21722+ mov $0x67,%sil
21723+ lea i*8(%rbx),%rdi
21724+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21725+ i = i + 1
21726+ .endr
21727+ jmp 2f
21728+1:
21729+#endif
21730+
21731+ i = 0
21732+ .rept USER_PGD_PTRS
21733+ movb $0x67,i*8(%rbx)
21734+ i = i + 1
21735+ .endr
21736+2:
21737+
21738+#ifdef CONFIG_PARAVIRT
21739+ PV_RESTORE_REGS(CLBR_RDI)
21740+#endif
21741+
21742+ popq %rbx
21743+ popq %rdi
21744+ pax_force_retaddr
21745+ retq
21746+3: ud2
21747+ENDPROC(pax_exit_kernel_user)
21748+#endif
21749+
21750+ .macro pax_enter_kernel_nmi
21751+ pax_set_fptr_mask
21752+
21753+#ifdef CONFIG_PAX_KERNEXEC
21754+ GET_CR0_INTO_RDI
21755+ bts $16,%rdi
21756+ jc 110f
21757+ SET_RDI_INTO_CR0
21758+ or $2,%ebx
21759+110:
21760+#endif
21761+
21762+#ifdef CONFIG_PAX_MEMORY_UDEREF
21763+ 661: jmp 111f
21764+ .pushsection .altinstr_replacement, "a"
21765+ 662: ASM_NOP2
21766+ .popsection
21767+ .pushsection .altinstructions, "a"
21768+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21769+ .popsection
21770+ GET_CR3_INTO_RDI
21771+ cmp $0,%dil
21772+ jz 111f
21773+ sub $4097,%rdi
21774+ or $4,%ebx
21775+ bts $63,%rdi
21776+ SET_RDI_INTO_CR3
21777+ mov $__UDEREF_KERNEL_DS,%edi
21778+ mov %edi,%ss
21779+111:
21780+#endif
21781+ .endm
21782+
21783+ .macro pax_exit_kernel_nmi
21784+#ifdef CONFIG_PAX_KERNEXEC
21785+ btr $1,%ebx
21786+ jnc 110f
21787+ GET_CR0_INTO_RDI
21788+ btr $16,%rdi
21789+ SET_RDI_INTO_CR0
21790+110:
21791+#endif
21792+
21793+#ifdef CONFIG_PAX_MEMORY_UDEREF
21794+ btr $2,%ebx
21795+ jnc 111f
21796+ GET_CR3_INTO_RDI
21797+ add $4097,%rdi
21798+ bts $63,%rdi
21799+ SET_RDI_INTO_CR3
21800+ mov $__KERNEL_DS,%edi
21801+ mov %edi,%ss
21802+111:
21803+#endif
21804+ .endm
21805+
21806+ .macro pax_erase_kstack
21807+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21808+ call pax_erase_kstack
21809+#endif
21810+ .endm
21811+
21812+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21813+ENTRY(pax_erase_kstack)
21814+ pushq %rdi
21815+ pushq %rcx
21816+ pushq %rax
21817+ pushq %r11
21818+
21819+ GET_THREAD_INFO(%r11)
21820+ mov TI_lowest_stack(%r11), %rdi
21821+ mov $-0xBEEF, %rax
21822+ std
21823+
21824+1: mov %edi, %ecx
21825+ and $THREAD_SIZE_asm - 1, %ecx
21826+ shr $3, %ecx
21827+ repne scasq
21828+ jecxz 2f
21829+
21830+ cmp $2*8, %ecx
21831+ jc 2f
21832+
21833+ mov $2*8, %ecx
21834+ repe scasq
21835+ jecxz 2f
21836+ jne 1b
21837+
21838+2: cld
21839+ mov %esp, %ecx
21840+ sub %edi, %ecx
21841+
21842+ cmp $THREAD_SIZE_asm, %rcx
21843+ jb 3f
21844+ ud2
21845+3:
21846+
21847+ shr $3, %ecx
21848+ rep stosq
21849+
21850+ mov TI_task_thread_sp0(%r11), %rdi
21851+ sub $256, %rdi
21852+ mov %rdi, TI_lowest_stack(%r11)
21853+
21854+ popq %r11
21855+ popq %rax
21856+ popq %rcx
21857+ popq %rdi
21858+ pax_force_retaddr
21859+ ret
21860+ENDPROC(pax_erase_kstack)
21861+#endif
21862
21863 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21864 #ifdef CONFIG_TRACE_IRQFLAGS
21865@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21866 .endm
21867
21868 .macro UNFAKE_STACK_FRAME
21869- addq $8*6, %rsp
21870- CFI_ADJUST_CFA_OFFSET -(6*8)
21871+ addq $8*6 + ARG_SKIP, %rsp
21872+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21873 .endm
21874
21875 /*
21876@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21877 movq %rsp, %rsi
21878
21879 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21880- testl $3, CS-RBP(%rsi)
21881+ testb $3, CS-RBP(%rsi)
21882 je 1f
21883 SWAPGS
21884 /*
21885@@ -498,9 +931,10 @@ ENTRY(save_rest)
21886 movq_cfi r15, R15+16
21887 movq %r11, 8(%rsp) /* return address */
21888 FIXUP_TOP_OF_STACK %r11, 16
21889+ pax_force_retaddr
21890 ret
21891 CFI_ENDPROC
21892-END(save_rest)
21893+ENDPROC(save_rest)
21894
21895 /* save complete stack frame */
21896 .pushsection .kprobes.text, "ax"
21897@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21898 js 1f /* negative -> in kernel */
21899 SWAPGS
21900 xorl %ebx,%ebx
21901-1: ret
21902+1: pax_force_retaddr_bts
21903+ ret
21904 CFI_ENDPROC
21905-END(save_paranoid)
21906+ENDPROC(save_paranoid)
21907 .popsection
21908
21909 /*
21910@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21911
21912 RESTORE_REST
21913
21914- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21915+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21916 jz 1f
21917
21918 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21919@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21920 RESTORE_REST
21921 jmp int_ret_from_sys_call
21922 CFI_ENDPROC
21923-END(ret_from_fork)
21924+ENDPROC(ret_from_fork)
21925
21926 /*
21927 * System call entry. Up to 6 arguments in registers are supported.
21928@@ -608,7 +1043,7 @@ END(ret_from_fork)
21929 ENTRY(system_call)
21930 CFI_STARTPROC simple
21931 CFI_SIGNAL_FRAME
21932- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21933+ CFI_DEF_CFA rsp,0
21934 CFI_REGISTER rip,rcx
21935 /*CFI_REGISTER rflags,r11*/
21936 SWAPGS_UNSAFE_STACK
21937@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21938
21939 movq %rsp,PER_CPU_VAR(old_rsp)
21940 movq PER_CPU_VAR(kernel_stack),%rsp
21941+ SAVE_ARGS 8*6,0
21942+ pax_enter_kernel_user
21943+
21944+#ifdef CONFIG_PAX_RANDKSTACK
21945+ pax_erase_kstack
21946+#endif
21947+
21948 /*
21949 * No need to follow this irqs off/on section - it's straight
21950 * and short:
21951 */
21952 ENABLE_INTERRUPTS(CLBR_NONE)
21953- SAVE_ARGS 8,0
21954 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21955 movq %rcx,RIP-ARGOFFSET(%rsp)
21956 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21957- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21958+ GET_THREAD_INFO(%rcx)
21959+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21960 jnz tracesys
21961 system_call_fastpath:
21962 #if __SYSCALL_MASK == ~0
21963@@ -640,7 +1082,7 @@ system_call_fastpath:
21964 cmpl $__NR_syscall_max,%eax
21965 #endif
21966 ja badsys
21967- movq %r10,%rcx
21968+ movq R10-ARGOFFSET(%rsp),%rcx
21969 call *sys_call_table(,%rax,8) # XXX: rip relative
21970 movq %rax,RAX-ARGOFFSET(%rsp)
21971 /*
21972@@ -654,10 +1096,13 @@ sysret_check:
21973 LOCKDEP_SYS_EXIT
21974 DISABLE_INTERRUPTS(CLBR_NONE)
21975 TRACE_IRQS_OFF
21976- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21977+ GET_THREAD_INFO(%rcx)
21978+ movl TI_flags(%rcx),%edx
21979 andl %edi,%edx
21980 jnz sysret_careful
21981 CFI_REMEMBER_STATE
21982+ pax_exit_kernel_user
21983+ pax_erase_kstack
21984 /*
21985 * sysretq will re-enable interrupts:
21986 */
21987@@ -709,14 +1154,18 @@ badsys:
21988 * jump back to the normal fast path.
21989 */
21990 auditsys:
21991- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21992+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21993 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21994 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21995 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21996 movq %rax,%rsi /* 2nd arg: syscall number */
21997 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21998 call __audit_syscall_entry
21999+
22000+ pax_erase_kstack
22001+
22002 LOAD_ARGS 0 /* reload call-clobbered registers */
22003+ pax_set_fptr_mask
22004 jmp system_call_fastpath
22005
22006 /*
22007@@ -737,7 +1186,7 @@ sysret_audit:
22008 /* Do syscall tracing */
22009 tracesys:
22010 #ifdef CONFIG_AUDITSYSCALL
22011- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22012+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22013 jz auditsys
22014 #endif
22015 SAVE_REST
22016@@ -745,12 +1194,16 @@ tracesys:
22017 FIXUP_TOP_OF_STACK %rdi
22018 movq %rsp,%rdi
22019 call syscall_trace_enter
22020+
22021+ pax_erase_kstack
22022+
22023 /*
22024 * Reload arg registers from stack in case ptrace changed them.
22025 * We don't reload %rax because syscall_trace_enter() returned
22026 * the value it wants us to use in the table lookup.
22027 */
22028 LOAD_ARGS ARGOFFSET, 1
22029+ pax_set_fptr_mask
22030 RESTORE_REST
22031 #if __SYSCALL_MASK == ~0
22032 cmpq $__NR_syscall_max,%rax
22033@@ -759,7 +1212,7 @@ tracesys:
22034 cmpl $__NR_syscall_max,%eax
22035 #endif
22036 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
22037- movq %r10,%rcx /* fixup for C */
22038+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
22039 call *sys_call_table(,%rax,8)
22040 movq %rax,RAX-ARGOFFSET(%rsp)
22041 /* Use IRET because user could have changed frame */
22042@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
22043 andl %edi,%edx
22044 jnz int_careful
22045 andl $~TS_COMPAT,TI_status(%rcx)
22046- jmp retint_swapgs
22047+ pax_exit_kernel_user
22048+ pax_erase_kstack
22049+ jmp retint_swapgs_pax
22050
22051 /* Either reschedule or signal or syscall exit tracking needed. */
22052 /* First do a reschedule test. */
22053@@ -826,7 +1281,7 @@ int_restore_rest:
22054 TRACE_IRQS_OFF
22055 jmp int_with_check
22056 CFI_ENDPROC
22057-END(system_call)
22058+ENDPROC(system_call)
22059
22060 .macro FORK_LIKE func
22061 ENTRY(stub_\func)
22062@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22063 DEFAULT_FRAME 0 8 /* offset 8: return address */
22064 call sys_\func
22065 RESTORE_TOP_OF_STACK %r11, 8
22066+ pax_force_retaddr
22067 ret $REST_SKIP /* pop extended registers */
22068 CFI_ENDPROC
22069-END(stub_\func)
22070+ENDPROC(stub_\func)
22071 .endm
22072
22073 .macro FIXED_FRAME label,func
22074@@ -851,9 +1307,10 @@ ENTRY(\label)
22075 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22076 call \func
22077 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22078+ pax_force_retaddr
22079 ret
22080 CFI_ENDPROC
22081-END(\label)
22082+ENDPROC(\label)
22083 .endm
22084
22085 FORK_LIKE clone
22086@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22087 movq_cfi_restore R12+8, r12
22088 movq_cfi_restore RBP+8, rbp
22089 movq_cfi_restore RBX+8, rbx
22090+ pax_force_retaddr
22091 ret $REST_SKIP /* pop extended registers */
22092 CFI_ENDPROC
22093-END(ptregscall_common)
22094+ENDPROC(ptregscall_common)
22095
22096 ENTRY(stub_execve)
22097 CFI_STARTPROC
22098@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22099 RESTORE_REST
22100 jmp int_ret_from_sys_call
22101 CFI_ENDPROC
22102-END(stub_execve)
22103+ENDPROC(stub_execve)
22104
22105 /*
22106 * sigreturn is special because it needs to restore all registers on return.
22107@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22108 RESTORE_REST
22109 jmp int_ret_from_sys_call
22110 CFI_ENDPROC
22111-END(stub_rt_sigreturn)
22112+ENDPROC(stub_rt_sigreturn)
22113
22114 #ifdef CONFIG_X86_X32_ABI
22115 ENTRY(stub_x32_rt_sigreturn)
22116@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22117 RESTORE_REST
22118 jmp int_ret_from_sys_call
22119 CFI_ENDPROC
22120-END(stub_x32_rt_sigreturn)
22121+ENDPROC(stub_x32_rt_sigreturn)
22122
22123 ENTRY(stub_x32_execve)
22124 CFI_STARTPROC
22125@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22126 RESTORE_REST
22127 jmp int_ret_from_sys_call
22128 CFI_ENDPROC
22129-END(stub_x32_execve)
22130+ENDPROC(stub_x32_execve)
22131
22132 #endif
22133
22134@@ -967,7 +1425,7 @@ vector=vector+1
22135 2: jmp common_interrupt
22136 .endr
22137 CFI_ENDPROC
22138-END(irq_entries_start)
22139+ENDPROC(irq_entries_start)
22140
22141 .previous
22142 END(interrupt)
22143@@ -987,6 +1445,16 @@ END(interrupt)
22144 subq $ORIG_RAX-RBP, %rsp
22145 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22146 SAVE_ARGS_IRQ
22147+#ifdef CONFIG_PAX_MEMORY_UDEREF
22148+ testb $3, CS(%rdi)
22149+ jnz 1f
22150+ pax_enter_kernel
22151+ jmp 2f
22152+1: pax_enter_kernel_user
22153+2:
22154+#else
22155+ pax_enter_kernel
22156+#endif
22157 call \func
22158 .endm
22159
22160@@ -1019,7 +1487,7 @@ ret_from_intr:
22161
22162 exit_intr:
22163 GET_THREAD_INFO(%rcx)
22164- testl $3,CS-ARGOFFSET(%rsp)
22165+ testb $3,CS-ARGOFFSET(%rsp)
22166 je retint_kernel
22167
22168 /* Interrupt came from user space */
22169@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22170 * The iretq could re-enable interrupts:
22171 */
22172 DISABLE_INTERRUPTS(CLBR_ANY)
22173+ pax_exit_kernel_user
22174+retint_swapgs_pax:
22175 TRACE_IRQS_IRETQ
22176 SWAPGS
22177 jmp restore_args
22178
22179 retint_restore_args: /* return to kernel space */
22180 DISABLE_INTERRUPTS(CLBR_ANY)
22181+ pax_exit_kernel
22182+ pax_force_retaddr (RIP-ARGOFFSET)
22183 /*
22184 * The iretq could re-enable interrupts:
22185 */
22186@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22187 #endif
22188
22189 CFI_ENDPROC
22190-END(common_interrupt)
22191+ENDPROC(common_interrupt)
22192 /*
22193 * End of kprobes section
22194 */
22195@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22196 interrupt \do_sym
22197 jmp ret_from_intr
22198 CFI_ENDPROC
22199-END(\sym)
22200+ENDPROC(\sym)
22201 .endm
22202
22203 #ifdef CONFIG_TRACING
22204@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22205 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22206 call error_entry
22207 DEFAULT_FRAME 0
22208+#ifdef CONFIG_PAX_MEMORY_UDEREF
22209+ testb $3, CS(%rsp)
22210+ jnz 1f
22211+ pax_enter_kernel
22212+ jmp 2f
22213+1: pax_enter_kernel_user
22214+2:
22215+#else
22216+ pax_enter_kernel
22217+#endif
22218 movq %rsp,%rdi /* pt_regs pointer */
22219 xorl %esi,%esi /* no error code */
22220 call \do_sym
22221 jmp error_exit /* %ebx: no swapgs flag */
22222 CFI_ENDPROC
22223-END(\sym)
22224+ENDPROC(\sym)
22225 .endm
22226
22227 .macro paranoidzeroentry sym do_sym
22228@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22229 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22230 call save_paranoid
22231 TRACE_IRQS_OFF
22232+#ifdef CONFIG_PAX_MEMORY_UDEREF
22233+ testb $3, CS(%rsp)
22234+ jnz 1f
22235+ pax_enter_kernel
22236+ jmp 2f
22237+1: pax_enter_kernel_user
22238+2:
22239+#else
22240+ pax_enter_kernel
22241+#endif
22242 movq %rsp,%rdi /* pt_regs pointer */
22243 xorl %esi,%esi /* no error code */
22244 call \do_sym
22245 jmp paranoid_exit /* %ebx: no swapgs flag */
22246 CFI_ENDPROC
22247-END(\sym)
22248+ENDPROC(\sym)
22249 .endm
22250
22251-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22252+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22253 .macro paranoidzeroentry_ist sym do_sym ist
22254 ENTRY(\sym)
22255 INTR_FRAME
22256@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22257 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22258 call save_paranoid
22259 TRACE_IRQS_OFF_DEBUG
22260+#ifdef CONFIG_PAX_MEMORY_UDEREF
22261+ testb $3, CS(%rsp)
22262+ jnz 1f
22263+ pax_enter_kernel
22264+ jmp 2f
22265+1: pax_enter_kernel_user
22266+2:
22267+#else
22268+ pax_enter_kernel
22269+#endif
22270 movq %rsp,%rdi /* pt_regs pointer */
22271 xorl %esi,%esi /* no error code */
22272+#ifdef CONFIG_SMP
22273+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22274+ lea init_tss(%r12), %r12
22275+#else
22276+ lea init_tss(%rip), %r12
22277+#endif
22278 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22279 call \do_sym
22280 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22281 jmp paranoid_exit /* %ebx: no swapgs flag */
22282 CFI_ENDPROC
22283-END(\sym)
22284+ENDPROC(\sym)
22285 .endm
22286
22287 .macro errorentry sym do_sym
22288@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22289 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22290 call error_entry
22291 DEFAULT_FRAME 0
22292+#ifdef CONFIG_PAX_MEMORY_UDEREF
22293+ testb $3, CS(%rsp)
22294+ jnz 1f
22295+ pax_enter_kernel
22296+ jmp 2f
22297+1: pax_enter_kernel_user
22298+2:
22299+#else
22300+ pax_enter_kernel
22301+#endif
22302 movq %rsp,%rdi /* pt_regs pointer */
22303 movq ORIG_RAX(%rsp),%rsi /* get error code */
22304 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22305 call \do_sym
22306 jmp error_exit /* %ebx: no swapgs flag */
22307 CFI_ENDPROC
22308-END(\sym)
22309+ENDPROC(\sym)
22310 .endm
22311
22312 /* error code is on the stack already */
22313@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22314 call save_paranoid
22315 DEFAULT_FRAME 0
22316 TRACE_IRQS_OFF
22317+#ifdef CONFIG_PAX_MEMORY_UDEREF
22318+ testb $3, CS(%rsp)
22319+ jnz 1f
22320+ pax_enter_kernel
22321+ jmp 2f
22322+1: pax_enter_kernel_user
22323+2:
22324+#else
22325+ pax_enter_kernel
22326+#endif
22327 movq %rsp,%rdi /* pt_regs pointer */
22328 movq ORIG_RAX(%rsp),%rsi /* get error code */
22329 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22330 call \do_sym
22331 jmp paranoid_exit /* %ebx: no swapgs flag */
22332 CFI_ENDPROC
22333-END(\sym)
22334+ENDPROC(\sym)
22335 .endm
22336
22337 zeroentry divide_error do_divide_error
22338@@ -1342,9 +1870,10 @@ gs_change:
22339 2: mfence /* workaround */
22340 SWAPGS
22341 popfq_cfi
22342+ pax_force_retaddr
22343 ret
22344 CFI_ENDPROC
22345-END(native_load_gs_index)
22346+ENDPROC(native_load_gs_index)
22347
22348 _ASM_EXTABLE(gs_change,bad_gs)
22349 .section .fixup,"ax"
22350@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22351 CFI_DEF_CFA_REGISTER rsp
22352 CFI_ADJUST_CFA_OFFSET -8
22353 decl PER_CPU_VAR(irq_count)
22354+ pax_force_retaddr
22355 ret
22356 CFI_ENDPROC
22357-END(call_softirq)
22358+ENDPROC(call_softirq)
22359
22360 #ifdef CONFIG_XEN
22361 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22362@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22363 decl PER_CPU_VAR(irq_count)
22364 jmp error_exit
22365 CFI_ENDPROC
22366-END(xen_do_hypervisor_callback)
22367+ENDPROC(xen_do_hypervisor_callback)
22368
22369 /*
22370 * Hypervisor uses this for application faults while it executes.
22371@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22372 SAVE_ALL
22373 jmp error_exit
22374 CFI_ENDPROC
22375-END(xen_failsafe_callback)
22376+ENDPROC(xen_failsafe_callback)
22377
22378 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22379 xen_hvm_callback_vector xen_evtchn_do_upcall
22380@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22381 DEFAULT_FRAME
22382 DISABLE_INTERRUPTS(CLBR_NONE)
22383 TRACE_IRQS_OFF_DEBUG
22384- testl %ebx,%ebx /* swapgs needed? */
22385+ testl $1,%ebx /* swapgs needed? */
22386 jnz paranoid_restore
22387- testl $3,CS(%rsp)
22388+ testb $3,CS(%rsp)
22389 jnz paranoid_userspace
22390+#ifdef CONFIG_PAX_MEMORY_UDEREF
22391+ pax_exit_kernel
22392+ TRACE_IRQS_IRETQ 0
22393+ SWAPGS_UNSAFE_STACK
22394+ RESTORE_ALL 8
22395+ pax_force_retaddr_bts
22396+ jmp irq_return
22397+#endif
22398 paranoid_swapgs:
22399+#ifdef CONFIG_PAX_MEMORY_UDEREF
22400+ pax_exit_kernel_user
22401+#else
22402+ pax_exit_kernel
22403+#endif
22404 TRACE_IRQS_IRETQ 0
22405 SWAPGS_UNSAFE_STACK
22406 RESTORE_ALL 8
22407 jmp irq_return
22408 paranoid_restore:
22409+ pax_exit_kernel
22410 TRACE_IRQS_IRETQ_DEBUG 0
22411 RESTORE_ALL 8
22412+ pax_force_retaddr_bts
22413 jmp irq_return
22414 paranoid_userspace:
22415 GET_THREAD_INFO(%rcx)
22416@@ -1563,7 +2108,7 @@ paranoid_schedule:
22417 TRACE_IRQS_OFF
22418 jmp paranoid_userspace
22419 CFI_ENDPROC
22420-END(paranoid_exit)
22421+ENDPROC(paranoid_exit)
22422
22423 /*
22424 * Exception entry point. This expects an error code/orig_rax on the stack.
22425@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22426 movq_cfi r14, R14+8
22427 movq_cfi r15, R15+8
22428 xorl %ebx,%ebx
22429- testl $3,CS+8(%rsp)
22430+ testb $3,CS+8(%rsp)
22431 je error_kernelspace
22432 error_swapgs:
22433 SWAPGS
22434 error_sti:
22435 TRACE_IRQS_OFF
22436+ pax_force_retaddr_bts
22437 ret
22438
22439 /*
22440@@ -1622,7 +2168,7 @@ bstep_iret:
22441 movq %rcx,RIP+8(%rsp)
22442 jmp error_swapgs
22443 CFI_ENDPROC
22444-END(error_entry)
22445+ENDPROC(error_entry)
22446
22447
22448 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22449@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22450 DISABLE_INTERRUPTS(CLBR_NONE)
22451 TRACE_IRQS_OFF
22452 GET_THREAD_INFO(%rcx)
22453- testl %eax,%eax
22454+ testl $1,%eax
22455 jne retint_kernel
22456 LOCKDEP_SYS_EXIT_IRQ
22457 movl TI_flags(%rcx),%edx
22458@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22459 jnz retint_careful
22460 jmp retint_swapgs
22461 CFI_ENDPROC
22462-END(error_exit)
22463+ENDPROC(error_exit)
22464
22465 /*
22466 * Test if a given stack is an NMI stack or not.
22467@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22468 * If %cs was not the kernel segment, then the NMI triggered in user
22469 * space, which means it is definitely not nested.
22470 */
22471+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22472+ je 1f
22473 cmpl $__KERNEL_CS, 16(%rsp)
22474 jne first_nmi
22475-
22476+1:
22477 /*
22478 * Check the special variable on the stack to see if NMIs are
22479 * executing.
22480@@ -1736,8 +2284,7 @@ nested_nmi:
22481
22482 1:
22483 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22484- leaq -1*8(%rsp), %rdx
22485- movq %rdx, %rsp
22486+ subq $8, %rsp
22487 CFI_ADJUST_CFA_OFFSET 1*8
22488 leaq -10*8(%rsp), %rdx
22489 pushq_cfi $__KERNEL_DS
22490@@ -1755,6 +2302,7 @@ nested_nmi_out:
22491 CFI_RESTORE rdx
22492
22493 /* No need to check faults here */
22494+# pax_force_retaddr_bts
22495 INTERRUPT_RETURN
22496
22497 CFI_RESTORE_STATE
22498@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22499 */
22500 movq %cr2, %r12
22501
22502+ pax_enter_kernel_nmi
22503+
22504 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22505 movq %rsp,%rdi
22506 movq $-1,%rsi
22507@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22508 movq %r12, %cr2
22509 1:
22510
22511- testl %ebx,%ebx /* swapgs needed? */
22512+ testl $1,%ebx /* swapgs needed? */
22513 jnz nmi_restore
22514 nmi_swapgs:
22515 SWAPGS_UNSAFE_STACK
22516 nmi_restore:
22517+ pax_exit_kernel_nmi
22518 /* Pop the extra iret frame at once */
22519 RESTORE_ALL 6*8
22520+ testb $3, 8(%rsp)
22521+ jnz 1f
22522+ pax_force_retaddr_bts
22523+1:
22524
22525 /* Clear the NMI executing stack variable */
22526 movq $0, 5*8(%rsp)
22527 jmp irq_return
22528 CFI_ENDPROC
22529-END(nmi)
22530+ENDPROC(nmi)
22531
22532 ENTRY(ignore_sysret)
22533 CFI_STARTPROC
22534 mov $-ENOSYS,%eax
22535 sysret
22536 CFI_ENDPROC
22537-END(ignore_sysret)
22538+ENDPROC(ignore_sysret)
22539
22540 /*
22541 * End of kprobes section
22542diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22543index 42a392a..fbbd930 100644
22544--- a/arch/x86/kernel/ftrace.c
22545+++ b/arch/x86/kernel/ftrace.c
22546@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22547 {
22548 unsigned char replaced[MCOUNT_INSN_SIZE];
22549
22550+ ip = ktla_ktva(ip);
22551+
22552 /*
22553 * Note: Due to modules and __init, code can
22554 * disappear and change, we need to protect against faulting
22555@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22556 unsigned char old[MCOUNT_INSN_SIZE], *new;
22557 int ret;
22558
22559- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22560+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22561 new = ftrace_call_replace(ip, (unsigned long)func);
22562
22563 /* See comment above by declaration of modifying_ftrace_code */
22564@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22565 /* Also update the regs callback function */
22566 if (!ret) {
22567 ip = (unsigned long)(&ftrace_regs_call);
22568- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22569+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22570 new = ftrace_call_replace(ip, (unsigned long)func);
22571 ret = ftrace_modify_code(ip, old, new);
22572 }
22573@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22574 * kernel identity mapping to modify code.
22575 */
22576 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22577- ip = (unsigned long)__va(__pa_symbol(ip));
22578+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22579
22580 return probe_kernel_write((void *)ip, val, size);
22581 }
22582@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22583 unsigned char replaced[MCOUNT_INSN_SIZE];
22584 unsigned char brk = BREAKPOINT_INSTRUCTION;
22585
22586- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22587+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22588 return -EFAULT;
22589
22590 /* Make sure it is what we expect it to be */
22591@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22592 return ret;
22593
22594 fail_update:
22595- probe_kernel_write((void *)ip, &old_code[0], 1);
22596+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22597 goto out;
22598 }
22599
22600@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22601 {
22602 unsigned char code[MCOUNT_INSN_SIZE];
22603
22604+ ip = ktla_ktva(ip);
22605+
22606 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22607 return -EFAULT;
22608
22609diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22610index 55b6761..a6456fc 100644
22611--- a/arch/x86/kernel/head64.c
22612+++ b/arch/x86/kernel/head64.c
22613@@ -67,12 +67,12 @@ again:
22614 pgd = *pgd_p;
22615
22616 /*
22617- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22618- * critical -- __PAGE_OFFSET would point us back into the dynamic
22619+ * The use of __early_va rather than __va here is critical:
22620+ * __va would point us back into the dynamic
22621 * range and we might end up looping forever...
22622 */
22623 if (pgd)
22624- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22625+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22626 else {
22627 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22628 reset_early_page_tables();
22629@@ -82,13 +82,13 @@ again:
22630 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22631 for (i = 0; i < PTRS_PER_PUD; i++)
22632 pud_p[i] = 0;
22633- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22634+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22635 }
22636 pud_p += pud_index(address);
22637 pud = *pud_p;
22638
22639 if (pud)
22640- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22641+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22642 else {
22643 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22644 reset_early_page_tables();
22645@@ -98,7 +98,7 @@ again:
22646 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22647 for (i = 0; i < PTRS_PER_PMD; i++)
22648 pmd_p[i] = 0;
22649- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22650+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22651 }
22652 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22653 pmd_p[pmd_index(address)] = pmd;
22654@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22655 if (console_loglevel == 10)
22656 early_printk("Kernel alive\n");
22657
22658- clear_page(init_level4_pgt);
22659 /* set init_level4_pgt kernel high mapping*/
22660 init_level4_pgt[511] = early_level4_pgt[511];
22661
22662diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22663index 5dd87a8..d68b3f4 100644
22664--- a/arch/x86/kernel/head_32.S
22665+++ b/arch/x86/kernel/head_32.S
22666@@ -26,6 +26,12 @@
22667 /* Physical address */
22668 #define pa(X) ((X) - __PAGE_OFFSET)
22669
22670+#ifdef CONFIG_PAX_KERNEXEC
22671+#define ta(X) (X)
22672+#else
22673+#define ta(X) ((X) - __PAGE_OFFSET)
22674+#endif
22675+
22676 /*
22677 * References to members of the new_cpu_data structure.
22678 */
22679@@ -55,11 +61,7 @@
22680 * and small than max_low_pfn, otherwise will waste some page table entries
22681 */
22682
22683-#if PTRS_PER_PMD > 1
22684-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22685-#else
22686-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22687-#endif
22688+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22689
22690 /* Number of possible pages in the lowmem region */
22691 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22692@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22693 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22694
22695 /*
22696+ * Real beginning of normal "text" segment
22697+ */
22698+ENTRY(stext)
22699+ENTRY(_stext)
22700+
22701+/*
22702 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22703 * %esi points to the real-mode code as a 32-bit pointer.
22704 * CS and DS must be 4 GB flat segments, but we don't depend on
22705@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22706 * can.
22707 */
22708 __HEAD
22709+
22710+#ifdef CONFIG_PAX_KERNEXEC
22711+ jmp startup_32
22712+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22713+.fill PAGE_SIZE-5,1,0xcc
22714+#endif
22715+
22716 ENTRY(startup_32)
22717 movl pa(stack_start),%ecx
22718
22719@@ -106,6 +121,59 @@ ENTRY(startup_32)
22720 2:
22721 leal -__PAGE_OFFSET(%ecx),%esp
22722
22723+#ifdef CONFIG_SMP
22724+ movl $pa(cpu_gdt_table),%edi
22725+ movl $__per_cpu_load,%eax
22726+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22727+ rorl $16,%eax
22728+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22729+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22730+ movl $__per_cpu_end - 1,%eax
22731+ subl $__per_cpu_start,%eax
22732+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22733+#endif
22734+
22735+#ifdef CONFIG_PAX_MEMORY_UDEREF
22736+ movl $NR_CPUS,%ecx
22737+ movl $pa(cpu_gdt_table),%edi
22738+1:
22739+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22740+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22741+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22742+ addl $PAGE_SIZE_asm,%edi
22743+ loop 1b
22744+#endif
22745+
22746+#ifdef CONFIG_PAX_KERNEXEC
22747+ movl $pa(boot_gdt),%edi
22748+ movl $__LOAD_PHYSICAL_ADDR,%eax
22749+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22750+ rorl $16,%eax
22751+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22752+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22753+ rorl $16,%eax
22754+
22755+ ljmp $(__BOOT_CS),$1f
22756+1:
22757+
22758+ movl $NR_CPUS,%ecx
22759+ movl $pa(cpu_gdt_table),%edi
22760+ addl $__PAGE_OFFSET,%eax
22761+1:
22762+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22763+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22764+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22765+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22766+ rorl $16,%eax
22767+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22768+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22769+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22770+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22771+ rorl $16,%eax
22772+ addl $PAGE_SIZE_asm,%edi
22773+ loop 1b
22774+#endif
22775+
22776 /*
22777 * Clear BSS first so that there are no surprises...
22778 */
22779@@ -201,8 +269,11 @@ ENTRY(startup_32)
22780 movl %eax, pa(max_pfn_mapped)
22781
22782 /* Do early initialization of the fixmap area */
22783- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22784- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22785+#ifdef CONFIG_COMPAT_VDSO
22786+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22787+#else
22788+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22789+#endif
22790 #else /* Not PAE */
22791
22792 page_pde_offset = (__PAGE_OFFSET >> 20);
22793@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22794 movl %eax, pa(max_pfn_mapped)
22795
22796 /* Do early initialization of the fixmap area */
22797- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22798- movl %eax,pa(initial_page_table+0xffc)
22799+#ifdef CONFIG_COMPAT_VDSO
22800+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22801+#else
22802+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22803+#endif
22804 #endif
22805
22806 #ifdef CONFIG_PARAVIRT
22807@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22808 cmpl $num_subarch_entries, %eax
22809 jae bad_subarch
22810
22811- movl pa(subarch_entries)(,%eax,4), %eax
22812- subl $__PAGE_OFFSET, %eax
22813- jmp *%eax
22814+ jmp *pa(subarch_entries)(,%eax,4)
22815
22816 bad_subarch:
22817 WEAK(lguest_entry)
22818@@ -261,10 +333,10 @@ WEAK(xen_entry)
22819 __INITDATA
22820
22821 subarch_entries:
22822- .long default_entry /* normal x86/PC */
22823- .long lguest_entry /* lguest hypervisor */
22824- .long xen_entry /* Xen hypervisor */
22825- .long default_entry /* Moorestown MID */
22826+ .long ta(default_entry) /* normal x86/PC */
22827+ .long ta(lguest_entry) /* lguest hypervisor */
22828+ .long ta(xen_entry) /* Xen hypervisor */
22829+ .long ta(default_entry) /* Moorestown MID */
22830 num_subarch_entries = (. - subarch_entries) / 4
22831 .previous
22832 #else
22833@@ -354,6 +426,7 @@ default_entry:
22834 movl pa(mmu_cr4_features),%eax
22835 movl %eax,%cr4
22836
22837+#ifdef CONFIG_X86_PAE
22838 testb $X86_CR4_PAE, %al # check if PAE is enabled
22839 jz enable_paging
22840
22841@@ -382,6 +455,9 @@ default_entry:
22842 /* Make changes effective */
22843 wrmsr
22844
22845+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22846+#endif
22847+
22848 enable_paging:
22849
22850 /*
22851@@ -449,14 +525,20 @@ is486:
22852 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22853 movl %eax,%ss # after changing gdt.
22854
22855- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22856+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22857 movl %eax,%ds
22858 movl %eax,%es
22859
22860 movl $(__KERNEL_PERCPU), %eax
22861 movl %eax,%fs # set this cpu's percpu
22862
22863+#ifdef CONFIG_CC_STACKPROTECTOR
22864 movl $(__KERNEL_STACK_CANARY),%eax
22865+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22866+ movl $(__USER_DS),%eax
22867+#else
22868+ xorl %eax,%eax
22869+#endif
22870 movl %eax,%gs
22871
22872 xorl %eax,%eax # Clear LDT
22873@@ -512,8 +594,11 @@ setup_once:
22874 * relocation. Manually set base address in stack canary
22875 * segment descriptor.
22876 */
22877- movl $gdt_page,%eax
22878+ movl $cpu_gdt_table,%eax
22879 movl $stack_canary,%ecx
22880+#ifdef CONFIG_SMP
22881+ addl $__per_cpu_load,%ecx
22882+#endif
22883 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22884 shrl $16, %ecx
22885 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22886@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22887 /* This is global to keep gas from relaxing the jumps */
22888 ENTRY(early_idt_handler)
22889 cld
22890- cmpl $2,%ss:early_recursion_flag
22891+ cmpl $1,%ss:early_recursion_flag
22892 je hlt_loop
22893 incl %ss:early_recursion_flag
22894
22895@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22896 pushl (20+6*4)(%esp) /* trapno */
22897 pushl $fault_msg
22898 call printk
22899-#endif
22900 call dump_stack
22901+#endif
22902 hlt_loop:
22903 hlt
22904 jmp hlt_loop
22905@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22906 /* This is the default interrupt "handler" :-) */
22907 ALIGN
22908 ignore_int:
22909- cld
22910 #ifdef CONFIG_PRINTK
22911+ cmpl $2,%ss:early_recursion_flag
22912+ je hlt_loop
22913+ incl %ss:early_recursion_flag
22914+ cld
22915 pushl %eax
22916 pushl %ecx
22917 pushl %edx
22918@@ -612,9 +700,6 @@ ignore_int:
22919 movl $(__KERNEL_DS),%eax
22920 movl %eax,%ds
22921 movl %eax,%es
22922- cmpl $2,early_recursion_flag
22923- je hlt_loop
22924- incl early_recursion_flag
22925 pushl 16(%esp)
22926 pushl 24(%esp)
22927 pushl 32(%esp)
22928@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22929 /*
22930 * BSS section
22931 */
22932-__PAGE_ALIGNED_BSS
22933- .align PAGE_SIZE
22934 #ifdef CONFIG_X86_PAE
22935+.section .initial_pg_pmd,"a",@progbits
22936 initial_pg_pmd:
22937 .fill 1024*KPMDS,4,0
22938 #else
22939+.section .initial_page_table,"a",@progbits
22940 ENTRY(initial_page_table)
22941 .fill 1024,4,0
22942 #endif
22943+.section .initial_pg_fixmap,"a",@progbits
22944 initial_pg_fixmap:
22945 .fill 1024,4,0
22946+.section .empty_zero_page,"a",@progbits
22947 ENTRY(empty_zero_page)
22948 .fill 4096,1,0
22949+.section .swapper_pg_dir,"a",@progbits
22950 ENTRY(swapper_pg_dir)
22951+#ifdef CONFIG_X86_PAE
22952+ .fill 4,8,0
22953+#else
22954 .fill 1024,4,0
22955+#endif
22956
22957 /*
22958 * This starts the data section.
22959 */
22960 #ifdef CONFIG_X86_PAE
22961-__PAGE_ALIGNED_DATA
22962- /* Page-aligned for the benefit of paravirt? */
22963- .align PAGE_SIZE
22964+.section .initial_page_table,"a",@progbits
22965 ENTRY(initial_page_table)
22966 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22967 # if KPMDS == 3
22968@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22969 # error "Kernel PMDs should be 1, 2 or 3"
22970 # endif
22971 .align PAGE_SIZE /* needs to be page-sized too */
22972+
22973+#ifdef CONFIG_PAX_PER_CPU_PGD
22974+ENTRY(cpu_pgd)
22975+ .rept 2*NR_CPUS
22976+ .fill 4,8,0
22977+ .endr
22978+#endif
22979+
22980 #endif
22981
22982 .data
22983 .balign 4
22984 ENTRY(stack_start)
22985- .long init_thread_union+THREAD_SIZE
22986+ .long init_thread_union+THREAD_SIZE-8
22987
22988 __INITRODATA
22989 int_msg:
22990@@ -722,7 +820,7 @@ fault_msg:
22991 * segment size, and 32-bit linear address value:
22992 */
22993
22994- .data
22995+.section .rodata,"a",@progbits
22996 .globl boot_gdt_descr
22997 .globl idt_descr
22998
22999@@ -731,7 +829,7 @@ fault_msg:
23000 .word 0 # 32 bit align gdt_desc.address
23001 boot_gdt_descr:
23002 .word __BOOT_DS+7
23003- .long boot_gdt - __PAGE_OFFSET
23004+ .long pa(boot_gdt)
23005
23006 .word 0 # 32-bit align idt_desc.address
23007 idt_descr:
23008@@ -742,7 +840,7 @@ idt_descr:
23009 .word 0 # 32 bit align gdt_desc.address
23010 ENTRY(early_gdt_descr)
23011 .word GDT_ENTRIES*8-1
23012- .long gdt_page /* Overwritten for secondary CPUs */
23013+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23014
23015 /*
23016 * The boot_gdt must mirror the equivalent in setup.S and is
23017@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23018 .align L1_CACHE_BYTES
23019 ENTRY(boot_gdt)
23020 .fill GDT_ENTRY_BOOT_CS,8,0
23021- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23022- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23023+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23024+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23025+
23026+ .align PAGE_SIZE_asm
23027+ENTRY(cpu_gdt_table)
23028+ .rept NR_CPUS
23029+ .quad 0x0000000000000000 /* NULL descriptor */
23030+ .quad 0x0000000000000000 /* 0x0b reserved */
23031+ .quad 0x0000000000000000 /* 0x13 reserved */
23032+ .quad 0x0000000000000000 /* 0x1b reserved */
23033+
23034+#ifdef CONFIG_PAX_KERNEXEC
23035+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23036+#else
23037+ .quad 0x0000000000000000 /* 0x20 unused */
23038+#endif
23039+
23040+ .quad 0x0000000000000000 /* 0x28 unused */
23041+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23042+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23043+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23044+ .quad 0x0000000000000000 /* 0x4b reserved */
23045+ .quad 0x0000000000000000 /* 0x53 reserved */
23046+ .quad 0x0000000000000000 /* 0x5b reserved */
23047+
23048+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23049+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23050+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23051+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23052+
23053+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23054+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23055+
23056+ /*
23057+ * Segments used for calling PnP BIOS have byte granularity.
23058+ * The code segments and data segments have fixed 64k limits,
23059+ * the transfer segment sizes are set at run time.
23060+ */
23061+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23062+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23063+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23064+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23065+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23066+
23067+ /*
23068+ * The APM segments have byte granularity and their bases
23069+ * are set at run time. All have 64k limits.
23070+ */
23071+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23072+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23073+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23074+
23075+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23076+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23077+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23078+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23079+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23080+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23081+
23082+ /* Be sure this is zeroed to avoid false validations in Xen */
23083+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23084+ .endr
23085diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23086index e1aabdb..73dcad8 100644
23087--- a/arch/x86/kernel/head_64.S
23088+++ b/arch/x86/kernel/head_64.S
23089@@ -20,6 +20,8 @@
23090 #include <asm/processor-flags.h>
23091 #include <asm/percpu.h>
23092 #include <asm/nops.h>
23093+#include <asm/cpufeature.h>
23094+#include <asm/alternative-asm.h>
23095
23096 #ifdef CONFIG_PARAVIRT
23097 #include <asm/asm-offsets.h>
23098@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23099 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23100 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23101 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23102+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23103+L3_VMALLOC_START = pud_index(VMALLOC_START)
23104+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23105+L3_VMALLOC_END = pud_index(VMALLOC_END)
23106+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23107+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23108
23109 .text
23110 __HEAD
23111@@ -89,11 +97,23 @@ startup_64:
23112 * Fixup the physical addresses in the page table
23113 */
23114 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23115+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23116+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23117+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23118+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23119+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23120
23121- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23122- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23123+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23124+#ifndef CONFIG_XEN
23125+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23126+#endif
23127
23128- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23129+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23130+
23131+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23132+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23133+
23134+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23135
23136 /*
23137 * Set up the identity mapping for the switchover. These
23138@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23139 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23140 1:
23141
23142- /* Enable PAE mode and PGE */
23143- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23144+ /* Enable PAE mode and PSE/PGE */
23145+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23146 movq %rcx, %cr4
23147
23148 /* Setup early boot stage 4 level pagetables. */
23149@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23150 movl $MSR_EFER, %ecx
23151 rdmsr
23152 btsl $_EFER_SCE, %eax /* Enable System Call */
23153- btl $20,%edi /* No Execute supported? */
23154+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23155 jnc 1f
23156 btsl $_EFER_NX, %eax
23157 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23158+ leaq init_level4_pgt(%rip), %rdi
23159+#ifndef CONFIG_EFI
23160+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23161+#endif
23162+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23163+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23164+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23165+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23166 1: wrmsr /* Make changes effective */
23167
23168 /* Setup cr0 */
23169@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23170 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23171 * address given in m16:64.
23172 */
23173+ pax_set_fptr_mask
23174 movq initial_code(%rip),%rax
23175 pushq $0 # fake return address to stop unwinder
23176 pushq $__KERNEL_CS # set correct cs
23177@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23178 call dump_stack
23179 #ifdef CONFIG_KALLSYMS
23180 leaq early_idt_ripmsg(%rip),%rdi
23181- movq 40(%rsp),%rsi # %rip again
23182+ movq 88(%rsp),%rsi # %rip again
23183 call __print_symbol
23184 #endif
23185 #endif /* EARLY_PRINTK */
23186@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23187 early_recursion_flag:
23188 .long 0
23189
23190+ .section .rodata,"a",@progbits
23191 #ifdef CONFIG_EARLY_PRINTK
23192 early_idt_msg:
23193 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23194@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23195 NEXT_PAGE(early_dynamic_pgts)
23196 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23197
23198- .data
23199+ .section .rodata,"a",@progbits
23200
23201-#ifndef CONFIG_XEN
23202 NEXT_PAGE(init_level4_pgt)
23203- .fill 512,8,0
23204-#else
23205-NEXT_PAGE(init_level4_pgt)
23206- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23207 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23208 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23209+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23210+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23211+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23212+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23213+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23214+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23215 .org init_level4_pgt + L4_START_KERNEL*8, 0
23216 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23217 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23218
23219+#ifdef CONFIG_PAX_PER_CPU_PGD
23220+NEXT_PAGE(cpu_pgd)
23221+ .rept 2*NR_CPUS
23222+ .fill 512,8,0
23223+ .endr
23224+#endif
23225+
23226 NEXT_PAGE(level3_ident_pgt)
23227 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23228+#ifdef CONFIG_XEN
23229 .fill 511, 8, 0
23230+#else
23231+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23232+ .fill 510,8,0
23233+#endif
23234+
23235+NEXT_PAGE(level3_vmalloc_start_pgt)
23236+ .fill 512,8,0
23237+
23238+NEXT_PAGE(level3_vmalloc_end_pgt)
23239+ .fill 512,8,0
23240+
23241+NEXT_PAGE(level3_vmemmap_pgt)
23242+ .fill L3_VMEMMAP_START,8,0
23243+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23244+
23245 NEXT_PAGE(level2_ident_pgt)
23246- /* Since I easily can, map the first 1G.
23247+ /* Since I easily can, map the first 2G.
23248 * Don't set NX because code runs from these pages.
23249 */
23250- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23251-#endif
23252+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23253
23254 NEXT_PAGE(level3_kernel_pgt)
23255 .fill L3_START_KERNEL,8,0
23256@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23257 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23258 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23259
23260+NEXT_PAGE(level2_vmemmap_pgt)
23261+ .fill 512,8,0
23262+
23263 NEXT_PAGE(level2_kernel_pgt)
23264 /*
23265 * 512 MB kernel mapping. We spend a full page on this pagetable
23266@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23267 KERNEL_IMAGE_SIZE/PMD_SIZE)
23268
23269 NEXT_PAGE(level2_fixmap_pgt)
23270- .fill 506,8,0
23271- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23272- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23273- .fill 5,8,0
23274+ .fill 507,8,0
23275+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23276+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23277+ .fill 4,8,0
23278
23279-NEXT_PAGE(level1_fixmap_pgt)
23280+NEXT_PAGE(level1_vsyscall_pgt)
23281 .fill 512,8,0
23282
23283 #undef PMDS
23284
23285- .data
23286+ .align PAGE_SIZE
23287+ENTRY(cpu_gdt_table)
23288+ .rept NR_CPUS
23289+ .quad 0x0000000000000000 /* NULL descriptor */
23290+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23291+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23292+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23293+ .quad 0x00cffb000000ffff /* __USER32_CS */
23294+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23295+ .quad 0x00affb000000ffff /* __USER_CS */
23296+
23297+#ifdef CONFIG_PAX_KERNEXEC
23298+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23299+#else
23300+ .quad 0x0 /* unused */
23301+#endif
23302+
23303+ .quad 0,0 /* TSS */
23304+ .quad 0,0 /* LDT */
23305+ .quad 0,0,0 /* three TLS descriptors */
23306+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23307+ /* asm/segment.h:GDT_ENTRIES must match this */
23308+
23309+#ifdef CONFIG_PAX_MEMORY_UDEREF
23310+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23311+#else
23312+ .quad 0x0 /* unused */
23313+#endif
23314+
23315+ /* zero the remaining page */
23316+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23317+ .endr
23318+
23319 .align 16
23320 .globl early_gdt_descr
23321 early_gdt_descr:
23322 .word GDT_ENTRIES*8-1
23323 early_gdt_descr_base:
23324- .quad INIT_PER_CPU_VAR(gdt_page)
23325+ .quad cpu_gdt_table
23326
23327 ENTRY(phys_base)
23328 /* This must match the first entry in level2_kernel_pgt */
23329 .quad 0x0000000000000000
23330
23331 #include "../../x86/xen/xen-head.S"
23332-
23333- __PAGE_ALIGNED_BSS
23334+
23335+ .section .rodata,"a",@progbits
23336 NEXT_PAGE(empty_zero_page)
23337 .skip PAGE_SIZE
23338diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23339index 0fa6912..b37438b 100644
23340--- a/arch/x86/kernel/i386_ksyms_32.c
23341+++ b/arch/x86/kernel/i386_ksyms_32.c
23342@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23343 EXPORT_SYMBOL(cmpxchg8b_emu);
23344 #endif
23345
23346+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23347+
23348 /* Networking helper routines. */
23349 EXPORT_SYMBOL(csum_partial_copy_generic);
23350+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23351+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23352
23353 EXPORT_SYMBOL(__get_user_1);
23354 EXPORT_SYMBOL(__get_user_2);
23355@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23356
23357 EXPORT_SYMBOL(csum_partial);
23358 EXPORT_SYMBOL(empty_zero_page);
23359+
23360+#ifdef CONFIG_PAX_KERNEXEC
23361+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23362+#endif
23363+
23364+#ifdef CONFIG_PAX_PER_CPU_PGD
23365+EXPORT_SYMBOL(cpu_pgd);
23366+#endif
23367diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23368index 5d576ab..1403a03 100644
23369--- a/arch/x86/kernel/i387.c
23370+++ b/arch/x86/kernel/i387.c
23371@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23372 static inline bool interrupted_user_mode(void)
23373 {
23374 struct pt_regs *regs = get_irq_regs();
23375- return regs && user_mode_vm(regs);
23376+ return regs && user_mode(regs);
23377 }
23378
23379 /*
23380diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23381index 9a5c460..84868423 100644
23382--- a/arch/x86/kernel/i8259.c
23383+++ b/arch/x86/kernel/i8259.c
23384@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23385 static void make_8259A_irq(unsigned int irq)
23386 {
23387 disable_irq_nosync(irq);
23388- io_apic_irqs &= ~(1<<irq);
23389+ io_apic_irqs &= ~(1UL<<irq);
23390 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23391 i8259A_chip.name);
23392 enable_irq(irq);
23393@@ -209,7 +209,7 @@ spurious_8259A_irq:
23394 "spurious 8259A interrupt: IRQ%d.\n", irq);
23395 spurious_irq_mask |= irqmask;
23396 }
23397- atomic_inc(&irq_err_count);
23398+ atomic_inc_unchecked(&irq_err_count);
23399 /*
23400 * Theoretically we do not have to handle this IRQ,
23401 * but in Linux this does not cause problems and is
23402@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23403 /* (slave's support for AEOI in flat mode is to be investigated) */
23404 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23405
23406+ pax_open_kernel();
23407 if (auto_eoi)
23408 /*
23409 * In AEOI mode we just have to mask the interrupt
23410 * when acking.
23411 */
23412- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23413+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23414 else
23415- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23416+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23417+ pax_close_kernel();
23418
23419 udelay(100); /* wait for 8259A to initialize */
23420
23421diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23422index a979b5b..1d6db75 100644
23423--- a/arch/x86/kernel/io_delay.c
23424+++ b/arch/x86/kernel/io_delay.c
23425@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23426 * Quirk table for systems that misbehave (lock up, etc.) if port
23427 * 0x80 is used:
23428 */
23429-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23430+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23431 {
23432 .callback = dmi_io_delay_0xed_port,
23433 .ident = "Compaq Presario V6000",
23434diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23435index 4ddaf66..6292f4e 100644
23436--- a/arch/x86/kernel/ioport.c
23437+++ b/arch/x86/kernel/ioport.c
23438@@ -6,6 +6,7 @@
23439 #include <linux/sched.h>
23440 #include <linux/kernel.h>
23441 #include <linux/capability.h>
23442+#include <linux/security.h>
23443 #include <linux/errno.h>
23444 #include <linux/types.h>
23445 #include <linux/ioport.h>
23446@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23447
23448 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23449 return -EINVAL;
23450+#ifdef CONFIG_GRKERNSEC_IO
23451+ if (turn_on && grsec_disable_privio) {
23452+ gr_handle_ioperm();
23453+ return -EPERM;
23454+ }
23455+#endif
23456 if (turn_on && !capable(CAP_SYS_RAWIO))
23457 return -EPERM;
23458
23459@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23460 * because the ->io_bitmap_max value must match the bitmap
23461 * contents:
23462 */
23463- tss = &per_cpu(init_tss, get_cpu());
23464+ tss = init_tss + get_cpu();
23465
23466 if (turn_on)
23467 bitmap_clear(t->io_bitmap_ptr, from, num);
23468@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23469 return -EINVAL;
23470 /* Trying to gain more privileges? */
23471 if (level > old) {
23472+#ifdef CONFIG_GRKERNSEC_IO
23473+ if (grsec_disable_privio) {
23474+ gr_handle_iopl();
23475+ return -EPERM;
23476+ }
23477+#endif
23478 if (!capable(CAP_SYS_RAWIO))
23479 return -EPERM;
23480 }
23481diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23482index 3a8185c..3c042ee 100644
23483--- a/arch/x86/kernel/irq.c
23484+++ b/arch/x86/kernel/irq.c
23485@@ -21,7 +21,7 @@
23486 #define CREATE_TRACE_POINTS
23487 #include <asm/trace/irq_vectors.h>
23488
23489-atomic_t irq_err_count;
23490+atomic_unchecked_t irq_err_count;
23491
23492 /* Function pointer for generic interrupt vector handling */
23493 void (*x86_platform_ipi_callback)(void) = NULL;
23494@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23495 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23496 seq_printf(p, " Machine check polls\n");
23497 #endif
23498- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23499+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23500 #if defined(CONFIG_X86_IO_APIC)
23501- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23502+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23503 #endif
23504 return 0;
23505 }
23506@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23507
23508 u64 arch_irq_stat(void)
23509 {
23510- u64 sum = atomic_read(&irq_err_count);
23511+ u64 sum = atomic_read_unchecked(&irq_err_count);
23512 return sum;
23513 }
23514
23515diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23516index 4186755..784efa0 100644
23517--- a/arch/x86/kernel/irq_32.c
23518+++ b/arch/x86/kernel/irq_32.c
23519@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23520 __asm__ __volatile__("andl %%esp,%0" :
23521 "=r" (sp) : "0" (THREAD_SIZE - 1));
23522
23523- return sp < (sizeof(struct thread_info) + STACK_WARN);
23524+ return sp < STACK_WARN;
23525 }
23526
23527 static void print_stack_overflow(void)
23528@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23529 * per-CPU IRQ handling contexts (thread information and stack)
23530 */
23531 union irq_ctx {
23532- struct thread_info tinfo;
23533- u32 stack[THREAD_SIZE/sizeof(u32)];
23534+ unsigned long previous_esp;
23535+ u32 stack[THREAD_SIZE/sizeof(u32)];
23536 } __attribute__((aligned(THREAD_SIZE)));
23537
23538 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23539@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23540 static inline int
23541 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23542 {
23543- union irq_ctx *curctx, *irqctx;
23544+ union irq_ctx *irqctx;
23545 u32 *isp, arg1, arg2;
23546
23547- curctx = (union irq_ctx *) current_thread_info();
23548 irqctx = __this_cpu_read(hardirq_ctx);
23549
23550 /*
23551@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23552 * handler) we can't do that and just have to keep using the
23553 * current stack (which is the irq stack already after all)
23554 */
23555- if (unlikely(curctx == irqctx))
23556+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23557 return 0;
23558
23559 /* build the stack frame on the IRQ stack */
23560- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23561- irqctx->tinfo.task = curctx->tinfo.task;
23562- irqctx->tinfo.previous_esp = current_stack_pointer;
23563+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23564+ irqctx->previous_esp = current_stack_pointer;
23565
23566- /* Copy the preempt_count so that the [soft]irq checks work. */
23567- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23568+#ifdef CONFIG_PAX_MEMORY_UDEREF
23569+ __set_fs(MAKE_MM_SEG(0));
23570+#endif
23571
23572 if (unlikely(overflow))
23573 call_on_stack(print_stack_overflow, isp);
23574@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23575 : "0" (irq), "1" (desc), "2" (isp),
23576 "D" (desc->handle_irq)
23577 : "memory", "cc", "ecx");
23578+
23579+#ifdef CONFIG_PAX_MEMORY_UDEREF
23580+ __set_fs(current_thread_info()->addr_limit);
23581+#endif
23582+
23583 return 1;
23584 }
23585
23586@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23587 */
23588 void irq_ctx_init(int cpu)
23589 {
23590- union irq_ctx *irqctx;
23591-
23592 if (per_cpu(hardirq_ctx, cpu))
23593 return;
23594
23595- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23596- THREADINFO_GFP,
23597- THREAD_SIZE_ORDER));
23598- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23599- irqctx->tinfo.cpu = cpu;
23600- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23601- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23602+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23603+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23604
23605- per_cpu(hardirq_ctx, cpu) = irqctx;
23606-
23607- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23608- THREADINFO_GFP,
23609- THREAD_SIZE_ORDER));
23610- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23611- irqctx->tinfo.cpu = cpu;
23612- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23613-
23614- per_cpu(softirq_ctx, cpu) = irqctx;
23615+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23616+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23617
23618 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23619 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23620@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23621 asmlinkage void do_softirq(void)
23622 {
23623 unsigned long flags;
23624- struct thread_info *curctx;
23625 union irq_ctx *irqctx;
23626 u32 *isp;
23627
23628@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23629 local_irq_save(flags);
23630
23631 if (local_softirq_pending()) {
23632- curctx = current_thread_info();
23633 irqctx = __this_cpu_read(softirq_ctx);
23634- irqctx->tinfo.task = curctx->task;
23635- irqctx->tinfo.previous_esp = current_stack_pointer;
23636+ irqctx->previous_esp = current_stack_pointer;
23637
23638 /* build the stack frame on the softirq stack */
23639- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23640+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23641+
23642+#ifdef CONFIG_PAX_MEMORY_UDEREF
23643+ __set_fs(MAKE_MM_SEG(0));
23644+#endif
23645
23646 call_on_stack(__do_softirq, isp);
23647+
23648+#ifdef CONFIG_PAX_MEMORY_UDEREF
23649+ __set_fs(current_thread_info()->addr_limit);
23650+#endif
23651+
23652 /*
23653 * Shouldn't happen, we returned above if in_interrupt():
23654 */
23655@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23656 if (unlikely(!desc))
23657 return false;
23658
23659- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23660+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23661 if (unlikely(overflow))
23662 print_stack_overflow();
23663 desc->handle_irq(irq, desc);
23664diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23665index d04d3ec..ea4b374 100644
23666--- a/arch/x86/kernel/irq_64.c
23667+++ b/arch/x86/kernel/irq_64.c
23668@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23669 u64 estack_top, estack_bottom;
23670 u64 curbase = (u64)task_stack_page(current);
23671
23672- if (user_mode_vm(regs))
23673+ if (user_mode(regs))
23674 return;
23675
23676 if (regs->sp >= curbase + sizeof(struct thread_info) +
23677diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23678index dc1404b..bbc43e7 100644
23679--- a/arch/x86/kernel/kdebugfs.c
23680+++ b/arch/x86/kernel/kdebugfs.c
23681@@ -27,7 +27,7 @@ struct setup_data_node {
23682 u32 len;
23683 };
23684
23685-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23686+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23687 size_t count, loff_t *ppos)
23688 {
23689 struct setup_data_node *node = file->private_data;
23690diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23691index 836f832..a8bda67 100644
23692--- a/arch/x86/kernel/kgdb.c
23693+++ b/arch/x86/kernel/kgdb.c
23694@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23695 #ifdef CONFIG_X86_32
23696 switch (regno) {
23697 case GDB_SS:
23698- if (!user_mode_vm(regs))
23699+ if (!user_mode(regs))
23700 *(unsigned long *)mem = __KERNEL_DS;
23701 break;
23702 case GDB_SP:
23703- if (!user_mode_vm(regs))
23704+ if (!user_mode(regs))
23705 *(unsigned long *)mem = kernel_stack_pointer(regs);
23706 break;
23707 case GDB_GS:
23708@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23709 bp->attr.bp_addr = breakinfo[breakno].addr;
23710 bp->attr.bp_len = breakinfo[breakno].len;
23711 bp->attr.bp_type = breakinfo[breakno].type;
23712- info->address = breakinfo[breakno].addr;
23713+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23714+ info->address = ktla_ktva(breakinfo[breakno].addr);
23715+ else
23716+ info->address = breakinfo[breakno].addr;
23717 info->len = breakinfo[breakno].len;
23718 info->type = breakinfo[breakno].type;
23719 val = arch_install_hw_breakpoint(bp);
23720@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23721 case 'k':
23722 /* clear the trace bit */
23723 linux_regs->flags &= ~X86_EFLAGS_TF;
23724- atomic_set(&kgdb_cpu_doing_single_step, -1);
23725+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23726
23727 /* set the trace bit if we're stepping */
23728 if (remcomInBuffer[0] == 's') {
23729 linux_regs->flags |= X86_EFLAGS_TF;
23730- atomic_set(&kgdb_cpu_doing_single_step,
23731+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23732 raw_smp_processor_id());
23733 }
23734
23735@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23736
23737 switch (cmd) {
23738 case DIE_DEBUG:
23739- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23740+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23741 if (user_mode(regs))
23742 return single_step_cont(regs, args);
23743 break;
23744@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23745 #endif /* CONFIG_DEBUG_RODATA */
23746
23747 bpt->type = BP_BREAKPOINT;
23748- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23749+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23750 BREAK_INSTR_SIZE);
23751 if (err)
23752 return err;
23753- err = probe_kernel_write((char *)bpt->bpt_addr,
23754+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23755 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23756 #ifdef CONFIG_DEBUG_RODATA
23757 if (!err)
23758@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23759 return -EBUSY;
23760 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23761 BREAK_INSTR_SIZE);
23762- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23763+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23764 if (err)
23765 return err;
23766 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23767@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23768 if (mutex_is_locked(&text_mutex))
23769 goto knl_write;
23770 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23771- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23772+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23773 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23774 goto knl_write;
23775 return err;
23776 knl_write:
23777 #endif /* CONFIG_DEBUG_RODATA */
23778- return probe_kernel_write((char *)bpt->bpt_addr,
23779+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23780 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23781 }
23782
23783diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23784index 211bce4..6e2580a 100644
23785--- a/arch/x86/kernel/kprobes/core.c
23786+++ b/arch/x86/kernel/kprobes/core.c
23787@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23788 s32 raddr;
23789 } __packed *insn;
23790
23791- insn = (struct __arch_relative_insn *)from;
23792+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23793+
23794+ pax_open_kernel();
23795 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23796 insn->op = op;
23797+ pax_close_kernel();
23798 }
23799
23800 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23801@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23802 kprobe_opcode_t opcode;
23803 kprobe_opcode_t *orig_opcodes = opcodes;
23804
23805- if (search_exception_tables((unsigned long)opcodes))
23806+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23807 return 0; /* Page fault may occur on this address. */
23808
23809 retry:
23810@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23811 * for the first byte, we can recover the original instruction
23812 * from it and kp->opcode.
23813 */
23814- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23815+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23816 buf[0] = kp->opcode;
23817- return (unsigned long)buf;
23818+ return ktva_ktla((unsigned long)buf);
23819 }
23820
23821 /*
23822@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23823 /* Another subsystem puts a breakpoint, failed to recover */
23824 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23825 return 0;
23826+ pax_open_kernel();
23827 memcpy(dest, insn.kaddr, insn.length);
23828+ pax_close_kernel();
23829
23830 #ifdef CONFIG_X86_64
23831 if (insn_rip_relative(&insn)) {
23832@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23833 return 0;
23834 }
23835 disp = (u8 *) dest + insn_offset_displacement(&insn);
23836+ pax_open_kernel();
23837 *(s32 *) disp = (s32) newdisp;
23838+ pax_close_kernel();
23839 }
23840 #endif
23841 return insn.length;
23842@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23843 * nor set current_kprobe, because it doesn't use single
23844 * stepping.
23845 */
23846- regs->ip = (unsigned long)p->ainsn.insn;
23847+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23848 preempt_enable_no_resched();
23849 return;
23850 }
23851@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23852 regs->flags &= ~X86_EFLAGS_IF;
23853 /* single step inline if the instruction is an int3 */
23854 if (p->opcode == BREAKPOINT_INSTRUCTION)
23855- regs->ip = (unsigned long)p->addr;
23856+ regs->ip = ktla_ktva((unsigned long)p->addr);
23857 else
23858- regs->ip = (unsigned long)p->ainsn.insn;
23859+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23860 }
23861
23862 /*
23863@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23864 setup_singlestep(p, regs, kcb, 0);
23865 return 1;
23866 }
23867- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23868+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23869 /*
23870 * The breakpoint instruction was removed right
23871 * after we hit it. Another cpu has removed
23872@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23873 " movq %rax, 152(%rsp)\n"
23874 RESTORE_REGS_STRING
23875 " popfq\n"
23876+#ifdef KERNEXEC_PLUGIN
23877+ " btsq $63,(%rsp)\n"
23878+#endif
23879 #else
23880 " pushf\n"
23881 SAVE_REGS_STRING
23882@@ -779,7 +789,7 @@ static void __kprobes
23883 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23884 {
23885 unsigned long *tos = stack_addr(regs);
23886- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23887+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23888 unsigned long orig_ip = (unsigned long)p->addr;
23889 kprobe_opcode_t *insn = p->ainsn.insn;
23890
23891@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23892 struct die_args *args = data;
23893 int ret = NOTIFY_DONE;
23894
23895- if (args->regs && user_mode_vm(args->regs))
23896+ if (args->regs && user_mode(args->regs))
23897 return ret;
23898
23899 switch (val) {
23900diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23901index 76dc6f0..66bdfc3 100644
23902--- a/arch/x86/kernel/kprobes/opt.c
23903+++ b/arch/x86/kernel/kprobes/opt.c
23904@@ -79,6 +79,7 @@ found:
23905 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23906 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23907 {
23908+ pax_open_kernel();
23909 #ifdef CONFIG_X86_64
23910 *addr++ = 0x48;
23911 *addr++ = 0xbf;
23912@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23913 *addr++ = 0xb8;
23914 #endif
23915 *(unsigned long *)addr = val;
23916+ pax_close_kernel();
23917 }
23918
23919 static void __used __kprobes kprobes_optinsn_template_holder(void)
23920@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23921 * Verify if the address gap is in 2GB range, because this uses
23922 * a relative jump.
23923 */
23924- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23925+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23926 if (abs(rel) > 0x7fffffff)
23927 return -ERANGE;
23928
23929@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23930 op->optinsn.size = ret;
23931
23932 /* Copy arch-dep-instance from template */
23933- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23934+ pax_open_kernel();
23935+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23936+ pax_close_kernel();
23937
23938 /* Set probe information */
23939 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23940
23941 /* Set probe function call */
23942- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23943+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23944
23945 /* Set returning jmp instruction at the tail of out-of-line buffer */
23946- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23947+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23948 (u8 *)op->kp.addr + op->optinsn.size);
23949
23950 flush_icache_range((unsigned long) buf,
23951@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23952 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23953
23954 /* Backup instructions which will be replaced by jump address */
23955- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23956+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23957 RELATIVE_ADDR_SIZE);
23958
23959 insn_buf[0] = RELATIVEJUMP_OPCODE;
23960@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23961 /* This kprobe is really able to run optimized path. */
23962 op = container_of(p, struct optimized_kprobe, kp);
23963 /* Detour through copied instructions */
23964- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23965+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23966 if (!reenter)
23967 reset_current_kprobe();
23968 preempt_enable_no_resched();
23969diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23970index ebc9873..1b9724b 100644
23971--- a/arch/x86/kernel/ldt.c
23972+++ b/arch/x86/kernel/ldt.c
23973@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23974 if (reload) {
23975 #ifdef CONFIG_SMP
23976 preempt_disable();
23977- load_LDT(pc);
23978+ load_LDT_nolock(pc);
23979 if (!cpumask_equal(mm_cpumask(current->mm),
23980 cpumask_of(smp_processor_id())))
23981 smp_call_function(flush_ldt, current->mm, 1);
23982 preempt_enable();
23983 #else
23984- load_LDT(pc);
23985+ load_LDT_nolock(pc);
23986 #endif
23987 }
23988 if (oldsize) {
23989@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23990 return err;
23991
23992 for (i = 0; i < old->size; i++)
23993- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23994+ write_ldt_entry(new->ldt, i, old->ldt + i);
23995 return 0;
23996 }
23997
23998@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23999 retval = copy_ldt(&mm->context, &old_mm->context);
24000 mutex_unlock(&old_mm->context.lock);
24001 }
24002+
24003+ if (tsk == current) {
24004+ mm->context.vdso = 0;
24005+
24006+#ifdef CONFIG_X86_32
24007+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24008+ mm->context.user_cs_base = 0UL;
24009+ mm->context.user_cs_limit = ~0UL;
24010+
24011+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24012+ cpus_clear(mm->context.cpu_user_cs_mask);
24013+#endif
24014+
24015+#endif
24016+#endif
24017+
24018+ }
24019+
24020 return retval;
24021 }
24022
24023@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24024 }
24025 }
24026
24027+#ifdef CONFIG_PAX_SEGMEXEC
24028+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24029+ error = -EINVAL;
24030+ goto out_unlock;
24031+ }
24032+#endif
24033+
24034 fill_ldt(&ldt, &ldt_info);
24035 if (oldmode)
24036 ldt.avl = 0;
24037diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24038index 5b19e4d..6476a76 100644
24039--- a/arch/x86/kernel/machine_kexec_32.c
24040+++ b/arch/x86/kernel/machine_kexec_32.c
24041@@ -26,7 +26,7 @@
24042 #include <asm/cacheflush.h>
24043 #include <asm/debugreg.h>
24044
24045-static void set_idt(void *newidt, __u16 limit)
24046+static void set_idt(struct desc_struct *newidt, __u16 limit)
24047 {
24048 struct desc_ptr curidt;
24049
24050@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24051 }
24052
24053
24054-static void set_gdt(void *newgdt, __u16 limit)
24055+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24056 {
24057 struct desc_ptr curgdt;
24058
24059@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24060 }
24061
24062 control_page = page_address(image->control_code_page);
24063- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24064+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24065
24066 relocate_kernel_ptr = control_page;
24067 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24068diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24069index 15c9876..0a43909 100644
24070--- a/arch/x86/kernel/microcode_core.c
24071+++ b/arch/x86/kernel/microcode_core.c
24072@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24073 return NOTIFY_OK;
24074 }
24075
24076-static struct notifier_block __refdata mc_cpu_notifier = {
24077+static struct notifier_block mc_cpu_notifier = {
24078 .notifier_call = mc_cpu_callback,
24079 };
24080
24081diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24082index 5fb2ceb..3ae90bb 100644
24083--- a/arch/x86/kernel/microcode_intel.c
24084+++ b/arch/x86/kernel/microcode_intel.c
24085@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24086
24087 static int get_ucode_user(void *to, const void *from, size_t n)
24088 {
24089- return copy_from_user(to, from, n);
24090+ return copy_from_user(to, (const void __force_user *)from, n);
24091 }
24092
24093 static enum ucode_state
24094 request_microcode_user(int cpu, const void __user *buf, size_t size)
24095 {
24096- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24097+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24098 }
24099
24100 static void microcode_fini_cpu(int cpu)
24101diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24102index 216a4d7..228255a 100644
24103--- a/arch/x86/kernel/module.c
24104+++ b/arch/x86/kernel/module.c
24105@@ -43,15 +43,60 @@ do { \
24106 } while (0)
24107 #endif
24108
24109-void *module_alloc(unsigned long size)
24110+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24111 {
24112- if (PAGE_ALIGN(size) > MODULES_LEN)
24113+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24114 return NULL;
24115 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24116- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24117+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24118 -1, __builtin_return_address(0));
24119 }
24120
24121+void *module_alloc(unsigned long size)
24122+{
24123+
24124+#ifdef CONFIG_PAX_KERNEXEC
24125+ return __module_alloc(size, PAGE_KERNEL);
24126+#else
24127+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24128+#endif
24129+
24130+}
24131+
24132+#ifdef CONFIG_PAX_KERNEXEC
24133+#ifdef CONFIG_X86_32
24134+void *module_alloc_exec(unsigned long size)
24135+{
24136+ struct vm_struct *area;
24137+
24138+ if (size == 0)
24139+ return NULL;
24140+
24141+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24142+ return area ? area->addr : NULL;
24143+}
24144+EXPORT_SYMBOL(module_alloc_exec);
24145+
24146+void module_free_exec(struct module *mod, void *module_region)
24147+{
24148+ vunmap(module_region);
24149+}
24150+EXPORT_SYMBOL(module_free_exec);
24151+#else
24152+void module_free_exec(struct module *mod, void *module_region)
24153+{
24154+ module_free(mod, module_region);
24155+}
24156+EXPORT_SYMBOL(module_free_exec);
24157+
24158+void *module_alloc_exec(unsigned long size)
24159+{
24160+ return __module_alloc(size, PAGE_KERNEL_RX);
24161+}
24162+EXPORT_SYMBOL(module_alloc_exec);
24163+#endif
24164+#endif
24165+
24166 #ifdef CONFIG_X86_32
24167 int apply_relocate(Elf32_Shdr *sechdrs,
24168 const char *strtab,
24169@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24170 unsigned int i;
24171 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24172 Elf32_Sym *sym;
24173- uint32_t *location;
24174+ uint32_t *plocation, location;
24175
24176 DEBUGP("Applying relocate section %u to %u\n",
24177 relsec, sechdrs[relsec].sh_info);
24178 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24179 /* This is where to make the change */
24180- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24181- + rel[i].r_offset;
24182+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24183+ location = (uint32_t)plocation;
24184+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24185+ plocation = ktla_ktva((void *)plocation);
24186 /* This is the symbol it is referring to. Note that all
24187 undefined symbols have been resolved. */
24188 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24189@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24190 switch (ELF32_R_TYPE(rel[i].r_info)) {
24191 case R_386_32:
24192 /* We add the value into the location given */
24193- *location += sym->st_value;
24194+ pax_open_kernel();
24195+ *plocation += sym->st_value;
24196+ pax_close_kernel();
24197 break;
24198 case R_386_PC32:
24199 /* Add the value, subtract its position */
24200- *location += sym->st_value - (uint32_t)location;
24201+ pax_open_kernel();
24202+ *plocation += sym->st_value - location;
24203+ pax_close_kernel();
24204 break;
24205 default:
24206 pr_err("%s: Unknown relocation: %u\n",
24207@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24208 case R_X86_64_NONE:
24209 break;
24210 case R_X86_64_64:
24211+ pax_open_kernel();
24212 *(u64 *)loc = val;
24213+ pax_close_kernel();
24214 break;
24215 case R_X86_64_32:
24216+ pax_open_kernel();
24217 *(u32 *)loc = val;
24218+ pax_close_kernel();
24219 if (val != *(u32 *)loc)
24220 goto overflow;
24221 break;
24222 case R_X86_64_32S:
24223+ pax_open_kernel();
24224 *(s32 *)loc = val;
24225+ pax_close_kernel();
24226 if ((s64)val != *(s32 *)loc)
24227 goto overflow;
24228 break;
24229 case R_X86_64_PC32:
24230 val -= (u64)loc;
24231+ pax_open_kernel();
24232 *(u32 *)loc = val;
24233+ pax_close_kernel();
24234+
24235 #if 0
24236 if ((s64)val != *(s32 *)loc)
24237 goto overflow;
24238diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24239index 88458fa..349f7a4 100644
24240--- a/arch/x86/kernel/msr.c
24241+++ b/arch/x86/kernel/msr.c
24242@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24243 return notifier_from_errno(err);
24244 }
24245
24246-static struct notifier_block __refdata msr_class_cpu_notifier = {
24247+static struct notifier_block msr_class_cpu_notifier = {
24248 .notifier_call = msr_class_cpu_callback,
24249 };
24250
24251diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24252index ba77ebc..65da999 100644
24253--- a/arch/x86/kernel/nmi.c
24254+++ b/arch/x86/kernel/nmi.c
24255@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24256 return handled;
24257 }
24258
24259-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24260+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24261 {
24262 struct nmi_desc *desc = nmi_to_desc(type);
24263 unsigned long flags;
24264@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24265 * event confuses some handlers (kdump uses this flag)
24266 */
24267 if (action->flags & NMI_FLAG_FIRST)
24268- list_add_rcu(&action->list, &desc->head);
24269+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24270 else
24271- list_add_tail_rcu(&action->list, &desc->head);
24272+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24273
24274 spin_unlock_irqrestore(&desc->lock, flags);
24275 return 0;
24276@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24277 if (!strcmp(n->name, name)) {
24278 WARN(in_nmi(),
24279 "Trying to free NMI (%s) from NMI context!\n", n->name);
24280- list_del_rcu(&n->list);
24281+ pax_list_del_rcu((struct list_head *)&n->list);
24282 break;
24283 }
24284 }
24285@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24286 dotraplinkage notrace __kprobes void
24287 do_nmi(struct pt_regs *regs, long error_code)
24288 {
24289+
24290+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24291+ if (!user_mode(regs)) {
24292+ unsigned long cs = regs->cs & 0xFFFF;
24293+ unsigned long ip = ktva_ktla(regs->ip);
24294+
24295+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24296+ regs->ip = ip;
24297+ }
24298+#endif
24299+
24300 nmi_nesting_preprocess(regs);
24301
24302 nmi_enter();
24303diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24304index 6d9582e..f746287 100644
24305--- a/arch/x86/kernel/nmi_selftest.c
24306+++ b/arch/x86/kernel/nmi_selftest.c
24307@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24308 {
24309 /* trap all the unknown NMIs we may generate */
24310 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24311- __initdata);
24312+ __initconst);
24313 }
24314
24315 static void __init cleanup_nmi_testsuite(void)
24316@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24317 unsigned long timeout;
24318
24319 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24320- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24321+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24322 nmi_fail = FAILURE;
24323 return;
24324 }
24325diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24326index 676b8c7..870ba04 100644
24327--- a/arch/x86/kernel/paravirt-spinlocks.c
24328+++ b/arch/x86/kernel/paravirt-spinlocks.c
24329@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24330 arch_spin_lock(lock);
24331 }
24332
24333-struct pv_lock_ops pv_lock_ops = {
24334+struct pv_lock_ops pv_lock_ops __read_only = {
24335 #ifdef CONFIG_SMP
24336 .spin_is_locked = __ticket_spin_is_locked,
24337 .spin_is_contended = __ticket_spin_is_contended,
24338diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24339index cd6de64..27c6af0 100644
24340--- a/arch/x86/kernel/paravirt.c
24341+++ b/arch/x86/kernel/paravirt.c
24342@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24343 {
24344 return x;
24345 }
24346+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24347+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24348+#endif
24349
24350 void __init default_banner(void)
24351 {
24352@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24353 if (opfunc == NULL)
24354 /* If there's no function, patch it with a ud2a (BUG) */
24355 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24356- else if (opfunc == _paravirt_nop)
24357+ else if (opfunc == (void *)_paravirt_nop)
24358 /* If the operation is a nop, then nop the callsite */
24359 ret = paravirt_patch_nop();
24360
24361 /* identity functions just return their single argument */
24362- else if (opfunc == _paravirt_ident_32)
24363+ else if (opfunc == (void *)_paravirt_ident_32)
24364 ret = paravirt_patch_ident_32(insnbuf, len);
24365- else if (opfunc == _paravirt_ident_64)
24366+ else if (opfunc == (void *)_paravirt_ident_64)
24367 ret = paravirt_patch_ident_64(insnbuf, len);
24368+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24369+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24370+ ret = paravirt_patch_ident_64(insnbuf, len);
24371+#endif
24372
24373 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24374 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24375@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24376 if (insn_len > len || start == NULL)
24377 insn_len = len;
24378 else
24379- memcpy(insnbuf, start, insn_len);
24380+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24381
24382 return insn_len;
24383 }
24384@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24385 return this_cpu_read(paravirt_lazy_mode);
24386 }
24387
24388-struct pv_info pv_info = {
24389+struct pv_info pv_info __read_only = {
24390 .name = "bare hardware",
24391 .paravirt_enabled = 0,
24392 .kernel_rpl = 0,
24393@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24394 #endif
24395 };
24396
24397-struct pv_init_ops pv_init_ops = {
24398+struct pv_init_ops pv_init_ops __read_only = {
24399 .patch = native_patch,
24400 };
24401
24402-struct pv_time_ops pv_time_ops = {
24403+struct pv_time_ops pv_time_ops __read_only = {
24404 .sched_clock = native_sched_clock,
24405 .steal_clock = native_steal_clock,
24406 };
24407
24408-struct pv_irq_ops pv_irq_ops = {
24409+struct pv_irq_ops pv_irq_ops __read_only = {
24410 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24411 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24412 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24413@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24414 #endif
24415 };
24416
24417-struct pv_cpu_ops pv_cpu_ops = {
24418+struct pv_cpu_ops pv_cpu_ops __read_only = {
24419 .cpuid = native_cpuid,
24420 .get_debugreg = native_get_debugreg,
24421 .set_debugreg = native_set_debugreg,
24422@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24423 .end_context_switch = paravirt_nop,
24424 };
24425
24426-struct pv_apic_ops pv_apic_ops = {
24427+struct pv_apic_ops pv_apic_ops __read_only= {
24428 #ifdef CONFIG_X86_LOCAL_APIC
24429 .startup_ipi_hook = paravirt_nop,
24430 #endif
24431 };
24432
24433-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24434+#ifdef CONFIG_X86_32
24435+#ifdef CONFIG_X86_PAE
24436+/* 64-bit pagetable entries */
24437+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24438+#else
24439 /* 32-bit pagetable entries */
24440 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24441+#endif
24442 #else
24443 /* 64-bit pagetable entries */
24444 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24445 #endif
24446
24447-struct pv_mmu_ops pv_mmu_ops = {
24448+struct pv_mmu_ops pv_mmu_ops __read_only = {
24449
24450 .read_cr2 = native_read_cr2,
24451 .write_cr2 = native_write_cr2,
24452@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24453 .make_pud = PTE_IDENT,
24454
24455 .set_pgd = native_set_pgd,
24456+ .set_pgd_batched = native_set_pgd_batched,
24457 #endif
24458 #endif /* PAGETABLE_LEVELS >= 3 */
24459
24460@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24461 },
24462
24463 .set_fixmap = native_set_fixmap,
24464+
24465+#ifdef CONFIG_PAX_KERNEXEC
24466+ .pax_open_kernel = native_pax_open_kernel,
24467+ .pax_close_kernel = native_pax_close_kernel,
24468+#endif
24469+
24470 };
24471
24472 EXPORT_SYMBOL_GPL(pv_time_ops);
24473diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24474index 299d493..2ccb0ee 100644
24475--- a/arch/x86/kernel/pci-calgary_64.c
24476+++ b/arch/x86/kernel/pci-calgary_64.c
24477@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24478 tce_space = be64_to_cpu(readq(target));
24479 tce_space = tce_space & TAR_SW_BITS;
24480
24481- tce_space = tce_space & (~specified_table_size);
24482+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24483 info->tce_space = (u64 *)__va(tce_space);
24484 }
24485 }
24486diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24487index 35ccf75..7a15747 100644
24488--- a/arch/x86/kernel/pci-iommu_table.c
24489+++ b/arch/x86/kernel/pci-iommu_table.c
24490@@ -2,7 +2,7 @@
24491 #include <asm/iommu_table.h>
24492 #include <linux/string.h>
24493 #include <linux/kallsyms.h>
24494-
24495+#include <linux/sched.h>
24496
24497 #define DEBUG 1
24498
24499diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24500index 6c483ba..d10ce2f 100644
24501--- a/arch/x86/kernel/pci-swiotlb.c
24502+++ b/arch/x86/kernel/pci-swiotlb.c
24503@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24504 void *vaddr, dma_addr_t dma_addr,
24505 struct dma_attrs *attrs)
24506 {
24507- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24508+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24509 }
24510
24511 static struct dma_map_ops swiotlb_dma_ops = {
24512diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24513index 83369e5..52b93f0 100644
24514--- a/arch/x86/kernel/process.c
24515+++ b/arch/x86/kernel/process.c
24516@@ -36,7 +36,8 @@
24517 * section. Since TSS's are completely CPU-local, we want them
24518 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24519 */
24520-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24521+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24522+EXPORT_SYMBOL(init_tss);
24523
24524 #ifdef CONFIG_X86_64
24525 static DEFINE_PER_CPU(unsigned char, is_idle);
24526@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24527 task_xstate_cachep =
24528 kmem_cache_create("task_xstate", xstate_size,
24529 __alignof__(union thread_xstate),
24530- SLAB_PANIC | SLAB_NOTRACK, NULL);
24531+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24532 }
24533
24534 /*
24535@@ -105,7 +106,7 @@ void exit_thread(void)
24536 unsigned long *bp = t->io_bitmap_ptr;
24537
24538 if (bp) {
24539- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24540+ struct tss_struct *tss = init_tss + get_cpu();
24541
24542 t->io_bitmap_ptr = NULL;
24543 clear_thread_flag(TIF_IO_BITMAP);
24544@@ -125,6 +126,9 @@ void flush_thread(void)
24545 {
24546 struct task_struct *tsk = current;
24547
24548+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24549+ loadsegment(gs, 0);
24550+#endif
24551 flush_ptrace_hw_breakpoint(tsk);
24552 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24553 drop_init_fpu(tsk);
24554@@ -271,7 +275,7 @@ static void __exit_idle(void)
24555 void exit_idle(void)
24556 {
24557 /* idle loop has pid 0 */
24558- if (current->pid)
24559+ if (task_pid_nr(current))
24560 return;
24561 __exit_idle();
24562 }
24563@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24564 return ret;
24565 }
24566 #endif
24567-void stop_this_cpu(void *dummy)
24568+__noreturn void stop_this_cpu(void *dummy)
24569 {
24570 local_irq_disable();
24571 /*
24572@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24573 }
24574 early_param("idle", idle_setup);
24575
24576-unsigned long arch_align_stack(unsigned long sp)
24577+#ifdef CONFIG_PAX_RANDKSTACK
24578+void pax_randomize_kstack(struct pt_regs *regs)
24579 {
24580- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24581- sp -= get_random_int() % 8192;
24582- return sp & ~0xf;
24583-}
24584+ struct thread_struct *thread = &current->thread;
24585+ unsigned long time;
24586
24587-unsigned long arch_randomize_brk(struct mm_struct *mm)
24588-{
24589- unsigned long range_end = mm->brk + 0x02000000;
24590- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24591-}
24592+ if (!randomize_va_space)
24593+ return;
24594+
24595+ if (v8086_mode(regs))
24596+ return;
24597
24598+ rdtscl(time);
24599+
24600+ /* P4 seems to return a 0 LSB, ignore it */
24601+#ifdef CONFIG_MPENTIUM4
24602+ time &= 0x3EUL;
24603+ time <<= 2;
24604+#elif defined(CONFIG_X86_64)
24605+ time &= 0xFUL;
24606+ time <<= 4;
24607+#else
24608+ time &= 0x1FUL;
24609+ time <<= 3;
24610+#endif
24611+
24612+ thread->sp0 ^= time;
24613+ load_sp0(init_tss + smp_processor_id(), thread);
24614+
24615+#ifdef CONFIG_X86_64
24616+ this_cpu_write(kernel_stack, thread->sp0);
24617+#endif
24618+}
24619+#endif
24620diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24621index f8adefc..4bce3d6 100644
24622--- a/arch/x86/kernel/process_32.c
24623+++ b/arch/x86/kernel/process_32.c
24624@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24625 unsigned long thread_saved_pc(struct task_struct *tsk)
24626 {
24627 return ((unsigned long *)tsk->thread.sp)[3];
24628+//XXX return tsk->thread.eip;
24629 }
24630
24631 void __show_regs(struct pt_regs *regs, int all)
24632@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24633 unsigned long sp;
24634 unsigned short ss, gs;
24635
24636- if (user_mode_vm(regs)) {
24637+ if (user_mode(regs)) {
24638 sp = regs->sp;
24639 ss = regs->ss & 0xffff;
24640- gs = get_user_gs(regs);
24641 } else {
24642 sp = kernel_stack_pointer(regs);
24643 savesegment(ss, ss);
24644- savesegment(gs, gs);
24645 }
24646+ gs = get_user_gs(regs);
24647
24648 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24649 (u16)regs->cs, regs->ip, regs->flags,
24650- smp_processor_id());
24651+ raw_smp_processor_id());
24652 print_symbol("EIP is at %s\n", regs->ip);
24653
24654 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24655@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24656 int copy_thread(unsigned long clone_flags, unsigned long sp,
24657 unsigned long arg, struct task_struct *p)
24658 {
24659- struct pt_regs *childregs = task_pt_regs(p);
24660+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24661 struct task_struct *tsk;
24662 int err;
24663
24664 p->thread.sp = (unsigned long) childregs;
24665 p->thread.sp0 = (unsigned long) (childregs+1);
24666+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24667
24668 if (unlikely(p->flags & PF_KTHREAD)) {
24669 /* kernel thread */
24670 memset(childregs, 0, sizeof(struct pt_regs));
24671 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24672- task_user_gs(p) = __KERNEL_STACK_CANARY;
24673- childregs->ds = __USER_DS;
24674- childregs->es = __USER_DS;
24675+ savesegment(gs, childregs->gs);
24676+ childregs->ds = __KERNEL_DS;
24677+ childregs->es = __KERNEL_DS;
24678 childregs->fs = __KERNEL_PERCPU;
24679 childregs->bx = sp; /* function */
24680 childregs->bp = arg;
24681@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24682 struct thread_struct *prev = &prev_p->thread,
24683 *next = &next_p->thread;
24684 int cpu = smp_processor_id();
24685- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24686+ struct tss_struct *tss = init_tss + cpu;
24687 fpu_switch_t fpu;
24688
24689 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24690@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24691 */
24692 lazy_save_gs(prev->gs);
24693
24694+#ifdef CONFIG_PAX_MEMORY_UDEREF
24695+ __set_fs(task_thread_info(next_p)->addr_limit);
24696+#endif
24697+
24698 /*
24699 * Load the per-thread Thread-Local Storage descriptor.
24700 */
24701@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24702 */
24703 arch_end_context_switch(next_p);
24704
24705+ this_cpu_write(current_task, next_p);
24706+ this_cpu_write(current_tinfo, &next_p->tinfo);
24707+
24708 /*
24709 * Restore %gs if needed (which is common)
24710 */
24711@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24712
24713 switch_fpu_finish(next_p, fpu);
24714
24715- this_cpu_write(current_task, next_p);
24716-
24717 return prev_p;
24718 }
24719
24720@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24721 } while (count++ < 16);
24722 return 0;
24723 }
24724-
24725diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24726index 05646ba..0c2906d 100644
24727--- a/arch/x86/kernel/process_64.c
24728+++ b/arch/x86/kernel/process_64.c
24729@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24730 struct pt_regs *childregs;
24731 struct task_struct *me = current;
24732
24733- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24734+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24735 childregs = task_pt_regs(p);
24736 p->thread.sp = (unsigned long) childregs;
24737 p->thread.usersp = me->thread.usersp;
24738+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24739 set_tsk_thread_flag(p, TIF_FORK);
24740 p->fpu_counter = 0;
24741 p->thread.io_bitmap_ptr = NULL;
24742@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24743 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24744 savesegment(es, p->thread.es);
24745 savesegment(ds, p->thread.ds);
24746+ savesegment(ss, p->thread.ss);
24747+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24748 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24749
24750 if (unlikely(p->flags & PF_KTHREAD)) {
24751@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24752 struct thread_struct *prev = &prev_p->thread;
24753 struct thread_struct *next = &next_p->thread;
24754 int cpu = smp_processor_id();
24755- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24756+ struct tss_struct *tss = init_tss + cpu;
24757 unsigned fsindex, gsindex;
24758 fpu_switch_t fpu;
24759
24760@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24761 if (unlikely(next->ds | prev->ds))
24762 loadsegment(ds, next->ds);
24763
24764+ savesegment(ss, prev->ss);
24765+ if (unlikely(next->ss != prev->ss))
24766+ loadsegment(ss, next->ss);
24767
24768 /* We must save %fs and %gs before load_TLS() because
24769 * %fs and %gs may be cleared by load_TLS().
24770@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24771 prev->usersp = this_cpu_read(old_rsp);
24772 this_cpu_write(old_rsp, next->usersp);
24773 this_cpu_write(current_task, next_p);
24774+ this_cpu_write(current_tinfo, &next_p->tinfo);
24775
24776- this_cpu_write(kernel_stack,
24777- (unsigned long)task_stack_page(next_p) +
24778- THREAD_SIZE - KERNEL_STACK_OFFSET);
24779+ this_cpu_write(kernel_stack, next->sp0);
24780
24781 /*
24782 * Now maybe reload the debug registers and handle I/O bitmaps
24783@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24784 if (!p || p == current || p->state == TASK_RUNNING)
24785 return 0;
24786 stack = (unsigned long)task_stack_page(p);
24787- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24788+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24789 return 0;
24790 fp = *(u64 *)(p->thread.sp);
24791 do {
24792- if (fp < (unsigned long)stack ||
24793- fp >= (unsigned long)stack+THREAD_SIZE)
24794+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24795 return 0;
24796 ip = *(u64 *)(fp+8);
24797 if (!in_sched_functions(ip))
24798diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24799index 7461f50..1334029 100644
24800--- a/arch/x86/kernel/ptrace.c
24801+++ b/arch/x86/kernel/ptrace.c
24802@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24803 {
24804 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24805 unsigned long sp = (unsigned long)&regs->sp;
24806- struct thread_info *tinfo;
24807
24808- if (context == (sp & ~(THREAD_SIZE - 1)))
24809+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24810 return sp;
24811
24812- tinfo = (struct thread_info *)context;
24813- if (tinfo->previous_esp)
24814- return tinfo->previous_esp;
24815+ sp = *(unsigned long *)context;
24816+ if (sp)
24817+ return sp;
24818
24819 return (unsigned long)regs;
24820 }
24821@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24822 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24823 {
24824 int i;
24825- int dr7 = 0;
24826+ unsigned long dr7 = 0;
24827 struct arch_hw_breakpoint *info;
24828
24829 for (i = 0; i < HBP_NUM; i++) {
24830@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24831 unsigned long addr, unsigned long data)
24832 {
24833 int ret;
24834- unsigned long __user *datap = (unsigned long __user *)data;
24835+ unsigned long __user *datap = (__force unsigned long __user *)data;
24836
24837 switch (request) {
24838 /* read the word at location addr in the USER area. */
24839@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24840 if ((int) addr < 0)
24841 return -EIO;
24842 ret = do_get_thread_area(child, addr,
24843- (struct user_desc __user *)data);
24844+ (__force struct user_desc __user *) data);
24845 break;
24846
24847 case PTRACE_SET_THREAD_AREA:
24848 if ((int) addr < 0)
24849 return -EIO;
24850 ret = do_set_thread_area(child, addr,
24851- (struct user_desc __user *)data, 0);
24852+ (__force struct user_desc __user *) data, 0);
24853 break;
24854 #endif
24855
24856@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24857
24858 #ifdef CONFIG_X86_64
24859
24860-static struct user_regset x86_64_regsets[] __read_mostly = {
24861+static user_regset_no_const x86_64_regsets[] __read_only = {
24862 [REGSET_GENERAL] = {
24863 .core_note_type = NT_PRSTATUS,
24864 .n = sizeof(struct user_regs_struct) / sizeof(long),
24865@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24866 #endif /* CONFIG_X86_64 */
24867
24868 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24869-static struct user_regset x86_32_regsets[] __read_mostly = {
24870+static user_regset_no_const x86_32_regsets[] __read_only = {
24871 [REGSET_GENERAL] = {
24872 .core_note_type = NT_PRSTATUS,
24873 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24874@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24875 */
24876 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24877
24878-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24879+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24880 {
24881 #ifdef CONFIG_X86_64
24882 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24883@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24884 memset(info, 0, sizeof(*info));
24885 info->si_signo = SIGTRAP;
24886 info->si_code = si_code;
24887- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24888+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24889 }
24890
24891 void user_single_step_siginfo(struct task_struct *tsk,
24892@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24893 # define IS_IA32 0
24894 #endif
24895
24896+#ifdef CONFIG_GRKERNSEC_SETXID
24897+extern void gr_delayed_cred_worker(void);
24898+#endif
24899+
24900 /*
24901 * We must return the syscall number to actually look up in the table.
24902 * This can be -1L to skip running any syscall at all.
24903@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24904
24905 user_exit();
24906
24907+#ifdef CONFIG_GRKERNSEC_SETXID
24908+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24909+ gr_delayed_cred_worker();
24910+#endif
24911+
24912 /*
24913 * If we stepped into a sysenter/syscall insn, it trapped in
24914 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24915@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24916 */
24917 user_exit();
24918
24919+#ifdef CONFIG_GRKERNSEC_SETXID
24920+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24921+ gr_delayed_cred_worker();
24922+#endif
24923+
24924 audit_syscall_exit(regs);
24925
24926 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24927diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24928index 2cb9470..ff1fd80 100644
24929--- a/arch/x86/kernel/pvclock.c
24930+++ b/arch/x86/kernel/pvclock.c
24931@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24932 return pv_tsc_khz;
24933 }
24934
24935-static atomic64_t last_value = ATOMIC64_INIT(0);
24936+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24937
24938 void pvclock_resume(void)
24939 {
24940- atomic64_set(&last_value, 0);
24941+ atomic64_set_unchecked(&last_value, 0);
24942 }
24943
24944 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24945@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24946 * updating at the same time, and one of them could be slightly behind,
24947 * making the assumption that last_value always go forward fail to hold.
24948 */
24949- last = atomic64_read(&last_value);
24950+ last = atomic64_read_unchecked(&last_value);
24951 do {
24952 if (ret < last)
24953 return last;
24954- last = atomic64_cmpxchg(&last_value, last, ret);
24955+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24956 } while (unlikely(last != ret));
24957
24958 return ret;
24959diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24960index 5f4ad27..9d96c99 100644
24961--- a/arch/x86/kernel/reboot.c
24962+++ b/arch/x86/kernel/reboot.c
24963@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24964
24965 void __noreturn machine_real_restart(unsigned int type)
24966 {
24967+
24968+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24969+ struct desc_struct *gdt;
24970+#endif
24971+
24972 local_irq_disable();
24973
24974 /*
24975@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24976
24977 /* Jump to the identity-mapped low memory code */
24978 #ifdef CONFIG_X86_32
24979- asm volatile("jmpl *%0" : :
24980+
24981+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24982+ gdt = get_cpu_gdt_table(smp_processor_id());
24983+ pax_open_kernel();
24984+#ifdef CONFIG_PAX_MEMORY_UDEREF
24985+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24986+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24987+ loadsegment(ds, __KERNEL_DS);
24988+ loadsegment(es, __KERNEL_DS);
24989+ loadsegment(ss, __KERNEL_DS);
24990+#endif
24991+#ifdef CONFIG_PAX_KERNEXEC
24992+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24993+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24994+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24995+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24996+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24997+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24998+#endif
24999+ pax_close_kernel();
25000+#endif
25001+
25002+ asm volatile("ljmpl *%0" : :
25003 "rm" (real_mode_header->machine_real_restart_asm),
25004 "a" (type));
25005 #else
25006@@ -458,7 +485,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25007 * try to force a triple fault and then cycle between hitting the keyboard
25008 * controller and doing that
25009 */
25010-static void native_machine_emergency_restart(void)
25011+static void __noreturn native_machine_emergency_restart(void)
25012 {
25013 int i;
25014 int attempt = 0;
25015@@ -567,13 +594,13 @@ void native_machine_shutdown(void)
25016 #endif
25017 }
25018
25019-static void __machine_emergency_restart(int emergency)
25020+static void __noreturn __machine_emergency_restart(int emergency)
25021 {
25022 reboot_emergency = emergency;
25023 machine_ops.emergency_restart();
25024 }
25025
25026-static void native_machine_restart(char *__unused)
25027+static void __noreturn native_machine_restart(char *__unused)
25028 {
25029 pr_notice("machine restart\n");
25030
25031@@ -582,7 +609,7 @@ static void native_machine_restart(char *__unused)
25032 __machine_emergency_restart(0);
25033 }
25034
25035-static void native_machine_halt(void)
25036+static void __noreturn native_machine_halt(void)
25037 {
25038 /* Stop other cpus and apics */
25039 machine_shutdown();
25040@@ -592,7 +619,7 @@ static void native_machine_halt(void)
25041 stop_this_cpu(NULL);
25042 }
25043
25044-static void native_machine_power_off(void)
25045+static void __noreturn native_machine_power_off(void)
25046 {
25047 if (pm_power_off) {
25048 if (!reboot_force)
25049@@ -601,9 +628,10 @@ static void native_machine_power_off(void)
25050 }
25051 /* A fallback in case there is no PM info available */
25052 tboot_shutdown(TB_SHUTDOWN_HALT);
25053+ unreachable();
25054 }
25055
25056-struct machine_ops machine_ops = {
25057+struct machine_ops machine_ops __read_only = {
25058 .power_off = native_machine_power_off,
25059 .shutdown = native_machine_shutdown,
25060 .emergency_restart = native_machine_emergency_restart,
25061diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25062index c8e41e9..64049ef 100644
25063--- a/arch/x86/kernel/reboot_fixups_32.c
25064+++ b/arch/x86/kernel/reboot_fixups_32.c
25065@@ -57,7 +57,7 @@ struct device_fixup {
25066 unsigned int vendor;
25067 unsigned int device;
25068 void (*reboot_fixup)(struct pci_dev *);
25069-};
25070+} __do_const;
25071
25072 /*
25073 * PCI ids solely used for fixups_table go here
25074diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25075index 3fd2c69..16ef367 100644
25076--- a/arch/x86/kernel/relocate_kernel_64.S
25077+++ b/arch/x86/kernel/relocate_kernel_64.S
25078@@ -11,6 +11,7 @@
25079 #include <asm/kexec.h>
25080 #include <asm/processor-flags.h>
25081 #include <asm/pgtable_types.h>
25082+#include <asm/alternative-asm.h>
25083
25084 /*
25085 * Must be relocatable PIC code callable as a C function
25086@@ -96,8 +97,7 @@ relocate_kernel:
25087
25088 /* jump to identity mapped page */
25089 addq $(identity_mapped - relocate_kernel), %r8
25090- pushq %r8
25091- ret
25092+ jmp *%r8
25093
25094 identity_mapped:
25095 /* set return address to 0 if not preserving context */
25096@@ -167,6 +167,7 @@ identity_mapped:
25097 xorl %r14d, %r14d
25098 xorl %r15d, %r15d
25099
25100+ pax_force_retaddr 0, 1
25101 ret
25102
25103 1:
25104diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25105index f8ec578..0cc110a 100644
25106--- a/arch/x86/kernel/setup.c
25107+++ b/arch/x86/kernel/setup.c
25108@@ -110,6 +110,7 @@
25109 #include <asm/mce.h>
25110 #include <asm/alternative.h>
25111 #include <asm/prom.h>
25112+#include <asm/boot.h>
25113
25114 /*
25115 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25116@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25117 #endif
25118
25119
25120-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25121-unsigned long mmu_cr4_features;
25122+#ifdef CONFIG_X86_64
25123+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25124+#elif defined(CONFIG_X86_PAE)
25125+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25126 #else
25127-unsigned long mmu_cr4_features = X86_CR4_PAE;
25128+unsigned long mmu_cr4_features __read_only;
25129 #endif
25130
25131+void set_in_cr4(unsigned long mask)
25132+{
25133+ unsigned long cr4 = read_cr4();
25134+
25135+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25136+ return;
25137+
25138+ pax_open_kernel();
25139+ mmu_cr4_features |= mask;
25140+ pax_close_kernel();
25141+
25142+ if (trampoline_cr4_features)
25143+ *trampoline_cr4_features = mmu_cr4_features;
25144+ cr4 |= mask;
25145+ write_cr4(cr4);
25146+}
25147+EXPORT_SYMBOL(set_in_cr4);
25148+
25149+void clear_in_cr4(unsigned long mask)
25150+{
25151+ unsigned long cr4 = read_cr4();
25152+
25153+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25154+ return;
25155+
25156+ pax_open_kernel();
25157+ mmu_cr4_features &= ~mask;
25158+ pax_close_kernel();
25159+
25160+ if (trampoline_cr4_features)
25161+ *trampoline_cr4_features = mmu_cr4_features;
25162+ cr4 &= ~mask;
25163+ write_cr4(cr4);
25164+}
25165+EXPORT_SYMBOL(clear_in_cr4);
25166+
25167 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25168 int bootloader_type, bootloader_version;
25169
25170@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25171
25172 switch (data->type) {
25173 case SETUP_E820_EXT:
25174- parse_e820_ext(data);
25175+ parse_e820_ext((struct setup_data __force_kernel *)data);
25176 break;
25177 case SETUP_DTB:
25178 add_dtb(pa_data);
25179@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25180 * area (640->1Mb) as ram even though it is not.
25181 * take them out.
25182 */
25183- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25184+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25185
25186 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25187 }
25188@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25189 /* called before trim_bios_range() to spare extra sanitize */
25190 static void __init e820_add_kernel_range(void)
25191 {
25192- u64 start = __pa_symbol(_text);
25193+ u64 start = __pa_symbol(ktla_ktva(_text));
25194 u64 size = __pa_symbol(_end) - start;
25195
25196 /*
25197@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25198
25199 void __init setup_arch(char **cmdline_p)
25200 {
25201+#ifdef CONFIG_X86_32
25202+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25203+#else
25204 memblock_reserve(__pa_symbol(_text),
25205 (unsigned long)__bss_stop - (unsigned long)_text);
25206+#endif
25207
25208 early_reserve_initrd();
25209
25210@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25211
25212 if (!boot_params.hdr.root_flags)
25213 root_mountflags &= ~MS_RDONLY;
25214- init_mm.start_code = (unsigned long) _text;
25215- init_mm.end_code = (unsigned long) _etext;
25216+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25217+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25218 init_mm.end_data = (unsigned long) _edata;
25219 init_mm.brk = _brk_end;
25220
25221- code_resource.start = __pa_symbol(_text);
25222- code_resource.end = __pa_symbol(_etext)-1;
25223- data_resource.start = __pa_symbol(_etext);
25224+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25225+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25226+ data_resource.start = __pa_symbol(_sdata);
25227 data_resource.end = __pa_symbol(_edata)-1;
25228 bss_resource.start = __pa_symbol(__bss_start);
25229 bss_resource.end = __pa_symbol(__bss_stop)-1;
25230diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25231index 5cdff03..80fa283 100644
25232--- a/arch/x86/kernel/setup_percpu.c
25233+++ b/arch/x86/kernel/setup_percpu.c
25234@@ -21,19 +21,17 @@
25235 #include <asm/cpu.h>
25236 #include <asm/stackprotector.h>
25237
25238-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25239+#ifdef CONFIG_SMP
25240+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25241 EXPORT_PER_CPU_SYMBOL(cpu_number);
25242+#endif
25243
25244-#ifdef CONFIG_X86_64
25245 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25246-#else
25247-#define BOOT_PERCPU_OFFSET 0
25248-#endif
25249
25250 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25251 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25252
25253-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25254+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25255 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25256 };
25257 EXPORT_SYMBOL(__per_cpu_offset);
25258@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25259 {
25260 #ifdef CONFIG_NEED_MULTIPLE_NODES
25261 pg_data_t *last = NULL;
25262- unsigned int cpu;
25263+ int cpu;
25264
25265 for_each_possible_cpu(cpu) {
25266 int node = early_cpu_to_node(cpu);
25267@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25268 {
25269 #ifdef CONFIG_X86_32
25270 struct desc_struct gdt;
25271+ unsigned long base = per_cpu_offset(cpu);
25272
25273- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25274- 0x2 | DESCTYPE_S, 0x8);
25275- gdt.s = 1;
25276+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25277+ 0x83 | DESCTYPE_S, 0xC);
25278 write_gdt_entry(get_cpu_gdt_table(cpu),
25279 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25280 #endif
25281@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25282 /* alrighty, percpu areas up and running */
25283 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25284 for_each_possible_cpu(cpu) {
25285+#ifdef CONFIG_CC_STACKPROTECTOR
25286+#ifdef CONFIG_X86_32
25287+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25288+#endif
25289+#endif
25290 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25291 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25292 per_cpu(cpu_number, cpu) = cpu;
25293@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25294 */
25295 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25296 #endif
25297+#ifdef CONFIG_CC_STACKPROTECTOR
25298+#ifdef CONFIG_X86_32
25299+ if (!cpu)
25300+ per_cpu(stack_canary.canary, cpu) = canary;
25301+#endif
25302+#endif
25303 /*
25304 * Up to this point, the boot CPU has been using .init.data
25305 * area. Reload any changed state for the boot CPU.
25306diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25307index d859eea..44e17c4 100644
25308--- a/arch/x86/kernel/signal.c
25309+++ b/arch/x86/kernel/signal.c
25310@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25311 * Align the stack pointer according to the i386 ABI,
25312 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25313 */
25314- sp = ((sp + 4) & -16ul) - 4;
25315+ sp = ((sp - 12) & -16ul) - 4;
25316 #else /* !CONFIG_X86_32 */
25317 sp = round_down(sp, 16) - 8;
25318 #endif
25319@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25320 }
25321
25322 if (current->mm->context.vdso)
25323- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25324+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25325 else
25326- restorer = &frame->retcode;
25327+ restorer = (void __user *)&frame->retcode;
25328 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25329 restorer = ksig->ka.sa.sa_restorer;
25330
25331@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25332 * reasons and because gdb uses it as a signature to notice
25333 * signal handler stack frames.
25334 */
25335- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25336+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25337
25338 if (err)
25339 return -EFAULT;
25340@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25341 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25342
25343 /* Set up to return from userspace. */
25344- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25345+ if (current->mm->context.vdso)
25346+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25347+ else
25348+ restorer = (void __user *)&frame->retcode;
25349 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25350 restorer = ksig->ka.sa.sa_restorer;
25351 put_user_ex(restorer, &frame->pretcode);
25352@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25353 * reasons and because gdb uses it as a signature to notice
25354 * signal handler stack frames.
25355 */
25356- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25357+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25358 } put_user_catch(err);
25359
25360 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25361@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25362 {
25363 int usig = signr_convert(ksig->sig);
25364 sigset_t *set = sigmask_to_save();
25365- compat_sigset_t *cset = (compat_sigset_t *) set;
25366+ sigset_t sigcopy;
25367+ compat_sigset_t *cset;
25368+
25369+ sigcopy = *set;
25370+
25371+ cset = (compat_sigset_t *) &sigcopy;
25372
25373 /* Set up the stack frame */
25374 if (is_ia32_frame()) {
25375@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25376 } else if (is_x32_frame()) {
25377 return x32_setup_rt_frame(ksig, cset, regs);
25378 } else {
25379- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25380+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25381 }
25382 }
25383
25384diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25385index cdaa347..f5af55d 100644
25386--- a/arch/x86/kernel/smp.c
25387+++ b/arch/x86/kernel/smp.c
25388@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25389
25390 __setup("nonmi_ipi", nonmi_ipi_setup);
25391
25392-struct smp_ops smp_ops = {
25393+struct smp_ops smp_ops __read_only = {
25394 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25395 .smp_prepare_cpus = native_smp_prepare_cpus,
25396 .smp_cpus_done = native_smp_cpus_done,
25397diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25398index aecc98a..0244a53 100644
25399--- a/arch/x86/kernel/smpboot.c
25400+++ b/arch/x86/kernel/smpboot.c
25401@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25402
25403 enable_start_cpu0 = 0;
25404
25405-#ifdef CONFIG_X86_32
25406- /* switch away from the initial page table */
25407- load_cr3(swapper_pg_dir);
25408- __flush_tlb_all();
25409-#endif
25410-
25411 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25412 barrier();
25413+
25414+ /* switch away from the initial page table */
25415+#ifdef CONFIG_PAX_PER_CPU_PGD
25416+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25417+ __flush_tlb_all();
25418+#elif defined(CONFIG_X86_32)
25419+ load_cr3(swapper_pg_dir);
25420+ __flush_tlb_all();
25421+#endif
25422+
25423 /*
25424 * Check TSC synchronization with the BP:
25425 */
25426@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25427 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25428 (THREAD_SIZE + task_stack_page(idle))) - 1);
25429 per_cpu(current_task, cpu) = idle;
25430+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25431
25432 #ifdef CONFIG_X86_32
25433 /* Stack for startup_32 can be just as for start_secondary onwards */
25434@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25435 #else
25436 clear_tsk_thread_flag(idle, TIF_FORK);
25437 initial_gs = per_cpu_offset(cpu);
25438- per_cpu(kernel_stack, cpu) =
25439- (unsigned long)task_stack_page(idle) -
25440- KERNEL_STACK_OFFSET + THREAD_SIZE;
25441+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25442 #endif
25443+
25444+ pax_open_kernel();
25445 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25446+ pax_close_kernel();
25447+
25448 initial_code = (unsigned long)start_secondary;
25449 stack_start = idle->thread.sp;
25450
25451@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25452 /* the FPU context is blank, nobody can own it */
25453 __cpu_disable_lazy_restore(cpu);
25454
25455+#ifdef CONFIG_PAX_PER_CPU_PGD
25456+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25457+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25458+ KERNEL_PGD_PTRS);
25459+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25460+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25461+ KERNEL_PGD_PTRS);
25462+#endif
25463+
25464 err = do_boot_cpu(apicid, cpu, tidle);
25465 if (err) {
25466 pr_debug("do_boot_cpu failed %d\n", err);
25467diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25468index 9b4d51d..5d28b58 100644
25469--- a/arch/x86/kernel/step.c
25470+++ b/arch/x86/kernel/step.c
25471@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25472 struct desc_struct *desc;
25473 unsigned long base;
25474
25475- seg &= ~7UL;
25476+ seg >>= 3;
25477
25478 mutex_lock(&child->mm->context.lock);
25479- if (unlikely((seg >> 3) >= child->mm->context.size))
25480+ if (unlikely(seg >= child->mm->context.size))
25481 addr = -1L; /* bogus selector, access would fault */
25482 else {
25483 desc = child->mm->context.ldt + seg;
25484@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25485 addr += base;
25486 }
25487 mutex_unlock(&child->mm->context.lock);
25488- }
25489+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25490+ addr = ktla_ktva(addr);
25491
25492 return addr;
25493 }
25494@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25495 unsigned char opcode[15];
25496 unsigned long addr = convert_ip_to_linear(child, regs);
25497
25498+ if (addr == -EINVAL)
25499+ return 0;
25500+
25501 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25502 for (i = 0; i < copied; i++) {
25503 switch (opcode[i]) {
25504diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25505new file mode 100644
25506index 0000000..5877189
25507--- /dev/null
25508+++ b/arch/x86/kernel/sys_i386_32.c
25509@@ -0,0 +1,189 @@
25510+/*
25511+ * This file contains various random system calls that
25512+ * have a non-standard calling sequence on the Linux/i386
25513+ * platform.
25514+ */
25515+
25516+#include <linux/errno.h>
25517+#include <linux/sched.h>
25518+#include <linux/mm.h>
25519+#include <linux/fs.h>
25520+#include <linux/smp.h>
25521+#include <linux/sem.h>
25522+#include <linux/msg.h>
25523+#include <linux/shm.h>
25524+#include <linux/stat.h>
25525+#include <linux/syscalls.h>
25526+#include <linux/mman.h>
25527+#include <linux/file.h>
25528+#include <linux/utsname.h>
25529+#include <linux/ipc.h>
25530+#include <linux/elf.h>
25531+
25532+#include <linux/uaccess.h>
25533+#include <linux/unistd.h>
25534+
25535+#include <asm/syscalls.h>
25536+
25537+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25538+{
25539+ unsigned long pax_task_size = TASK_SIZE;
25540+
25541+#ifdef CONFIG_PAX_SEGMEXEC
25542+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25543+ pax_task_size = SEGMEXEC_TASK_SIZE;
25544+#endif
25545+
25546+ if (flags & MAP_FIXED)
25547+ if (len > pax_task_size || addr > pax_task_size - len)
25548+ return -EINVAL;
25549+
25550+ return 0;
25551+}
25552+
25553+/*
25554+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25555+ */
25556+static unsigned long get_align_mask(void)
25557+{
25558+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25559+ return 0;
25560+
25561+ if (!(current->flags & PF_RANDOMIZE))
25562+ return 0;
25563+
25564+ return va_align.mask;
25565+}
25566+
25567+unsigned long
25568+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25569+ unsigned long len, unsigned long pgoff, unsigned long flags)
25570+{
25571+ struct mm_struct *mm = current->mm;
25572+ struct vm_area_struct *vma;
25573+ unsigned long pax_task_size = TASK_SIZE;
25574+ struct vm_unmapped_area_info info;
25575+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25576+
25577+#ifdef CONFIG_PAX_SEGMEXEC
25578+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25579+ pax_task_size = SEGMEXEC_TASK_SIZE;
25580+#endif
25581+
25582+ pax_task_size -= PAGE_SIZE;
25583+
25584+ if (len > pax_task_size)
25585+ return -ENOMEM;
25586+
25587+ if (flags & MAP_FIXED)
25588+ return addr;
25589+
25590+#ifdef CONFIG_PAX_RANDMMAP
25591+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25592+#endif
25593+
25594+ if (addr) {
25595+ addr = PAGE_ALIGN(addr);
25596+ if (pax_task_size - len >= addr) {
25597+ vma = find_vma(mm, addr);
25598+ if (check_heap_stack_gap(vma, addr, len, offset))
25599+ return addr;
25600+ }
25601+ }
25602+
25603+ info.flags = 0;
25604+ info.length = len;
25605+ info.align_mask = filp ? get_align_mask() : 0;
25606+ info.align_offset = pgoff << PAGE_SHIFT;
25607+ info.threadstack_offset = offset;
25608+
25609+#ifdef CONFIG_PAX_PAGEEXEC
25610+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25611+ info.low_limit = 0x00110000UL;
25612+ info.high_limit = mm->start_code;
25613+
25614+#ifdef CONFIG_PAX_RANDMMAP
25615+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25616+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25617+#endif
25618+
25619+ if (info.low_limit < info.high_limit) {
25620+ addr = vm_unmapped_area(&info);
25621+ if (!IS_ERR_VALUE(addr))
25622+ return addr;
25623+ }
25624+ } else
25625+#endif
25626+
25627+ info.low_limit = mm->mmap_base;
25628+ info.high_limit = pax_task_size;
25629+
25630+ return vm_unmapped_area(&info);
25631+}
25632+
25633+unsigned long
25634+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25635+ const unsigned long len, const unsigned long pgoff,
25636+ const unsigned long flags)
25637+{
25638+ struct vm_area_struct *vma;
25639+ struct mm_struct *mm = current->mm;
25640+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25641+ struct vm_unmapped_area_info info;
25642+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25643+
25644+#ifdef CONFIG_PAX_SEGMEXEC
25645+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25646+ pax_task_size = SEGMEXEC_TASK_SIZE;
25647+#endif
25648+
25649+ pax_task_size -= PAGE_SIZE;
25650+
25651+ /* requested length too big for entire address space */
25652+ if (len > pax_task_size)
25653+ return -ENOMEM;
25654+
25655+ if (flags & MAP_FIXED)
25656+ return addr;
25657+
25658+#ifdef CONFIG_PAX_PAGEEXEC
25659+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25660+ goto bottomup;
25661+#endif
25662+
25663+#ifdef CONFIG_PAX_RANDMMAP
25664+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25665+#endif
25666+
25667+ /* requesting a specific address */
25668+ if (addr) {
25669+ addr = PAGE_ALIGN(addr);
25670+ if (pax_task_size - len >= addr) {
25671+ vma = find_vma(mm, addr);
25672+ if (check_heap_stack_gap(vma, addr, len, offset))
25673+ return addr;
25674+ }
25675+ }
25676+
25677+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25678+ info.length = len;
25679+ info.low_limit = PAGE_SIZE;
25680+ info.high_limit = mm->mmap_base;
25681+ info.align_mask = filp ? get_align_mask() : 0;
25682+ info.align_offset = pgoff << PAGE_SHIFT;
25683+ info.threadstack_offset = offset;
25684+
25685+ addr = vm_unmapped_area(&info);
25686+ if (!(addr & ~PAGE_MASK))
25687+ return addr;
25688+ VM_BUG_ON(addr != -ENOMEM);
25689+
25690+bottomup:
25691+ /*
25692+ * A failed mmap() very likely causes application failure,
25693+ * so fall back to the bottom-up function here. This scenario
25694+ * can happen with large stack limits and large mmap()
25695+ * allocations.
25696+ */
25697+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25698+}
25699diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25700index 30277e2..5664a29 100644
25701--- a/arch/x86/kernel/sys_x86_64.c
25702+++ b/arch/x86/kernel/sys_x86_64.c
25703@@ -81,8 +81,8 @@ out:
25704 return error;
25705 }
25706
25707-static void find_start_end(unsigned long flags, unsigned long *begin,
25708- unsigned long *end)
25709+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25710+ unsigned long *begin, unsigned long *end)
25711 {
25712 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25713 unsigned long new_begin;
25714@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25715 *begin = new_begin;
25716 }
25717 } else {
25718- *begin = current->mm->mmap_legacy_base;
25719+ *begin = mm->mmap_legacy_base;
25720 *end = TASK_SIZE;
25721 }
25722 }
25723@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25724 struct vm_area_struct *vma;
25725 struct vm_unmapped_area_info info;
25726 unsigned long begin, end;
25727+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25728
25729 if (flags & MAP_FIXED)
25730 return addr;
25731
25732- find_start_end(flags, &begin, &end);
25733+ find_start_end(mm, flags, &begin, &end);
25734
25735 if (len > end)
25736 return -ENOMEM;
25737
25738+#ifdef CONFIG_PAX_RANDMMAP
25739+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25740+#endif
25741+
25742 if (addr) {
25743 addr = PAGE_ALIGN(addr);
25744 vma = find_vma(mm, addr);
25745- if (end - len >= addr &&
25746- (!vma || addr + len <= vma->vm_start))
25747+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25748 return addr;
25749 }
25750
25751@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25752 info.high_limit = end;
25753 info.align_mask = filp ? get_align_mask() : 0;
25754 info.align_offset = pgoff << PAGE_SHIFT;
25755+ info.threadstack_offset = offset;
25756 return vm_unmapped_area(&info);
25757 }
25758
25759@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25760 struct mm_struct *mm = current->mm;
25761 unsigned long addr = addr0;
25762 struct vm_unmapped_area_info info;
25763+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25764
25765 /* requested length too big for entire address space */
25766 if (len > TASK_SIZE)
25767@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25768 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25769 goto bottomup;
25770
25771+#ifdef CONFIG_PAX_RANDMMAP
25772+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25773+#endif
25774+
25775 /* requesting a specific address */
25776 if (addr) {
25777 addr = PAGE_ALIGN(addr);
25778 vma = find_vma(mm, addr);
25779- if (TASK_SIZE - len >= addr &&
25780- (!vma || addr + len <= vma->vm_start))
25781+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25782 return addr;
25783 }
25784
25785@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25786 info.high_limit = mm->mmap_base;
25787 info.align_mask = filp ? get_align_mask() : 0;
25788 info.align_offset = pgoff << PAGE_SHIFT;
25789+ info.threadstack_offset = offset;
25790 addr = vm_unmapped_area(&info);
25791 if (!(addr & ~PAGE_MASK))
25792 return addr;
25793diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25794index addf7b5..f960685 100644
25795--- a/arch/x86/kernel/tboot.c
25796+++ b/arch/x86/kernel/tboot.c
25797@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25798
25799 void tboot_shutdown(u32 shutdown_type)
25800 {
25801- void (*shutdown)(void);
25802+ void (* __noreturn shutdown)(void);
25803
25804 if (!tboot_enabled())
25805 return;
25806@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25807
25808 switch_to_tboot_pt();
25809
25810- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25811+ shutdown = (void *)tboot->shutdown_entry;
25812 shutdown();
25813
25814 /* should not reach here */
25815@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25816 return 0;
25817 }
25818
25819-static atomic_t ap_wfs_count;
25820+static atomic_unchecked_t ap_wfs_count;
25821
25822 static int tboot_wait_for_aps(int num_aps)
25823 {
25824@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25825 {
25826 switch (action) {
25827 case CPU_DYING:
25828- atomic_inc(&ap_wfs_count);
25829+ atomic_inc_unchecked(&ap_wfs_count);
25830 if (num_online_cpus() == 1)
25831- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25832+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25833 return NOTIFY_BAD;
25834 break;
25835 }
25836@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25837
25838 tboot_create_trampoline();
25839
25840- atomic_set(&ap_wfs_count, 0);
25841+ atomic_set_unchecked(&ap_wfs_count, 0);
25842 register_hotcpu_notifier(&tboot_cpu_notifier);
25843
25844 #ifdef CONFIG_DEBUG_FS
25845diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25846index 24d3c91..d06b473 100644
25847--- a/arch/x86/kernel/time.c
25848+++ b/arch/x86/kernel/time.c
25849@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25850 {
25851 unsigned long pc = instruction_pointer(regs);
25852
25853- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25854+ if (!user_mode(regs) && in_lock_functions(pc)) {
25855 #ifdef CONFIG_FRAME_POINTER
25856- return *(unsigned long *)(regs->bp + sizeof(long));
25857+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25858 #else
25859 unsigned long *sp =
25860 (unsigned long *)kernel_stack_pointer(regs);
25861@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25862 * or above a saved flags. Eflags has bits 22-31 zero,
25863 * kernel addresses don't.
25864 */
25865+
25866+#ifdef CONFIG_PAX_KERNEXEC
25867+ return ktla_ktva(sp[0]);
25868+#else
25869 if (sp[0] >> 22)
25870 return sp[0];
25871 if (sp[1] >> 22)
25872 return sp[1];
25873 #endif
25874+
25875+#endif
25876 }
25877 return pc;
25878 }
25879diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25880index f7fec09..9991981 100644
25881--- a/arch/x86/kernel/tls.c
25882+++ b/arch/x86/kernel/tls.c
25883@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25884 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25885 return -EINVAL;
25886
25887+#ifdef CONFIG_PAX_SEGMEXEC
25888+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25889+ return -EINVAL;
25890+#endif
25891+
25892 set_tls_desc(p, idx, &info, 1);
25893
25894 return 0;
25895@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25896
25897 if (kbuf)
25898 info = kbuf;
25899- else if (__copy_from_user(infobuf, ubuf, count))
25900+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25901 return -EFAULT;
25902 else
25903 info = infobuf;
25904diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25905index 1c113db..287b42e 100644
25906--- a/arch/x86/kernel/tracepoint.c
25907+++ b/arch/x86/kernel/tracepoint.c
25908@@ -9,11 +9,11 @@
25909 #include <linux/atomic.h>
25910
25911 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25912-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25913+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25914 (unsigned long) trace_idt_table };
25915
25916 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25917-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25918+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25919
25920 static int trace_irq_vector_refcount;
25921 static DEFINE_MUTEX(irq_vector_mutex);
25922diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25923index 1b23a1c..910de0d 100644
25924--- a/arch/x86/kernel/traps.c
25925+++ b/arch/x86/kernel/traps.c
25926@@ -65,7 +65,7 @@
25927 #include <asm/proto.h>
25928
25929 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25930-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25931+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25932 #else
25933 #include <asm/processor-flags.h>
25934 #include <asm/setup.h>
25935@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25936 #endif
25937
25938 /* Must be page-aligned because the real IDT is used in a fixmap. */
25939-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25940+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25941
25942 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25943 EXPORT_SYMBOL_GPL(used_vectors);
25944@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25945 }
25946
25947 static int __kprobes
25948-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25949+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25950 struct pt_regs *regs, long error_code)
25951 {
25952 #ifdef CONFIG_X86_32
25953- if (regs->flags & X86_VM_MASK) {
25954+ if (v8086_mode(regs)) {
25955 /*
25956 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25957 * On nmi (interrupt 2), do_trap should not be called.
25958@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25959 return -1;
25960 }
25961 #endif
25962- if (!user_mode(regs)) {
25963+ if (!user_mode_novm(regs)) {
25964 if (!fixup_exception(regs)) {
25965 tsk->thread.error_code = error_code;
25966 tsk->thread.trap_nr = trapnr;
25967+
25968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25969+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25970+ str = "PAX: suspicious stack segment fault";
25971+#endif
25972+
25973 die(str, regs, error_code);
25974 }
25975+
25976+#ifdef CONFIG_PAX_REFCOUNT
25977+ if (trapnr == 4)
25978+ pax_report_refcount_overflow(regs);
25979+#endif
25980+
25981 return 0;
25982 }
25983
25984@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25985 }
25986
25987 static void __kprobes
25988-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25989+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25990 long error_code, siginfo_t *info)
25991 {
25992 struct task_struct *tsk = current;
25993@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25994 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25995 printk_ratelimit()) {
25996 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25997- tsk->comm, tsk->pid, str,
25998+ tsk->comm, task_pid_nr(tsk), str,
25999 regs->ip, regs->sp, error_code);
26000 print_vma_addr(" in ", regs->ip);
26001 pr_cont("\n");
26002@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26003 conditional_sti(regs);
26004
26005 #ifdef CONFIG_X86_32
26006- if (regs->flags & X86_VM_MASK) {
26007+ if (v8086_mode(regs)) {
26008 local_irq_enable();
26009 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26010 goto exit;
26011@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26012 #endif
26013
26014 tsk = current;
26015- if (!user_mode(regs)) {
26016+ if (!user_mode_novm(regs)) {
26017 if (fixup_exception(regs))
26018 goto exit;
26019
26020 tsk->thread.error_code = error_code;
26021 tsk->thread.trap_nr = X86_TRAP_GP;
26022 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26023- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26024+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26025+
26026+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26027+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26028+ die("PAX: suspicious general protection fault", regs, error_code);
26029+ else
26030+#endif
26031+
26032 die("general protection fault", regs, error_code);
26033+ }
26034 goto exit;
26035 }
26036
26037+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26038+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26039+ struct mm_struct *mm = tsk->mm;
26040+ unsigned long limit;
26041+
26042+ down_write(&mm->mmap_sem);
26043+ limit = mm->context.user_cs_limit;
26044+ if (limit < TASK_SIZE) {
26045+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26046+ up_write(&mm->mmap_sem);
26047+ return;
26048+ }
26049+ up_write(&mm->mmap_sem);
26050+ }
26051+#endif
26052+
26053 tsk->thread.error_code = error_code;
26054 tsk->thread.trap_nr = X86_TRAP_GP;
26055
26056@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26057 /* It's safe to allow irq's after DR6 has been saved */
26058 preempt_conditional_sti(regs);
26059
26060- if (regs->flags & X86_VM_MASK) {
26061+ if (v8086_mode(regs)) {
26062 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26063 X86_TRAP_DB);
26064 preempt_conditional_cli(regs);
26065@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26066 * We already checked v86 mode above, so we can check for kernel mode
26067 * by just checking the CPL of CS.
26068 */
26069- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26070+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26071 tsk->thread.debugreg6 &= ~DR_STEP;
26072 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26073 regs->flags &= ~X86_EFLAGS_TF;
26074@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26075 return;
26076 conditional_sti(regs);
26077
26078- if (!user_mode_vm(regs))
26079+ if (!user_mode(regs))
26080 {
26081 if (!fixup_exception(regs)) {
26082 task->thread.error_code = error_code;
26083diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26084index 2ed8459..7cf329f 100644
26085--- a/arch/x86/kernel/uprobes.c
26086+++ b/arch/x86/kernel/uprobes.c
26087@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26088 int ret = NOTIFY_DONE;
26089
26090 /* We are only interested in userspace traps */
26091- if (regs && !user_mode_vm(regs))
26092+ if (regs && !user_mode(regs))
26093 return NOTIFY_DONE;
26094
26095 switch (val) {
26096@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26097
26098 if (ncopied != rasize) {
26099 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26100- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26101+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26102
26103 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26104 }
26105diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26106index b9242ba..50c5edd 100644
26107--- a/arch/x86/kernel/verify_cpu.S
26108+++ b/arch/x86/kernel/verify_cpu.S
26109@@ -20,6 +20,7 @@
26110 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26111 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26112 * arch/x86/kernel/head_32.S: processor startup
26113+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26114 *
26115 * verify_cpu, returns the status of longmode and SSE in register %eax.
26116 * 0: Success 1: Failure
26117diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26118index e8edcf5..27f9344 100644
26119--- a/arch/x86/kernel/vm86_32.c
26120+++ b/arch/x86/kernel/vm86_32.c
26121@@ -44,6 +44,7 @@
26122 #include <linux/ptrace.h>
26123 #include <linux/audit.h>
26124 #include <linux/stddef.h>
26125+#include <linux/grsecurity.h>
26126
26127 #include <asm/uaccess.h>
26128 #include <asm/io.h>
26129@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26130 do_exit(SIGSEGV);
26131 }
26132
26133- tss = &per_cpu(init_tss, get_cpu());
26134+ tss = init_tss + get_cpu();
26135 current->thread.sp0 = current->thread.saved_sp0;
26136 current->thread.sysenter_cs = __KERNEL_CS;
26137 load_sp0(tss, &current->thread);
26138@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26139
26140 if (tsk->thread.saved_sp0)
26141 return -EPERM;
26142+
26143+#ifdef CONFIG_GRKERNSEC_VM86
26144+ if (!capable(CAP_SYS_RAWIO)) {
26145+ gr_handle_vm86();
26146+ return -EPERM;
26147+ }
26148+#endif
26149+
26150 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26151 offsetof(struct kernel_vm86_struct, vm86plus) -
26152 sizeof(info.regs));
26153@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26154 int tmp;
26155 struct vm86plus_struct __user *v86;
26156
26157+#ifdef CONFIG_GRKERNSEC_VM86
26158+ if (!capable(CAP_SYS_RAWIO)) {
26159+ gr_handle_vm86();
26160+ return -EPERM;
26161+ }
26162+#endif
26163+
26164 tsk = current;
26165 switch (cmd) {
26166 case VM86_REQUEST_IRQ:
26167@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26168 tsk->thread.saved_fs = info->regs32->fs;
26169 tsk->thread.saved_gs = get_user_gs(info->regs32);
26170
26171- tss = &per_cpu(init_tss, get_cpu());
26172+ tss = init_tss + get_cpu();
26173 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26174 if (cpu_has_sep)
26175 tsk->thread.sysenter_cs = 0;
26176@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26177 goto cannot_handle;
26178 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26179 goto cannot_handle;
26180- intr_ptr = (unsigned long __user *) (i << 2);
26181+ intr_ptr = (__force unsigned long __user *) (i << 2);
26182 if (get_user(segoffs, intr_ptr))
26183 goto cannot_handle;
26184 if ((segoffs >> 16) == BIOSSEG)
26185diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26186index 10c4f30..65408b9 100644
26187--- a/arch/x86/kernel/vmlinux.lds.S
26188+++ b/arch/x86/kernel/vmlinux.lds.S
26189@@ -26,6 +26,13 @@
26190 #include <asm/page_types.h>
26191 #include <asm/cache.h>
26192 #include <asm/boot.h>
26193+#include <asm/segment.h>
26194+
26195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26196+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26197+#else
26198+#define __KERNEL_TEXT_OFFSET 0
26199+#endif
26200
26201 #undef i386 /* in case the preprocessor is a 32bit one */
26202
26203@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26204
26205 PHDRS {
26206 text PT_LOAD FLAGS(5); /* R_E */
26207+#ifdef CONFIG_X86_32
26208+ module PT_LOAD FLAGS(5); /* R_E */
26209+#endif
26210+#ifdef CONFIG_XEN
26211+ rodata PT_LOAD FLAGS(5); /* R_E */
26212+#else
26213+ rodata PT_LOAD FLAGS(4); /* R__ */
26214+#endif
26215 data PT_LOAD FLAGS(6); /* RW_ */
26216-#ifdef CONFIG_X86_64
26217+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26218 #ifdef CONFIG_SMP
26219 percpu PT_LOAD FLAGS(6); /* RW_ */
26220 #endif
26221+ text.init PT_LOAD FLAGS(5); /* R_E */
26222+ text.exit PT_LOAD FLAGS(5); /* R_E */
26223 init PT_LOAD FLAGS(7); /* RWE */
26224-#endif
26225 note PT_NOTE FLAGS(0); /* ___ */
26226 }
26227
26228 SECTIONS
26229 {
26230 #ifdef CONFIG_X86_32
26231- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26232- phys_startup_32 = startup_32 - LOAD_OFFSET;
26233+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26234 #else
26235- . = __START_KERNEL;
26236- phys_startup_64 = startup_64 - LOAD_OFFSET;
26237+ . = __START_KERNEL;
26238 #endif
26239
26240 /* Text and read-only data */
26241- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26242- _text = .;
26243+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26244 /* bootstrapping code */
26245+#ifdef CONFIG_X86_32
26246+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26247+#else
26248+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26249+#endif
26250+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26251+ _text = .;
26252 HEAD_TEXT
26253 . = ALIGN(8);
26254 _stext = .;
26255@@ -104,13 +124,47 @@ SECTIONS
26256 IRQENTRY_TEXT
26257 *(.fixup)
26258 *(.gnu.warning)
26259- /* End of text section */
26260- _etext = .;
26261 } :text = 0x9090
26262
26263- NOTES :text :note
26264+ . += __KERNEL_TEXT_OFFSET;
26265
26266- EXCEPTION_TABLE(16) :text = 0x9090
26267+#ifdef CONFIG_X86_32
26268+ . = ALIGN(PAGE_SIZE);
26269+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26270+
26271+#ifdef CONFIG_PAX_KERNEXEC
26272+ MODULES_EXEC_VADDR = .;
26273+ BYTE(0)
26274+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26275+ . = ALIGN(HPAGE_SIZE) - 1;
26276+ MODULES_EXEC_END = .;
26277+#endif
26278+
26279+ } :module
26280+#endif
26281+
26282+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26283+ /* End of text section */
26284+ BYTE(0)
26285+ _etext = . - __KERNEL_TEXT_OFFSET;
26286+ }
26287+
26288+#ifdef CONFIG_X86_32
26289+ . = ALIGN(PAGE_SIZE);
26290+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26291+ . = ALIGN(PAGE_SIZE);
26292+ *(.empty_zero_page)
26293+ *(.initial_pg_fixmap)
26294+ *(.initial_pg_pmd)
26295+ *(.initial_page_table)
26296+ *(.swapper_pg_dir)
26297+ } :rodata
26298+#endif
26299+
26300+ . = ALIGN(PAGE_SIZE);
26301+ NOTES :rodata :note
26302+
26303+ EXCEPTION_TABLE(16) :rodata
26304
26305 #if defined(CONFIG_DEBUG_RODATA)
26306 /* .text should occupy whole number of pages */
26307@@ -122,16 +176,20 @@ SECTIONS
26308
26309 /* Data */
26310 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26311+
26312+#ifdef CONFIG_PAX_KERNEXEC
26313+ . = ALIGN(HPAGE_SIZE);
26314+#else
26315+ . = ALIGN(PAGE_SIZE);
26316+#endif
26317+
26318 /* Start of data section */
26319 _sdata = .;
26320
26321 /* init_task */
26322 INIT_TASK_DATA(THREAD_SIZE)
26323
26324-#ifdef CONFIG_X86_32
26325- /* 32 bit has nosave before _edata */
26326 NOSAVE_DATA
26327-#endif
26328
26329 PAGE_ALIGNED_DATA(PAGE_SIZE)
26330
26331@@ -172,12 +230,19 @@ SECTIONS
26332 #endif /* CONFIG_X86_64 */
26333
26334 /* Init code and data - will be freed after init */
26335- . = ALIGN(PAGE_SIZE);
26336 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26337+ BYTE(0)
26338+
26339+#ifdef CONFIG_PAX_KERNEXEC
26340+ . = ALIGN(HPAGE_SIZE);
26341+#else
26342+ . = ALIGN(PAGE_SIZE);
26343+#endif
26344+
26345 __init_begin = .; /* paired with __init_end */
26346- }
26347+ } :init.begin
26348
26349-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26350+#ifdef CONFIG_SMP
26351 /*
26352 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26353 * output PHDR, so the next output section - .init.text - should
26354@@ -186,12 +251,27 @@ SECTIONS
26355 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26356 #endif
26357
26358- INIT_TEXT_SECTION(PAGE_SIZE)
26359-#ifdef CONFIG_X86_64
26360- :init
26361-#endif
26362+ . = ALIGN(PAGE_SIZE);
26363+ init_begin = .;
26364+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26365+ VMLINUX_SYMBOL(_sinittext) = .;
26366+ INIT_TEXT
26367+ VMLINUX_SYMBOL(_einittext) = .;
26368+ . = ALIGN(PAGE_SIZE);
26369+ } :text.init
26370
26371- INIT_DATA_SECTION(16)
26372+ /*
26373+ * .exit.text is discard at runtime, not link time, to deal with
26374+ * references from .altinstructions and .eh_frame
26375+ */
26376+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26377+ EXIT_TEXT
26378+ . = ALIGN(16);
26379+ } :text.exit
26380+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26381+
26382+ . = ALIGN(PAGE_SIZE);
26383+ INIT_DATA_SECTION(16) :init
26384
26385 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26386 __x86_cpu_dev_start = .;
26387@@ -253,19 +333,12 @@ SECTIONS
26388 }
26389
26390 . = ALIGN(8);
26391- /*
26392- * .exit.text is discard at runtime, not link time, to deal with
26393- * references from .altinstructions and .eh_frame
26394- */
26395- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26396- EXIT_TEXT
26397- }
26398
26399 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26400 EXIT_DATA
26401 }
26402
26403-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26404+#ifndef CONFIG_SMP
26405 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26406 #endif
26407
26408@@ -284,16 +357,10 @@ SECTIONS
26409 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26410 __smp_locks = .;
26411 *(.smp_locks)
26412- . = ALIGN(PAGE_SIZE);
26413 __smp_locks_end = .;
26414+ . = ALIGN(PAGE_SIZE);
26415 }
26416
26417-#ifdef CONFIG_X86_64
26418- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26419- NOSAVE_DATA
26420- }
26421-#endif
26422-
26423 /* BSS */
26424 . = ALIGN(PAGE_SIZE);
26425 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26426@@ -309,6 +376,7 @@ SECTIONS
26427 __brk_base = .;
26428 . += 64 * 1024; /* 64k alignment slop space */
26429 *(.brk_reservation) /* areas brk users have reserved */
26430+ . = ALIGN(HPAGE_SIZE);
26431 __brk_limit = .;
26432 }
26433
26434@@ -335,13 +403,12 @@ SECTIONS
26435 * for the boot processor.
26436 */
26437 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26438-INIT_PER_CPU(gdt_page);
26439 INIT_PER_CPU(irq_stack_union);
26440
26441 /*
26442 * Build-time check on the image size:
26443 */
26444-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26445+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26446 "kernel image bigger than KERNEL_IMAGE_SIZE");
26447
26448 #ifdef CONFIG_SMP
26449diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26450index 1f96f93..d5c8f7a 100644
26451--- a/arch/x86/kernel/vsyscall_64.c
26452+++ b/arch/x86/kernel/vsyscall_64.c
26453@@ -56,15 +56,13 @@
26454 DEFINE_VVAR(int, vgetcpu_mode);
26455 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26456
26457-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26458+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26459
26460 static int __init vsyscall_setup(char *str)
26461 {
26462 if (str) {
26463 if (!strcmp("emulate", str))
26464 vsyscall_mode = EMULATE;
26465- else if (!strcmp("native", str))
26466- vsyscall_mode = NATIVE;
26467 else if (!strcmp("none", str))
26468 vsyscall_mode = NONE;
26469 else
26470@@ -323,8 +321,7 @@ do_ret:
26471 return true;
26472
26473 sigsegv:
26474- force_sig(SIGSEGV, current);
26475- return true;
26476+ do_group_exit(SIGKILL);
26477 }
26478
26479 /*
26480@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26481 extern char __vvar_page;
26482 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26483
26484- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26485- vsyscall_mode == NATIVE
26486- ? PAGE_KERNEL_VSYSCALL
26487- : PAGE_KERNEL_VVAR);
26488+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26489 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26490 (unsigned long)VSYSCALL_START);
26491
26492diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26493index b014d94..e775258 100644
26494--- a/arch/x86/kernel/x8664_ksyms_64.c
26495+++ b/arch/x86/kernel/x8664_ksyms_64.c
26496@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26497 EXPORT_SYMBOL(copy_user_generic_unrolled);
26498 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26499 EXPORT_SYMBOL(__copy_user_nocache);
26500-EXPORT_SYMBOL(_copy_from_user);
26501-EXPORT_SYMBOL(_copy_to_user);
26502
26503 EXPORT_SYMBOL(copy_page);
26504 EXPORT_SYMBOL(clear_page);
26505@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26506 #ifndef CONFIG_PARAVIRT
26507 EXPORT_SYMBOL(native_load_gs_index);
26508 #endif
26509+
26510+#ifdef CONFIG_PAX_PER_CPU_PGD
26511+EXPORT_SYMBOL(cpu_pgd);
26512+#endif
26513diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26514index 5f24c71..1dadf09 100644
26515--- a/arch/x86/kernel/x86_init.c
26516+++ b/arch/x86/kernel/x86_init.c
26517@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26518 static void default_nmi_init(void) { };
26519 static int default_i8042_detect(void) { return 1; };
26520
26521-struct x86_platform_ops x86_platform = {
26522+struct x86_platform_ops x86_platform __read_only = {
26523 .calibrate_tsc = native_calibrate_tsc,
26524 .get_wallclock = mach_get_cmos_time,
26525 .set_wallclock = mach_set_rtc_mmss,
26526@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26527 };
26528
26529 EXPORT_SYMBOL_GPL(x86_platform);
26530-struct x86_msi_ops x86_msi = {
26531+struct x86_msi_ops x86_msi __read_only = {
26532 .setup_msi_irqs = native_setup_msi_irqs,
26533 .compose_msi_msg = native_compose_msi_msg,
26534 .teardown_msi_irq = native_teardown_msi_irq,
26535@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26536 .setup_hpet_msi = default_setup_hpet_msi,
26537 };
26538
26539-struct x86_io_apic_ops x86_io_apic_ops = {
26540+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26541 .init = native_io_apic_init_mappings,
26542 .read = native_io_apic_read,
26543 .write = native_io_apic_write,
26544diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26545index 422fd82..c3687ca 100644
26546--- a/arch/x86/kernel/xsave.c
26547+++ b/arch/x86/kernel/xsave.c
26548@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26549 {
26550 int err;
26551
26552+ buf = (struct xsave_struct __user *)____m(buf);
26553 if (use_xsave())
26554 err = xsave_user(buf);
26555 else if (use_fxsr())
26556@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26557 */
26558 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26559 {
26560+ buf = (void __user *)____m(buf);
26561 if (use_xsave()) {
26562 if ((unsigned long)buf % 64 || fx_only) {
26563 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26564diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26565index a20ecb5..d0e2194 100644
26566--- a/arch/x86/kvm/cpuid.c
26567+++ b/arch/x86/kvm/cpuid.c
26568@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26569 struct kvm_cpuid2 *cpuid,
26570 struct kvm_cpuid_entry2 __user *entries)
26571 {
26572- int r;
26573+ int r, i;
26574
26575 r = -E2BIG;
26576 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26577 goto out;
26578 r = -EFAULT;
26579- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26580- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26581+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26582 goto out;
26583+ for (i = 0; i < cpuid->nent; ++i) {
26584+ struct kvm_cpuid_entry2 cpuid_entry;
26585+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26586+ goto out;
26587+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26588+ }
26589 vcpu->arch.cpuid_nent = cpuid->nent;
26590 kvm_apic_set_version(vcpu);
26591 kvm_x86_ops->cpuid_update(vcpu);
26592@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26593 struct kvm_cpuid2 *cpuid,
26594 struct kvm_cpuid_entry2 __user *entries)
26595 {
26596- int r;
26597+ int r, i;
26598
26599 r = -E2BIG;
26600 if (cpuid->nent < vcpu->arch.cpuid_nent)
26601 goto out;
26602 r = -EFAULT;
26603- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26604- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26605+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26606 goto out;
26607+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26608+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26609+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26610+ goto out;
26611+ }
26612 return 0;
26613
26614 out:
26615diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26616index afc1124..3e431f2 100644
26617--- a/arch/x86/kvm/lapic.c
26618+++ b/arch/x86/kvm/lapic.c
26619@@ -55,7 +55,7 @@
26620 #define APIC_BUS_CYCLE_NS 1
26621
26622 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26623-#define apic_debug(fmt, arg...)
26624+#define apic_debug(fmt, arg...) do {} while (0)
26625
26626 #define APIC_LVT_NUM 6
26627 /* 14 is the version for Xeon and Pentium 8.4.8*/
26628diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26629index 7769699..c8aca4a7f 100644
26630--- a/arch/x86/kvm/paging_tmpl.h
26631+++ b/arch/x86/kvm/paging_tmpl.h
26632@@ -208,7 +208,7 @@ retry_walk:
26633 if (unlikely(kvm_is_error_hva(host_addr)))
26634 goto error;
26635
26636- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26637+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26638 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26639 goto error;
26640 walker->ptep_user[walker->level - 1] = ptep_user;
26641diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26642index c0bc803..6837a50 100644
26643--- a/arch/x86/kvm/svm.c
26644+++ b/arch/x86/kvm/svm.c
26645@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26646 int cpu = raw_smp_processor_id();
26647
26648 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26649+
26650+ pax_open_kernel();
26651 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26652+ pax_close_kernel();
26653+
26654 load_TR_desc();
26655 }
26656
26657@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26658 #endif
26659 #endif
26660
26661+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26662+ __set_fs(current_thread_info()->addr_limit);
26663+#endif
26664+
26665 reload_tss(vcpu);
26666
26667 local_irq_disable();
26668diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26669index 064d0be..f5f758e 100644
26670--- a/arch/x86/kvm/vmx.c
26671+++ b/arch/x86/kvm/vmx.c
26672@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26673 #endif
26674 }
26675
26676-static void vmcs_clear_bits(unsigned long field, u32 mask)
26677+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26678 {
26679 vmcs_writel(field, vmcs_readl(field) & ~mask);
26680 }
26681
26682-static void vmcs_set_bits(unsigned long field, u32 mask)
26683+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26684 {
26685 vmcs_writel(field, vmcs_readl(field) | mask);
26686 }
26687@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26688 struct desc_struct *descs;
26689
26690 descs = (void *)gdt->address;
26691+
26692+ pax_open_kernel();
26693 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26694+ pax_close_kernel();
26695+
26696 load_TR_desc();
26697 }
26698
26699@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26700 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26701 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26702
26703+#ifdef CONFIG_PAX_PER_CPU_PGD
26704+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26705+#endif
26706+
26707 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26708 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26709 vmx->loaded_vmcs->cpu = cpu;
26710@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26711 if (!cpu_has_vmx_flexpriority())
26712 flexpriority_enabled = 0;
26713
26714- if (!cpu_has_vmx_tpr_shadow())
26715- kvm_x86_ops->update_cr8_intercept = NULL;
26716+ if (!cpu_has_vmx_tpr_shadow()) {
26717+ pax_open_kernel();
26718+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26719+ pax_close_kernel();
26720+ }
26721
26722 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26723 kvm_disable_largepages();
26724@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26725 if (!cpu_has_vmx_apicv())
26726 enable_apicv = 0;
26727
26728+ pax_open_kernel();
26729 if (enable_apicv)
26730- kvm_x86_ops->update_cr8_intercept = NULL;
26731+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26732 else {
26733- kvm_x86_ops->hwapic_irr_update = NULL;
26734- kvm_x86_ops->deliver_posted_interrupt = NULL;
26735- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26736+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26737+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26738+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26739 }
26740+ pax_close_kernel();
26741
26742 if (nested)
26743 nested_vmx_setup_ctls_msrs();
26744@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26745
26746 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26747 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26748+
26749+#ifndef CONFIG_PAX_PER_CPU_PGD
26750 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26751+#endif
26752
26753 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26754 #ifdef CONFIG_X86_64
26755@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26756 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26757 vmx->host_idt_base = dt.address;
26758
26759- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26760+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26761
26762 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26763 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26764@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26765 "jmp 2f \n\t"
26766 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26767 "2: "
26768+
26769+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26770+ "ljmp %[cs],$3f\n\t"
26771+ "3: "
26772+#endif
26773+
26774 /* Save guest registers, load host registers, keep flags */
26775 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26776 "pop %0 \n\t"
26777@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26778 #endif
26779 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26780 [wordsize]"i"(sizeof(ulong))
26781+
26782+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26783+ ,[cs]"i"(__KERNEL_CS)
26784+#endif
26785+
26786 : "cc", "memory"
26787 #ifdef CONFIG_X86_64
26788 , "rax", "rbx", "rdi", "rsi"
26789@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26790 if (debugctlmsr)
26791 update_debugctlmsr(debugctlmsr);
26792
26793-#ifndef CONFIG_X86_64
26794+#ifdef CONFIG_X86_32
26795 /*
26796 * The sysexit path does not restore ds/es, so we must set them to
26797 * a reasonable value ourselves.
26798@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26799 * may be executed in interrupt context, which saves and restore segments
26800 * around it, nullifying its effect.
26801 */
26802- loadsegment(ds, __USER_DS);
26803- loadsegment(es, __USER_DS);
26804+ loadsegment(ds, __KERNEL_DS);
26805+ loadsegment(es, __KERNEL_DS);
26806+ loadsegment(ss, __KERNEL_DS);
26807+
26808+#ifdef CONFIG_PAX_KERNEXEC
26809+ loadsegment(fs, __KERNEL_PERCPU);
26810+#endif
26811+
26812+#ifdef CONFIG_PAX_MEMORY_UDEREF
26813+ __set_fs(current_thread_info()->addr_limit);
26814+#endif
26815+
26816 #endif
26817
26818 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26819diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26820index d21bce5..fdae9f1 100644
26821--- a/arch/x86/kvm/x86.c
26822+++ b/arch/x86/kvm/x86.c
26823@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26824 {
26825 struct kvm *kvm = vcpu->kvm;
26826 int lm = is_long_mode(vcpu);
26827- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26828- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26829+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26830+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26831 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26832 : kvm->arch.xen_hvm_config.blob_size_32;
26833 u32 page_num = data & ~PAGE_MASK;
26834@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26835 if (n < msr_list.nmsrs)
26836 goto out;
26837 r = -EFAULT;
26838+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26839+ goto out;
26840 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26841 num_msrs_to_save * sizeof(u32)))
26842 goto out;
26843@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26844 };
26845 #endif
26846
26847-int kvm_arch_init(void *opaque)
26848+int kvm_arch_init(const void *opaque)
26849 {
26850 int r;
26851 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26852diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26853index 6a22c19..1763f04 100644
26854--- a/arch/x86/lguest/boot.c
26855+++ b/arch/x86/lguest/boot.c
26856@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26857 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26858 * Launcher to reboot us.
26859 */
26860-static void lguest_restart(char *reason)
26861+static __noreturn void lguest_restart(char *reason)
26862 {
26863 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26864+ BUG();
26865 }
26866
26867 /*G:050
26868diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26869index 00933d5..3a64af9 100644
26870--- a/arch/x86/lib/atomic64_386_32.S
26871+++ b/arch/x86/lib/atomic64_386_32.S
26872@@ -48,6 +48,10 @@ BEGIN(read)
26873 movl (v), %eax
26874 movl 4(v), %edx
26875 RET_ENDP
26876+BEGIN(read_unchecked)
26877+ movl (v), %eax
26878+ movl 4(v), %edx
26879+RET_ENDP
26880 #undef v
26881
26882 #define v %esi
26883@@ -55,6 +59,10 @@ BEGIN(set)
26884 movl %ebx, (v)
26885 movl %ecx, 4(v)
26886 RET_ENDP
26887+BEGIN(set_unchecked)
26888+ movl %ebx, (v)
26889+ movl %ecx, 4(v)
26890+RET_ENDP
26891 #undef v
26892
26893 #define v %esi
26894@@ -70,6 +78,20 @@ RET_ENDP
26895 BEGIN(add)
26896 addl %eax, (v)
26897 adcl %edx, 4(v)
26898+
26899+#ifdef CONFIG_PAX_REFCOUNT
26900+ jno 0f
26901+ subl %eax, (v)
26902+ sbbl %edx, 4(v)
26903+ int $4
26904+0:
26905+ _ASM_EXTABLE(0b, 0b)
26906+#endif
26907+
26908+RET_ENDP
26909+BEGIN(add_unchecked)
26910+ addl %eax, (v)
26911+ adcl %edx, 4(v)
26912 RET_ENDP
26913 #undef v
26914
26915@@ -77,6 +99,24 @@ RET_ENDP
26916 BEGIN(add_return)
26917 addl (v), %eax
26918 adcl 4(v), %edx
26919+
26920+#ifdef CONFIG_PAX_REFCOUNT
26921+ into
26922+1234:
26923+ _ASM_EXTABLE(1234b, 2f)
26924+#endif
26925+
26926+ movl %eax, (v)
26927+ movl %edx, 4(v)
26928+
26929+#ifdef CONFIG_PAX_REFCOUNT
26930+2:
26931+#endif
26932+
26933+RET_ENDP
26934+BEGIN(add_return_unchecked)
26935+ addl (v), %eax
26936+ adcl 4(v), %edx
26937 movl %eax, (v)
26938 movl %edx, 4(v)
26939 RET_ENDP
26940@@ -86,6 +126,20 @@ RET_ENDP
26941 BEGIN(sub)
26942 subl %eax, (v)
26943 sbbl %edx, 4(v)
26944+
26945+#ifdef CONFIG_PAX_REFCOUNT
26946+ jno 0f
26947+ addl %eax, (v)
26948+ adcl %edx, 4(v)
26949+ int $4
26950+0:
26951+ _ASM_EXTABLE(0b, 0b)
26952+#endif
26953+
26954+RET_ENDP
26955+BEGIN(sub_unchecked)
26956+ subl %eax, (v)
26957+ sbbl %edx, 4(v)
26958 RET_ENDP
26959 #undef v
26960
26961@@ -96,6 +150,27 @@ BEGIN(sub_return)
26962 sbbl $0, %edx
26963 addl (v), %eax
26964 adcl 4(v), %edx
26965+
26966+#ifdef CONFIG_PAX_REFCOUNT
26967+ into
26968+1234:
26969+ _ASM_EXTABLE(1234b, 2f)
26970+#endif
26971+
26972+ movl %eax, (v)
26973+ movl %edx, 4(v)
26974+
26975+#ifdef CONFIG_PAX_REFCOUNT
26976+2:
26977+#endif
26978+
26979+RET_ENDP
26980+BEGIN(sub_return_unchecked)
26981+ negl %edx
26982+ negl %eax
26983+ sbbl $0, %edx
26984+ addl (v), %eax
26985+ adcl 4(v), %edx
26986 movl %eax, (v)
26987 movl %edx, 4(v)
26988 RET_ENDP
26989@@ -105,6 +180,20 @@ RET_ENDP
26990 BEGIN(inc)
26991 addl $1, (v)
26992 adcl $0, 4(v)
26993+
26994+#ifdef CONFIG_PAX_REFCOUNT
26995+ jno 0f
26996+ subl $1, (v)
26997+ sbbl $0, 4(v)
26998+ int $4
26999+0:
27000+ _ASM_EXTABLE(0b, 0b)
27001+#endif
27002+
27003+RET_ENDP
27004+BEGIN(inc_unchecked)
27005+ addl $1, (v)
27006+ adcl $0, 4(v)
27007 RET_ENDP
27008 #undef v
27009
27010@@ -114,6 +203,26 @@ BEGIN(inc_return)
27011 movl 4(v), %edx
27012 addl $1, %eax
27013 adcl $0, %edx
27014+
27015+#ifdef CONFIG_PAX_REFCOUNT
27016+ into
27017+1234:
27018+ _ASM_EXTABLE(1234b, 2f)
27019+#endif
27020+
27021+ movl %eax, (v)
27022+ movl %edx, 4(v)
27023+
27024+#ifdef CONFIG_PAX_REFCOUNT
27025+2:
27026+#endif
27027+
27028+RET_ENDP
27029+BEGIN(inc_return_unchecked)
27030+ movl (v), %eax
27031+ movl 4(v), %edx
27032+ addl $1, %eax
27033+ adcl $0, %edx
27034 movl %eax, (v)
27035 movl %edx, 4(v)
27036 RET_ENDP
27037@@ -123,6 +232,20 @@ RET_ENDP
27038 BEGIN(dec)
27039 subl $1, (v)
27040 sbbl $0, 4(v)
27041+
27042+#ifdef CONFIG_PAX_REFCOUNT
27043+ jno 0f
27044+ addl $1, (v)
27045+ adcl $0, 4(v)
27046+ int $4
27047+0:
27048+ _ASM_EXTABLE(0b, 0b)
27049+#endif
27050+
27051+RET_ENDP
27052+BEGIN(dec_unchecked)
27053+ subl $1, (v)
27054+ sbbl $0, 4(v)
27055 RET_ENDP
27056 #undef v
27057
27058@@ -132,6 +255,26 @@ BEGIN(dec_return)
27059 movl 4(v), %edx
27060 subl $1, %eax
27061 sbbl $0, %edx
27062+
27063+#ifdef CONFIG_PAX_REFCOUNT
27064+ into
27065+1234:
27066+ _ASM_EXTABLE(1234b, 2f)
27067+#endif
27068+
27069+ movl %eax, (v)
27070+ movl %edx, 4(v)
27071+
27072+#ifdef CONFIG_PAX_REFCOUNT
27073+2:
27074+#endif
27075+
27076+RET_ENDP
27077+BEGIN(dec_return_unchecked)
27078+ movl (v), %eax
27079+ movl 4(v), %edx
27080+ subl $1, %eax
27081+ sbbl $0, %edx
27082 movl %eax, (v)
27083 movl %edx, 4(v)
27084 RET_ENDP
27085@@ -143,6 +286,13 @@ BEGIN(add_unless)
27086 adcl %edx, %edi
27087 addl (v), %eax
27088 adcl 4(v), %edx
27089+
27090+#ifdef CONFIG_PAX_REFCOUNT
27091+ into
27092+1234:
27093+ _ASM_EXTABLE(1234b, 2f)
27094+#endif
27095+
27096 cmpl %eax, %ecx
27097 je 3f
27098 1:
27099@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27100 1:
27101 addl $1, %eax
27102 adcl $0, %edx
27103+
27104+#ifdef CONFIG_PAX_REFCOUNT
27105+ into
27106+1234:
27107+ _ASM_EXTABLE(1234b, 2f)
27108+#endif
27109+
27110 movl %eax, (v)
27111 movl %edx, 4(v)
27112 movl $1, %eax
27113@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27114 movl 4(v), %edx
27115 subl $1, %eax
27116 sbbl $0, %edx
27117+
27118+#ifdef CONFIG_PAX_REFCOUNT
27119+ into
27120+1234:
27121+ _ASM_EXTABLE(1234b, 1f)
27122+#endif
27123+
27124 js 1f
27125 movl %eax, (v)
27126 movl %edx, 4(v)
27127diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27128index f5cc9eb..51fa319 100644
27129--- a/arch/x86/lib/atomic64_cx8_32.S
27130+++ b/arch/x86/lib/atomic64_cx8_32.S
27131@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27132 CFI_STARTPROC
27133
27134 read64 %ecx
27135+ pax_force_retaddr
27136 ret
27137 CFI_ENDPROC
27138 ENDPROC(atomic64_read_cx8)
27139
27140+ENTRY(atomic64_read_unchecked_cx8)
27141+ CFI_STARTPROC
27142+
27143+ read64 %ecx
27144+ pax_force_retaddr
27145+ ret
27146+ CFI_ENDPROC
27147+ENDPROC(atomic64_read_unchecked_cx8)
27148+
27149 ENTRY(atomic64_set_cx8)
27150 CFI_STARTPROC
27151
27152@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27153 cmpxchg8b (%esi)
27154 jne 1b
27155
27156+ pax_force_retaddr
27157 ret
27158 CFI_ENDPROC
27159 ENDPROC(atomic64_set_cx8)
27160
27161+ENTRY(atomic64_set_unchecked_cx8)
27162+ CFI_STARTPROC
27163+
27164+1:
27165+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27166+ * are atomic on 586 and newer */
27167+ cmpxchg8b (%esi)
27168+ jne 1b
27169+
27170+ pax_force_retaddr
27171+ ret
27172+ CFI_ENDPROC
27173+ENDPROC(atomic64_set_unchecked_cx8)
27174+
27175 ENTRY(atomic64_xchg_cx8)
27176 CFI_STARTPROC
27177
27178@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27179 cmpxchg8b (%esi)
27180 jne 1b
27181
27182+ pax_force_retaddr
27183 ret
27184 CFI_ENDPROC
27185 ENDPROC(atomic64_xchg_cx8)
27186
27187-.macro addsub_return func ins insc
27188-ENTRY(atomic64_\func\()_return_cx8)
27189+.macro addsub_return func ins insc unchecked=""
27190+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27191 CFI_STARTPROC
27192 SAVE ebp
27193 SAVE ebx
27194@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27195 movl %edx, %ecx
27196 \ins\()l %esi, %ebx
27197 \insc\()l %edi, %ecx
27198+
27199+.ifb \unchecked
27200+#ifdef CONFIG_PAX_REFCOUNT
27201+ into
27202+2:
27203+ _ASM_EXTABLE(2b, 3f)
27204+#endif
27205+.endif
27206+
27207 LOCK_PREFIX
27208 cmpxchg8b (%ebp)
27209 jne 1b
27210-
27211-10:
27212 movl %ebx, %eax
27213 movl %ecx, %edx
27214+
27215+.ifb \unchecked
27216+#ifdef CONFIG_PAX_REFCOUNT
27217+3:
27218+#endif
27219+.endif
27220+
27221 RESTORE edi
27222 RESTORE esi
27223 RESTORE ebx
27224 RESTORE ebp
27225+ pax_force_retaddr
27226 ret
27227 CFI_ENDPROC
27228-ENDPROC(atomic64_\func\()_return_cx8)
27229+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27230 .endm
27231
27232 addsub_return add add adc
27233 addsub_return sub sub sbb
27234+addsub_return add add adc _unchecked
27235+addsub_return sub sub sbb _unchecked
27236
27237-.macro incdec_return func ins insc
27238-ENTRY(atomic64_\func\()_return_cx8)
27239+.macro incdec_return func ins insc unchecked=""
27240+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27241 CFI_STARTPROC
27242 SAVE ebx
27243
27244@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27245 movl %edx, %ecx
27246 \ins\()l $1, %ebx
27247 \insc\()l $0, %ecx
27248+
27249+.ifb \unchecked
27250+#ifdef CONFIG_PAX_REFCOUNT
27251+ into
27252+2:
27253+ _ASM_EXTABLE(2b, 3f)
27254+#endif
27255+.endif
27256+
27257 LOCK_PREFIX
27258 cmpxchg8b (%esi)
27259 jne 1b
27260
27261-10:
27262 movl %ebx, %eax
27263 movl %ecx, %edx
27264+
27265+.ifb \unchecked
27266+#ifdef CONFIG_PAX_REFCOUNT
27267+3:
27268+#endif
27269+.endif
27270+
27271 RESTORE ebx
27272+ pax_force_retaddr
27273 ret
27274 CFI_ENDPROC
27275-ENDPROC(atomic64_\func\()_return_cx8)
27276+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27277 .endm
27278
27279 incdec_return inc add adc
27280 incdec_return dec sub sbb
27281+incdec_return inc add adc _unchecked
27282+incdec_return dec sub sbb _unchecked
27283
27284 ENTRY(atomic64_dec_if_positive_cx8)
27285 CFI_STARTPROC
27286@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27287 movl %edx, %ecx
27288 subl $1, %ebx
27289 sbb $0, %ecx
27290+
27291+#ifdef CONFIG_PAX_REFCOUNT
27292+ into
27293+1234:
27294+ _ASM_EXTABLE(1234b, 2f)
27295+#endif
27296+
27297 js 2f
27298 LOCK_PREFIX
27299 cmpxchg8b (%esi)
27300@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27301 movl %ebx, %eax
27302 movl %ecx, %edx
27303 RESTORE ebx
27304+ pax_force_retaddr
27305 ret
27306 CFI_ENDPROC
27307 ENDPROC(atomic64_dec_if_positive_cx8)
27308@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27309 movl %edx, %ecx
27310 addl %ebp, %ebx
27311 adcl %edi, %ecx
27312+
27313+#ifdef CONFIG_PAX_REFCOUNT
27314+ into
27315+1234:
27316+ _ASM_EXTABLE(1234b, 3f)
27317+#endif
27318+
27319 LOCK_PREFIX
27320 cmpxchg8b (%esi)
27321 jne 1b
27322@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27323 CFI_ADJUST_CFA_OFFSET -8
27324 RESTORE ebx
27325 RESTORE ebp
27326+ pax_force_retaddr
27327 ret
27328 4:
27329 cmpl %edx, 4(%esp)
27330@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27331 xorl %ecx, %ecx
27332 addl $1, %ebx
27333 adcl %edx, %ecx
27334+
27335+#ifdef CONFIG_PAX_REFCOUNT
27336+ into
27337+1234:
27338+ _ASM_EXTABLE(1234b, 3f)
27339+#endif
27340+
27341 LOCK_PREFIX
27342 cmpxchg8b (%esi)
27343 jne 1b
27344@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27345 movl $1, %eax
27346 3:
27347 RESTORE ebx
27348+ pax_force_retaddr
27349 ret
27350 CFI_ENDPROC
27351 ENDPROC(atomic64_inc_not_zero_cx8)
27352diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27353index e78b8ee..7e173a8 100644
27354--- a/arch/x86/lib/checksum_32.S
27355+++ b/arch/x86/lib/checksum_32.S
27356@@ -29,7 +29,8 @@
27357 #include <asm/dwarf2.h>
27358 #include <asm/errno.h>
27359 #include <asm/asm.h>
27360-
27361+#include <asm/segment.h>
27362+
27363 /*
27364 * computes a partial checksum, e.g. for TCP/UDP fragments
27365 */
27366@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27367
27368 #define ARGBASE 16
27369 #define FP 12
27370-
27371-ENTRY(csum_partial_copy_generic)
27372+
27373+ENTRY(csum_partial_copy_generic_to_user)
27374 CFI_STARTPROC
27375+
27376+#ifdef CONFIG_PAX_MEMORY_UDEREF
27377+ pushl_cfi %gs
27378+ popl_cfi %es
27379+ jmp csum_partial_copy_generic
27380+#endif
27381+
27382+ENTRY(csum_partial_copy_generic_from_user)
27383+
27384+#ifdef CONFIG_PAX_MEMORY_UDEREF
27385+ pushl_cfi %gs
27386+ popl_cfi %ds
27387+#endif
27388+
27389+ENTRY(csum_partial_copy_generic)
27390 subl $4,%esp
27391 CFI_ADJUST_CFA_OFFSET 4
27392 pushl_cfi %edi
27393@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27394 jmp 4f
27395 SRC(1: movw (%esi), %bx )
27396 addl $2, %esi
27397-DST( movw %bx, (%edi) )
27398+DST( movw %bx, %es:(%edi) )
27399 addl $2, %edi
27400 addw %bx, %ax
27401 adcl $0, %eax
27402@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27403 SRC(1: movl (%esi), %ebx )
27404 SRC( movl 4(%esi), %edx )
27405 adcl %ebx, %eax
27406-DST( movl %ebx, (%edi) )
27407+DST( movl %ebx, %es:(%edi) )
27408 adcl %edx, %eax
27409-DST( movl %edx, 4(%edi) )
27410+DST( movl %edx, %es:4(%edi) )
27411
27412 SRC( movl 8(%esi), %ebx )
27413 SRC( movl 12(%esi), %edx )
27414 adcl %ebx, %eax
27415-DST( movl %ebx, 8(%edi) )
27416+DST( movl %ebx, %es:8(%edi) )
27417 adcl %edx, %eax
27418-DST( movl %edx, 12(%edi) )
27419+DST( movl %edx, %es:12(%edi) )
27420
27421 SRC( movl 16(%esi), %ebx )
27422 SRC( movl 20(%esi), %edx )
27423 adcl %ebx, %eax
27424-DST( movl %ebx, 16(%edi) )
27425+DST( movl %ebx, %es:16(%edi) )
27426 adcl %edx, %eax
27427-DST( movl %edx, 20(%edi) )
27428+DST( movl %edx, %es:20(%edi) )
27429
27430 SRC( movl 24(%esi), %ebx )
27431 SRC( movl 28(%esi), %edx )
27432 adcl %ebx, %eax
27433-DST( movl %ebx, 24(%edi) )
27434+DST( movl %ebx, %es:24(%edi) )
27435 adcl %edx, %eax
27436-DST( movl %edx, 28(%edi) )
27437+DST( movl %edx, %es:28(%edi) )
27438
27439 lea 32(%esi), %esi
27440 lea 32(%edi), %edi
27441@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27442 shrl $2, %edx # This clears CF
27443 SRC(3: movl (%esi), %ebx )
27444 adcl %ebx, %eax
27445-DST( movl %ebx, (%edi) )
27446+DST( movl %ebx, %es:(%edi) )
27447 lea 4(%esi), %esi
27448 lea 4(%edi), %edi
27449 dec %edx
27450@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27451 jb 5f
27452 SRC( movw (%esi), %cx )
27453 leal 2(%esi), %esi
27454-DST( movw %cx, (%edi) )
27455+DST( movw %cx, %es:(%edi) )
27456 leal 2(%edi), %edi
27457 je 6f
27458 shll $16,%ecx
27459 SRC(5: movb (%esi), %cl )
27460-DST( movb %cl, (%edi) )
27461+DST( movb %cl, %es:(%edi) )
27462 6: addl %ecx, %eax
27463 adcl $0, %eax
27464 7:
27465@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27466
27467 6001:
27468 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27469- movl $-EFAULT, (%ebx)
27470+ movl $-EFAULT, %ss:(%ebx)
27471
27472 # zero the complete destination - computing the rest
27473 # is too much work
27474@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27475
27476 6002:
27477 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27478- movl $-EFAULT,(%ebx)
27479+ movl $-EFAULT,%ss:(%ebx)
27480 jmp 5000b
27481
27482 .previous
27483
27484+ pushl_cfi %ss
27485+ popl_cfi %ds
27486+ pushl_cfi %ss
27487+ popl_cfi %es
27488 popl_cfi %ebx
27489 CFI_RESTORE ebx
27490 popl_cfi %esi
27491@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27492 popl_cfi %ecx # equivalent to addl $4,%esp
27493 ret
27494 CFI_ENDPROC
27495-ENDPROC(csum_partial_copy_generic)
27496+ENDPROC(csum_partial_copy_generic_to_user)
27497
27498 #else
27499
27500 /* Version for PentiumII/PPro */
27501
27502 #define ROUND1(x) \
27503+ nop; nop; nop; \
27504 SRC(movl x(%esi), %ebx ) ; \
27505 addl %ebx, %eax ; \
27506- DST(movl %ebx, x(%edi) ) ;
27507+ DST(movl %ebx, %es:x(%edi)) ;
27508
27509 #define ROUND(x) \
27510+ nop; nop; nop; \
27511 SRC(movl x(%esi), %ebx ) ; \
27512 adcl %ebx, %eax ; \
27513- DST(movl %ebx, x(%edi) ) ;
27514+ DST(movl %ebx, %es:x(%edi)) ;
27515
27516 #define ARGBASE 12
27517-
27518-ENTRY(csum_partial_copy_generic)
27519+
27520+ENTRY(csum_partial_copy_generic_to_user)
27521 CFI_STARTPROC
27522+
27523+#ifdef CONFIG_PAX_MEMORY_UDEREF
27524+ pushl_cfi %gs
27525+ popl_cfi %es
27526+ jmp csum_partial_copy_generic
27527+#endif
27528+
27529+ENTRY(csum_partial_copy_generic_from_user)
27530+
27531+#ifdef CONFIG_PAX_MEMORY_UDEREF
27532+ pushl_cfi %gs
27533+ popl_cfi %ds
27534+#endif
27535+
27536+ENTRY(csum_partial_copy_generic)
27537 pushl_cfi %ebx
27538 CFI_REL_OFFSET ebx, 0
27539 pushl_cfi %edi
27540@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27541 subl %ebx, %edi
27542 lea -1(%esi),%edx
27543 andl $-32,%edx
27544- lea 3f(%ebx,%ebx), %ebx
27545+ lea 3f(%ebx,%ebx,2), %ebx
27546 testl %esi, %esi
27547 jmp *%ebx
27548 1: addl $64,%esi
27549@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27550 jb 5f
27551 SRC( movw (%esi), %dx )
27552 leal 2(%esi), %esi
27553-DST( movw %dx, (%edi) )
27554+DST( movw %dx, %es:(%edi) )
27555 leal 2(%edi), %edi
27556 je 6f
27557 shll $16,%edx
27558 5:
27559 SRC( movb (%esi), %dl )
27560-DST( movb %dl, (%edi) )
27561+DST( movb %dl, %es:(%edi) )
27562 6: addl %edx, %eax
27563 adcl $0, %eax
27564 7:
27565 .section .fixup, "ax"
27566 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27567- movl $-EFAULT, (%ebx)
27568+ movl $-EFAULT, %ss:(%ebx)
27569 # zero the complete destination (computing the rest is too much work)
27570 movl ARGBASE+8(%esp),%edi # dst
27571 movl ARGBASE+12(%esp),%ecx # len
27572@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27573 rep; stosb
27574 jmp 7b
27575 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27576- movl $-EFAULT, (%ebx)
27577+ movl $-EFAULT, %ss:(%ebx)
27578 jmp 7b
27579 .previous
27580
27581+#ifdef CONFIG_PAX_MEMORY_UDEREF
27582+ pushl_cfi %ss
27583+ popl_cfi %ds
27584+ pushl_cfi %ss
27585+ popl_cfi %es
27586+#endif
27587+
27588 popl_cfi %esi
27589 CFI_RESTORE esi
27590 popl_cfi %edi
27591@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27592 CFI_RESTORE ebx
27593 ret
27594 CFI_ENDPROC
27595-ENDPROC(csum_partial_copy_generic)
27596+ENDPROC(csum_partial_copy_generic_to_user)
27597
27598 #undef ROUND
27599 #undef ROUND1
27600diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27601index f2145cf..cea889d 100644
27602--- a/arch/x86/lib/clear_page_64.S
27603+++ b/arch/x86/lib/clear_page_64.S
27604@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27605 movl $4096/8,%ecx
27606 xorl %eax,%eax
27607 rep stosq
27608+ pax_force_retaddr
27609 ret
27610 CFI_ENDPROC
27611 ENDPROC(clear_page_c)
27612@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27613 movl $4096,%ecx
27614 xorl %eax,%eax
27615 rep stosb
27616+ pax_force_retaddr
27617 ret
27618 CFI_ENDPROC
27619 ENDPROC(clear_page_c_e)
27620@@ -43,6 +45,7 @@ ENTRY(clear_page)
27621 leaq 64(%rdi),%rdi
27622 jnz .Lloop
27623 nop
27624+ pax_force_retaddr
27625 ret
27626 CFI_ENDPROC
27627 .Lclear_page_end:
27628@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27629
27630 #include <asm/cpufeature.h>
27631
27632- .section .altinstr_replacement,"ax"
27633+ .section .altinstr_replacement,"a"
27634 1: .byte 0xeb /* jmp <disp8> */
27635 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27636 2: .byte 0xeb /* jmp <disp8> */
27637diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27638index 1e572c5..2a162cd 100644
27639--- a/arch/x86/lib/cmpxchg16b_emu.S
27640+++ b/arch/x86/lib/cmpxchg16b_emu.S
27641@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27642
27643 popf
27644 mov $1, %al
27645+ pax_force_retaddr
27646 ret
27647
27648 not_same:
27649 popf
27650 xor %al,%al
27651+ pax_force_retaddr
27652 ret
27653
27654 CFI_ENDPROC
27655diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27656index 176cca6..1166c50 100644
27657--- a/arch/x86/lib/copy_page_64.S
27658+++ b/arch/x86/lib/copy_page_64.S
27659@@ -9,6 +9,7 @@ copy_page_rep:
27660 CFI_STARTPROC
27661 movl $4096/8, %ecx
27662 rep movsq
27663+ pax_force_retaddr
27664 ret
27665 CFI_ENDPROC
27666 ENDPROC(copy_page_rep)
27667@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27668
27669 ENTRY(copy_page)
27670 CFI_STARTPROC
27671- subq $2*8, %rsp
27672- CFI_ADJUST_CFA_OFFSET 2*8
27673+ subq $3*8, %rsp
27674+ CFI_ADJUST_CFA_OFFSET 3*8
27675 movq %rbx, (%rsp)
27676 CFI_REL_OFFSET rbx, 0
27677 movq %r12, 1*8(%rsp)
27678 CFI_REL_OFFSET r12, 1*8
27679+ movq %r13, 2*8(%rsp)
27680+ CFI_REL_OFFSET r13, 2*8
27681
27682 movl $(4096/64)-5, %ecx
27683 .p2align 4
27684@@ -36,7 +39,7 @@ ENTRY(copy_page)
27685 movq 0x8*2(%rsi), %rdx
27686 movq 0x8*3(%rsi), %r8
27687 movq 0x8*4(%rsi), %r9
27688- movq 0x8*5(%rsi), %r10
27689+ movq 0x8*5(%rsi), %r13
27690 movq 0x8*6(%rsi), %r11
27691 movq 0x8*7(%rsi), %r12
27692
27693@@ -47,7 +50,7 @@ ENTRY(copy_page)
27694 movq %rdx, 0x8*2(%rdi)
27695 movq %r8, 0x8*3(%rdi)
27696 movq %r9, 0x8*4(%rdi)
27697- movq %r10, 0x8*5(%rdi)
27698+ movq %r13, 0x8*5(%rdi)
27699 movq %r11, 0x8*6(%rdi)
27700 movq %r12, 0x8*7(%rdi)
27701
27702@@ -66,7 +69,7 @@ ENTRY(copy_page)
27703 movq 0x8*2(%rsi), %rdx
27704 movq 0x8*3(%rsi), %r8
27705 movq 0x8*4(%rsi), %r9
27706- movq 0x8*5(%rsi), %r10
27707+ movq 0x8*5(%rsi), %r13
27708 movq 0x8*6(%rsi), %r11
27709 movq 0x8*7(%rsi), %r12
27710
27711@@ -75,7 +78,7 @@ ENTRY(copy_page)
27712 movq %rdx, 0x8*2(%rdi)
27713 movq %r8, 0x8*3(%rdi)
27714 movq %r9, 0x8*4(%rdi)
27715- movq %r10, 0x8*5(%rdi)
27716+ movq %r13, 0x8*5(%rdi)
27717 movq %r11, 0x8*6(%rdi)
27718 movq %r12, 0x8*7(%rdi)
27719
27720@@ -87,8 +90,11 @@ ENTRY(copy_page)
27721 CFI_RESTORE rbx
27722 movq 1*8(%rsp), %r12
27723 CFI_RESTORE r12
27724- addq $2*8, %rsp
27725- CFI_ADJUST_CFA_OFFSET -2*8
27726+ movq 2*8(%rsp), %r13
27727+ CFI_RESTORE r13
27728+ addq $3*8, %rsp
27729+ CFI_ADJUST_CFA_OFFSET -3*8
27730+ pax_force_retaddr
27731 ret
27732 .Lcopy_page_end:
27733 CFI_ENDPROC
27734@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27735
27736 #include <asm/cpufeature.h>
27737
27738- .section .altinstr_replacement,"ax"
27739+ .section .altinstr_replacement,"a"
27740 1: .byte 0xeb /* jmp <disp8> */
27741 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27742 2:
27743diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27744index a30ca15..6b3f4e1 100644
27745--- a/arch/x86/lib/copy_user_64.S
27746+++ b/arch/x86/lib/copy_user_64.S
27747@@ -18,31 +18,7 @@
27748 #include <asm/alternative-asm.h>
27749 #include <asm/asm.h>
27750 #include <asm/smap.h>
27751-
27752-/*
27753- * By placing feature2 after feature1 in altinstructions section, we logically
27754- * implement:
27755- * If CPU has feature2, jmp to alt2 is used
27756- * else if CPU has feature1, jmp to alt1 is used
27757- * else jmp to orig is used.
27758- */
27759- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27760-0:
27761- .byte 0xe9 /* 32bit jump */
27762- .long \orig-1f /* by default jump to orig */
27763-1:
27764- .section .altinstr_replacement,"ax"
27765-2: .byte 0xe9 /* near jump with 32bit immediate */
27766- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27767-3: .byte 0xe9 /* near jump with 32bit immediate */
27768- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27769- .previous
27770-
27771- .section .altinstructions,"a"
27772- altinstruction_entry 0b,2b,\feature1,5,5
27773- altinstruction_entry 0b,3b,\feature2,5,5
27774- .previous
27775- .endm
27776+#include <asm/pgtable.h>
27777
27778 .macro ALIGN_DESTINATION
27779 #ifdef FIX_ALIGNMENT
27780@@ -70,52 +46,6 @@
27781 #endif
27782 .endm
27783
27784-/* Standard copy_to_user with segment limit checking */
27785-ENTRY(_copy_to_user)
27786- CFI_STARTPROC
27787- GET_THREAD_INFO(%rax)
27788- movq %rdi,%rcx
27789- addq %rdx,%rcx
27790- jc bad_to_user
27791- cmpq TI_addr_limit(%rax),%rcx
27792- ja bad_to_user
27793- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27794- copy_user_generic_unrolled,copy_user_generic_string, \
27795- copy_user_enhanced_fast_string
27796- CFI_ENDPROC
27797-ENDPROC(_copy_to_user)
27798-
27799-/* Standard copy_from_user with segment limit checking */
27800-ENTRY(_copy_from_user)
27801- CFI_STARTPROC
27802- GET_THREAD_INFO(%rax)
27803- movq %rsi,%rcx
27804- addq %rdx,%rcx
27805- jc bad_from_user
27806- cmpq TI_addr_limit(%rax),%rcx
27807- ja bad_from_user
27808- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27809- copy_user_generic_unrolled,copy_user_generic_string, \
27810- copy_user_enhanced_fast_string
27811- CFI_ENDPROC
27812-ENDPROC(_copy_from_user)
27813-
27814- .section .fixup,"ax"
27815- /* must zero dest */
27816-ENTRY(bad_from_user)
27817-bad_from_user:
27818- CFI_STARTPROC
27819- movl %edx,%ecx
27820- xorl %eax,%eax
27821- rep
27822- stosb
27823-bad_to_user:
27824- movl %edx,%eax
27825- ret
27826- CFI_ENDPROC
27827-ENDPROC(bad_from_user)
27828- .previous
27829-
27830 /*
27831 * copy_user_generic_unrolled - memory copy with exception handling.
27832 * This version is for CPUs like P4 that don't have efficient micro
27833@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27834 */
27835 ENTRY(copy_user_generic_unrolled)
27836 CFI_STARTPROC
27837+ ASM_PAX_OPEN_USERLAND
27838 ASM_STAC
27839 cmpl $8,%edx
27840 jb 20f /* less then 8 bytes, go to byte copy loop */
27841@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27842 jz 17f
27843 1: movq (%rsi),%r8
27844 2: movq 1*8(%rsi),%r9
27845-3: movq 2*8(%rsi),%r10
27846+3: movq 2*8(%rsi),%rax
27847 4: movq 3*8(%rsi),%r11
27848 5: movq %r8,(%rdi)
27849 6: movq %r9,1*8(%rdi)
27850-7: movq %r10,2*8(%rdi)
27851+7: movq %rax,2*8(%rdi)
27852 8: movq %r11,3*8(%rdi)
27853 9: movq 4*8(%rsi),%r8
27854 10: movq 5*8(%rsi),%r9
27855-11: movq 6*8(%rsi),%r10
27856+11: movq 6*8(%rsi),%rax
27857 12: movq 7*8(%rsi),%r11
27858 13: movq %r8,4*8(%rdi)
27859 14: movq %r9,5*8(%rdi)
27860-15: movq %r10,6*8(%rdi)
27861+15: movq %rax,6*8(%rdi)
27862 16: movq %r11,7*8(%rdi)
27863 leaq 64(%rsi),%rsi
27864 leaq 64(%rdi),%rdi
27865@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27866 jnz 21b
27867 23: xor %eax,%eax
27868 ASM_CLAC
27869+ ASM_PAX_CLOSE_USERLAND
27870+ pax_force_retaddr
27871 ret
27872
27873 .section .fixup,"ax"
27874@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27875 */
27876 ENTRY(copy_user_generic_string)
27877 CFI_STARTPROC
27878+ ASM_PAX_OPEN_USERLAND
27879 ASM_STAC
27880 andl %edx,%edx
27881 jz 4f
27882@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27883 movsb
27884 4: xorl %eax,%eax
27885 ASM_CLAC
27886+ ASM_PAX_CLOSE_USERLAND
27887+ pax_force_retaddr
27888 ret
27889
27890 .section .fixup,"ax"
27891@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27892 */
27893 ENTRY(copy_user_enhanced_fast_string)
27894 CFI_STARTPROC
27895+ ASM_PAX_OPEN_USERLAND
27896 ASM_STAC
27897 andl %edx,%edx
27898 jz 2f
27899@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27900 movsb
27901 2: xorl %eax,%eax
27902 ASM_CLAC
27903+ ASM_PAX_CLOSE_USERLAND
27904+ pax_force_retaddr
27905 ret
27906
27907 .section .fixup,"ax"
27908diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27909index 6a4f43c..55d26f2 100644
27910--- a/arch/x86/lib/copy_user_nocache_64.S
27911+++ b/arch/x86/lib/copy_user_nocache_64.S
27912@@ -8,6 +8,7 @@
27913
27914 #include <linux/linkage.h>
27915 #include <asm/dwarf2.h>
27916+#include <asm/alternative-asm.h>
27917
27918 #define FIX_ALIGNMENT 1
27919
27920@@ -16,6 +17,7 @@
27921 #include <asm/thread_info.h>
27922 #include <asm/asm.h>
27923 #include <asm/smap.h>
27924+#include <asm/pgtable.h>
27925
27926 .macro ALIGN_DESTINATION
27927 #ifdef FIX_ALIGNMENT
27928@@ -49,6 +51,16 @@
27929 */
27930 ENTRY(__copy_user_nocache)
27931 CFI_STARTPROC
27932+
27933+#ifdef CONFIG_PAX_MEMORY_UDEREF
27934+ mov pax_user_shadow_base,%rcx
27935+ cmp %rcx,%rsi
27936+ jae 1f
27937+ add %rcx,%rsi
27938+1:
27939+#endif
27940+
27941+ ASM_PAX_OPEN_USERLAND
27942 ASM_STAC
27943 cmpl $8,%edx
27944 jb 20f /* less then 8 bytes, go to byte copy loop */
27945@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27946 jz 17f
27947 1: movq (%rsi),%r8
27948 2: movq 1*8(%rsi),%r9
27949-3: movq 2*8(%rsi),%r10
27950+3: movq 2*8(%rsi),%rax
27951 4: movq 3*8(%rsi),%r11
27952 5: movnti %r8,(%rdi)
27953 6: movnti %r9,1*8(%rdi)
27954-7: movnti %r10,2*8(%rdi)
27955+7: movnti %rax,2*8(%rdi)
27956 8: movnti %r11,3*8(%rdi)
27957 9: movq 4*8(%rsi),%r8
27958 10: movq 5*8(%rsi),%r9
27959-11: movq 6*8(%rsi),%r10
27960+11: movq 6*8(%rsi),%rax
27961 12: movq 7*8(%rsi),%r11
27962 13: movnti %r8,4*8(%rdi)
27963 14: movnti %r9,5*8(%rdi)
27964-15: movnti %r10,6*8(%rdi)
27965+15: movnti %rax,6*8(%rdi)
27966 16: movnti %r11,7*8(%rdi)
27967 leaq 64(%rsi),%rsi
27968 leaq 64(%rdi),%rdi
27969@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27970 jnz 21b
27971 23: xorl %eax,%eax
27972 ASM_CLAC
27973+ ASM_PAX_CLOSE_USERLAND
27974 sfence
27975+ pax_force_retaddr
27976 ret
27977
27978 .section .fixup,"ax"
27979diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27980index 2419d5f..953ee51 100644
27981--- a/arch/x86/lib/csum-copy_64.S
27982+++ b/arch/x86/lib/csum-copy_64.S
27983@@ -9,6 +9,7 @@
27984 #include <asm/dwarf2.h>
27985 #include <asm/errno.h>
27986 #include <asm/asm.h>
27987+#include <asm/alternative-asm.h>
27988
27989 /*
27990 * Checksum copy with exception handling.
27991@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27992 CFI_RESTORE rbp
27993 addq $7*8, %rsp
27994 CFI_ADJUST_CFA_OFFSET -7*8
27995+ pax_force_retaddr 0, 1
27996 ret
27997 CFI_RESTORE_STATE
27998
27999diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28000index 7609e0e..b449b98 100644
28001--- a/arch/x86/lib/csum-wrappers_64.c
28002+++ b/arch/x86/lib/csum-wrappers_64.c
28003@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28004 len -= 2;
28005 }
28006 }
28007+ pax_open_userland();
28008 stac();
28009- isum = csum_partial_copy_generic((__force const void *)src,
28010+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28011 dst, len, isum, errp, NULL);
28012 clac();
28013+ pax_close_userland();
28014 if (unlikely(*errp))
28015 goto out_err;
28016
28017@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28018 }
28019
28020 *errp = 0;
28021+ pax_open_userland();
28022 stac();
28023- ret = csum_partial_copy_generic(src, (void __force *)dst,
28024+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28025 len, isum, NULL, errp);
28026 clac();
28027+ pax_close_userland();
28028 return ret;
28029 }
28030 EXPORT_SYMBOL(csum_partial_copy_to_user);
28031diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28032index a451235..1daa956 100644
28033--- a/arch/x86/lib/getuser.S
28034+++ b/arch/x86/lib/getuser.S
28035@@ -33,17 +33,40 @@
28036 #include <asm/thread_info.h>
28037 #include <asm/asm.h>
28038 #include <asm/smap.h>
28039+#include <asm/segment.h>
28040+#include <asm/pgtable.h>
28041+#include <asm/alternative-asm.h>
28042+
28043+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28044+#define __copyuser_seg gs;
28045+#else
28046+#define __copyuser_seg
28047+#endif
28048
28049 .text
28050 ENTRY(__get_user_1)
28051 CFI_STARTPROC
28052+
28053+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28054 GET_THREAD_INFO(%_ASM_DX)
28055 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28056 jae bad_get_user
28057 ASM_STAC
28058-1: movzbl (%_ASM_AX),%edx
28059+
28060+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28061+ mov pax_user_shadow_base,%_ASM_DX
28062+ cmp %_ASM_DX,%_ASM_AX
28063+ jae 1234f
28064+ add %_ASM_DX,%_ASM_AX
28065+1234:
28066+#endif
28067+
28068+#endif
28069+
28070+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28071 xor %eax,%eax
28072 ASM_CLAC
28073+ pax_force_retaddr
28074 ret
28075 CFI_ENDPROC
28076 ENDPROC(__get_user_1)
28077@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28078 ENTRY(__get_user_2)
28079 CFI_STARTPROC
28080 add $1,%_ASM_AX
28081+
28082+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28083 jc bad_get_user
28084 GET_THREAD_INFO(%_ASM_DX)
28085 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28086 jae bad_get_user
28087 ASM_STAC
28088-2: movzwl -1(%_ASM_AX),%edx
28089+
28090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28091+ mov pax_user_shadow_base,%_ASM_DX
28092+ cmp %_ASM_DX,%_ASM_AX
28093+ jae 1234f
28094+ add %_ASM_DX,%_ASM_AX
28095+1234:
28096+#endif
28097+
28098+#endif
28099+
28100+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28101 xor %eax,%eax
28102 ASM_CLAC
28103+ pax_force_retaddr
28104 ret
28105 CFI_ENDPROC
28106 ENDPROC(__get_user_2)
28107@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28108 ENTRY(__get_user_4)
28109 CFI_STARTPROC
28110 add $3,%_ASM_AX
28111+
28112+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28113 jc bad_get_user
28114 GET_THREAD_INFO(%_ASM_DX)
28115 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28116 jae bad_get_user
28117 ASM_STAC
28118-3: movl -3(%_ASM_AX),%edx
28119+
28120+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28121+ mov pax_user_shadow_base,%_ASM_DX
28122+ cmp %_ASM_DX,%_ASM_AX
28123+ jae 1234f
28124+ add %_ASM_DX,%_ASM_AX
28125+1234:
28126+#endif
28127+
28128+#endif
28129+
28130+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28131 xor %eax,%eax
28132 ASM_CLAC
28133+ pax_force_retaddr
28134 ret
28135 CFI_ENDPROC
28136 ENDPROC(__get_user_4)
28137@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28138 GET_THREAD_INFO(%_ASM_DX)
28139 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28140 jae bad_get_user
28141+
28142+#ifdef CONFIG_PAX_MEMORY_UDEREF
28143+ mov pax_user_shadow_base,%_ASM_DX
28144+ cmp %_ASM_DX,%_ASM_AX
28145+ jae 1234f
28146+ add %_ASM_DX,%_ASM_AX
28147+1234:
28148+#endif
28149+
28150 ASM_STAC
28151 4: movq -7(%_ASM_AX),%rdx
28152 xor %eax,%eax
28153 ASM_CLAC
28154+ pax_force_retaddr
28155 ret
28156 #else
28157 add $7,%_ASM_AX
28158@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28159 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28160 jae bad_get_user_8
28161 ASM_STAC
28162-4: movl -7(%_ASM_AX),%edx
28163-5: movl -3(%_ASM_AX),%ecx
28164+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28165+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28166 xor %eax,%eax
28167 ASM_CLAC
28168+ pax_force_retaddr
28169 ret
28170 #endif
28171 CFI_ENDPROC
28172@@ -113,6 +175,7 @@ bad_get_user:
28173 xor %edx,%edx
28174 mov $(-EFAULT),%_ASM_AX
28175 ASM_CLAC
28176+ pax_force_retaddr
28177 ret
28178 CFI_ENDPROC
28179 END(bad_get_user)
28180@@ -124,6 +187,7 @@ bad_get_user_8:
28181 xor %ecx,%ecx
28182 mov $(-EFAULT),%_ASM_AX
28183 ASM_CLAC
28184+ pax_force_retaddr
28185 ret
28186 CFI_ENDPROC
28187 END(bad_get_user_8)
28188diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28189index 54fcffe..7be149e 100644
28190--- a/arch/x86/lib/insn.c
28191+++ b/arch/x86/lib/insn.c
28192@@ -20,8 +20,10 @@
28193
28194 #ifdef __KERNEL__
28195 #include <linux/string.h>
28196+#include <asm/pgtable_types.h>
28197 #else
28198 #include <string.h>
28199+#define ktla_ktva(addr) addr
28200 #endif
28201 #include <asm/inat.h>
28202 #include <asm/insn.h>
28203@@ -53,8 +55,8 @@
28204 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28205 {
28206 memset(insn, 0, sizeof(*insn));
28207- insn->kaddr = kaddr;
28208- insn->next_byte = kaddr;
28209+ insn->kaddr = ktla_ktva(kaddr);
28210+ insn->next_byte = ktla_ktva(kaddr);
28211 insn->x86_64 = x86_64 ? 1 : 0;
28212 insn->opnd_bytes = 4;
28213 if (x86_64)
28214diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28215index 05a95e7..326f2fa 100644
28216--- a/arch/x86/lib/iomap_copy_64.S
28217+++ b/arch/x86/lib/iomap_copy_64.S
28218@@ -17,6 +17,7 @@
28219
28220 #include <linux/linkage.h>
28221 #include <asm/dwarf2.h>
28222+#include <asm/alternative-asm.h>
28223
28224 /*
28225 * override generic version in lib/iomap_copy.c
28226@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28227 CFI_STARTPROC
28228 movl %edx,%ecx
28229 rep movsd
28230+ pax_force_retaddr
28231 ret
28232 CFI_ENDPROC
28233 ENDPROC(__iowrite32_copy)
28234diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28235index 56313a3..9b59269 100644
28236--- a/arch/x86/lib/memcpy_64.S
28237+++ b/arch/x86/lib/memcpy_64.S
28238@@ -24,7 +24,7 @@
28239 * This gets patched over the unrolled variant (below) via the
28240 * alternative instructions framework:
28241 */
28242- .section .altinstr_replacement, "ax", @progbits
28243+ .section .altinstr_replacement, "a", @progbits
28244 .Lmemcpy_c:
28245 movq %rdi, %rax
28246 movq %rdx, %rcx
28247@@ -33,6 +33,7 @@
28248 rep movsq
28249 movl %edx, %ecx
28250 rep movsb
28251+ pax_force_retaddr
28252 ret
28253 .Lmemcpy_e:
28254 .previous
28255@@ -44,11 +45,12 @@
28256 * This gets patched over the unrolled variant (below) via the
28257 * alternative instructions framework:
28258 */
28259- .section .altinstr_replacement, "ax", @progbits
28260+ .section .altinstr_replacement, "a", @progbits
28261 .Lmemcpy_c_e:
28262 movq %rdi, %rax
28263 movq %rdx, %rcx
28264 rep movsb
28265+ pax_force_retaddr
28266 ret
28267 .Lmemcpy_e_e:
28268 .previous
28269@@ -76,13 +78,13 @@ ENTRY(memcpy)
28270 */
28271 movq 0*8(%rsi), %r8
28272 movq 1*8(%rsi), %r9
28273- movq 2*8(%rsi), %r10
28274+ movq 2*8(%rsi), %rcx
28275 movq 3*8(%rsi), %r11
28276 leaq 4*8(%rsi), %rsi
28277
28278 movq %r8, 0*8(%rdi)
28279 movq %r9, 1*8(%rdi)
28280- movq %r10, 2*8(%rdi)
28281+ movq %rcx, 2*8(%rdi)
28282 movq %r11, 3*8(%rdi)
28283 leaq 4*8(%rdi), %rdi
28284 jae .Lcopy_forward_loop
28285@@ -105,12 +107,12 @@ ENTRY(memcpy)
28286 subq $0x20, %rdx
28287 movq -1*8(%rsi), %r8
28288 movq -2*8(%rsi), %r9
28289- movq -3*8(%rsi), %r10
28290+ movq -3*8(%rsi), %rcx
28291 movq -4*8(%rsi), %r11
28292 leaq -4*8(%rsi), %rsi
28293 movq %r8, -1*8(%rdi)
28294 movq %r9, -2*8(%rdi)
28295- movq %r10, -3*8(%rdi)
28296+ movq %rcx, -3*8(%rdi)
28297 movq %r11, -4*8(%rdi)
28298 leaq -4*8(%rdi), %rdi
28299 jae .Lcopy_backward_loop
28300@@ -130,12 +132,13 @@ ENTRY(memcpy)
28301 */
28302 movq 0*8(%rsi), %r8
28303 movq 1*8(%rsi), %r9
28304- movq -2*8(%rsi, %rdx), %r10
28305+ movq -2*8(%rsi, %rdx), %rcx
28306 movq -1*8(%rsi, %rdx), %r11
28307 movq %r8, 0*8(%rdi)
28308 movq %r9, 1*8(%rdi)
28309- movq %r10, -2*8(%rdi, %rdx)
28310+ movq %rcx, -2*8(%rdi, %rdx)
28311 movq %r11, -1*8(%rdi, %rdx)
28312+ pax_force_retaddr
28313 retq
28314 .p2align 4
28315 .Lless_16bytes:
28316@@ -148,6 +151,7 @@ ENTRY(memcpy)
28317 movq -1*8(%rsi, %rdx), %r9
28318 movq %r8, 0*8(%rdi)
28319 movq %r9, -1*8(%rdi, %rdx)
28320+ pax_force_retaddr
28321 retq
28322 .p2align 4
28323 .Lless_8bytes:
28324@@ -161,6 +165,7 @@ ENTRY(memcpy)
28325 movl -4(%rsi, %rdx), %r8d
28326 movl %ecx, (%rdi)
28327 movl %r8d, -4(%rdi, %rdx)
28328+ pax_force_retaddr
28329 retq
28330 .p2align 4
28331 .Lless_3bytes:
28332@@ -179,6 +184,7 @@ ENTRY(memcpy)
28333 movb %cl, (%rdi)
28334
28335 .Lend:
28336+ pax_force_retaddr
28337 retq
28338 CFI_ENDPROC
28339 ENDPROC(memcpy)
28340diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28341index 65268a6..5aa7815 100644
28342--- a/arch/x86/lib/memmove_64.S
28343+++ b/arch/x86/lib/memmove_64.S
28344@@ -61,13 +61,13 @@ ENTRY(memmove)
28345 5:
28346 sub $0x20, %rdx
28347 movq 0*8(%rsi), %r11
28348- movq 1*8(%rsi), %r10
28349+ movq 1*8(%rsi), %rcx
28350 movq 2*8(%rsi), %r9
28351 movq 3*8(%rsi), %r8
28352 leaq 4*8(%rsi), %rsi
28353
28354 movq %r11, 0*8(%rdi)
28355- movq %r10, 1*8(%rdi)
28356+ movq %rcx, 1*8(%rdi)
28357 movq %r9, 2*8(%rdi)
28358 movq %r8, 3*8(%rdi)
28359 leaq 4*8(%rdi), %rdi
28360@@ -81,10 +81,10 @@ ENTRY(memmove)
28361 4:
28362 movq %rdx, %rcx
28363 movq -8(%rsi, %rdx), %r11
28364- lea -8(%rdi, %rdx), %r10
28365+ lea -8(%rdi, %rdx), %r9
28366 shrq $3, %rcx
28367 rep movsq
28368- movq %r11, (%r10)
28369+ movq %r11, (%r9)
28370 jmp 13f
28371 .Lmemmove_end_forward:
28372
28373@@ -95,14 +95,14 @@ ENTRY(memmove)
28374 7:
28375 movq %rdx, %rcx
28376 movq (%rsi), %r11
28377- movq %rdi, %r10
28378+ movq %rdi, %r9
28379 leaq -8(%rsi, %rdx), %rsi
28380 leaq -8(%rdi, %rdx), %rdi
28381 shrq $3, %rcx
28382 std
28383 rep movsq
28384 cld
28385- movq %r11, (%r10)
28386+ movq %r11, (%r9)
28387 jmp 13f
28388
28389 /*
28390@@ -127,13 +127,13 @@ ENTRY(memmove)
28391 8:
28392 subq $0x20, %rdx
28393 movq -1*8(%rsi), %r11
28394- movq -2*8(%rsi), %r10
28395+ movq -2*8(%rsi), %rcx
28396 movq -3*8(%rsi), %r9
28397 movq -4*8(%rsi), %r8
28398 leaq -4*8(%rsi), %rsi
28399
28400 movq %r11, -1*8(%rdi)
28401- movq %r10, -2*8(%rdi)
28402+ movq %rcx, -2*8(%rdi)
28403 movq %r9, -3*8(%rdi)
28404 movq %r8, -4*8(%rdi)
28405 leaq -4*8(%rdi), %rdi
28406@@ -151,11 +151,11 @@ ENTRY(memmove)
28407 * Move data from 16 bytes to 31 bytes.
28408 */
28409 movq 0*8(%rsi), %r11
28410- movq 1*8(%rsi), %r10
28411+ movq 1*8(%rsi), %rcx
28412 movq -2*8(%rsi, %rdx), %r9
28413 movq -1*8(%rsi, %rdx), %r8
28414 movq %r11, 0*8(%rdi)
28415- movq %r10, 1*8(%rdi)
28416+ movq %rcx, 1*8(%rdi)
28417 movq %r9, -2*8(%rdi, %rdx)
28418 movq %r8, -1*8(%rdi, %rdx)
28419 jmp 13f
28420@@ -167,9 +167,9 @@ ENTRY(memmove)
28421 * Move data from 8 bytes to 15 bytes.
28422 */
28423 movq 0*8(%rsi), %r11
28424- movq -1*8(%rsi, %rdx), %r10
28425+ movq -1*8(%rsi, %rdx), %r9
28426 movq %r11, 0*8(%rdi)
28427- movq %r10, -1*8(%rdi, %rdx)
28428+ movq %r9, -1*8(%rdi, %rdx)
28429 jmp 13f
28430 10:
28431 cmpq $4, %rdx
28432@@ -178,9 +178,9 @@ ENTRY(memmove)
28433 * Move data from 4 bytes to 7 bytes.
28434 */
28435 movl (%rsi), %r11d
28436- movl -4(%rsi, %rdx), %r10d
28437+ movl -4(%rsi, %rdx), %r9d
28438 movl %r11d, (%rdi)
28439- movl %r10d, -4(%rdi, %rdx)
28440+ movl %r9d, -4(%rdi, %rdx)
28441 jmp 13f
28442 11:
28443 cmp $2, %rdx
28444@@ -189,9 +189,9 @@ ENTRY(memmove)
28445 * Move data from 2 bytes to 3 bytes.
28446 */
28447 movw (%rsi), %r11w
28448- movw -2(%rsi, %rdx), %r10w
28449+ movw -2(%rsi, %rdx), %r9w
28450 movw %r11w, (%rdi)
28451- movw %r10w, -2(%rdi, %rdx)
28452+ movw %r9w, -2(%rdi, %rdx)
28453 jmp 13f
28454 12:
28455 cmp $1, %rdx
28456@@ -202,14 +202,16 @@ ENTRY(memmove)
28457 movb (%rsi), %r11b
28458 movb %r11b, (%rdi)
28459 13:
28460+ pax_force_retaddr
28461 retq
28462 CFI_ENDPROC
28463
28464- .section .altinstr_replacement,"ax"
28465+ .section .altinstr_replacement,"a"
28466 .Lmemmove_begin_forward_efs:
28467 /* Forward moving data. */
28468 movq %rdx, %rcx
28469 rep movsb
28470+ pax_force_retaddr
28471 retq
28472 .Lmemmove_end_forward_efs:
28473 .previous
28474diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28475index 2dcb380..50a78bc 100644
28476--- a/arch/x86/lib/memset_64.S
28477+++ b/arch/x86/lib/memset_64.S
28478@@ -16,7 +16,7 @@
28479 *
28480 * rax original destination
28481 */
28482- .section .altinstr_replacement, "ax", @progbits
28483+ .section .altinstr_replacement, "a", @progbits
28484 .Lmemset_c:
28485 movq %rdi,%r9
28486 movq %rdx,%rcx
28487@@ -30,6 +30,7 @@
28488 movl %edx,%ecx
28489 rep stosb
28490 movq %r9,%rax
28491+ pax_force_retaddr
28492 ret
28493 .Lmemset_e:
28494 .previous
28495@@ -45,13 +46,14 @@
28496 *
28497 * rax original destination
28498 */
28499- .section .altinstr_replacement, "ax", @progbits
28500+ .section .altinstr_replacement, "a", @progbits
28501 .Lmemset_c_e:
28502 movq %rdi,%r9
28503 movb %sil,%al
28504 movq %rdx,%rcx
28505 rep stosb
28506 movq %r9,%rax
28507+ pax_force_retaddr
28508 ret
28509 .Lmemset_e_e:
28510 .previous
28511@@ -59,7 +61,7 @@
28512 ENTRY(memset)
28513 ENTRY(__memset)
28514 CFI_STARTPROC
28515- movq %rdi,%r10
28516+ movq %rdi,%r11
28517
28518 /* expand byte value */
28519 movzbl %sil,%ecx
28520@@ -117,7 +119,8 @@ ENTRY(__memset)
28521 jnz .Lloop_1
28522
28523 .Lende:
28524- movq %r10,%rax
28525+ movq %r11,%rax
28526+ pax_force_retaddr
28527 ret
28528
28529 CFI_RESTORE_STATE
28530diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28531index c9f2d9b..e7fd2c0 100644
28532--- a/arch/x86/lib/mmx_32.c
28533+++ b/arch/x86/lib/mmx_32.c
28534@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28535 {
28536 void *p;
28537 int i;
28538+ unsigned long cr0;
28539
28540 if (unlikely(in_interrupt()))
28541 return __memcpy(to, from, len);
28542@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28543 kernel_fpu_begin();
28544
28545 __asm__ __volatile__ (
28546- "1: prefetch (%0)\n" /* This set is 28 bytes */
28547- " prefetch 64(%0)\n"
28548- " prefetch 128(%0)\n"
28549- " prefetch 192(%0)\n"
28550- " prefetch 256(%0)\n"
28551+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28552+ " prefetch 64(%1)\n"
28553+ " prefetch 128(%1)\n"
28554+ " prefetch 192(%1)\n"
28555+ " prefetch 256(%1)\n"
28556 "2: \n"
28557 ".section .fixup, \"ax\"\n"
28558- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28559+ "3: \n"
28560+
28561+#ifdef CONFIG_PAX_KERNEXEC
28562+ " movl %%cr0, %0\n"
28563+ " movl %0, %%eax\n"
28564+ " andl $0xFFFEFFFF, %%eax\n"
28565+ " movl %%eax, %%cr0\n"
28566+#endif
28567+
28568+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28569+
28570+#ifdef CONFIG_PAX_KERNEXEC
28571+ " movl %0, %%cr0\n"
28572+#endif
28573+
28574 " jmp 2b\n"
28575 ".previous\n"
28576 _ASM_EXTABLE(1b, 3b)
28577- : : "r" (from));
28578+ : "=&r" (cr0) : "r" (from) : "ax");
28579
28580 for ( ; i > 5; i--) {
28581 __asm__ __volatile__ (
28582- "1: prefetch 320(%0)\n"
28583- "2: movq (%0), %%mm0\n"
28584- " movq 8(%0), %%mm1\n"
28585- " movq 16(%0), %%mm2\n"
28586- " movq 24(%0), %%mm3\n"
28587- " movq %%mm0, (%1)\n"
28588- " movq %%mm1, 8(%1)\n"
28589- " movq %%mm2, 16(%1)\n"
28590- " movq %%mm3, 24(%1)\n"
28591- " movq 32(%0), %%mm0\n"
28592- " movq 40(%0), %%mm1\n"
28593- " movq 48(%0), %%mm2\n"
28594- " movq 56(%0), %%mm3\n"
28595- " movq %%mm0, 32(%1)\n"
28596- " movq %%mm1, 40(%1)\n"
28597- " movq %%mm2, 48(%1)\n"
28598- " movq %%mm3, 56(%1)\n"
28599+ "1: prefetch 320(%1)\n"
28600+ "2: movq (%1), %%mm0\n"
28601+ " movq 8(%1), %%mm1\n"
28602+ " movq 16(%1), %%mm2\n"
28603+ " movq 24(%1), %%mm3\n"
28604+ " movq %%mm0, (%2)\n"
28605+ " movq %%mm1, 8(%2)\n"
28606+ " movq %%mm2, 16(%2)\n"
28607+ " movq %%mm3, 24(%2)\n"
28608+ " movq 32(%1), %%mm0\n"
28609+ " movq 40(%1), %%mm1\n"
28610+ " movq 48(%1), %%mm2\n"
28611+ " movq 56(%1), %%mm3\n"
28612+ " movq %%mm0, 32(%2)\n"
28613+ " movq %%mm1, 40(%2)\n"
28614+ " movq %%mm2, 48(%2)\n"
28615+ " movq %%mm3, 56(%2)\n"
28616 ".section .fixup, \"ax\"\n"
28617- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28618+ "3:\n"
28619+
28620+#ifdef CONFIG_PAX_KERNEXEC
28621+ " movl %%cr0, %0\n"
28622+ " movl %0, %%eax\n"
28623+ " andl $0xFFFEFFFF, %%eax\n"
28624+ " movl %%eax, %%cr0\n"
28625+#endif
28626+
28627+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28628+
28629+#ifdef CONFIG_PAX_KERNEXEC
28630+ " movl %0, %%cr0\n"
28631+#endif
28632+
28633 " jmp 2b\n"
28634 ".previous\n"
28635 _ASM_EXTABLE(1b, 3b)
28636- : : "r" (from), "r" (to) : "memory");
28637+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28638
28639 from += 64;
28640 to += 64;
28641@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28642 static void fast_copy_page(void *to, void *from)
28643 {
28644 int i;
28645+ unsigned long cr0;
28646
28647 kernel_fpu_begin();
28648
28649@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28650 * but that is for later. -AV
28651 */
28652 __asm__ __volatile__(
28653- "1: prefetch (%0)\n"
28654- " prefetch 64(%0)\n"
28655- " prefetch 128(%0)\n"
28656- " prefetch 192(%0)\n"
28657- " prefetch 256(%0)\n"
28658+ "1: prefetch (%1)\n"
28659+ " prefetch 64(%1)\n"
28660+ " prefetch 128(%1)\n"
28661+ " prefetch 192(%1)\n"
28662+ " prefetch 256(%1)\n"
28663 "2: \n"
28664 ".section .fixup, \"ax\"\n"
28665- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28666+ "3: \n"
28667+
28668+#ifdef CONFIG_PAX_KERNEXEC
28669+ " movl %%cr0, %0\n"
28670+ " movl %0, %%eax\n"
28671+ " andl $0xFFFEFFFF, %%eax\n"
28672+ " movl %%eax, %%cr0\n"
28673+#endif
28674+
28675+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28676+
28677+#ifdef CONFIG_PAX_KERNEXEC
28678+ " movl %0, %%cr0\n"
28679+#endif
28680+
28681 " jmp 2b\n"
28682 ".previous\n"
28683- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28684+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28685
28686 for (i = 0; i < (4096-320)/64; i++) {
28687 __asm__ __volatile__ (
28688- "1: prefetch 320(%0)\n"
28689- "2: movq (%0), %%mm0\n"
28690- " movntq %%mm0, (%1)\n"
28691- " movq 8(%0), %%mm1\n"
28692- " movntq %%mm1, 8(%1)\n"
28693- " movq 16(%0), %%mm2\n"
28694- " movntq %%mm2, 16(%1)\n"
28695- " movq 24(%0), %%mm3\n"
28696- " movntq %%mm3, 24(%1)\n"
28697- " movq 32(%0), %%mm4\n"
28698- " movntq %%mm4, 32(%1)\n"
28699- " movq 40(%0), %%mm5\n"
28700- " movntq %%mm5, 40(%1)\n"
28701- " movq 48(%0), %%mm6\n"
28702- " movntq %%mm6, 48(%1)\n"
28703- " movq 56(%0), %%mm7\n"
28704- " movntq %%mm7, 56(%1)\n"
28705+ "1: prefetch 320(%1)\n"
28706+ "2: movq (%1), %%mm0\n"
28707+ " movntq %%mm0, (%2)\n"
28708+ " movq 8(%1), %%mm1\n"
28709+ " movntq %%mm1, 8(%2)\n"
28710+ " movq 16(%1), %%mm2\n"
28711+ " movntq %%mm2, 16(%2)\n"
28712+ " movq 24(%1), %%mm3\n"
28713+ " movntq %%mm3, 24(%2)\n"
28714+ " movq 32(%1), %%mm4\n"
28715+ " movntq %%mm4, 32(%2)\n"
28716+ " movq 40(%1), %%mm5\n"
28717+ " movntq %%mm5, 40(%2)\n"
28718+ " movq 48(%1), %%mm6\n"
28719+ " movntq %%mm6, 48(%2)\n"
28720+ " movq 56(%1), %%mm7\n"
28721+ " movntq %%mm7, 56(%2)\n"
28722 ".section .fixup, \"ax\"\n"
28723- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28724+ "3:\n"
28725+
28726+#ifdef CONFIG_PAX_KERNEXEC
28727+ " movl %%cr0, %0\n"
28728+ " movl %0, %%eax\n"
28729+ " andl $0xFFFEFFFF, %%eax\n"
28730+ " movl %%eax, %%cr0\n"
28731+#endif
28732+
28733+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28734+
28735+#ifdef CONFIG_PAX_KERNEXEC
28736+ " movl %0, %%cr0\n"
28737+#endif
28738+
28739 " jmp 2b\n"
28740 ".previous\n"
28741- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28742+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28743
28744 from += 64;
28745 to += 64;
28746@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28747 static void fast_copy_page(void *to, void *from)
28748 {
28749 int i;
28750+ unsigned long cr0;
28751
28752 kernel_fpu_begin();
28753
28754 __asm__ __volatile__ (
28755- "1: prefetch (%0)\n"
28756- " prefetch 64(%0)\n"
28757- " prefetch 128(%0)\n"
28758- " prefetch 192(%0)\n"
28759- " prefetch 256(%0)\n"
28760+ "1: prefetch (%1)\n"
28761+ " prefetch 64(%1)\n"
28762+ " prefetch 128(%1)\n"
28763+ " prefetch 192(%1)\n"
28764+ " prefetch 256(%1)\n"
28765 "2: \n"
28766 ".section .fixup, \"ax\"\n"
28767- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28768+ "3: \n"
28769+
28770+#ifdef CONFIG_PAX_KERNEXEC
28771+ " movl %%cr0, %0\n"
28772+ " movl %0, %%eax\n"
28773+ " andl $0xFFFEFFFF, %%eax\n"
28774+ " movl %%eax, %%cr0\n"
28775+#endif
28776+
28777+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28778+
28779+#ifdef CONFIG_PAX_KERNEXEC
28780+ " movl %0, %%cr0\n"
28781+#endif
28782+
28783 " jmp 2b\n"
28784 ".previous\n"
28785- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28786+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28787
28788 for (i = 0; i < 4096/64; i++) {
28789 __asm__ __volatile__ (
28790- "1: prefetch 320(%0)\n"
28791- "2: movq (%0), %%mm0\n"
28792- " movq 8(%0), %%mm1\n"
28793- " movq 16(%0), %%mm2\n"
28794- " movq 24(%0), %%mm3\n"
28795- " movq %%mm0, (%1)\n"
28796- " movq %%mm1, 8(%1)\n"
28797- " movq %%mm2, 16(%1)\n"
28798- " movq %%mm3, 24(%1)\n"
28799- " movq 32(%0), %%mm0\n"
28800- " movq 40(%0), %%mm1\n"
28801- " movq 48(%0), %%mm2\n"
28802- " movq 56(%0), %%mm3\n"
28803- " movq %%mm0, 32(%1)\n"
28804- " movq %%mm1, 40(%1)\n"
28805- " movq %%mm2, 48(%1)\n"
28806- " movq %%mm3, 56(%1)\n"
28807+ "1: prefetch 320(%1)\n"
28808+ "2: movq (%1), %%mm0\n"
28809+ " movq 8(%1), %%mm1\n"
28810+ " movq 16(%1), %%mm2\n"
28811+ " movq 24(%1), %%mm3\n"
28812+ " movq %%mm0, (%2)\n"
28813+ " movq %%mm1, 8(%2)\n"
28814+ " movq %%mm2, 16(%2)\n"
28815+ " movq %%mm3, 24(%2)\n"
28816+ " movq 32(%1), %%mm0\n"
28817+ " movq 40(%1), %%mm1\n"
28818+ " movq 48(%1), %%mm2\n"
28819+ " movq 56(%1), %%mm3\n"
28820+ " movq %%mm0, 32(%2)\n"
28821+ " movq %%mm1, 40(%2)\n"
28822+ " movq %%mm2, 48(%2)\n"
28823+ " movq %%mm3, 56(%2)\n"
28824 ".section .fixup, \"ax\"\n"
28825- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28826+ "3:\n"
28827+
28828+#ifdef CONFIG_PAX_KERNEXEC
28829+ " movl %%cr0, %0\n"
28830+ " movl %0, %%eax\n"
28831+ " andl $0xFFFEFFFF, %%eax\n"
28832+ " movl %%eax, %%cr0\n"
28833+#endif
28834+
28835+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28836+
28837+#ifdef CONFIG_PAX_KERNEXEC
28838+ " movl %0, %%cr0\n"
28839+#endif
28840+
28841 " jmp 2b\n"
28842 ".previous\n"
28843 _ASM_EXTABLE(1b, 3b)
28844- : : "r" (from), "r" (to) : "memory");
28845+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28846
28847 from += 64;
28848 to += 64;
28849diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28850index f6d13ee..aca5f0b 100644
28851--- a/arch/x86/lib/msr-reg.S
28852+++ b/arch/x86/lib/msr-reg.S
28853@@ -3,6 +3,7 @@
28854 #include <asm/dwarf2.h>
28855 #include <asm/asm.h>
28856 #include <asm/msr.h>
28857+#include <asm/alternative-asm.h>
28858
28859 #ifdef CONFIG_X86_64
28860 /*
28861@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28862 CFI_STARTPROC
28863 pushq_cfi %rbx
28864 pushq_cfi %rbp
28865- movq %rdi, %r10 /* Save pointer */
28866+ movq %rdi, %r9 /* Save pointer */
28867 xorl %r11d, %r11d /* Return value */
28868 movl (%rdi), %eax
28869 movl 4(%rdi), %ecx
28870@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28871 movl 28(%rdi), %edi
28872 CFI_REMEMBER_STATE
28873 1: \op
28874-2: movl %eax, (%r10)
28875+2: movl %eax, (%r9)
28876 movl %r11d, %eax /* Return value */
28877- movl %ecx, 4(%r10)
28878- movl %edx, 8(%r10)
28879- movl %ebx, 12(%r10)
28880- movl %ebp, 20(%r10)
28881- movl %esi, 24(%r10)
28882- movl %edi, 28(%r10)
28883+ movl %ecx, 4(%r9)
28884+ movl %edx, 8(%r9)
28885+ movl %ebx, 12(%r9)
28886+ movl %ebp, 20(%r9)
28887+ movl %esi, 24(%r9)
28888+ movl %edi, 28(%r9)
28889 popq_cfi %rbp
28890 popq_cfi %rbx
28891+ pax_force_retaddr
28892 ret
28893 3:
28894 CFI_RESTORE_STATE
28895diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28896index fc6ba17..d4d989d 100644
28897--- a/arch/x86/lib/putuser.S
28898+++ b/arch/x86/lib/putuser.S
28899@@ -16,7 +16,9 @@
28900 #include <asm/errno.h>
28901 #include <asm/asm.h>
28902 #include <asm/smap.h>
28903-
28904+#include <asm/segment.h>
28905+#include <asm/pgtable.h>
28906+#include <asm/alternative-asm.h>
28907
28908 /*
28909 * __put_user_X
28910@@ -30,57 +32,125 @@
28911 * as they get called from within inline assembly.
28912 */
28913
28914-#define ENTER CFI_STARTPROC ; \
28915- GET_THREAD_INFO(%_ASM_BX)
28916-#define EXIT ASM_CLAC ; \
28917- ret ; \
28918+#define ENTER CFI_STARTPROC
28919+#define EXIT ASM_CLAC ; \
28920+ pax_force_retaddr ; \
28921+ ret ; \
28922 CFI_ENDPROC
28923
28924+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28925+#define _DEST %_ASM_CX,%_ASM_BX
28926+#else
28927+#define _DEST %_ASM_CX
28928+#endif
28929+
28930+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28931+#define __copyuser_seg gs;
28932+#else
28933+#define __copyuser_seg
28934+#endif
28935+
28936 .text
28937 ENTRY(__put_user_1)
28938 ENTER
28939+
28940+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28941+ GET_THREAD_INFO(%_ASM_BX)
28942 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28943 jae bad_put_user
28944 ASM_STAC
28945-1: movb %al,(%_ASM_CX)
28946+
28947+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28948+ mov pax_user_shadow_base,%_ASM_BX
28949+ cmp %_ASM_BX,%_ASM_CX
28950+ jb 1234f
28951+ xor %ebx,%ebx
28952+1234:
28953+#endif
28954+
28955+#endif
28956+
28957+1: __copyuser_seg movb %al,(_DEST)
28958 xor %eax,%eax
28959 EXIT
28960 ENDPROC(__put_user_1)
28961
28962 ENTRY(__put_user_2)
28963 ENTER
28964+
28965+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28966+ GET_THREAD_INFO(%_ASM_BX)
28967 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28968 sub $1,%_ASM_BX
28969 cmp %_ASM_BX,%_ASM_CX
28970 jae bad_put_user
28971 ASM_STAC
28972-2: movw %ax,(%_ASM_CX)
28973+
28974+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28975+ mov pax_user_shadow_base,%_ASM_BX
28976+ cmp %_ASM_BX,%_ASM_CX
28977+ jb 1234f
28978+ xor %ebx,%ebx
28979+1234:
28980+#endif
28981+
28982+#endif
28983+
28984+2: __copyuser_seg movw %ax,(_DEST)
28985 xor %eax,%eax
28986 EXIT
28987 ENDPROC(__put_user_2)
28988
28989 ENTRY(__put_user_4)
28990 ENTER
28991+
28992+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28993+ GET_THREAD_INFO(%_ASM_BX)
28994 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28995 sub $3,%_ASM_BX
28996 cmp %_ASM_BX,%_ASM_CX
28997 jae bad_put_user
28998 ASM_STAC
28999-3: movl %eax,(%_ASM_CX)
29000+
29001+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29002+ mov pax_user_shadow_base,%_ASM_BX
29003+ cmp %_ASM_BX,%_ASM_CX
29004+ jb 1234f
29005+ xor %ebx,%ebx
29006+1234:
29007+#endif
29008+
29009+#endif
29010+
29011+3: __copyuser_seg movl %eax,(_DEST)
29012 xor %eax,%eax
29013 EXIT
29014 ENDPROC(__put_user_4)
29015
29016 ENTRY(__put_user_8)
29017 ENTER
29018+
29019+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29020+ GET_THREAD_INFO(%_ASM_BX)
29021 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29022 sub $7,%_ASM_BX
29023 cmp %_ASM_BX,%_ASM_CX
29024 jae bad_put_user
29025 ASM_STAC
29026-4: mov %_ASM_AX,(%_ASM_CX)
29027+
29028+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29029+ mov pax_user_shadow_base,%_ASM_BX
29030+ cmp %_ASM_BX,%_ASM_CX
29031+ jb 1234f
29032+ xor %ebx,%ebx
29033+1234:
29034+#endif
29035+
29036+#endif
29037+
29038+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29039 #ifdef CONFIG_X86_32
29040-5: movl %edx,4(%_ASM_CX)
29041+5: __copyuser_seg movl %edx,4(_DEST)
29042 #endif
29043 xor %eax,%eax
29044 EXIT
29045diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29046index 1cad221..de671ee 100644
29047--- a/arch/x86/lib/rwlock.S
29048+++ b/arch/x86/lib/rwlock.S
29049@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29050 FRAME
29051 0: LOCK_PREFIX
29052 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29053+
29054+#ifdef CONFIG_PAX_REFCOUNT
29055+ jno 1234f
29056+ LOCK_PREFIX
29057+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29058+ int $4
29059+1234:
29060+ _ASM_EXTABLE(1234b, 1234b)
29061+#endif
29062+
29063 1: rep; nop
29064 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29065 jne 1b
29066 LOCK_PREFIX
29067 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29068+
29069+#ifdef CONFIG_PAX_REFCOUNT
29070+ jno 1234f
29071+ LOCK_PREFIX
29072+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29073+ int $4
29074+1234:
29075+ _ASM_EXTABLE(1234b, 1234b)
29076+#endif
29077+
29078 jnz 0b
29079 ENDFRAME
29080+ pax_force_retaddr
29081 ret
29082 CFI_ENDPROC
29083 END(__write_lock_failed)
29084@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29085 FRAME
29086 0: LOCK_PREFIX
29087 READ_LOCK_SIZE(inc) (%__lock_ptr)
29088+
29089+#ifdef CONFIG_PAX_REFCOUNT
29090+ jno 1234f
29091+ LOCK_PREFIX
29092+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29093+ int $4
29094+1234:
29095+ _ASM_EXTABLE(1234b, 1234b)
29096+#endif
29097+
29098 1: rep; nop
29099 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29100 js 1b
29101 LOCK_PREFIX
29102 READ_LOCK_SIZE(dec) (%__lock_ptr)
29103+
29104+#ifdef CONFIG_PAX_REFCOUNT
29105+ jno 1234f
29106+ LOCK_PREFIX
29107+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29108+ int $4
29109+1234:
29110+ _ASM_EXTABLE(1234b, 1234b)
29111+#endif
29112+
29113 js 0b
29114 ENDFRAME
29115+ pax_force_retaddr
29116 ret
29117 CFI_ENDPROC
29118 END(__read_lock_failed)
29119diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29120index 5dff5f0..cadebf4 100644
29121--- a/arch/x86/lib/rwsem.S
29122+++ b/arch/x86/lib/rwsem.S
29123@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29124 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29125 CFI_RESTORE __ASM_REG(dx)
29126 restore_common_regs
29127+ pax_force_retaddr
29128 ret
29129 CFI_ENDPROC
29130 ENDPROC(call_rwsem_down_read_failed)
29131@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29132 movq %rax,%rdi
29133 call rwsem_down_write_failed
29134 restore_common_regs
29135+ pax_force_retaddr
29136 ret
29137 CFI_ENDPROC
29138 ENDPROC(call_rwsem_down_write_failed)
29139@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29140 movq %rax,%rdi
29141 call rwsem_wake
29142 restore_common_regs
29143-1: ret
29144+1: pax_force_retaddr
29145+ ret
29146 CFI_ENDPROC
29147 ENDPROC(call_rwsem_wake)
29148
29149@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29150 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29151 CFI_RESTORE __ASM_REG(dx)
29152 restore_common_regs
29153+ pax_force_retaddr
29154 ret
29155 CFI_ENDPROC
29156 ENDPROC(call_rwsem_downgrade_wake)
29157diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29158index a63efd6..ccecad8 100644
29159--- a/arch/x86/lib/thunk_64.S
29160+++ b/arch/x86/lib/thunk_64.S
29161@@ -8,6 +8,7 @@
29162 #include <linux/linkage.h>
29163 #include <asm/dwarf2.h>
29164 #include <asm/calling.h>
29165+#include <asm/alternative-asm.h>
29166
29167 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29168 .macro THUNK name, func, put_ret_addr_in_rdi=0
29169@@ -41,5 +42,6 @@
29170 SAVE_ARGS
29171 restore:
29172 RESTORE_ARGS
29173+ pax_force_retaddr
29174 ret
29175 CFI_ENDPROC
29176diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29177index 3eb18ac..6890bc3 100644
29178--- a/arch/x86/lib/usercopy_32.c
29179+++ b/arch/x86/lib/usercopy_32.c
29180@@ -42,11 +42,13 @@ do { \
29181 int __d0; \
29182 might_fault(); \
29183 __asm__ __volatile__( \
29184+ __COPYUSER_SET_ES \
29185 ASM_STAC "\n" \
29186 "0: rep; stosl\n" \
29187 " movl %2,%0\n" \
29188 "1: rep; stosb\n" \
29189 "2: " ASM_CLAC "\n" \
29190+ __COPYUSER_RESTORE_ES \
29191 ".section .fixup,\"ax\"\n" \
29192 "3: lea 0(%2,%0,4),%0\n" \
29193 " jmp 2b\n" \
29194@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29195
29196 #ifdef CONFIG_X86_INTEL_USERCOPY
29197 static unsigned long
29198-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29199+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29200 {
29201 int d0, d1;
29202 __asm__ __volatile__(
29203@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29204 " .align 2,0x90\n"
29205 "3: movl 0(%4), %%eax\n"
29206 "4: movl 4(%4), %%edx\n"
29207- "5: movl %%eax, 0(%3)\n"
29208- "6: movl %%edx, 4(%3)\n"
29209+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29210+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29211 "7: movl 8(%4), %%eax\n"
29212 "8: movl 12(%4),%%edx\n"
29213- "9: movl %%eax, 8(%3)\n"
29214- "10: movl %%edx, 12(%3)\n"
29215+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29216+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29217 "11: movl 16(%4), %%eax\n"
29218 "12: movl 20(%4), %%edx\n"
29219- "13: movl %%eax, 16(%3)\n"
29220- "14: movl %%edx, 20(%3)\n"
29221+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29222+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29223 "15: movl 24(%4), %%eax\n"
29224 "16: movl 28(%4), %%edx\n"
29225- "17: movl %%eax, 24(%3)\n"
29226- "18: movl %%edx, 28(%3)\n"
29227+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29228+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29229 "19: movl 32(%4), %%eax\n"
29230 "20: movl 36(%4), %%edx\n"
29231- "21: movl %%eax, 32(%3)\n"
29232- "22: movl %%edx, 36(%3)\n"
29233+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29234+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29235 "23: movl 40(%4), %%eax\n"
29236 "24: movl 44(%4), %%edx\n"
29237- "25: movl %%eax, 40(%3)\n"
29238- "26: movl %%edx, 44(%3)\n"
29239+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29240+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29241 "27: movl 48(%4), %%eax\n"
29242 "28: movl 52(%4), %%edx\n"
29243- "29: movl %%eax, 48(%3)\n"
29244- "30: movl %%edx, 52(%3)\n"
29245+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29246+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29247 "31: movl 56(%4), %%eax\n"
29248 "32: movl 60(%4), %%edx\n"
29249- "33: movl %%eax, 56(%3)\n"
29250- "34: movl %%edx, 60(%3)\n"
29251+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29252+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29253 " addl $-64, %0\n"
29254 " addl $64, %4\n"
29255 " addl $64, %3\n"
29256@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29257 " shrl $2, %0\n"
29258 " andl $3, %%eax\n"
29259 " cld\n"
29260+ __COPYUSER_SET_ES
29261 "99: rep; movsl\n"
29262 "36: movl %%eax, %0\n"
29263 "37: rep; movsb\n"
29264 "100:\n"
29265+ __COPYUSER_RESTORE_ES
29266 ".section .fixup,\"ax\"\n"
29267 "101: lea 0(%%eax,%0,4),%0\n"
29268 " jmp 100b\n"
29269@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29270 }
29271
29272 static unsigned long
29273+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29274+{
29275+ int d0, d1;
29276+ __asm__ __volatile__(
29277+ " .align 2,0x90\n"
29278+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29279+ " cmpl $67, %0\n"
29280+ " jbe 3f\n"
29281+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29282+ " .align 2,0x90\n"
29283+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29284+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29285+ "5: movl %%eax, 0(%3)\n"
29286+ "6: movl %%edx, 4(%3)\n"
29287+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29288+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29289+ "9: movl %%eax, 8(%3)\n"
29290+ "10: movl %%edx, 12(%3)\n"
29291+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29292+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29293+ "13: movl %%eax, 16(%3)\n"
29294+ "14: movl %%edx, 20(%3)\n"
29295+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29296+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29297+ "17: movl %%eax, 24(%3)\n"
29298+ "18: movl %%edx, 28(%3)\n"
29299+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29300+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29301+ "21: movl %%eax, 32(%3)\n"
29302+ "22: movl %%edx, 36(%3)\n"
29303+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29304+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29305+ "25: movl %%eax, 40(%3)\n"
29306+ "26: movl %%edx, 44(%3)\n"
29307+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29308+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29309+ "29: movl %%eax, 48(%3)\n"
29310+ "30: movl %%edx, 52(%3)\n"
29311+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29312+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29313+ "33: movl %%eax, 56(%3)\n"
29314+ "34: movl %%edx, 60(%3)\n"
29315+ " addl $-64, %0\n"
29316+ " addl $64, %4\n"
29317+ " addl $64, %3\n"
29318+ " cmpl $63, %0\n"
29319+ " ja 1b\n"
29320+ "35: movl %0, %%eax\n"
29321+ " shrl $2, %0\n"
29322+ " andl $3, %%eax\n"
29323+ " cld\n"
29324+ "99: rep; "__copyuser_seg" movsl\n"
29325+ "36: movl %%eax, %0\n"
29326+ "37: rep; "__copyuser_seg" movsb\n"
29327+ "100:\n"
29328+ ".section .fixup,\"ax\"\n"
29329+ "101: lea 0(%%eax,%0,4),%0\n"
29330+ " jmp 100b\n"
29331+ ".previous\n"
29332+ _ASM_EXTABLE(1b,100b)
29333+ _ASM_EXTABLE(2b,100b)
29334+ _ASM_EXTABLE(3b,100b)
29335+ _ASM_EXTABLE(4b,100b)
29336+ _ASM_EXTABLE(5b,100b)
29337+ _ASM_EXTABLE(6b,100b)
29338+ _ASM_EXTABLE(7b,100b)
29339+ _ASM_EXTABLE(8b,100b)
29340+ _ASM_EXTABLE(9b,100b)
29341+ _ASM_EXTABLE(10b,100b)
29342+ _ASM_EXTABLE(11b,100b)
29343+ _ASM_EXTABLE(12b,100b)
29344+ _ASM_EXTABLE(13b,100b)
29345+ _ASM_EXTABLE(14b,100b)
29346+ _ASM_EXTABLE(15b,100b)
29347+ _ASM_EXTABLE(16b,100b)
29348+ _ASM_EXTABLE(17b,100b)
29349+ _ASM_EXTABLE(18b,100b)
29350+ _ASM_EXTABLE(19b,100b)
29351+ _ASM_EXTABLE(20b,100b)
29352+ _ASM_EXTABLE(21b,100b)
29353+ _ASM_EXTABLE(22b,100b)
29354+ _ASM_EXTABLE(23b,100b)
29355+ _ASM_EXTABLE(24b,100b)
29356+ _ASM_EXTABLE(25b,100b)
29357+ _ASM_EXTABLE(26b,100b)
29358+ _ASM_EXTABLE(27b,100b)
29359+ _ASM_EXTABLE(28b,100b)
29360+ _ASM_EXTABLE(29b,100b)
29361+ _ASM_EXTABLE(30b,100b)
29362+ _ASM_EXTABLE(31b,100b)
29363+ _ASM_EXTABLE(32b,100b)
29364+ _ASM_EXTABLE(33b,100b)
29365+ _ASM_EXTABLE(34b,100b)
29366+ _ASM_EXTABLE(35b,100b)
29367+ _ASM_EXTABLE(36b,100b)
29368+ _ASM_EXTABLE(37b,100b)
29369+ _ASM_EXTABLE(99b,101b)
29370+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29371+ : "1"(to), "2"(from), "0"(size)
29372+ : "eax", "edx", "memory");
29373+ return size;
29374+}
29375+
29376+static unsigned long __size_overflow(3)
29377 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29378 {
29379 int d0, d1;
29380 __asm__ __volatile__(
29381 " .align 2,0x90\n"
29382- "0: movl 32(%4), %%eax\n"
29383+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29384 " cmpl $67, %0\n"
29385 " jbe 2f\n"
29386- "1: movl 64(%4), %%eax\n"
29387+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29388 " .align 2,0x90\n"
29389- "2: movl 0(%4), %%eax\n"
29390- "21: movl 4(%4), %%edx\n"
29391+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29392+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29393 " movl %%eax, 0(%3)\n"
29394 " movl %%edx, 4(%3)\n"
29395- "3: movl 8(%4), %%eax\n"
29396- "31: movl 12(%4),%%edx\n"
29397+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29398+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29399 " movl %%eax, 8(%3)\n"
29400 " movl %%edx, 12(%3)\n"
29401- "4: movl 16(%4), %%eax\n"
29402- "41: movl 20(%4), %%edx\n"
29403+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29404+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29405 " movl %%eax, 16(%3)\n"
29406 " movl %%edx, 20(%3)\n"
29407- "10: movl 24(%4), %%eax\n"
29408- "51: movl 28(%4), %%edx\n"
29409+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29410+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29411 " movl %%eax, 24(%3)\n"
29412 " movl %%edx, 28(%3)\n"
29413- "11: movl 32(%4), %%eax\n"
29414- "61: movl 36(%4), %%edx\n"
29415+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29416+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29417 " movl %%eax, 32(%3)\n"
29418 " movl %%edx, 36(%3)\n"
29419- "12: movl 40(%4), %%eax\n"
29420- "71: movl 44(%4), %%edx\n"
29421+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29422+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29423 " movl %%eax, 40(%3)\n"
29424 " movl %%edx, 44(%3)\n"
29425- "13: movl 48(%4), %%eax\n"
29426- "81: movl 52(%4), %%edx\n"
29427+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29428+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29429 " movl %%eax, 48(%3)\n"
29430 " movl %%edx, 52(%3)\n"
29431- "14: movl 56(%4), %%eax\n"
29432- "91: movl 60(%4), %%edx\n"
29433+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29434+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29435 " movl %%eax, 56(%3)\n"
29436 " movl %%edx, 60(%3)\n"
29437 " addl $-64, %0\n"
29438@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29439 " shrl $2, %0\n"
29440 " andl $3, %%eax\n"
29441 " cld\n"
29442- "6: rep; movsl\n"
29443+ "6: rep; "__copyuser_seg" movsl\n"
29444 " movl %%eax,%0\n"
29445- "7: rep; movsb\n"
29446+ "7: rep; "__copyuser_seg" movsb\n"
29447 "8:\n"
29448 ".section .fixup,\"ax\"\n"
29449 "9: lea 0(%%eax,%0,4),%0\n"
29450@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29451 * hyoshiok@miraclelinux.com
29452 */
29453
29454-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29455+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29456 const void __user *from, unsigned long size)
29457 {
29458 int d0, d1;
29459
29460 __asm__ __volatile__(
29461 " .align 2,0x90\n"
29462- "0: movl 32(%4), %%eax\n"
29463+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29464 " cmpl $67, %0\n"
29465 " jbe 2f\n"
29466- "1: movl 64(%4), %%eax\n"
29467+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29468 " .align 2,0x90\n"
29469- "2: movl 0(%4), %%eax\n"
29470- "21: movl 4(%4), %%edx\n"
29471+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29472+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29473 " movnti %%eax, 0(%3)\n"
29474 " movnti %%edx, 4(%3)\n"
29475- "3: movl 8(%4), %%eax\n"
29476- "31: movl 12(%4),%%edx\n"
29477+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29478+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29479 " movnti %%eax, 8(%3)\n"
29480 " movnti %%edx, 12(%3)\n"
29481- "4: movl 16(%4), %%eax\n"
29482- "41: movl 20(%4), %%edx\n"
29483+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29484+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29485 " movnti %%eax, 16(%3)\n"
29486 " movnti %%edx, 20(%3)\n"
29487- "10: movl 24(%4), %%eax\n"
29488- "51: movl 28(%4), %%edx\n"
29489+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29490+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29491 " movnti %%eax, 24(%3)\n"
29492 " movnti %%edx, 28(%3)\n"
29493- "11: movl 32(%4), %%eax\n"
29494- "61: movl 36(%4), %%edx\n"
29495+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29496+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29497 " movnti %%eax, 32(%3)\n"
29498 " movnti %%edx, 36(%3)\n"
29499- "12: movl 40(%4), %%eax\n"
29500- "71: movl 44(%4), %%edx\n"
29501+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29502+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29503 " movnti %%eax, 40(%3)\n"
29504 " movnti %%edx, 44(%3)\n"
29505- "13: movl 48(%4), %%eax\n"
29506- "81: movl 52(%4), %%edx\n"
29507+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29508+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29509 " movnti %%eax, 48(%3)\n"
29510 " movnti %%edx, 52(%3)\n"
29511- "14: movl 56(%4), %%eax\n"
29512- "91: movl 60(%4), %%edx\n"
29513+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29514+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29515 " movnti %%eax, 56(%3)\n"
29516 " movnti %%edx, 60(%3)\n"
29517 " addl $-64, %0\n"
29518@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29519 " shrl $2, %0\n"
29520 " andl $3, %%eax\n"
29521 " cld\n"
29522- "6: rep; movsl\n"
29523+ "6: rep; "__copyuser_seg" movsl\n"
29524 " movl %%eax,%0\n"
29525- "7: rep; movsb\n"
29526+ "7: rep; "__copyuser_seg" movsb\n"
29527 "8:\n"
29528 ".section .fixup,\"ax\"\n"
29529 "9: lea 0(%%eax,%0,4),%0\n"
29530@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29531 return size;
29532 }
29533
29534-static unsigned long __copy_user_intel_nocache(void *to,
29535+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29536 const void __user *from, unsigned long size)
29537 {
29538 int d0, d1;
29539
29540 __asm__ __volatile__(
29541 " .align 2,0x90\n"
29542- "0: movl 32(%4), %%eax\n"
29543+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29544 " cmpl $67, %0\n"
29545 " jbe 2f\n"
29546- "1: movl 64(%4), %%eax\n"
29547+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29548 " .align 2,0x90\n"
29549- "2: movl 0(%4), %%eax\n"
29550- "21: movl 4(%4), %%edx\n"
29551+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29552+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29553 " movnti %%eax, 0(%3)\n"
29554 " movnti %%edx, 4(%3)\n"
29555- "3: movl 8(%4), %%eax\n"
29556- "31: movl 12(%4),%%edx\n"
29557+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29558+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29559 " movnti %%eax, 8(%3)\n"
29560 " movnti %%edx, 12(%3)\n"
29561- "4: movl 16(%4), %%eax\n"
29562- "41: movl 20(%4), %%edx\n"
29563+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29564+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29565 " movnti %%eax, 16(%3)\n"
29566 " movnti %%edx, 20(%3)\n"
29567- "10: movl 24(%4), %%eax\n"
29568- "51: movl 28(%4), %%edx\n"
29569+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29570+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29571 " movnti %%eax, 24(%3)\n"
29572 " movnti %%edx, 28(%3)\n"
29573- "11: movl 32(%4), %%eax\n"
29574- "61: movl 36(%4), %%edx\n"
29575+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29576+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29577 " movnti %%eax, 32(%3)\n"
29578 " movnti %%edx, 36(%3)\n"
29579- "12: movl 40(%4), %%eax\n"
29580- "71: movl 44(%4), %%edx\n"
29581+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29582+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29583 " movnti %%eax, 40(%3)\n"
29584 " movnti %%edx, 44(%3)\n"
29585- "13: movl 48(%4), %%eax\n"
29586- "81: movl 52(%4), %%edx\n"
29587+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29588+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29589 " movnti %%eax, 48(%3)\n"
29590 " movnti %%edx, 52(%3)\n"
29591- "14: movl 56(%4), %%eax\n"
29592- "91: movl 60(%4), %%edx\n"
29593+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29594+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29595 " movnti %%eax, 56(%3)\n"
29596 " movnti %%edx, 60(%3)\n"
29597 " addl $-64, %0\n"
29598@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29599 " shrl $2, %0\n"
29600 " andl $3, %%eax\n"
29601 " cld\n"
29602- "6: rep; movsl\n"
29603+ "6: rep; "__copyuser_seg" movsl\n"
29604 " movl %%eax,%0\n"
29605- "7: rep; movsb\n"
29606+ "7: rep; "__copyuser_seg" movsb\n"
29607 "8:\n"
29608 ".section .fixup,\"ax\"\n"
29609 "9: lea 0(%%eax,%0,4),%0\n"
29610@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29611 */
29612 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29613 unsigned long size);
29614-unsigned long __copy_user_intel(void __user *to, const void *from,
29615+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29616+ unsigned long size);
29617+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29618 unsigned long size);
29619 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29620 const void __user *from, unsigned long size);
29621 #endif /* CONFIG_X86_INTEL_USERCOPY */
29622
29623 /* Generic arbitrary sized copy. */
29624-#define __copy_user(to, from, size) \
29625+#define __copy_user(to, from, size, prefix, set, restore) \
29626 do { \
29627 int __d0, __d1, __d2; \
29628 __asm__ __volatile__( \
29629+ set \
29630 " cmp $7,%0\n" \
29631 " jbe 1f\n" \
29632 " movl %1,%0\n" \
29633 " negl %0\n" \
29634 " andl $7,%0\n" \
29635 " subl %0,%3\n" \
29636- "4: rep; movsb\n" \
29637+ "4: rep; "prefix"movsb\n" \
29638 " movl %3,%0\n" \
29639 " shrl $2,%0\n" \
29640 " andl $3,%3\n" \
29641 " .align 2,0x90\n" \
29642- "0: rep; movsl\n" \
29643+ "0: rep; "prefix"movsl\n" \
29644 " movl %3,%0\n" \
29645- "1: rep; movsb\n" \
29646+ "1: rep; "prefix"movsb\n" \
29647 "2:\n" \
29648+ restore \
29649 ".section .fixup,\"ax\"\n" \
29650 "5: addl %3,%0\n" \
29651 " jmp 2b\n" \
29652@@ -538,14 +650,14 @@ do { \
29653 " negl %0\n" \
29654 " andl $7,%0\n" \
29655 " subl %0,%3\n" \
29656- "4: rep; movsb\n" \
29657+ "4: rep; "__copyuser_seg"movsb\n" \
29658 " movl %3,%0\n" \
29659 " shrl $2,%0\n" \
29660 " andl $3,%3\n" \
29661 " .align 2,0x90\n" \
29662- "0: rep; movsl\n" \
29663+ "0: rep; "__copyuser_seg"movsl\n" \
29664 " movl %3,%0\n" \
29665- "1: rep; movsb\n" \
29666+ "1: rep; "__copyuser_seg"movsb\n" \
29667 "2:\n" \
29668 ".section .fixup,\"ax\"\n" \
29669 "5: addl %3,%0\n" \
29670@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29671 {
29672 stac();
29673 if (movsl_is_ok(to, from, n))
29674- __copy_user(to, from, n);
29675+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29676 else
29677- n = __copy_user_intel(to, from, n);
29678+ n = __generic_copy_to_user_intel(to, from, n);
29679 clac();
29680 return n;
29681 }
29682@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29683 {
29684 stac();
29685 if (movsl_is_ok(to, from, n))
29686- __copy_user(to, from, n);
29687+ __copy_user(to, from, n, __copyuser_seg, "", "");
29688 else
29689- n = __copy_user_intel((void __user *)to,
29690- (const void *)from, n);
29691+ n = __generic_copy_from_user_intel(to, from, n);
29692 clac();
29693 return n;
29694 }
29695@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29696 if (n > 64 && cpu_has_xmm2)
29697 n = __copy_user_intel_nocache(to, from, n);
29698 else
29699- __copy_user(to, from, n);
29700+ __copy_user(to, from, n, __copyuser_seg, "", "");
29701 #else
29702- __copy_user(to, from, n);
29703+ __copy_user(to, from, n, __copyuser_seg, "", "");
29704 #endif
29705 clac();
29706 return n;
29707 }
29708 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29709
29710-/**
29711- * copy_to_user: - Copy a block of data into user space.
29712- * @to: Destination address, in user space.
29713- * @from: Source address, in kernel space.
29714- * @n: Number of bytes to copy.
29715- *
29716- * Context: User context only. This function may sleep.
29717- *
29718- * Copy data from kernel space to user space.
29719- *
29720- * Returns number of bytes that could not be copied.
29721- * On success, this will be zero.
29722- */
29723-unsigned long
29724-copy_to_user(void __user *to, const void *from, unsigned long n)
29725+#ifdef CONFIG_PAX_MEMORY_UDEREF
29726+void __set_fs(mm_segment_t x)
29727 {
29728- if (access_ok(VERIFY_WRITE, to, n))
29729- n = __copy_to_user(to, from, n);
29730- return n;
29731+ switch (x.seg) {
29732+ case 0:
29733+ loadsegment(gs, 0);
29734+ break;
29735+ case TASK_SIZE_MAX:
29736+ loadsegment(gs, __USER_DS);
29737+ break;
29738+ case -1UL:
29739+ loadsegment(gs, __KERNEL_DS);
29740+ break;
29741+ default:
29742+ BUG();
29743+ }
29744 }
29745-EXPORT_SYMBOL(copy_to_user);
29746+EXPORT_SYMBOL(__set_fs);
29747
29748-/**
29749- * copy_from_user: - Copy a block of data from user space.
29750- * @to: Destination address, in kernel space.
29751- * @from: Source address, in user space.
29752- * @n: Number of bytes to copy.
29753- *
29754- * Context: User context only. This function may sleep.
29755- *
29756- * Copy data from user space to kernel space.
29757- *
29758- * Returns number of bytes that could not be copied.
29759- * On success, this will be zero.
29760- *
29761- * If some data could not be copied, this function will pad the copied
29762- * data to the requested size using zero bytes.
29763- */
29764-unsigned long
29765-_copy_from_user(void *to, const void __user *from, unsigned long n)
29766+void set_fs(mm_segment_t x)
29767 {
29768- if (access_ok(VERIFY_READ, from, n))
29769- n = __copy_from_user(to, from, n);
29770- else
29771- memset(to, 0, n);
29772- return n;
29773+ current_thread_info()->addr_limit = x;
29774+ __set_fs(x);
29775 }
29776-EXPORT_SYMBOL(_copy_from_user);
29777+EXPORT_SYMBOL(set_fs);
29778+#endif
29779diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29780index 906fea3..0194a18 100644
29781--- a/arch/x86/lib/usercopy_64.c
29782+++ b/arch/x86/lib/usercopy_64.c
29783@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29784 might_fault();
29785 /* no memory constraint because it doesn't change any memory gcc knows
29786 about */
29787+ pax_open_userland();
29788 stac();
29789 asm volatile(
29790 " testq %[size8],%[size8]\n"
29791@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29792 _ASM_EXTABLE(0b,3b)
29793 _ASM_EXTABLE(1b,2b)
29794 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29795- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29796+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29797 [zero] "r" (0UL), [eight] "r" (8UL));
29798 clac();
29799+ pax_close_userland();
29800 return size;
29801 }
29802 EXPORT_SYMBOL(__clear_user);
29803@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29804 }
29805 EXPORT_SYMBOL(clear_user);
29806
29807-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29808+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29809 {
29810- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29811- return copy_user_generic((__force void *)to, (__force void *)from, len);
29812- }
29813- return len;
29814+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29815+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29816+ return len;
29817 }
29818 EXPORT_SYMBOL(copy_in_user);
29819
29820@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29821 * it is not necessary to optimize tail handling.
29822 */
29823 unsigned long
29824-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29825+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29826 {
29827 char c;
29828 unsigned zero_len;
29829
29830+ clac();
29831+ pax_close_userland();
29832 for (; len; --len, to++) {
29833 if (__get_user_nocheck(c, from++, sizeof(char)))
29834 break;
29835@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29836 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29837 if (__put_user_nocheck(c, to++, sizeof(char)))
29838 break;
29839- clac();
29840 return len;
29841 }
29842diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29843index 23d8e5f..9ccc13a 100644
29844--- a/arch/x86/mm/Makefile
29845+++ b/arch/x86/mm/Makefile
29846@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29847 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29848
29849 obj-$(CONFIG_MEMTEST) += memtest.o
29850+
29851+quote:="
29852+obj-$(CONFIG_X86_64) += uderef_64.o
29853+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29854diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29855index 903ec1e..c4166b2 100644
29856--- a/arch/x86/mm/extable.c
29857+++ b/arch/x86/mm/extable.c
29858@@ -6,12 +6,24 @@
29859 static inline unsigned long
29860 ex_insn_addr(const struct exception_table_entry *x)
29861 {
29862- return (unsigned long)&x->insn + x->insn;
29863+ unsigned long reloc = 0;
29864+
29865+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29866+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29867+#endif
29868+
29869+ return (unsigned long)&x->insn + x->insn + reloc;
29870 }
29871 static inline unsigned long
29872 ex_fixup_addr(const struct exception_table_entry *x)
29873 {
29874- return (unsigned long)&x->fixup + x->fixup;
29875+ unsigned long reloc = 0;
29876+
29877+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29878+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29879+#endif
29880+
29881+ return (unsigned long)&x->fixup + x->fixup + reloc;
29882 }
29883
29884 int fixup_exception(struct pt_regs *regs)
29885@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29886 unsigned long new_ip;
29887
29888 #ifdef CONFIG_PNPBIOS
29889- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29890+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29891 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29892 extern u32 pnp_bios_is_utter_crap;
29893 pnp_bios_is_utter_crap = 1;
29894@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29895 i += 4;
29896 p->fixup -= i;
29897 i += 4;
29898+
29899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29900+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29901+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29902+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29903+#endif
29904+
29905 }
29906 }
29907
29908diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29909index 654be4a..a4a3da1 100644
29910--- a/arch/x86/mm/fault.c
29911+++ b/arch/x86/mm/fault.c
29912@@ -14,11 +14,18 @@
29913 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29914 #include <linux/prefetch.h> /* prefetchw */
29915 #include <linux/context_tracking.h> /* exception_enter(), ... */
29916+#include <linux/unistd.h>
29917+#include <linux/compiler.h>
29918
29919 #include <asm/traps.h> /* dotraplinkage, ... */
29920 #include <asm/pgalloc.h> /* pgd_*(), ... */
29921 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29922 #include <asm/fixmap.h> /* VSYSCALL_START */
29923+#include <asm/tlbflush.h>
29924+
29925+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29926+#include <asm/stacktrace.h>
29927+#endif
29928
29929 /*
29930 * Page fault error code bits:
29931@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29932 int ret = 0;
29933
29934 /* kprobe_running() needs smp_processor_id() */
29935- if (kprobes_built_in() && !user_mode_vm(regs)) {
29936+ if (kprobes_built_in() && !user_mode(regs)) {
29937 preempt_disable();
29938 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29939 ret = 1;
29940@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29941 return !instr_lo || (instr_lo>>1) == 1;
29942 case 0x00:
29943 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29944- if (probe_kernel_address(instr, opcode))
29945+ if (user_mode(regs)) {
29946+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29947+ return 0;
29948+ } else if (probe_kernel_address(instr, opcode))
29949 return 0;
29950
29951 *prefetch = (instr_lo == 0xF) &&
29952@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29953 while (instr < max_instr) {
29954 unsigned char opcode;
29955
29956- if (probe_kernel_address(instr, opcode))
29957+ if (user_mode(regs)) {
29958+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29959+ break;
29960+ } else if (probe_kernel_address(instr, opcode))
29961 break;
29962
29963 instr++;
29964@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29965 force_sig_info(si_signo, &info, tsk);
29966 }
29967
29968+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29969+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29970+#endif
29971+
29972+#ifdef CONFIG_PAX_EMUTRAMP
29973+static int pax_handle_fetch_fault(struct pt_regs *regs);
29974+#endif
29975+
29976+#ifdef CONFIG_PAX_PAGEEXEC
29977+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29978+{
29979+ pgd_t *pgd;
29980+ pud_t *pud;
29981+ pmd_t *pmd;
29982+
29983+ pgd = pgd_offset(mm, address);
29984+ if (!pgd_present(*pgd))
29985+ return NULL;
29986+ pud = pud_offset(pgd, address);
29987+ if (!pud_present(*pud))
29988+ return NULL;
29989+ pmd = pmd_offset(pud, address);
29990+ if (!pmd_present(*pmd))
29991+ return NULL;
29992+ return pmd;
29993+}
29994+#endif
29995+
29996 DEFINE_SPINLOCK(pgd_lock);
29997 LIST_HEAD(pgd_list);
29998
29999@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30000 for (address = VMALLOC_START & PMD_MASK;
30001 address >= TASK_SIZE && address < FIXADDR_TOP;
30002 address += PMD_SIZE) {
30003+
30004+#ifdef CONFIG_PAX_PER_CPU_PGD
30005+ unsigned long cpu;
30006+#else
30007 struct page *page;
30008+#endif
30009
30010 spin_lock(&pgd_lock);
30011+
30012+#ifdef CONFIG_PAX_PER_CPU_PGD
30013+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30014+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30015+ pmd_t *ret;
30016+
30017+ ret = vmalloc_sync_one(pgd, address);
30018+ if (!ret)
30019+ break;
30020+ pgd = get_cpu_pgd(cpu, kernel);
30021+#else
30022 list_for_each_entry(page, &pgd_list, lru) {
30023+ pgd_t *pgd;
30024 spinlock_t *pgt_lock;
30025 pmd_t *ret;
30026
30027@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30028 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30029
30030 spin_lock(pgt_lock);
30031- ret = vmalloc_sync_one(page_address(page), address);
30032+ pgd = page_address(page);
30033+#endif
30034+
30035+ ret = vmalloc_sync_one(pgd, address);
30036+
30037+#ifndef CONFIG_PAX_PER_CPU_PGD
30038 spin_unlock(pgt_lock);
30039+#endif
30040
30041 if (!ret)
30042 break;
30043@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30044 * an interrupt in the middle of a task switch..
30045 */
30046 pgd_paddr = read_cr3();
30047+
30048+#ifdef CONFIG_PAX_PER_CPU_PGD
30049+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30050+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30051+#endif
30052+
30053 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30054 if (!pmd_k)
30055 return -1;
30056@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30057 * happen within a race in page table update. In the later
30058 * case just flush:
30059 */
30060- pgd = pgd_offset(current->active_mm, address);
30061+
30062 pgd_ref = pgd_offset_k(address);
30063 if (pgd_none(*pgd_ref))
30064 return -1;
30065
30066+#ifdef CONFIG_PAX_PER_CPU_PGD
30067+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30068+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30069+ if (pgd_none(*pgd)) {
30070+ set_pgd(pgd, *pgd_ref);
30071+ arch_flush_lazy_mmu_mode();
30072+ } else {
30073+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30074+ }
30075+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30076+#else
30077+ pgd = pgd_offset(current->active_mm, address);
30078+#endif
30079+
30080 if (pgd_none(*pgd)) {
30081 set_pgd(pgd, *pgd_ref);
30082 arch_flush_lazy_mmu_mode();
30083@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30084 static int is_errata100(struct pt_regs *regs, unsigned long address)
30085 {
30086 #ifdef CONFIG_X86_64
30087- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30088+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30089 return 1;
30090 #endif
30091 return 0;
30092@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30093 }
30094
30095 static const char nx_warning[] = KERN_CRIT
30096-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30097+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30098
30099 static void
30100 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30101@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30102 if (!oops_may_print())
30103 return;
30104
30105- if (error_code & PF_INSTR) {
30106+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30107 unsigned int level;
30108
30109 pte_t *pte = lookup_address(address, &level);
30110
30111 if (pte && pte_present(*pte) && !pte_exec(*pte))
30112- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30113+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30114 }
30115
30116+#ifdef CONFIG_PAX_KERNEXEC
30117+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30118+ if (current->signal->curr_ip)
30119+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30120+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30121+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30122+ else
30123+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30124+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30125+ }
30126+#endif
30127+
30128 printk(KERN_ALERT "BUG: unable to handle kernel ");
30129 if (address < PAGE_SIZE)
30130 printk(KERN_CONT "NULL pointer dereference");
30131@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30132 return;
30133 }
30134 #endif
30135+
30136+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30137+ if (pax_is_fetch_fault(regs, error_code, address)) {
30138+
30139+#ifdef CONFIG_PAX_EMUTRAMP
30140+ switch (pax_handle_fetch_fault(regs)) {
30141+ case 2:
30142+ return;
30143+ }
30144+#endif
30145+
30146+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30147+ do_group_exit(SIGKILL);
30148+ }
30149+#endif
30150+
30151 /* Kernel addresses are always protection faults: */
30152 if (address >= TASK_SIZE)
30153 error_code |= PF_PROT;
30154@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30155 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30156 printk(KERN_ERR
30157 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30158- tsk->comm, tsk->pid, address);
30159+ tsk->comm, task_pid_nr(tsk), address);
30160 code = BUS_MCEERR_AR;
30161 }
30162 #endif
30163@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30164 return 1;
30165 }
30166
30167+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30168+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30169+{
30170+ pte_t *pte;
30171+ pmd_t *pmd;
30172+ spinlock_t *ptl;
30173+ unsigned char pte_mask;
30174+
30175+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30176+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30177+ return 0;
30178+
30179+ /* PaX: it's our fault, let's handle it if we can */
30180+
30181+ /* PaX: take a look at read faults before acquiring any locks */
30182+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30183+ /* instruction fetch attempt from a protected page in user mode */
30184+ up_read(&mm->mmap_sem);
30185+
30186+#ifdef CONFIG_PAX_EMUTRAMP
30187+ switch (pax_handle_fetch_fault(regs)) {
30188+ case 2:
30189+ return 1;
30190+ }
30191+#endif
30192+
30193+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30194+ do_group_exit(SIGKILL);
30195+ }
30196+
30197+ pmd = pax_get_pmd(mm, address);
30198+ if (unlikely(!pmd))
30199+ return 0;
30200+
30201+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30202+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30203+ pte_unmap_unlock(pte, ptl);
30204+ return 0;
30205+ }
30206+
30207+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30208+ /* write attempt to a protected page in user mode */
30209+ pte_unmap_unlock(pte, ptl);
30210+ return 0;
30211+ }
30212+
30213+#ifdef CONFIG_SMP
30214+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30215+#else
30216+ if (likely(address > get_limit(regs->cs)))
30217+#endif
30218+ {
30219+ set_pte(pte, pte_mkread(*pte));
30220+ __flush_tlb_one(address);
30221+ pte_unmap_unlock(pte, ptl);
30222+ up_read(&mm->mmap_sem);
30223+ return 1;
30224+ }
30225+
30226+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30227+
30228+ /*
30229+ * PaX: fill DTLB with user rights and retry
30230+ */
30231+ __asm__ __volatile__ (
30232+ "orb %2,(%1)\n"
30233+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30234+/*
30235+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30236+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30237+ * page fault when examined during a TLB load attempt. this is true not only
30238+ * for PTEs holding a non-present entry but also present entries that will
30239+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30240+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30241+ * for our target pages since their PTEs are simply not in the TLBs at all.
30242+
30243+ * the best thing in omitting it is that we gain around 15-20% speed in the
30244+ * fast path of the page fault handler and can get rid of tracing since we
30245+ * can no longer flush unintended entries.
30246+ */
30247+ "invlpg (%0)\n"
30248+#endif
30249+ __copyuser_seg"testb $0,(%0)\n"
30250+ "xorb %3,(%1)\n"
30251+ :
30252+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30253+ : "memory", "cc");
30254+ pte_unmap_unlock(pte, ptl);
30255+ up_read(&mm->mmap_sem);
30256+ return 1;
30257+}
30258+#endif
30259+
30260 /*
30261 * Handle a spurious fault caused by a stale TLB entry.
30262 *
30263@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30264 static inline int
30265 access_error(unsigned long error_code, struct vm_area_struct *vma)
30266 {
30267+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30268+ return 1;
30269+
30270 if (error_code & PF_WRITE) {
30271 /* write, present and write, not present: */
30272 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30273@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30274 if (error_code & PF_USER)
30275 return false;
30276
30277- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30278+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30279 return false;
30280
30281 return true;
30282@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30283 {
30284 struct vm_area_struct *vma;
30285 struct task_struct *tsk;
30286- unsigned long address;
30287 struct mm_struct *mm;
30288 int fault;
30289 int write = error_code & PF_WRITE;
30290 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30291 (write ? FAULT_FLAG_WRITE : 0);
30292
30293- tsk = current;
30294- mm = tsk->mm;
30295-
30296 /* Get the faulting address: */
30297- address = read_cr2();
30298+ unsigned long address = read_cr2();
30299+
30300+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30301+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30302+ if (!search_exception_tables(regs->ip)) {
30303+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30304+ bad_area_nosemaphore(regs, error_code, address);
30305+ return;
30306+ }
30307+ if (address < pax_user_shadow_base) {
30308+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30309+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30310+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30311+ } else
30312+ address -= pax_user_shadow_base;
30313+ }
30314+#endif
30315+
30316+ tsk = current;
30317+ mm = tsk->mm;
30318
30319 /*
30320 * Detect and handle instructions that would cause a page fault for
30321@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30322 * User-mode registers count as a user access even for any
30323 * potential system fault or CPU buglet:
30324 */
30325- if (user_mode_vm(regs)) {
30326+ if (user_mode(regs)) {
30327 local_irq_enable();
30328 error_code |= PF_USER;
30329 } else {
30330@@ -1142,6 +1365,11 @@ retry:
30331 might_sleep();
30332 }
30333
30334+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30335+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30336+ return;
30337+#endif
30338+
30339 vma = find_vma(mm, address);
30340 if (unlikely(!vma)) {
30341 bad_area(regs, error_code, address);
30342@@ -1153,18 +1381,24 @@ retry:
30343 bad_area(regs, error_code, address);
30344 return;
30345 }
30346- if (error_code & PF_USER) {
30347- /*
30348- * Accessing the stack below %sp is always a bug.
30349- * The large cushion allows instructions like enter
30350- * and pusha to work. ("enter $65535, $31" pushes
30351- * 32 pointers and then decrements %sp by 65535.)
30352- */
30353- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30354- bad_area(regs, error_code, address);
30355- return;
30356- }
30357+ /*
30358+ * Accessing the stack below %sp is always a bug.
30359+ * The large cushion allows instructions like enter
30360+ * and pusha to work. ("enter $65535, $31" pushes
30361+ * 32 pointers and then decrements %sp by 65535.)
30362+ */
30363+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30364+ bad_area(regs, error_code, address);
30365+ return;
30366 }
30367+
30368+#ifdef CONFIG_PAX_SEGMEXEC
30369+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30370+ bad_area(regs, error_code, address);
30371+ return;
30372+ }
30373+#endif
30374+
30375 if (unlikely(expand_stack(vma, address))) {
30376 bad_area(regs, error_code, address);
30377 return;
30378@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30379 __do_page_fault(regs, error_code);
30380 exception_exit(prev_state);
30381 }
30382+
30383+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30384+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30385+{
30386+ struct mm_struct *mm = current->mm;
30387+ unsigned long ip = regs->ip;
30388+
30389+ if (v8086_mode(regs))
30390+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30391+
30392+#ifdef CONFIG_PAX_PAGEEXEC
30393+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30394+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30395+ return true;
30396+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30397+ return true;
30398+ return false;
30399+ }
30400+#endif
30401+
30402+#ifdef CONFIG_PAX_SEGMEXEC
30403+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30404+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30405+ return true;
30406+ return false;
30407+ }
30408+#endif
30409+
30410+ return false;
30411+}
30412+#endif
30413+
30414+#ifdef CONFIG_PAX_EMUTRAMP
30415+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30416+{
30417+ int err;
30418+
30419+ do { /* PaX: libffi trampoline emulation */
30420+ unsigned char mov, jmp;
30421+ unsigned int addr1, addr2;
30422+
30423+#ifdef CONFIG_X86_64
30424+ if ((regs->ip + 9) >> 32)
30425+ break;
30426+#endif
30427+
30428+ err = get_user(mov, (unsigned char __user *)regs->ip);
30429+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30430+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30431+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30432+
30433+ if (err)
30434+ break;
30435+
30436+ if (mov == 0xB8 && jmp == 0xE9) {
30437+ regs->ax = addr1;
30438+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30439+ return 2;
30440+ }
30441+ } while (0);
30442+
30443+ do { /* PaX: gcc trampoline emulation #1 */
30444+ unsigned char mov1, mov2;
30445+ unsigned short jmp;
30446+ unsigned int addr1, addr2;
30447+
30448+#ifdef CONFIG_X86_64
30449+ if ((regs->ip + 11) >> 32)
30450+ break;
30451+#endif
30452+
30453+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30454+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30455+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30456+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30457+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30458+
30459+ if (err)
30460+ break;
30461+
30462+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30463+ regs->cx = addr1;
30464+ regs->ax = addr2;
30465+ regs->ip = addr2;
30466+ return 2;
30467+ }
30468+ } while (0);
30469+
30470+ do { /* PaX: gcc trampoline emulation #2 */
30471+ unsigned char mov, jmp;
30472+ unsigned int addr1, addr2;
30473+
30474+#ifdef CONFIG_X86_64
30475+ if ((regs->ip + 9) >> 32)
30476+ break;
30477+#endif
30478+
30479+ err = get_user(mov, (unsigned char __user *)regs->ip);
30480+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30481+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30482+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30483+
30484+ if (err)
30485+ break;
30486+
30487+ if (mov == 0xB9 && jmp == 0xE9) {
30488+ regs->cx = addr1;
30489+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30490+ return 2;
30491+ }
30492+ } while (0);
30493+
30494+ return 1; /* PaX in action */
30495+}
30496+
30497+#ifdef CONFIG_X86_64
30498+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30499+{
30500+ int err;
30501+
30502+ do { /* PaX: libffi trampoline emulation */
30503+ unsigned short mov1, mov2, jmp1;
30504+ unsigned char stcclc, jmp2;
30505+ unsigned long addr1, addr2;
30506+
30507+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30508+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30509+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30510+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30511+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30512+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30513+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30514+
30515+ if (err)
30516+ break;
30517+
30518+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30519+ regs->r11 = addr1;
30520+ regs->r10 = addr2;
30521+ if (stcclc == 0xF8)
30522+ regs->flags &= ~X86_EFLAGS_CF;
30523+ else
30524+ regs->flags |= X86_EFLAGS_CF;
30525+ regs->ip = addr1;
30526+ return 2;
30527+ }
30528+ } while (0);
30529+
30530+ do { /* PaX: gcc trampoline emulation #1 */
30531+ unsigned short mov1, mov2, jmp1;
30532+ unsigned char jmp2;
30533+ unsigned int addr1;
30534+ unsigned long addr2;
30535+
30536+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30537+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30538+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30539+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30540+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30541+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30542+
30543+ if (err)
30544+ break;
30545+
30546+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30547+ regs->r11 = addr1;
30548+ regs->r10 = addr2;
30549+ regs->ip = addr1;
30550+ return 2;
30551+ }
30552+ } while (0);
30553+
30554+ do { /* PaX: gcc trampoline emulation #2 */
30555+ unsigned short mov1, mov2, jmp1;
30556+ unsigned char jmp2;
30557+ unsigned long addr1, addr2;
30558+
30559+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30560+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30561+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30562+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30563+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30564+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30565+
30566+ if (err)
30567+ break;
30568+
30569+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30570+ regs->r11 = addr1;
30571+ regs->r10 = addr2;
30572+ regs->ip = addr1;
30573+ return 2;
30574+ }
30575+ } while (0);
30576+
30577+ return 1; /* PaX in action */
30578+}
30579+#endif
30580+
30581+/*
30582+ * PaX: decide what to do with offenders (regs->ip = fault address)
30583+ *
30584+ * returns 1 when task should be killed
30585+ * 2 when gcc trampoline was detected
30586+ */
30587+static int pax_handle_fetch_fault(struct pt_regs *regs)
30588+{
30589+ if (v8086_mode(regs))
30590+ return 1;
30591+
30592+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30593+ return 1;
30594+
30595+#ifdef CONFIG_X86_32
30596+ return pax_handle_fetch_fault_32(regs);
30597+#else
30598+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30599+ return pax_handle_fetch_fault_32(regs);
30600+ else
30601+ return pax_handle_fetch_fault_64(regs);
30602+#endif
30603+}
30604+#endif
30605+
30606+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30607+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30608+{
30609+ long i;
30610+
30611+ printk(KERN_ERR "PAX: bytes at PC: ");
30612+ for (i = 0; i < 20; i++) {
30613+ unsigned char c;
30614+ if (get_user(c, (unsigned char __force_user *)pc+i))
30615+ printk(KERN_CONT "?? ");
30616+ else
30617+ printk(KERN_CONT "%02x ", c);
30618+ }
30619+ printk("\n");
30620+
30621+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30622+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30623+ unsigned long c;
30624+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30625+#ifdef CONFIG_X86_32
30626+ printk(KERN_CONT "???????? ");
30627+#else
30628+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30629+ printk(KERN_CONT "???????? ???????? ");
30630+ else
30631+ printk(KERN_CONT "???????????????? ");
30632+#endif
30633+ } else {
30634+#ifdef CONFIG_X86_64
30635+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30636+ printk(KERN_CONT "%08x ", (unsigned int)c);
30637+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30638+ } else
30639+#endif
30640+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30641+ }
30642+ }
30643+ printk("\n");
30644+}
30645+#endif
30646+
30647+/**
30648+ * probe_kernel_write(): safely attempt to write to a location
30649+ * @dst: address to write to
30650+ * @src: pointer to the data that shall be written
30651+ * @size: size of the data chunk
30652+ *
30653+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30654+ * happens, handle that and return -EFAULT.
30655+ */
30656+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30657+{
30658+ long ret;
30659+ mm_segment_t old_fs = get_fs();
30660+
30661+ set_fs(KERNEL_DS);
30662+ pagefault_disable();
30663+ pax_open_kernel();
30664+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30665+ pax_close_kernel();
30666+ pagefault_enable();
30667+ set_fs(old_fs);
30668+
30669+ return ret ? -EFAULT : 0;
30670+}
30671diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30672index dd74e46..7d26398 100644
30673--- a/arch/x86/mm/gup.c
30674+++ b/arch/x86/mm/gup.c
30675@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30676 addr = start;
30677 len = (unsigned long) nr_pages << PAGE_SHIFT;
30678 end = start + len;
30679- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30680+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30681 (void __user *)start, len)))
30682 return 0;
30683
30684diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30685index 4500142..53a363c 100644
30686--- a/arch/x86/mm/highmem_32.c
30687+++ b/arch/x86/mm/highmem_32.c
30688@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30689 idx = type + KM_TYPE_NR*smp_processor_id();
30690 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30691 BUG_ON(!pte_none(*(kmap_pte-idx)));
30692+
30693+ pax_open_kernel();
30694 set_pte(kmap_pte-idx, mk_pte(page, prot));
30695+ pax_close_kernel();
30696+
30697 arch_flush_lazy_mmu_mode();
30698
30699 return (void *)vaddr;
30700diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30701index 7e73e8c..11d3b86 100644
30702--- a/arch/x86/mm/hugetlbpage.c
30703+++ b/arch/x86/mm/hugetlbpage.c
30704@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30705 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30706 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30707 unsigned long addr, unsigned long len,
30708- unsigned long pgoff, unsigned long flags)
30709+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30710 {
30711 struct hstate *h = hstate_file(file);
30712 struct vm_unmapped_area_info info;
30713-
30714+
30715 info.flags = 0;
30716 info.length = len;
30717 info.low_limit = TASK_UNMAPPED_BASE;
30718+
30719+#ifdef CONFIG_PAX_RANDMMAP
30720+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30721+ info.low_limit += current->mm->delta_mmap;
30722+#endif
30723+
30724 info.high_limit = TASK_SIZE;
30725 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30726 info.align_offset = 0;
30727+ info.threadstack_offset = offset;
30728 return vm_unmapped_area(&info);
30729 }
30730
30731 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30732 unsigned long addr0, unsigned long len,
30733- unsigned long pgoff, unsigned long flags)
30734+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30735 {
30736 struct hstate *h = hstate_file(file);
30737 struct vm_unmapped_area_info info;
30738@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30739 info.high_limit = current->mm->mmap_base;
30740 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30741 info.align_offset = 0;
30742+ info.threadstack_offset = offset;
30743 addr = vm_unmapped_area(&info);
30744
30745 /*
30746@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30747 VM_BUG_ON(addr != -ENOMEM);
30748 info.flags = 0;
30749 info.low_limit = TASK_UNMAPPED_BASE;
30750+
30751+#ifdef CONFIG_PAX_RANDMMAP
30752+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30753+ info.low_limit += current->mm->delta_mmap;
30754+#endif
30755+
30756 info.high_limit = TASK_SIZE;
30757 addr = vm_unmapped_area(&info);
30758 }
30759@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30760 struct hstate *h = hstate_file(file);
30761 struct mm_struct *mm = current->mm;
30762 struct vm_area_struct *vma;
30763+ unsigned long pax_task_size = TASK_SIZE;
30764+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30765
30766 if (len & ~huge_page_mask(h))
30767 return -EINVAL;
30768- if (len > TASK_SIZE)
30769+
30770+#ifdef CONFIG_PAX_SEGMEXEC
30771+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30772+ pax_task_size = SEGMEXEC_TASK_SIZE;
30773+#endif
30774+
30775+ pax_task_size -= PAGE_SIZE;
30776+
30777+ if (len > pax_task_size)
30778 return -ENOMEM;
30779
30780 if (flags & MAP_FIXED) {
30781@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30782 return addr;
30783 }
30784
30785+#ifdef CONFIG_PAX_RANDMMAP
30786+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30787+#endif
30788+
30789 if (addr) {
30790 addr = ALIGN(addr, huge_page_size(h));
30791 vma = find_vma(mm, addr);
30792- if (TASK_SIZE - len >= addr &&
30793- (!vma || addr + len <= vma->vm_start))
30794+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30795 return addr;
30796 }
30797 if (mm->get_unmapped_area == arch_get_unmapped_area)
30798 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30799- pgoff, flags);
30800+ pgoff, flags, offset);
30801 else
30802 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30803- pgoff, flags);
30804+ pgoff, flags, offset);
30805 }
30806
30807 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30808diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30809index 04664cd..dae6e5d 100644
30810--- a/arch/x86/mm/init.c
30811+++ b/arch/x86/mm/init.c
30812@@ -4,6 +4,7 @@
30813 #include <linux/swap.h>
30814 #include <linux/memblock.h>
30815 #include <linux/bootmem.h> /* for max_low_pfn */
30816+#include <linux/tboot.h>
30817
30818 #include <asm/cacheflush.h>
30819 #include <asm/e820.h>
30820@@ -17,6 +18,8 @@
30821 #include <asm/proto.h>
30822 #include <asm/dma.h> /* for MAX_DMA_PFN */
30823 #include <asm/microcode.h>
30824+#include <asm/desc.h>
30825+#include <asm/bios_ebda.h>
30826
30827 #include "mm_internal.h"
30828
30829@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30830 early_ioremap_page_table_range_init();
30831 #endif
30832
30833+#ifdef CONFIG_PAX_PER_CPU_PGD
30834+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30835+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30836+ KERNEL_PGD_PTRS);
30837+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30838+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30839+ KERNEL_PGD_PTRS);
30840+ load_cr3(get_cpu_pgd(0, kernel));
30841+#else
30842 load_cr3(swapper_pg_dir);
30843+#endif
30844+
30845 __flush_tlb_all();
30846
30847 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30848@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30849 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30850 * mmio resources as well as potential bios/acpi data regions.
30851 */
30852+
30853+#ifdef CONFIG_GRKERNSEC_KMEM
30854+static unsigned int ebda_start __read_only;
30855+static unsigned int ebda_end __read_only;
30856+#endif
30857+
30858 int devmem_is_allowed(unsigned long pagenr)
30859 {
30860- if (pagenr < 256)
30861+#ifdef CONFIG_GRKERNSEC_KMEM
30862+ /* allow BDA */
30863+ if (!pagenr)
30864 return 1;
30865+ /* allow EBDA */
30866+ if (pagenr >= ebda_start && pagenr < ebda_end)
30867+ return 1;
30868+ /* if tboot is in use, allow access to its hardcoded serial log range */
30869+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30870+ return 1;
30871+#else
30872+ if (!pagenr)
30873+ return 1;
30874+#ifdef CONFIG_VM86
30875+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30876+ return 1;
30877+#endif
30878+#endif
30879+
30880+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30881+ return 1;
30882+#ifdef CONFIG_GRKERNSEC_KMEM
30883+ /* throw out everything else below 1MB */
30884+ if (pagenr <= 256)
30885+ return 0;
30886+#endif
30887 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30888 return 0;
30889 if (!page_is_ram(pagenr))
30890@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30891 #endif
30892 }
30893
30894+#ifdef CONFIG_GRKERNSEC_KMEM
30895+static inline void gr_init_ebda(void)
30896+{
30897+ unsigned int ebda_addr;
30898+ unsigned int ebda_size = 0;
30899+
30900+ ebda_addr = get_bios_ebda();
30901+ if (ebda_addr) {
30902+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30903+ ebda_size <<= 10;
30904+ }
30905+ if (ebda_addr && ebda_size) {
30906+ ebda_start = ebda_addr >> PAGE_SHIFT;
30907+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30908+ } else {
30909+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30910+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30911+ }
30912+}
30913+#else
30914+static inline void gr_init_ebda(void) { }
30915+#endif
30916+
30917 void free_initmem(void)
30918 {
30919+#ifdef CONFIG_PAX_KERNEXEC
30920+#ifdef CONFIG_X86_32
30921+ /* PaX: limit KERNEL_CS to actual size */
30922+ unsigned long addr, limit;
30923+ struct desc_struct d;
30924+ int cpu;
30925+#else
30926+ pgd_t *pgd;
30927+ pud_t *pud;
30928+ pmd_t *pmd;
30929+ unsigned long addr, end;
30930+#endif
30931+#endif
30932+
30933+ gr_init_ebda();
30934+
30935+#ifdef CONFIG_PAX_KERNEXEC
30936+#ifdef CONFIG_X86_32
30937+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30938+ limit = (limit - 1UL) >> PAGE_SHIFT;
30939+
30940+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30941+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30942+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30943+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30944+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30945+ }
30946+
30947+ /* PaX: make KERNEL_CS read-only */
30948+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30949+ if (!paravirt_enabled())
30950+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30951+/*
30952+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30953+ pgd = pgd_offset_k(addr);
30954+ pud = pud_offset(pgd, addr);
30955+ pmd = pmd_offset(pud, addr);
30956+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30957+ }
30958+*/
30959+#ifdef CONFIG_X86_PAE
30960+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30961+/*
30962+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30963+ pgd = pgd_offset_k(addr);
30964+ pud = pud_offset(pgd, addr);
30965+ pmd = pmd_offset(pud, addr);
30966+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30967+ }
30968+*/
30969+#endif
30970+
30971+#ifdef CONFIG_MODULES
30972+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30973+#endif
30974+
30975+#else
30976+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30977+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30978+ pgd = pgd_offset_k(addr);
30979+ pud = pud_offset(pgd, addr);
30980+ pmd = pmd_offset(pud, addr);
30981+ if (!pmd_present(*pmd))
30982+ continue;
30983+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30984+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30985+ else
30986+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30987+ }
30988+
30989+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30990+ end = addr + KERNEL_IMAGE_SIZE;
30991+ for (; addr < end; addr += PMD_SIZE) {
30992+ pgd = pgd_offset_k(addr);
30993+ pud = pud_offset(pgd, addr);
30994+ pmd = pmd_offset(pud, addr);
30995+ if (!pmd_present(*pmd))
30996+ continue;
30997+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30998+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30999+ }
31000+#endif
31001+
31002+ flush_tlb_all();
31003+#endif
31004+
31005 free_init_pages("unused kernel",
31006 (unsigned long)(&__init_begin),
31007 (unsigned long)(&__init_end));
31008diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31009index 4287f1f..3b99c71 100644
31010--- a/arch/x86/mm/init_32.c
31011+++ b/arch/x86/mm/init_32.c
31012@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31013 bool __read_mostly __vmalloc_start_set = false;
31014
31015 /*
31016- * Creates a middle page table and puts a pointer to it in the
31017- * given global directory entry. This only returns the gd entry
31018- * in non-PAE compilation mode, since the middle layer is folded.
31019- */
31020-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31021-{
31022- pud_t *pud;
31023- pmd_t *pmd_table;
31024-
31025-#ifdef CONFIG_X86_PAE
31026- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31027- pmd_table = (pmd_t *)alloc_low_page();
31028- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31029- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31030- pud = pud_offset(pgd, 0);
31031- BUG_ON(pmd_table != pmd_offset(pud, 0));
31032-
31033- return pmd_table;
31034- }
31035-#endif
31036- pud = pud_offset(pgd, 0);
31037- pmd_table = pmd_offset(pud, 0);
31038-
31039- return pmd_table;
31040-}
31041-
31042-/*
31043 * Create a page table and place a pointer to it in a middle page
31044 * directory entry:
31045 */
31046@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31047 pte_t *page_table = (pte_t *)alloc_low_page();
31048
31049 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31050+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31051+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31052+#else
31053 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31054+#endif
31055 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31056 }
31057
31058 return pte_offset_kernel(pmd, 0);
31059 }
31060
31061+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31062+{
31063+ pud_t *pud;
31064+ pmd_t *pmd_table;
31065+
31066+ pud = pud_offset(pgd, 0);
31067+ pmd_table = pmd_offset(pud, 0);
31068+
31069+ return pmd_table;
31070+}
31071+
31072 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31073 {
31074 int pgd_idx = pgd_index(vaddr);
31075@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31076 int pgd_idx, pmd_idx;
31077 unsigned long vaddr;
31078 pgd_t *pgd;
31079+ pud_t *pud;
31080 pmd_t *pmd;
31081 pte_t *pte = NULL;
31082 unsigned long count = page_table_range_init_count(start, end);
31083@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31084 pgd = pgd_base + pgd_idx;
31085
31086 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31087- pmd = one_md_table_init(pgd);
31088- pmd = pmd + pmd_index(vaddr);
31089+ pud = pud_offset(pgd, vaddr);
31090+ pmd = pmd_offset(pud, vaddr);
31091+
31092+#ifdef CONFIG_X86_PAE
31093+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31094+#endif
31095+
31096 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31097 pmd++, pmd_idx++) {
31098 pte = page_table_kmap_check(one_page_table_init(pmd),
31099@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31100 }
31101 }
31102
31103-static inline int is_kernel_text(unsigned long addr)
31104+static inline int is_kernel_text(unsigned long start, unsigned long end)
31105 {
31106- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31107- return 1;
31108- return 0;
31109+ if ((start > ktla_ktva((unsigned long)_etext) ||
31110+ end <= ktla_ktva((unsigned long)_stext)) &&
31111+ (start > ktla_ktva((unsigned long)_einittext) ||
31112+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31113+
31114+#ifdef CONFIG_ACPI_SLEEP
31115+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31116+#endif
31117+
31118+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31119+ return 0;
31120+ return 1;
31121 }
31122
31123 /*
31124@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31125 unsigned long last_map_addr = end;
31126 unsigned long start_pfn, end_pfn;
31127 pgd_t *pgd_base = swapper_pg_dir;
31128- int pgd_idx, pmd_idx, pte_ofs;
31129+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31130 unsigned long pfn;
31131 pgd_t *pgd;
31132+ pud_t *pud;
31133 pmd_t *pmd;
31134 pte_t *pte;
31135 unsigned pages_2m, pages_4k;
31136@@ -291,8 +295,13 @@ repeat:
31137 pfn = start_pfn;
31138 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31139 pgd = pgd_base + pgd_idx;
31140- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31141- pmd = one_md_table_init(pgd);
31142+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31143+ pud = pud_offset(pgd, 0);
31144+ pmd = pmd_offset(pud, 0);
31145+
31146+#ifdef CONFIG_X86_PAE
31147+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31148+#endif
31149
31150 if (pfn >= end_pfn)
31151 continue;
31152@@ -304,14 +313,13 @@ repeat:
31153 #endif
31154 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31155 pmd++, pmd_idx++) {
31156- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31157+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31158
31159 /*
31160 * Map with big pages if possible, otherwise
31161 * create normal page tables:
31162 */
31163 if (use_pse) {
31164- unsigned int addr2;
31165 pgprot_t prot = PAGE_KERNEL_LARGE;
31166 /*
31167 * first pass will use the same initial
31168@@ -322,11 +330,7 @@ repeat:
31169 _PAGE_PSE);
31170
31171 pfn &= PMD_MASK >> PAGE_SHIFT;
31172- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31173- PAGE_OFFSET + PAGE_SIZE-1;
31174-
31175- if (is_kernel_text(addr) ||
31176- is_kernel_text(addr2))
31177+ if (is_kernel_text(address, address + PMD_SIZE))
31178 prot = PAGE_KERNEL_LARGE_EXEC;
31179
31180 pages_2m++;
31181@@ -343,7 +347,7 @@ repeat:
31182 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31183 pte += pte_ofs;
31184 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31185- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31186+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31187 pgprot_t prot = PAGE_KERNEL;
31188 /*
31189 * first pass will use the same initial
31190@@ -351,7 +355,7 @@ repeat:
31191 */
31192 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31193
31194- if (is_kernel_text(addr))
31195+ if (is_kernel_text(address, address + PAGE_SIZE))
31196 prot = PAGE_KERNEL_EXEC;
31197
31198 pages_4k++;
31199@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31200
31201 pud = pud_offset(pgd, va);
31202 pmd = pmd_offset(pud, va);
31203- if (!pmd_present(*pmd))
31204+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31205 break;
31206
31207 /* should not be large page here */
31208@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31209
31210 static void __init pagetable_init(void)
31211 {
31212- pgd_t *pgd_base = swapper_pg_dir;
31213-
31214- permanent_kmaps_init(pgd_base);
31215+ permanent_kmaps_init(swapper_pg_dir);
31216 }
31217
31218-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31219+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31220 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31221
31222 /* user-defined highmem size */
31223@@ -787,10 +789,10 @@ void __init mem_init(void)
31224 ((unsigned long)&__init_end -
31225 (unsigned long)&__init_begin) >> 10,
31226
31227- (unsigned long)&_etext, (unsigned long)&_edata,
31228- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31229+ (unsigned long)&_sdata, (unsigned long)&_edata,
31230+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31231
31232- (unsigned long)&_text, (unsigned long)&_etext,
31233+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31234 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31235
31236 /*
31237@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31238 if (!kernel_set_to_readonly)
31239 return;
31240
31241+ start = ktla_ktva(start);
31242 pr_debug("Set kernel text: %lx - %lx for read write\n",
31243 start, start+size);
31244
31245@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31246 if (!kernel_set_to_readonly)
31247 return;
31248
31249+ start = ktla_ktva(start);
31250 pr_debug("Set kernel text: %lx - %lx for read only\n",
31251 start, start+size);
31252
31253@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31254 unsigned long start = PFN_ALIGN(_text);
31255 unsigned long size = PFN_ALIGN(_etext) - start;
31256
31257+ start = ktla_ktva(start);
31258 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31259 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31260 size >> 10);
31261diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31262index 104d56a..62ba13f 100644
31263--- a/arch/x86/mm/init_64.c
31264+++ b/arch/x86/mm/init_64.c
31265@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31266 * around without checking the pgd every time.
31267 */
31268
31269-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31270+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31271 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31272
31273 int force_personality32;
31274@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31275
31276 for (address = start; address <= end; address += PGDIR_SIZE) {
31277 const pgd_t *pgd_ref = pgd_offset_k(address);
31278+
31279+#ifdef CONFIG_PAX_PER_CPU_PGD
31280+ unsigned long cpu;
31281+#else
31282 struct page *page;
31283+#endif
31284
31285 if (pgd_none(*pgd_ref))
31286 continue;
31287
31288 spin_lock(&pgd_lock);
31289+
31290+#ifdef CONFIG_PAX_PER_CPU_PGD
31291+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31292+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31293+
31294+ if (pgd_none(*pgd))
31295+ set_pgd(pgd, *pgd_ref);
31296+ else
31297+ BUG_ON(pgd_page_vaddr(*pgd)
31298+ != pgd_page_vaddr(*pgd_ref));
31299+ pgd = pgd_offset_cpu(cpu, kernel, address);
31300+#else
31301 list_for_each_entry(page, &pgd_list, lru) {
31302 pgd_t *pgd;
31303 spinlock_t *pgt_lock;
31304@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31305 /* the pgt_lock only for Xen */
31306 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31307 spin_lock(pgt_lock);
31308+#endif
31309
31310 if (pgd_none(*pgd))
31311 set_pgd(pgd, *pgd_ref);
31312@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31313 BUG_ON(pgd_page_vaddr(*pgd)
31314 != pgd_page_vaddr(*pgd_ref));
31315
31316+#ifndef CONFIG_PAX_PER_CPU_PGD
31317 spin_unlock(pgt_lock);
31318+#endif
31319+
31320 }
31321 spin_unlock(&pgd_lock);
31322 }
31323@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31324 {
31325 if (pgd_none(*pgd)) {
31326 pud_t *pud = (pud_t *)spp_getpage();
31327- pgd_populate(&init_mm, pgd, pud);
31328+ pgd_populate_kernel(&init_mm, pgd, pud);
31329 if (pud != pud_offset(pgd, 0))
31330 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31331 pud, pud_offset(pgd, 0));
31332@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31333 {
31334 if (pud_none(*pud)) {
31335 pmd_t *pmd = (pmd_t *) spp_getpage();
31336- pud_populate(&init_mm, pud, pmd);
31337+ pud_populate_kernel(&init_mm, pud, pmd);
31338 if (pmd != pmd_offset(pud, 0))
31339 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31340 pmd, pmd_offset(pud, 0));
31341@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31342 pmd = fill_pmd(pud, vaddr);
31343 pte = fill_pte(pmd, vaddr);
31344
31345+ pax_open_kernel();
31346 set_pte(pte, new_pte);
31347+ pax_close_kernel();
31348
31349 /*
31350 * It's enough to flush this one mapping.
31351@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31352 pgd = pgd_offset_k((unsigned long)__va(phys));
31353 if (pgd_none(*pgd)) {
31354 pud = (pud_t *) spp_getpage();
31355- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31356- _PAGE_USER));
31357+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31358 }
31359 pud = pud_offset(pgd, (unsigned long)__va(phys));
31360 if (pud_none(*pud)) {
31361 pmd = (pmd_t *) spp_getpage();
31362- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31363- _PAGE_USER));
31364+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31365 }
31366 pmd = pmd_offset(pud, phys);
31367 BUG_ON(!pmd_none(*pmd));
31368@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31369 prot);
31370
31371 spin_lock(&init_mm.page_table_lock);
31372- pud_populate(&init_mm, pud, pmd);
31373+ pud_populate_kernel(&init_mm, pud, pmd);
31374 spin_unlock(&init_mm.page_table_lock);
31375 }
31376 __flush_tlb_all();
31377@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31378 page_size_mask);
31379
31380 spin_lock(&init_mm.page_table_lock);
31381- pgd_populate(&init_mm, pgd, pud);
31382+ pgd_populate_kernel(&init_mm, pgd, pud);
31383 spin_unlock(&init_mm.page_table_lock);
31384 pgd_changed = true;
31385 }
31386@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31387 static struct vm_area_struct gate_vma = {
31388 .vm_start = VSYSCALL_START,
31389 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31390- .vm_page_prot = PAGE_READONLY_EXEC,
31391- .vm_flags = VM_READ | VM_EXEC
31392+ .vm_page_prot = PAGE_READONLY,
31393+ .vm_flags = VM_READ
31394 };
31395
31396 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31397@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31398
31399 const char *arch_vma_name(struct vm_area_struct *vma)
31400 {
31401- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31402+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31403 return "[vdso]";
31404 if (vma == &gate_vma)
31405 return "[vsyscall]";
31406diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31407index 7b179b4..6bd17777 100644
31408--- a/arch/x86/mm/iomap_32.c
31409+++ b/arch/x86/mm/iomap_32.c
31410@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31411 type = kmap_atomic_idx_push();
31412 idx = type + KM_TYPE_NR * smp_processor_id();
31413 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31414+
31415+ pax_open_kernel();
31416 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31417+ pax_close_kernel();
31418+
31419 arch_flush_lazy_mmu_mode();
31420
31421 return (void *)vaddr;
31422diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31423index 0215e2c..1c62dab 100644
31424--- a/arch/x86/mm/ioremap.c
31425+++ b/arch/x86/mm/ioremap.c
31426@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31427 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31428 int is_ram = page_is_ram(pfn);
31429
31430- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31431+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31432 return NULL;
31433 WARN_ON_ONCE(is_ram);
31434 }
31435@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31436 *
31437 * Caller must ensure there is only one unmapping for the same pointer.
31438 */
31439-void iounmap(volatile void __iomem *addr)
31440+void iounmap(const volatile void __iomem *addr)
31441 {
31442 struct vm_struct *p, *o;
31443
31444@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31445
31446 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31447 if (page_is_ram(start >> PAGE_SHIFT))
31448+#ifdef CONFIG_HIGHMEM
31449+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31450+#endif
31451 return __va(phys);
31452
31453 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31454@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31455 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31456 {
31457 if (page_is_ram(phys >> PAGE_SHIFT))
31458+#ifdef CONFIG_HIGHMEM
31459+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31460+#endif
31461 return;
31462
31463 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31464@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31465 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31466
31467 static __initdata int after_paging_init;
31468-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31469+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31470
31471 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31472 {
31473@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31474 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31475
31476 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31477- memset(bm_pte, 0, sizeof(bm_pte));
31478- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31479+ pmd_populate_user(&init_mm, pmd, bm_pte);
31480
31481 /*
31482 * The boot-ioremap range spans multiple pmds, for which
31483diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31484index d87dd6d..bf3fa66 100644
31485--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31486+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31487@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31488 * memory (e.g. tracked pages)? For now, we need this to avoid
31489 * invoking kmemcheck for PnP BIOS calls.
31490 */
31491- if (regs->flags & X86_VM_MASK)
31492+ if (v8086_mode(regs))
31493 return false;
31494- if (regs->cs != __KERNEL_CS)
31495+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31496 return false;
31497
31498 pte = kmemcheck_pte_lookup(address);
31499diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31500index 25e7e13..1964579 100644
31501--- a/arch/x86/mm/mmap.c
31502+++ b/arch/x86/mm/mmap.c
31503@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31504 * Leave an at least ~128 MB hole with possible stack randomization.
31505 */
31506 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31507-#define MAX_GAP (TASK_SIZE/6*5)
31508+#define MAX_GAP (pax_task_size/6*5)
31509
31510 static int mmap_is_legacy(void)
31511 {
31512@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31513 return rnd << PAGE_SHIFT;
31514 }
31515
31516-static unsigned long mmap_base(void)
31517+static unsigned long mmap_base(struct mm_struct *mm)
31518 {
31519 unsigned long gap = rlimit(RLIMIT_STACK);
31520+ unsigned long pax_task_size = TASK_SIZE;
31521+
31522+#ifdef CONFIG_PAX_SEGMEXEC
31523+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31524+ pax_task_size = SEGMEXEC_TASK_SIZE;
31525+#endif
31526
31527 if (gap < MIN_GAP)
31528 gap = MIN_GAP;
31529 else if (gap > MAX_GAP)
31530 gap = MAX_GAP;
31531
31532- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31533+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31534 }
31535
31536 /*
31537 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31538 * does, but not when emulating X86_32
31539 */
31540-static unsigned long mmap_legacy_base(void)
31541+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31542 {
31543- if (mmap_is_ia32())
31544+ if (mmap_is_ia32()) {
31545+
31546+#ifdef CONFIG_PAX_SEGMEXEC
31547+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31548+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31549+ else
31550+#endif
31551+
31552 return TASK_UNMAPPED_BASE;
31553- else
31554+ } else
31555 return TASK_UNMAPPED_BASE + mmap_rnd();
31556 }
31557
31558@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31559 */
31560 void arch_pick_mmap_layout(struct mm_struct *mm)
31561 {
31562- mm->mmap_legacy_base = mmap_legacy_base();
31563- mm->mmap_base = mmap_base();
31564+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31565+ mm->mmap_base = mmap_base(mm);
31566+
31567+#ifdef CONFIG_PAX_RANDMMAP
31568+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31569+ mm->mmap_legacy_base += mm->delta_mmap;
31570+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31571+ }
31572+#endif
31573
31574 if (mmap_is_legacy()) {
31575 mm->mmap_base = mm->mmap_legacy_base;
31576diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31577index 0057a7a..95c7edd 100644
31578--- a/arch/x86/mm/mmio-mod.c
31579+++ b/arch/x86/mm/mmio-mod.c
31580@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31581 break;
31582 default:
31583 {
31584- unsigned char *ip = (unsigned char *)instptr;
31585+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31586 my_trace->opcode = MMIO_UNKNOWN_OP;
31587 my_trace->width = 0;
31588 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31589@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31590 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31591 void __iomem *addr)
31592 {
31593- static atomic_t next_id;
31594+ static atomic_unchecked_t next_id;
31595 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31596 /* These are page-unaligned. */
31597 struct mmiotrace_map map = {
31598@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31599 .private = trace
31600 },
31601 .phys = offset,
31602- .id = atomic_inc_return(&next_id)
31603+ .id = atomic_inc_return_unchecked(&next_id)
31604 };
31605 map.map_id = trace->id;
31606
31607@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31608 ioremap_trace_core(offset, size, addr);
31609 }
31610
31611-static void iounmap_trace_core(volatile void __iomem *addr)
31612+static void iounmap_trace_core(const volatile void __iomem *addr)
31613 {
31614 struct mmiotrace_map map = {
31615 .phys = 0,
31616@@ -328,7 +328,7 @@ not_enabled:
31617 }
31618 }
31619
31620-void mmiotrace_iounmap(volatile void __iomem *addr)
31621+void mmiotrace_iounmap(const volatile void __iomem *addr)
31622 {
31623 might_sleep();
31624 if (is_enabled()) /* recheck and proper locking in *_core() */
31625diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31626index 8bf93ba..dbcd670 100644
31627--- a/arch/x86/mm/numa.c
31628+++ b/arch/x86/mm/numa.c
31629@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31630 return true;
31631 }
31632
31633-static int __init numa_register_memblks(struct numa_meminfo *mi)
31634+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31635 {
31636 unsigned long uninitialized_var(pfn_align);
31637 int i, nid;
31638diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31639index d0b1773..4c3327c 100644
31640--- a/arch/x86/mm/pageattr-test.c
31641+++ b/arch/x86/mm/pageattr-test.c
31642@@ -36,7 +36,7 @@ enum {
31643
31644 static int pte_testbit(pte_t pte)
31645 {
31646- return pte_flags(pte) & _PAGE_UNUSED1;
31647+ return pte_flags(pte) & _PAGE_CPA_TEST;
31648 }
31649
31650 struct split_state {
31651diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31652index bb32480..75f2f5e 100644
31653--- a/arch/x86/mm/pageattr.c
31654+++ b/arch/x86/mm/pageattr.c
31655@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31656 */
31657 #ifdef CONFIG_PCI_BIOS
31658 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31659- pgprot_val(forbidden) |= _PAGE_NX;
31660+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31661 #endif
31662
31663 /*
31664@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31665 * Does not cover __inittext since that is gone later on. On
31666 * 64bit we do not enforce !NX on the low mapping
31667 */
31668- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31669- pgprot_val(forbidden) |= _PAGE_NX;
31670+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31671+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31672
31673+#ifdef CONFIG_DEBUG_RODATA
31674 /*
31675 * The .rodata section needs to be read-only. Using the pfn
31676 * catches all aliases.
31677@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31678 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31679 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31680 pgprot_val(forbidden) |= _PAGE_RW;
31681+#endif
31682
31683 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31684 /*
31685@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31686 }
31687 #endif
31688
31689+#ifdef CONFIG_PAX_KERNEXEC
31690+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31691+ pgprot_val(forbidden) |= _PAGE_RW;
31692+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31693+ }
31694+#endif
31695+
31696 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31697
31698 return prot;
31699@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31700 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31701 {
31702 /* change init_mm */
31703+ pax_open_kernel();
31704 set_pte_atomic(kpte, pte);
31705+
31706 #ifdef CONFIG_X86_32
31707 if (!SHARED_KERNEL_PMD) {
31708+
31709+#ifdef CONFIG_PAX_PER_CPU_PGD
31710+ unsigned long cpu;
31711+#else
31712 struct page *page;
31713+#endif
31714
31715+#ifdef CONFIG_PAX_PER_CPU_PGD
31716+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31717+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31718+#else
31719 list_for_each_entry(page, &pgd_list, lru) {
31720- pgd_t *pgd;
31721+ pgd_t *pgd = (pgd_t *)page_address(page);
31722+#endif
31723+
31724 pud_t *pud;
31725 pmd_t *pmd;
31726
31727- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31728+ pgd += pgd_index(address);
31729 pud = pud_offset(pgd, address);
31730 pmd = pmd_offset(pud, address);
31731 set_pte_atomic((pte_t *)pmd, pte);
31732 }
31733 }
31734 #endif
31735+ pax_close_kernel();
31736 }
31737
31738 static int
31739diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31740index 6574388..87e9bef 100644
31741--- a/arch/x86/mm/pat.c
31742+++ b/arch/x86/mm/pat.c
31743@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31744
31745 if (!entry) {
31746 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31747- current->comm, current->pid, start, end - 1);
31748+ current->comm, task_pid_nr(current), start, end - 1);
31749 return -EINVAL;
31750 }
31751
31752@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31753
31754 while (cursor < to) {
31755 if (!devmem_is_allowed(pfn)) {
31756- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31757- current->comm, from, to - 1);
31758+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31759+ current->comm, from, to - 1, cursor);
31760 return 0;
31761 }
31762 cursor += PAGE_SIZE;
31763@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31764 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31765 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31766 "for [mem %#010Lx-%#010Lx]\n",
31767- current->comm, current->pid,
31768+ current->comm, task_pid_nr(current),
31769 cattr_name(flags),
31770 base, (unsigned long long)(base + size-1));
31771 return -EINVAL;
31772@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31773 flags = lookup_memtype(paddr);
31774 if (want_flags != flags) {
31775 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31776- current->comm, current->pid,
31777+ current->comm, task_pid_nr(current),
31778 cattr_name(want_flags),
31779 (unsigned long long)paddr,
31780 (unsigned long long)(paddr + size - 1),
31781@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31782 free_memtype(paddr, paddr + size);
31783 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31784 " for [mem %#010Lx-%#010Lx], got %s\n",
31785- current->comm, current->pid,
31786+ current->comm, task_pid_nr(current),
31787 cattr_name(want_flags),
31788 (unsigned long long)paddr,
31789 (unsigned long long)(paddr + size - 1),
31790diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31791index 415f6c4..d319983 100644
31792--- a/arch/x86/mm/pat_rbtree.c
31793+++ b/arch/x86/mm/pat_rbtree.c
31794@@ -160,7 +160,7 @@ success:
31795
31796 failure:
31797 printk(KERN_INFO "%s:%d conflicting memory types "
31798- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31799+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31800 end, cattr_name(found_type), cattr_name(match->type));
31801 return -EBUSY;
31802 }
31803diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31804index 9f0614d..92ae64a 100644
31805--- a/arch/x86/mm/pf_in.c
31806+++ b/arch/x86/mm/pf_in.c
31807@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31808 int i;
31809 enum reason_type rv = OTHERS;
31810
31811- p = (unsigned char *)ins_addr;
31812+ p = (unsigned char *)ktla_ktva(ins_addr);
31813 p += skip_prefix(p, &prf);
31814 p += get_opcode(p, &opcode);
31815
31816@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31817 struct prefix_bits prf;
31818 int i;
31819
31820- p = (unsigned char *)ins_addr;
31821+ p = (unsigned char *)ktla_ktva(ins_addr);
31822 p += skip_prefix(p, &prf);
31823 p += get_opcode(p, &opcode);
31824
31825@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31826 struct prefix_bits prf;
31827 int i;
31828
31829- p = (unsigned char *)ins_addr;
31830+ p = (unsigned char *)ktla_ktva(ins_addr);
31831 p += skip_prefix(p, &prf);
31832 p += get_opcode(p, &opcode);
31833
31834@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31835 struct prefix_bits prf;
31836 int i;
31837
31838- p = (unsigned char *)ins_addr;
31839+ p = (unsigned char *)ktla_ktva(ins_addr);
31840 p += skip_prefix(p, &prf);
31841 p += get_opcode(p, &opcode);
31842 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31843@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31844 struct prefix_bits prf;
31845 int i;
31846
31847- p = (unsigned char *)ins_addr;
31848+ p = (unsigned char *)ktla_ktva(ins_addr);
31849 p += skip_prefix(p, &prf);
31850 p += get_opcode(p, &opcode);
31851 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31852diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31853index dfa537a..fd45c64 100644
31854--- a/arch/x86/mm/pgtable.c
31855+++ b/arch/x86/mm/pgtable.c
31856@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31857 list_del(&page->lru);
31858 }
31859
31860-#define UNSHARED_PTRS_PER_PGD \
31861- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31862+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31863+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31864
31865+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31866+{
31867+ unsigned int count = USER_PGD_PTRS;
31868
31869+ if (!pax_user_shadow_base)
31870+ return;
31871+
31872+ while (count--)
31873+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31874+}
31875+#endif
31876+
31877+#ifdef CONFIG_PAX_PER_CPU_PGD
31878+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31879+{
31880+ unsigned int count = USER_PGD_PTRS;
31881+
31882+ while (count--) {
31883+ pgd_t pgd;
31884+
31885+#ifdef CONFIG_X86_64
31886+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31887+#else
31888+ pgd = *src++;
31889+#endif
31890+
31891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31892+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31893+#endif
31894+
31895+ *dst++ = pgd;
31896+ }
31897+
31898+}
31899+#endif
31900+
31901+#ifdef CONFIG_X86_64
31902+#define pxd_t pud_t
31903+#define pyd_t pgd_t
31904+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31905+#define pxd_free(mm, pud) pud_free((mm), (pud))
31906+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31907+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31908+#define PYD_SIZE PGDIR_SIZE
31909+#else
31910+#define pxd_t pmd_t
31911+#define pyd_t pud_t
31912+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31913+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31914+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31915+#define pyd_offset(mm, address) pud_offset((mm), (address))
31916+#define PYD_SIZE PUD_SIZE
31917+#endif
31918+
31919+#ifdef CONFIG_PAX_PER_CPU_PGD
31920+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31921+static inline void pgd_dtor(pgd_t *pgd) {}
31922+#else
31923 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31924 {
31925 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31926@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31927 pgd_list_del(pgd);
31928 spin_unlock(&pgd_lock);
31929 }
31930+#endif
31931
31932 /*
31933 * List of all pgd's needed for non-PAE so it can invalidate entries
31934@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31935 * -- nyc
31936 */
31937
31938-#ifdef CONFIG_X86_PAE
31939+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31940 /*
31941 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31942 * updating the top-level pagetable entries to guarantee the
31943@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31944 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31945 * and initialize the kernel pmds here.
31946 */
31947-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31948+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31949
31950 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31951 {
31952@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31953 */
31954 flush_tlb_mm(mm);
31955 }
31956+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31957+#define PREALLOCATED_PXDS USER_PGD_PTRS
31958 #else /* !CONFIG_X86_PAE */
31959
31960 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31961-#define PREALLOCATED_PMDS 0
31962+#define PREALLOCATED_PXDS 0
31963
31964 #endif /* CONFIG_X86_PAE */
31965
31966-static void free_pmds(pmd_t *pmds[])
31967+static void free_pxds(pxd_t *pxds[])
31968 {
31969 int i;
31970
31971- for(i = 0; i < PREALLOCATED_PMDS; i++)
31972- if (pmds[i])
31973- free_page((unsigned long)pmds[i]);
31974+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31975+ if (pxds[i])
31976+ free_page((unsigned long)pxds[i]);
31977 }
31978
31979-static int preallocate_pmds(pmd_t *pmds[])
31980+static int preallocate_pxds(pxd_t *pxds[])
31981 {
31982 int i;
31983 bool failed = false;
31984
31985- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31986- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31987- if (pmd == NULL)
31988+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31989+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31990+ if (pxd == NULL)
31991 failed = true;
31992- pmds[i] = pmd;
31993+ pxds[i] = pxd;
31994 }
31995
31996 if (failed) {
31997- free_pmds(pmds);
31998+ free_pxds(pxds);
31999 return -ENOMEM;
32000 }
32001
32002@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32003 * preallocate which never got a corresponding vma will need to be
32004 * freed manually.
32005 */
32006-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32007+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32008 {
32009 int i;
32010
32011- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32012+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32013 pgd_t pgd = pgdp[i];
32014
32015 if (pgd_val(pgd) != 0) {
32016- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32017+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32018
32019- pgdp[i] = native_make_pgd(0);
32020+ set_pgd(pgdp + i, native_make_pgd(0));
32021
32022- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32023- pmd_free(mm, pmd);
32024+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32025+ pxd_free(mm, pxd);
32026 }
32027 }
32028 }
32029
32030-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32031+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32032 {
32033- pud_t *pud;
32034+ pyd_t *pyd;
32035 int i;
32036
32037- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32038+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32039 return;
32040
32041- pud = pud_offset(pgd, 0);
32042-
32043- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32044- pmd_t *pmd = pmds[i];
32045+#ifdef CONFIG_X86_64
32046+ pyd = pyd_offset(mm, 0L);
32047+#else
32048+ pyd = pyd_offset(pgd, 0L);
32049+#endif
32050
32051+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32052+ pxd_t *pxd = pxds[i];
32053 if (i >= KERNEL_PGD_BOUNDARY)
32054- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32055- sizeof(pmd_t) * PTRS_PER_PMD);
32056+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32057+ sizeof(pxd_t) * PTRS_PER_PMD);
32058
32059- pud_populate(mm, pud, pmd);
32060+ pyd_populate(mm, pyd, pxd);
32061 }
32062 }
32063
32064 pgd_t *pgd_alloc(struct mm_struct *mm)
32065 {
32066 pgd_t *pgd;
32067- pmd_t *pmds[PREALLOCATED_PMDS];
32068+ pxd_t *pxds[PREALLOCATED_PXDS];
32069
32070 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32071
32072@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32073
32074 mm->pgd = pgd;
32075
32076- if (preallocate_pmds(pmds) != 0)
32077+ if (preallocate_pxds(pxds) != 0)
32078 goto out_free_pgd;
32079
32080 if (paravirt_pgd_alloc(mm) != 0)
32081- goto out_free_pmds;
32082+ goto out_free_pxds;
32083
32084 /*
32085 * Make sure that pre-populating the pmds is atomic with
32086@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32087 spin_lock(&pgd_lock);
32088
32089 pgd_ctor(mm, pgd);
32090- pgd_prepopulate_pmd(mm, pgd, pmds);
32091+ pgd_prepopulate_pxd(mm, pgd, pxds);
32092
32093 spin_unlock(&pgd_lock);
32094
32095 return pgd;
32096
32097-out_free_pmds:
32098- free_pmds(pmds);
32099+out_free_pxds:
32100+ free_pxds(pxds);
32101 out_free_pgd:
32102 free_page((unsigned long)pgd);
32103 out:
32104@@ -300,7 +363,7 @@ out:
32105
32106 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32107 {
32108- pgd_mop_up_pmds(mm, pgd);
32109+ pgd_mop_up_pxds(mm, pgd);
32110 pgd_dtor(pgd);
32111 paravirt_pgd_free(mm, pgd);
32112 free_page((unsigned long)pgd);
32113diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32114index a69bcb8..19068ab 100644
32115--- a/arch/x86/mm/pgtable_32.c
32116+++ b/arch/x86/mm/pgtable_32.c
32117@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32118 return;
32119 }
32120 pte = pte_offset_kernel(pmd, vaddr);
32121+
32122+ pax_open_kernel();
32123 if (pte_val(pteval))
32124 set_pte_at(&init_mm, vaddr, pte, pteval);
32125 else
32126 pte_clear(&init_mm, vaddr, pte);
32127+ pax_close_kernel();
32128
32129 /*
32130 * It's enough to flush this one mapping.
32131diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32132index e666cbb..61788c45 100644
32133--- a/arch/x86/mm/physaddr.c
32134+++ b/arch/x86/mm/physaddr.c
32135@@ -10,7 +10,7 @@
32136 #ifdef CONFIG_X86_64
32137
32138 #ifdef CONFIG_DEBUG_VIRTUAL
32139-unsigned long __phys_addr(unsigned long x)
32140+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32141 {
32142 unsigned long y = x - __START_KERNEL_map;
32143
32144@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32145 #else
32146
32147 #ifdef CONFIG_DEBUG_VIRTUAL
32148-unsigned long __phys_addr(unsigned long x)
32149+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32150 {
32151 unsigned long phys_addr = x - PAGE_OFFSET;
32152 /* VMALLOC_* aren't constants */
32153diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32154index 90555bf..f5f1828 100644
32155--- a/arch/x86/mm/setup_nx.c
32156+++ b/arch/x86/mm/setup_nx.c
32157@@ -5,8 +5,10 @@
32158 #include <asm/pgtable.h>
32159 #include <asm/proto.h>
32160
32161+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32162 static int disable_nx;
32163
32164+#ifndef CONFIG_PAX_PAGEEXEC
32165 /*
32166 * noexec = on|off
32167 *
32168@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32169 return 0;
32170 }
32171 early_param("noexec", noexec_setup);
32172+#endif
32173+
32174+#endif
32175
32176 void x86_configure_nx(void)
32177 {
32178+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32179 if (cpu_has_nx && !disable_nx)
32180 __supported_pte_mask |= _PAGE_NX;
32181 else
32182+#endif
32183 __supported_pte_mask &= ~_PAGE_NX;
32184 }
32185
32186diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32187index 282375f..e03a98f 100644
32188--- a/arch/x86/mm/tlb.c
32189+++ b/arch/x86/mm/tlb.c
32190@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32191 BUG();
32192 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32193 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32194+
32195+#ifndef CONFIG_PAX_PER_CPU_PGD
32196 load_cr3(swapper_pg_dir);
32197+#endif
32198+
32199 }
32200 }
32201 EXPORT_SYMBOL_GPL(leave_mm);
32202diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32203new file mode 100644
32204index 0000000..dace51c
32205--- /dev/null
32206+++ b/arch/x86/mm/uderef_64.c
32207@@ -0,0 +1,37 @@
32208+#include <linux/mm.h>
32209+#include <asm/pgtable.h>
32210+#include <asm/uaccess.h>
32211+
32212+#ifdef CONFIG_PAX_MEMORY_UDEREF
32213+/* PaX: due to the special call convention these functions must
32214+ * - remain leaf functions under all configurations,
32215+ * - never be called directly, only dereferenced from the wrappers.
32216+ */
32217+void __pax_open_userland(void)
32218+{
32219+ unsigned int cpu;
32220+
32221+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32222+ return;
32223+
32224+ cpu = raw_get_cpu();
32225+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32226+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32227+ raw_put_cpu_no_resched();
32228+}
32229+EXPORT_SYMBOL(__pax_open_userland);
32230+
32231+void __pax_close_userland(void)
32232+{
32233+ unsigned int cpu;
32234+
32235+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32236+ return;
32237+
32238+ cpu = raw_get_cpu();
32239+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32240+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32241+ raw_put_cpu_no_resched();
32242+}
32243+EXPORT_SYMBOL(__pax_close_userland);
32244+#endif
32245diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32246index 877b9a1..a8ecf42 100644
32247--- a/arch/x86/net/bpf_jit.S
32248+++ b/arch/x86/net/bpf_jit.S
32249@@ -9,6 +9,7 @@
32250 */
32251 #include <linux/linkage.h>
32252 #include <asm/dwarf2.h>
32253+#include <asm/alternative-asm.h>
32254
32255 /*
32256 * Calling convention :
32257@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32258 jle bpf_slow_path_word
32259 mov (SKBDATA,%rsi),%eax
32260 bswap %eax /* ntohl() */
32261+ pax_force_retaddr
32262 ret
32263
32264 sk_load_half:
32265@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32266 jle bpf_slow_path_half
32267 movzwl (SKBDATA,%rsi),%eax
32268 rol $8,%ax # ntohs()
32269+ pax_force_retaddr
32270 ret
32271
32272 sk_load_byte:
32273@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32274 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32275 jle bpf_slow_path_byte
32276 movzbl (SKBDATA,%rsi),%eax
32277+ pax_force_retaddr
32278 ret
32279
32280 /**
32281@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32282 movzbl (SKBDATA,%rsi),%ebx
32283 and $15,%bl
32284 shl $2,%bl
32285+ pax_force_retaddr
32286 ret
32287
32288 /* rsi contains offset and can be scratched */
32289@@ -109,6 +114,7 @@ bpf_slow_path_word:
32290 js bpf_error
32291 mov -12(%rbp),%eax
32292 bswap %eax
32293+ pax_force_retaddr
32294 ret
32295
32296 bpf_slow_path_half:
32297@@ -117,12 +123,14 @@ bpf_slow_path_half:
32298 mov -12(%rbp),%ax
32299 rol $8,%ax
32300 movzwl %ax,%eax
32301+ pax_force_retaddr
32302 ret
32303
32304 bpf_slow_path_byte:
32305 bpf_slow_path_common(1)
32306 js bpf_error
32307 movzbl -12(%rbp),%eax
32308+ pax_force_retaddr
32309 ret
32310
32311 bpf_slow_path_byte_msh:
32312@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32313 and $15,%al
32314 shl $2,%al
32315 xchg %eax,%ebx
32316+ pax_force_retaddr
32317 ret
32318
32319 #define sk_negative_common(SIZE) \
32320@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32321 sk_negative_common(4)
32322 mov (%rax), %eax
32323 bswap %eax
32324+ pax_force_retaddr
32325 ret
32326
32327 bpf_slow_path_half_neg:
32328@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32329 mov (%rax),%ax
32330 rol $8,%ax
32331 movzwl %ax,%eax
32332+ pax_force_retaddr
32333 ret
32334
32335 bpf_slow_path_byte_neg:
32336@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32337 .globl sk_load_byte_negative_offset
32338 sk_negative_common(1)
32339 movzbl (%rax), %eax
32340+ pax_force_retaddr
32341 ret
32342
32343 bpf_slow_path_byte_msh_neg:
32344@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32345 and $15,%al
32346 shl $2,%al
32347 xchg %eax,%ebx
32348+ pax_force_retaddr
32349 ret
32350
32351 bpf_error:
32352@@ -197,4 +210,5 @@ bpf_error:
32353 xor %eax,%eax
32354 mov -8(%rbp),%rbx
32355 leaveq
32356+ pax_force_retaddr
32357 ret
32358diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32359index 79c216a..08d39cc 100644
32360--- a/arch/x86/net/bpf_jit_comp.c
32361+++ b/arch/x86/net/bpf_jit_comp.c
32362@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32363 return ptr + len;
32364 }
32365
32366+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32367+#define MAX_INSTR_CODE_SIZE 96
32368+#else
32369+#define MAX_INSTR_CODE_SIZE 64
32370+#endif
32371+
32372 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32373
32374 #define EMIT1(b1) EMIT(b1, 1)
32375 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32376 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32377 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32378+
32379+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32380+/* original constant will appear in ecx */
32381+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32382+do { \
32383+ /* mov ecx, randkey */ \
32384+ EMIT1(0xb9); \
32385+ EMIT(_key, 4); \
32386+ /* xor ecx, randkey ^ off */ \
32387+ EMIT2(0x81, 0xf1); \
32388+ EMIT((_key) ^ (_off), 4); \
32389+} while (0)
32390+
32391+#define EMIT1_off32(b1, _off) \
32392+do { \
32393+ switch (b1) { \
32394+ case 0x05: /* add eax, imm32 */ \
32395+ case 0x2d: /* sub eax, imm32 */ \
32396+ case 0x25: /* and eax, imm32 */ \
32397+ case 0x0d: /* or eax, imm32 */ \
32398+ case 0xb8: /* mov eax, imm32 */ \
32399+ case 0x35: /* xor eax, imm32 */ \
32400+ case 0x3d: /* cmp eax, imm32 */ \
32401+ case 0xa9: /* test eax, imm32 */ \
32402+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32403+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32404+ break; \
32405+ case 0xbb: /* mov ebx, imm32 */ \
32406+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32407+ /* mov ebx, ecx */ \
32408+ EMIT2(0x89, 0xcb); \
32409+ break; \
32410+ case 0xbe: /* mov esi, imm32 */ \
32411+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32412+ /* mov esi, ecx */ \
32413+ EMIT2(0x89, 0xce); \
32414+ break; \
32415+ case 0xe8: /* call rel imm32, always to known funcs */ \
32416+ EMIT1(b1); \
32417+ EMIT(_off, 4); \
32418+ break; \
32419+ case 0xe9: /* jmp rel imm32 */ \
32420+ EMIT1(b1); \
32421+ EMIT(_off, 4); \
32422+ /* prevent fall-through, we're not called if off = 0 */ \
32423+ EMIT(0xcccccccc, 4); \
32424+ EMIT(0xcccccccc, 4); \
32425+ break; \
32426+ default: \
32427+ BUILD_BUG(); \
32428+ } \
32429+} while (0)
32430+
32431+#define EMIT2_off32(b1, b2, _off) \
32432+do { \
32433+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32434+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32435+ EMIT(randkey, 4); \
32436+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32437+ EMIT((_off) - randkey, 4); \
32438+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32439+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32440+ /* imul eax, ecx */ \
32441+ EMIT3(0x0f, 0xaf, 0xc1); \
32442+ } else { \
32443+ BUILD_BUG(); \
32444+ } \
32445+} while (0)
32446+#else
32447 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32448+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32449+#endif
32450
32451 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32452 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32453@@ -91,6 +168,24 @@ do { \
32454 #define X86_JBE 0x76
32455 #define X86_JA 0x77
32456
32457+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32458+#define APPEND_FLOW_VERIFY() \
32459+do { \
32460+ /* mov ecx, randkey */ \
32461+ EMIT1(0xb9); \
32462+ EMIT(randkey, 4); \
32463+ /* cmp ecx, randkey */ \
32464+ EMIT2(0x81, 0xf9); \
32465+ EMIT(randkey, 4); \
32466+ /* jz after 8 int 3s */ \
32467+ EMIT2(0x74, 0x08); \
32468+ EMIT(0xcccccccc, 4); \
32469+ EMIT(0xcccccccc, 4); \
32470+} while (0)
32471+#else
32472+#define APPEND_FLOW_VERIFY() do { } while (0)
32473+#endif
32474+
32475 #define EMIT_COND_JMP(op, offset) \
32476 do { \
32477 if (is_near(offset)) \
32478@@ -98,6 +193,7 @@ do { \
32479 else { \
32480 EMIT2(0x0f, op + 0x10); \
32481 EMIT(offset, 4); /* jxx .+off32 */ \
32482+ APPEND_FLOW_VERIFY(); \
32483 } \
32484 } while (0)
32485
32486@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32487 return -1;
32488 }
32489
32490-struct bpf_binary_header {
32491- unsigned int pages;
32492- /* Note : for security reasons, bpf code will follow a randomly
32493- * sized amount of int3 instructions
32494- */
32495- u8 image[];
32496-};
32497-
32498-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32499+/* Note : for security reasons, bpf code will follow a randomly
32500+ * sized amount of int3 instructions
32501+ */
32502+static u8 *bpf_alloc_binary(unsigned int proglen,
32503 u8 **image_ptr)
32504 {
32505 unsigned int sz, hole;
32506- struct bpf_binary_header *header;
32507+ u8 *header;
32508
32509 /* Most of BPF filters are really small,
32510 * but if some of them fill a page, allow at least
32511 * 128 extra bytes to insert a random section of int3
32512 */
32513- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32514- header = module_alloc(sz);
32515+ sz = round_up(proglen + 128, PAGE_SIZE);
32516+ header = module_alloc_exec(sz);
32517 if (!header)
32518 return NULL;
32519
32520+ pax_open_kernel();
32521 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32522+ pax_close_kernel();
32523
32524- header->pages = sz / PAGE_SIZE;
32525- hole = sz - (proglen + sizeof(*header));
32526+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32527
32528 /* insert a random number of int3 instructions before BPF code */
32529- *image_ptr = &header->image[prandom_u32() % hole];
32530+ *image_ptr = &header[prandom_u32() % hole];
32531 return header;
32532 }
32533
32534 void bpf_jit_compile(struct sk_filter *fp)
32535 {
32536- u8 temp[64];
32537+ u8 temp[MAX_INSTR_CODE_SIZE];
32538 u8 *prog;
32539 unsigned int proglen, oldproglen = 0;
32540 int ilen, i;
32541 int t_offset, f_offset;
32542 u8 t_op, f_op, seen = 0, pass;
32543 u8 *image = NULL;
32544- struct bpf_binary_header *header = NULL;
32545+ u8 *header = NULL;
32546 u8 *func;
32547 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32548 unsigned int cleanup_addr; /* epilogue code offset */
32549 unsigned int *addrs;
32550 const struct sock_filter *filter = fp->insns;
32551 int flen = fp->len;
32552+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32553+ unsigned int randkey;
32554+#endif
32555
32556 if (!bpf_jit_enable)
32557 return;
32558@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32559 if (addrs == NULL)
32560 return;
32561
32562+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32563+ randkey = get_random_int();
32564+#endif
32565+
32566 /* Before first pass, make a rough estimation of addrs[]
32567- * each bpf instruction is translated to less than 64 bytes
32568+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32569 */
32570 for (proglen = 0, i = 0; i < flen; i++) {
32571- proglen += 64;
32572+ proglen += MAX_INSTR_CODE_SIZE;
32573 addrs[i] = proglen;
32574 }
32575 cleanup_addr = proglen; /* epilogue address */
32576@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32577 case BPF_S_ALU_MUL_K: /* A *= K */
32578 if (is_imm8(K))
32579 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32580- else {
32581- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32582- EMIT(K, 4);
32583- }
32584+ else
32585+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32586 break;
32587 case BPF_S_ALU_DIV_X: /* A /= X; */
32588 seen |= SEEN_XREG;
32589@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32590 break;
32591 case BPF_S_ALU_MOD_K: /* A %= K; */
32592 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32593+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32594+ DILUTE_CONST_SEQUENCE(K, randkey);
32595+#else
32596 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32597+#endif
32598 EMIT2(0xf7, 0xf1); /* div %ecx */
32599 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32600 break;
32601 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32602+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32603+ DILUTE_CONST_SEQUENCE(K, randkey);
32604+ // imul rax, rcx
32605+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32606+#else
32607 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32608 EMIT(K, 4);
32609+#endif
32610 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32611 break;
32612 case BPF_S_ALU_AND_X:
32613@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32614 if (is_imm8(K)) {
32615 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32616 } else {
32617- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32618- EMIT(K, 4);
32619+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32620 }
32621 } else {
32622 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32623@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32624 if (unlikely(proglen + ilen > oldproglen)) {
32625 pr_err("bpb_jit_compile fatal error\n");
32626 kfree(addrs);
32627- module_free(NULL, header);
32628+ module_free_exec(NULL, image);
32629 return;
32630 }
32631+ pax_open_kernel();
32632 memcpy(image + proglen, temp, ilen);
32633+ pax_close_kernel();
32634 }
32635 proglen += ilen;
32636 addrs[i] = proglen;
32637@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32638
32639 if (image) {
32640 bpf_flush_icache(header, image + proglen);
32641- set_memory_ro((unsigned long)header, header->pages);
32642 fp->bpf_func = (void *)image;
32643 }
32644 out:
32645@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32646 {
32647 if (fp->bpf_func != sk_run_filter) {
32648 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32649- struct bpf_binary_header *header = (void *)addr;
32650-
32651- set_memory_rw(addr, header->pages);
32652- module_free(NULL, header);
32653+ set_memory_rw(addr, 1);
32654+ module_free_exec(NULL, (void *)addr);
32655 }
32656 }
32657diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32658index d6aa6e8..266395a 100644
32659--- a/arch/x86/oprofile/backtrace.c
32660+++ b/arch/x86/oprofile/backtrace.c
32661@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32662 struct stack_frame_ia32 *fp;
32663 unsigned long bytes;
32664
32665- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32666+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32667 if (bytes != sizeof(bufhead))
32668 return NULL;
32669
32670- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32671+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32672
32673 oprofile_add_trace(bufhead[0].return_address);
32674
32675@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32676 struct stack_frame bufhead[2];
32677 unsigned long bytes;
32678
32679- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32680+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32681 if (bytes != sizeof(bufhead))
32682 return NULL;
32683
32684@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32685 {
32686 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32687
32688- if (!user_mode_vm(regs)) {
32689+ if (!user_mode(regs)) {
32690 unsigned long stack = kernel_stack_pointer(regs);
32691 if (depth)
32692 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32693diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32694index 48768df..ba9143c 100644
32695--- a/arch/x86/oprofile/nmi_int.c
32696+++ b/arch/x86/oprofile/nmi_int.c
32697@@ -23,6 +23,7 @@
32698 #include <asm/nmi.h>
32699 #include <asm/msr.h>
32700 #include <asm/apic.h>
32701+#include <asm/pgtable.h>
32702
32703 #include "op_counter.h"
32704 #include "op_x86_model.h"
32705@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32706 if (ret)
32707 return ret;
32708
32709- if (!model->num_virt_counters)
32710- model->num_virt_counters = model->num_counters;
32711+ if (!model->num_virt_counters) {
32712+ pax_open_kernel();
32713+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32714+ pax_close_kernel();
32715+ }
32716
32717 mux_init(ops);
32718
32719diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32720index b2b9443..be58856 100644
32721--- a/arch/x86/oprofile/op_model_amd.c
32722+++ b/arch/x86/oprofile/op_model_amd.c
32723@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32724 num_counters = AMD64_NUM_COUNTERS;
32725 }
32726
32727- op_amd_spec.num_counters = num_counters;
32728- op_amd_spec.num_controls = num_counters;
32729- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32730+ pax_open_kernel();
32731+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32732+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32733+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32734+ pax_close_kernel();
32735
32736 return 0;
32737 }
32738diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32739index d90528e..0127e2b 100644
32740--- a/arch/x86/oprofile/op_model_ppro.c
32741+++ b/arch/x86/oprofile/op_model_ppro.c
32742@@ -19,6 +19,7 @@
32743 #include <asm/msr.h>
32744 #include <asm/apic.h>
32745 #include <asm/nmi.h>
32746+#include <asm/pgtable.h>
32747
32748 #include "op_x86_model.h"
32749 #include "op_counter.h"
32750@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32751
32752 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32753
32754- op_arch_perfmon_spec.num_counters = num_counters;
32755- op_arch_perfmon_spec.num_controls = num_counters;
32756+ pax_open_kernel();
32757+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32758+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32759+ pax_close_kernel();
32760 }
32761
32762 static int arch_perfmon_init(struct oprofile_operations *ignore)
32763diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32764index 71e8a67..6a313bb 100644
32765--- a/arch/x86/oprofile/op_x86_model.h
32766+++ b/arch/x86/oprofile/op_x86_model.h
32767@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32768 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32769 struct op_msrs const * const msrs);
32770 #endif
32771-};
32772+} __do_const;
32773
32774 struct op_counter_config;
32775
32776diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32777index 372e9b8..e775a6c 100644
32778--- a/arch/x86/pci/irq.c
32779+++ b/arch/x86/pci/irq.c
32780@@ -50,7 +50,7 @@ struct irq_router {
32781 struct irq_router_handler {
32782 u16 vendor;
32783 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32784-};
32785+} __do_const;
32786
32787 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32788 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32789@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32790 return 0;
32791 }
32792
32793-static __initdata struct irq_router_handler pirq_routers[] = {
32794+static __initconst const struct irq_router_handler pirq_routers[] = {
32795 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32796 { PCI_VENDOR_ID_AL, ali_router_probe },
32797 { PCI_VENDOR_ID_ITE, ite_router_probe },
32798@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32799 static void __init pirq_find_router(struct irq_router *r)
32800 {
32801 struct irq_routing_table *rt = pirq_table;
32802- struct irq_router_handler *h;
32803+ const struct irq_router_handler *h;
32804
32805 #ifdef CONFIG_PCI_BIOS
32806 if (!rt->signature) {
32807@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32808 return 0;
32809 }
32810
32811-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32812+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32813 {
32814 .callback = fix_broken_hp_bios_irq9,
32815 .ident = "HP Pavilion N5400 Series Laptop",
32816diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32817index 6eb18c4..20d83de 100644
32818--- a/arch/x86/pci/mrst.c
32819+++ b/arch/x86/pci/mrst.c
32820@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32821 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32822 pci_mmcfg_late_init();
32823 pcibios_enable_irq = mrst_pci_irq_enable;
32824- pci_root_ops = pci_mrst_ops;
32825+ pax_open_kernel();
32826+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32827+ pax_close_kernel();
32828 pci_soc_mode = 1;
32829 /* Continue with standard init */
32830 return 1;
32831diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32832index c77b24a..c979855 100644
32833--- a/arch/x86/pci/pcbios.c
32834+++ b/arch/x86/pci/pcbios.c
32835@@ -79,7 +79,7 @@ union bios32 {
32836 static struct {
32837 unsigned long address;
32838 unsigned short segment;
32839-} bios32_indirect = { 0, __KERNEL_CS };
32840+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32841
32842 /*
32843 * Returns the entry point for the given service, NULL on error
32844@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32845 unsigned long length; /* %ecx */
32846 unsigned long entry; /* %edx */
32847 unsigned long flags;
32848+ struct desc_struct d, *gdt;
32849
32850 local_irq_save(flags);
32851- __asm__("lcall *(%%edi); cld"
32852+
32853+ gdt = get_cpu_gdt_table(smp_processor_id());
32854+
32855+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32856+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32857+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32858+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32859+
32860+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32861 : "=a" (return_code),
32862 "=b" (address),
32863 "=c" (length),
32864 "=d" (entry)
32865 : "0" (service),
32866 "1" (0),
32867- "D" (&bios32_indirect));
32868+ "D" (&bios32_indirect),
32869+ "r"(__PCIBIOS_DS)
32870+ : "memory");
32871+
32872+ pax_open_kernel();
32873+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32874+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32875+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32876+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32877+ pax_close_kernel();
32878+
32879 local_irq_restore(flags);
32880
32881 switch (return_code) {
32882- case 0:
32883- return address + entry;
32884- case 0x80: /* Not present */
32885- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32886- return 0;
32887- default: /* Shouldn't happen */
32888- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32889- service, return_code);
32890+ case 0: {
32891+ int cpu;
32892+ unsigned char flags;
32893+
32894+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32895+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32896+ printk(KERN_WARNING "bios32_service: not valid\n");
32897 return 0;
32898+ }
32899+ address = address + PAGE_OFFSET;
32900+ length += 16UL; /* some BIOSs underreport this... */
32901+ flags = 4;
32902+ if (length >= 64*1024*1024) {
32903+ length >>= PAGE_SHIFT;
32904+ flags |= 8;
32905+ }
32906+
32907+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32908+ gdt = get_cpu_gdt_table(cpu);
32909+ pack_descriptor(&d, address, length, 0x9b, flags);
32910+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32911+ pack_descriptor(&d, address, length, 0x93, flags);
32912+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32913+ }
32914+ return entry;
32915+ }
32916+ case 0x80: /* Not present */
32917+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32918+ return 0;
32919+ default: /* Shouldn't happen */
32920+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32921+ service, return_code);
32922+ return 0;
32923 }
32924 }
32925
32926 static struct {
32927 unsigned long address;
32928 unsigned short segment;
32929-} pci_indirect = { 0, __KERNEL_CS };
32930+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32931
32932-static int pci_bios_present;
32933+static int pci_bios_present __read_only;
32934
32935 static int check_pcibios(void)
32936 {
32937@@ -131,11 +174,13 @@ static int check_pcibios(void)
32938 unsigned long flags, pcibios_entry;
32939
32940 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32941- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32942+ pci_indirect.address = pcibios_entry;
32943
32944 local_irq_save(flags);
32945- __asm__(
32946- "lcall *(%%edi); cld\n\t"
32947+ __asm__("movw %w6, %%ds\n\t"
32948+ "lcall *%%ss:(%%edi); cld\n\t"
32949+ "push %%ss\n\t"
32950+ "pop %%ds\n\t"
32951 "jc 1f\n\t"
32952 "xor %%ah, %%ah\n"
32953 "1:"
32954@@ -144,7 +189,8 @@ static int check_pcibios(void)
32955 "=b" (ebx),
32956 "=c" (ecx)
32957 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32958- "D" (&pci_indirect)
32959+ "D" (&pci_indirect),
32960+ "r" (__PCIBIOS_DS)
32961 : "memory");
32962 local_irq_restore(flags);
32963
32964@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32965
32966 switch (len) {
32967 case 1:
32968- __asm__("lcall *(%%esi); cld\n\t"
32969+ __asm__("movw %w6, %%ds\n\t"
32970+ "lcall *%%ss:(%%esi); cld\n\t"
32971+ "push %%ss\n\t"
32972+ "pop %%ds\n\t"
32973 "jc 1f\n\t"
32974 "xor %%ah, %%ah\n"
32975 "1:"
32976@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32977 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32978 "b" (bx),
32979 "D" ((long)reg),
32980- "S" (&pci_indirect));
32981+ "S" (&pci_indirect),
32982+ "r" (__PCIBIOS_DS));
32983 /*
32984 * Zero-extend the result beyond 8 bits, do not trust the
32985 * BIOS having done it:
32986@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32987 *value &= 0xff;
32988 break;
32989 case 2:
32990- __asm__("lcall *(%%esi); cld\n\t"
32991+ __asm__("movw %w6, %%ds\n\t"
32992+ "lcall *%%ss:(%%esi); cld\n\t"
32993+ "push %%ss\n\t"
32994+ "pop %%ds\n\t"
32995 "jc 1f\n\t"
32996 "xor %%ah, %%ah\n"
32997 "1:"
32998@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32999 : "1" (PCIBIOS_READ_CONFIG_WORD),
33000 "b" (bx),
33001 "D" ((long)reg),
33002- "S" (&pci_indirect));
33003+ "S" (&pci_indirect),
33004+ "r" (__PCIBIOS_DS));
33005 /*
33006 * Zero-extend the result beyond 16 bits, do not trust the
33007 * BIOS having done it:
33008@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33009 *value &= 0xffff;
33010 break;
33011 case 4:
33012- __asm__("lcall *(%%esi); cld\n\t"
33013+ __asm__("movw %w6, %%ds\n\t"
33014+ "lcall *%%ss:(%%esi); cld\n\t"
33015+ "push %%ss\n\t"
33016+ "pop %%ds\n\t"
33017 "jc 1f\n\t"
33018 "xor %%ah, %%ah\n"
33019 "1:"
33020@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33021 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33022 "b" (bx),
33023 "D" ((long)reg),
33024- "S" (&pci_indirect));
33025+ "S" (&pci_indirect),
33026+ "r" (__PCIBIOS_DS));
33027 break;
33028 }
33029
33030@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33031
33032 switch (len) {
33033 case 1:
33034- __asm__("lcall *(%%esi); cld\n\t"
33035+ __asm__("movw %w6, %%ds\n\t"
33036+ "lcall *%%ss:(%%esi); cld\n\t"
33037+ "push %%ss\n\t"
33038+ "pop %%ds\n\t"
33039 "jc 1f\n\t"
33040 "xor %%ah, %%ah\n"
33041 "1:"
33042@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33043 "c" (value),
33044 "b" (bx),
33045 "D" ((long)reg),
33046- "S" (&pci_indirect));
33047+ "S" (&pci_indirect),
33048+ "r" (__PCIBIOS_DS));
33049 break;
33050 case 2:
33051- __asm__("lcall *(%%esi); cld\n\t"
33052+ __asm__("movw %w6, %%ds\n\t"
33053+ "lcall *%%ss:(%%esi); cld\n\t"
33054+ "push %%ss\n\t"
33055+ "pop %%ds\n\t"
33056 "jc 1f\n\t"
33057 "xor %%ah, %%ah\n"
33058 "1:"
33059@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33060 "c" (value),
33061 "b" (bx),
33062 "D" ((long)reg),
33063- "S" (&pci_indirect));
33064+ "S" (&pci_indirect),
33065+ "r" (__PCIBIOS_DS));
33066 break;
33067 case 4:
33068- __asm__("lcall *(%%esi); cld\n\t"
33069+ __asm__("movw %w6, %%ds\n\t"
33070+ "lcall *%%ss:(%%esi); cld\n\t"
33071+ "push %%ss\n\t"
33072+ "pop %%ds\n\t"
33073 "jc 1f\n\t"
33074 "xor %%ah, %%ah\n"
33075 "1:"
33076@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33077 "c" (value),
33078 "b" (bx),
33079 "D" ((long)reg),
33080- "S" (&pci_indirect));
33081+ "S" (&pci_indirect),
33082+ "r" (__PCIBIOS_DS));
33083 break;
33084 }
33085
33086@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33087
33088 DBG("PCI: Fetching IRQ routing table... ");
33089 __asm__("push %%es\n\t"
33090+ "movw %w8, %%ds\n\t"
33091 "push %%ds\n\t"
33092 "pop %%es\n\t"
33093- "lcall *(%%esi); cld\n\t"
33094+ "lcall *%%ss:(%%esi); cld\n\t"
33095 "pop %%es\n\t"
33096+ "push %%ss\n\t"
33097+ "pop %%ds\n"
33098 "jc 1f\n\t"
33099 "xor %%ah, %%ah\n"
33100 "1:"
33101@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33102 "1" (0),
33103 "D" ((long) &opt),
33104 "S" (&pci_indirect),
33105- "m" (opt)
33106+ "m" (opt),
33107+ "r" (__PCIBIOS_DS)
33108 : "memory");
33109 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33110 if (ret & 0xff00)
33111@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33112 {
33113 int ret;
33114
33115- __asm__("lcall *(%%esi); cld\n\t"
33116+ __asm__("movw %w5, %%ds\n\t"
33117+ "lcall *%%ss:(%%esi); cld\n\t"
33118+ "push %%ss\n\t"
33119+ "pop %%ds\n"
33120 "jc 1f\n\t"
33121 "xor %%ah, %%ah\n"
33122 "1:"
33123@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33124 : "0" (PCIBIOS_SET_PCI_HW_INT),
33125 "b" ((dev->bus->number << 8) | dev->devfn),
33126 "c" ((irq << 8) | (pin + 10)),
33127- "S" (&pci_indirect));
33128+ "S" (&pci_indirect),
33129+ "r" (__PCIBIOS_DS));
33130 return !(ret & 0xff00);
33131 }
33132 EXPORT_SYMBOL(pcibios_set_irq_routing);
33133diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33134index 40e4469..d915bf9 100644
33135--- a/arch/x86/platform/efi/efi_32.c
33136+++ b/arch/x86/platform/efi/efi_32.c
33137@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33138 {
33139 struct desc_ptr gdt_descr;
33140
33141+#ifdef CONFIG_PAX_KERNEXEC
33142+ struct desc_struct d;
33143+#endif
33144+
33145 local_irq_save(efi_rt_eflags);
33146
33147 load_cr3(initial_page_table);
33148 __flush_tlb_all();
33149
33150+#ifdef CONFIG_PAX_KERNEXEC
33151+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33152+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33153+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33154+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33155+#endif
33156+
33157 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33158 gdt_descr.size = GDT_SIZE - 1;
33159 load_gdt(&gdt_descr);
33160@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33161 {
33162 struct desc_ptr gdt_descr;
33163
33164+#ifdef CONFIG_PAX_KERNEXEC
33165+ struct desc_struct d;
33166+
33167+ memset(&d, 0, sizeof d);
33168+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33169+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33170+#endif
33171+
33172 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33173 gdt_descr.size = GDT_SIZE - 1;
33174 load_gdt(&gdt_descr);
33175
33176+#ifdef CONFIG_PAX_PER_CPU_PGD
33177+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33178+#else
33179 load_cr3(swapper_pg_dir);
33180+#endif
33181+
33182 __flush_tlb_all();
33183
33184 local_irq_restore(efi_rt_eflags);
33185diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33186index 39a0e7f1..872396e 100644
33187--- a/arch/x86/platform/efi/efi_64.c
33188+++ b/arch/x86/platform/efi/efi_64.c
33189@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33190 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33191 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33192 }
33193+
33194+#ifdef CONFIG_PAX_PER_CPU_PGD
33195+ load_cr3(swapper_pg_dir);
33196+#endif
33197+
33198 __flush_tlb_all();
33199 }
33200
33201@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33202 for (pgd = 0; pgd < n_pgds; pgd++)
33203 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33204 kfree(save_pgd);
33205+
33206+#ifdef CONFIG_PAX_PER_CPU_PGD
33207+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33208+#endif
33209+
33210 __flush_tlb_all();
33211 local_irq_restore(efi_flags);
33212 early_code_mapping_set_exec(0);
33213diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33214index fbe66e6..eae5e38 100644
33215--- a/arch/x86/platform/efi/efi_stub_32.S
33216+++ b/arch/x86/platform/efi/efi_stub_32.S
33217@@ -6,7 +6,9 @@
33218 */
33219
33220 #include <linux/linkage.h>
33221+#include <linux/init.h>
33222 #include <asm/page_types.h>
33223+#include <asm/segment.h>
33224
33225 /*
33226 * efi_call_phys(void *, ...) is a function with variable parameters.
33227@@ -20,7 +22,7 @@
33228 * service functions will comply with gcc calling convention, too.
33229 */
33230
33231-.text
33232+__INIT
33233 ENTRY(efi_call_phys)
33234 /*
33235 * 0. The function can only be called in Linux kernel. So CS has been
33236@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33237 * The mapping of lower virtual memory has been created in prelog and
33238 * epilog.
33239 */
33240- movl $1f, %edx
33241- subl $__PAGE_OFFSET, %edx
33242- jmp *%edx
33243+#ifdef CONFIG_PAX_KERNEXEC
33244+ movl $(__KERNEXEC_EFI_DS), %edx
33245+ mov %edx, %ds
33246+ mov %edx, %es
33247+ mov %edx, %ss
33248+ addl $2f,(1f)
33249+ ljmp *(1f)
33250+
33251+__INITDATA
33252+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33253+.previous
33254+
33255+2:
33256+ subl $2b,(1b)
33257+#else
33258+ jmp 1f-__PAGE_OFFSET
33259 1:
33260+#endif
33261
33262 /*
33263 * 2. Now on the top of stack is the return
33264@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33265 * parameter 2, ..., param n. To make things easy, we save the return
33266 * address of efi_call_phys in a global variable.
33267 */
33268- popl %edx
33269- movl %edx, saved_return_addr
33270- /* get the function pointer into ECX*/
33271- popl %ecx
33272- movl %ecx, efi_rt_function_ptr
33273- movl $2f, %edx
33274- subl $__PAGE_OFFSET, %edx
33275- pushl %edx
33276+ popl (saved_return_addr)
33277+ popl (efi_rt_function_ptr)
33278
33279 /*
33280 * 3. Clear PG bit in %CR0.
33281@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33282 /*
33283 * 5. Call the physical function.
33284 */
33285- jmp *%ecx
33286+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33287
33288-2:
33289 /*
33290 * 6. After EFI runtime service returns, control will return to
33291 * following instruction. We'd better readjust stack pointer first.
33292@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33293 movl %cr0, %edx
33294 orl $0x80000000, %edx
33295 movl %edx, %cr0
33296- jmp 1f
33297-1:
33298+
33299 /*
33300 * 8. Now restore the virtual mode from flat mode by
33301 * adding EIP with PAGE_OFFSET.
33302 */
33303- movl $1f, %edx
33304- jmp *%edx
33305+#ifdef CONFIG_PAX_KERNEXEC
33306+ movl $(__KERNEL_DS), %edx
33307+ mov %edx, %ds
33308+ mov %edx, %es
33309+ mov %edx, %ss
33310+ ljmp $(__KERNEL_CS),$1f
33311+#else
33312+ jmp 1f+__PAGE_OFFSET
33313+#endif
33314 1:
33315
33316 /*
33317 * 9. Balance the stack. And because EAX contain the return value,
33318 * we'd better not clobber it.
33319 */
33320- leal efi_rt_function_ptr, %edx
33321- movl (%edx), %ecx
33322- pushl %ecx
33323+ pushl (efi_rt_function_ptr)
33324
33325 /*
33326- * 10. Push the saved return address onto the stack and return.
33327+ * 10. Return to the saved return address.
33328 */
33329- leal saved_return_addr, %edx
33330- movl (%edx), %ecx
33331- pushl %ecx
33332- ret
33333+ jmpl *(saved_return_addr)
33334 ENDPROC(efi_call_phys)
33335 .previous
33336
33337-.data
33338+__INITDATA
33339 saved_return_addr:
33340 .long 0
33341 efi_rt_function_ptr:
33342diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33343index 4c07cca..2c8427d 100644
33344--- a/arch/x86/platform/efi/efi_stub_64.S
33345+++ b/arch/x86/platform/efi/efi_stub_64.S
33346@@ -7,6 +7,7 @@
33347 */
33348
33349 #include <linux/linkage.h>
33350+#include <asm/alternative-asm.h>
33351
33352 #define SAVE_XMM \
33353 mov %rsp, %rax; \
33354@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33355 call *%rdi
33356 addq $32, %rsp
33357 RESTORE_XMM
33358+ pax_force_retaddr 0, 1
33359 ret
33360 ENDPROC(efi_call0)
33361
33362@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33363 call *%rdi
33364 addq $32, %rsp
33365 RESTORE_XMM
33366+ pax_force_retaddr 0, 1
33367 ret
33368 ENDPROC(efi_call1)
33369
33370@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33371 call *%rdi
33372 addq $32, %rsp
33373 RESTORE_XMM
33374+ pax_force_retaddr 0, 1
33375 ret
33376 ENDPROC(efi_call2)
33377
33378@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33379 call *%rdi
33380 addq $32, %rsp
33381 RESTORE_XMM
33382+ pax_force_retaddr 0, 1
33383 ret
33384 ENDPROC(efi_call3)
33385
33386@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33387 call *%rdi
33388 addq $32, %rsp
33389 RESTORE_XMM
33390+ pax_force_retaddr 0, 1
33391 ret
33392 ENDPROC(efi_call4)
33393
33394@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33395 call *%rdi
33396 addq $48, %rsp
33397 RESTORE_XMM
33398+ pax_force_retaddr 0, 1
33399 ret
33400 ENDPROC(efi_call5)
33401
33402@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33403 call *%rdi
33404 addq $48, %rsp
33405 RESTORE_XMM
33406+ pax_force_retaddr 0, 1
33407 ret
33408 ENDPROC(efi_call6)
33409diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33410index 47fe66f..6206449 100644
33411--- a/arch/x86/platform/mrst/mrst.c
33412+++ b/arch/x86/platform/mrst/mrst.c
33413@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33414 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33415 int sfi_mrtc_num;
33416
33417-static void mrst_power_off(void)
33418+static __noreturn void mrst_power_off(void)
33419 {
33420+ BUG();
33421 }
33422
33423-static void mrst_reboot(void)
33424+static __noreturn void mrst_reboot(void)
33425 {
33426 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33427+ BUG();
33428 }
33429
33430 /* parse all the mtimer info to a static mtimer array */
33431diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33432index d6ee929..3637cb5 100644
33433--- a/arch/x86/platform/olpc/olpc_dt.c
33434+++ b/arch/x86/platform/olpc/olpc_dt.c
33435@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33436 return res;
33437 }
33438
33439-static struct of_pdt_ops prom_olpc_ops __initdata = {
33440+static struct of_pdt_ops prom_olpc_ops __initconst = {
33441 .nextprop = olpc_dt_nextprop,
33442 .getproplen = olpc_dt_getproplen,
33443 .getproperty = olpc_dt_getproperty,
33444diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33445index 1cf5b30..fd45732 100644
33446--- a/arch/x86/power/cpu.c
33447+++ b/arch/x86/power/cpu.c
33448@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33449 static void fix_processor_context(void)
33450 {
33451 int cpu = smp_processor_id();
33452- struct tss_struct *t = &per_cpu(init_tss, cpu);
33453-#ifdef CONFIG_X86_64
33454- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33455- tss_desc tss;
33456-#endif
33457+ struct tss_struct *t = init_tss + cpu;
33458+
33459 set_tss_desc(cpu, t); /*
33460 * This just modifies memory; should not be
33461 * necessary. But... This is necessary, because
33462@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33463 */
33464
33465 #ifdef CONFIG_X86_64
33466- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33467- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33468- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33469-
33470 syscall_init(); /* This sets MSR_*STAR and related */
33471 #endif
33472 load_TR_desc(); /* This does ltr */
33473diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33474index a44f457..9140171 100644
33475--- a/arch/x86/realmode/init.c
33476+++ b/arch/x86/realmode/init.c
33477@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33478 __va(real_mode_header->trampoline_header);
33479
33480 #ifdef CONFIG_X86_32
33481- trampoline_header->start = __pa_symbol(startup_32_smp);
33482+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33483+
33484+#ifdef CONFIG_PAX_KERNEXEC
33485+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33486+#endif
33487+
33488+ trampoline_header->boot_cs = __BOOT_CS;
33489 trampoline_header->gdt_limit = __BOOT_DS + 7;
33490 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33491 #else
33492@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33493 *trampoline_cr4_features = read_cr4();
33494
33495 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33496- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33497+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33498 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33499 #endif
33500 }
33501diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33502index 8869287..d577672 100644
33503--- a/arch/x86/realmode/rm/Makefile
33504+++ b/arch/x86/realmode/rm/Makefile
33505@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33506 $(call cc-option, -fno-unit-at-a-time)) \
33507 $(call cc-option, -fno-stack-protector) \
33508 $(call cc-option, -mpreferred-stack-boundary=2)
33509+ifdef CONSTIFY_PLUGIN
33510+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33511+endif
33512 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33513 GCOV_PROFILE := n
33514diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33515index a28221d..93c40f1 100644
33516--- a/arch/x86/realmode/rm/header.S
33517+++ b/arch/x86/realmode/rm/header.S
33518@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33519 #endif
33520 /* APM/BIOS reboot */
33521 .long pa_machine_real_restart_asm
33522-#ifdef CONFIG_X86_64
33523+#ifdef CONFIG_X86_32
33524+ .long __KERNEL_CS
33525+#else
33526 .long __KERNEL32_CS
33527 #endif
33528 END(real_mode_header)
33529diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33530index c1b2791..f9e31c7 100644
33531--- a/arch/x86/realmode/rm/trampoline_32.S
33532+++ b/arch/x86/realmode/rm/trampoline_32.S
33533@@ -25,6 +25,12 @@
33534 #include <asm/page_types.h>
33535 #include "realmode.h"
33536
33537+#ifdef CONFIG_PAX_KERNEXEC
33538+#define ta(X) (X)
33539+#else
33540+#define ta(X) (pa_ ## X)
33541+#endif
33542+
33543 .text
33544 .code16
33545
33546@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33547
33548 cli # We should be safe anyway
33549
33550- movl tr_start, %eax # where we need to go
33551-
33552 movl $0xA5A5A5A5, trampoline_status
33553 # write marker for master knows we're running
33554
33555@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33556 movw $1, %dx # protected mode (PE) bit
33557 lmsw %dx # into protected mode
33558
33559- ljmpl $__BOOT_CS, $pa_startup_32
33560+ ljmpl *(trampoline_header)
33561
33562 .section ".text32","ax"
33563 .code32
33564@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33565 .balign 8
33566 GLOBAL(trampoline_header)
33567 tr_start: .space 4
33568- tr_gdt_pad: .space 2
33569+ tr_boot_cs: .space 2
33570 tr_gdt: .space 6
33571 END(trampoline_header)
33572
33573diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33574index bb360dc..d0fd8f8 100644
33575--- a/arch/x86/realmode/rm/trampoline_64.S
33576+++ b/arch/x86/realmode/rm/trampoline_64.S
33577@@ -94,6 +94,7 @@ ENTRY(startup_32)
33578 movl %edx, %gs
33579
33580 movl pa_tr_cr4, %eax
33581+ andl $~X86_CR4_PCIDE, %eax
33582 movl %eax, %cr4 # Enable PAE mode
33583
33584 # Setup trampoline 4 level pagetables
33585@@ -107,7 +108,7 @@ ENTRY(startup_32)
33586 wrmsr
33587
33588 # Enable paging and in turn activate Long Mode
33589- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33590+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33591 movl %eax, %cr0
33592
33593 /*
33594diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33595index e812034..c747134 100644
33596--- a/arch/x86/tools/Makefile
33597+++ b/arch/x86/tools/Makefile
33598@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33599
33600 $(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
33601
33602-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33603+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33604 hostprogs-y += relocs
33605 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33606 relocs: $(obj)/relocs
33607diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33608index f7bab68..b6d9886 100644
33609--- a/arch/x86/tools/relocs.c
33610+++ b/arch/x86/tools/relocs.c
33611@@ -1,5 +1,7 @@
33612 /* This is included from relocs_32/64.c */
33613
33614+#include "../../../include/generated/autoconf.h"
33615+
33616 #define ElfW(type) _ElfW(ELF_BITS, type)
33617 #define _ElfW(bits, type) __ElfW(bits, type)
33618 #define __ElfW(bits, type) Elf##bits##_##type
33619@@ -11,6 +13,7 @@
33620 #define Elf_Sym ElfW(Sym)
33621
33622 static Elf_Ehdr ehdr;
33623+static Elf_Phdr *phdr;
33624
33625 struct relocs {
33626 uint32_t *offset;
33627@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33628 }
33629 }
33630
33631+static void read_phdrs(FILE *fp)
33632+{
33633+ unsigned int i;
33634+
33635+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33636+ if (!phdr) {
33637+ die("Unable to allocate %d program headers\n",
33638+ ehdr.e_phnum);
33639+ }
33640+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33641+ die("Seek to %d failed: %s\n",
33642+ ehdr.e_phoff, strerror(errno));
33643+ }
33644+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33645+ die("Cannot read ELF program headers: %s\n",
33646+ strerror(errno));
33647+ }
33648+ for(i = 0; i < ehdr.e_phnum; i++) {
33649+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33650+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33651+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33652+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33653+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33654+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33655+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33656+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33657+ }
33658+
33659+}
33660+
33661 static void read_shdrs(FILE *fp)
33662 {
33663- int i;
33664+ unsigned int i;
33665 Elf_Shdr shdr;
33666
33667 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33668@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33669
33670 static void read_strtabs(FILE *fp)
33671 {
33672- int i;
33673+ unsigned int i;
33674 for (i = 0; i < ehdr.e_shnum; i++) {
33675 struct section *sec = &secs[i];
33676 if (sec->shdr.sh_type != SHT_STRTAB) {
33677@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33678
33679 static void read_symtabs(FILE *fp)
33680 {
33681- int i,j;
33682+ unsigned int i,j;
33683 for (i = 0; i < ehdr.e_shnum; i++) {
33684 struct section *sec = &secs[i];
33685 if (sec->shdr.sh_type != SHT_SYMTAB) {
33686@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33687 }
33688
33689
33690-static void read_relocs(FILE *fp)
33691+static void read_relocs(FILE *fp, int use_real_mode)
33692 {
33693- int i,j;
33694+ unsigned int i,j;
33695+ uint32_t base;
33696+
33697 for (i = 0; i < ehdr.e_shnum; i++) {
33698 struct section *sec = &secs[i];
33699 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33700@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33701 die("Cannot read symbol table: %s\n",
33702 strerror(errno));
33703 }
33704+ base = 0;
33705+
33706+#ifdef CONFIG_X86_32
33707+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33708+ if (phdr[j].p_type != PT_LOAD )
33709+ continue;
33710+ 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)
33711+ continue;
33712+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33713+ break;
33714+ }
33715+#endif
33716+
33717 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33718 Elf_Rel *rel = &sec->reltab[j];
33719- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33720+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33721 rel->r_info = elf_xword_to_cpu(rel->r_info);
33722 #if (SHT_REL_TYPE == SHT_RELA)
33723 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33724@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33725
33726 static void print_absolute_symbols(void)
33727 {
33728- int i;
33729+ unsigned int i;
33730 const char *format;
33731
33732 if (ELF_BITS == 64)
33733@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33734 for (i = 0; i < ehdr.e_shnum; i++) {
33735 struct section *sec = &secs[i];
33736 char *sym_strtab;
33737- int j;
33738+ unsigned int j;
33739
33740 if (sec->shdr.sh_type != SHT_SYMTAB) {
33741 continue;
33742@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33743
33744 static void print_absolute_relocs(void)
33745 {
33746- int i, printed = 0;
33747+ unsigned int i, printed = 0;
33748 const char *format;
33749
33750 if (ELF_BITS == 64)
33751@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33752 struct section *sec_applies, *sec_symtab;
33753 char *sym_strtab;
33754 Elf_Sym *sh_symtab;
33755- int j;
33756+ unsigned int j;
33757 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33758 continue;
33759 }
33760@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33761 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33762 Elf_Sym *sym, const char *symname))
33763 {
33764- int i;
33765+ unsigned int i;
33766 /* Walk through the relocations */
33767 for (i = 0; i < ehdr.e_shnum; i++) {
33768 char *sym_strtab;
33769 Elf_Sym *sh_symtab;
33770 struct section *sec_applies, *sec_symtab;
33771- int j;
33772+ unsigned int j;
33773 struct section *sec = &secs[i];
33774
33775 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33776@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33777 {
33778 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33779 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33780+ char *sym_strtab = sec->link->link->strtab;
33781+
33782+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33783+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33784+ return 0;
33785+
33786+#ifdef CONFIG_PAX_KERNEXEC
33787+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33788+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33789+ return 0;
33790+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33791+ return 0;
33792+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33793+ return 0;
33794+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33795+ return 0;
33796+#endif
33797
33798 switch (r_type) {
33799 case R_386_NONE:
33800@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33801
33802 static void emit_relocs(int as_text, int use_real_mode)
33803 {
33804- int i;
33805+ unsigned int i;
33806 int (*write_reloc)(uint32_t, FILE *) = write32;
33807 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33808 const char *symname);
33809@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33810 {
33811 regex_init(use_real_mode);
33812 read_ehdr(fp);
33813+ read_phdrs(fp);
33814 read_shdrs(fp);
33815 read_strtabs(fp);
33816 read_symtabs(fp);
33817- read_relocs(fp);
33818+ read_relocs(fp, use_real_mode);
33819 if (ELF_BITS == 64)
33820 percpu_init();
33821 if (show_absolute_syms) {
33822diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33823index 80ffa5b..a33bd15 100644
33824--- a/arch/x86/um/tls_32.c
33825+++ b/arch/x86/um/tls_32.c
33826@@ -260,7 +260,7 @@ out:
33827 if (unlikely(task == current &&
33828 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33829 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33830- "without flushed TLS.", current->pid);
33831+ "without flushed TLS.", task_pid_nr(current));
33832 }
33833
33834 return 0;
33835diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33836index fd14be1..e3c79c0 100644
33837--- a/arch/x86/vdso/Makefile
33838+++ b/arch/x86/vdso/Makefile
33839@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33840 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33841 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33842
33843-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33844+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33845 GCOV_PROFILE := n
33846
33847 #
33848diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33849index d6bfb87..876ee18 100644
33850--- a/arch/x86/vdso/vdso32-setup.c
33851+++ b/arch/x86/vdso/vdso32-setup.c
33852@@ -25,6 +25,7 @@
33853 #include <asm/tlbflush.h>
33854 #include <asm/vdso.h>
33855 #include <asm/proto.h>
33856+#include <asm/mman.h>
33857
33858 enum {
33859 VDSO_DISABLED = 0,
33860@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33861 void enable_sep_cpu(void)
33862 {
33863 int cpu = get_cpu();
33864- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33865+ struct tss_struct *tss = init_tss + cpu;
33866
33867 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33868 put_cpu();
33869@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33870 gate_vma.vm_start = FIXADDR_USER_START;
33871 gate_vma.vm_end = FIXADDR_USER_END;
33872 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33873- gate_vma.vm_page_prot = __P101;
33874+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33875
33876 return 0;
33877 }
33878@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33879 if (compat)
33880 addr = VDSO_HIGH_BASE;
33881 else {
33882- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33883+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33884 if (IS_ERR_VALUE(addr)) {
33885 ret = addr;
33886 goto up_fail;
33887 }
33888 }
33889
33890- current->mm->context.vdso = (void *)addr;
33891+ current->mm->context.vdso = addr;
33892
33893 if (compat_uses_vma || !compat) {
33894 /*
33895@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33896 }
33897
33898 current_thread_info()->sysenter_return =
33899- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33900+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33901
33902 up_fail:
33903 if (ret)
33904- current->mm->context.vdso = NULL;
33905+ current->mm->context.vdso = 0;
33906
33907 up_write(&mm->mmap_sem);
33908
33909@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33910
33911 const char *arch_vma_name(struct vm_area_struct *vma)
33912 {
33913- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33914+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33915 return "[vdso]";
33916+
33917+#ifdef CONFIG_PAX_SEGMEXEC
33918+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33919+ return "[vdso]";
33920+#endif
33921+
33922 return NULL;
33923 }
33924
33925@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33926 * Check to see if the corresponding task was created in compat vdso
33927 * mode.
33928 */
33929- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33930+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33931 return &gate_vma;
33932 return NULL;
33933 }
33934diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33935index 431e875..cbb23f3 100644
33936--- a/arch/x86/vdso/vma.c
33937+++ b/arch/x86/vdso/vma.c
33938@@ -16,8 +16,6 @@
33939 #include <asm/vdso.h>
33940 #include <asm/page.h>
33941
33942-unsigned int __read_mostly vdso_enabled = 1;
33943-
33944 extern char vdso_start[], vdso_end[];
33945 extern unsigned short vdso_sync_cpuid;
33946
33947@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33948 * unaligned here as a result of stack start randomization.
33949 */
33950 addr = PAGE_ALIGN(addr);
33951- addr = align_vdso_addr(addr);
33952
33953 return addr;
33954 }
33955@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33956 unsigned size)
33957 {
33958 struct mm_struct *mm = current->mm;
33959- unsigned long addr;
33960+ unsigned long addr = 0;
33961 int ret;
33962
33963- if (!vdso_enabled)
33964- return 0;
33965-
33966 down_write(&mm->mmap_sem);
33967+
33968+#ifdef CONFIG_PAX_RANDMMAP
33969+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33970+#endif
33971+
33972 addr = vdso_addr(mm->start_stack, size);
33973+ addr = align_vdso_addr(addr);
33974 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33975 if (IS_ERR_VALUE(addr)) {
33976 ret = addr;
33977 goto up_fail;
33978 }
33979
33980- current->mm->context.vdso = (void *)addr;
33981+ mm->context.vdso = addr;
33982
33983 ret = install_special_mapping(mm, addr, size,
33984 VM_READ|VM_EXEC|
33985 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33986 pages);
33987- if (ret) {
33988- current->mm->context.vdso = NULL;
33989- goto up_fail;
33990- }
33991+ if (ret)
33992+ mm->context.vdso = 0;
33993
33994 up_fail:
33995 up_write(&mm->mmap_sem);
33996@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33997 vdsox32_size);
33998 }
33999 #endif
34000-
34001-static __init int vdso_setup(char *s)
34002-{
34003- vdso_enabled = simple_strtoul(s, NULL, 0);
34004- return 0;
34005-}
34006-__setup("vdso=", vdso_setup);
34007diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34008index 193097e..7590269 100644
34009--- a/arch/x86/xen/enlighten.c
34010+++ b/arch/x86/xen/enlighten.c
34011@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34012
34013 struct shared_info xen_dummy_shared_info;
34014
34015-void *xen_initial_gdt;
34016-
34017 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34018 __read_mostly int xen_have_vector_callback;
34019 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34020@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34021 {
34022 unsigned long va = dtr->address;
34023 unsigned int size = dtr->size + 1;
34024- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34025- unsigned long frames[pages];
34026+ unsigned long frames[65536 / PAGE_SIZE];
34027 int f;
34028
34029 /*
34030@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34031 {
34032 unsigned long va = dtr->address;
34033 unsigned int size = dtr->size + 1;
34034- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34035- unsigned long frames[pages];
34036+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34037 int f;
34038
34039 /*
34040@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34041 * 8-byte entries, or 16 4k pages..
34042 */
34043
34044- BUG_ON(size > 65536);
34045+ BUG_ON(size > GDT_SIZE);
34046 BUG_ON(va & ~PAGE_MASK);
34047
34048 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34049@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34050 return 0;
34051 }
34052
34053-static void set_xen_basic_apic_ops(void)
34054+static void __init set_xen_basic_apic_ops(void)
34055 {
34056 apic->read = xen_apic_read;
34057 apic->write = xen_apic_write;
34058@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34059 #endif
34060 };
34061
34062-static void xen_reboot(int reason)
34063+static __noreturn void xen_reboot(int reason)
34064 {
34065 struct sched_shutdown r = { .reason = reason };
34066
34067- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34068- BUG();
34069+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34070+ BUG();
34071 }
34072
34073-static void xen_restart(char *msg)
34074+static __noreturn void xen_restart(char *msg)
34075 {
34076 xen_reboot(SHUTDOWN_reboot);
34077 }
34078
34079-static void xen_emergency_restart(void)
34080+static __noreturn void xen_emergency_restart(void)
34081 {
34082 xen_reboot(SHUTDOWN_reboot);
34083 }
34084
34085-static void xen_machine_halt(void)
34086+static __noreturn void xen_machine_halt(void)
34087 {
34088 xen_reboot(SHUTDOWN_poweroff);
34089 }
34090
34091-static void xen_machine_power_off(void)
34092+static __noreturn void xen_machine_power_off(void)
34093 {
34094 if (pm_power_off)
34095 pm_power_off();
34096@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34097 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34098
34099 /* Work out if we support NX */
34100- x86_configure_nx();
34101+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34102+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34103+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34104+ unsigned l, h;
34105+
34106+ __supported_pte_mask |= _PAGE_NX;
34107+ rdmsr(MSR_EFER, l, h);
34108+ l |= EFER_NX;
34109+ wrmsr(MSR_EFER, l, h);
34110+ }
34111+#endif
34112
34113 xen_setup_features();
34114
34115@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34116
34117 machine_ops = xen_machine_ops;
34118
34119- /*
34120- * The only reliable way to retain the initial address of the
34121- * percpu gdt_page is to remember it here, so we can go and
34122- * mark it RW later, when the initial percpu area is freed.
34123- */
34124- xen_initial_gdt = &per_cpu(gdt_page, 0);
34125-
34126 xen_smp_init();
34127
34128 #ifdef CONFIG_ACPI_NUMA
34129diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34130index fdc3ba2..3daee39 100644
34131--- a/arch/x86/xen/mmu.c
34132+++ b/arch/x86/xen/mmu.c
34133@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34134 /* L3_k[510] -> level2_kernel_pgt
34135 * L3_i[511] -> level2_fixmap_pgt */
34136 convert_pfn_mfn(level3_kernel_pgt);
34137+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34138+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34139+ convert_pfn_mfn(level3_vmemmap_pgt);
34140
34141 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34142 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34143@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34144 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34145 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34146 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34147+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34148+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34149+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34150 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34151 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34152+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34153 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34154 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34155
34156@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34157 pv_mmu_ops.set_pud = xen_set_pud;
34158 #if PAGETABLE_LEVELS == 4
34159 pv_mmu_ops.set_pgd = xen_set_pgd;
34160+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34161 #endif
34162
34163 /* This will work as long as patching hasn't happened yet
34164@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34165 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34166 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34167 .set_pgd = xen_set_pgd_hyper,
34168+ .set_pgd_batched = xen_set_pgd_hyper,
34169
34170 .alloc_pud = xen_alloc_pmd_init,
34171 .release_pud = xen_release_pmd_init,
34172diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34173index b81c88e..2cbe7b8 100644
34174--- a/arch/x86/xen/smp.c
34175+++ b/arch/x86/xen/smp.c
34176@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34177 {
34178 BUG_ON(smp_processor_id() != 0);
34179 native_smp_prepare_boot_cpu();
34180-
34181- /* We've switched to the "real" per-cpu gdt, so make sure the
34182- old memory can be recycled */
34183- make_lowmem_page_readwrite(xen_initial_gdt);
34184-
34185 xen_filter_cpu_maps();
34186 xen_setup_vcpu_info_placement();
34187 }
34188@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34189 ctxt->user_regs.ss = __KERNEL_DS;
34190 #ifdef CONFIG_X86_32
34191 ctxt->user_regs.fs = __KERNEL_PERCPU;
34192- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34193+ savesegment(gs, ctxt->user_regs.gs);
34194 #else
34195 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34196 #endif
34197@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34198
34199 {
34200 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34201- ctxt->user_regs.ds = __USER_DS;
34202- ctxt->user_regs.es = __USER_DS;
34203+ ctxt->user_regs.ds = __KERNEL_DS;
34204+ ctxt->user_regs.es = __KERNEL_DS;
34205
34206 xen_copy_trap_info(ctxt->trap_ctxt);
34207
34208@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34209 int rc;
34210
34211 per_cpu(current_task, cpu) = idle;
34212+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34213 #ifdef CONFIG_X86_32
34214 irq_ctx_init(cpu);
34215 #else
34216 clear_tsk_thread_flag(idle, TIF_FORK);
34217- per_cpu(kernel_stack, cpu) =
34218- (unsigned long)task_stack_page(idle) -
34219- KERNEL_STACK_OFFSET + THREAD_SIZE;
34220+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34221 #endif
34222 xen_setup_runstate_info(cpu);
34223 xen_setup_timer(cpu);
34224@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34225
34226 void __init xen_smp_init(void)
34227 {
34228- smp_ops = xen_smp_ops;
34229+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34230 xen_fill_possible_map();
34231 xen_init_spinlocks();
34232 }
34233diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34234index 33ca6e4..0ded929 100644
34235--- a/arch/x86/xen/xen-asm_32.S
34236+++ b/arch/x86/xen/xen-asm_32.S
34237@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34238 ESP_OFFSET=4 # bytes pushed onto stack
34239
34240 /*
34241- * Store vcpu_info pointer for easy access. Do it this way to
34242- * avoid having to reload %fs
34243+ * Store vcpu_info pointer for easy access.
34244 */
34245 #ifdef CONFIG_SMP
34246- GET_THREAD_INFO(%eax)
34247- movl %ss:TI_cpu(%eax), %eax
34248- movl %ss:__per_cpu_offset(,%eax,4), %eax
34249- mov %ss:xen_vcpu(%eax), %eax
34250+ push %fs
34251+ mov $(__KERNEL_PERCPU), %eax
34252+ mov %eax, %fs
34253+ mov PER_CPU_VAR(xen_vcpu), %eax
34254+ pop %fs
34255 #else
34256 movl %ss:xen_vcpu, %eax
34257 #endif
34258diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34259index 7faed58..ba4427c 100644
34260--- a/arch/x86/xen/xen-head.S
34261+++ b/arch/x86/xen/xen-head.S
34262@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34263 #ifdef CONFIG_X86_32
34264 mov %esi,xen_start_info
34265 mov $init_thread_union+THREAD_SIZE,%esp
34266+#ifdef CONFIG_SMP
34267+ movl $cpu_gdt_table,%edi
34268+ movl $__per_cpu_load,%eax
34269+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34270+ rorl $16,%eax
34271+ movb %al,__KERNEL_PERCPU + 4(%edi)
34272+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34273+ movl $__per_cpu_end - 1,%eax
34274+ subl $__per_cpu_start,%eax
34275+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34276+#endif
34277 #else
34278 mov %rsi,xen_start_info
34279 mov $init_thread_union+THREAD_SIZE,%rsp
34280diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34281index 86782c5..fa272c8 100644
34282--- a/arch/x86/xen/xen-ops.h
34283+++ b/arch/x86/xen/xen-ops.h
34284@@ -10,8 +10,6 @@
34285 extern const char xen_hypervisor_callback[];
34286 extern const char xen_failsafe_callback[];
34287
34288-extern void *xen_initial_gdt;
34289-
34290 struct trap_info;
34291 void xen_copy_trap_info(struct trap_info *traps);
34292
34293diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34294index 525bd3d..ef888b1 100644
34295--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34296+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34297@@ -119,9 +119,9 @@
34298 ----------------------------------------------------------------------*/
34299
34300 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34301-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34302 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34303 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34304+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34305
34306 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34307 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34308diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34309index 2f33760..835e50a 100644
34310--- a/arch/xtensa/variants/fsf/include/variant/core.h
34311+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34312@@ -11,6 +11,7 @@
34313 #ifndef _XTENSA_CORE_H
34314 #define _XTENSA_CORE_H
34315
34316+#include <linux/const.h>
34317
34318 /****************************************************************************
34319 Parameters Useful for Any Code, USER or PRIVILEGED
34320@@ -112,9 +113,9 @@
34321 ----------------------------------------------------------------------*/
34322
34323 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34324-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34325 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34326 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34327+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34328
34329 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34330 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34331diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34332index af00795..2bb8105 100644
34333--- a/arch/xtensa/variants/s6000/include/variant/core.h
34334+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34335@@ -11,6 +11,7 @@
34336 #ifndef _XTENSA_CORE_CONFIGURATION_H
34337 #define _XTENSA_CORE_CONFIGURATION_H
34338
34339+#include <linux/const.h>
34340
34341 /****************************************************************************
34342 Parameters Useful for Any Code, USER or PRIVILEGED
34343@@ -118,9 +119,9 @@
34344 ----------------------------------------------------------------------*/
34345
34346 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34347-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34348 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34349 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34350+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34351
34352 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34353 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34354diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34355index 290792a..416f287 100644
34356--- a/block/blk-cgroup.c
34357+++ b/block/blk-cgroup.c
34358@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34359
34360 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34361 {
34362- static atomic64_t id_seq = ATOMIC64_INIT(0);
34363+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34364 struct blkcg *blkcg;
34365 struct cgroup *parent = cgroup->parent;
34366
34367@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34368
34369 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34370 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34371- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34372+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34373 done:
34374 spin_lock_init(&blkcg->lock);
34375 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34376diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34377index 4b8d9b54..a7178c0 100644
34378--- a/block/blk-iopoll.c
34379+++ b/block/blk-iopoll.c
34380@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34381 }
34382 EXPORT_SYMBOL(blk_iopoll_complete);
34383
34384-static void blk_iopoll_softirq(struct softirq_action *h)
34385+static __latent_entropy void blk_iopoll_softirq(void)
34386 {
34387 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34388 int rearm = 0, budget = blk_iopoll_budget;
34389diff --git a/block/blk-map.c b/block/blk-map.c
34390index 623e1cd..ca1e109 100644
34391--- a/block/blk-map.c
34392+++ b/block/blk-map.c
34393@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34394 if (!len || !kbuf)
34395 return -EINVAL;
34396
34397- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34398+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34399 if (do_copy)
34400 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34401 else
34402diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34403index ec9e606..3f38839 100644
34404--- a/block/blk-softirq.c
34405+++ b/block/blk-softirq.c
34406@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34407 * Softirq action handler - move entries to local list and loop over them
34408 * while passing them to the queue registered handler.
34409 */
34410-static void blk_done_softirq(struct softirq_action *h)
34411+static __latent_entropy void blk_done_softirq(void)
34412 {
34413 struct list_head *cpu_list, local_list;
34414
34415diff --git a/block/bsg.c b/block/bsg.c
34416index 420a5a9..23834aa 100644
34417--- a/block/bsg.c
34418+++ b/block/bsg.c
34419@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34420 struct sg_io_v4 *hdr, struct bsg_device *bd,
34421 fmode_t has_write_perm)
34422 {
34423+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34424+ unsigned char *cmdptr;
34425+
34426 if (hdr->request_len > BLK_MAX_CDB) {
34427 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34428 if (!rq->cmd)
34429 return -ENOMEM;
34430- }
34431+ cmdptr = rq->cmd;
34432+ } else
34433+ cmdptr = tmpcmd;
34434
34435- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34436+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34437 hdr->request_len))
34438 return -EFAULT;
34439
34440+ if (cmdptr != rq->cmd)
34441+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34442+
34443 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34444 if (blk_verify_command(rq->cmd, has_write_perm))
34445 return -EPERM;
34446diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34447index 7e5d474..0cf0017 100644
34448--- a/block/compat_ioctl.c
34449+++ b/block/compat_ioctl.c
34450@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34451 err |= __get_user(f->spec1, &uf->spec1);
34452 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34453 err |= __get_user(name, &uf->name);
34454- f->name = compat_ptr(name);
34455+ f->name = (void __force_kernel *)compat_ptr(name);
34456 if (err) {
34457 err = -EFAULT;
34458 goto out;
34459diff --git a/block/genhd.c b/block/genhd.c
34460index dadf42b..48dc887 100644
34461--- a/block/genhd.c
34462+++ b/block/genhd.c
34463@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34464
34465 /*
34466 * Register device numbers dev..(dev+range-1)
34467- * range must be nonzero
34468+ * Noop if @range is zero.
34469 * The hash chain is sorted on range, so that subranges can override.
34470 */
34471 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34472 struct kobject *(*probe)(dev_t, int *, void *),
34473 int (*lock)(dev_t, void *), void *data)
34474 {
34475- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34476+ if (range)
34477+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34478 }
34479
34480 EXPORT_SYMBOL(blk_register_region);
34481
34482+/* undo blk_register_region(), noop if @range is zero */
34483 void blk_unregister_region(dev_t devt, unsigned long range)
34484 {
34485- kobj_unmap(bdev_map, devt, range);
34486+ if (range)
34487+ kobj_unmap(bdev_map, devt, range);
34488 }
34489
34490 EXPORT_SYMBOL(blk_unregister_region);
34491diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34492index c85fc89..51e690b 100644
34493--- a/block/partitions/efi.c
34494+++ b/block/partitions/efi.c
34495@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34496 if (!gpt)
34497 return NULL;
34498
34499+ if (!le32_to_cpu(gpt->num_partition_entries))
34500+ return NULL;
34501+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34502+ if (!pte)
34503+ return NULL;
34504+
34505 count = le32_to_cpu(gpt->num_partition_entries) *
34506 le32_to_cpu(gpt->sizeof_partition_entry);
34507- if (!count)
34508- return NULL;
34509- pte = kmalloc(count, GFP_KERNEL);
34510- if (!pte)
34511- return NULL;
34512-
34513 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34514 (u8 *) pte,
34515 count) < count) {
34516diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34517index a5ffcc9..3cedc9c 100644
34518--- a/block/scsi_ioctl.c
34519+++ b/block/scsi_ioctl.c
34520@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34521 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34522 struct sg_io_hdr *hdr, fmode_t mode)
34523 {
34524- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34525+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34526+ unsigned char *cmdptr;
34527+
34528+ if (rq->cmd != rq->__cmd)
34529+ cmdptr = rq->cmd;
34530+ else
34531+ cmdptr = tmpcmd;
34532+
34533+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34534 return -EFAULT;
34535+
34536+ if (cmdptr != rq->cmd)
34537+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34538+
34539 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34540 return -EPERM;
34541
34542@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34543 int err;
34544 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34545 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34546+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34547+ unsigned char *cmdptr;
34548
34549 if (!sic)
34550 return -EINVAL;
34551@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34552 */
34553 err = -EFAULT;
34554 rq->cmd_len = cmdlen;
34555- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34556+
34557+ if (rq->cmd != rq->__cmd)
34558+ cmdptr = rq->cmd;
34559+ else
34560+ cmdptr = tmpcmd;
34561+
34562+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34563 goto error;
34564
34565+ if (rq->cmd != cmdptr)
34566+ memcpy(rq->cmd, cmdptr, cmdlen);
34567+
34568 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34569 goto error;
34570
34571diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34572index 7bdd61b..afec999 100644
34573--- a/crypto/cryptd.c
34574+++ b/crypto/cryptd.c
34575@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34576
34577 struct cryptd_blkcipher_request_ctx {
34578 crypto_completion_t complete;
34579-};
34580+} __no_const;
34581
34582 struct cryptd_hash_ctx {
34583 struct crypto_shash *child;
34584@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34585
34586 struct cryptd_aead_request_ctx {
34587 crypto_completion_t complete;
34588-};
34589+} __no_const;
34590
34591 static void cryptd_queue_worker(struct work_struct *work);
34592
34593diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34594index f8c920c..ab2cb5a 100644
34595--- a/crypto/pcrypt.c
34596+++ b/crypto/pcrypt.c
34597@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34598 int ret;
34599
34600 pinst->kobj.kset = pcrypt_kset;
34601- ret = kobject_add(&pinst->kobj, NULL, name);
34602+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34603 if (!ret)
34604 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34605
34606diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34607index f220d64..d359ad6 100644
34608--- a/drivers/acpi/apei/apei-internal.h
34609+++ b/drivers/acpi/apei/apei-internal.h
34610@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34611 struct apei_exec_ins_type {
34612 u32 flags;
34613 apei_exec_ins_func_t run;
34614-};
34615+} __do_const;
34616
34617 struct apei_exec_context {
34618 u32 ip;
34619diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34620index 33dc6a0..4b24b47 100644
34621--- a/drivers/acpi/apei/cper.c
34622+++ b/drivers/acpi/apei/cper.c
34623@@ -39,12 +39,12 @@
34624 */
34625 u64 cper_next_record_id(void)
34626 {
34627- static atomic64_t seq;
34628+ static atomic64_unchecked_t seq;
34629
34630- if (!atomic64_read(&seq))
34631- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34632+ if (!atomic64_read_unchecked(&seq))
34633+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34634
34635- return atomic64_inc_return(&seq);
34636+ return atomic64_inc_return_unchecked(&seq);
34637 }
34638 EXPORT_SYMBOL_GPL(cper_next_record_id);
34639
34640diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34641index ec9b57d..9682b3a 100644
34642--- a/drivers/acpi/apei/ghes.c
34643+++ b/drivers/acpi/apei/ghes.c
34644@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34645 const struct acpi_hest_generic *generic,
34646 const struct acpi_hest_generic_status *estatus)
34647 {
34648- static atomic_t seqno;
34649+ static atomic_unchecked_t seqno;
34650 unsigned int curr_seqno;
34651 char pfx_seq[64];
34652
34653@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34654 else
34655 pfx = KERN_ERR;
34656 }
34657- curr_seqno = atomic_inc_return(&seqno);
34658+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34659 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34660 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34661 pfx_seq, generic->header.source_id);
34662diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34663index be60399..778b33e8 100644
34664--- a/drivers/acpi/bgrt.c
34665+++ b/drivers/acpi/bgrt.c
34666@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34667 return -ENODEV;
34668
34669 sysfs_bin_attr_init(&image_attr);
34670- image_attr.private = bgrt_image;
34671- image_attr.size = bgrt_image_size;
34672+ pax_open_kernel();
34673+ *(void **)&image_attr.private = bgrt_image;
34674+ *(size_t *)&image_attr.size = bgrt_image_size;
34675+ pax_close_kernel();
34676
34677 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34678 if (!bgrt_kobj)
34679diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34680index cb96296..b81293b 100644
34681--- a/drivers/acpi/blacklist.c
34682+++ b/drivers/acpi/blacklist.c
34683@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34684 u32 is_critical_error;
34685 };
34686
34687-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34688+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34689
34690 /*
34691 * POLICY: If *anything* doesn't work, put it on the blacklist.
34692@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34693 return 0;
34694 }
34695
34696-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34697+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34698 {
34699 .callback = dmi_disable_osi_vista,
34700 .ident = "Fujitsu Siemens",
34701diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34702index f98dd00..7b69865 100644
34703--- a/drivers/acpi/processor_idle.c
34704+++ b/drivers/acpi/processor_idle.c
34705@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34706 {
34707 int i, count = CPUIDLE_DRIVER_STATE_START;
34708 struct acpi_processor_cx *cx;
34709- struct cpuidle_state *state;
34710+ cpuidle_state_no_const *state;
34711 struct cpuidle_driver *drv = &acpi_idle_driver;
34712
34713 if (!pr->flags.power_setup_done)
34714diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34715index 05306a5..733d1f0 100644
34716--- a/drivers/acpi/sysfs.c
34717+++ b/drivers/acpi/sysfs.c
34718@@ -423,11 +423,11 @@ static u32 num_counters;
34719 static struct attribute **all_attrs;
34720 static u32 acpi_gpe_count;
34721
34722-static struct attribute_group interrupt_stats_attr_group = {
34723+static attribute_group_no_const interrupt_stats_attr_group = {
34724 .name = "interrupts",
34725 };
34726
34727-static struct kobj_attribute *counter_attrs;
34728+static kobj_attribute_no_const *counter_attrs;
34729
34730 static void delete_gpe_attr_array(void)
34731 {
34732diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34733index acfd0f7..e5acb08 100644
34734--- a/drivers/ata/libahci.c
34735+++ b/drivers/ata/libahci.c
34736@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34737 }
34738 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34739
34740-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34741+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34742 struct ata_taskfile *tf, int is_cmd, u16 flags,
34743 unsigned long timeout_msec)
34744 {
34745diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34746index c24354d..335c975 100644
34747--- a/drivers/ata/libata-core.c
34748+++ b/drivers/ata/libata-core.c
34749@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34750 static void ata_dev_xfermask(struct ata_device *dev);
34751 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34752
34753-atomic_t ata_print_id = ATOMIC_INIT(0);
34754+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34755
34756 struct ata_force_param {
34757 const char *name;
34758@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34759 struct ata_port *ap;
34760 unsigned int tag;
34761
34762- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34763+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34764 ap = qc->ap;
34765
34766 qc->flags = 0;
34767@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34768 struct ata_port *ap;
34769 struct ata_link *link;
34770
34771- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34772+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34773 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34774 ap = qc->ap;
34775 link = qc->dev->link;
34776@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34777 return;
34778
34779 spin_lock(&lock);
34780+ pax_open_kernel();
34781
34782 for (cur = ops->inherits; cur; cur = cur->inherits) {
34783 void **inherit = (void **)cur;
34784@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34785 if (IS_ERR(*pp))
34786 *pp = NULL;
34787
34788- ops->inherits = NULL;
34789+ *(struct ata_port_operations **)&ops->inherits = NULL;
34790
34791+ pax_close_kernel();
34792 spin_unlock(&lock);
34793 }
34794
34795@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34796
34797 /* give ports names and add SCSI hosts */
34798 for (i = 0; i < host->n_ports; i++) {
34799- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34800+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34801 host->ports[i]->local_port_no = i + 1;
34802 }
34803
34804diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34805index b1e880a..8cf82e1 100644
34806--- a/drivers/ata/libata-scsi.c
34807+++ b/drivers/ata/libata-scsi.c
34808@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34809
34810 if (rc)
34811 return rc;
34812- ap->print_id = atomic_inc_return(&ata_print_id);
34813+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34814 return 0;
34815 }
34816 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34817diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34818index 577d902b..cb4781e 100644
34819--- a/drivers/ata/libata.h
34820+++ b/drivers/ata/libata.h
34821@@ -53,7 +53,7 @@ enum {
34822 ATA_DNXFER_QUIET = (1 << 31),
34823 };
34824
34825-extern atomic_t ata_print_id;
34826+extern atomic_unchecked_t ata_print_id;
34827 extern int atapi_passthru16;
34828 extern int libata_fua;
34829 extern int libata_noacpi;
34830diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34831index 848ed32..132f39d 100644
34832--- a/drivers/ata/pata_arasan_cf.c
34833+++ b/drivers/ata/pata_arasan_cf.c
34834@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34835 /* Handle platform specific quirks */
34836 if (quirk) {
34837 if (quirk & CF_BROKEN_PIO) {
34838- ap->ops->set_piomode = NULL;
34839+ pax_open_kernel();
34840+ *(void **)&ap->ops->set_piomode = NULL;
34841+ pax_close_kernel();
34842 ap->pio_mask = 0;
34843 }
34844 if (quirk & CF_BROKEN_MWDMA)
34845diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34846index f9b983a..887b9d8 100644
34847--- a/drivers/atm/adummy.c
34848+++ b/drivers/atm/adummy.c
34849@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34850 vcc->pop(vcc, skb);
34851 else
34852 dev_kfree_skb_any(skb);
34853- atomic_inc(&vcc->stats->tx);
34854+ atomic_inc_unchecked(&vcc->stats->tx);
34855
34856 return 0;
34857 }
34858diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34859index 62a7607..cc4be104 100644
34860--- a/drivers/atm/ambassador.c
34861+++ b/drivers/atm/ambassador.c
34862@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34863 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34864
34865 // VC layer stats
34866- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34867+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34868
34869 // free the descriptor
34870 kfree (tx_descr);
34871@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34872 dump_skb ("<<<", vc, skb);
34873
34874 // VC layer stats
34875- atomic_inc(&atm_vcc->stats->rx);
34876+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34877 __net_timestamp(skb);
34878 // end of our responsibility
34879 atm_vcc->push (atm_vcc, skb);
34880@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34881 } else {
34882 PRINTK (KERN_INFO, "dropped over-size frame");
34883 // should we count this?
34884- atomic_inc(&atm_vcc->stats->rx_drop);
34885+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34886 }
34887
34888 } else {
34889@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34890 }
34891
34892 if (check_area (skb->data, skb->len)) {
34893- atomic_inc(&atm_vcc->stats->tx_err);
34894+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34895 return -ENOMEM; // ?
34896 }
34897
34898diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34899index 0e3f8f9..765a7a5 100644
34900--- a/drivers/atm/atmtcp.c
34901+++ b/drivers/atm/atmtcp.c
34902@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34903 if (vcc->pop) vcc->pop(vcc,skb);
34904 else dev_kfree_skb(skb);
34905 if (dev_data) return 0;
34906- atomic_inc(&vcc->stats->tx_err);
34907+ atomic_inc_unchecked(&vcc->stats->tx_err);
34908 return -ENOLINK;
34909 }
34910 size = skb->len+sizeof(struct atmtcp_hdr);
34911@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34912 if (!new_skb) {
34913 if (vcc->pop) vcc->pop(vcc,skb);
34914 else dev_kfree_skb(skb);
34915- atomic_inc(&vcc->stats->tx_err);
34916+ atomic_inc_unchecked(&vcc->stats->tx_err);
34917 return -ENOBUFS;
34918 }
34919 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34920@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34921 if (vcc->pop) vcc->pop(vcc,skb);
34922 else dev_kfree_skb(skb);
34923 out_vcc->push(out_vcc,new_skb);
34924- atomic_inc(&vcc->stats->tx);
34925- atomic_inc(&out_vcc->stats->rx);
34926+ atomic_inc_unchecked(&vcc->stats->tx);
34927+ atomic_inc_unchecked(&out_vcc->stats->rx);
34928 return 0;
34929 }
34930
34931@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34932 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34933 read_unlock(&vcc_sklist_lock);
34934 if (!out_vcc) {
34935- atomic_inc(&vcc->stats->tx_err);
34936+ atomic_inc_unchecked(&vcc->stats->tx_err);
34937 goto done;
34938 }
34939 skb_pull(skb,sizeof(struct atmtcp_hdr));
34940@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34941 __net_timestamp(new_skb);
34942 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34943 out_vcc->push(out_vcc,new_skb);
34944- atomic_inc(&vcc->stats->tx);
34945- atomic_inc(&out_vcc->stats->rx);
34946+ atomic_inc_unchecked(&vcc->stats->tx);
34947+ atomic_inc_unchecked(&out_vcc->stats->rx);
34948 done:
34949 if (vcc->pop) vcc->pop(vcc,skb);
34950 else dev_kfree_skb(skb);
34951diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34952index b1955ba..b179940 100644
34953--- a/drivers/atm/eni.c
34954+++ b/drivers/atm/eni.c
34955@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34956 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34957 vcc->dev->number);
34958 length = 0;
34959- atomic_inc(&vcc->stats->rx_err);
34960+ atomic_inc_unchecked(&vcc->stats->rx_err);
34961 }
34962 else {
34963 length = ATM_CELL_SIZE-1; /* no HEC */
34964@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34965 size);
34966 }
34967 eff = length = 0;
34968- atomic_inc(&vcc->stats->rx_err);
34969+ atomic_inc_unchecked(&vcc->stats->rx_err);
34970 }
34971 else {
34972 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34973@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34974 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34975 vcc->dev->number,vcc->vci,length,size << 2,descr);
34976 length = eff = 0;
34977- atomic_inc(&vcc->stats->rx_err);
34978+ atomic_inc_unchecked(&vcc->stats->rx_err);
34979 }
34980 }
34981 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34982@@ -767,7 +767,7 @@ rx_dequeued++;
34983 vcc->push(vcc,skb);
34984 pushed++;
34985 }
34986- atomic_inc(&vcc->stats->rx);
34987+ atomic_inc_unchecked(&vcc->stats->rx);
34988 }
34989 wake_up(&eni_dev->rx_wait);
34990 }
34991@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34992 PCI_DMA_TODEVICE);
34993 if (vcc->pop) vcc->pop(vcc,skb);
34994 else dev_kfree_skb_irq(skb);
34995- atomic_inc(&vcc->stats->tx);
34996+ atomic_inc_unchecked(&vcc->stats->tx);
34997 wake_up(&eni_dev->tx_wait);
34998 dma_complete++;
34999 }
35000diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35001index b41c948..a002b17 100644
35002--- a/drivers/atm/firestream.c
35003+++ b/drivers/atm/firestream.c
35004@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35005 }
35006 }
35007
35008- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35009+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35010
35011 fs_dprintk (FS_DEBUG_TXMEM, "i");
35012 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35013@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35014 #endif
35015 skb_put (skb, qe->p1 & 0xffff);
35016 ATM_SKB(skb)->vcc = atm_vcc;
35017- atomic_inc(&atm_vcc->stats->rx);
35018+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35019 __net_timestamp(skb);
35020 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35021 atm_vcc->push (atm_vcc, skb);
35022@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35023 kfree (pe);
35024 }
35025 if (atm_vcc)
35026- atomic_inc(&atm_vcc->stats->rx_drop);
35027+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35028 break;
35029 case 0x1f: /* Reassembly abort: no buffers. */
35030 /* Silently increment error counter. */
35031 if (atm_vcc)
35032- atomic_inc(&atm_vcc->stats->rx_drop);
35033+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35034 break;
35035 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35036 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35037diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35038index 204814e..cede831 100644
35039--- a/drivers/atm/fore200e.c
35040+++ b/drivers/atm/fore200e.c
35041@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35042 #endif
35043 /* check error condition */
35044 if (*entry->status & STATUS_ERROR)
35045- atomic_inc(&vcc->stats->tx_err);
35046+ atomic_inc_unchecked(&vcc->stats->tx_err);
35047 else
35048- atomic_inc(&vcc->stats->tx);
35049+ atomic_inc_unchecked(&vcc->stats->tx);
35050 }
35051 }
35052
35053@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35054 if (skb == NULL) {
35055 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35056
35057- atomic_inc(&vcc->stats->rx_drop);
35058+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35059 return -ENOMEM;
35060 }
35061
35062@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35063
35064 dev_kfree_skb_any(skb);
35065
35066- atomic_inc(&vcc->stats->rx_drop);
35067+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35068 return -ENOMEM;
35069 }
35070
35071 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35072
35073 vcc->push(vcc, skb);
35074- atomic_inc(&vcc->stats->rx);
35075+ atomic_inc_unchecked(&vcc->stats->rx);
35076
35077 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35078
35079@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35080 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35081 fore200e->atm_dev->number,
35082 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35083- atomic_inc(&vcc->stats->rx_err);
35084+ atomic_inc_unchecked(&vcc->stats->rx_err);
35085 }
35086 }
35087
35088@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35089 goto retry_here;
35090 }
35091
35092- atomic_inc(&vcc->stats->tx_err);
35093+ atomic_inc_unchecked(&vcc->stats->tx_err);
35094
35095 fore200e->tx_sat++;
35096 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35097diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35098index 507362a..a845e57 100644
35099--- a/drivers/atm/he.c
35100+++ b/drivers/atm/he.c
35101@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35102
35103 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35104 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35105- atomic_inc(&vcc->stats->rx_drop);
35106+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35107 goto return_host_buffers;
35108 }
35109
35110@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35111 RBRQ_LEN_ERR(he_dev->rbrq_head)
35112 ? "LEN_ERR" : "",
35113 vcc->vpi, vcc->vci);
35114- atomic_inc(&vcc->stats->rx_err);
35115+ atomic_inc_unchecked(&vcc->stats->rx_err);
35116 goto return_host_buffers;
35117 }
35118
35119@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35120 vcc->push(vcc, skb);
35121 spin_lock(&he_dev->global_lock);
35122
35123- atomic_inc(&vcc->stats->rx);
35124+ atomic_inc_unchecked(&vcc->stats->rx);
35125
35126 return_host_buffers:
35127 ++pdus_assembled;
35128@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35129 tpd->vcc->pop(tpd->vcc, tpd->skb);
35130 else
35131 dev_kfree_skb_any(tpd->skb);
35132- atomic_inc(&tpd->vcc->stats->tx_err);
35133+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35134 }
35135 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35136 return;
35137@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35138 vcc->pop(vcc, skb);
35139 else
35140 dev_kfree_skb_any(skb);
35141- atomic_inc(&vcc->stats->tx_err);
35142+ atomic_inc_unchecked(&vcc->stats->tx_err);
35143 return -EINVAL;
35144 }
35145
35146@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35147 vcc->pop(vcc, skb);
35148 else
35149 dev_kfree_skb_any(skb);
35150- atomic_inc(&vcc->stats->tx_err);
35151+ atomic_inc_unchecked(&vcc->stats->tx_err);
35152 return -EINVAL;
35153 }
35154 #endif
35155@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35156 vcc->pop(vcc, skb);
35157 else
35158 dev_kfree_skb_any(skb);
35159- atomic_inc(&vcc->stats->tx_err);
35160+ atomic_inc_unchecked(&vcc->stats->tx_err);
35161 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35162 return -ENOMEM;
35163 }
35164@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35165 vcc->pop(vcc, skb);
35166 else
35167 dev_kfree_skb_any(skb);
35168- atomic_inc(&vcc->stats->tx_err);
35169+ atomic_inc_unchecked(&vcc->stats->tx_err);
35170 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35171 return -ENOMEM;
35172 }
35173@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35174 __enqueue_tpd(he_dev, tpd, cid);
35175 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35176
35177- atomic_inc(&vcc->stats->tx);
35178+ atomic_inc_unchecked(&vcc->stats->tx);
35179
35180 return 0;
35181 }
35182diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35183index 1dc0519..1aadaf7 100644
35184--- a/drivers/atm/horizon.c
35185+++ b/drivers/atm/horizon.c
35186@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35187 {
35188 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35189 // VC layer stats
35190- atomic_inc(&vcc->stats->rx);
35191+ atomic_inc_unchecked(&vcc->stats->rx);
35192 __net_timestamp(skb);
35193 // end of our responsibility
35194 vcc->push (vcc, skb);
35195@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35196 dev->tx_iovec = NULL;
35197
35198 // VC layer stats
35199- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35200+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35201
35202 // free the skb
35203 hrz_kfree_skb (skb);
35204diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35205index 272f009..a18ba55 100644
35206--- a/drivers/atm/idt77252.c
35207+++ b/drivers/atm/idt77252.c
35208@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35209 else
35210 dev_kfree_skb(skb);
35211
35212- atomic_inc(&vcc->stats->tx);
35213+ atomic_inc_unchecked(&vcc->stats->tx);
35214 }
35215
35216 atomic_dec(&scq->used);
35217@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35218 if ((sb = dev_alloc_skb(64)) == NULL) {
35219 printk("%s: Can't allocate buffers for aal0.\n",
35220 card->name);
35221- atomic_add(i, &vcc->stats->rx_drop);
35222+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35223 break;
35224 }
35225 if (!atm_charge(vcc, sb->truesize)) {
35226 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35227 card->name);
35228- atomic_add(i - 1, &vcc->stats->rx_drop);
35229+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35230 dev_kfree_skb(sb);
35231 break;
35232 }
35233@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35234 ATM_SKB(sb)->vcc = vcc;
35235 __net_timestamp(sb);
35236 vcc->push(vcc, sb);
35237- atomic_inc(&vcc->stats->rx);
35238+ atomic_inc_unchecked(&vcc->stats->rx);
35239
35240 cell += ATM_CELL_PAYLOAD;
35241 }
35242@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35243 "(CDC: %08x)\n",
35244 card->name, len, rpp->len, readl(SAR_REG_CDC));
35245 recycle_rx_pool_skb(card, rpp);
35246- atomic_inc(&vcc->stats->rx_err);
35247+ atomic_inc_unchecked(&vcc->stats->rx_err);
35248 return;
35249 }
35250 if (stat & SAR_RSQE_CRC) {
35251 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35252 recycle_rx_pool_skb(card, rpp);
35253- atomic_inc(&vcc->stats->rx_err);
35254+ atomic_inc_unchecked(&vcc->stats->rx_err);
35255 return;
35256 }
35257 if (skb_queue_len(&rpp->queue) > 1) {
35258@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35259 RXPRINTK("%s: Can't alloc RX skb.\n",
35260 card->name);
35261 recycle_rx_pool_skb(card, rpp);
35262- atomic_inc(&vcc->stats->rx_err);
35263+ atomic_inc_unchecked(&vcc->stats->rx_err);
35264 return;
35265 }
35266 if (!atm_charge(vcc, skb->truesize)) {
35267@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35268 __net_timestamp(skb);
35269
35270 vcc->push(vcc, skb);
35271- atomic_inc(&vcc->stats->rx);
35272+ atomic_inc_unchecked(&vcc->stats->rx);
35273
35274 return;
35275 }
35276@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35277 __net_timestamp(skb);
35278
35279 vcc->push(vcc, skb);
35280- atomic_inc(&vcc->stats->rx);
35281+ atomic_inc_unchecked(&vcc->stats->rx);
35282
35283 if (skb->truesize > SAR_FB_SIZE_3)
35284 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35285@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35286 if (vcc->qos.aal != ATM_AAL0) {
35287 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35288 card->name, vpi, vci);
35289- atomic_inc(&vcc->stats->rx_drop);
35290+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35291 goto drop;
35292 }
35293
35294 if ((sb = dev_alloc_skb(64)) == NULL) {
35295 printk("%s: Can't allocate buffers for AAL0.\n",
35296 card->name);
35297- atomic_inc(&vcc->stats->rx_err);
35298+ atomic_inc_unchecked(&vcc->stats->rx_err);
35299 goto drop;
35300 }
35301
35302@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35303 ATM_SKB(sb)->vcc = vcc;
35304 __net_timestamp(sb);
35305 vcc->push(vcc, sb);
35306- atomic_inc(&vcc->stats->rx);
35307+ atomic_inc_unchecked(&vcc->stats->rx);
35308
35309 drop:
35310 skb_pull(queue, 64);
35311@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35312
35313 if (vc == NULL) {
35314 printk("%s: NULL connection in send().\n", card->name);
35315- atomic_inc(&vcc->stats->tx_err);
35316+ atomic_inc_unchecked(&vcc->stats->tx_err);
35317 dev_kfree_skb(skb);
35318 return -EINVAL;
35319 }
35320 if (!test_bit(VCF_TX, &vc->flags)) {
35321 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35322- atomic_inc(&vcc->stats->tx_err);
35323+ atomic_inc_unchecked(&vcc->stats->tx_err);
35324 dev_kfree_skb(skb);
35325 return -EINVAL;
35326 }
35327@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35328 break;
35329 default:
35330 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35331- atomic_inc(&vcc->stats->tx_err);
35332+ atomic_inc_unchecked(&vcc->stats->tx_err);
35333 dev_kfree_skb(skb);
35334 return -EINVAL;
35335 }
35336
35337 if (skb_shinfo(skb)->nr_frags != 0) {
35338 printk("%s: No scatter-gather yet.\n", card->name);
35339- atomic_inc(&vcc->stats->tx_err);
35340+ atomic_inc_unchecked(&vcc->stats->tx_err);
35341 dev_kfree_skb(skb);
35342 return -EINVAL;
35343 }
35344@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35345
35346 err = queue_skb(card, vc, skb, oam);
35347 if (err) {
35348- atomic_inc(&vcc->stats->tx_err);
35349+ atomic_inc_unchecked(&vcc->stats->tx_err);
35350 dev_kfree_skb(skb);
35351 return err;
35352 }
35353@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35354 skb = dev_alloc_skb(64);
35355 if (!skb) {
35356 printk("%s: Out of memory in send_oam().\n", card->name);
35357- atomic_inc(&vcc->stats->tx_err);
35358+ atomic_inc_unchecked(&vcc->stats->tx_err);
35359 return -ENOMEM;
35360 }
35361 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35362diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35363index 4217f29..88f547a 100644
35364--- a/drivers/atm/iphase.c
35365+++ b/drivers/atm/iphase.c
35366@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35367 status = (u_short) (buf_desc_ptr->desc_mode);
35368 if (status & (RX_CER | RX_PTE | RX_OFL))
35369 {
35370- atomic_inc(&vcc->stats->rx_err);
35371+ atomic_inc_unchecked(&vcc->stats->rx_err);
35372 IF_ERR(printk("IA: bad packet, dropping it");)
35373 if (status & RX_CER) {
35374 IF_ERR(printk(" cause: packet CRC error\n");)
35375@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35376 len = dma_addr - buf_addr;
35377 if (len > iadev->rx_buf_sz) {
35378 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35379- atomic_inc(&vcc->stats->rx_err);
35380+ atomic_inc_unchecked(&vcc->stats->rx_err);
35381 goto out_free_desc;
35382 }
35383
35384@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35385 ia_vcc = INPH_IA_VCC(vcc);
35386 if (ia_vcc == NULL)
35387 {
35388- atomic_inc(&vcc->stats->rx_err);
35389+ atomic_inc_unchecked(&vcc->stats->rx_err);
35390 atm_return(vcc, skb->truesize);
35391 dev_kfree_skb_any(skb);
35392 goto INCR_DLE;
35393@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35394 if ((length > iadev->rx_buf_sz) || (length >
35395 (skb->len - sizeof(struct cpcs_trailer))))
35396 {
35397- atomic_inc(&vcc->stats->rx_err);
35398+ atomic_inc_unchecked(&vcc->stats->rx_err);
35399 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35400 length, skb->len);)
35401 atm_return(vcc, skb->truesize);
35402@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35403
35404 IF_RX(printk("rx_dle_intr: skb push");)
35405 vcc->push(vcc,skb);
35406- atomic_inc(&vcc->stats->rx);
35407+ atomic_inc_unchecked(&vcc->stats->rx);
35408 iadev->rx_pkt_cnt++;
35409 }
35410 INCR_DLE:
35411@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35412 {
35413 struct k_sonet_stats *stats;
35414 stats = &PRIV(_ia_dev[board])->sonet_stats;
35415- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35416- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35417- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35418- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35419- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35420- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35421- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35422- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35423- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35424+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35425+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35426+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35427+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35428+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35429+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35430+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35431+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35432+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35433 }
35434 ia_cmds.status = 0;
35435 break;
35436@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35437 if ((desc == 0) || (desc > iadev->num_tx_desc))
35438 {
35439 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35440- atomic_inc(&vcc->stats->tx);
35441+ atomic_inc_unchecked(&vcc->stats->tx);
35442 if (vcc->pop)
35443 vcc->pop(vcc, skb);
35444 else
35445@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35446 ATM_DESC(skb) = vcc->vci;
35447 skb_queue_tail(&iadev->tx_dma_q, skb);
35448
35449- atomic_inc(&vcc->stats->tx);
35450+ atomic_inc_unchecked(&vcc->stats->tx);
35451 iadev->tx_pkt_cnt++;
35452 /* Increment transaction counter */
35453 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35454
35455 #if 0
35456 /* add flow control logic */
35457- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35458+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35459 if (iavcc->vc_desc_cnt > 10) {
35460 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35461 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35462diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35463index fa7d701..1e404c7 100644
35464--- a/drivers/atm/lanai.c
35465+++ b/drivers/atm/lanai.c
35466@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35467 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35468 lanai_endtx(lanai, lvcc);
35469 lanai_free_skb(lvcc->tx.atmvcc, skb);
35470- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35471+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35472 }
35473
35474 /* Try to fill the buffer - don't call unless there is backlog */
35475@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35476 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35477 __net_timestamp(skb);
35478 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35479- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35480+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35481 out:
35482 lvcc->rx.buf.ptr = end;
35483 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35484@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35485 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35486 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35487 lanai->stats.service_rxnotaal5++;
35488- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35489+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35490 return 0;
35491 }
35492 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35493@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35494 int bytes;
35495 read_unlock(&vcc_sklist_lock);
35496 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35497- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35498+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35499 lvcc->stats.x.aal5.service_trash++;
35500 bytes = (SERVICE_GET_END(s) * 16) -
35501 (((unsigned long) lvcc->rx.buf.ptr) -
35502@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35503 }
35504 if (s & SERVICE_STREAM) {
35505 read_unlock(&vcc_sklist_lock);
35506- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35507+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35508 lvcc->stats.x.aal5.service_stream++;
35509 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35510 "PDU on VCI %d!\n", lanai->number, vci);
35511@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35512 return 0;
35513 }
35514 DPRINTK("got rx crc error on vci %d\n", vci);
35515- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35516+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35517 lvcc->stats.x.aal5.service_rxcrc++;
35518 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35519 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35520diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35521index 6587dc2..149833d 100644
35522--- a/drivers/atm/nicstar.c
35523+++ b/drivers/atm/nicstar.c
35524@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35525 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35526 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35527 card->index);
35528- atomic_inc(&vcc->stats->tx_err);
35529+ atomic_inc_unchecked(&vcc->stats->tx_err);
35530 dev_kfree_skb_any(skb);
35531 return -EINVAL;
35532 }
35533@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35534 if (!vc->tx) {
35535 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35536 card->index);
35537- atomic_inc(&vcc->stats->tx_err);
35538+ atomic_inc_unchecked(&vcc->stats->tx_err);
35539 dev_kfree_skb_any(skb);
35540 return -EINVAL;
35541 }
35542@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35543 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35544 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35545 card->index);
35546- atomic_inc(&vcc->stats->tx_err);
35547+ atomic_inc_unchecked(&vcc->stats->tx_err);
35548 dev_kfree_skb_any(skb);
35549 return -EINVAL;
35550 }
35551
35552 if (skb_shinfo(skb)->nr_frags != 0) {
35553 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35554- atomic_inc(&vcc->stats->tx_err);
35555+ atomic_inc_unchecked(&vcc->stats->tx_err);
35556 dev_kfree_skb_any(skb);
35557 return -EINVAL;
35558 }
35559@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35560 }
35561
35562 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35563- atomic_inc(&vcc->stats->tx_err);
35564+ atomic_inc_unchecked(&vcc->stats->tx_err);
35565 dev_kfree_skb_any(skb);
35566 return -EIO;
35567 }
35568- atomic_inc(&vcc->stats->tx);
35569+ atomic_inc_unchecked(&vcc->stats->tx);
35570
35571 return 0;
35572 }
35573@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35574 printk
35575 ("nicstar%d: Can't allocate buffers for aal0.\n",
35576 card->index);
35577- atomic_add(i, &vcc->stats->rx_drop);
35578+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35579 break;
35580 }
35581 if (!atm_charge(vcc, sb->truesize)) {
35582 RXPRINTK
35583 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35584 card->index);
35585- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35586+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35587 dev_kfree_skb_any(sb);
35588 break;
35589 }
35590@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35591 ATM_SKB(sb)->vcc = vcc;
35592 __net_timestamp(sb);
35593 vcc->push(vcc, sb);
35594- atomic_inc(&vcc->stats->rx);
35595+ atomic_inc_unchecked(&vcc->stats->rx);
35596 cell += ATM_CELL_PAYLOAD;
35597 }
35598
35599@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35600 if (iovb == NULL) {
35601 printk("nicstar%d: Out of iovec buffers.\n",
35602 card->index);
35603- atomic_inc(&vcc->stats->rx_drop);
35604+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35605 recycle_rx_buf(card, skb);
35606 return;
35607 }
35608@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35609 small or large buffer itself. */
35610 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35611 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35612- atomic_inc(&vcc->stats->rx_err);
35613+ atomic_inc_unchecked(&vcc->stats->rx_err);
35614 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35615 NS_MAX_IOVECS);
35616 NS_PRV_IOVCNT(iovb) = 0;
35617@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35618 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35619 card->index);
35620 which_list(card, skb);
35621- atomic_inc(&vcc->stats->rx_err);
35622+ atomic_inc_unchecked(&vcc->stats->rx_err);
35623 recycle_rx_buf(card, skb);
35624 vc->rx_iov = NULL;
35625 recycle_iov_buf(card, iovb);
35626@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35627 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35628 card->index);
35629 which_list(card, skb);
35630- atomic_inc(&vcc->stats->rx_err);
35631+ atomic_inc_unchecked(&vcc->stats->rx_err);
35632 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35633 NS_PRV_IOVCNT(iovb));
35634 vc->rx_iov = NULL;
35635@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35636 printk(" - PDU size mismatch.\n");
35637 else
35638 printk(".\n");
35639- atomic_inc(&vcc->stats->rx_err);
35640+ atomic_inc_unchecked(&vcc->stats->rx_err);
35641 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35642 NS_PRV_IOVCNT(iovb));
35643 vc->rx_iov = NULL;
35644@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35645 /* skb points to a small buffer */
35646 if (!atm_charge(vcc, skb->truesize)) {
35647 push_rxbufs(card, skb);
35648- atomic_inc(&vcc->stats->rx_drop);
35649+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35650 } else {
35651 skb_put(skb, len);
35652 dequeue_sm_buf(card, skb);
35653@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35654 ATM_SKB(skb)->vcc = vcc;
35655 __net_timestamp(skb);
35656 vcc->push(vcc, skb);
35657- atomic_inc(&vcc->stats->rx);
35658+ atomic_inc_unchecked(&vcc->stats->rx);
35659 }
35660 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35661 struct sk_buff *sb;
35662@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35663 if (len <= NS_SMBUFSIZE) {
35664 if (!atm_charge(vcc, sb->truesize)) {
35665 push_rxbufs(card, sb);
35666- atomic_inc(&vcc->stats->rx_drop);
35667+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35668 } else {
35669 skb_put(sb, len);
35670 dequeue_sm_buf(card, sb);
35671@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35672 ATM_SKB(sb)->vcc = vcc;
35673 __net_timestamp(sb);
35674 vcc->push(vcc, sb);
35675- atomic_inc(&vcc->stats->rx);
35676+ atomic_inc_unchecked(&vcc->stats->rx);
35677 }
35678
35679 push_rxbufs(card, skb);
35680@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35681
35682 if (!atm_charge(vcc, skb->truesize)) {
35683 push_rxbufs(card, skb);
35684- atomic_inc(&vcc->stats->rx_drop);
35685+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35686 } else {
35687 dequeue_lg_buf(card, skb);
35688 #ifdef NS_USE_DESTRUCTORS
35689@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35690 ATM_SKB(skb)->vcc = vcc;
35691 __net_timestamp(skb);
35692 vcc->push(vcc, skb);
35693- atomic_inc(&vcc->stats->rx);
35694+ atomic_inc_unchecked(&vcc->stats->rx);
35695 }
35696
35697 push_rxbufs(card, sb);
35698@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35699 printk
35700 ("nicstar%d: Out of huge buffers.\n",
35701 card->index);
35702- atomic_inc(&vcc->stats->rx_drop);
35703+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35704 recycle_iovec_rx_bufs(card,
35705 (struct iovec *)
35706 iovb->data,
35707@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35708 card->hbpool.count++;
35709 } else
35710 dev_kfree_skb_any(hb);
35711- atomic_inc(&vcc->stats->rx_drop);
35712+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35713 } else {
35714 /* Copy the small buffer to the huge buffer */
35715 sb = (struct sk_buff *)iov->iov_base;
35716@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35717 #endif /* NS_USE_DESTRUCTORS */
35718 __net_timestamp(hb);
35719 vcc->push(vcc, hb);
35720- atomic_inc(&vcc->stats->rx);
35721+ atomic_inc_unchecked(&vcc->stats->rx);
35722 }
35723 }
35724
35725diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35726index 32784d1..4a8434a 100644
35727--- a/drivers/atm/solos-pci.c
35728+++ b/drivers/atm/solos-pci.c
35729@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35730 }
35731 atm_charge(vcc, skb->truesize);
35732 vcc->push(vcc, skb);
35733- atomic_inc(&vcc->stats->rx);
35734+ atomic_inc_unchecked(&vcc->stats->rx);
35735 break;
35736
35737 case PKT_STATUS:
35738@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35739 vcc = SKB_CB(oldskb)->vcc;
35740
35741 if (vcc) {
35742- atomic_inc(&vcc->stats->tx);
35743+ atomic_inc_unchecked(&vcc->stats->tx);
35744 solos_pop(vcc, oldskb);
35745 } else {
35746 dev_kfree_skb_irq(oldskb);
35747diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35748index 0215934..ce9f5b1 100644
35749--- a/drivers/atm/suni.c
35750+++ b/drivers/atm/suni.c
35751@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35752
35753
35754 #define ADD_LIMITED(s,v) \
35755- atomic_add((v),&stats->s); \
35756- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35757+ atomic_add_unchecked((v),&stats->s); \
35758+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35759
35760
35761 static void suni_hz(unsigned long from_timer)
35762diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35763index 5120a96..e2572bd 100644
35764--- a/drivers/atm/uPD98402.c
35765+++ b/drivers/atm/uPD98402.c
35766@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35767 struct sonet_stats tmp;
35768 int error = 0;
35769
35770- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35771+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35772 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35773 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35774 if (zero && !error) {
35775@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35776
35777
35778 #define ADD_LIMITED(s,v) \
35779- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35780- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35781- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35782+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35783+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35784+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35785
35786
35787 static void stat_event(struct atm_dev *dev)
35788@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35789 if (reason & uPD98402_INT_PFM) stat_event(dev);
35790 if (reason & uPD98402_INT_PCO) {
35791 (void) GET(PCOCR); /* clear interrupt cause */
35792- atomic_add(GET(HECCT),
35793+ atomic_add_unchecked(GET(HECCT),
35794 &PRIV(dev)->sonet_stats.uncorr_hcs);
35795 }
35796 if ((reason & uPD98402_INT_RFO) &&
35797@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35798 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35799 uPD98402_INT_LOS),PIMR); /* enable them */
35800 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35801- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35802- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35803- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35804+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35805+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35806+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35807 return 0;
35808 }
35809
35810diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35811index 969c3c2..9b72956 100644
35812--- a/drivers/atm/zatm.c
35813+++ b/drivers/atm/zatm.c
35814@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35815 }
35816 if (!size) {
35817 dev_kfree_skb_irq(skb);
35818- if (vcc) atomic_inc(&vcc->stats->rx_err);
35819+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35820 continue;
35821 }
35822 if (!atm_charge(vcc,skb->truesize)) {
35823@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35824 skb->len = size;
35825 ATM_SKB(skb)->vcc = vcc;
35826 vcc->push(vcc,skb);
35827- atomic_inc(&vcc->stats->rx);
35828+ atomic_inc_unchecked(&vcc->stats->rx);
35829 }
35830 zout(pos & 0xffff,MTA(mbx));
35831 #if 0 /* probably a stupid idea */
35832@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35833 skb_queue_head(&zatm_vcc->backlog,skb);
35834 break;
35835 }
35836- atomic_inc(&vcc->stats->tx);
35837+ atomic_inc_unchecked(&vcc->stats->tx);
35838 wake_up(&zatm_vcc->tx_wait);
35839 }
35840
35841diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35842index d414331..b4dd4ba 100644
35843--- a/drivers/base/bus.c
35844+++ b/drivers/base/bus.c
35845@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35846 return -EINVAL;
35847
35848 mutex_lock(&subsys->p->mutex);
35849- list_add_tail(&sif->node, &subsys->p->interfaces);
35850+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35851 if (sif->add_dev) {
35852 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35853 while ((dev = subsys_dev_iter_next(&iter)))
35854@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35855 subsys = sif->subsys;
35856
35857 mutex_lock(&subsys->p->mutex);
35858- list_del_init(&sif->node);
35859+ pax_list_del_init((struct list_head *)&sif->node);
35860 if (sif->remove_dev) {
35861 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35862 while ((dev = subsys_dev_iter_next(&iter)))
35863diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35864index 7413d06..79155fa 100644
35865--- a/drivers/base/devtmpfs.c
35866+++ b/drivers/base/devtmpfs.c
35867@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35868 if (!thread)
35869 return 0;
35870
35871- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35872+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35873 if (err)
35874 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35875 else
35876@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35877 *err = sys_unshare(CLONE_NEWNS);
35878 if (*err)
35879 goto out;
35880- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35881+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35882 if (*err)
35883 goto out;
35884- sys_chdir("/.."); /* will traverse into overmounted root */
35885- sys_chroot(".");
35886+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35887+ sys_chroot((char __force_user *)".");
35888 complete(&setup_done);
35889 while (1) {
35890 spin_lock(&req_lock);
35891diff --git a/drivers/base/node.c b/drivers/base/node.c
35892index 7616a77c..8f57f51 100644
35893--- a/drivers/base/node.c
35894+++ b/drivers/base/node.c
35895@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35896 struct node_attr {
35897 struct device_attribute attr;
35898 enum node_states state;
35899-};
35900+} __do_const;
35901
35902 static ssize_t show_node_state(struct device *dev,
35903 struct device_attribute *attr, char *buf)
35904diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35905index bfb8955..42c9b9a 100644
35906--- a/drivers/base/power/domain.c
35907+++ b/drivers/base/power/domain.c
35908@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35909 {
35910 struct cpuidle_driver *cpuidle_drv;
35911 struct gpd_cpu_data *cpu_data;
35912- struct cpuidle_state *idle_state;
35913+ cpuidle_state_no_const *idle_state;
35914 int ret = 0;
35915
35916 if (IS_ERR_OR_NULL(genpd) || state < 0)
35917@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35918 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35919 {
35920 struct gpd_cpu_data *cpu_data;
35921- struct cpuidle_state *idle_state;
35922+ cpuidle_state_no_const *idle_state;
35923 int ret = 0;
35924
35925 if (IS_ERR_OR_NULL(genpd))
35926diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35927index a53ebd2..8f73eeb 100644
35928--- a/drivers/base/power/sysfs.c
35929+++ b/drivers/base/power/sysfs.c
35930@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35931 return -EIO;
35932 }
35933 }
35934- return sprintf(buf, p);
35935+ return sprintf(buf, "%s", p);
35936 }
35937
35938 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35939diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35940index 2d56f41..8830f19 100644
35941--- a/drivers/base/power/wakeup.c
35942+++ b/drivers/base/power/wakeup.c
35943@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35944 * They need to be modified together atomically, so it's better to use one
35945 * atomic variable to hold them both.
35946 */
35947-static atomic_t combined_event_count = ATOMIC_INIT(0);
35948+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35949
35950 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35951 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35952
35953 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35954 {
35955- unsigned int comb = atomic_read(&combined_event_count);
35956+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35957
35958 *cnt = (comb >> IN_PROGRESS_BITS);
35959 *inpr = comb & MAX_IN_PROGRESS;
35960@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35961 ws->start_prevent_time = ws->last_time;
35962
35963 /* Increment the counter of events in progress. */
35964- cec = atomic_inc_return(&combined_event_count);
35965+ cec = atomic_inc_return_unchecked(&combined_event_count);
35966
35967 trace_wakeup_source_activate(ws->name, cec);
35968 }
35969@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35970 * Increment the counter of registered wakeup events and decrement the
35971 * couter of wakeup events in progress simultaneously.
35972 */
35973- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35974+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35975 trace_wakeup_source_deactivate(ws->name, cec);
35976
35977 split_counters(&cnt, &inpr);
35978diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35979index e8d11b6..7b1b36f 100644
35980--- a/drivers/base/syscore.c
35981+++ b/drivers/base/syscore.c
35982@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35983 void register_syscore_ops(struct syscore_ops *ops)
35984 {
35985 mutex_lock(&syscore_ops_lock);
35986- list_add_tail(&ops->node, &syscore_ops_list);
35987+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35988 mutex_unlock(&syscore_ops_lock);
35989 }
35990 EXPORT_SYMBOL_GPL(register_syscore_ops);
35991@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35992 void unregister_syscore_ops(struct syscore_ops *ops)
35993 {
35994 mutex_lock(&syscore_ops_lock);
35995- list_del(&ops->node);
35996+ pax_list_del((struct list_head *)&ops->node);
35997 mutex_unlock(&syscore_ops_lock);
35998 }
35999 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36000diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36001index 90a4e6b..002d10f 100644
36002--- a/drivers/block/cciss.c
36003+++ b/drivers/block/cciss.c
36004@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36005 while (!list_empty(&h->reqQ)) {
36006 c = list_entry(h->reqQ.next, CommandList_struct, list);
36007 /* can't do anything if fifo is full */
36008- if ((h->access.fifo_full(h))) {
36009+ if ((h->access->fifo_full(h))) {
36010 dev_warn(&h->pdev->dev, "fifo full\n");
36011 break;
36012 }
36013@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36014 h->Qdepth--;
36015
36016 /* Tell the controller execute command */
36017- h->access.submit_command(h, c);
36018+ h->access->submit_command(h, c);
36019
36020 /* Put job onto the completed Q */
36021 addQ(&h->cmpQ, c);
36022@@ -3447,17 +3447,17 @@ startio:
36023
36024 static inline unsigned long get_next_completion(ctlr_info_t *h)
36025 {
36026- return h->access.command_completed(h);
36027+ return h->access->command_completed(h);
36028 }
36029
36030 static inline int interrupt_pending(ctlr_info_t *h)
36031 {
36032- return h->access.intr_pending(h);
36033+ return h->access->intr_pending(h);
36034 }
36035
36036 static inline long interrupt_not_for_us(ctlr_info_t *h)
36037 {
36038- return ((h->access.intr_pending(h) == 0) ||
36039+ return ((h->access->intr_pending(h) == 0) ||
36040 (h->interrupts_enabled == 0));
36041 }
36042
36043@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36044 u32 a;
36045
36046 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36047- return h->access.command_completed(h);
36048+ return h->access->command_completed(h);
36049
36050 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36051 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36052@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36053 trans_support & CFGTBL_Trans_use_short_tags);
36054
36055 /* Change the access methods to the performant access methods */
36056- h->access = SA5_performant_access;
36057+ h->access = &SA5_performant_access;
36058 h->transMethod = CFGTBL_Trans_Performant;
36059
36060 return;
36061@@ -4320,7 +4320,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36062 if (prod_index < 0)
36063 return -ENODEV;
36064 h->product_name = products[prod_index].product_name;
36065- h->access = *(products[prod_index].access);
36066+ h->access = products[prod_index].access;
36067
36068 if (cciss_board_disabled(h)) {
36069 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36070@@ -5052,7 +5052,7 @@ reinit_after_soft_reset:
36071 }
36072
36073 /* make sure the board interrupts are off */
36074- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36075+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36076 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36077 if (rc)
36078 goto clean2;
36079@@ -5102,7 +5102,7 @@ reinit_after_soft_reset:
36080 * fake ones to scoop up any residual completions.
36081 */
36082 spin_lock_irqsave(&h->lock, flags);
36083- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36084+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36085 spin_unlock_irqrestore(&h->lock, flags);
36086 free_irq(h->intr[h->intr_mode], h);
36087 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36088@@ -5122,9 +5122,9 @@ reinit_after_soft_reset:
36089 dev_info(&h->pdev->dev, "Board READY.\n");
36090 dev_info(&h->pdev->dev,
36091 "Waiting for stale completions to drain.\n");
36092- h->access.set_intr_mask(h, CCISS_INTR_ON);
36093+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36094 msleep(10000);
36095- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36096+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36097
36098 rc = controller_reset_failed(h->cfgtable);
36099 if (rc)
36100@@ -5147,7 +5147,7 @@ reinit_after_soft_reset:
36101 cciss_scsi_setup(h);
36102
36103 /* Turn the interrupts on so we can service requests */
36104- h->access.set_intr_mask(h, CCISS_INTR_ON);
36105+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36106
36107 /* Get the firmware version */
36108 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36109@@ -5219,7 +5219,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36110 kfree(flush_buf);
36111 if (return_code != IO_OK)
36112 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36113- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36114+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36115 free_irq(h->intr[h->intr_mode], h);
36116 }
36117
36118diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36119index 7fda30e..eb5dfe0 100644
36120--- a/drivers/block/cciss.h
36121+++ b/drivers/block/cciss.h
36122@@ -101,7 +101,7 @@ struct ctlr_info
36123 /* information about each logical volume */
36124 drive_info_struct *drv[CISS_MAX_LUN];
36125
36126- struct access_method access;
36127+ struct access_method *access;
36128
36129 /* queue and queue Info */
36130 struct list_head reqQ;
36131diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36132index 2b94403..fd6ad1f 100644
36133--- a/drivers/block/cpqarray.c
36134+++ b/drivers/block/cpqarray.c
36135@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36136 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36137 goto Enomem4;
36138 }
36139- hba[i]->access.set_intr_mask(hba[i], 0);
36140+ hba[i]->access->set_intr_mask(hba[i], 0);
36141 if (request_irq(hba[i]->intr, do_ida_intr,
36142 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36143 {
36144@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36145 add_timer(&hba[i]->timer);
36146
36147 /* Enable IRQ now that spinlock and rate limit timer are set up */
36148- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36149+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36150
36151 for(j=0; j<NWD; j++) {
36152 struct gendisk *disk = ida_gendisk[i][j];
36153@@ -694,7 +694,7 @@ DBGINFO(
36154 for(i=0; i<NR_PRODUCTS; i++) {
36155 if (board_id == products[i].board_id) {
36156 c->product_name = products[i].product_name;
36157- c->access = *(products[i].access);
36158+ c->access = products[i].access;
36159 break;
36160 }
36161 }
36162@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36163 hba[ctlr]->intr = intr;
36164 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36165 hba[ctlr]->product_name = products[j].product_name;
36166- hba[ctlr]->access = *(products[j].access);
36167+ hba[ctlr]->access = products[j].access;
36168 hba[ctlr]->ctlr = ctlr;
36169 hba[ctlr]->board_id = board_id;
36170 hba[ctlr]->pci_dev = NULL; /* not PCI */
36171@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36172
36173 while((c = h->reqQ) != NULL) {
36174 /* Can't do anything if we're busy */
36175- if (h->access.fifo_full(h) == 0)
36176+ if (h->access->fifo_full(h) == 0)
36177 return;
36178
36179 /* Get the first entry from the request Q */
36180@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36181 h->Qdepth--;
36182
36183 /* Tell the controller to do our bidding */
36184- h->access.submit_command(h, c);
36185+ h->access->submit_command(h, c);
36186
36187 /* Get onto the completion Q */
36188 addQ(&h->cmpQ, c);
36189@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36190 unsigned long flags;
36191 __u32 a,a1;
36192
36193- istat = h->access.intr_pending(h);
36194+ istat = h->access->intr_pending(h);
36195 /* Is this interrupt for us? */
36196 if (istat == 0)
36197 return IRQ_NONE;
36198@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36199 */
36200 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36201 if (istat & FIFO_NOT_EMPTY) {
36202- while((a = h->access.command_completed(h))) {
36203+ while((a = h->access->command_completed(h))) {
36204 a1 = a; a &= ~3;
36205 if ((c = h->cmpQ) == NULL)
36206 {
36207@@ -1448,11 +1448,11 @@ static int sendcmd(
36208 /*
36209 * Disable interrupt
36210 */
36211- info_p->access.set_intr_mask(info_p, 0);
36212+ info_p->access->set_intr_mask(info_p, 0);
36213 /* Make sure there is room in the command FIFO */
36214 /* Actually it should be completely empty at this time. */
36215 for (i = 200000; i > 0; i--) {
36216- temp = info_p->access.fifo_full(info_p);
36217+ temp = info_p->access->fifo_full(info_p);
36218 if (temp != 0) {
36219 break;
36220 }
36221@@ -1465,7 +1465,7 @@ DBG(
36222 /*
36223 * Send the cmd
36224 */
36225- info_p->access.submit_command(info_p, c);
36226+ info_p->access->submit_command(info_p, c);
36227 complete = pollcomplete(ctlr);
36228
36229 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36230@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36231 * we check the new geometry. Then turn interrupts back on when
36232 * we're done.
36233 */
36234- host->access.set_intr_mask(host, 0);
36235+ host->access->set_intr_mask(host, 0);
36236 getgeometry(ctlr);
36237- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36238+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36239
36240 for(i=0; i<NWD; i++) {
36241 struct gendisk *disk = ida_gendisk[ctlr][i];
36242@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36243 /* Wait (up to 2 seconds) for a command to complete */
36244
36245 for (i = 200000; i > 0; i--) {
36246- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36247+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36248 if (done == 0) {
36249 udelay(10); /* a short fixed delay */
36250 } else
36251diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36252index be73e9d..7fbf140 100644
36253--- a/drivers/block/cpqarray.h
36254+++ b/drivers/block/cpqarray.h
36255@@ -99,7 +99,7 @@ struct ctlr_info {
36256 drv_info_t drv[NWD];
36257 struct proc_dir_entry *proc;
36258
36259- struct access_method access;
36260+ struct access_method *access;
36261
36262 cmdlist_t *reqQ;
36263 cmdlist_t *cmpQ;
36264diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36265index 2d7f608..11245fe 100644
36266--- a/drivers/block/drbd/drbd_int.h
36267+++ b/drivers/block/drbd/drbd_int.h
36268@@ -582,7 +582,7 @@ struct drbd_epoch {
36269 struct drbd_tconn *tconn;
36270 struct list_head list;
36271 unsigned int barrier_nr;
36272- atomic_t epoch_size; /* increased on every request added. */
36273+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36274 atomic_t active; /* increased on every req. added, and dec on every finished. */
36275 unsigned long flags;
36276 };
36277@@ -1022,7 +1022,7 @@ struct drbd_conf {
36278 unsigned int al_tr_number;
36279 int al_tr_cycle;
36280 wait_queue_head_t seq_wait;
36281- atomic_t packet_seq;
36282+ atomic_unchecked_t packet_seq;
36283 unsigned int peer_seq;
36284 spinlock_t peer_seq_lock;
36285 unsigned int minor;
36286@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36287 char __user *uoptval;
36288 int err;
36289
36290- uoptval = (char __user __force *)optval;
36291+ uoptval = (char __force_user *)optval;
36292
36293 set_fs(KERNEL_DS);
36294 if (level == SOL_SOCKET)
36295diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36296index 55635ed..40e837c 100644
36297--- a/drivers/block/drbd/drbd_main.c
36298+++ b/drivers/block/drbd/drbd_main.c
36299@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36300 p->sector = sector;
36301 p->block_id = block_id;
36302 p->blksize = blksize;
36303- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36304+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36305 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36306 }
36307
36308@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36309 return -EIO;
36310 p->sector = cpu_to_be64(req->i.sector);
36311 p->block_id = (unsigned long)req;
36312- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36313+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36314 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36315 if (mdev->state.conn >= C_SYNC_SOURCE &&
36316 mdev->state.conn <= C_PAUSED_SYNC_T)
36317@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36318 {
36319 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36320
36321- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36322- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36323+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36324+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36325 kfree(tconn->current_epoch);
36326
36327 idr_destroy(&tconn->volumes);
36328diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36329index 8cc1e64..ba7ffa9 100644
36330--- a/drivers/block/drbd/drbd_nl.c
36331+++ b/drivers/block/drbd/drbd_nl.c
36332@@ -3440,7 +3440,7 @@ out:
36333
36334 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36335 {
36336- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36337+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36338 struct sk_buff *msg;
36339 struct drbd_genlmsghdr *d_out;
36340 unsigned seq;
36341@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36342 return;
36343 }
36344
36345- seq = atomic_inc_return(&drbd_genl_seq);
36346+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36347 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36348 if (!msg)
36349 goto failed;
36350diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36351index cc29cd3..d4b058b 100644
36352--- a/drivers/block/drbd/drbd_receiver.c
36353+++ b/drivers/block/drbd/drbd_receiver.c
36354@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36355 {
36356 int err;
36357
36358- atomic_set(&mdev->packet_seq, 0);
36359+ atomic_set_unchecked(&mdev->packet_seq, 0);
36360 mdev->peer_seq = 0;
36361
36362 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36363@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36364 do {
36365 next_epoch = NULL;
36366
36367- epoch_size = atomic_read(&epoch->epoch_size);
36368+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36369
36370 switch (ev & ~EV_CLEANUP) {
36371 case EV_PUT:
36372@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36373 rv = FE_DESTROYED;
36374 } else {
36375 epoch->flags = 0;
36376- atomic_set(&epoch->epoch_size, 0);
36377+ atomic_set_unchecked(&epoch->epoch_size, 0);
36378 /* atomic_set(&epoch->active, 0); is already zero */
36379 if (rv == FE_STILL_LIVE)
36380 rv = FE_RECYCLED;
36381@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36382 conn_wait_active_ee_empty(tconn);
36383 drbd_flush(tconn);
36384
36385- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36386+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36387 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36388 if (epoch)
36389 break;
36390@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36391 }
36392
36393 epoch->flags = 0;
36394- atomic_set(&epoch->epoch_size, 0);
36395+ atomic_set_unchecked(&epoch->epoch_size, 0);
36396 atomic_set(&epoch->active, 0);
36397
36398 spin_lock(&tconn->epoch_lock);
36399- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36400+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36401 list_add(&epoch->list, &tconn->current_epoch->list);
36402 tconn->current_epoch = epoch;
36403 tconn->epochs++;
36404@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36405
36406 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36407 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36408- atomic_inc(&tconn->current_epoch->epoch_size);
36409+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36410 err2 = drbd_drain_block(mdev, pi->size);
36411 if (!err)
36412 err = err2;
36413@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36414
36415 spin_lock(&tconn->epoch_lock);
36416 peer_req->epoch = tconn->current_epoch;
36417- atomic_inc(&peer_req->epoch->epoch_size);
36418+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36419 atomic_inc(&peer_req->epoch->active);
36420 spin_unlock(&tconn->epoch_lock);
36421
36422@@ -4347,7 +4347,7 @@ struct data_cmd {
36423 int expect_payload;
36424 size_t pkt_size;
36425 int (*fn)(struct drbd_tconn *, struct packet_info *);
36426-};
36427+} __do_const;
36428
36429 static struct data_cmd drbd_cmd_handler[] = {
36430 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36431@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36432 if (!list_empty(&tconn->current_epoch->list))
36433 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36434 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36435- atomic_set(&tconn->current_epoch->epoch_size, 0);
36436+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36437 tconn->send.seen_any_write_yet = false;
36438
36439 conn_info(tconn, "Connection closed\n");
36440@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36441 struct asender_cmd {
36442 size_t pkt_size;
36443 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36444-};
36445+} __do_const;
36446
36447 static struct asender_cmd asender_tbl[] = {
36448 [P_PING] = { 0, got_Ping },
36449diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36450index 40e7155..df5c79a 100644
36451--- a/drivers/block/loop.c
36452+++ b/drivers/block/loop.c
36453@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36454
36455 file_start_write(file);
36456 set_fs(get_ds());
36457- bw = file->f_op->write(file, buf, len, &pos);
36458+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36459 set_fs(old_fs);
36460 file_end_write(file);
36461 if (likely(bw == len))
36462diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36463index f5d0ea1..c62380a 100644
36464--- a/drivers/block/pktcdvd.c
36465+++ b/drivers/block/pktcdvd.c
36466@@ -84,7 +84,7 @@
36467 #define MAX_SPEED 0xffff
36468
36469 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36470- ~(sector_t)((pd)->settings.size - 1))
36471+ ~(sector_t)((pd)->settings.size - 1UL))
36472
36473 static DEFINE_MUTEX(pktcdvd_mutex);
36474 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36475diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36476index 7332889..9ece19e 100644
36477--- a/drivers/bus/arm-cci.c
36478+++ b/drivers/bus/arm-cci.c
36479@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36480
36481 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36482
36483- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36484+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36485 if (!ports)
36486 return -ENOMEM;
36487
36488diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36489index 8a3aff7..d7538c2 100644
36490--- a/drivers/cdrom/cdrom.c
36491+++ b/drivers/cdrom/cdrom.c
36492@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36493 ENSURE(reset, CDC_RESET);
36494 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36495 cdi->mc_flags = 0;
36496- cdo->n_minors = 0;
36497 cdi->options = CDO_USE_FFLAGS;
36498
36499 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36500@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36501 else
36502 cdi->cdda_method = CDDA_OLD;
36503
36504- if (!cdo->generic_packet)
36505- cdo->generic_packet = cdrom_dummy_generic_packet;
36506+ if (!cdo->generic_packet) {
36507+ pax_open_kernel();
36508+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36509+ pax_close_kernel();
36510+ }
36511
36512 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36513 mutex_lock(&cdrom_mutex);
36514@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36515 if (cdi->exit)
36516 cdi->exit(cdi);
36517
36518- cdi->ops->n_minors--;
36519 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36520 }
36521
36522@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36523 */
36524 nr = nframes;
36525 do {
36526- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36527+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36528 if (cgc.buffer)
36529 break;
36530
36531@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36532 struct cdrom_device_info *cdi;
36533 int ret;
36534
36535- ret = scnprintf(info + *pos, max_size - *pos, header);
36536+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36537 if (!ret)
36538 return 1;
36539
36540diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36541index 5980cb9..6d7bd7e 100644
36542--- a/drivers/cdrom/gdrom.c
36543+++ b/drivers/cdrom/gdrom.c
36544@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36545 .audio_ioctl = gdrom_audio_ioctl,
36546 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36547 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36548- .n_minors = 1,
36549 };
36550
36551 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36552diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36553index 1421997..33f5d6d 100644
36554--- a/drivers/char/Kconfig
36555+++ b/drivers/char/Kconfig
36556@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36557
36558 config DEVKMEM
36559 bool "/dev/kmem virtual device support"
36560- default y
36561+ default n
36562+ depends on !GRKERNSEC_KMEM
36563 help
36564 Say Y here if you want to support the /dev/kmem device. The
36565 /dev/kmem device is rarely used, but can be used for certain
36566@@ -570,6 +571,7 @@ config DEVPORT
36567 bool
36568 depends on !M68K
36569 depends on ISA || PCI
36570+ depends on !GRKERNSEC_KMEM
36571 default y
36572
36573 source "drivers/s390/char/Kconfig"
36574diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36575index a48e05b..6bac831 100644
36576--- a/drivers/char/agp/compat_ioctl.c
36577+++ b/drivers/char/agp/compat_ioctl.c
36578@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36579 return -ENOMEM;
36580 }
36581
36582- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36583+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36584 sizeof(*usegment) * ureserve.seg_count)) {
36585 kfree(usegment);
36586 kfree(ksegment);
36587diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36588index 1b19239..b87b143 100644
36589--- a/drivers/char/agp/frontend.c
36590+++ b/drivers/char/agp/frontend.c
36591@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36592 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36593 return -EFAULT;
36594
36595- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36596+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36597 return -EFAULT;
36598
36599 client = agp_find_client_by_pid(reserve.pid);
36600@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36601 if (segment == NULL)
36602 return -ENOMEM;
36603
36604- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36605+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36606 sizeof(struct agp_segment) * reserve.seg_count)) {
36607 kfree(segment);
36608 return -EFAULT;
36609diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36610index 4f94375..413694e 100644
36611--- a/drivers/char/genrtc.c
36612+++ b/drivers/char/genrtc.c
36613@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36614 switch (cmd) {
36615
36616 case RTC_PLL_GET:
36617+ memset(&pll, 0, sizeof(pll));
36618 if (get_rtc_pll(&pll))
36619 return -EINVAL;
36620 else
36621diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36622index 448ce5e..3a76625 100644
36623--- a/drivers/char/hpet.c
36624+++ b/drivers/char/hpet.c
36625@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36626 }
36627
36628 static int
36629-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36630+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36631 struct hpet_info *info)
36632 {
36633 struct hpet_timer __iomem *timer;
36634diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36635index 86fe45c..c0ea948 100644
36636--- a/drivers/char/hw_random/intel-rng.c
36637+++ b/drivers/char/hw_random/intel-rng.c
36638@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36639
36640 if (no_fwh_detect)
36641 return -ENODEV;
36642- printk(warning);
36643+ printk("%s", warning);
36644 return -EBUSY;
36645 }
36646
36647diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36648index 4445fa1..7c6de37 100644
36649--- a/drivers/char/ipmi/ipmi_msghandler.c
36650+++ b/drivers/char/ipmi/ipmi_msghandler.c
36651@@ -420,7 +420,7 @@ struct ipmi_smi {
36652 struct proc_dir_entry *proc_dir;
36653 char proc_dir_name[10];
36654
36655- atomic_t stats[IPMI_NUM_STATS];
36656+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36657
36658 /*
36659 * run_to_completion duplicate of smb_info, smi_info
36660@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36661
36662
36663 #define ipmi_inc_stat(intf, stat) \
36664- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36665+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36666 #define ipmi_get_stat(intf, stat) \
36667- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36668+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36669
36670 static int is_lan_addr(struct ipmi_addr *addr)
36671 {
36672@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36673 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36674 init_waitqueue_head(&intf->waitq);
36675 for (i = 0; i < IPMI_NUM_STATS; i++)
36676- atomic_set(&intf->stats[i], 0);
36677+ atomic_set_unchecked(&intf->stats[i], 0);
36678
36679 intf->proc_dir = NULL;
36680
36681diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36682index af4b23f..79806fc 100644
36683--- a/drivers/char/ipmi/ipmi_si_intf.c
36684+++ b/drivers/char/ipmi/ipmi_si_intf.c
36685@@ -275,7 +275,7 @@ struct smi_info {
36686 unsigned char slave_addr;
36687
36688 /* Counters and things for the proc filesystem. */
36689- atomic_t stats[SI_NUM_STATS];
36690+ atomic_unchecked_t stats[SI_NUM_STATS];
36691
36692 struct task_struct *thread;
36693
36694@@ -284,9 +284,9 @@ struct smi_info {
36695 };
36696
36697 #define smi_inc_stat(smi, stat) \
36698- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36699+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36700 #define smi_get_stat(smi, stat) \
36701- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36702+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36703
36704 #define SI_MAX_PARMS 4
36705
36706@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36707 atomic_set(&new_smi->req_events, 0);
36708 new_smi->run_to_completion = 0;
36709 for (i = 0; i < SI_NUM_STATS; i++)
36710- atomic_set(&new_smi->stats[i], 0);
36711+ atomic_set_unchecked(&new_smi->stats[i], 0);
36712
36713 new_smi->interrupt_disabled = 1;
36714 atomic_set(&new_smi->stop_operation, 0);
36715diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36716index f895a8c..2bc9147 100644
36717--- a/drivers/char/mem.c
36718+++ b/drivers/char/mem.c
36719@@ -18,6 +18,7 @@
36720 #include <linux/raw.h>
36721 #include <linux/tty.h>
36722 #include <linux/capability.h>
36723+#include <linux/security.h>
36724 #include <linux/ptrace.h>
36725 #include <linux/device.h>
36726 #include <linux/highmem.h>
36727@@ -37,6 +38,10 @@
36728
36729 #define DEVPORT_MINOR 4
36730
36731+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36732+extern const struct file_operations grsec_fops;
36733+#endif
36734+
36735 static inline unsigned long size_inside_page(unsigned long start,
36736 unsigned long size)
36737 {
36738@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36739
36740 while (cursor < to) {
36741 if (!devmem_is_allowed(pfn)) {
36742+#ifdef CONFIG_GRKERNSEC_KMEM
36743+ gr_handle_mem_readwrite(from, to);
36744+#else
36745 printk(KERN_INFO
36746 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36747 current->comm, from, to);
36748+#endif
36749 return 0;
36750 }
36751 cursor += PAGE_SIZE;
36752@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36753 }
36754 return 1;
36755 }
36756+#elif defined(CONFIG_GRKERNSEC_KMEM)
36757+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36758+{
36759+ return 0;
36760+}
36761 #else
36762 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36763 {
36764@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36765
36766 while (count > 0) {
36767 unsigned long remaining;
36768+ char *temp;
36769
36770 sz = size_inside_page(p, count);
36771
36772@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36773 if (!ptr)
36774 return -EFAULT;
36775
36776- remaining = copy_to_user(buf, ptr, sz);
36777+#ifdef CONFIG_PAX_USERCOPY
36778+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36779+ if (!temp) {
36780+ unxlate_dev_mem_ptr(p, ptr);
36781+ return -ENOMEM;
36782+ }
36783+ memcpy(temp, ptr, sz);
36784+#else
36785+ temp = ptr;
36786+#endif
36787+
36788+ remaining = copy_to_user(buf, temp, sz);
36789+
36790+#ifdef CONFIG_PAX_USERCOPY
36791+ kfree(temp);
36792+#endif
36793+
36794 unxlate_dev_mem_ptr(p, ptr);
36795 if (remaining)
36796 return -EFAULT;
36797@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36798 size_t count, loff_t *ppos)
36799 {
36800 unsigned long p = *ppos;
36801- ssize_t low_count, read, sz;
36802+ ssize_t low_count, read, sz, err = 0;
36803 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36804- int err = 0;
36805
36806 read = 0;
36807 if (p < (unsigned long) high_memory) {
36808@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36809 }
36810 #endif
36811 while (low_count > 0) {
36812+ char *temp;
36813+
36814 sz = size_inside_page(p, low_count);
36815
36816 /*
36817@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36818 */
36819 kbuf = xlate_dev_kmem_ptr((char *)p);
36820
36821- if (copy_to_user(buf, kbuf, sz))
36822+#ifdef CONFIG_PAX_USERCOPY
36823+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36824+ if (!temp)
36825+ return -ENOMEM;
36826+ memcpy(temp, kbuf, sz);
36827+#else
36828+ temp = kbuf;
36829+#endif
36830+
36831+ err = copy_to_user(buf, temp, sz);
36832+
36833+#ifdef CONFIG_PAX_USERCOPY
36834+ kfree(temp);
36835+#endif
36836+
36837+ if (err)
36838 return -EFAULT;
36839 buf += sz;
36840 p += sz;
36841@@ -822,6 +869,9 @@ static const struct memdev {
36842 #ifdef CONFIG_PRINTK
36843 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36844 #endif
36845+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36846+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36847+#endif
36848 };
36849
36850 static int memory_open(struct inode *inode, struct file *filp)
36851@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36852 continue;
36853
36854 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36855- NULL, devlist[minor].name);
36856+ NULL, "%s", devlist[minor].name);
36857 }
36858
36859 return tty_init();
36860diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36861index 9df78e2..01ba9ae 100644
36862--- a/drivers/char/nvram.c
36863+++ b/drivers/char/nvram.c
36864@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36865
36866 spin_unlock_irq(&rtc_lock);
36867
36868- if (copy_to_user(buf, contents, tmp - contents))
36869+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36870 return -EFAULT;
36871
36872 *ppos = i;
36873diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36874index 5c5cc00..ac9edb7 100644
36875--- a/drivers/char/pcmcia/synclink_cs.c
36876+++ b/drivers/char/pcmcia/synclink_cs.c
36877@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36878
36879 if (debug_level >= DEBUG_LEVEL_INFO)
36880 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36881- __FILE__, __LINE__, info->device_name, port->count);
36882+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36883
36884- WARN_ON(!port->count);
36885+ WARN_ON(!atomic_read(&port->count));
36886
36887 if (tty_port_close_start(port, tty, filp) == 0)
36888 goto cleanup;
36889@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36890 cleanup:
36891 if (debug_level >= DEBUG_LEVEL_INFO)
36892 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36893- tty->driver->name, port->count);
36894+ tty->driver->name, atomic_read(&port->count));
36895 }
36896
36897 /* Wait until the transmitter is empty.
36898@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36899
36900 if (debug_level >= DEBUG_LEVEL_INFO)
36901 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36902- __FILE__, __LINE__, tty->driver->name, port->count);
36903+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36904
36905 /* If port is closing, signal caller to try again */
36906 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36907@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36908 goto cleanup;
36909 }
36910 spin_lock(&port->lock);
36911- port->count++;
36912+ atomic_inc(&port->count);
36913 spin_unlock(&port->lock);
36914 spin_unlock_irqrestore(&info->netlock, flags);
36915
36916- if (port->count == 1) {
36917+ if (atomic_read(&port->count) == 1) {
36918 /* 1st open on this device, init hardware */
36919 retval = startup(info, tty);
36920 if (retval < 0)
36921@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36922 unsigned short new_crctype;
36923
36924 /* return error if TTY interface open */
36925- if (info->port.count)
36926+ if (atomic_read(&info->port.count))
36927 return -EBUSY;
36928
36929 switch (encoding)
36930@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36931
36932 /* arbitrate between network and tty opens */
36933 spin_lock_irqsave(&info->netlock, flags);
36934- if (info->port.count != 0 || info->netcount != 0) {
36935+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36936 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36937 spin_unlock_irqrestore(&info->netlock, flags);
36938 return -EBUSY;
36939@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36940 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36941
36942 /* return error if TTY interface open */
36943- if (info->port.count)
36944+ if (atomic_read(&info->port.count))
36945 return -EBUSY;
36946
36947 if (cmd != SIOCWANDEV)
36948diff --git a/drivers/char/random.c b/drivers/char/random.c
36949index 0d91fe5..f8e37b0 100644
36950--- a/drivers/char/random.c
36951+++ b/drivers/char/random.c
36952@@ -272,8 +272,13 @@
36953 /*
36954 * Configuration information
36955 */
36956+#ifdef CONFIG_GRKERNSEC_RANDNET
36957+#define INPUT_POOL_WORDS 512
36958+#define OUTPUT_POOL_WORDS 128
36959+#else
36960 #define INPUT_POOL_WORDS 128
36961 #define OUTPUT_POOL_WORDS 32
36962+#endif
36963 #define SEC_XFER_SIZE 512
36964 #define EXTRACT_SIZE 10
36965
36966@@ -313,10 +318,17 @@ static struct poolinfo {
36967 int poolwords;
36968 int tap1, tap2, tap3, tap4, tap5;
36969 } poolinfo_table[] = {
36970+#ifdef CONFIG_GRKERNSEC_RANDNET
36971+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36972+ { 512, 411, 308, 208, 104, 1 },
36973+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36974+ { 128, 103, 76, 51, 25, 1 },
36975+#else
36976 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36977 { 128, 103, 76, 51, 25, 1 },
36978 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36979 { 32, 26, 20, 14, 7, 1 },
36980+#endif
36981 #if 0
36982 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36983 { 2048, 1638, 1231, 819, 411, 1 },
36984@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36985 input_rotate += i ? 7 : 14;
36986 }
36987
36988- ACCESS_ONCE(r->input_rotate) = input_rotate;
36989- ACCESS_ONCE(r->add_ptr) = i;
36990+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36991+ ACCESS_ONCE_RW(r->add_ptr) = i;
36992 smp_wmb();
36993
36994 if (out)
36995@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36996
36997 extract_buf(r, tmp);
36998 i = min_t(int, nbytes, EXTRACT_SIZE);
36999- if (copy_to_user(buf, tmp, i)) {
37000+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37001 ret = -EFAULT;
37002 break;
37003 }
37004@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37005 #include <linux/sysctl.h>
37006
37007 static int min_read_thresh = 8, min_write_thresh;
37008-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37009+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37010 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37011 static char sysctl_bootid[16];
37012
37013@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
37014 static int proc_do_uuid(struct ctl_table *table, int write,
37015 void __user *buffer, size_t *lenp, loff_t *ppos)
37016 {
37017- struct ctl_table fake_table;
37018+ ctl_table_no_const fake_table;
37019 unsigned char buf[64], tmp_uuid[16], *uuid;
37020
37021 uuid = table->data;
37022diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37023index bf2349db..5456d53 100644
37024--- a/drivers/char/sonypi.c
37025+++ b/drivers/char/sonypi.c
37026@@ -54,6 +54,7 @@
37027
37028 #include <asm/uaccess.h>
37029 #include <asm/io.h>
37030+#include <asm/local.h>
37031
37032 #include <linux/sonypi.h>
37033
37034@@ -490,7 +491,7 @@ static struct sonypi_device {
37035 spinlock_t fifo_lock;
37036 wait_queue_head_t fifo_proc_list;
37037 struct fasync_struct *fifo_async;
37038- int open_count;
37039+ local_t open_count;
37040 int model;
37041 struct input_dev *input_jog_dev;
37042 struct input_dev *input_key_dev;
37043@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37044 static int sonypi_misc_release(struct inode *inode, struct file *file)
37045 {
37046 mutex_lock(&sonypi_device.lock);
37047- sonypi_device.open_count--;
37048+ local_dec(&sonypi_device.open_count);
37049 mutex_unlock(&sonypi_device.lock);
37050 return 0;
37051 }
37052@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37053 {
37054 mutex_lock(&sonypi_device.lock);
37055 /* Flush input queue on first open */
37056- if (!sonypi_device.open_count)
37057+ if (!local_read(&sonypi_device.open_count))
37058 kfifo_reset(&sonypi_device.fifo);
37059- sonypi_device.open_count++;
37060+ local_inc(&sonypi_device.open_count);
37061 mutex_unlock(&sonypi_device.lock);
37062
37063 return 0;
37064diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37065index 64420b3..5c40b56 100644
37066--- a/drivers/char/tpm/tpm_acpi.c
37067+++ b/drivers/char/tpm/tpm_acpi.c
37068@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37069 virt = acpi_os_map_memory(start, len);
37070 if (!virt) {
37071 kfree(log->bios_event_log);
37072+ log->bios_event_log = NULL;
37073 printk("%s: ERROR - Unable to map memory\n", __func__);
37074 return -EIO;
37075 }
37076
37077- memcpy_fromio(log->bios_event_log, virt, len);
37078+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37079
37080 acpi_os_unmap_memory(virt, len);
37081 return 0;
37082diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37083index 84ddc55..1d32f1e 100644
37084--- a/drivers/char/tpm/tpm_eventlog.c
37085+++ b/drivers/char/tpm/tpm_eventlog.c
37086@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37087 event = addr;
37088
37089 if ((event->event_type == 0 && event->event_size == 0) ||
37090- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37091+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37092 return NULL;
37093
37094 return addr;
37095@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37096 return NULL;
37097
37098 if ((event->event_type == 0 && event->event_size == 0) ||
37099- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37100+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37101 return NULL;
37102
37103 (*pos)++;
37104@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37105 int i;
37106
37107 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37108- seq_putc(m, data[i]);
37109+ if (!seq_putc(m, data[i]))
37110+ return -EFAULT;
37111
37112 return 0;
37113 }
37114diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37115index fc45567..fa2a590 100644
37116--- a/drivers/char/virtio_console.c
37117+++ b/drivers/char/virtio_console.c
37118@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37119 if (to_user) {
37120 ssize_t ret;
37121
37122- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37123+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37124 if (ret)
37125 return -EFAULT;
37126 } else {
37127@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37128 if (!port_has_data(port) && !port->host_connected)
37129 return 0;
37130
37131- return fill_readbuf(port, ubuf, count, true);
37132+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37133 }
37134
37135 static int wait_port_writable(struct port *port, bool nonblock)
37136diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37137index a33f46f..a720eed 100644
37138--- a/drivers/clk/clk-composite.c
37139+++ b/drivers/clk/clk-composite.c
37140@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37141 struct clk *clk;
37142 struct clk_init_data init;
37143 struct clk_composite *composite;
37144- struct clk_ops *clk_composite_ops;
37145+ clk_ops_no_const *clk_composite_ops;
37146
37147 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37148 if (!composite) {
37149diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37150index 5bb848c..f1d4fc9 100644
37151--- a/drivers/clk/socfpga/clk.c
37152+++ b/drivers/clk/socfpga/clk.c
37153@@ -22,6 +22,7 @@
37154 #include <linux/clk-provider.h>
37155 #include <linux/io.h>
37156 #include <linux/of.h>
37157+#include <asm/pgtable.h>
37158
37159 /* Clock Manager offsets */
37160 #define CLKMGR_CTRL 0x0
37161@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37162 streq(clk_name, "periph_pll") ||
37163 streq(clk_name, "sdram_pll")) {
37164 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37165- clk_pll_ops.enable = clk_gate_ops.enable;
37166- clk_pll_ops.disable = clk_gate_ops.disable;
37167+ pax_open_kernel();
37168+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37169+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37170+ pax_close_kernel();
37171 }
37172
37173 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37174@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37175 return parent_rate / div;
37176 }
37177
37178-static struct clk_ops gateclk_ops = {
37179+static clk_ops_no_const gateclk_ops __read_only = {
37180 .recalc_rate = socfpga_clk_recalc_rate,
37181 .get_parent = socfpga_clk_get_parent,
37182 .set_parent = socfpga_clk_set_parent,
37183diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
37184index 08ae128..c73fc2b 100644
37185--- a/drivers/connector/cn_proc.c
37186+++ b/drivers/connector/cn_proc.c
37187@@ -65,6 +65,7 @@ void proc_fork_connector(struct task_struct *task)
37188
37189 msg = (struct cn_msg *)buffer;
37190 ev = (struct proc_event *)msg->data;
37191+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37192 get_seq(&msg->seq, &ev->cpu);
37193 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37194 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37195@@ -80,6 +81,7 @@ void proc_fork_connector(struct task_struct *task)
37196 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37197 msg->ack = 0; /* not used */
37198 msg->len = sizeof(*ev);
37199+ msg->flags = 0; /* not used */
37200 /* If cn_netlink_send() failed, the data is not sent */
37201 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37202 }
37203@@ -96,6 +98,7 @@ void proc_exec_connector(struct task_struct *task)
37204
37205 msg = (struct cn_msg *)buffer;
37206 ev = (struct proc_event *)msg->data;
37207+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37208 get_seq(&msg->seq, &ev->cpu);
37209 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37210 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37211@@ -106,6 +109,7 @@ void proc_exec_connector(struct task_struct *task)
37212 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37213 msg->ack = 0; /* not used */
37214 msg->len = sizeof(*ev);
37215+ msg->flags = 0; /* not used */
37216 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37217 }
37218
37219@@ -122,6 +126,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37220
37221 msg = (struct cn_msg *)buffer;
37222 ev = (struct proc_event *)msg->data;
37223+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37224 ev->what = which_id;
37225 ev->event_data.id.process_pid = task->pid;
37226 ev->event_data.id.process_tgid = task->tgid;
37227@@ -145,6 +150,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37228 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37229 msg->ack = 0; /* not used */
37230 msg->len = sizeof(*ev);
37231+ msg->flags = 0; /* not used */
37232 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37233 }
37234
37235@@ -160,6 +166,7 @@ void proc_sid_connector(struct task_struct *task)
37236
37237 msg = (struct cn_msg *)buffer;
37238 ev = (struct proc_event *)msg->data;
37239+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37240 get_seq(&msg->seq, &ev->cpu);
37241 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37242 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37243@@ -170,6 +177,7 @@ void proc_sid_connector(struct task_struct *task)
37244 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37245 msg->ack = 0; /* not used */
37246 msg->len = sizeof(*ev);
37247+ msg->flags = 0; /* not used */
37248 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37249 }
37250
37251@@ -185,6 +193,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37252
37253 msg = (struct cn_msg *)buffer;
37254 ev = (struct proc_event *)msg->data;
37255+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37256 get_seq(&msg->seq, &ev->cpu);
37257 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37258 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37259@@ -203,6 +212,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37260 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37261 msg->ack = 0; /* not used */
37262 msg->len = sizeof(*ev);
37263+ msg->flags = 0; /* not used */
37264 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37265 }
37266
37267@@ -218,6 +228,7 @@ void proc_comm_connector(struct task_struct *task)
37268
37269 msg = (struct cn_msg *)buffer;
37270 ev = (struct proc_event *)msg->data;
37271+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37272 get_seq(&msg->seq, &ev->cpu);
37273 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37274 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37275@@ -229,6 +240,7 @@ void proc_comm_connector(struct task_struct *task)
37276 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37277 msg->ack = 0; /* not used */
37278 msg->len = sizeof(*ev);
37279+ msg->flags = 0; /* not used */
37280 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37281 }
37282
37283@@ -244,6 +256,7 @@ void proc_coredump_connector(struct task_struct *task)
37284
37285 msg = (struct cn_msg *)buffer;
37286 ev = (struct proc_event *)msg->data;
37287+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37288 get_seq(&msg->seq, &ev->cpu);
37289 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37290 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37291@@ -254,6 +267,7 @@ void proc_coredump_connector(struct task_struct *task)
37292 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37293 msg->ack = 0; /* not used */
37294 msg->len = sizeof(*ev);
37295+ msg->flags = 0; /* not used */
37296 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37297 }
37298
37299@@ -269,6 +283,7 @@ void proc_exit_connector(struct task_struct *task)
37300
37301 msg = (struct cn_msg *)buffer;
37302 ev = (struct proc_event *)msg->data;
37303+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37304 get_seq(&msg->seq, &ev->cpu);
37305 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37306 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37307@@ -281,6 +296,7 @@ void proc_exit_connector(struct task_struct *task)
37308 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37309 msg->ack = 0; /* not used */
37310 msg->len = sizeof(*ev);
37311+ msg->flags = 0; /* not used */
37312 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37313 }
37314
37315@@ -304,6 +320,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37316
37317 msg = (struct cn_msg *)buffer;
37318 ev = (struct proc_event *)msg->data;
37319+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37320 msg->seq = rcvd_seq;
37321 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37322 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37323@@ -313,6 +330,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37324 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37325 msg->ack = rcvd_ack + 1;
37326 msg->len = sizeof(*ev);
37327+ msg->flags = 0; /* not used */
37328 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37329 }
37330
37331diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
37332index 6ecfa75..0daa11e 100644
37333--- a/drivers/connector/connector.c
37334+++ b/drivers/connector/connector.c
37335@@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb)
37336 static void cn_rx_skb(struct sk_buff *__skb)
37337 {
37338 struct nlmsghdr *nlh;
37339- int err;
37340 struct sk_buff *skb;
37341+ int len, err;
37342
37343 skb = skb_get(__skb);
37344
37345 if (skb->len >= NLMSG_HDRLEN) {
37346 nlh = nlmsg_hdr(skb);
37347+ len = nlmsg_len(nlh);
37348
37349- if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
37350+ if (len < (int)sizeof(struct cn_msg) ||
37351 skb->len < nlh->nlmsg_len ||
37352- nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) {
37353+ len > CONNECTOR_MAX_MSG_SIZE) {
37354 kfree_skb(skb);
37355 return;
37356 }
37357diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37358index 3926402..37b580d 100644
37359--- a/drivers/cpufreq/acpi-cpufreq.c
37360+++ b/drivers/cpufreq/acpi-cpufreq.c
37361@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37362 return sprintf(buf, "%u\n", boost_enabled);
37363 }
37364
37365-static struct global_attr global_boost = __ATTR(boost, 0644,
37366+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37367 show_global_boost,
37368 store_global_boost);
37369
37370@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37371 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37372 per_cpu(acfreq_data, cpu) = data;
37373
37374- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37375- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37376+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37377+ pax_open_kernel();
37378+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37379+ pax_close_kernel();
37380+ }
37381
37382 result = acpi_processor_register_performance(data->acpi_data, cpu);
37383 if (result)
37384@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37385 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37386 break;
37387 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37388- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37389+ pax_open_kernel();
37390+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37391+ pax_close_kernel();
37392 policy->cur = get_cur_freq_on_cpu(cpu);
37393 break;
37394 default:
37395@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37396 acpi_processor_notify_smm(THIS_MODULE);
37397
37398 /* Check for APERF/MPERF support in hardware */
37399- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37400- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37401+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37402+ pax_open_kernel();
37403+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37404+ pax_close_kernel();
37405+ }
37406
37407 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37408 for (i = 0; i < perf->state_count; i++)
37409diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37410index f0a5e2b..0a7ee46 100644
37411--- a/drivers/cpufreq/cpufreq.c
37412+++ b/drivers/cpufreq/cpufreq.c
37413@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37414 return NOTIFY_OK;
37415 }
37416
37417-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37418+static struct notifier_block cpufreq_cpu_notifier = {
37419 .notifier_call = cpufreq_cpu_callback,
37420 };
37421
37422@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37423
37424 pr_debug("trying to register driver %s\n", driver_data->name);
37425
37426- if (driver_data->setpolicy)
37427- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37428+ if (driver_data->setpolicy) {
37429+ pax_open_kernel();
37430+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37431+ pax_close_kernel();
37432+ }
37433
37434 write_lock_irqsave(&cpufreq_driver_lock, flags);
37435 if (cpufreq_driver) {
37436diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37437index e59afaa..a53a3ff 100644
37438--- a/drivers/cpufreq/cpufreq_governor.c
37439+++ b/drivers/cpufreq/cpufreq_governor.c
37440@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37441 struct dbs_data *dbs_data;
37442 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37443 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37444- struct od_ops *od_ops = NULL;
37445+ const struct od_ops *od_ops = NULL;
37446 struct od_dbs_tuners *od_tuners = NULL;
37447 struct cs_dbs_tuners *cs_tuners = NULL;
37448 struct cpu_dbs_common_info *cpu_cdbs;
37449@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37450
37451 if ((cdata->governor == GOV_CONSERVATIVE) &&
37452 (!policy->governor->initialized)) {
37453- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37454+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37455
37456 cpufreq_register_notifier(cs_ops->notifier_block,
37457 CPUFREQ_TRANSITION_NOTIFIER);
37458@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37459
37460 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37461 (policy->governor->initialized == 1)) {
37462- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37463+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37464
37465 cpufreq_unregister_notifier(cs_ops->notifier_block,
37466 CPUFREQ_TRANSITION_NOTIFIER);
37467diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37468index d5f12b4..eb30af1 100644
37469--- a/drivers/cpufreq/cpufreq_governor.h
37470+++ b/drivers/cpufreq/cpufreq_governor.h
37471@@ -204,7 +204,7 @@ struct common_dbs_data {
37472 void (*exit)(struct dbs_data *dbs_data);
37473
37474 /* Governor specific ops, see below */
37475- void *gov_ops;
37476+ const void *gov_ops;
37477 };
37478
37479 /* Governer Per policy data */
37480@@ -224,7 +224,7 @@ struct od_ops {
37481 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37482 unsigned int freq_next, unsigned int relation);
37483 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37484-};
37485+} __no_const;
37486
37487 struct cs_ops {
37488 struct notifier_block *notifier_block;
37489diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37490index c087347..989aa2e 100644
37491--- a/drivers/cpufreq/cpufreq_ondemand.c
37492+++ b/drivers/cpufreq/cpufreq_ondemand.c
37493@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37494
37495 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37496
37497-static struct od_ops od_ops = {
37498+static struct od_ops od_ops __read_only = {
37499 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37500 .powersave_bias_target = generic_powersave_bias_target,
37501 .freq_increase = dbs_freq_increase,
37502@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37503 (struct cpufreq_policy *, unsigned int, unsigned int),
37504 unsigned int powersave_bias)
37505 {
37506- od_ops.powersave_bias_target = f;
37507+ pax_open_kernel();
37508+ *(void **)&od_ops.powersave_bias_target = f;
37509+ pax_close_kernel();
37510 od_set_powersave_bias(powersave_bias);
37511 }
37512 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37513
37514 void od_unregister_powersave_bias_handler(void)
37515 {
37516- od_ops.powersave_bias_target = generic_powersave_bias_target;
37517+ pax_open_kernel();
37518+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37519+ pax_close_kernel();
37520 od_set_powersave_bias(0);
37521 }
37522 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37523diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37524index d37568c..fbb19a1 100644
37525--- a/drivers/cpufreq/cpufreq_stats.c
37526+++ b/drivers/cpufreq/cpufreq_stats.c
37527@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37528 }
37529
37530 /* priority=1 so this will get called before cpufreq_remove_dev */
37531-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37532+static struct notifier_block cpufreq_stat_cpu_notifier = {
37533 .notifier_call = cpufreq_stat_cpu_callback,
37534 .priority = 1,
37535 };
37536diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37537index 9ee7817..17b658e 100644
37538--- a/drivers/cpufreq/p4-clockmod.c
37539+++ b/drivers/cpufreq/p4-clockmod.c
37540@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37541 case 0x0F: /* Core Duo */
37542 case 0x16: /* Celeron Core */
37543 case 0x1C: /* Atom */
37544- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37545+ pax_open_kernel();
37546+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37547+ pax_close_kernel();
37548 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37549 case 0x0D: /* Pentium M (Dothan) */
37550- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37551+ pax_open_kernel();
37552+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37553+ pax_close_kernel();
37554 /* fall through */
37555 case 0x09: /* Pentium M (Banias) */
37556 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37557@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37558
37559 /* on P-4s, the TSC runs with constant frequency independent whether
37560 * throttling is active or not. */
37561- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37562+ pax_open_kernel();
37563+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37564+ pax_close_kernel();
37565
37566 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37567 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37568diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37569index 880ee29..2445bc6 100644
37570--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37571+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37572@@ -18,14 +18,12 @@
37573 #include <asm/head.h>
37574 #include <asm/timer.h>
37575
37576-static struct cpufreq_driver *cpufreq_us3_driver;
37577-
37578 struct us3_freq_percpu_info {
37579 struct cpufreq_frequency_table table[4];
37580 };
37581
37582 /* Indexed by cpu number. */
37583-static struct us3_freq_percpu_info *us3_freq_table;
37584+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37585
37586 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37587 * in the Safari config register.
37588@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37589
37590 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37591 {
37592- if (cpufreq_us3_driver)
37593- us3_set_cpu_divider_index(policy, 0);
37594+ us3_set_cpu_divider_index(policy->cpu, 0);
37595
37596 return 0;
37597 }
37598
37599+static int __init us3_freq_init(void);
37600+static void __exit us3_freq_exit(void);
37601+
37602+static struct cpufreq_driver cpufreq_us3_driver = {
37603+ .init = us3_freq_cpu_init,
37604+ .verify = us3_freq_verify,
37605+ .target = us3_freq_target,
37606+ .get = us3_freq_get,
37607+ .exit = us3_freq_cpu_exit,
37608+ .owner = THIS_MODULE,
37609+ .name = "UltraSPARC-III",
37610+
37611+};
37612+
37613 static int __init us3_freq_init(void)
37614 {
37615 unsigned long manuf, impl, ver;
37616@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37617 (impl == CHEETAH_IMPL ||
37618 impl == CHEETAH_PLUS_IMPL ||
37619 impl == JAGUAR_IMPL ||
37620- impl == PANTHER_IMPL)) {
37621- struct cpufreq_driver *driver;
37622-
37623- ret = -ENOMEM;
37624- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37625- if (!driver)
37626- goto err_out;
37627-
37628- us3_freq_table = kzalloc(
37629- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37630- GFP_KERNEL);
37631- if (!us3_freq_table)
37632- goto err_out;
37633-
37634- driver->init = us3_freq_cpu_init;
37635- driver->verify = us3_freq_verify;
37636- driver->target = us3_freq_target;
37637- driver->get = us3_freq_get;
37638- driver->exit = us3_freq_cpu_exit;
37639- driver->owner = THIS_MODULE,
37640- strcpy(driver->name, "UltraSPARC-III");
37641-
37642- cpufreq_us3_driver = driver;
37643- ret = cpufreq_register_driver(driver);
37644- if (ret)
37645- goto err_out;
37646-
37647- return 0;
37648-
37649-err_out:
37650- if (driver) {
37651- kfree(driver);
37652- cpufreq_us3_driver = NULL;
37653- }
37654- kfree(us3_freq_table);
37655- us3_freq_table = NULL;
37656- return ret;
37657- }
37658+ impl == PANTHER_IMPL))
37659+ return cpufreq_register_driver(&cpufreq_us3_driver);
37660
37661 return -ENODEV;
37662 }
37663
37664 static void __exit us3_freq_exit(void)
37665 {
37666- if (cpufreq_us3_driver) {
37667- cpufreq_unregister_driver(cpufreq_us3_driver);
37668- kfree(cpufreq_us3_driver);
37669- cpufreq_us3_driver = NULL;
37670- kfree(us3_freq_table);
37671- us3_freq_table = NULL;
37672- }
37673+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37674 }
37675
37676 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37677diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37678index 0915e71..53376ed 100644
37679--- a/drivers/cpufreq/speedstep-centrino.c
37680+++ b/drivers/cpufreq/speedstep-centrino.c
37681@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37682 !cpu_has(cpu, X86_FEATURE_EST))
37683 return -ENODEV;
37684
37685- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37686- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37687+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37688+ pax_open_kernel();
37689+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37690+ pax_close_kernel();
37691+ }
37692
37693 if (policy->cpu != 0)
37694 return -ENODEV;
37695diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37696index fdc432f..98e64e2 100644
37697--- a/drivers/cpuidle/cpuidle.c
37698+++ b/drivers/cpuidle/cpuidle.c
37699@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37700
37701 static void poll_idle_init(struct cpuidle_driver *drv)
37702 {
37703- struct cpuidle_state *state = &drv->states[0];
37704+ cpuidle_state_no_const *state = &drv->states[0];
37705
37706 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37707 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37708diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37709index ea2f8e7..70ac501 100644
37710--- a/drivers/cpuidle/governor.c
37711+++ b/drivers/cpuidle/governor.c
37712@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37713 mutex_lock(&cpuidle_lock);
37714 if (__cpuidle_find_governor(gov->name) == NULL) {
37715 ret = 0;
37716- list_add_tail(&gov->governor_list, &cpuidle_governors);
37717+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37718 if (!cpuidle_curr_governor ||
37719 cpuidle_curr_governor->rating < gov->rating)
37720 cpuidle_switch_governor(gov);
37721@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37722 new_gov = cpuidle_replace_governor(gov->rating);
37723 cpuidle_switch_governor(new_gov);
37724 }
37725- list_del(&gov->governor_list);
37726+ pax_list_del((struct list_head *)&gov->governor_list);
37727 mutex_unlock(&cpuidle_lock);
37728 }
37729
37730diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37731index 428754a..8bdf9cc 100644
37732--- a/drivers/cpuidle/sysfs.c
37733+++ b/drivers/cpuidle/sysfs.c
37734@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37735 NULL
37736 };
37737
37738-static struct attribute_group cpuidle_attr_group = {
37739+static attribute_group_no_const cpuidle_attr_group = {
37740 .attrs = cpuidle_default_attrs,
37741 .name = "cpuidle",
37742 };
37743diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37744index 12fea3e..1e28f47 100644
37745--- a/drivers/crypto/hifn_795x.c
37746+++ b/drivers/crypto/hifn_795x.c
37747@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37748 MODULE_PARM_DESC(hifn_pll_ref,
37749 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37750
37751-static atomic_t hifn_dev_number;
37752+static atomic_unchecked_t hifn_dev_number;
37753
37754 #define ACRYPTO_OP_DECRYPT 0
37755 #define ACRYPTO_OP_ENCRYPT 1
37756@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37757 goto err_out_disable_pci_device;
37758
37759 snprintf(name, sizeof(name), "hifn%d",
37760- atomic_inc_return(&hifn_dev_number)-1);
37761+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37762
37763 err = pci_request_regions(pdev, name);
37764 if (err)
37765diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37766index e94e619..f7e249c 100644
37767--- a/drivers/devfreq/devfreq.c
37768+++ b/drivers/devfreq/devfreq.c
37769@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37770 goto err_out;
37771 }
37772
37773- list_add(&governor->node, &devfreq_governor_list);
37774+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37775
37776 list_for_each_entry(devfreq, &devfreq_list, node) {
37777 int ret = 0;
37778@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37779 }
37780 }
37781
37782- list_del(&governor->node);
37783+ pax_list_del((struct list_head *)&governor->node);
37784 err_out:
37785 mutex_unlock(&devfreq_list_lock);
37786
37787diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37788index 5039fbc..841169f 100644
37789--- a/drivers/dma/sh/shdma.c
37790+++ b/drivers/dma/sh/shdma.c
37791@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37792 return ret;
37793 }
37794
37795-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37796+static struct notifier_block sh_dmae_nmi_notifier = {
37797 .notifier_call = sh_dmae_nmi_handler,
37798
37799 /* Run before NMI debug handler and KGDB */
37800diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37801index 211021d..201d47f 100644
37802--- a/drivers/edac/edac_device.c
37803+++ b/drivers/edac/edac_device.c
37804@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37805 */
37806 int edac_device_alloc_index(void)
37807 {
37808- static atomic_t device_indexes = ATOMIC_INIT(0);
37809+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37810
37811- return atomic_inc_return(&device_indexes) - 1;
37812+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37813 }
37814 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37815
37816diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37817index e7c32c4..6397af1 100644
37818--- a/drivers/edac/edac_mc_sysfs.c
37819+++ b/drivers/edac/edac_mc_sysfs.c
37820@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37821 struct dev_ch_attribute {
37822 struct device_attribute attr;
37823 int channel;
37824-};
37825+} __do_const;
37826
37827 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37828 struct dev_ch_attribute dev_attr_legacy_##_name = \
37829@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37830 }
37831
37832 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37833+ pax_open_kernel();
37834 if (mci->get_sdram_scrub_rate) {
37835- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37836- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37837+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37838+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37839 }
37840 if (mci->set_sdram_scrub_rate) {
37841- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37842- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37843+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37844+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37845 }
37846+ pax_close_kernel();
37847 err = device_create_file(&mci->dev,
37848 &dev_attr_sdram_scrub_rate);
37849 if (err) {
37850diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37851index dd370f9..0281629 100644
37852--- a/drivers/edac/edac_pci.c
37853+++ b/drivers/edac/edac_pci.c
37854@@ -29,7 +29,7 @@
37855
37856 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37857 static LIST_HEAD(edac_pci_list);
37858-static atomic_t pci_indexes = ATOMIC_INIT(0);
37859+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37860
37861 /*
37862 * edac_pci_alloc_ctl_info
37863@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37864 */
37865 int edac_pci_alloc_index(void)
37866 {
37867- return atomic_inc_return(&pci_indexes) - 1;
37868+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37869 }
37870 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37871
37872diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37873index e8658e4..22746d6 100644
37874--- a/drivers/edac/edac_pci_sysfs.c
37875+++ b/drivers/edac/edac_pci_sysfs.c
37876@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37877 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37878 static int edac_pci_poll_msec = 1000; /* one second workq period */
37879
37880-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37881-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37882+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37883+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37884
37885 static struct kobject *edac_pci_top_main_kobj;
37886 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37887@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37888 void *value;
37889 ssize_t(*show) (void *, char *);
37890 ssize_t(*store) (void *, const char *, size_t);
37891-};
37892+} __do_const;
37893
37894 /* Set of show/store abstract level functions for PCI Parity object */
37895 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37896@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37897 edac_printk(KERN_CRIT, EDAC_PCI,
37898 "Signaled System Error on %s\n",
37899 pci_name(dev));
37900- atomic_inc(&pci_nonparity_count);
37901+ atomic_inc_unchecked(&pci_nonparity_count);
37902 }
37903
37904 if (status & (PCI_STATUS_PARITY)) {
37905@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37906 "Master Data Parity Error on %s\n",
37907 pci_name(dev));
37908
37909- atomic_inc(&pci_parity_count);
37910+ atomic_inc_unchecked(&pci_parity_count);
37911 }
37912
37913 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37914@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37915 "Detected Parity Error on %s\n",
37916 pci_name(dev));
37917
37918- atomic_inc(&pci_parity_count);
37919+ atomic_inc_unchecked(&pci_parity_count);
37920 }
37921 }
37922
37923@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37924 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37925 "Signaled System Error on %s\n",
37926 pci_name(dev));
37927- atomic_inc(&pci_nonparity_count);
37928+ atomic_inc_unchecked(&pci_nonparity_count);
37929 }
37930
37931 if (status & (PCI_STATUS_PARITY)) {
37932@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37933 "Master Data Parity Error on "
37934 "%s\n", pci_name(dev));
37935
37936- atomic_inc(&pci_parity_count);
37937+ atomic_inc_unchecked(&pci_parity_count);
37938 }
37939
37940 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37941@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37942 "Detected Parity Error on %s\n",
37943 pci_name(dev));
37944
37945- atomic_inc(&pci_parity_count);
37946+ atomic_inc_unchecked(&pci_parity_count);
37947 }
37948 }
37949 }
37950@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37951 if (!check_pci_errors)
37952 return;
37953
37954- before_count = atomic_read(&pci_parity_count);
37955+ before_count = atomic_read_unchecked(&pci_parity_count);
37956
37957 /* scan all PCI devices looking for a Parity Error on devices and
37958 * bridges.
37959@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37960 /* Only if operator has selected panic on PCI Error */
37961 if (edac_pci_get_panic_on_pe()) {
37962 /* If the count is different 'after' from 'before' */
37963- if (before_count != atomic_read(&pci_parity_count))
37964+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37965 panic("EDAC: PCI Parity Error");
37966 }
37967 }
37968diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37969index 51b7e3a..aa8a3e8 100644
37970--- a/drivers/edac/mce_amd.h
37971+++ b/drivers/edac/mce_amd.h
37972@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37973 bool (*mc0_mce)(u16, u8);
37974 bool (*mc1_mce)(u16, u8);
37975 bool (*mc2_mce)(u16, u8);
37976-};
37977+} __no_const;
37978
37979 void amd_report_gart_errors(bool);
37980 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37981diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37982index 57ea7f4..af06b76 100644
37983--- a/drivers/firewire/core-card.c
37984+++ b/drivers/firewire/core-card.c
37985@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37986 const struct fw_card_driver *driver,
37987 struct device *device)
37988 {
37989- static atomic_t index = ATOMIC_INIT(-1);
37990+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37991
37992- card->index = atomic_inc_return(&index);
37993+ card->index = atomic_inc_return_unchecked(&index);
37994 card->driver = driver;
37995 card->device = device;
37996 card->current_tlabel = 0;
37997@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37998
37999 void fw_core_remove_card(struct fw_card *card)
38000 {
38001- struct fw_card_driver dummy_driver = dummy_driver_template;
38002+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38003
38004 card->driver->update_phy_reg(card, 4,
38005 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38006diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38007index de4aa40..49ab1f2 100644
38008--- a/drivers/firewire/core-device.c
38009+++ b/drivers/firewire/core-device.c
38010@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38011 struct config_rom_attribute {
38012 struct device_attribute attr;
38013 u32 key;
38014-};
38015+} __do_const;
38016
38017 static ssize_t show_immediate(struct device *dev,
38018 struct device_attribute *dattr, char *buf)
38019diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38020index 28a94c7..58da63a 100644
38021--- a/drivers/firewire/core-transaction.c
38022+++ b/drivers/firewire/core-transaction.c
38023@@ -38,6 +38,7 @@
38024 #include <linux/timer.h>
38025 #include <linux/types.h>
38026 #include <linux/workqueue.h>
38027+#include <linux/sched.h>
38028
38029 #include <asm/byteorder.h>
38030
38031diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38032index 515a42c..5ecf3ba 100644
38033--- a/drivers/firewire/core.h
38034+++ b/drivers/firewire/core.h
38035@@ -111,6 +111,7 @@ struct fw_card_driver {
38036
38037 int (*stop_iso)(struct fw_iso_context *ctx);
38038 };
38039+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38040
38041 void fw_card_initialize(struct fw_card *card,
38042 const struct fw_card_driver *driver, struct device *device);
38043diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38044index 94a58a0..f5eba42 100644
38045--- a/drivers/firmware/dmi-id.c
38046+++ b/drivers/firmware/dmi-id.c
38047@@ -16,7 +16,7 @@
38048 struct dmi_device_attribute{
38049 struct device_attribute dev_attr;
38050 int field;
38051-};
38052+} __do_const;
38053 #define to_dmi_dev_attr(_dev_attr) \
38054 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38055
38056diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38057index 232fa8f..386c255 100644
38058--- a/drivers/firmware/dmi_scan.c
38059+++ b/drivers/firmware/dmi_scan.c
38060@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
38061 }
38062 }
38063 else {
38064- /*
38065- * no iounmap() for that ioremap(); it would be a no-op, but
38066- * it's so early in setup that sucker gets confused into doing
38067- * what it shouldn't if we actually call it.
38068- */
38069 p = dmi_ioremap(0xF0000, 0x10000);
38070 if (p == NULL)
38071 goto error;
38072@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38073 if (buf == NULL)
38074 return -1;
38075
38076- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38077+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38078
38079 iounmap(buf);
38080 return 0;
38081diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38082index 5145fa3..0d3babd 100644
38083--- a/drivers/firmware/efi/efi.c
38084+++ b/drivers/firmware/efi/efi.c
38085@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38086 };
38087
38088 static struct efivars generic_efivars;
38089-static struct efivar_operations generic_ops;
38090+static efivar_operations_no_const generic_ops __read_only;
38091
38092 static int generic_ops_register(void)
38093 {
38094- generic_ops.get_variable = efi.get_variable;
38095- generic_ops.set_variable = efi.set_variable;
38096- generic_ops.get_next_variable = efi.get_next_variable;
38097- generic_ops.query_variable_store = efi_query_variable_store;
38098+ pax_open_kernel();
38099+ *(void **)&generic_ops.get_variable = efi.get_variable;
38100+ *(void **)&generic_ops.set_variable = efi.set_variable;
38101+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38102+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38103+ pax_close_kernel();
38104
38105 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38106 }
38107diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38108index 8a7432a..28fb839 100644
38109--- a/drivers/firmware/efi/efivars.c
38110+++ b/drivers/firmware/efi/efivars.c
38111@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38112 static int
38113 create_efivars_bin_attributes(void)
38114 {
38115- struct bin_attribute *attr;
38116+ bin_attribute_no_const *attr;
38117 int error;
38118
38119 /* new_var */
38120diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38121index 2a90ba6..07f3733 100644
38122--- a/drivers/firmware/google/memconsole.c
38123+++ b/drivers/firmware/google/memconsole.c
38124@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38125 if (!found_memconsole())
38126 return -ENODEV;
38127
38128- memconsole_bin_attr.size = memconsole_length;
38129+ pax_open_kernel();
38130+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38131+ pax_close_kernel();
38132
38133 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38134
38135diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38136index 2729e3d..f9deca1 100644
38137--- a/drivers/gpio/gpio-ich.c
38138+++ b/drivers/gpio/gpio-ich.c
38139@@ -71,7 +71,7 @@ struct ichx_desc {
38140 /* Some chipsets have quirks, let these use their own request/get */
38141 int (*request)(struct gpio_chip *chip, unsigned offset);
38142 int (*get)(struct gpio_chip *chip, unsigned offset);
38143-};
38144+} __do_const;
38145
38146 static struct {
38147 spinlock_t lock;
38148diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38149index 9902732..64b62dd 100644
38150--- a/drivers/gpio/gpio-vr41xx.c
38151+++ b/drivers/gpio/gpio-vr41xx.c
38152@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38153 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38154 maskl, pendl, maskh, pendh);
38155
38156- atomic_inc(&irq_err_count);
38157+ atomic_inc_unchecked(&irq_err_count);
38158
38159 return -EINVAL;
38160 }
38161diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38162index 6a64749..0767a9f 100644
38163--- a/drivers/gpu/drm/drm_crtc_helper.c
38164+++ b/drivers/gpu/drm/drm_crtc_helper.c
38165@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38166 struct drm_crtc *tmp;
38167 int crtc_mask = 1;
38168
38169- WARN(!crtc, "checking null crtc?\n");
38170+ BUG_ON(!crtc);
38171
38172 dev = crtc->dev;
38173
38174diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38175index 99fcd7c..13cf6c5 100644
38176--- a/drivers/gpu/drm/drm_drv.c
38177+++ b/drivers/gpu/drm/drm_drv.c
38178@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
38179 /**
38180 * Copy and IOCTL return string to user space
38181 */
38182-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38183+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38184 {
38185 int len;
38186
38187@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
38188 struct drm_file *file_priv = filp->private_data;
38189 struct drm_device *dev;
38190 const struct drm_ioctl_desc *ioctl = NULL;
38191- drm_ioctl_t *func;
38192+ drm_ioctl_no_const_t func;
38193 unsigned int nr = DRM_IOCTL_NR(cmd);
38194 int retcode = -EINVAL;
38195 char stack_kdata[128];
38196@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
38197 return -ENODEV;
38198
38199 atomic_inc(&dev->ioctl_count);
38200- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38201+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38202 ++file_priv->ioctl_count;
38203
38204 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38205diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38206index 3a24385..4e426e0 100644
38207--- a/drivers/gpu/drm/drm_fops.c
38208+++ b/drivers/gpu/drm/drm_fops.c
38209@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38210 }
38211
38212 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38213- atomic_set(&dev->counts[i], 0);
38214+ atomic_set_unchecked(&dev->counts[i], 0);
38215
38216 dev->sigdata.lock = NULL;
38217
38218@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38219 if (drm_device_is_unplugged(dev))
38220 return -ENODEV;
38221
38222- if (!dev->open_count++)
38223+ if (local_inc_return(&dev->open_count) == 1)
38224 need_setup = 1;
38225 mutex_lock(&dev->struct_mutex);
38226 old_imapping = inode->i_mapping;
38227@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38228 retcode = drm_open_helper(inode, filp, dev);
38229 if (retcode)
38230 goto err_undo;
38231- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38232+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38233 if (need_setup) {
38234 retcode = drm_setup(dev);
38235 if (retcode)
38236@@ -166,7 +166,7 @@ err_undo:
38237 iput(container_of(dev->dev_mapping, struct inode, i_data));
38238 dev->dev_mapping = old_mapping;
38239 mutex_unlock(&dev->struct_mutex);
38240- dev->open_count--;
38241+ local_dec(&dev->open_count);
38242 return retcode;
38243 }
38244 EXPORT_SYMBOL(drm_open);
38245@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38246
38247 mutex_lock(&drm_global_mutex);
38248
38249- DRM_DEBUG("open_count = %d\n", dev->open_count);
38250+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38251
38252 if (dev->driver->preclose)
38253 dev->driver->preclose(dev, file_priv);
38254@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38255 * Begin inline drm_release
38256 */
38257
38258- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38259+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38260 task_pid_nr(current),
38261 (long)old_encode_dev(file_priv->minor->device),
38262- dev->open_count);
38263+ local_read(&dev->open_count));
38264
38265 /* Release any auth tokens that might point to this file_priv,
38266 (do that under the drm_global_mutex) */
38267@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38268 * End inline drm_release
38269 */
38270
38271- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38272- if (!--dev->open_count) {
38273+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38274+ if (local_dec_and_test(&dev->open_count)) {
38275 if (atomic_read(&dev->ioctl_count)) {
38276 DRM_ERROR("Device busy: %d\n",
38277 atomic_read(&dev->ioctl_count));
38278diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38279index f731116..629842c 100644
38280--- a/drivers/gpu/drm/drm_global.c
38281+++ b/drivers/gpu/drm/drm_global.c
38282@@ -36,7 +36,7 @@
38283 struct drm_global_item {
38284 struct mutex mutex;
38285 void *object;
38286- int refcount;
38287+ atomic_t refcount;
38288 };
38289
38290 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38291@@ -49,7 +49,7 @@ void drm_global_init(void)
38292 struct drm_global_item *item = &glob[i];
38293 mutex_init(&item->mutex);
38294 item->object = NULL;
38295- item->refcount = 0;
38296+ atomic_set(&item->refcount, 0);
38297 }
38298 }
38299
38300@@ -59,7 +59,7 @@ void drm_global_release(void)
38301 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38302 struct drm_global_item *item = &glob[i];
38303 BUG_ON(item->object != NULL);
38304- BUG_ON(item->refcount != 0);
38305+ BUG_ON(atomic_read(&item->refcount) != 0);
38306 }
38307 }
38308
38309@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38310 void *object;
38311
38312 mutex_lock(&item->mutex);
38313- if (item->refcount == 0) {
38314+ if (atomic_read(&item->refcount) == 0) {
38315 item->object = kzalloc(ref->size, GFP_KERNEL);
38316 if (unlikely(item->object == NULL)) {
38317 ret = -ENOMEM;
38318@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38319 goto out_err;
38320
38321 }
38322- ++item->refcount;
38323+ atomic_inc(&item->refcount);
38324 ref->object = item->object;
38325 object = item->object;
38326 mutex_unlock(&item->mutex);
38327@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38328 struct drm_global_item *item = &glob[ref->global_type];
38329
38330 mutex_lock(&item->mutex);
38331- BUG_ON(item->refcount == 0);
38332+ BUG_ON(atomic_read(&item->refcount) == 0);
38333 BUG_ON(ref->object != item->object);
38334- if (--item->refcount == 0) {
38335+ if (atomic_dec_and_test(&item->refcount)) {
38336 ref->release(ref);
38337 item->object = NULL;
38338 }
38339diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38340index d4b20ce..77a8d41 100644
38341--- a/drivers/gpu/drm/drm_info.c
38342+++ b/drivers/gpu/drm/drm_info.c
38343@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38344 struct drm_local_map *map;
38345 struct drm_map_list *r_list;
38346
38347- /* Hardcoded from _DRM_FRAME_BUFFER,
38348- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38349- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38350- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38351+ static const char * const types[] = {
38352+ [_DRM_FRAME_BUFFER] = "FB",
38353+ [_DRM_REGISTERS] = "REG",
38354+ [_DRM_SHM] = "SHM",
38355+ [_DRM_AGP] = "AGP",
38356+ [_DRM_SCATTER_GATHER] = "SG",
38357+ [_DRM_CONSISTENT] = "PCI",
38358+ [_DRM_GEM] = "GEM" };
38359 const char *type;
38360 int i;
38361
38362@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38363 map = r_list->map;
38364 if (!map)
38365 continue;
38366- if (map->type < 0 || map->type > 5)
38367+ if (map->type >= ARRAY_SIZE(types))
38368 type = "??";
38369 else
38370 type = types[map->type];
38371@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38372 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38373 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38374 vma->vm_flags & VM_IO ? 'i' : '-',
38375+#ifdef CONFIG_GRKERNSEC_HIDESYM
38376+ 0);
38377+#else
38378 vma->vm_pgoff);
38379+#endif
38380
38381 #if defined(__i386__)
38382 pgprot = pgprot_val(vma->vm_page_prot);
38383diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38384index 2f4c434..dd12cd2 100644
38385--- a/drivers/gpu/drm/drm_ioc32.c
38386+++ b/drivers/gpu/drm/drm_ioc32.c
38387@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38388 request = compat_alloc_user_space(nbytes);
38389 if (!access_ok(VERIFY_WRITE, request, nbytes))
38390 return -EFAULT;
38391- list = (struct drm_buf_desc *) (request + 1);
38392+ list = (struct drm_buf_desc __user *) (request + 1);
38393
38394 if (__put_user(count, &request->count)
38395 || __put_user(list, &request->list))
38396@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38397 request = compat_alloc_user_space(nbytes);
38398 if (!access_ok(VERIFY_WRITE, request, nbytes))
38399 return -EFAULT;
38400- list = (struct drm_buf_pub *) (request + 1);
38401+ list = (struct drm_buf_pub __user *) (request + 1);
38402
38403 if (__put_user(count, &request->count)
38404 || __put_user(list, &request->list))
38405@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38406 return 0;
38407 }
38408
38409-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38410+drm_ioctl_compat_t drm_compat_ioctls[] = {
38411 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38412 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38413 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38414@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38415 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38416 {
38417 unsigned int nr = DRM_IOCTL_NR(cmd);
38418- drm_ioctl_compat_t *fn;
38419 int ret;
38420
38421 /* Assume that ioctls without an explicit compat routine will just
38422@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38423 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38424 return drm_ioctl(filp, cmd, arg);
38425
38426- fn = drm_compat_ioctls[nr];
38427-
38428- if (fn != NULL)
38429- ret = (*fn) (filp, cmd, arg);
38430+ if (drm_compat_ioctls[nr] != NULL)
38431+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38432 else
38433 ret = drm_ioctl(filp, cmd, arg);
38434
38435diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38436index ffd7a7b..a64643e 100644
38437--- a/drivers/gpu/drm/drm_ioctl.c
38438+++ b/drivers/gpu/drm/drm_ioctl.c
38439@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38440 stats->data[i].value =
38441 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38442 else
38443- stats->data[i].value = atomic_read(&dev->counts[i]);
38444+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38445 stats->data[i].type = dev->types[i];
38446 }
38447
38448diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38449index d752c96..fe08455 100644
38450--- a/drivers/gpu/drm/drm_lock.c
38451+++ b/drivers/gpu/drm/drm_lock.c
38452@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38453 if (drm_lock_take(&master->lock, lock->context)) {
38454 master->lock.file_priv = file_priv;
38455 master->lock.lock_time = jiffies;
38456- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38457+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38458 break; /* Got lock */
38459 }
38460
38461@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38462 return -EINVAL;
38463 }
38464
38465- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38466+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38467
38468 if (drm_lock_free(&master->lock, lock->context)) {
38469 /* FIXME: Should really bail out here. */
38470diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38471index 327ca19..684d3c0 100644
38472--- a/drivers/gpu/drm/drm_stub.c
38473+++ b/drivers/gpu/drm/drm_stub.c
38474@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38475
38476 drm_device_set_unplugged(dev);
38477
38478- if (dev->open_count == 0) {
38479+ if (local_read(&dev->open_count) == 0) {
38480 drm_put_dev(dev);
38481 }
38482 mutex_unlock(&drm_global_mutex);
38483diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38484index 2290b3b..22056a1 100644
38485--- a/drivers/gpu/drm/drm_sysfs.c
38486+++ b/drivers/gpu/drm/drm_sysfs.c
38487@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38488 int drm_sysfs_device_add(struct drm_minor *minor)
38489 {
38490 int err;
38491- char *minor_str;
38492+ const char *minor_str;
38493
38494 minor->kdev.parent = minor->dev->dev;
38495
38496diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38497index ada49ed..29275a0 100644
38498--- a/drivers/gpu/drm/i810/i810_dma.c
38499+++ b/drivers/gpu/drm/i810/i810_dma.c
38500@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38501 dma->buflist[vertex->idx],
38502 vertex->discard, vertex->used);
38503
38504- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38505- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38506+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38507+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38508 sarea_priv->last_enqueue = dev_priv->counter - 1;
38509 sarea_priv->last_dispatch = (int)hw_status[5];
38510
38511@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38512 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38513 mc->last_render);
38514
38515- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38516- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38517+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38518+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38519 sarea_priv->last_enqueue = dev_priv->counter - 1;
38520 sarea_priv->last_dispatch = (int)hw_status[5];
38521
38522diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38523index 6e0acad..93c8289 100644
38524--- a/drivers/gpu/drm/i810/i810_drv.h
38525+++ b/drivers/gpu/drm/i810/i810_drv.h
38526@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38527 int page_flipping;
38528
38529 wait_queue_head_t irq_queue;
38530- atomic_t irq_received;
38531- atomic_t irq_emitted;
38532+ atomic_unchecked_t irq_received;
38533+ atomic_unchecked_t irq_emitted;
38534
38535 int front_offset;
38536 } drm_i810_private_t;
38537diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38538index 47d6c74..279123f 100644
38539--- a/drivers/gpu/drm/i915/i915_debugfs.c
38540+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38541@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38542 I915_READ(GTIMR));
38543 }
38544 seq_printf(m, "Interrupts received: %d\n",
38545- atomic_read(&dev_priv->irq_received));
38546+ atomic_read_unchecked(&dev_priv->irq_received));
38547 for_each_ring(ring, dev_priv, i) {
38548 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38549 seq_printf(m,
38550diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38551index f466980..8f2883f 100644
38552--- a/drivers/gpu/drm/i915/i915_dma.c
38553+++ b/drivers/gpu/drm/i915/i915_dma.c
38554@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38555 bool can_switch;
38556
38557 spin_lock(&dev->count_lock);
38558- can_switch = (dev->open_count == 0);
38559+ can_switch = (local_read(&dev->open_count) == 0);
38560 spin_unlock(&dev->count_lock);
38561 return can_switch;
38562 }
38563diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38564index 2f09e80..077876d 100644
38565--- a/drivers/gpu/drm/i915/i915_drv.h
38566+++ b/drivers/gpu/drm/i915/i915_drv.h
38567@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38568 drm_dma_handle_t *status_page_dmah;
38569 struct resource mch_res;
38570
38571- atomic_t irq_received;
38572+ atomic_unchecked_t irq_received;
38573
38574 /* protects the irq masks */
38575 spinlock_t irq_lock;
38576diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38577index 87a3227..cd13d8f 100644
38578--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38579+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38580@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38581
38582 static int
38583 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38584- int count)
38585+ unsigned int count)
38586 {
38587- int i;
38588+ unsigned int i;
38589 int relocs_total = 0;
38590 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38591
38592diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38593index 3c59584..500f2e9 100644
38594--- a/drivers/gpu/drm/i915/i915_ioc32.c
38595+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38596@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38597 (unsigned long)request);
38598 }
38599
38600-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38601+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38602 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38603 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38604 [DRM_I915_GETPARAM] = compat_i915_getparam,
38605@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38606 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38607 {
38608 unsigned int nr = DRM_IOCTL_NR(cmd);
38609- drm_ioctl_compat_t *fn = NULL;
38610 int ret;
38611
38612 if (nr < DRM_COMMAND_BASE)
38613 return drm_compat_ioctl(filp, cmd, arg);
38614
38615- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38616- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38617-
38618- if (fn != NULL)
38619+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38620+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38621 ret = (*fn) (filp, cmd, arg);
38622- else
38623+ } else
38624 ret = drm_ioctl(filp, cmd, arg);
38625
38626 return ret;
38627diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38628index 46d46ba..6e49848 100644
38629--- a/drivers/gpu/drm/i915/i915_irq.c
38630+++ b/drivers/gpu/drm/i915/i915_irq.c
38631@@ -975,7 +975,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38632 int pipe;
38633 u32 pipe_stats[I915_MAX_PIPES];
38634
38635- atomic_inc(&dev_priv->irq_received);
38636+ atomic_inc_unchecked(&dev_priv->irq_received);
38637
38638 while (true) {
38639 iir = I915_READ(VLV_IIR);
38640@@ -1192,7 +1192,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38641 irqreturn_t ret = IRQ_NONE;
38642 int i;
38643
38644- atomic_inc(&dev_priv->irq_received);
38645+ atomic_inc_unchecked(&dev_priv->irq_received);
38646
38647 /* We get interrupts on unclaimed registers, so check for this before we
38648 * do any I915_{READ,WRITE}. */
38649@@ -1312,7 +1312,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38650 int ret = IRQ_NONE;
38651 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38652
38653- atomic_inc(&dev_priv->irq_received);
38654+ atomic_inc_unchecked(&dev_priv->irq_received);
38655
38656 /* disable master interrupt before clearing iir */
38657 de_ier = I915_READ(DEIER);
38658@@ -2617,7 +2617,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38659 {
38660 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38661
38662- atomic_set(&dev_priv->irq_received, 0);
38663+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38664
38665 I915_WRITE(HWSTAM, 0xeffe);
38666
38667@@ -2639,7 +2639,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38668 {
38669 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38670
38671- atomic_set(&dev_priv->irq_received, 0);
38672+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38673
38674 I915_WRITE(HWSTAM, 0xeffe);
38675
38676@@ -2667,7 +2667,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38677 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38678 int pipe;
38679
38680- atomic_set(&dev_priv->irq_received, 0);
38681+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38682
38683 /* VLV magic */
38684 I915_WRITE(VLV_IMR, 0);
38685@@ -2979,7 +2979,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38686 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38687 int pipe;
38688
38689- atomic_set(&dev_priv->irq_received, 0);
38690+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38691
38692 for_each_pipe(pipe)
38693 I915_WRITE(PIPESTAT(pipe), 0);
38694@@ -3058,7 +3058,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38695 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38696 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38697
38698- atomic_inc(&dev_priv->irq_received);
38699+ atomic_inc_unchecked(&dev_priv->irq_received);
38700
38701 iir = I915_READ16(IIR);
38702 if (iir == 0)
38703@@ -3133,7 +3133,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38704 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38705 int pipe;
38706
38707- atomic_set(&dev_priv->irq_received, 0);
38708+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38709
38710 if (I915_HAS_HOTPLUG(dev)) {
38711 I915_WRITE(PORT_HOTPLUG_EN, 0);
38712@@ -3232,7 +3232,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38713 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38714 int pipe, ret = IRQ_NONE;
38715
38716- atomic_inc(&dev_priv->irq_received);
38717+ atomic_inc_unchecked(&dev_priv->irq_received);
38718
38719 iir = I915_READ(IIR);
38720 do {
38721@@ -3356,7 +3356,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38722 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38723 int pipe;
38724
38725- atomic_set(&dev_priv->irq_received, 0);
38726+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38727
38728 I915_WRITE(PORT_HOTPLUG_EN, 0);
38729 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38730@@ -3465,7 +3465,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38731 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38732 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38733
38734- atomic_inc(&dev_priv->irq_received);
38735+ atomic_inc_unchecked(&dev_priv->irq_received);
38736
38737 iir = I915_READ(IIR);
38738
38739diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38740index 7fc8a76..95672c0 100644
38741--- a/drivers/gpu/drm/i915/intel_display.c
38742+++ b/drivers/gpu/drm/i915/intel_display.c
38743@@ -9428,13 +9428,13 @@ struct intel_quirk {
38744 int subsystem_vendor;
38745 int subsystem_device;
38746 void (*hook)(struct drm_device *dev);
38747-};
38748+} __do_const;
38749
38750 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38751 struct intel_dmi_quirk {
38752 void (*hook)(struct drm_device *dev);
38753 const struct dmi_system_id (*dmi_id_list)[];
38754-};
38755+} __do_const;
38756
38757 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38758 {
38759@@ -9442,18 +9442,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38760 return 1;
38761 }
38762
38763-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38764+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38765 {
38766- .dmi_id_list = &(const struct dmi_system_id[]) {
38767- {
38768- .callback = intel_dmi_reverse_brightness,
38769- .ident = "NCR Corporation",
38770- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38771- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38772- },
38773- },
38774- { } /* terminating entry */
38775+ .callback = intel_dmi_reverse_brightness,
38776+ .ident = "NCR Corporation",
38777+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38778+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38779 },
38780+ },
38781+ { } /* terminating entry */
38782+};
38783+
38784+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38785+ {
38786+ .dmi_id_list = &intel_dmi_quirks_table,
38787 .hook = quirk_invert_brightness,
38788 },
38789 };
38790diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38791index 54558a0..2d97005 100644
38792--- a/drivers/gpu/drm/mga/mga_drv.h
38793+++ b/drivers/gpu/drm/mga/mga_drv.h
38794@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38795 u32 clear_cmd;
38796 u32 maccess;
38797
38798- atomic_t vbl_received; /**< Number of vblanks received. */
38799+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38800 wait_queue_head_t fence_queue;
38801- atomic_t last_fence_retired;
38802+ atomic_unchecked_t last_fence_retired;
38803 u32 next_fence_to_post;
38804
38805 unsigned int fb_cpp;
38806diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38807index 709e90d..89a1c0d 100644
38808--- a/drivers/gpu/drm/mga/mga_ioc32.c
38809+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38810@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38811 return 0;
38812 }
38813
38814-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38815+drm_ioctl_compat_t mga_compat_ioctls[] = {
38816 [DRM_MGA_INIT] = compat_mga_init,
38817 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38818 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38819@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38820 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38821 {
38822 unsigned int nr = DRM_IOCTL_NR(cmd);
38823- drm_ioctl_compat_t *fn = NULL;
38824 int ret;
38825
38826 if (nr < DRM_COMMAND_BASE)
38827 return drm_compat_ioctl(filp, cmd, arg);
38828
38829- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38830- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38831-
38832- if (fn != NULL)
38833+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38834+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38835 ret = (*fn) (filp, cmd, arg);
38836- else
38837+ } else
38838 ret = drm_ioctl(filp, cmd, arg);
38839
38840 return ret;
38841diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38842index 598c281..60d590e 100644
38843--- a/drivers/gpu/drm/mga/mga_irq.c
38844+++ b/drivers/gpu/drm/mga/mga_irq.c
38845@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38846 if (crtc != 0)
38847 return 0;
38848
38849- return atomic_read(&dev_priv->vbl_received);
38850+ return atomic_read_unchecked(&dev_priv->vbl_received);
38851 }
38852
38853
38854@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38855 /* VBLANK interrupt */
38856 if (status & MGA_VLINEPEN) {
38857 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38858- atomic_inc(&dev_priv->vbl_received);
38859+ atomic_inc_unchecked(&dev_priv->vbl_received);
38860 drm_handle_vblank(dev, 0);
38861 handled = 1;
38862 }
38863@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38864 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38865 MGA_WRITE(MGA_PRIMEND, prim_end);
38866
38867- atomic_inc(&dev_priv->last_fence_retired);
38868+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38869 DRM_WAKEUP(&dev_priv->fence_queue);
38870 handled = 1;
38871 }
38872@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38873 * using fences.
38874 */
38875 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38876- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38877+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38878 - *sequence) <= (1 << 23)));
38879
38880 *sequence = cur_fence;
38881diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38882index 3e72876..d1c15ad 100644
38883--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38884+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38885@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38886 struct bit_table {
38887 const char id;
38888 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38889-};
38890+} __no_const;
38891
38892 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38893
38894diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38895index 41ff7e0..fa854ef 100644
38896--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38897+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38898@@ -92,7 +92,6 @@ struct nouveau_drm {
38899 struct drm_global_reference mem_global_ref;
38900 struct ttm_bo_global_ref bo_global_ref;
38901 struct ttm_bo_device bdev;
38902- atomic_t validate_sequence;
38903 int (*move)(struct nouveau_channel *,
38904 struct ttm_buffer_object *,
38905 struct ttm_mem_reg *, struct ttm_mem_reg *);
38906diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38907index 08214bc..9208577 100644
38908--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38909+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38910@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38911 unsigned long arg)
38912 {
38913 unsigned int nr = DRM_IOCTL_NR(cmd);
38914- drm_ioctl_compat_t *fn = NULL;
38915+ drm_ioctl_compat_t fn = NULL;
38916 int ret;
38917
38918 if (nr < DRM_COMMAND_BASE)
38919diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38920index 25d3495..d81aaf6 100644
38921--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38922+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38923@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38924 bool can_switch;
38925
38926 spin_lock(&dev->count_lock);
38927- can_switch = (dev->open_count == 0);
38928+ can_switch = (local_read(&dev->open_count) == 0);
38929 spin_unlock(&dev->count_lock);
38930 return can_switch;
38931 }
38932diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38933index 1dfd84c..104896c 100644
38934--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38935+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38936@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38937 }
38938 }
38939
38940-static struct vm_operations_struct qxl_ttm_vm_ops;
38941+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38942 static const struct vm_operations_struct *ttm_vm_ops;
38943
38944 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38945@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38946 return r;
38947 if (unlikely(ttm_vm_ops == NULL)) {
38948 ttm_vm_ops = vma->vm_ops;
38949+ pax_open_kernel();
38950 qxl_ttm_vm_ops = *ttm_vm_ops;
38951 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38952+ pax_close_kernel();
38953 }
38954 vma->vm_ops = &qxl_ttm_vm_ops;
38955 return 0;
38956@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38957 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38958 {
38959 #if defined(CONFIG_DEBUG_FS)
38960- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38961- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38962- unsigned i;
38963+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38964+ {
38965+ .name = "qxl_mem_mm",
38966+ .show = &qxl_mm_dump_table,
38967+ },
38968+ {
38969+ .name = "qxl_surf_mm",
38970+ .show = &qxl_mm_dump_table,
38971+ }
38972+ };
38973
38974- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38975- if (i == 0)
38976- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38977- else
38978- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38979- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38980- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38981- qxl_mem_types_list[i].driver_features = 0;
38982- if (i == 0)
38983- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38984- else
38985- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38986+ pax_open_kernel();
38987+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38988+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38989+ pax_close_kernel();
38990
38991- }
38992- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38993+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38994 #else
38995 return 0;
38996 #endif
38997diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38998index d4660cf..70dbe65 100644
38999--- a/drivers/gpu/drm/r128/r128_cce.c
39000+++ b/drivers/gpu/drm/r128/r128_cce.c
39001@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
39002
39003 /* GH: Simple idle check.
39004 */
39005- atomic_set(&dev_priv->idle_count, 0);
39006+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39007
39008 /* We don't support anything other than bus-mastering ring mode,
39009 * but the ring can be in either AGP or PCI space for the ring
39010diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
39011index 930c71b..499aded 100644
39012--- a/drivers/gpu/drm/r128/r128_drv.h
39013+++ b/drivers/gpu/drm/r128/r128_drv.h
39014@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
39015 int is_pci;
39016 unsigned long cce_buffers_offset;
39017
39018- atomic_t idle_count;
39019+ atomic_unchecked_t idle_count;
39020
39021 int page_flipping;
39022 int current_page;
39023 u32 crtc_offset;
39024 u32 crtc_offset_cntl;
39025
39026- atomic_t vbl_received;
39027+ atomic_unchecked_t vbl_received;
39028
39029 u32 color_fmt;
39030 unsigned int front_offset;
39031diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
39032index a954c54..9cc595c 100644
39033--- a/drivers/gpu/drm/r128/r128_ioc32.c
39034+++ b/drivers/gpu/drm/r128/r128_ioc32.c
39035@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
39036 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
39037 }
39038
39039-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39040+drm_ioctl_compat_t r128_compat_ioctls[] = {
39041 [DRM_R128_INIT] = compat_r128_init,
39042 [DRM_R128_DEPTH] = compat_r128_depth,
39043 [DRM_R128_STIPPLE] = compat_r128_stipple,
39044@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39045 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39046 {
39047 unsigned int nr = DRM_IOCTL_NR(cmd);
39048- drm_ioctl_compat_t *fn = NULL;
39049 int ret;
39050
39051 if (nr < DRM_COMMAND_BASE)
39052 return drm_compat_ioctl(filp, cmd, arg);
39053
39054- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39055- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39056-
39057- if (fn != NULL)
39058+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39059+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39060 ret = (*fn) (filp, cmd, arg);
39061- else
39062+ } else
39063 ret = drm_ioctl(filp, cmd, arg);
39064
39065 return ret;
39066diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39067index 2ea4f09..d391371 100644
39068--- a/drivers/gpu/drm/r128/r128_irq.c
39069+++ b/drivers/gpu/drm/r128/r128_irq.c
39070@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39071 if (crtc != 0)
39072 return 0;
39073
39074- return atomic_read(&dev_priv->vbl_received);
39075+ return atomic_read_unchecked(&dev_priv->vbl_received);
39076 }
39077
39078 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39079@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39080 /* VBLANK interrupt */
39081 if (status & R128_CRTC_VBLANK_INT) {
39082 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39083- atomic_inc(&dev_priv->vbl_received);
39084+ atomic_inc_unchecked(&dev_priv->vbl_received);
39085 drm_handle_vblank(dev, 0);
39086 return IRQ_HANDLED;
39087 }
39088diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39089index 19bb7e6..de7e2a2 100644
39090--- a/drivers/gpu/drm/r128/r128_state.c
39091+++ b/drivers/gpu/drm/r128/r128_state.c
39092@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39093
39094 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39095 {
39096- if (atomic_read(&dev_priv->idle_count) == 0)
39097+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39098 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39099 else
39100- atomic_set(&dev_priv->idle_count, 0);
39101+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39102 }
39103
39104 #endif
39105diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39106index af85299..ed9ac8d 100644
39107--- a/drivers/gpu/drm/radeon/mkregtable.c
39108+++ b/drivers/gpu/drm/radeon/mkregtable.c
39109@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39110 regex_t mask_rex;
39111 regmatch_t match[4];
39112 char buf[1024];
39113- size_t end;
39114+ long end;
39115 int len;
39116 int done = 0;
39117 int r;
39118 unsigned o;
39119 struct offset *offset;
39120 char last_reg_s[10];
39121- int last_reg;
39122+ unsigned long last_reg;
39123
39124 if (regcomp
39125 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39126diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39127index d15f27e..ef11ffc 100644
39128--- a/drivers/gpu/drm/radeon/radeon_device.c
39129+++ b/drivers/gpu/drm/radeon/radeon_device.c
39130@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39131 bool can_switch;
39132
39133 spin_lock(&dev->count_lock);
39134- can_switch = (dev->open_count == 0);
39135+ can_switch = (local_read(&dev->open_count) == 0);
39136 spin_unlock(&dev->count_lock);
39137 return can_switch;
39138 }
39139diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39140index b369d42..8dd04eb 100644
39141--- a/drivers/gpu/drm/radeon/radeon_drv.h
39142+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39143@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39144
39145 /* SW interrupt */
39146 wait_queue_head_t swi_queue;
39147- atomic_t swi_emitted;
39148+ atomic_unchecked_t swi_emitted;
39149 int vblank_crtc;
39150 uint32_t irq_enable_reg;
39151 uint32_t r500_disp_irq_reg;
39152diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39153index c180df8..5fd8186 100644
39154--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39155+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39156@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39157 request = compat_alloc_user_space(sizeof(*request));
39158 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39159 || __put_user(req32.param, &request->param)
39160- || __put_user((void __user *)(unsigned long)req32.value,
39161+ || __put_user((unsigned long)req32.value,
39162 &request->value))
39163 return -EFAULT;
39164
39165@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39166 #define compat_radeon_cp_setparam NULL
39167 #endif /* X86_64 || IA64 */
39168
39169-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39170+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39171 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39172 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39173 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39174@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39175 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39176 {
39177 unsigned int nr = DRM_IOCTL_NR(cmd);
39178- drm_ioctl_compat_t *fn = NULL;
39179 int ret;
39180
39181 if (nr < DRM_COMMAND_BASE)
39182 return drm_compat_ioctl(filp, cmd, arg);
39183
39184- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39185- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39186-
39187- if (fn != NULL)
39188+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39189+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39190 ret = (*fn) (filp, cmd, arg);
39191- else
39192+ } else
39193 ret = drm_ioctl(filp, cmd, arg);
39194
39195 return ret;
39196diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39197index 8d68e97..9dcfed8 100644
39198--- a/drivers/gpu/drm/radeon/radeon_irq.c
39199+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39200@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39201 unsigned int ret;
39202 RING_LOCALS;
39203
39204- atomic_inc(&dev_priv->swi_emitted);
39205- ret = atomic_read(&dev_priv->swi_emitted);
39206+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39207+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39208
39209 BEGIN_RING(4);
39210 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39211@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39212 drm_radeon_private_t *dev_priv =
39213 (drm_radeon_private_t *) dev->dev_private;
39214
39215- atomic_set(&dev_priv->swi_emitted, 0);
39216+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39217 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39218
39219 dev->max_vblank_count = 0x001fffff;
39220diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39221index 4d20910..6726b6d 100644
39222--- a/drivers/gpu/drm/radeon/radeon_state.c
39223+++ b/drivers/gpu/drm/radeon/radeon_state.c
39224@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39225 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39226 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39227
39228- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39229+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39230 sarea_priv->nbox * sizeof(depth_boxes[0])))
39231 return -EFAULT;
39232
39233@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39234 {
39235 drm_radeon_private_t *dev_priv = dev->dev_private;
39236 drm_radeon_getparam_t *param = data;
39237- int value;
39238+ int value = 0;
39239
39240 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39241
39242diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39243index 6c0ce89..57a2529 100644
39244--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39245+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39246@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39247 man->size = size >> PAGE_SHIFT;
39248 }
39249
39250-static struct vm_operations_struct radeon_ttm_vm_ops;
39251+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39252 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39253
39254 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39255@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39256 }
39257 if (unlikely(ttm_vm_ops == NULL)) {
39258 ttm_vm_ops = vma->vm_ops;
39259+ pax_open_kernel();
39260 radeon_ttm_vm_ops = *ttm_vm_ops;
39261 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39262+ pax_close_kernel();
39263 }
39264 vma->vm_ops = &radeon_ttm_vm_ops;
39265 return 0;
39266@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39267 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39268 {
39269 #if defined(CONFIG_DEBUG_FS)
39270- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39271- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39272+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39273+ {
39274+ .name = "radeon_vram_mm",
39275+ .show = &radeon_mm_dump_table,
39276+ },
39277+ {
39278+ .name = "radeon_gtt_mm",
39279+ .show = &radeon_mm_dump_table,
39280+ },
39281+ {
39282+ .name = "ttm_page_pool",
39283+ .show = &ttm_page_alloc_debugfs,
39284+ },
39285+ {
39286+ .name = "ttm_dma_page_pool",
39287+ .show = &ttm_dma_page_alloc_debugfs,
39288+ },
39289+ };
39290 unsigned i;
39291
39292- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39293- if (i == 0)
39294- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39295- else
39296- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39297- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39298- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39299- radeon_mem_types_list[i].driver_features = 0;
39300- if (i == 0)
39301- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39302- else
39303- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39304-
39305- }
39306- /* Add ttm page pool to debugfs */
39307- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39308- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39309- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39310- radeon_mem_types_list[i].driver_features = 0;
39311- radeon_mem_types_list[i++].data = NULL;
39312+ pax_open_kernel();
39313+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39314+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39315+ pax_close_kernel();
39316 #ifdef CONFIG_SWIOTLB
39317- if (swiotlb_nr_tbl()) {
39318- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39319- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39320- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39321- radeon_mem_types_list[i].driver_features = 0;
39322- radeon_mem_types_list[i++].data = NULL;
39323- }
39324+ if (swiotlb_nr_tbl())
39325+ i++;
39326 #endif
39327 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39328
39329diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39330index d8ddfb3..609de1d 100644
39331--- a/drivers/gpu/drm/radeon/rs690.c
39332+++ b/drivers/gpu/drm/radeon/rs690.c
39333@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39334 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39335 rdev->pm.sideport_bandwidth.full)
39336 max_bandwidth = rdev->pm.sideport_bandwidth;
39337- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39338+ read_delay_latency.full = dfixed_const(800 * 1000);
39339 read_delay_latency.full = dfixed_div(read_delay_latency,
39340 rdev->pm.igp_sideport_mclk);
39341+ a.full = dfixed_const(370);
39342+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39343 } else {
39344 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39345 rdev->pm.k8_bandwidth.full)
39346diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39347index dbc2def..0a9f710 100644
39348--- a/drivers/gpu/drm/ttm/ttm_memory.c
39349+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39350@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39351 zone->glob = glob;
39352 glob->zone_kernel = zone;
39353 ret = kobject_init_and_add(
39354- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39355+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39356 if (unlikely(ret != 0)) {
39357 kobject_put(&zone->kobj);
39358 return ret;
39359@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39360 zone->glob = glob;
39361 glob->zone_dma32 = zone;
39362 ret = kobject_init_and_add(
39363- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39364+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39365 if (unlikely(ret != 0)) {
39366 kobject_put(&zone->kobj);
39367 return ret;
39368diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39369index bd2a3b4..122d9ad 100644
39370--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39371+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39372@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39373 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39374 struct shrink_control *sc)
39375 {
39376- static atomic_t start_pool = ATOMIC_INIT(0);
39377+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39378 unsigned i;
39379- unsigned pool_offset = atomic_add_return(1, &start_pool);
39380+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39381 struct ttm_page_pool *pool;
39382 int shrink_pages = sc->nr_to_scan;
39383
39384diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39385index 97e9d61..bf23c461 100644
39386--- a/drivers/gpu/drm/udl/udl_fb.c
39387+++ b/drivers/gpu/drm/udl/udl_fb.c
39388@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39389 fb_deferred_io_cleanup(info);
39390 kfree(info->fbdefio);
39391 info->fbdefio = NULL;
39392- info->fbops->fb_mmap = udl_fb_mmap;
39393 }
39394
39395 pr_warn("released /dev/fb%d user=%d count=%d\n",
39396diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39397index 893a650..6190d3b 100644
39398--- a/drivers/gpu/drm/via/via_drv.h
39399+++ b/drivers/gpu/drm/via/via_drv.h
39400@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39401 typedef uint32_t maskarray_t[5];
39402
39403 typedef struct drm_via_irq {
39404- atomic_t irq_received;
39405+ atomic_unchecked_t irq_received;
39406 uint32_t pending_mask;
39407 uint32_t enable_mask;
39408 wait_queue_head_t irq_queue;
39409@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39410 struct timeval last_vblank;
39411 int last_vblank_valid;
39412 unsigned usec_per_vblank;
39413- atomic_t vbl_received;
39414+ atomic_unchecked_t vbl_received;
39415 drm_via_state_t hc_state;
39416 char pci_buf[VIA_PCI_BUF_SIZE];
39417 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39418diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39419index ac98964..5dbf512 100644
39420--- a/drivers/gpu/drm/via/via_irq.c
39421+++ b/drivers/gpu/drm/via/via_irq.c
39422@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39423 if (crtc != 0)
39424 return 0;
39425
39426- return atomic_read(&dev_priv->vbl_received);
39427+ return atomic_read_unchecked(&dev_priv->vbl_received);
39428 }
39429
39430 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39431@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39432
39433 status = VIA_READ(VIA_REG_INTERRUPT);
39434 if (status & VIA_IRQ_VBLANK_PENDING) {
39435- atomic_inc(&dev_priv->vbl_received);
39436- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39437+ atomic_inc_unchecked(&dev_priv->vbl_received);
39438+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39439 do_gettimeofday(&cur_vblank);
39440 if (dev_priv->last_vblank_valid) {
39441 dev_priv->usec_per_vblank =
39442@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39443 dev_priv->last_vblank = cur_vblank;
39444 dev_priv->last_vblank_valid = 1;
39445 }
39446- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39447+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39448 DRM_DEBUG("US per vblank is: %u\n",
39449 dev_priv->usec_per_vblank);
39450 }
39451@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39452
39453 for (i = 0; i < dev_priv->num_irqs; ++i) {
39454 if (status & cur_irq->pending_mask) {
39455- atomic_inc(&cur_irq->irq_received);
39456+ atomic_inc_unchecked(&cur_irq->irq_received);
39457 DRM_WAKEUP(&cur_irq->irq_queue);
39458 handled = 1;
39459 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39460@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39461 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39462 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39463 masks[irq][4]));
39464- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39465+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39466 } else {
39467 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39468 (((cur_irq_sequence =
39469- atomic_read(&cur_irq->irq_received)) -
39470+ atomic_read_unchecked(&cur_irq->irq_received)) -
39471 *sequence) <= (1 << 23)));
39472 }
39473 *sequence = cur_irq_sequence;
39474@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39475 }
39476
39477 for (i = 0; i < dev_priv->num_irqs; ++i) {
39478- atomic_set(&cur_irq->irq_received, 0);
39479+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39480 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39481 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39482 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39483@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39484 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39485 case VIA_IRQ_RELATIVE:
39486 irqwait->request.sequence +=
39487- atomic_read(&cur_irq->irq_received);
39488+ atomic_read_unchecked(&cur_irq->irq_received);
39489 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39490 case VIA_IRQ_ABSOLUTE:
39491 break;
39492diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39493index 13aeda7..4a952d1 100644
39494--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39495+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39496@@ -290,7 +290,7 @@ struct vmw_private {
39497 * Fencing and IRQs.
39498 */
39499
39500- atomic_t marker_seq;
39501+ atomic_unchecked_t marker_seq;
39502 wait_queue_head_t fence_queue;
39503 wait_queue_head_t fifo_queue;
39504 int fence_queue_waiters; /* Protected by hw_mutex */
39505diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39506index 3eb1486..0a47ee9 100644
39507--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39508+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39509@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39510 (unsigned int) min,
39511 (unsigned int) fifo->capabilities);
39512
39513- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39514+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39515 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39516 vmw_marker_queue_init(&fifo->marker_queue);
39517 return vmw_fifo_send_fence(dev_priv, &dummy);
39518@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39519 if (reserveable)
39520 iowrite32(bytes, fifo_mem +
39521 SVGA_FIFO_RESERVED);
39522- return fifo_mem + (next_cmd >> 2);
39523+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39524 } else {
39525 need_bounce = true;
39526 }
39527@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39528
39529 fm = vmw_fifo_reserve(dev_priv, bytes);
39530 if (unlikely(fm == NULL)) {
39531- *seqno = atomic_read(&dev_priv->marker_seq);
39532+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39533 ret = -ENOMEM;
39534 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39535 false, 3*HZ);
39536@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39537 }
39538
39539 do {
39540- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39541+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39542 } while (*seqno == 0);
39543
39544 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39545diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39546index c509d40..3b640c3 100644
39547--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39548+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39549@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39550 int ret;
39551
39552 num_clips = arg->num_clips;
39553- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39554+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39555
39556 if (unlikely(num_clips == 0))
39557 return 0;
39558@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39559 int ret;
39560
39561 num_clips = arg->num_clips;
39562- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39563+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39564
39565 if (unlikely(num_clips == 0))
39566 return 0;
39567diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39568index 4640adb..e1384ed 100644
39569--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39570+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39571@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39572 * emitted. Then the fence is stale and signaled.
39573 */
39574
39575- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39576+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39577 > VMW_FENCE_WRAP);
39578
39579 return ret;
39580@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39581
39582 if (fifo_idle)
39583 down_read(&fifo_state->rwsem);
39584- signal_seq = atomic_read(&dev_priv->marker_seq);
39585+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39586 ret = 0;
39587
39588 for (;;) {
39589diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39590index 8a8725c2..afed796 100644
39591--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39592+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39593@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39594 while (!vmw_lag_lt(queue, us)) {
39595 spin_lock(&queue->lock);
39596 if (list_empty(&queue->head))
39597- seqno = atomic_read(&dev_priv->marker_seq);
39598+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39599 else {
39600 marker = list_first_entry(&queue->head,
39601 struct vmw_marker, head);
39602diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39603index 5360e5a..c2c0d26 100644
39604--- a/drivers/gpu/host1x/drm/dc.c
39605+++ b/drivers/gpu/host1x/drm/dc.c
39606@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39607 }
39608
39609 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39610- dc->debugfs_files[i].data = dc;
39611+ *(void **)&dc->debugfs_files[i].data = dc;
39612
39613 err = drm_debugfs_create_files(dc->debugfs_files,
39614 ARRAY_SIZE(debugfs_files),
39615diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39616index 9f60d63..c89e0b7 100644
39617--- a/drivers/hid/hid-core.c
39618+++ b/drivers/hid/hid-core.c
39619@@ -2370,7 +2370,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39620
39621 int hid_add_device(struct hid_device *hdev)
39622 {
39623- static atomic_t id = ATOMIC_INIT(0);
39624+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39625 int ret;
39626
39627 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39628@@ -2404,7 +2404,7 @@ int hid_add_device(struct hid_device *hdev)
39629 /* XXX hack, any other cleaner solution after the driver core
39630 * is converted to allow more than 20 bytes as the device name? */
39631 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39632- hdev->vendor, hdev->product, atomic_inc_return(&id));
39633+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39634
39635 hid_debug_register(hdev, dev_name(&hdev->dev));
39636 ret = device_add(&hdev->dev);
39637diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39638index c13fb5b..55a3802 100644
39639--- a/drivers/hid/hid-wiimote-debug.c
39640+++ b/drivers/hid/hid-wiimote-debug.c
39641@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39642 else if (size == 0)
39643 return -EIO;
39644
39645- if (copy_to_user(u, buf, size))
39646+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39647 return -EFAULT;
39648
39649 *off += size;
39650diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39651index 145a4cb..2353a3e 100644
39652--- a/drivers/hid/uhid.c
39653+++ b/drivers/hid/uhid.c
39654@@ -47,7 +47,7 @@ struct uhid_device {
39655 struct mutex report_lock;
39656 wait_queue_head_t report_wait;
39657 atomic_t report_done;
39658- atomic_t report_id;
39659+ atomic_unchecked_t report_id;
39660 struct uhid_event report_buf;
39661 };
39662
39663@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39664
39665 spin_lock_irqsave(&uhid->qlock, flags);
39666 ev->type = UHID_FEATURE;
39667- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39668+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39669 ev->u.feature.rnum = rnum;
39670 ev->u.feature.rtype = report_type;
39671
39672@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39673 spin_lock_irqsave(&uhid->qlock, flags);
39674
39675 /* id for old report; drop it silently */
39676- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39677+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39678 goto unlock;
39679 if (atomic_read(&uhid->report_done))
39680 goto unlock;
39681diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39682index 6de6c98..18319e9 100644
39683--- a/drivers/hv/channel.c
39684+++ b/drivers/hv/channel.c
39685@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39686 int ret = 0;
39687 int t;
39688
39689- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39690- atomic_inc(&vmbus_connection.next_gpadl_handle);
39691+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39692+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39693
39694 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39695 if (ret)
39696diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39697index 88f4096..e50452e 100644
39698--- a/drivers/hv/hv.c
39699+++ b/drivers/hv/hv.c
39700@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39701 u64 output_address = (output) ? virt_to_phys(output) : 0;
39702 u32 output_address_hi = output_address >> 32;
39703 u32 output_address_lo = output_address & 0xFFFFFFFF;
39704- void *hypercall_page = hv_context.hypercall_page;
39705+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39706
39707 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39708 "=a"(hv_status_lo) : "d" (control_hi),
39709diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39710index deb5c25..ed2d4fd 100644
39711--- a/drivers/hv/hv_balloon.c
39712+++ b/drivers/hv/hv_balloon.c
39713@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39714
39715 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39716 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39717-static atomic_t trans_id = ATOMIC_INIT(0);
39718+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39719
39720 static int dm_ring_size = (5 * PAGE_SIZE);
39721
39722@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39723 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39724 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39725 resp.hdr.size = sizeof(struct dm_hot_add_response);
39726- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39727+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39728
39729 #ifdef CONFIG_MEMORY_HOTPLUG
39730 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39731@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39732 memset(&status, 0, sizeof(struct dm_status));
39733 status.hdr.type = DM_STATUS_REPORT;
39734 status.hdr.size = sizeof(struct dm_status);
39735- status.hdr.trans_id = atomic_inc_return(&trans_id);
39736+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39737
39738 /*
39739 * The host expects the guest to report free memory.
39740@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39741 * send the status. This can happen if we were interrupted
39742 * after we picked our transaction ID.
39743 */
39744- if (status.hdr.trans_id != atomic_read(&trans_id))
39745+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39746 return;
39747
39748 vmbus_sendpacket(dm->dev->channel, &status,
39749@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39750 bl_resp = (struct dm_balloon_response *)send_buffer;
39751 memset(send_buffer, 0, PAGE_SIZE);
39752 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39753- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39754+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39755 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39756 bl_resp->more_pages = 1;
39757
39758@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39759
39760 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39761 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39762- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39763+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39764 resp.hdr.size = sizeof(struct dm_unballoon_response);
39765
39766 vmbus_sendpacket(dm_device.dev->channel, &resp,
39767@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39768 memset(&version_req, 0, sizeof(struct dm_version_request));
39769 version_req.hdr.type = DM_VERSION_REQUEST;
39770 version_req.hdr.size = sizeof(struct dm_version_request);
39771- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39772+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39773 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39774 version_req.is_last_attempt = 1;
39775
39776@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39777 memset(&version_req, 0, sizeof(struct dm_version_request));
39778 version_req.hdr.type = DM_VERSION_REQUEST;
39779 version_req.hdr.size = sizeof(struct dm_version_request);
39780- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39781+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39782 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39783 version_req.is_last_attempt = 0;
39784
39785@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39786 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39787 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39788 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39789- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39790+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39791
39792 cap_msg.caps.cap_bits.balloon = 1;
39793 cap_msg.caps.cap_bits.hot_add = 1;
39794diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39795index d84918f..7f38f9f 100644
39796--- a/drivers/hv/hyperv_vmbus.h
39797+++ b/drivers/hv/hyperv_vmbus.h
39798@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39799 struct vmbus_connection {
39800 enum vmbus_connect_state conn_state;
39801
39802- atomic_t next_gpadl_handle;
39803+ atomic_unchecked_t next_gpadl_handle;
39804
39805 /*
39806 * Represents channel interrupts. Each bit position represents a
39807diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39808index e8e071f..5b4b245 100644
39809--- a/drivers/hv/vmbus_drv.c
39810+++ b/drivers/hv/vmbus_drv.c
39811@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39812 {
39813 int ret = 0;
39814
39815- static atomic_t device_num = ATOMIC_INIT(0);
39816+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39817
39818 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39819- atomic_inc_return(&device_num));
39820+ atomic_inc_return_unchecked(&device_num));
39821
39822 child_device_obj->device.bus = &hv_bus;
39823 child_device_obj->device.parent = &hv_acpi_dev->dev;
39824diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39825index 6351aba..dc4aaf4 100644
39826--- a/drivers/hwmon/acpi_power_meter.c
39827+++ b/drivers/hwmon/acpi_power_meter.c
39828@@ -117,7 +117,7 @@ struct sensor_template {
39829 struct device_attribute *devattr,
39830 const char *buf, size_t count);
39831 int index;
39832-};
39833+} __do_const;
39834
39835 /* Averaging interval */
39836 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39837@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39838 struct sensor_template *attrs)
39839 {
39840 struct device *dev = &resource->acpi_dev->dev;
39841- struct sensor_device_attribute *sensors =
39842+ sensor_device_attribute_no_const *sensors =
39843 &resource->sensors[resource->num_sensors];
39844 int res = 0;
39845
39846diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39847index 98814d1..9435d05 100644
39848--- a/drivers/hwmon/applesmc.c
39849+++ b/drivers/hwmon/applesmc.c
39850@@ -1093,7 +1093,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39851 {
39852 struct applesmc_node_group *grp;
39853 struct applesmc_dev_attr *node;
39854- struct attribute *attr;
39855+ attribute_no_const *attr;
39856 int ret, i;
39857
39858 for (grp = groups; grp->format; grp++) {
39859diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39860index b25c643..a13460d 100644
39861--- a/drivers/hwmon/asus_atk0110.c
39862+++ b/drivers/hwmon/asus_atk0110.c
39863@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39864 struct atk_sensor_data {
39865 struct list_head list;
39866 struct atk_data *data;
39867- struct device_attribute label_attr;
39868- struct device_attribute input_attr;
39869- struct device_attribute limit1_attr;
39870- struct device_attribute limit2_attr;
39871+ device_attribute_no_const label_attr;
39872+ device_attribute_no_const input_attr;
39873+ device_attribute_no_const limit1_attr;
39874+ device_attribute_no_const limit2_attr;
39875 char label_attr_name[ATTR_NAME_SIZE];
39876 char input_attr_name[ATTR_NAME_SIZE];
39877 char limit1_attr_name[ATTR_NAME_SIZE];
39878@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39879 static struct device_attribute atk_name_attr =
39880 __ATTR(name, 0444, atk_name_show, NULL);
39881
39882-static void atk_init_attribute(struct device_attribute *attr, char *name,
39883+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39884 sysfs_show_func show)
39885 {
39886 sysfs_attr_init(&attr->attr);
39887diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39888index 2e5e2dc..5208b31 100644
39889--- a/drivers/hwmon/coretemp.c
39890+++ b/drivers/hwmon/coretemp.c
39891@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39892 return NOTIFY_OK;
39893 }
39894
39895-static struct notifier_block coretemp_cpu_notifier __refdata = {
39896+static struct notifier_block coretemp_cpu_notifier = {
39897 .notifier_call = coretemp_cpu_callback,
39898 };
39899
39900diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39901index 1429f6e..ee03d59 100644
39902--- a/drivers/hwmon/ibmaem.c
39903+++ b/drivers/hwmon/ibmaem.c
39904@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39905 struct aem_rw_sensor_template *rw)
39906 {
39907 struct device *dev = &data->pdev->dev;
39908- struct sensor_device_attribute *sensors = data->sensors;
39909+ sensor_device_attribute_no_const *sensors = data->sensors;
39910 int err;
39911
39912 /* Set up read-only sensors */
39913diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39914index 708081b..fe2d4ab 100644
39915--- a/drivers/hwmon/iio_hwmon.c
39916+++ b/drivers/hwmon/iio_hwmon.c
39917@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39918 {
39919 struct device *dev = &pdev->dev;
39920 struct iio_hwmon_state *st;
39921- struct sensor_device_attribute *a;
39922+ sensor_device_attribute_no_const *a;
39923 int ret, i;
39924 int in_i = 1, temp_i = 1, curr_i = 1;
39925 enum iio_chan_type type;
39926diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39927index 9add6092..ee7ba3f 100644
39928--- a/drivers/hwmon/pmbus/pmbus_core.c
39929+++ b/drivers/hwmon/pmbus/pmbus_core.c
39930@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39931 return 0;
39932 }
39933
39934-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39935+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39936 const char *name,
39937 umode_t mode,
39938 ssize_t (*show)(struct device *dev,
39939@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39940 dev_attr->store = store;
39941 }
39942
39943-static void pmbus_attr_init(struct sensor_device_attribute *a,
39944+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39945 const char *name,
39946 umode_t mode,
39947 ssize_t (*show)(struct device *dev,
39948@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39949 u16 reg, u8 mask)
39950 {
39951 struct pmbus_boolean *boolean;
39952- struct sensor_device_attribute *a;
39953+ sensor_device_attribute_no_const *a;
39954
39955 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39956 if (!boolean)
39957@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39958 bool update, bool readonly)
39959 {
39960 struct pmbus_sensor *sensor;
39961- struct device_attribute *a;
39962+ device_attribute_no_const *a;
39963
39964 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39965 if (!sensor)
39966@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39967 const char *lstring, int index)
39968 {
39969 struct pmbus_label *label;
39970- struct device_attribute *a;
39971+ device_attribute_no_const *a;
39972
39973 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39974 if (!label)
39975diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39976index 2507f90..1645765 100644
39977--- a/drivers/hwmon/sht15.c
39978+++ b/drivers/hwmon/sht15.c
39979@@ -169,7 +169,7 @@ struct sht15_data {
39980 int supply_uv;
39981 bool supply_uv_valid;
39982 struct work_struct update_supply_work;
39983- atomic_t interrupt_handled;
39984+ atomic_unchecked_t interrupt_handled;
39985 };
39986
39987 /**
39988@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39989 ret = gpio_direction_input(data->pdata->gpio_data);
39990 if (ret)
39991 return ret;
39992- atomic_set(&data->interrupt_handled, 0);
39993+ atomic_set_unchecked(&data->interrupt_handled, 0);
39994
39995 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39996 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39997 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39998 /* Only relevant if the interrupt hasn't occurred. */
39999- if (!atomic_read(&data->interrupt_handled))
40000+ if (!atomic_read_unchecked(&data->interrupt_handled))
40001 schedule_work(&data->read_work);
40002 }
40003 ret = wait_event_timeout(data->wait_queue,
40004@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40005
40006 /* First disable the interrupt */
40007 disable_irq_nosync(irq);
40008- atomic_inc(&data->interrupt_handled);
40009+ atomic_inc_unchecked(&data->interrupt_handled);
40010 /* Then schedule a reading work struct */
40011 if (data->state != SHT15_READING_NOTHING)
40012 schedule_work(&data->read_work);
40013@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40014 * If not, then start the interrupt again - care here as could
40015 * have gone low in meantime so verify it hasn't!
40016 */
40017- atomic_set(&data->interrupt_handled, 0);
40018+ atomic_set_unchecked(&data->interrupt_handled, 0);
40019 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40020 /* If still not occurred or another handler was scheduled */
40021 if (gpio_get_value(data->pdata->gpio_data)
40022- || atomic_read(&data->interrupt_handled))
40023+ || atomic_read_unchecked(&data->interrupt_handled))
40024 return;
40025 }
40026
40027diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40028index 38944e9..ae9e5ed 100644
40029--- a/drivers/hwmon/via-cputemp.c
40030+++ b/drivers/hwmon/via-cputemp.c
40031@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40032 return NOTIFY_OK;
40033 }
40034
40035-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40036+static struct notifier_block via_cputemp_cpu_notifier = {
40037 .notifier_call = via_cputemp_cpu_callback,
40038 };
40039
40040diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40041index 07f01ac..d79ad3d 100644
40042--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40043+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40044@@ -43,7 +43,7 @@
40045 extern struct i2c_adapter amd756_smbus;
40046
40047 static struct i2c_adapter *s4882_adapter;
40048-static struct i2c_algorithm *s4882_algo;
40049+static i2c_algorithm_no_const *s4882_algo;
40050
40051 /* Wrapper access functions for multiplexed SMBus */
40052 static DEFINE_MUTEX(amd756_lock);
40053diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40054index 2ca268d..c6acbdf 100644
40055--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40056+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40057@@ -41,7 +41,7 @@
40058 extern struct i2c_adapter *nforce2_smbus;
40059
40060 static struct i2c_adapter *s4985_adapter;
40061-static struct i2c_algorithm *s4985_algo;
40062+static i2c_algorithm_no_const *s4985_algo;
40063
40064 /* Wrapper access functions for multiplexed SMBus */
40065 static DEFINE_MUTEX(nforce2_lock);
40066diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40067index c3ccdea..5b3dc1a 100644
40068--- a/drivers/i2c/i2c-dev.c
40069+++ b/drivers/i2c/i2c-dev.c
40070@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40071 break;
40072 }
40073
40074- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40075+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40076 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40077 if (IS_ERR(rdwr_pa[i].buf)) {
40078 res = PTR_ERR(rdwr_pa[i].buf);
40079diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40080index 0b510ba..4fbb5085 100644
40081--- a/drivers/ide/ide-cd.c
40082+++ b/drivers/ide/ide-cd.c
40083@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40084 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40085 if ((unsigned long)buf & alignment
40086 || blk_rq_bytes(rq) & q->dma_pad_mask
40087- || object_is_on_stack(buf))
40088+ || object_starts_on_stack(buf))
40089 drive->dma = 0;
40090 }
40091 }
40092diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40093index e145931..08bfc59 100644
40094--- a/drivers/iio/industrialio-core.c
40095+++ b/drivers/iio/industrialio-core.c
40096@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40097 }
40098
40099 static
40100-int __iio_device_attr_init(struct device_attribute *dev_attr,
40101+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40102 const char *postfix,
40103 struct iio_chan_spec const *chan,
40104 ssize_t (*readfunc)(struct device *dev,
40105diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40106index 784b97c..c9ceadf 100644
40107--- a/drivers/infiniband/core/cm.c
40108+++ b/drivers/infiniband/core/cm.c
40109@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40110
40111 struct cm_counter_group {
40112 struct kobject obj;
40113- atomic_long_t counter[CM_ATTR_COUNT];
40114+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40115 };
40116
40117 struct cm_counter_attribute {
40118@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40119 struct ib_mad_send_buf *msg = NULL;
40120 int ret;
40121
40122- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40123+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40124 counter[CM_REQ_COUNTER]);
40125
40126 /* Quick state check to discard duplicate REQs. */
40127@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40128 if (!cm_id_priv)
40129 return;
40130
40131- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40132+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40133 counter[CM_REP_COUNTER]);
40134 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40135 if (ret)
40136@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40137 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40138 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40139 spin_unlock_irq(&cm_id_priv->lock);
40140- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40141+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40142 counter[CM_RTU_COUNTER]);
40143 goto out;
40144 }
40145@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40146 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40147 dreq_msg->local_comm_id);
40148 if (!cm_id_priv) {
40149- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40150+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40151 counter[CM_DREQ_COUNTER]);
40152 cm_issue_drep(work->port, work->mad_recv_wc);
40153 return -EINVAL;
40154@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40155 case IB_CM_MRA_REP_RCVD:
40156 break;
40157 case IB_CM_TIMEWAIT:
40158- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40159+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40160 counter[CM_DREQ_COUNTER]);
40161 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40162 goto unlock;
40163@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40164 cm_free_msg(msg);
40165 goto deref;
40166 case IB_CM_DREQ_RCVD:
40167- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40168+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40169 counter[CM_DREQ_COUNTER]);
40170 goto unlock;
40171 default:
40172@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40173 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40174 cm_id_priv->msg, timeout)) {
40175 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40176- atomic_long_inc(&work->port->
40177+ atomic_long_inc_unchecked(&work->port->
40178 counter_group[CM_RECV_DUPLICATES].
40179 counter[CM_MRA_COUNTER]);
40180 goto out;
40181@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40182 break;
40183 case IB_CM_MRA_REQ_RCVD:
40184 case IB_CM_MRA_REP_RCVD:
40185- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40186+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40187 counter[CM_MRA_COUNTER]);
40188 /* fall through */
40189 default:
40190@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40191 case IB_CM_LAP_IDLE:
40192 break;
40193 case IB_CM_MRA_LAP_SENT:
40194- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40195+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40196 counter[CM_LAP_COUNTER]);
40197 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40198 goto unlock;
40199@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40200 cm_free_msg(msg);
40201 goto deref;
40202 case IB_CM_LAP_RCVD:
40203- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40204+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40205 counter[CM_LAP_COUNTER]);
40206 goto unlock;
40207 default:
40208@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40209 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40210 if (cur_cm_id_priv) {
40211 spin_unlock_irq(&cm.lock);
40212- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40213+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40214 counter[CM_SIDR_REQ_COUNTER]);
40215 goto out; /* Duplicate message. */
40216 }
40217@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40218 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40219 msg->retries = 1;
40220
40221- atomic_long_add(1 + msg->retries,
40222+ atomic_long_add_unchecked(1 + msg->retries,
40223 &port->counter_group[CM_XMIT].counter[attr_index]);
40224 if (msg->retries)
40225- atomic_long_add(msg->retries,
40226+ atomic_long_add_unchecked(msg->retries,
40227 &port->counter_group[CM_XMIT_RETRIES].
40228 counter[attr_index]);
40229
40230@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40231 }
40232
40233 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40234- atomic_long_inc(&port->counter_group[CM_RECV].
40235+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40236 counter[attr_id - CM_ATTR_ID_OFFSET]);
40237
40238 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40239@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40240 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40241
40242 return sprintf(buf, "%ld\n",
40243- atomic_long_read(&group->counter[cm_attr->index]));
40244+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40245 }
40246
40247 static const struct sysfs_ops cm_counter_ops = {
40248diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40249index 9f5ad7c..588cd84 100644
40250--- a/drivers/infiniband/core/fmr_pool.c
40251+++ b/drivers/infiniband/core/fmr_pool.c
40252@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40253
40254 struct task_struct *thread;
40255
40256- atomic_t req_ser;
40257- atomic_t flush_ser;
40258+ atomic_unchecked_t req_ser;
40259+ atomic_unchecked_t flush_ser;
40260
40261 wait_queue_head_t force_wait;
40262 };
40263@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40264 struct ib_fmr_pool *pool = pool_ptr;
40265
40266 do {
40267- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40268+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40269 ib_fmr_batch_release(pool);
40270
40271- atomic_inc(&pool->flush_ser);
40272+ atomic_inc_unchecked(&pool->flush_ser);
40273 wake_up_interruptible(&pool->force_wait);
40274
40275 if (pool->flush_function)
40276@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40277 }
40278
40279 set_current_state(TASK_INTERRUPTIBLE);
40280- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40281+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40282 !kthread_should_stop())
40283 schedule();
40284 __set_current_state(TASK_RUNNING);
40285@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40286 pool->dirty_watermark = params->dirty_watermark;
40287 pool->dirty_len = 0;
40288 spin_lock_init(&pool->pool_lock);
40289- atomic_set(&pool->req_ser, 0);
40290- atomic_set(&pool->flush_ser, 0);
40291+ atomic_set_unchecked(&pool->req_ser, 0);
40292+ atomic_set_unchecked(&pool->flush_ser, 0);
40293 init_waitqueue_head(&pool->force_wait);
40294
40295 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40296@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40297 }
40298 spin_unlock_irq(&pool->pool_lock);
40299
40300- serial = atomic_inc_return(&pool->req_ser);
40301+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40302 wake_up_process(pool->thread);
40303
40304 if (wait_event_interruptible(pool->force_wait,
40305- atomic_read(&pool->flush_ser) - serial >= 0))
40306+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40307 return -EINTR;
40308
40309 return 0;
40310@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40311 } else {
40312 list_add_tail(&fmr->list, &pool->dirty_list);
40313 if (++pool->dirty_len >= pool->dirty_watermark) {
40314- atomic_inc(&pool->req_ser);
40315+ atomic_inc_unchecked(&pool->req_ser);
40316 wake_up_process(pool->thread);
40317 }
40318 }
40319diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40320index 4cb8eb2..146bf60 100644
40321--- a/drivers/infiniband/hw/cxgb4/mem.c
40322+++ b/drivers/infiniband/hw/cxgb4/mem.c
40323@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40324 int err;
40325 struct fw_ri_tpte tpt;
40326 u32 stag_idx;
40327- static atomic_t key;
40328+ static atomic_unchecked_t key;
40329
40330 if (c4iw_fatal_error(rdev))
40331 return -EIO;
40332@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40333 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40334 rdev->stats.stag.max = rdev->stats.stag.cur;
40335 mutex_unlock(&rdev->stats.lock);
40336- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40337+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40338 }
40339 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40340 __func__, stag_state, type, pdid, stag_idx);
40341diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40342index 79b3dbc..96e5fcc 100644
40343--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40344+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40345@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40346 struct ib_atomic_eth *ateth;
40347 struct ipath_ack_entry *e;
40348 u64 vaddr;
40349- atomic64_t *maddr;
40350+ atomic64_unchecked_t *maddr;
40351 u64 sdata;
40352 u32 rkey;
40353 u8 next;
40354@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40355 IB_ACCESS_REMOTE_ATOMIC)))
40356 goto nack_acc_unlck;
40357 /* Perform atomic OP and save result. */
40358- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40359+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40360 sdata = be64_to_cpu(ateth->swap_data);
40361 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40362 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40363- (u64) atomic64_add_return(sdata, maddr) - sdata :
40364+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40365 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40366 be64_to_cpu(ateth->compare_data),
40367 sdata);
40368diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40369index 1f95bba..9530f87 100644
40370--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40371+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40372@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40373 unsigned long flags;
40374 struct ib_wc wc;
40375 u64 sdata;
40376- atomic64_t *maddr;
40377+ atomic64_unchecked_t *maddr;
40378 enum ib_wc_status send_status;
40379
40380 /*
40381@@ -382,11 +382,11 @@ again:
40382 IB_ACCESS_REMOTE_ATOMIC)))
40383 goto acc_err;
40384 /* Perform atomic OP and save result. */
40385- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40386+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40387 sdata = wqe->wr.wr.atomic.compare_add;
40388 *(u64 *) sqp->s_sge.sge.vaddr =
40389 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40390- (u64) atomic64_add_return(sdata, maddr) - sdata :
40391+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40392 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40393 sdata, wqe->wr.wr.atomic.swap);
40394 goto send_comp;
40395diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40396index f2a3f48..673ec79 100644
40397--- a/drivers/infiniband/hw/mlx4/mad.c
40398+++ b/drivers/infiniband/hw/mlx4/mad.c
40399@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40400
40401 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40402 {
40403- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40404+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40405 cpu_to_be64(0xff00000000000000LL);
40406 }
40407
40408diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40409index 25b2cdf..099ff97 100644
40410--- a/drivers/infiniband/hw/mlx4/mcg.c
40411+++ b/drivers/infiniband/hw/mlx4/mcg.c
40412@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40413 {
40414 char name[20];
40415
40416- atomic_set(&ctx->tid, 0);
40417+ atomic_set_unchecked(&ctx->tid, 0);
40418 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40419 ctx->mcg_wq = create_singlethread_workqueue(name);
40420 if (!ctx->mcg_wq)
40421diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40422index f61ec26..ebf72cf 100644
40423--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40424+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40425@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40426 struct list_head mcg_mgid0_list;
40427 struct workqueue_struct *mcg_wq;
40428 struct mlx4_ib_demux_pv_ctx **tun;
40429- atomic_t tid;
40430+ atomic_unchecked_t tid;
40431 int flushing; /* flushing the work queue */
40432 };
40433
40434diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40435index 9d3e5c1..d9afe4a 100644
40436--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40437+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40438@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40439 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40440 }
40441
40442-int mthca_QUERY_FW(struct mthca_dev *dev)
40443+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40444 {
40445 struct mthca_mailbox *mailbox;
40446 u32 *outbox;
40447diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40448index ed9a989..e0c5871 100644
40449--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40450+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40451@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40452 return key;
40453 }
40454
40455-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40456+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40457 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40458 {
40459 struct mthca_mailbox *mailbox;
40460diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40461index 4291410..d2ab1fb 100644
40462--- a/drivers/infiniband/hw/nes/nes.c
40463+++ b/drivers/infiniband/hw/nes/nes.c
40464@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40465 LIST_HEAD(nes_adapter_list);
40466 static LIST_HEAD(nes_dev_list);
40467
40468-atomic_t qps_destroyed;
40469+atomic_unchecked_t qps_destroyed;
40470
40471 static unsigned int ee_flsh_adapter;
40472 static unsigned int sysfs_nonidx_addr;
40473@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40474 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40475 struct nes_adapter *nesadapter = nesdev->nesadapter;
40476
40477- atomic_inc(&qps_destroyed);
40478+ atomic_inc_unchecked(&qps_destroyed);
40479
40480 /* Free the control structures */
40481
40482diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40483index 33cc589..3bd6538 100644
40484--- a/drivers/infiniband/hw/nes/nes.h
40485+++ b/drivers/infiniband/hw/nes/nes.h
40486@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40487 extern unsigned int wqm_quanta;
40488 extern struct list_head nes_adapter_list;
40489
40490-extern atomic_t cm_connects;
40491-extern atomic_t cm_accepts;
40492-extern atomic_t cm_disconnects;
40493-extern atomic_t cm_closes;
40494-extern atomic_t cm_connecteds;
40495-extern atomic_t cm_connect_reqs;
40496-extern atomic_t cm_rejects;
40497-extern atomic_t mod_qp_timouts;
40498-extern atomic_t qps_created;
40499-extern atomic_t qps_destroyed;
40500-extern atomic_t sw_qps_destroyed;
40501+extern atomic_unchecked_t cm_connects;
40502+extern atomic_unchecked_t cm_accepts;
40503+extern atomic_unchecked_t cm_disconnects;
40504+extern atomic_unchecked_t cm_closes;
40505+extern atomic_unchecked_t cm_connecteds;
40506+extern atomic_unchecked_t cm_connect_reqs;
40507+extern atomic_unchecked_t cm_rejects;
40508+extern atomic_unchecked_t mod_qp_timouts;
40509+extern atomic_unchecked_t qps_created;
40510+extern atomic_unchecked_t qps_destroyed;
40511+extern atomic_unchecked_t sw_qps_destroyed;
40512 extern u32 mh_detected;
40513 extern u32 mh_pauses_sent;
40514 extern u32 cm_packets_sent;
40515@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40516 extern u32 cm_packets_received;
40517 extern u32 cm_packets_dropped;
40518 extern u32 cm_packets_retrans;
40519-extern atomic_t cm_listens_created;
40520-extern atomic_t cm_listens_destroyed;
40521+extern atomic_unchecked_t cm_listens_created;
40522+extern atomic_unchecked_t cm_listens_destroyed;
40523 extern u32 cm_backlog_drops;
40524-extern atomic_t cm_loopbacks;
40525-extern atomic_t cm_nodes_created;
40526-extern atomic_t cm_nodes_destroyed;
40527-extern atomic_t cm_accel_dropped_pkts;
40528-extern atomic_t cm_resets_recvd;
40529-extern atomic_t pau_qps_created;
40530-extern atomic_t pau_qps_destroyed;
40531+extern atomic_unchecked_t cm_loopbacks;
40532+extern atomic_unchecked_t cm_nodes_created;
40533+extern atomic_unchecked_t cm_nodes_destroyed;
40534+extern atomic_unchecked_t cm_accel_dropped_pkts;
40535+extern atomic_unchecked_t cm_resets_recvd;
40536+extern atomic_unchecked_t pau_qps_created;
40537+extern atomic_unchecked_t pau_qps_destroyed;
40538
40539 extern u32 int_mod_timer_init;
40540 extern u32 int_mod_cq_depth_256;
40541diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40542index 24b9f1a..00fd004 100644
40543--- a/drivers/infiniband/hw/nes/nes_cm.c
40544+++ b/drivers/infiniband/hw/nes/nes_cm.c
40545@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40546 u32 cm_packets_retrans;
40547 u32 cm_packets_created;
40548 u32 cm_packets_received;
40549-atomic_t cm_listens_created;
40550-atomic_t cm_listens_destroyed;
40551+atomic_unchecked_t cm_listens_created;
40552+atomic_unchecked_t cm_listens_destroyed;
40553 u32 cm_backlog_drops;
40554-atomic_t cm_loopbacks;
40555-atomic_t cm_nodes_created;
40556-atomic_t cm_nodes_destroyed;
40557-atomic_t cm_accel_dropped_pkts;
40558-atomic_t cm_resets_recvd;
40559+atomic_unchecked_t cm_loopbacks;
40560+atomic_unchecked_t cm_nodes_created;
40561+atomic_unchecked_t cm_nodes_destroyed;
40562+atomic_unchecked_t cm_accel_dropped_pkts;
40563+atomic_unchecked_t cm_resets_recvd;
40564
40565 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40566 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40567@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40568
40569 static struct nes_cm_core *g_cm_core;
40570
40571-atomic_t cm_connects;
40572-atomic_t cm_accepts;
40573-atomic_t cm_disconnects;
40574-atomic_t cm_closes;
40575-atomic_t cm_connecteds;
40576-atomic_t cm_connect_reqs;
40577-atomic_t cm_rejects;
40578+atomic_unchecked_t cm_connects;
40579+atomic_unchecked_t cm_accepts;
40580+atomic_unchecked_t cm_disconnects;
40581+atomic_unchecked_t cm_closes;
40582+atomic_unchecked_t cm_connecteds;
40583+atomic_unchecked_t cm_connect_reqs;
40584+atomic_unchecked_t cm_rejects;
40585
40586 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40587 {
40588@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40589 kfree(listener);
40590 listener = NULL;
40591 ret = 0;
40592- atomic_inc(&cm_listens_destroyed);
40593+ atomic_inc_unchecked(&cm_listens_destroyed);
40594 } else {
40595 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40596 }
40597@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40598 cm_node->rem_mac);
40599
40600 add_hte_node(cm_core, cm_node);
40601- atomic_inc(&cm_nodes_created);
40602+ atomic_inc_unchecked(&cm_nodes_created);
40603
40604 return cm_node;
40605 }
40606@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40607 }
40608
40609 atomic_dec(&cm_core->node_cnt);
40610- atomic_inc(&cm_nodes_destroyed);
40611+ atomic_inc_unchecked(&cm_nodes_destroyed);
40612 nesqp = cm_node->nesqp;
40613 if (nesqp) {
40614 nesqp->cm_node = NULL;
40615@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40616
40617 static void drop_packet(struct sk_buff *skb)
40618 {
40619- atomic_inc(&cm_accel_dropped_pkts);
40620+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40621 dev_kfree_skb_any(skb);
40622 }
40623
40624@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40625 {
40626
40627 int reset = 0; /* whether to send reset in case of err.. */
40628- atomic_inc(&cm_resets_recvd);
40629+ atomic_inc_unchecked(&cm_resets_recvd);
40630 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40631 " refcnt=%d\n", cm_node, cm_node->state,
40632 atomic_read(&cm_node->ref_count));
40633@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40634 rem_ref_cm_node(cm_node->cm_core, cm_node);
40635 return NULL;
40636 }
40637- atomic_inc(&cm_loopbacks);
40638+ atomic_inc_unchecked(&cm_loopbacks);
40639 loopbackremotenode->loopbackpartner = cm_node;
40640 loopbackremotenode->tcp_cntxt.rcv_wscale =
40641 NES_CM_DEFAULT_RCV_WND_SCALE;
40642@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40643 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40644 else {
40645 rem_ref_cm_node(cm_core, cm_node);
40646- atomic_inc(&cm_accel_dropped_pkts);
40647+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40648 dev_kfree_skb_any(skb);
40649 }
40650 break;
40651@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40652
40653 if ((cm_id) && (cm_id->event_handler)) {
40654 if (issue_disconn) {
40655- atomic_inc(&cm_disconnects);
40656+ atomic_inc_unchecked(&cm_disconnects);
40657 cm_event.event = IW_CM_EVENT_DISCONNECT;
40658 cm_event.status = disconn_status;
40659 cm_event.local_addr = cm_id->local_addr;
40660@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40661 }
40662
40663 if (issue_close) {
40664- atomic_inc(&cm_closes);
40665+ atomic_inc_unchecked(&cm_closes);
40666 nes_disconnect(nesqp, 1);
40667
40668 cm_id->provider_data = nesqp;
40669@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40670
40671 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40672 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40673- atomic_inc(&cm_accepts);
40674+ atomic_inc_unchecked(&cm_accepts);
40675
40676 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40677 netdev_refcnt_read(nesvnic->netdev));
40678@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40679 struct nes_cm_core *cm_core;
40680 u8 *start_buff;
40681
40682- atomic_inc(&cm_rejects);
40683+ atomic_inc_unchecked(&cm_rejects);
40684 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40685 loopback = cm_node->loopbackpartner;
40686 cm_core = cm_node->cm_core;
40687@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40688 ntohl(cm_id->local_addr.sin_addr.s_addr),
40689 ntohs(cm_id->local_addr.sin_port));
40690
40691- atomic_inc(&cm_connects);
40692+ atomic_inc_unchecked(&cm_connects);
40693 nesqp->active_conn = 1;
40694
40695 /* cache the cm_id in the qp */
40696@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40697 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40698 return err;
40699 }
40700- atomic_inc(&cm_listens_created);
40701+ atomic_inc_unchecked(&cm_listens_created);
40702 }
40703
40704 cm_id->add_ref(cm_id);
40705@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40706
40707 if (nesqp->destroyed)
40708 return;
40709- atomic_inc(&cm_connecteds);
40710+ atomic_inc_unchecked(&cm_connecteds);
40711 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40712 " local port 0x%04X. jiffies = %lu.\n",
40713 nesqp->hwqp.qp_id,
40714@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40715
40716 cm_id->add_ref(cm_id);
40717 ret = cm_id->event_handler(cm_id, &cm_event);
40718- atomic_inc(&cm_closes);
40719+ atomic_inc_unchecked(&cm_closes);
40720 cm_event.event = IW_CM_EVENT_CLOSE;
40721 cm_event.status = 0;
40722 cm_event.provider_data = cm_id->provider_data;
40723@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40724 return;
40725 cm_id = cm_node->cm_id;
40726
40727- atomic_inc(&cm_connect_reqs);
40728+ atomic_inc_unchecked(&cm_connect_reqs);
40729 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40730 cm_node, cm_id, jiffies);
40731
40732@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40733 return;
40734 cm_id = cm_node->cm_id;
40735
40736- atomic_inc(&cm_connect_reqs);
40737+ atomic_inc_unchecked(&cm_connect_reqs);
40738 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40739 cm_node, cm_id, jiffies);
40740
40741diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40742index 4166452..fc952c3 100644
40743--- a/drivers/infiniband/hw/nes/nes_mgt.c
40744+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40745@@ -40,8 +40,8 @@
40746 #include "nes.h"
40747 #include "nes_mgt.h"
40748
40749-atomic_t pau_qps_created;
40750-atomic_t pau_qps_destroyed;
40751+atomic_unchecked_t pau_qps_created;
40752+atomic_unchecked_t pau_qps_destroyed;
40753
40754 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40755 {
40756@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40757 {
40758 struct sk_buff *skb;
40759 unsigned long flags;
40760- atomic_inc(&pau_qps_destroyed);
40761+ atomic_inc_unchecked(&pau_qps_destroyed);
40762
40763 /* Free packets that have not yet been forwarded */
40764 /* Lock is acquired by skb_dequeue when removing the skb */
40765@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40766 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40767 skb_queue_head_init(&nesqp->pau_list);
40768 spin_lock_init(&nesqp->pau_lock);
40769- atomic_inc(&pau_qps_created);
40770+ atomic_inc_unchecked(&pau_qps_created);
40771 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40772 }
40773
40774diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40775index 49eb511..a774366 100644
40776--- a/drivers/infiniband/hw/nes/nes_nic.c
40777+++ b/drivers/infiniband/hw/nes/nes_nic.c
40778@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40779 target_stat_values[++index] = mh_detected;
40780 target_stat_values[++index] = mh_pauses_sent;
40781 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40782- target_stat_values[++index] = atomic_read(&cm_connects);
40783- target_stat_values[++index] = atomic_read(&cm_accepts);
40784- target_stat_values[++index] = atomic_read(&cm_disconnects);
40785- target_stat_values[++index] = atomic_read(&cm_connecteds);
40786- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40787- target_stat_values[++index] = atomic_read(&cm_rejects);
40788- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40789- target_stat_values[++index] = atomic_read(&qps_created);
40790- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40791- target_stat_values[++index] = atomic_read(&qps_destroyed);
40792- target_stat_values[++index] = atomic_read(&cm_closes);
40793+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40794+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40795+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40796+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40797+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40798+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40799+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40800+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40801+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40802+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40803+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40804 target_stat_values[++index] = cm_packets_sent;
40805 target_stat_values[++index] = cm_packets_bounced;
40806 target_stat_values[++index] = cm_packets_created;
40807 target_stat_values[++index] = cm_packets_received;
40808 target_stat_values[++index] = cm_packets_dropped;
40809 target_stat_values[++index] = cm_packets_retrans;
40810- target_stat_values[++index] = atomic_read(&cm_listens_created);
40811- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40812+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40813+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40814 target_stat_values[++index] = cm_backlog_drops;
40815- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40816- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40817- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40818- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40819- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40820+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40821+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40822+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40823+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40824+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40825 target_stat_values[++index] = nesadapter->free_4kpbl;
40826 target_stat_values[++index] = nesadapter->free_256pbl;
40827 target_stat_values[++index] = int_mod_timer_init;
40828 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40829 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40830 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40831- target_stat_values[++index] = atomic_read(&pau_qps_created);
40832- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40833+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40834+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40835 }
40836
40837 /**
40838diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40839index 5b53ca5..443da3c 100644
40840--- a/drivers/infiniband/hw/nes/nes_verbs.c
40841+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40842@@ -46,9 +46,9 @@
40843
40844 #include <rdma/ib_umem.h>
40845
40846-atomic_t mod_qp_timouts;
40847-atomic_t qps_created;
40848-atomic_t sw_qps_destroyed;
40849+atomic_unchecked_t mod_qp_timouts;
40850+atomic_unchecked_t qps_created;
40851+atomic_unchecked_t sw_qps_destroyed;
40852
40853 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40854
40855@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40856 if (init_attr->create_flags)
40857 return ERR_PTR(-EINVAL);
40858
40859- atomic_inc(&qps_created);
40860+ atomic_inc_unchecked(&qps_created);
40861 switch (init_attr->qp_type) {
40862 case IB_QPT_RC:
40863 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40864@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40865 struct iw_cm_event cm_event;
40866 int ret = 0;
40867
40868- atomic_inc(&sw_qps_destroyed);
40869+ atomic_inc_unchecked(&sw_qps_destroyed);
40870 nesqp->destroyed = 1;
40871
40872 /* Blow away the connection if it exists. */
40873diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40874index 4a9af79..b993f75 100644
40875--- a/drivers/infiniband/hw/qib/qib.h
40876+++ b/drivers/infiniband/hw/qib/qib.h
40877@@ -52,6 +52,7 @@
40878 #include <linux/kref.h>
40879 #include <linux/sched.h>
40880 #include <linux/kthread.h>
40881+#include <linux/slab.h>
40882
40883 #include "qib_common.h"
40884 #include "qib_verbs.h"
40885diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40886index da739d9..da1c7f4 100644
40887--- a/drivers/input/gameport/gameport.c
40888+++ b/drivers/input/gameport/gameport.c
40889@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40890 */
40891 static void gameport_init_port(struct gameport *gameport)
40892 {
40893- static atomic_t gameport_no = ATOMIC_INIT(0);
40894+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40895
40896 __module_get(THIS_MODULE);
40897
40898 mutex_init(&gameport->drv_mutex);
40899 device_initialize(&gameport->dev);
40900 dev_set_name(&gameport->dev, "gameport%lu",
40901- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40902+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40903 gameport->dev.bus = &gameport_bus;
40904 gameport->dev.release = gameport_release_port;
40905 if (gameport->parent)
40906diff --git a/drivers/input/input.c b/drivers/input/input.c
40907index c044699..174d71a 100644
40908--- a/drivers/input/input.c
40909+++ b/drivers/input/input.c
40910@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
40911 */
40912 int input_register_device(struct input_dev *dev)
40913 {
40914- static atomic_t input_no = ATOMIC_INIT(0);
40915+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40916 struct input_devres *devres = NULL;
40917 struct input_handler *handler;
40918 unsigned int packet_size;
40919@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
40920 dev->setkeycode = input_default_setkeycode;
40921
40922 dev_set_name(&dev->dev, "input%ld",
40923- (unsigned long) atomic_inc_return(&input_no) - 1);
40924+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40925
40926 error = device_add(&dev->dev);
40927 if (error)
40928diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40929index 04c69af..5f92d00 100644
40930--- a/drivers/input/joystick/sidewinder.c
40931+++ b/drivers/input/joystick/sidewinder.c
40932@@ -30,6 +30,7 @@
40933 #include <linux/kernel.h>
40934 #include <linux/module.h>
40935 #include <linux/slab.h>
40936+#include <linux/sched.h>
40937 #include <linux/init.h>
40938 #include <linux/input.h>
40939 #include <linux/gameport.h>
40940diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40941index 75e3b10..fb390fd 100644
40942--- a/drivers/input/joystick/xpad.c
40943+++ b/drivers/input/joystick/xpad.c
40944@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40945
40946 static int xpad_led_probe(struct usb_xpad *xpad)
40947 {
40948- static atomic_t led_seq = ATOMIC_INIT(0);
40949+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40950 long led_no;
40951 struct xpad_led *led;
40952 struct led_classdev *led_cdev;
40953@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40954 if (!led)
40955 return -ENOMEM;
40956
40957- led_no = (long)atomic_inc_return(&led_seq) - 1;
40958+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40959
40960 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40961 led->xpad = xpad;
40962diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40963index e204f26..8459f15 100644
40964--- a/drivers/input/misc/ims-pcu.c
40965+++ b/drivers/input/misc/ims-pcu.c
40966@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40967
40968 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40969 {
40970- static atomic_t device_no = ATOMIC_INIT(0);
40971+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40972
40973 const struct ims_pcu_device_info *info;
40974 u8 device_id;
40975@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40976 }
40977
40978 /* Device appears to be operable, complete initialization */
40979- pcu->device_no = atomic_inc_return(&device_no) - 1;
40980+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40981
40982 error = ims_pcu_setup_backlight(pcu);
40983 if (error)
40984diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40985index 2f0b39d..7370f13 100644
40986--- a/drivers/input/mouse/psmouse.h
40987+++ b/drivers/input/mouse/psmouse.h
40988@@ -116,7 +116,7 @@ struct psmouse_attribute {
40989 ssize_t (*set)(struct psmouse *psmouse, void *data,
40990 const char *buf, size_t count);
40991 bool protect;
40992-};
40993+} __do_const;
40994 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40995
40996 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40997diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40998index 4c842c3..590b0bf 100644
40999--- a/drivers/input/mousedev.c
41000+++ b/drivers/input/mousedev.c
41001@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41002
41003 spin_unlock_irq(&client->packet_lock);
41004
41005- if (copy_to_user(buffer, data, count))
41006+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41007 return -EFAULT;
41008
41009 return count;
41010diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41011index 25fc597..558bf3b3 100644
41012--- a/drivers/input/serio/serio.c
41013+++ b/drivers/input/serio/serio.c
41014@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41015 */
41016 static void serio_init_port(struct serio *serio)
41017 {
41018- static atomic_t serio_no = ATOMIC_INIT(0);
41019+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41020
41021 __module_get(THIS_MODULE);
41022
41023@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41024 mutex_init(&serio->drv_mutex);
41025 device_initialize(&serio->dev);
41026 dev_set_name(&serio->dev, "serio%ld",
41027- (long)atomic_inc_return(&serio_no) - 1);
41028+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41029 serio->dev.bus = &serio_bus;
41030 serio->dev.release = serio_release_port;
41031 serio->dev.groups = serio_device_attr_groups;
41032diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41033index 59df2e7..8f1cafb 100644
41034--- a/drivers/input/serio/serio_raw.c
41035+++ b/drivers/input/serio/serio_raw.c
41036@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41037
41038 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41039 {
41040- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41041+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41042 struct serio_raw *serio_raw;
41043 int err;
41044
41045@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41046 }
41047
41048 snprintf(serio_raw->name, sizeof(serio_raw->name),
41049- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41050+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41051 kref_init(&serio_raw->kref);
41052 INIT_LIST_HEAD(&serio_raw->client_list);
41053 init_waitqueue_head(&serio_raw->wait);
41054diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41055index fbe9ca7..dbee61d 100644
41056--- a/drivers/iommu/iommu.c
41057+++ b/drivers/iommu/iommu.c
41058@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41059 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41060 {
41061 bus_register_notifier(bus, &iommu_bus_nb);
41062- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41063+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41064 }
41065
41066 /**
41067diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41068index 39f81ae..2660096 100644
41069--- a/drivers/iommu/irq_remapping.c
41070+++ b/drivers/iommu/irq_remapping.c
41071@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41072 void panic_if_irq_remap(const char *msg)
41073 {
41074 if (irq_remapping_enabled)
41075- panic(msg);
41076+ panic("%s", msg);
41077 }
41078
41079 static void ir_ack_apic_edge(struct irq_data *data)
41080@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41081
41082 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41083 {
41084- chip->irq_print_chip = ir_print_prefix;
41085- chip->irq_ack = ir_ack_apic_edge;
41086- chip->irq_eoi = ir_ack_apic_level;
41087- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41088+ pax_open_kernel();
41089+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41090+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41091+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41092+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41093+ pax_close_kernel();
41094 }
41095
41096 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41097diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41098index ee7c503..5d4ce08 100644
41099--- a/drivers/irqchip/irq-gic.c
41100+++ b/drivers/irqchip/irq-gic.c
41101@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41102 * Supported arch specific GIC irq extension.
41103 * Default make them NULL.
41104 */
41105-struct irq_chip gic_arch_extn = {
41106+irq_chip_no_const gic_arch_extn = {
41107 .irq_eoi = NULL,
41108 .irq_mask = NULL,
41109 .irq_unmask = NULL,
41110@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41111 chained_irq_exit(chip, desc);
41112 }
41113
41114-static struct irq_chip gic_chip = {
41115+static irq_chip_no_const gic_chip __read_only = {
41116 .name = "GIC",
41117 .irq_mask = gic_mask_irq,
41118 .irq_unmask = gic_unmask_irq,
41119diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41120index ac6f72b..81150f2 100644
41121--- a/drivers/isdn/capi/capi.c
41122+++ b/drivers/isdn/capi/capi.c
41123@@ -81,8 +81,8 @@ struct capiminor {
41124
41125 struct capi20_appl *ap;
41126 u32 ncci;
41127- atomic_t datahandle;
41128- atomic_t msgid;
41129+ atomic_unchecked_t datahandle;
41130+ atomic_unchecked_t msgid;
41131
41132 struct tty_port port;
41133 int ttyinstop;
41134@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41135 capimsg_setu16(s, 2, mp->ap->applid);
41136 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41137 capimsg_setu8 (s, 5, CAPI_RESP);
41138- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41139+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41140 capimsg_setu32(s, 8, mp->ncci);
41141 capimsg_setu16(s, 12, datahandle);
41142 }
41143@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41144 mp->outbytes -= len;
41145 spin_unlock_bh(&mp->outlock);
41146
41147- datahandle = atomic_inc_return(&mp->datahandle);
41148+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41149 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41150 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41151 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41152 capimsg_setu16(skb->data, 2, mp->ap->applid);
41153 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41154 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41155- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41156+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41157 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41158 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41159 capimsg_setu16(skb->data, 16, len); /* Data length */
41160diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41161index 600c79b..3752bab 100644
41162--- a/drivers/isdn/gigaset/interface.c
41163+++ b/drivers/isdn/gigaset/interface.c
41164@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41165 }
41166 tty->driver_data = cs;
41167
41168- ++cs->port.count;
41169+ atomic_inc(&cs->port.count);
41170
41171- if (cs->port.count == 1) {
41172+ if (atomic_read(&cs->port.count) == 1) {
41173 tty_port_tty_set(&cs->port, tty);
41174 cs->port.low_latency = 1;
41175 }
41176@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41177
41178 if (!cs->connected)
41179 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41180- else if (!cs->port.count)
41181+ else if (!atomic_read(&cs->port.count))
41182 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41183- else if (!--cs->port.count)
41184+ else if (!atomic_dec_return(&cs->port.count))
41185 tty_port_tty_set(&cs->port, NULL);
41186
41187 mutex_unlock(&cs->mutex);
41188diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41189index d0a41cb..f0cdb8c 100644
41190--- a/drivers/isdn/gigaset/usb-gigaset.c
41191+++ b/drivers/isdn/gigaset/usb-gigaset.c
41192@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41193 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41194 memcpy(cs->hw.usb->bchars, buf, 6);
41195 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41196- 0, 0, &buf, 6, 2000);
41197+ 0, 0, buf, 6, 2000);
41198 }
41199
41200 static void gigaset_freebcshw(struct bc_state *bcs)
41201diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41202index 4d9b195..455075c 100644
41203--- a/drivers/isdn/hardware/avm/b1.c
41204+++ b/drivers/isdn/hardware/avm/b1.c
41205@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41206 }
41207 if (left) {
41208 if (t4file->user) {
41209- if (copy_from_user(buf, dp, left))
41210+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41211 return -EFAULT;
41212 } else {
41213 memcpy(buf, dp, left);
41214@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41215 }
41216 if (left) {
41217 if (config->user) {
41218- if (copy_from_user(buf, dp, left))
41219+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41220 return -EFAULT;
41221 } else {
41222 memcpy(buf, dp, left);
41223diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41224index 1063bab..36817e0 100644
41225--- a/drivers/isdn/hisax/amd7930_fn.c
41226+++ b/drivers/isdn/hisax/amd7930_fn.c
41227@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41228
41229 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41230 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41231- debugl1(cs, cs->dlog);
41232+ debugl1(cs, "%s", cs->dlog);
41233 }
41234 /* moves received data in sk-buffer */
41235 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41236@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41237
41238 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41239 QuickHex(t, deb_ptr, count);
41240- debugl1(cs, cs->dlog);
41241+ debugl1(cs, "%s", cs->dlog);
41242 }
41243 /* AMD interrupts on */
41244 AmdIrqOn(cs);
41245diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41246index ee9b9a0..d1427bd 100644
41247--- a/drivers/isdn/hisax/avm_pci.c
41248+++ b/drivers/isdn/hisax/avm_pci.c
41249@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41250 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41251 bcs->channel ? 'B' : 'A', count);
41252 QuickHex(t, p, count);
41253- debugl1(cs, bcs->blog);
41254+ debugl1(cs, "%s", bcs->blog);
41255 }
41256 }
41257
41258@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41259 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41260 bcs->channel ? 'B' : 'A', count);
41261 QuickHex(t, p, count);
41262- debugl1(cs, bcs->blog);
41263+ debugl1(cs, "%s", bcs->blog);
41264 }
41265 }
41266
41267diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41268index bf04d2a..b33f53b 100644
41269--- a/drivers/isdn/hisax/config.c
41270+++ b/drivers/isdn/hisax/config.c
41271@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41272 ptr--;
41273 *ptr++ = '\n';
41274 *ptr = 0;
41275- HiSax_putstatus(cs, NULL, cs->dlog);
41276+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41277 } else
41278 HiSax_putstatus(cs, "LogEcho: ",
41279 "warning Frame too big (%d)",
41280diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41281index 8d0cf6e..4fc90de 100644
41282--- a/drivers/isdn/hisax/diva.c
41283+++ b/drivers/isdn/hisax/diva.c
41284@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41285 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41286 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41287 QuickHex(t, ptr, count);
41288- debugl1(cs, bcs->blog);
41289+ debugl1(cs, "%s", bcs->blog);
41290 }
41291 }
41292
41293@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41294 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41295 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41296 QuickHex(t, ptr, count);
41297- debugl1(cs, bcs->blog);
41298+ debugl1(cs, "%s", bcs->blog);
41299 }
41300 }
41301
41302diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41303index 1df6f9a..2be1c8a 100644
41304--- a/drivers/isdn/hisax/elsa.c
41305+++ b/drivers/isdn/hisax/elsa.c
41306@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41307 t = tmp;
41308 t += sprintf(tmp, "Arcofi data");
41309 QuickHex(t, p, cs->dc.isac.mon_rxp);
41310- debugl1(cs, tmp);
41311+ debugl1(cs, "%s", tmp);
41312 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41313 switch (cs->dc.isac.mon_rx[1]) {
41314 case 0x80:
41315diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41316index d4c98d3..3f84dd8 100644
41317--- a/drivers/isdn/hisax/elsa_ser.c
41318+++ b/drivers/isdn/hisax/elsa_ser.c
41319@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41320
41321 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41322 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41323- debugl1(cs, tmp);
41324+ debugl1(cs, "%s", tmp);
41325 }
41326 cs->hw.elsa.rcvcnt = 0;
41327 }
41328diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41329index 3ccd724..497bd02 100644
41330--- a/drivers/isdn/hisax/hfc_pci.c
41331+++ b/drivers/isdn/hisax/hfc_pci.c
41332@@ -901,7 +901,7 @@ Begin:
41333 ptr--;
41334 *ptr++ = '\n';
41335 *ptr = 0;
41336- HiSax_putstatus(cs, NULL, cs->dlog);
41337+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41338 } else
41339 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41340 }
41341diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41342index dc4574f..fa1fefd 100644
41343--- a/drivers/isdn/hisax/hfc_sx.c
41344+++ b/drivers/isdn/hisax/hfc_sx.c
41345@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41346 ptr--;
41347 *ptr++ = '\n';
41348 *ptr = 0;
41349- HiSax_putstatus(cs, NULL, cs->dlog);
41350+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41351 } else
41352 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41353 }
41354diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41355index f398d48..a8d6188 100644
41356--- a/drivers/isdn/hisax/hscx_irq.c
41357+++ b/drivers/isdn/hisax/hscx_irq.c
41358@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41359 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41360 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41361 QuickHex(t, ptr, count);
41362- debugl1(cs, bcs->blog);
41363+ debugl1(cs, "%s", bcs->blog);
41364 }
41365 }
41366
41367@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41368 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41369 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41370 QuickHex(t, ptr, count);
41371- debugl1(cs, bcs->blog);
41372+ debugl1(cs, "%s", bcs->blog);
41373 }
41374 }
41375
41376diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41377index db5321f..51dae91 100644
41378--- a/drivers/isdn/hisax/icc.c
41379+++ b/drivers/isdn/hisax/icc.c
41380@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41381
41382 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41383 QuickHex(t, ptr, count);
41384- debugl1(cs, cs->dlog);
41385+ debugl1(cs, "%s", cs->dlog);
41386 }
41387 }
41388
41389@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41390
41391 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41392 QuickHex(t, ptr, count);
41393- debugl1(cs, cs->dlog);
41394+ debugl1(cs, "%s", cs->dlog);
41395 }
41396 }
41397
41398diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41399index 74feb5c..5faa5de 100644
41400--- a/drivers/isdn/hisax/ipacx.c
41401+++ b/drivers/isdn/hisax/ipacx.c
41402@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41403
41404 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41405 QuickHex(t, ptr, count);
41406- debugl1(cs, cs->dlog);
41407+ debugl1(cs, "%s", cs->dlog);
41408 }
41409 }
41410
41411@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41412
41413 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41414 QuickHex(t, ptr, count);
41415- debugl1(cs, cs->dlog);
41416+ debugl1(cs, "%s", cs->dlog);
41417 }
41418 }
41419
41420@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41421
41422 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41423 QuickHex(t, ptr, count);
41424- debugl1(cs, bcs->blog);
41425+ debugl1(cs, "%s", bcs->blog);
41426 }
41427 }
41428
41429@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41430
41431 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41432 QuickHex(t, ptr, count);
41433- debugl1(cs, bcs->blog);
41434+ debugl1(cs, "%s", bcs->blog);
41435 }
41436 }
41437
41438diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41439index a365ccc..7fdf78f 100644
41440--- a/drivers/isdn/hisax/isac.c
41441+++ b/drivers/isdn/hisax/isac.c
41442@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41443
41444 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41445 QuickHex(t, ptr, count);
41446- debugl1(cs, cs->dlog);
41447+ debugl1(cs, "%s", cs->dlog);
41448 }
41449 }
41450
41451@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41452
41453 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41454 QuickHex(t, ptr, count);
41455- debugl1(cs, cs->dlog);
41456+ debugl1(cs, "%s", cs->dlog);
41457 }
41458 }
41459
41460diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41461index 7fdf347..f4956c7 100644
41462--- a/drivers/isdn/hisax/isar.c
41463+++ b/drivers/isdn/hisax/isar.c
41464@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41465 t = tmp;
41466 t += sprintf(t, "sendmbox cnt %d", len);
41467 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41468- debugl1(cs, tmp);
41469+ debugl1(cs, "%s", tmp);
41470 i -= 64;
41471 }
41472 }
41473@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41474 t = tmp;
41475 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41476 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41477- debugl1(cs, tmp);
41478+ debugl1(cs, "%s", tmp);
41479 i -= 64;
41480 }
41481 }
41482@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41483 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41484 ireg->iis, ireg->cmsb);
41485 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41486- debugl1(cs, debbuf);
41487+ debugl1(cs, "%s", debbuf);
41488 }
41489 break;
41490 case ISAR_IIS_INVMSG:
41491diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41492index f946c58..e2ae787 100644
41493--- a/drivers/isdn/hisax/jade.c
41494+++ b/drivers/isdn/hisax/jade.c
41495@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41496 int jade = bcs->hw.hscx.hscx;
41497
41498 if (cs->debug & L1_DEB_HSCX) {
41499- char tmp[40];
41500- sprintf(tmp, "jade %c mode %d ichan %d",
41501- 'A' + jade, mode, bc);
41502- debugl1(cs, tmp);
41503+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41504 }
41505 bcs->mode = mode;
41506 bcs->channel = bc;
41507@@ -257,23 +254,18 @@ void
41508 clear_pending_jade_ints(struct IsdnCardState *cs)
41509 {
41510 int val;
41511- char tmp[64];
41512
41513 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41514 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41515
41516 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41517- sprintf(tmp, "jade B ISTA %x", val);
41518- debugl1(cs, tmp);
41519+ debugl1(cs, "jade B ISTA %x", val);
41520 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41521- sprintf(tmp, "jade A ISTA %x", val);
41522- debugl1(cs, tmp);
41523+ debugl1(cs, "jade A ISTA %x", val);
41524 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41525- sprintf(tmp, "jade B STAR %x", val);
41526- debugl1(cs, tmp);
41527+ debugl1(cs, "jade B STAR %x", val);
41528 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41529- sprintf(tmp, "jade A STAR %x", val);
41530- debugl1(cs, tmp);
41531+ debugl1(cs, "jade A STAR %x", val);
41532 /* Unmask ints */
41533 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41534 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41535diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41536index f521fc8..b930da9 100644
41537--- a/drivers/isdn/hisax/jade_irq.c
41538+++ b/drivers/isdn/hisax/jade_irq.c
41539@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41540 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41541 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41542 QuickHex(t, ptr, count);
41543- debugl1(cs, bcs->blog);
41544+ debugl1(cs, "%s", bcs->blog);
41545 }
41546 }
41547
41548@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41549 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41550 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41551 QuickHex(t, ptr, count);
41552- debugl1(cs, bcs->blog);
41553+ debugl1(cs, "%s", bcs->blog);
41554 }
41555 }
41556
41557diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41558index 4c1bca5..875402e 100644
41559--- a/drivers/isdn/hisax/l3_1tr6.c
41560+++ b/drivers/isdn/hisax/l3_1tr6.c
41561@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41562 {
41563 dev_kfree_skb(skb);
41564 if (pc->st->l3.debug & L3_DEB_WARN)
41565- l3_debug(pc->st, msg);
41566+ l3_debug(pc->st, "%s", msg);
41567 l3_1tr6_release_req(pc, 0, NULL);
41568 }
41569
41570@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41571 {
41572 u_char *p;
41573 int bcfound = 0;
41574- char tmp[80];
41575 struct sk_buff *skb = arg;
41576
41577 /* Channel Identification */
41578@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41579 /* Signal all services, linklevel takes care of Service-Indicator */
41580 if (bcfound) {
41581 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41582- sprintf(tmp, "non-digital call: %s -> %s",
41583+ l3_debug(pc->st, "non-digital call: %s -> %s",
41584 pc->para.setup.phone,
41585 pc->para.setup.eazmsn);
41586- l3_debug(pc->st, tmp);
41587 }
41588 newl3state(pc, 6);
41589 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41590@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41591 {
41592 u_char *p;
41593 int i, tmpcharge = 0;
41594- char a_charge[8], tmp[32];
41595+ char a_charge[8];
41596 struct sk_buff *skb = arg;
41597
41598 p = skb->data;
41599@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41600 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41601 }
41602 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41603- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41604- l3_debug(pc->st, tmp);
41605+ l3_debug(pc->st, "charging info %d",
41606+ pc->para.chargeinfo);
41607 }
41608 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41609 l3_debug(pc->st, "charging info not found");
41610@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41611 struct sk_buff *skb = arg;
41612 u_char *p;
41613 int i, tmpcharge = 0;
41614- char a_charge[8], tmp[32];
41615+ char a_charge[8];
41616
41617 StopAllL3Timer(pc);
41618 p = skb->data;
41619@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41620 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41621 }
41622 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41623- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41624- l3_debug(pc->st, tmp);
41625+ l3_debug(pc->st, "charging info %d",
41626+ pc->para.chargeinfo);
41627 }
41628 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41629 l3_debug(pc->st, "charging info not found");
41630@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41631 int i, mt, cr;
41632 struct l3_process *proc;
41633 struct sk_buff *skb = arg;
41634- char tmp[80];
41635
41636 switch (pr) {
41637 case (DL_DATA | INDICATION):
41638@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41639 }
41640 if (skb->len < 4) {
41641 if (st->l3.debug & L3_DEB_PROTERR) {
41642- sprintf(tmp, "up1tr6 len only %d", skb->len);
41643- l3_debug(st, tmp);
41644+ l3_debug(st, "up1tr6 len only %d", skb->len);
41645 }
41646 dev_kfree_skb(skb);
41647 return;
41648 }
41649 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41650 if (st->l3.debug & L3_DEB_PROTERR) {
41651- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41652+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41653 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41654 skb->data[0], skb->len);
41655- l3_debug(st, tmp);
41656 }
41657 dev_kfree_skb(skb);
41658 return;
41659 }
41660 if (skb->data[1] != 1) {
41661 if (st->l3.debug & L3_DEB_PROTERR) {
41662- sprintf(tmp, "up1tr6 CR len not 1");
41663- l3_debug(st, tmp);
41664+ l3_debug(st, "up1tr6 CR len not 1");
41665 }
41666 dev_kfree_skb(skb);
41667 return;
41668@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41669 if (skb->data[0] == PROTO_DIS_N0) {
41670 dev_kfree_skb(skb);
41671 if (st->l3.debug & L3_DEB_STATE) {
41672- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41673+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41674 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41675- l3_debug(st, tmp);
41676 }
41677 } else if (skb->data[0] == PROTO_DIS_N1) {
41678 if (!(proc = getl3proc(st, cr))) {
41679@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41680 if (cr < 128) {
41681 if (!(proc = new_l3_process(st, cr))) {
41682 if (st->l3.debug & L3_DEB_PROTERR) {
41683- sprintf(tmp, "up1tr6 no roc mem");
41684- l3_debug(st, tmp);
41685+ l3_debug(st, "up1tr6 no roc mem");
41686 }
41687 dev_kfree_skb(skb);
41688 return;
41689@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41690 } else {
41691 if (!(proc = new_l3_process(st, cr))) {
41692 if (st->l3.debug & L3_DEB_PROTERR) {
41693- sprintf(tmp, "up1tr6 no roc mem");
41694- l3_debug(st, tmp);
41695+ l3_debug(st, "up1tr6 no roc mem");
41696 }
41697 dev_kfree_skb(skb);
41698 return;
41699@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41700 if (i == ARRAY_SIZE(datastln1)) {
41701 dev_kfree_skb(skb);
41702 if (st->l3.debug & L3_DEB_STATE) {
41703- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41704+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41705 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41706 proc->state, mt);
41707- l3_debug(st, tmp);
41708 }
41709 return;
41710 } else {
41711 if (st->l3.debug & L3_DEB_STATE) {
41712- sprintf(tmp, "up1tr6%sstate %d mt %x",
41713+ l3_debug(st, "up1tr6%sstate %d mt %x",
41714 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41715 proc->state, mt);
41716- l3_debug(st, tmp);
41717 }
41718 datastln1[i].rout(proc, pr, skb);
41719 }
41720@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41721 int i, cr;
41722 struct l3_process *proc;
41723 struct Channel *chan;
41724- char tmp[80];
41725
41726 if ((DL_ESTABLISH | REQUEST) == pr) {
41727 l3_msg(st, pr, NULL);
41728@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41729 break;
41730 if (i == ARRAY_SIZE(downstl)) {
41731 if (st->l3.debug & L3_DEB_STATE) {
41732- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41733+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41734 proc->state, pr);
41735- l3_debug(st, tmp);
41736 }
41737 } else {
41738 if (st->l3.debug & L3_DEB_STATE) {
41739- sprintf(tmp, "down1tr6 state %d prim %d",
41740+ l3_debug(st, "down1tr6 state %d prim %d",
41741 proc->state, pr);
41742- l3_debug(st, tmp);
41743 }
41744 downstl[i].rout(proc, pr, arg);
41745 }
41746diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41747index b646eed..233e432 100644
41748--- a/drivers/isdn/hisax/netjet.c
41749+++ b/drivers/isdn/hisax/netjet.c
41750@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41751 else
41752 j = i;
41753 QuickHex(t, p, j);
41754- debugl1(cs, tmp);
41755+ debugl1(cs, "%s", tmp);
41756 p += j;
41757 i -= j;
41758 t = tmp;
41759diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41760index 041bf52..af1b020 100644
41761--- a/drivers/isdn/hisax/q931.c
41762+++ b/drivers/isdn/hisax/q931.c
41763@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41764 dp--;
41765 *dp++ = '\n';
41766 *dp = 0;
41767- HiSax_putstatus(cs, NULL, cs->dlog);
41768+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41769 } else
41770 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41771 }
41772@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41773 }
41774 if (finish) {
41775 *dp = 0;
41776- HiSax_putstatus(cs, NULL, cs->dlog);
41777+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41778 return;
41779 }
41780 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41781@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41782 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41783 }
41784 *dp = 0;
41785- HiSax_putstatus(cs, NULL, cs->dlog);
41786+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41787 }
41788diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41789index d8cac69..a858955 100644
41790--- a/drivers/isdn/hisax/w6692.c
41791+++ b/drivers/isdn/hisax/w6692.c
41792@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41793
41794 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41795 QuickHex(t, ptr, count);
41796- debugl1(cs, cs->dlog);
41797+ debugl1(cs, "%s", cs->dlog);
41798 }
41799 }
41800
41801@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41802
41803 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41804 QuickHex(t, ptr, count);
41805- debugl1(cs, cs->dlog);
41806+ debugl1(cs, "%s", cs->dlog);
41807 }
41808 }
41809
41810@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41811 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41812 bcs->channel + '1', count);
41813 QuickHex(t, ptr, count);
41814- debugl1(cs, bcs->blog);
41815+ debugl1(cs, "%s", bcs->blog);
41816 }
41817 }
41818
41819@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
41820 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
41821 bcs->channel + '1', count);
41822 QuickHex(t, ptr, count);
41823- debugl1(cs, bcs->blog);
41824+ debugl1(cs, "%s", bcs->blog);
41825 }
41826 }
41827
41828diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41829index 9bb12ba..d4262f7 100644
41830--- a/drivers/isdn/i4l/isdn_common.c
41831+++ b/drivers/isdn/i4l/isdn_common.c
41832@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41833 } else
41834 return -EINVAL;
41835 case IIOCDBGVAR:
41836+ if (!capable(CAP_SYS_RAWIO))
41837+ return -EPERM;
41838 if (arg) {
41839 if (copy_to_user(argp, &dev, sizeof(ulong)))
41840 return -EFAULT;
41841diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41842index 3c5f249..5fac4d0 100644
41843--- a/drivers/isdn/i4l/isdn_tty.c
41844+++ b/drivers/isdn/i4l/isdn_tty.c
41845@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41846
41847 #ifdef ISDN_DEBUG_MODEM_OPEN
41848 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41849- port->count);
41850+ atomic_read(&port->count));
41851 #endif
41852- port->count++;
41853+ atomic_inc(&port->count);
41854 port->tty = tty;
41855 /*
41856 * Start up serial port
41857@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41858 #endif
41859 return;
41860 }
41861- if ((tty->count == 1) && (port->count != 1)) {
41862+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41863 /*
41864 * Uh, oh. tty->count is 1, which means that the tty
41865 * structure will be freed. Info->count should always
41866@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41867 * serial port won't be shutdown.
41868 */
41869 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41870- "info->count is %d\n", port->count);
41871- port->count = 1;
41872+ "info->count is %d\n", atomic_read(&port->count));
41873+ atomic_set(&port->count, 1);
41874 }
41875- if (--port->count < 0) {
41876+ if (atomic_dec_return(&port->count) < 0) {
41877 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41878- info->line, port->count);
41879- port->count = 0;
41880+ info->line, atomic_read(&port->count));
41881+ atomic_set(&port->count, 0);
41882 }
41883- if (port->count) {
41884+ if (atomic_read(&port->count)) {
41885 #ifdef ISDN_DEBUG_MODEM_OPEN
41886 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41887 #endif
41888@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41889 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41890 return;
41891 isdn_tty_shutdown(info);
41892- port->count = 0;
41893+ atomic_set(&port->count, 0);
41894 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41895 port->tty = NULL;
41896 wake_up_interruptible(&port->open_wait);
41897@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41898 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41899 modem_info *info = &dev->mdm.info[i];
41900
41901- if (info->port.count == 0)
41902+ if (atomic_read(&info->port.count) == 0)
41903 continue;
41904 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41905 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41906diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41907index e74df7c..03a03ba 100644
41908--- a/drivers/isdn/icn/icn.c
41909+++ b/drivers/isdn/icn/icn.c
41910@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41911 if (count > len)
41912 count = len;
41913 if (user) {
41914- if (copy_from_user(msg, buf, count))
41915+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41916 return -EFAULT;
41917 } else
41918 memcpy(msg, buf, count);
41919diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41920index 6a8405d..0bd1c7e 100644
41921--- a/drivers/leds/leds-clevo-mail.c
41922+++ b/drivers/leds/leds-clevo-mail.c
41923@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41924 * detected as working, but in reality it is not) as low as
41925 * possible.
41926 */
41927-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
41928+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
41929 {
41930 .callback = clevo_mail_led_dmi_callback,
41931 .ident = "Clevo D410J",
41932diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41933index 64e204e..c6bf189 100644
41934--- a/drivers/leds/leds-ss4200.c
41935+++ b/drivers/leds/leds-ss4200.c
41936@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41937 * detected as working, but in reality it is not) as low as
41938 * possible.
41939 */
41940-static struct dmi_system_id __initdata nas_led_whitelist[] = {
41941+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
41942 {
41943 .callback = ss4200_led_dmi_callback,
41944 .ident = "Intel SS4200-E",
41945diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41946index 0bf1e4e..b4bf44e 100644
41947--- a/drivers/lguest/core.c
41948+++ b/drivers/lguest/core.c
41949@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41950 * The end address needs +1 because __get_vm_area allocates an
41951 * extra guard page, so we need space for that.
41952 */
41953+
41954+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41955+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41956+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41957+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41958+#else
41959 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41960 VM_ALLOC, switcher_addr, switcher_addr
41961 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41962+#endif
41963+
41964 if (!switcher_vma) {
41965 err = -ENOMEM;
41966 printk("lguest: could not map switcher pages high\n");
41967@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41968 * Now the Switcher is mapped at the right address, we can't fail!
41969 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41970 */
41971- memcpy(switcher_vma->addr, start_switcher_text,
41972+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41973 end_switcher_text - start_switcher_text);
41974
41975 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41976diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41977index a35d8d1..59fb772 100644
41978--- a/drivers/lguest/page_tables.c
41979+++ b/drivers/lguest/page_tables.c
41980@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41981 /*:*/
41982
41983 #ifdef CONFIG_X86_PAE
41984-static void release_pmd(pmd_t *spmd)
41985+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41986 {
41987 /* If the entry's not present, there's nothing to release. */
41988 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41989diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41990index 5169239..47cb4db 100644
41991--- a/drivers/lguest/x86/core.c
41992+++ b/drivers/lguest/x86/core.c
41993@@ -59,7 +59,7 @@ static struct {
41994 /* Offset from where switcher.S was compiled to where we've copied it */
41995 static unsigned long switcher_offset(void)
41996 {
41997- return switcher_addr - (unsigned long)start_switcher_text;
41998+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41999 }
42000
42001 /* This cpu's struct lguest_pages (after the Switcher text page) */
42002@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42003 * These copies are pretty cheap, so we do them unconditionally: */
42004 /* Save the current Host top-level page directory.
42005 */
42006+
42007+#ifdef CONFIG_PAX_PER_CPU_PGD
42008+ pages->state.host_cr3 = read_cr3();
42009+#else
42010 pages->state.host_cr3 = __pa(current->mm->pgd);
42011+#endif
42012+
42013 /*
42014 * Set up the Guest's page tables to see this CPU's pages (and no
42015 * other CPU's pages).
42016@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42017 * compiled-in switcher code and the high-mapped copy we just made.
42018 */
42019 for (i = 0; i < IDT_ENTRIES; i++)
42020- default_idt_entries[i] += switcher_offset();
42021+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42022
42023 /*
42024 * Set up the Switcher's per-cpu areas.
42025@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42026 * it will be undisturbed when we switch. To change %cs and jump we
42027 * need this structure to feed to Intel's "lcall" instruction.
42028 */
42029- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42030+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42031 lguest_entry.segment = LGUEST_CS;
42032
42033 /*
42034diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42035index 40634b0..4f5855e 100644
42036--- a/drivers/lguest/x86/switcher_32.S
42037+++ b/drivers/lguest/x86/switcher_32.S
42038@@ -87,6 +87,7 @@
42039 #include <asm/page.h>
42040 #include <asm/segment.h>
42041 #include <asm/lguest.h>
42042+#include <asm/processor-flags.h>
42043
42044 // We mark the start of the code to copy
42045 // It's placed in .text tho it's never run here
42046@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42047 // Changes type when we load it: damn Intel!
42048 // For after we switch over our page tables
42049 // That entry will be read-only: we'd crash.
42050+
42051+#ifdef CONFIG_PAX_KERNEXEC
42052+ mov %cr0, %edx
42053+ xor $X86_CR0_WP, %edx
42054+ mov %edx, %cr0
42055+#endif
42056+
42057 movl $(GDT_ENTRY_TSS*8), %edx
42058 ltr %dx
42059
42060@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42061 // Let's clear it again for our return.
42062 // The GDT descriptor of the Host
42063 // Points to the table after two "size" bytes
42064- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42065+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42066 // Clear "used" from type field (byte 5, bit 2)
42067- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42068+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42069+
42070+#ifdef CONFIG_PAX_KERNEXEC
42071+ mov %cr0, %eax
42072+ xor $X86_CR0_WP, %eax
42073+ mov %eax, %cr0
42074+#endif
42075
42076 // Once our page table's switched, the Guest is live!
42077 // The Host fades as we run this final step.
42078@@ -295,13 +309,12 @@ deliver_to_host:
42079 // I consulted gcc, and it gave
42080 // These instructions, which I gladly credit:
42081 leal (%edx,%ebx,8), %eax
42082- movzwl (%eax),%edx
42083- movl 4(%eax), %eax
42084- xorw %ax, %ax
42085- orl %eax, %edx
42086+ movl 4(%eax), %edx
42087+ movw (%eax), %dx
42088 // Now the address of the handler's in %edx
42089 // We call it now: its "iret" drops us home.
42090- jmp *%edx
42091+ ljmp $__KERNEL_CS, $1f
42092+1: jmp *%edx
42093
42094 // Every interrupt can come to us here
42095 // But we must truly tell each apart.
42096diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42097index 0003992..854bbce 100644
42098--- a/drivers/md/bcache/closure.h
42099+++ b/drivers/md/bcache/closure.h
42100@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42101 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42102 struct workqueue_struct *wq)
42103 {
42104- BUG_ON(object_is_on_stack(cl));
42105+ BUG_ON(object_starts_on_stack(cl));
42106 closure_set_ip(cl);
42107 cl->fn = fn;
42108 cl->wq = wq;
42109diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42110index 547c4c5..5be1de4 100644
42111--- a/drivers/md/bcache/super.c
42112+++ b/drivers/md/bcache/super.c
42113@@ -1644,7 +1644,7 @@ err_unlock_gc:
42114 err:
42115 closure_sync(&op.cl);
42116 /* XXX: test this, it's broken */
42117- bch_cache_set_error(c, err);
42118+ bch_cache_set_error(c, "%s", err);
42119 }
42120
42121 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42122diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42123index a7fd821..9dcf6c3 100644
42124--- a/drivers/md/bitmap.c
42125+++ b/drivers/md/bitmap.c
42126@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42127 chunk_kb ? "KB" : "B");
42128 if (bitmap->storage.file) {
42129 seq_printf(seq, ", file: ");
42130- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42131+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42132 }
42133
42134 seq_printf(seq, "\n");
42135diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42136index f1b7586..a49c4bd 100644
42137--- a/drivers/md/dm-ioctl.c
42138+++ b/drivers/md/dm-ioctl.c
42139@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42140 cmd == DM_LIST_VERSIONS_CMD)
42141 return 0;
42142
42143- if ((cmd == DM_DEV_CREATE_CMD)) {
42144+ if (cmd == DM_DEV_CREATE_CMD) {
42145 if (!*param->name) {
42146 DMWARN("name not supplied when creating device");
42147 return -EINVAL;
42148diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42149index 699b5be..eac0a15 100644
42150--- a/drivers/md/dm-raid1.c
42151+++ b/drivers/md/dm-raid1.c
42152@@ -40,7 +40,7 @@ enum dm_raid1_error {
42153
42154 struct mirror {
42155 struct mirror_set *ms;
42156- atomic_t error_count;
42157+ atomic_unchecked_t error_count;
42158 unsigned long error_type;
42159 struct dm_dev *dev;
42160 sector_t offset;
42161@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42162 struct mirror *m;
42163
42164 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42165- if (!atomic_read(&m->error_count))
42166+ if (!atomic_read_unchecked(&m->error_count))
42167 return m;
42168
42169 return NULL;
42170@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42171 * simple way to tell if a device has encountered
42172 * errors.
42173 */
42174- atomic_inc(&m->error_count);
42175+ atomic_inc_unchecked(&m->error_count);
42176
42177 if (test_and_set_bit(error_type, &m->error_type))
42178 return;
42179@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42180 struct mirror *m = get_default_mirror(ms);
42181
42182 do {
42183- if (likely(!atomic_read(&m->error_count)))
42184+ if (likely(!atomic_read_unchecked(&m->error_count)))
42185 return m;
42186
42187 if (m-- == ms->mirror)
42188@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42189 {
42190 struct mirror *default_mirror = get_default_mirror(m->ms);
42191
42192- return !atomic_read(&default_mirror->error_count);
42193+ return !atomic_read_unchecked(&default_mirror->error_count);
42194 }
42195
42196 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42197@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42198 */
42199 if (likely(region_in_sync(ms, region, 1)))
42200 m = choose_mirror(ms, bio->bi_sector);
42201- else if (m && atomic_read(&m->error_count))
42202+ else if (m && atomic_read_unchecked(&m->error_count))
42203 m = NULL;
42204
42205 if (likely(m))
42206@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42207 }
42208
42209 ms->mirror[mirror].ms = ms;
42210- atomic_set(&(ms->mirror[mirror].error_count), 0);
42211+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42212 ms->mirror[mirror].error_type = 0;
42213 ms->mirror[mirror].offset = offset;
42214
42215@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42216 */
42217 static char device_status_char(struct mirror *m)
42218 {
42219- if (!atomic_read(&(m->error_count)))
42220+ if (!atomic_read_unchecked(&(m->error_count)))
42221 return 'A';
42222
42223 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42224diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42225index d907ca6..cfb8384 100644
42226--- a/drivers/md/dm-stripe.c
42227+++ b/drivers/md/dm-stripe.c
42228@@ -20,7 +20,7 @@ struct stripe {
42229 struct dm_dev *dev;
42230 sector_t physical_start;
42231
42232- atomic_t error_count;
42233+ atomic_unchecked_t error_count;
42234 };
42235
42236 struct stripe_c {
42237@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42238 kfree(sc);
42239 return r;
42240 }
42241- atomic_set(&(sc->stripe[i].error_count), 0);
42242+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42243 }
42244
42245 ti->private = sc;
42246@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42247 DMEMIT("%d ", sc->stripes);
42248 for (i = 0; i < sc->stripes; i++) {
42249 DMEMIT("%s ", sc->stripe[i].dev->name);
42250- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42251+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42252 'D' : 'A';
42253 }
42254 buffer[i] = '\0';
42255@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42256 */
42257 for (i = 0; i < sc->stripes; i++)
42258 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42259- atomic_inc(&(sc->stripe[i].error_count));
42260- if (atomic_read(&(sc->stripe[i].error_count)) <
42261+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42262+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42263 DM_IO_ERROR_THRESHOLD)
42264 schedule_work(&sc->trigger_event);
42265 }
42266diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42267index f221812..aca962b 100644
42268--- a/drivers/md/dm-table.c
42269+++ b/drivers/md/dm-table.c
42270@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42271 if (!dev_size)
42272 return 0;
42273
42274- if ((start >= dev_size) || (start + len > dev_size)) {
42275+ if ((start >= dev_size) || (len > dev_size - start)) {
42276 DMWARN("%s: %s too small for target: "
42277 "start=%llu, len=%llu, dev_size=%llu",
42278 dm_device_name(ti->table->md), bdevname(bdev, b),
42279diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42280index 60bce43..9b997d0 100644
42281--- a/drivers/md/dm-thin-metadata.c
42282+++ b/drivers/md/dm-thin-metadata.c
42283@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42284 {
42285 pmd->info.tm = pmd->tm;
42286 pmd->info.levels = 2;
42287- pmd->info.value_type.context = pmd->data_sm;
42288+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42289 pmd->info.value_type.size = sizeof(__le64);
42290 pmd->info.value_type.inc = data_block_inc;
42291 pmd->info.value_type.dec = data_block_dec;
42292@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42293
42294 pmd->bl_info.tm = pmd->tm;
42295 pmd->bl_info.levels = 1;
42296- pmd->bl_info.value_type.context = pmd->data_sm;
42297+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42298 pmd->bl_info.value_type.size = sizeof(__le64);
42299 pmd->bl_info.value_type.inc = data_block_inc;
42300 pmd->bl_info.value_type.dec = data_block_dec;
42301diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42302index 995e1fc..2468cec 100644
42303--- a/drivers/md/dm.c
42304+++ b/drivers/md/dm.c
42305@@ -178,9 +178,9 @@ struct mapped_device {
42306 /*
42307 * Event handling.
42308 */
42309- atomic_t event_nr;
42310+ atomic_unchecked_t event_nr;
42311 wait_queue_head_t eventq;
42312- atomic_t uevent_seq;
42313+ atomic_unchecked_t uevent_seq;
42314 struct list_head uevent_list;
42315 spinlock_t uevent_lock; /* Protect access to uevent_list */
42316
42317@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42318 spin_lock_init(&md->deferred_lock);
42319 atomic_set(&md->holders, 1);
42320 atomic_set(&md->open_count, 0);
42321- atomic_set(&md->event_nr, 0);
42322- atomic_set(&md->uevent_seq, 0);
42323+ atomic_set_unchecked(&md->event_nr, 0);
42324+ atomic_set_unchecked(&md->uevent_seq, 0);
42325 INIT_LIST_HEAD(&md->uevent_list);
42326 spin_lock_init(&md->uevent_lock);
42327
42328@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42329
42330 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42331
42332- atomic_inc(&md->event_nr);
42333+ atomic_inc_unchecked(&md->event_nr);
42334 wake_up(&md->eventq);
42335 }
42336
42337@@ -2727,18 +2727,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42338
42339 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42340 {
42341- return atomic_add_return(1, &md->uevent_seq);
42342+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42343 }
42344
42345 uint32_t dm_get_event_nr(struct mapped_device *md)
42346 {
42347- return atomic_read(&md->event_nr);
42348+ return atomic_read_unchecked(&md->event_nr);
42349 }
42350
42351 int dm_wait_event(struct mapped_device *md, int event_nr)
42352 {
42353 return wait_event_interruptible(md->eventq,
42354- (event_nr != atomic_read(&md->event_nr)));
42355+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42356 }
42357
42358 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42359diff --git a/drivers/md/md.c b/drivers/md/md.c
42360index 9f13e13..411a5b8 100644
42361--- a/drivers/md/md.c
42362+++ b/drivers/md/md.c
42363@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42364 * start build, activate spare
42365 */
42366 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42367-static atomic_t md_event_count;
42368+static atomic_unchecked_t md_event_count;
42369 void md_new_event(struct mddev *mddev)
42370 {
42371- atomic_inc(&md_event_count);
42372+ atomic_inc_unchecked(&md_event_count);
42373 wake_up(&md_event_waiters);
42374 }
42375 EXPORT_SYMBOL_GPL(md_new_event);
42376@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42377 */
42378 static void md_new_event_inintr(struct mddev *mddev)
42379 {
42380- atomic_inc(&md_event_count);
42381+ atomic_inc_unchecked(&md_event_count);
42382 wake_up(&md_event_waiters);
42383 }
42384
42385@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42386 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42387 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42388 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42389- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42390+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42391
42392 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42393 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42394@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42395 else
42396 sb->resync_offset = cpu_to_le64(0);
42397
42398- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42399+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42400
42401 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42402 sb->size = cpu_to_le64(mddev->dev_sectors);
42403@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42404 static ssize_t
42405 errors_show(struct md_rdev *rdev, char *page)
42406 {
42407- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42408+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42409 }
42410
42411 static ssize_t
42412@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42413 char *e;
42414 unsigned long n = simple_strtoul(buf, &e, 10);
42415 if (*buf && (*e == 0 || *e == '\n')) {
42416- atomic_set(&rdev->corrected_errors, n);
42417+ atomic_set_unchecked(&rdev->corrected_errors, n);
42418 return len;
42419 }
42420 return -EINVAL;
42421@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42422 rdev->sb_loaded = 0;
42423 rdev->bb_page = NULL;
42424 atomic_set(&rdev->nr_pending, 0);
42425- atomic_set(&rdev->read_errors, 0);
42426- atomic_set(&rdev->corrected_errors, 0);
42427+ atomic_set_unchecked(&rdev->read_errors, 0);
42428+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42429
42430 INIT_LIST_HEAD(&rdev->same_set);
42431 init_waitqueue_head(&rdev->blocked_wait);
42432@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42433
42434 spin_unlock(&pers_lock);
42435 seq_printf(seq, "\n");
42436- seq->poll_event = atomic_read(&md_event_count);
42437+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42438 return 0;
42439 }
42440 if (v == (void*)2) {
42441@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42442 return error;
42443
42444 seq = file->private_data;
42445- seq->poll_event = atomic_read(&md_event_count);
42446+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42447 return error;
42448 }
42449
42450@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42451 /* always allow read */
42452 mask = POLLIN | POLLRDNORM;
42453
42454- if (seq->poll_event != atomic_read(&md_event_count))
42455+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42456 mask |= POLLERR | POLLPRI;
42457 return mask;
42458 }
42459@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42460 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42461 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42462 (int)part_stat_read(&disk->part0, sectors[1]) -
42463- atomic_read(&disk->sync_io);
42464+ atomic_read_unchecked(&disk->sync_io);
42465 /* sync IO will cause sync_io to increase before the disk_stats
42466 * as sync_io is counted when a request starts, and
42467 * disk_stats is counted when it completes.
42468diff --git a/drivers/md/md.h b/drivers/md/md.h
42469index 20f02c0..fd8c821 100644
42470--- a/drivers/md/md.h
42471+++ b/drivers/md/md.h
42472@@ -94,13 +94,13 @@ struct md_rdev {
42473 * only maintained for arrays that
42474 * support hot removal
42475 */
42476- atomic_t read_errors; /* number of consecutive read errors that
42477+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42478 * we have tried to ignore.
42479 */
42480 struct timespec last_read_error; /* monotonic time since our
42481 * last read error
42482 */
42483- atomic_t corrected_errors; /* number of corrected read errors,
42484+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42485 * for reporting to userspace and storing
42486 * in superblock.
42487 */
42488@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42489
42490 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42491 {
42492- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42493+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42494 }
42495
42496 struct md_personality
42497diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42498index 3e6d115..ffecdeb 100644
42499--- a/drivers/md/persistent-data/dm-space-map.h
42500+++ b/drivers/md/persistent-data/dm-space-map.h
42501@@ -71,6 +71,7 @@ struct dm_space_map {
42502 dm_sm_threshold_fn fn,
42503 void *context);
42504 };
42505+typedef struct dm_space_map __no_const dm_space_map_no_const;
42506
42507 /*----------------------------------------------------------------*/
42508
42509diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42510index d60412c..8d4c982 100644
42511--- a/drivers/md/raid1.c
42512+++ b/drivers/md/raid1.c
42513@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42514 if (r1_sync_page_io(rdev, sect, s,
42515 bio->bi_io_vec[idx].bv_page,
42516 READ) != 0)
42517- atomic_add(s, &rdev->corrected_errors);
42518+ atomic_add_unchecked(s, &rdev->corrected_errors);
42519 }
42520 sectors -= s;
42521 sect += s;
42522@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42523 test_bit(In_sync, &rdev->flags)) {
42524 if (r1_sync_page_io(rdev, sect, s,
42525 conf->tmppage, READ)) {
42526- atomic_add(s, &rdev->corrected_errors);
42527+ atomic_add_unchecked(s, &rdev->corrected_errors);
42528 printk(KERN_INFO
42529 "md/raid1:%s: read error corrected "
42530 "(%d sectors at %llu on %s)\n",
42531diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42532index df7b0a0..a257495 100644
42533--- a/drivers/md/raid10.c
42534+++ b/drivers/md/raid10.c
42535@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42536 /* The write handler will notice the lack of
42537 * R10BIO_Uptodate and record any errors etc
42538 */
42539- atomic_add(r10_bio->sectors,
42540+ atomic_add_unchecked(r10_bio->sectors,
42541 &conf->mirrors[d].rdev->corrected_errors);
42542
42543 /* for reconstruct, we always reschedule after a read.
42544@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42545 {
42546 struct timespec cur_time_mon;
42547 unsigned long hours_since_last;
42548- unsigned int read_errors = atomic_read(&rdev->read_errors);
42549+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42550
42551 ktime_get_ts(&cur_time_mon);
42552
42553@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42554 * overflowing the shift of read_errors by hours_since_last.
42555 */
42556 if (hours_since_last >= 8 * sizeof(read_errors))
42557- atomic_set(&rdev->read_errors, 0);
42558+ atomic_set_unchecked(&rdev->read_errors, 0);
42559 else
42560- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42561+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42562 }
42563
42564 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42565@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42566 return;
42567
42568 check_decay_read_errors(mddev, rdev);
42569- atomic_inc(&rdev->read_errors);
42570- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42571+ atomic_inc_unchecked(&rdev->read_errors);
42572+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42573 char b[BDEVNAME_SIZE];
42574 bdevname(rdev->bdev, b);
42575
42576@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42577 "md/raid10:%s: %s: Raid device exceeded "
42578 "read_error threshold [cur %d:max %d]\n",
42579 mdname(mddev), b,
42580- atomic_read(&rdev->read_errors), max_read_errors);
42581+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42582 printk(KERN_NOTICE
42583 "md/raid10:%s: %s: Failing raid device\n",
42584 mdname(mddev), b);
42585@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42586 sect +
42587 choose_data_offset(r10_bio, rdev)),
42588 bdevname(rdev->bdev, b));
42589- atomic_add(s, &rdev->corrected_errors);
42590+ atomic_add_unchecked(s, &rdev->corrected_errors);
42591 }
42592
42593 rdev_dec_pending(rdev, mddev);
42594diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42595index 78ea443..7d57513 100644
42596--- a/drivers/md/raid5.c
42597+++ b/drivers/md/raid5.c
42598@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42599 mdname(conf->mddev), STRIPE_SECTORS,
42600 (unsigned long long)s,
42601 bdevname(rdev->bdev, b));
42602- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42603+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42604 clear_bit(R5_ReadError, &sh->dev[i].flags);
42605 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42606 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42607 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42608
42609- if (atomic_read(&rdev->read_errors))
42610- atomic_set(&rdev->read_errors, 0);
42611+ if (atomic_read_unchecked(&rdev->read_errors))
42612+ atomic_set_unchecked(&rdev->read_errors, 0);
42613 } else {
42614 const char *bdn = bdevname(rdev->bdev, b);
42615 int retry = 0;
42616 int set_bad = 0;
42617
42618 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42619- atomic_inc(&rdev->read_errors);
42620+ atomic_inc_unchecked(&rdev->read_errors);
42621 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42622 printk_ratelimited(
42623 KERN_WARNING
42624@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42625 mdname(conf->mddev),
42626 (unsigned long long)s,
42627 bdn);
42628- } else if (atomic_read(&rdev->read_errors)
42629+ } else if (atomic_read_unchecked(&rdev->read_errors)
42630 > conf->max_nr_stripes)
42631 printk(KERN_WARNING
42632 "md/raid:%s: Too many read errors, failing device %s.\n",
42633diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42634index 401ef64..836e563 100644
42635--- a/drivers/media/dvb-core/dvbdev.c
42636+++ b/drivers/media/dvb-core/dvbdev.c
42637@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42638 const struct dvb_device *template, void *priv, int type)
42639 {
42640 struct dvb_device *dvbdev;
42641- struct file_operations *dvbdevfops;
42642+ file_operations_no_const *dvbdevfops;
42643 struct device *clsdev;
42644 int minor;
42645 int id;
42646diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42647index 9b6c3bb..baeb5c7 100644
42648--- a/drivers/media/dvb-frontends/dib3000.h
42649+++ b/drivers/media/dvb-frontends/dib3000.h
42650@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42651 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42652 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42653 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42654-};
42655+} __no_const;
42656
42657 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42658 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42659diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42660index ecf21d9..b992428d 100644
42661--- a/drivers/media/pci/cx88/cx88-video.c
42662+++ b/drivers/media/pci/cx88/cx88-video.c
42663@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42664
42665 /* ------------------------------------------------------------------ */
42666
42667-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42668-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42669-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42670+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42671+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42672+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42673
42674 module_param_array(video_nr, int, NULL, 0444);
42675 module_param_array(vbi_nr, int, NULL, 0444);
42676diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42677index c08ae3e..eb59af1 100644
42678--- a/drivers/media/pci/ivtv/ivtv-driver.c
42679+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42680@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42681 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42682
42683 /* ivtv instance counter */
42684-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42685+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42686
42687 /* Parameter declarations */
42688 static int cardtype[IVTV_MAX_CARDS];
42689diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42690index dfd0a21..6bbb465 100644
42691--- a/drivers/media/platform/omap/omap_vout.c
42692+++ b/drivers/media/platform/omap/omap_vout.c
42693@@ -63,7 +63,6 @@ enum omap_vout_channels {
42694 OMAP_VIDEO2,
42695 };
42696
42697-static struct videobuf_queue_ops video_vbq_ops;
42698 /* Variables configurable through module params*/
42699 static u32 video1_numbuffers = 3;
42700 static u32 video2_numbuffers = 3;
42701@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42702 {
42703 struct videobuf_queue *q;
42704 struct omap_vout_device *vout = NULL;
42705+ static struct videobuf_queue_ops video_vbq_ops = {
42706+ .buf_setup = omap_vout_buffer_setup,
42707+ .buf_prepare = omap_vout_buffer_prepare,
42708+ .buf_release = omap_vout_buffer_release,
42709+ .buf_queue = omap_vout_buffer_queue,
42710+ };
42711
42712 vout = video_drvdata(file);
42713 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42714@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42715 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42716
42717 q = &vout->vbq;
42718- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42719- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42720- video_vbq_ops.buf_release = omap_vout_buffer_release;
42721- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42722 spin_lock_init(&vout->vbq_lock);
42723
42724 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42725diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42726index 04e6490..2df65bf 100644
42727--- a/drivers/media/platform/s5p-tv/mixer.h
42728+++ b/drivers/media/platform/s5p-tv/mixer.h
42729@@ -156,7 +156,7 @@ struct mxr_layer {
42730 /** layer index (unique identifier) */
42731 int idx;
42732 /** callbacks for layer methods */
42733- struct mxr_layer_ops ops;
42734+ struct mxr_layer_ops *ops;
42735 /** format array */
42736 const struct mxr_format **fmt_array;
42737 /** size of format array */
42738diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42739index b93a21f..2535195 100644
42740--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42741+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42742@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42743 {
42744 struct mxr_layer *layer;
42745 int ret;
42746- struct mxr_layer_ops ops = {
42747+ static struct mxr_layer_ops ops = {
42748 .release = mxr_graph_layer_release,
42749 .buffer_set = mxr_graph_buffer_set,
42750 .stream_set = mxr_graph_stream_set,
42751diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42752index b713403..53cb5ad 100644
42753--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42754+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42755@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42756 layer->update_buf = next;
42757 }
42758
42759- layer->ops.buffer_set(layer, layer->update_buf);
42760+ layer->ops->buffer_set(layer, layer->update_buf);
42761
42762 if (done && done != layer->shadow_buf)
42763 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42764diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42765index 641b1f0..49cff30 100644
42766--- a/drivers/media/platform/s5p-tv/mixer_video.c
42767+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42768@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42769 layer->geo.src.height = layer->geo.src.full_height;
42770
42771 mxr_geometry_dump(mdev, &layer->geo);
42772- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42773+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42774 mxr_geometry_dump(mdev, &layer->geo);
42775 }
42776
42777@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42778 layer->geo.dst.full_width = mbus_fmt.width;
42779 layer->geo.dst.full_height = mbus_fmt.height;
42780 layer->geo.dst.field = mbus_fmt.field;
42781- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42782+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42783
42784 mxr_geometry_dump(mdev, &layer->geo);
42785 }
42786@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42787 /* set source size to highest accepted value */
42788 geo->src.full_width = max(geo->dst.full_width, pix->width);
42789 geo->src.full_height = max(geo->dst.full_height, pix->height);
42790- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42791+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42792 mxr_geometry_dump(mdev, &layer->geo);
42793 /* set cropping to total visible screen */
42794 geo->src.width = pix->width;
42795@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42796 geo->src.x_offset = 0;
42797 geo->src.y_offset = 0;
42798 /* assure consistency of geometry */
42799- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42800+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42801 mxr_geometry_dump(mdev, &layer->geo);
42802 /* set full size to lowest possible value */
42803 geo->src.full_width = 0;
42804 geo->src.full_height = 0;
42805- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42806+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42807 mxr_geometry_dump(mdev, &layer->geo);
42808
42809 /* returning results */
42810@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42811 target->width = s->r.width;
42812 target->height = s->r.height;
42813
42814- layer->ops.fix_geometry(layer, stage, s->flags);
42815+ layer->ops->fix_geometry(layer, stage, s->flags);
42816
42817 /* retrieve update selection rectangle */
42818 res.left = target->x_offset;
42819@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42820 mxr_output_get(mdev);
42821
42822 mxr_layer_update_output(layer);
42823- layer->ops.format_set(layer);
42824+ layer->ops->format_set(layer);
42825 /* enabling layer in hardware */
42826 spin_lock_irqsave(&layer->enq_slock, flags);
42827 layer->state = MXR_LAYER_STREAMING;
42828 spin_unlock_irqrestore(&layer->enq_slock, flags);
42829
42830- layer->ops.stream_set(layer, MXR_ENABLE);
42831+ layer->ops->stream_set(layer, MXR_ENABLE);
42832 mxr_streamer_get(mdev);
42833
42834 return 0;
42835@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42836 spin_unlock_irqrestore(&layer->enq_slock, flags);
42837
42838 /* disabling layer in hardware */
42839- layer->ops.stream_set(layer, MXR_DISABLE);
42840+ layer->ops->stream_set(layer, MXR_DISABLE);
42841 /* remove one streamer */
42842 mxr_streamer_put(mdev);
42843 /* allow changes in output configuration */
42844@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42845
42846 void mxr_layer_release(struct mxr_layer *layer)
42847 {
42848- if (layer->ops.release)
42849- layer->ops.release(layer);
42850+ if (layer->ops->release)
42851+ layer->ops->release(layer);
42852 }
42853
42854 void mxr_base_layer_release(struct mxr_layer *layer)
42855@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42856
42857 layer->mdev = mdev;
42858 layer->idx = idx;
42859- layer->ops = *ops;
42860+ layer->ops = ops;
42861
42862 spin_lock_init(&layer->enq_slock);
42863 INIT_LIST_HEAD(&layer->enq_list);
42864diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42865index 3d13a63..da31bf1 100644
42866--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42867+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42868@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42869 {
42870 struct mxr_layer *layer;
42871 int ret;
42872- struct mxr_layer_ops ops = {
42873+ static struct mxr_layer_ops ops = {
42874 .release = mxr_vp_layer_release,
42875 .buffer_set = mxr_vp_buffer_set,
42876 .stream_set = mxr_vp_stream_set,
42877diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42878index 545c04c..a14bded 100644
42879--- a/drivers/media/radio/radio-cadet.c
42880+++ b/drivers/media/radio/radio-cadet.c
42881@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42882 unsigned char readbuf[RDS_BUFFER];
42883 int i = 0;
42884
42885+ if (count > RDS_BUFFER)
42886+ return -EFAULT;
42887 mutex_lock(&dev->lock);
42888 if (dev->rdsstat == 0)
42889 cadet_start_rds(dev);
42890@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42891 while (i < count && dev->rdsin != dev->rdsout)
42892 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42893
42894- if (i && copy_to_user(data, readbuf, i))
42895+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42896 i = -EFAULT;
42897 unlock:
42898 mutex_unlock(&dev->lock);
42899diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42900index bd4d3a7..ffc0b9d 100644
42901--- a/drivers/media/radio/radio-maxiradio.c
42902+++ b/drivers/media/radio/radio-maxiradio.c
42903@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42904 /* TEA5757 pin mappings */
42905 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42906
42907-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42908+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42909
42910 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42911 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42912diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42913index 8fa18ab..caee70f 100644
42914--- a/drivers/media/radio/radio-shark.c
42915+++ b/drivers/media/radio/radio-shark.c
42916@@ -79,7 +79,7 @@ struct shark_device {
42917 u32 last_val;
42918 };
42919
42920-static atomic_t shark_instance = ATOMIC_INIT(0);
42921+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42922
42923 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42924 {
42925diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42926index 9fb6697..f167415 100644
42927--- a/drivers/media/radio/radio-shark2.c
42928+++ b/drivers/media/radio/radio-shark2.c
42929@@ -74,7 +74,7 @@ struct shark_device {
42930 u8 *transfer_buffer;
42931 };
42932
42933-static atomic_t shark_instance = ATOMIC_INIT(0);
42934+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42935
42936 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42937 {
42938diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42939index 9c9084c..a9e8dfb 100644
42940--- a/drivers/media/radio/radio-si476x.c
42941+++ b/drivers/media/radio/radio-si476x.c
42942@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42943 struct si476x_radio *radio;
42944 struct v4l2_ctrl *ctrl;
42945
42946- static atomic_t instance = ATOMIC_INIT(0);
42947+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42948
42949 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42950 if (!radio)
42951diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42952index 1cf382a..c22998c 100644
42953--- a/drivers/media/rc/rc-main.c
42954+++ b/drivers/media/rc/rc-main.c
42955@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42956 int rc_register_device(struct rc_dev *dev)
42957 {
42958 static bool raw_init = false; /* raw decoders loaded? */
42959- static atomic_t devno = ATOMIC_INIT(0);
42960+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42961 struct rc_map *rc_map;
42962 const char *path;
42963 int rc;
42964@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
42965 */
42966 mutex_lock(&dev->lock);
42967
42968- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42969+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42970 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42971 dev_set_drvdata(&dev->dev, dev);
42972 rc = device_add(&dev->dev);
42973diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42974index 3940bb0..fb3952a 100644
42975--- a/drivers/media/usb/dvb-usb/cxusb.c
42976+++ b/drivers/media/usb/dvb-usb/cxusb.c
42977@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42978
42979 struct dib0700_adapter_state {
42980 int (*set_param_save) (struct dvb_frontend *);
42981-};
42982+} __no_const;
42983
42984 static int dib7070_set_param_override(struct dvb_frontend *fe)
42985 {
42986diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42987index 6e237b6..dc25556 100644
42988--- a/drivers/media/usb/dvb-usb/dw2102.c
42989+++ b/drivers/media/usb/dvb-usb/dw2102.c
42990@@ -118,7 +118,7 @@ struct su3000_state {
42991
42992 struct s6x0_state {
42993 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42994-};
42995+} __no_const;
42996
42997 /* debug */
42998 static int dvb_usb_dw2102_debug;
42999diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43000index 8f7a6a4..59502dd 100644
43001--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43002+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43003@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43004 __u32 reserved;
43005 };
43006
43007-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43008+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43009 enum v4l2_memory memory)
43010 {
43011 void __user *up_pln;
43012@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43013 return 0;
43014 }
43015
43016-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43017+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43018 enum v4l2_memory memory)
43019 {
43020 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43021@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43022 put_user(kp->start_block, &up->start_block) ||
43023 put_user(kp->blocks, &up->blocks) ||
43024 put_user(tmp, &up->edid) ||
43025- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43026+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43027 return -EFAULT;
43028 return 0;
43029 }
43030diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43031index 02d1b63..5fd6b16 100644
43032--- a/drivers/media/v4l2-core/v4l2-device.c
43033+++ b/drivers/media/v4l2-core/v4l2-device.c
43034@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43035 EXPORT_SYMBOL_GPL(v4l2_device_put);
43036
43037 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43038- atomic_t *instance)
43039+ atomic_unchecked_t *instance)
43040 {
43041- int num = atomic_inc_return(instance) - 1;
43042+ int num = atomic_inc_return_unchecked(instance) - 1;
43043 int len = strlen(basename);
43044
43045 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43046diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43047index 68e6b5e..d8b923e 100644
43048--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43049+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43050@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43051 struct file *file, void *fh, void *p);
43052 } u;
43053 void (*debug)(const void *arg, bool write_only);
43054-};
43055+} __do_const;
43056+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43057
43058 /* This control needs a priority check */
43059 #define INFO_FL_PRIO (1 << 0)
43060@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43061 struct video_device *vfd = video_devdata(file);
43062 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43063 bool write_only = false;
43064- struct v4l2_ioctl_info default_info;
43065+ v4l2_ioctl_info_no_const default_info;
43066 const struct v4l2_ioctl_info *info;
43067 void *fh = file->private_data;
43068 struct v4l2_fh *vfh = NULL;
43069@@ -2194,7 +2195,7 @@ done:
43070 }
43071
43072 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43073- void * __user *user_ptr, void ***kernel_ptr)
43074+ void __user **user_ptr, void ***kernel_ptr)
43075 {
43076 int ret = 0;
43077
43078@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43079 ret = -EINVAL;
43080 break;
43081 }
43082- *user_ptr = (void __user *)buf->m.planes;
43083+ *user_ptr = (void __force_user *)buf->m.planes;
43084 *kernel_ptr = (void *)&buf->m.planes;
43085 *array_size = sizeof(struct v4l2_plane) * buf->length;
43086 ret = 1;
43087@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43088 ret = -EINVAL;
43089 break;
43090 }
43091- *user_ptr = (void __user *)ctrls->controls;
43092+ *user_ptr = (void __force_user *)ctrls->controls;
43093 *kernel_ptr = (void *)&ctrls->controls;
43094 *array_size = sizeof(struct v4l2_ext_control)
43095 * ctrls->count;
43096diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43097index 767ff4d..c69d259 100644
43098--- a/drivers/message/fusion/mptbase.c
43099+++ b/drivers/message/fusion/mptbase.c
43100@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43101 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43102 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43103
43104+#ifdef CONFIG_GRKERNSEC_HIDESYM
43105+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43106+#else
43107 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43108 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43109+#endif
43110+
43111 /*
43112 * Rounding UP to nearest 4-kB boundary here...
43113 */
43114@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43115 ioc->facts.GlobalCredits);
43116
43117 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43118+#ifdef CONFIG_GRKERNSEC_HIDESYM
43119+ NULL, NULL);
43120+#else
43121 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43122+#endif
43123 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43124 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43125 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43126diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43127index dd239bd..689c4f7 100644
43128--- a/drivers/message/fusion/mptsas.c
43129+++ b/drivers/message/fusion/mptsas.c
43130@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43131 return 0;
43132 }
43133
43134+static inline void
43135+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43136+{
43137+ if (phy_info->port_details) {
43138+ phy_info->port_details->rphy = rphy;
43139+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43140+ ioc->name, rphy));
43141+ }
43142+
43143+ if (rphy) {
43144+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43145+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43146+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43147+ ioc->name, rphy, rphy->dev.release));
43148+ }
43149+}
43150+
43151 /* no mutex */
43152 static void
43153 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43154@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43155 return NULL;
43156 }
43157
43158-static inline void
43159-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43160-{
43161- if (phy_info->port_details) {
43162- phy_info->port_details->rphy = rphy;
43163- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43164- ioc->name, rphy));
43165- }
43166-
43167- if (rphy) {
43168- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43169- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43170- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43171- ioc->name, rphy, rphy->dev.release));
43172- }
43173-}
43174-
43175 static inline struct sas_port *
43176 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43177 {
43178diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43179index 727819c..ad74694 100644
43180--- a/drivers/message/fusion/mptscsih.c
43181+++ b/drivers/message/fusion/mptscsih.c
43182@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43183
43184 h = shost_priv(SChost);
43185
43186- if (h) {
43187- if (h->info_kbuf == NULL)
43188- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43189- return h->info_kbuf;
43190- h->info_kbuf[0] = '\0';
43191+ if (!h)
43192+ return NULL;
43193
43194- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43195- h->info_kbuf[size-1] = '\0';
43196- }
43197+ if (h->info_kbuf == NULL)
43198+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43199+ return h->info_kbuf;
43200+ h->info_kbuf[0] = '\0';
43201+
43202+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43203+ h->info_kbuf[size-1] = '\0';
43204
43205 return h->info_kbuf;
43206 }
43207diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43208index b7d87cd..9890039 100644
43209--- a/drivers/message/i2o/i2o_proc.c
43210+++ b/drivers/message/i2o/i2o_proc.c
43211@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43212 "Array Controller Device"
43213 };
43214
43215-static char *chtostr(char *tmp, u8 *chars, int n)
43216-{
43217- tmp[0] = 0;
43218- return strncat(tmp, (char *)chars, n);
43219-}
43220-
43221 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43222 char *group)
43223 {
43224@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43225 } *result;
43226
43227 i2o_exec_execute_ddm_table ddm_table;
43228- char tmp[28 + 1];
43229
43230 result = kmalloc(sizeof(*result), GFP_KERNEL);
43231 if (!result)
43232@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43233
43234 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43235 seq_printf(seq, "%-#8x", ddm_table.module_id);
43236- seq_printf(seq, "%-29s",
43237- chtostr(tmp, ddm_table.module_name_version, 28));
43238+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43239 seq_printf(seq, "%9d ", ddm_table.data_size);
43240 seq_printf(seq, "%8d", ddm_table.code_size);
43241
43242@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43243
43244 i2o_driver_result_table *result;
43245 i2o_driver_store_table *dst;
43246- char tmp[28 + 1];
43247
43248 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43249 if (result == NULL)
43250@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43251
43252 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43253 seq_printf(seq, "%-#8x", dst->module_id);
43254- seq_printf(seq, "%-29s",
43255- chtostr(tmp, dst->module_name_version, 28));
43256- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43257+ seq_printf(seq, "%-.28s", dst->module_name_version);
43258+ seq_printf(seq, "%-.8s", dst->date);
43259 seq_printf(seq, "%8d ", dst->module_size);
43260 seq_printf(seq, "%8d ", dst->mpb_size);
43261 seq_printf(seq, "0x%04x", dst->module_flags);
43262@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43263 // == (allow) 512d bytes (max)
43264 static u16 *work16 = (u16 *) work32;
43265 int token;
43266- char tmp[16 + 1];
43267
43268 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43269
43270@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43271 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43272 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43273 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43274- seq_printf(seq, "Vendor info : %s\n",
43275- chtostr(tmp, (u8 *) (work32 + 2), 16));
43276- seq_printf(seq, "Product info : %s\n",
43277- chtostr(tmp, (u8 *) (work32 + 6), 16));
43278- seq_printf(seq, "Description : %s\n",
43279- chtostr(tmp, (u8 *) (work32 + 10), 16));
43280- seq_printf(seq, "Product rev. : %s\n",
43281- chtostr(tmp, (u8 *) (work32 + 14), 8));
43282+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43283+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43284+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43285+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43286
43287 seq_printf(seq, "Serial number : ");
43288 print_serial_number(seq, (u8 *) (work32 + 16),
43289@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43290 u8 pad[256]; // allow up to 256 byte (max) serial number
43291 } result;
43292
43293- char tmp[24 + 1];
43294-
43295 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43296
43297 if (token < 0) {
43298@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43299 }
43300
43301 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43302- seq_printf(seq, "Module name : %s\n",
43303- chtostr(tmp, result.module_name, 24));
43304- seq_printf(seq, "Module revision : %s\n",
43305- chtostr(tmp, result.module_rev, 8));
43306+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43307+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43308
43309 seq_printf(seq, "Serial number : ");
43310 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43311@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43312 u8 instance_number[4];
43313 } result;
43314
43315- char tmp[64 + 1];
43316-
43317 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43318
43319 if (token < 0) {
43320@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43321 return 0;
43322 }
43323
43324- seq_printf(seq, "Device name : %s\n",
43325- chtostr(tmp, result.device_name, 64));
43326- seq_printf(seq, "Service name : %s\n",
43327- chtostr(tmp, result.service_name, 64));
43328- seq_printf(seq, "Physical name : %s\n",
43329- chtostr(tmp, result.physical_location, 64));
43330- seq_printf(seq, "Instance number : %s\n",
43331- chtostr(tmp, result.instance_number, 4));
43332+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43333+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43334+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43335+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43336
43337 return 0;
43338 }
43339diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43340index a8c08f3..155fe3d 100644
43341--- a/drivers/message/i2o/iop.c
43342+++ b/drivers/message/i2o/iop.c
43343@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43344
43345 spin_lock_irqsave(&c->context_list_lock, flags);
43346
43347- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43348- atomic_inc(&c->context_list_counter);
43349+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43350+ atomic_inc_unchecked(&c->context_list_counter);
43351
43352- entry->context = atomic_read(&c->context_list_counter);
43353+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43354
43355 list_add(&entry->list, &c->context_list);
43356
43357@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43358
43359 #if BITS_PER_LONG == 64
43360 spin_lock_init(&c->context_list_lock);
43361- atomic_set(&c->context_list_counter, 0);
43362+ atomic_set_unchecked(&c->context_list_counter, 0);
43363 INIT_LIST_HEAD(&c->context_list);
43364 #endif
43365
43366diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43367index fcbb2e9..2635e11 100644
43368--- a/drivers/mfd/janz-cmodio.c
43369+++ b/drivers/mfd/janz-cmodio.c
43370@@ -13,6 +13,7 @@
43371
43372 #include <linux/kernel.h>
43373 #include <linux/module.h>
43374+#include <linux/slab.h>
43375 #include <linux/init.h>
43376 #include <linux/pci.h>
43377 #include <linux/interrupt.h>
43378diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43379index 9aa6d1e..1631bfc 100644
43380--- a/drivers/mfd/twl4030-irq.c
43381+++ b/drivers/mfd/twl4030-irq.c
43382@@ -35,6 +35,7 @@
43383 #include <linux/of.h>
43384 #include <linux/irqdomain.h>
43385 #include <linux/i2c/twl.h>
43386+#include <asm/pgtable.h>
43387
43388 #include "twl-core.h"
43389
43390@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43391 * Install an irq handler for each of the SIH modules;
43392 * clone dummy irq_chip since PIH can't *do* anything
43393 */
43394- twl4030_irq_chip = dummy_irq_chip;
43395- twl4030_irq_chip.name = "twl4030";
43396+ pax_open_kernel();
43397+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43398+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43399
43400- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43401+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43402+ pax_close_kernel();
43403
43404 for (i = irq_base; i < irq_end; i++) {
43405 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43406diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43407index 277a8db..0e0b754 100644
43408--- a/drivers/mfd/twl6030-irq.c
43409+++ b/drivers/mfd/twl6030-irq.c
43410@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43411 * install an irq handler for each of the modules;
43412 * clone dummy irq_chip since PIH can't *do* anything
43413 */
43414- twl6030_irq_chip = dummy_irq_chip;
43415- twl6030_irq_chip.name = "twl6030";
43416- twl6030_irq_chip.irq_set_type = NULL;
43417- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43418+ pax_open_kernel();
43419+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43420+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43421+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43422+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43423+ pax_close_kernel();
43424
43425 for (i = irq_base; i < irq_end; i++) {
43426 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43427diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43428index f32550a..e3e52a2 100644
43429--- a/drivers/misc/c2port/core.c
43430+++ b/drivers/misc/c2port/core.c
43431@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43432 mutex_init(&c2dev->mutex);
43433
43434 /* Create binary file */
43435- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43436+ pax_open_kernel();
43437+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43438+ pax_close_kernel();
43439 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43440 if (unlikely(ret))
43441 goto error_device_create_bin_file;
43442diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43443index 36f5d52..32311c3 100644
43444--- a/drivers/misc/kgdbts.c
43445+++ b/drivers/misc/kgdbts.c
43446@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43447 char before[BREAK_INSTR_SIZE];
43448 char after[BREAK_INSTR_SIZE];
43449
43450- probe_kernel_read(before, (char *)kgdbts_break_test,
43451+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43452 BREAK_INSTR_SIZE);
43453 init_simple_test();
43454 ts.tst = plant_and_detach_test;
43455@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43456 /* Activate test with initial breakpoint */
43457 if (!is_early)
43458 kgdb_breakpoint();
43459- probe_kernel_read(after, (char *)kgdbts_break_test,
43460+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43461 BREAK_INSTR_SIZE);
43462 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43463 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43464diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43465index 036effe..b3a6336 100644
43466--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43467+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43468@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43469 * the lid is closed. This leads to interrupts as soon as a little move
43470 * is done.
43471 */
43472- atomic_inc(&lis3->count);
43473+ atomic_inc_unchecked(&lis3->count);
43474
43475 wake_up_interruptible(&lis3->misc_wait);
43476 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43477@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43478 if (lis3->pm_dev)
43479 pm_runtime_get_sync(lis3->pm_dev);
43480
43481- atomic_set(&lis3->count, 0);
43482+ atomic_set_unchecked(&lis3->count, 0);
43483 return 0;
43484 }
43485
43486@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43487 add_wait_queue(&lis3->misc_wait, &wait);
43488 while (true) {
43489 set_current_state(TASK_INTERRUPTIBLE);
43490- data = atomic_xchg(&lis3->count, 0);
43491+ data = atomic_xchg_unchecked(&lis3->count, 0);
43492 if (data)
43493 break;
43494
43495@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43496 struct lis3lv02d, miscdev);
43497
43498 poll_wait(file, &lis3->misc_wait, wait);
43499- if (atomic_read(&lis3->count))
43500+ if (atomic_read_unchecked(&lis3->count))
43501 return POLLIN | POLLRDNORM;
43502 return 0;
43503 }
43504diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43505index c439c82..1f20f57 100644
43506--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43507+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43508@@ -297,7 +297,7 @@ struct lis3lv02d {
43509 struct input_polled_dev *idev; /* input device */
43510 struct platform_device *pdev; /* platform device */
43511 struct regulator_bulk_data regulators[2];
43512- atomic_t count; /* interrupt count after last read */
43513+ atomic_unchecked_t count; /* interrupt count after last read */
43514 union axis_conversion ac; /* hw -> logical axis */
43515 int mapped_btns[3];
43516
43517diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43518index 2f30bad..c4c13d0 100644
43519--- a/drivers/misc/sgi-gru/gruhandles.c
43520+++ b/drivers/misc/sgi-gru/gruhandles.c
43521@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43522 unsigned long nsec;
43523
43524 nsec = CLKS2NSEC(clks);
43525- atomic_long_inc(&mcs_op_statistics[op].count);
43526- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43527+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43528+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43529 if (mcs_op_statistics[op].max < nsec)
43530 mcs_op_statistics[op].max = nsec;
43531 }
43532diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43533index 4f76359..cdfcb2e 100644
43534--- a/drivers/misc/sgi-gru/gruprocfs.c
43535+++ b/drivers/misc/sgi-gru/gruprocfs.c
43536@@ -32,9 +32,9 @@
43537
43538 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43539
43540-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43541+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43542 {
43543- unsigned long val = atomic_long_read(v);
43544+ unsigned long val = atomic_long_read_unchecked(v);
43545
43546 seq_printf(s, "%16lu %s\n", val, id);
43547 }
43548@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43549
43550 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43551 for (op = 0; op < mcsop_last; op++) {
43552- count = atomic_long_read(&mcs_op_statistics[op].count);
43553- total = atomic_long_read(&mcs_op_statistics[op].total);
43554+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43555+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43556 max = mcs_op_statistics[op].max;
43557 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43558 count ? total / count : 0, max);
43559diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43560index 5c3ce24..4915ccb 100644
43561--- a/drivers/misc/sgi-gru/grutables.h
43562+++ b/drivers/misc/sgi-gru/grutables.h
43563@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43564 * GRU statistics.
43565 */
43566 struct gru_stats_s {
43567- atomic_long_t vdata_alloc;
43568- atomic_long_t vdata_free;
43569- atomic_long_t gts_alloc;
43570- atomic_long_t gts_free;
43571- atomic_long_t gms_alloc;
43572- atomic_long_t gms_free;
43573- atomic_long_t gts_double_allocate;
43574- atomic_long_t assign_context;
43575- atomic_long_t assign_context_failed;
43576- atomic_long_t free_context;
43577- atomic_long_t load_user_context;
43578- atomic_long_t load_kernel_context;
43579- atomic_long_t lock_kernel_context;
43580- atomic_long_t unlock_kernel_context;
43581- atomic_long_t steal_user_context;
43582- atomic_long_t steal_kernel_context;
43583- atomic_long_t steal_context_failed;
43584- atomic_long_t nopfn;
43585- atomic_long_t asid_new;
43586- atomic_long_t asid_next;
43587- atomic_long_t asid_wrap;
43588- atomic_long_t asid_reuse;
43589- atomic_long_t intr;
43590- atomic_long_t intr_cbr;
43591- atomic_long_t intr_tfh;
43592- atomic_long_t intr_spurious;
43593- atomic_long_t intr_mm_lock_failed;
43594- atomic_long_t call_os;
43595- atomic_long_t call_os_wait_queue;
43596- atomic_long_t user_flush_tlb;
43597- atomic_long_t user_unload_context;
43598- atomic_long_t user_exception;
43599- atomic_long_t set_context_option;
43600- atomic_long_t check_context_retarget_intr;
43601- atomic_long_t check_context_unload;
43602- atomic_long_t tlb_dropin;
43603- atomic_long_t tlb_preload_page;
43604- atomic_long_t tlb_dropin_fail_no_asid;
43605- atomic_long_t tlb_dropin_fail_upm;
43606- atomic_long_t tlb_dropin_fail_invalid;
43607- atomic_long_t tlb_dropin_fail_range_active;
43608- atomic_long_t tlb_dropin_fail_idle;
43609- atomic_long_t tlb_dropin_fail_fmm;
43610- atomic_long_t tlb_dropin_fail_no_exception;
43611- atomic_long_t tfh_stale_on_fault;
43612- atomic_long_t mmu_invalidate_range;
43613- atomic_long_t mmu_invalidate_page;
43614- atomic_long_t flush_tlb;
43615- atomic_long_t flush_tlb_gru;
43616- atomic_long_t flush_tlb_gru_tgh;
43617- atomic_long_t flush_tlb_gru_zero_asid;
43618+ atomic_long_unchecked_t vdata_alloc;
43619+ atomic_long_unchecked_t vdata_free;
43620+ atomic_long_unchecked_t gts_alloc;
43621+ atomic_long_unchecked_t gts_free;
43622+ atomic_long_unchecked_t gms_alloc;
43623+ atomic_long_unchecked_t gms_free;
43624+ atomic_long_unchecked_t gts_double_allocate;
43625+ atomic_long_unchecked_t assign_context;
43626+ atomic_long_unchecked_t assign_context_failed;
43627+ atomic_long_unchecked_t free_context;
43628+ atomic_long_unchecked_t load_user_context;
43629+ atomic_long_unchecked_t load_kernel_context;
43630+ atomic_long_unchecked_t lock_kernel_context;
43631+ atomic_long_unchecked_t unlock_kernel_context;
43632+ atomic_long_unchecked_t steal_user_context;
43633+ atomic_long_unchecked_t steal_kernel_context;
43634+ atomic_long_unchecked_t steal_context_failed;
43635+ atomic_long_unchecked_t nopfn;
43636+ atomic_long_unchecked_t asid_new;
43637+ atomic_long_unchecked_t asid_next;
43638+ atomic_long_unchecked_t asid_wrap;
43639+ atomic_long_unchecked_t asid_reuse;
43640+ atomic_long_unchecked_t intr;
43641+ atomic_long_unchecked_t intr_cbr;
43642+ atomic_long_unchecked_t intr_tfh;
43643+ atomic_long_unchecked_t intr_spurious;
43644+ atomic_long_unchecked_t intr_mm_lock_failed;
43645+ atomic_long_unchecked_t call_os;
43646+ atomic_long_unchecked_t call_os_wait_queue;
43647+ atomic_long_unchecked_t user_flush_tlb;
43648+ atomic_long_unchecked_t user_unload_context;
43649+ atomic_long_unchecked_t user_exception;
43650+ atomic_long_unchecked_t set_context_option;
43651+ atomic_long_unchecked_t check_context_retarget_intr;
43652+ atomic_long_unchecked_t check_context_unload;
43653+ atomic_long_unchecked_t tlb_dropin;
43654+ atomic_long_unchecked_t tlb_preload_page;
43655+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43656+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43657+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43658+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43659+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43660+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43661+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43662+ atomic_long_unchecked_t tfh_stale_on_fault;
43663+ atomic_long_unchecked_t mmu_invalidate_range;
43664+ atomic_long_unchecked_t mmu_invalidate_page;
43665+ atomic_long_unchecked_t flush_tlb;
43666+ atomic_long_unchecked_t flush_tlb_gru;
43667+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43668+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43669
43670- atomic_long_t copy_gpa;
43671- atomic_long_t read_gpa;
43672+ atomic_long_unchecked_t copy_gpa;
43673+ atomic_long_unchecked_t read_gpa;
43674
43675- atomic_long_t mesq_receive;
43676- atomic_long_t mesq_receive_none;
43677- atomic_long_t mesq_send;
43678- atomic_long_t mesq_send_failed;
43679- atomic_long_t mesq_noop;
43680- atomic_long_t mesq_send_unexpected_error;
43681- atomic_long_t mesq_send_lb_overflow;
43682- atomic_long_t mesq_send_qlimit_reached;
43683- atomic_long_t mesq_send_amo_nacked;
43684- atomic_long_t mesq_send_put_nacked;
43685- atomic_long_t mesq_page_overflow;
43686- atomic_long_t mesq_qf_locked;
43687- atomic_long_t mesq_qf_noop_not_full;
43688- atomic_long_t mesq_qf_switch_head_failed;
43689- atomic_long_t mesq_qf_unexpected_error;
43690- atomic_long_t mesq_noop_unexpected_error;
43691- atomic_long_t mesq_noop_lb_overflow;
43692- atomic_long_t mesq_noop_qlimit_reached;
43693- atomic_long_t mesq_noop_amo_nacked;
43694- atomic_long_t mesq_noop_put_nacked;
43695- atomic_long_t mesq_noop_page_overflow;
43696+ atomic_long_unchecked_t mesq_receive;
43697+ atomic_long_unchecked_t mesq_receive_none;
43698+ atomic_long_unchecked_t mesq_send;
43699+ atomic_long_unchecked_t mesq_send_failed;
43700+ atomic_long_unchecked_t mesq_noop;
43701+ atomic_long_unchecked_t mesq_send_unexpected_error;
43702+ atomic_long_unchecked_t mesq_send_lb_overflow;
43703+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43704+ atomic_long_unchecked_t mesq_send_amo_nacked;
43705+ atomic_long_unchecked_t mesq_send_put_nacked;
43706+ atomic_long_unchecked_t mesq_page_overflow;
43707+ atomic_long_unchecked_t mesq_qf_locked;
43708+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43709+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43710+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43711+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43712+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43713+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43714+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43715+ atomic_long_unchecked_t mesq_noop_put_nacked;
43716+ atomic_long_unchecked_t mesq_noop_page_overflow;
43717
43718 };
43719
43720@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43721 tghop_invalidate, mcsop_last};
43722
43723 struct mcs_op_statistic {
43724- atomic_long_t count;
43725- atomic_long_t total;
43726+ atomic_long_unchecked_t count;
43727+ atomic_long_unchecked_t total;
43728 unsigned long max;
43729 };
43730
43731@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43732
43733 #define STAT(id) do { \
43734 if (gru_options & OPT_STATS) \
43735- atomic_long_inc(&gru_stats.id); \
43736+ atomic_long_inc_unchecked(&gru_stats.id); \
43737 } while (0)
43738
43739 #ifdef CONFIG_SGI_GRU_DEBUG
43740diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43741index c862cd4..0d176fe 100644
43742--- a/drivers/misc/sgi-xp/xp.h
43743+++ b/drivers/misc/sgi-xp/xp.h
43744@@ -288,7 +288,7 @@ struct xpc_interface {
43745 xpc_notify_func, void *);
43746 void (*received) (short, int, void *);
43747 enum xp_retval (*partid_to_nasids) (short, void *);
43748-};
43749+} __no_const;
43750
43751 extern struct xpc_interface xpc_interface;
43752
43753diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43754index b94d5f7..7f494c5 100644
43755--- a/drivers/misc/sgi-xp/xpc.h
43756+++ b/drivers/misc/sgi-xp/xpc.h
43757@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43758 void (*received_payload) (struct xpc_channel *, void *);
43759 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43760 };
43761+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43762
43763 /* struct xpc_partition act_state values (for XPC HB) */
43764
43765@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43766 /* found in xpc_main.c */
43767 extern struct device *xpc_part;
43768 extern struct device *xpc_chan;
43769-extern struct xpc_arch_operations xpc_arch_ops;
43770+extern xpc_arch_operations_no_const xpc_arch_ops;
43771 extern int xpc_disengage_timelimit;
43772 extern int xpc_disengage_timedout;
43773 extern int xpc_activate_IRQ_rcvd;
43774diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43775index 82dc574..8539ab2 100644
43776--- a/drivers/misc/sgi-xp/xpc_main.c
43777+++ b/drivers/misc/sgi-xp/xpc_main.c
43778@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43779 .notifier_call = xpc_system_die,
43780 };
43781
43782-struct xpc_arch_operations xpc_arch_ops;
43783+xpc_arch_operations_no_const xpc_arch_ops;
43784
43785 /*
43786 * Timer function to enforce the timelimit on the partition disengage.
43787@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43788
43789 if (((die_args->trapnr == X86_TRAP_MF) ||
43790 (die_args->trapnr == X86_TRAP_XF)) &&
43791- !user_mode_vm(die_args->regs))
43792+ !user_mode(die_args->regs))
43793 xpc_die_deactivate();
43794
43795 break;
43796diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43797index 837fc73..acb5862 100644
43798--- a/drivers/mmc/core/mmc_ops.c
43799+++ b/drivers/mmc/core/mmc_ops.c
43800@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43801 void *data_buf;
43802 int is_on_stack;
43803
43804- is_on_stack = object_is_on_stack(buf);
43805+ is_on_stack = object_starts_on_stack(buf);
43806 if (is_on_stack) {
43807 /*
43808 * dma onto stack is unsafe/nonportable, but callers to this
43809diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43810index 81b2994..dce857e 100644
43811--- a/drivers/mmc/host/dw_mmc.h
43812+++ b/drivers/mmc/host/dw_mmc.h
43813@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43814 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43815 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43816 int (*parse_dt)(struct dw_mci *host);
43817-};
43818+} __do_const;
43819 #endif /* _DW_MMC_H_ */
43820diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43821index c3785ed..1984c44 100644
43822--- a/drivers/mmc/host/mmci.c
43823+++ b/drivers/mmc/host/mmci.c
43824@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43825 }
43826
43827 if (variant->busy_detect) {
43828- mmci_ops.card_busy = mmci_card_busy;
43829+ pax_open_kernel();
43830+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43831+ pax_close_kernel();
43832 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43833 }
43834
43835diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43836index 926aaf6..8e153e2 100644
43837--- a/drivers/mmc/host/sdhci-s3c.c
43838+++ b/drivers/mmc/host/sdhci-s3c.c
43839@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43840 * we can use overriding functions instead of default.
43841 */
43842 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43843- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43844- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43845- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43846+ pax_open_kernel();
43847+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43848+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43849+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43850+ pax_close_kernel();
43851 }
43852
43853 /* It supports additional host capabilities if needed */
43854diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43855index 0c8bb6b..6f35deb 100644
43856--- a/drivers/mtd/nand/denali.c
43857+++ b/drivers/mtd/nand/denali.c
43858@@ -24,6 +24,7 @@
43859 #include <linux/slab.h>
43860 #include <linux/mtd/mtd.h>
43861 #include <linux/module.h>
43862+#include <linux/slab.h>
43863
43864 #include "denali.h"
43865
43866diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43867index 51b9d6a..52af9a7 100644
43868--- a/drivers/mtd/nftlmount.c
43869+++ b/drivers/mtd/nftlmount.c
43870@@ -24,6 +24,7 @@
43871 #include <asm/errno.h>
43872 #include <linux/delay.h>
43873 #include <linux/slab.h>
43874+#include <linux/sched.h>
43875 #include <linux/mtd/mtd.h>
43876 #include <linux/mtd/nand.h>
43877 #include <linux/mtd/nftl.h>
43878diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43879index f9d5615..99dd95f 100644
43880--- a/drivers/mtd/sm_ftl.c
43881+++ b/drivers/mtd/sm_ftl.c
43882@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43883 #define SM_CIS_VENDOR_OFFSET 0x59
43884 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43885 {
43886- struct attribute_group *attr_group;
43887+ attribute_group_no_const *attr_group;
43888 struct attribute **attributes;
43889 struct sm_sysfs_attribute *vendor_attribute;
43890
43891diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43892index 5e31046..82f8ddc 100644
43893--- a/drivers/net/bonding/bond_main.c
43894+++ b/drivers/net/bonding/bond_main.c
43895@@ -4839,7 +4839,7 @@ static unsigned int bond_get_num_tx_queues(void)
43896 return tx_queues;
43897 }
43898
43899-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43900+static struct rtnl_link_ops bond_link_ops = {
43901 .kind = "bond",
43902 .priv_size = sizeof(struct bonding),
43903 .setup = bond_setup,
43904@@ -4964,8 +4964,8 @@ static void __exit bonding_exit(void)
43905
43906 bond_destroy_debugfs();
43907
43908- rtnl_link_unregister(&bond_link_ops);
43909 unregister_pernet_subsys(&bond_net_ops);
43910+ rtnl_link_unregister(&bond_link_ops);
43911
43912 #ifdef CONFIG_NET_POLL_CONTROLLER
43913 /*
43914diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43915index e1d2643..7f4133b 100644
43916--- a/drivers/net/ethernet/8390/ax88796.c
43917+++ b/drivers/net/ethernet/8390/ax88796.c
43918@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43919 if (ax->plat->reg_offsets)
43920 ei_local->reg_offset = ax->plat->reg_offsets;
43921 else {
43922+ resource_size_t _mem_size = mem_size;
43923+ do_div(_mem_size, 0x18);
43924 ei_local->reg_offset = ax->reg_offsets;
43925 for (ret = 0; ret < 0x18; ret++)
43926- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43927+ ax->reg_offsets[ret] = _mem_size * ret;
43928 }
43929
43930 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43931diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43932index c07a6d0..ca88c45 100644
43933--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43934+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43935@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43936 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43937 {
43938 /* RX_MODE controlling object */
43939- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43940+ bnx2x_init_rx_mode_obj(bp);
43941
43942 /* multicast configuration controlling object */
43943 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43944diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43945index 8f03c98..dd0ef10 100644
43946--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43947+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43948@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43949 return rc;
43950 }
43951
43952-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43953- struct bnx2x_rx_mode_obj *o)
43954+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43955 {
43956 if (CHIP_IS_E1x(bp)) {
43957- o->wait_comp = bnx2x_empty_rx_mode_wait;
43958- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43959+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43960+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43961 } else {
43962- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43963- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43964+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43965+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43966 }
43967 }
43968
43969diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43970index 798dfe9..05d0a44 100644
43971--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43972+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43973@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43974
43975 /********************* RX MODE ****************/
43976
43977-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43978- struct bnx2x_rx_mode_obj *o);
43979+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43980
43981 /**
43982 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43983diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43984index cd63d11..b67dd78 100644
43985--- a/drivers/net/ethernet/broadcom/tg3.h
43986+++ b/drivers/net/ethernet/broadcom/tg3.h
43987@@ -147,6 +147,7 @@
43988 #define CHIPREV_ID_5750_A0 0x4000
43989 #define CHIPREV_ID_5750_A1 0x4001
43990 #define CHIPREV_ID_5750_A3 0x4003
43991+#define CHIPREV_ID_5750_C1 0x4201
43992 #define CHIPREV_ID_5750_C2 0x4202
43993 #define CHIPREV_ID_5752_A0_HW 0x5000
43994 #define CHIPREV_ID_5752_A0 0x6000
43995diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43996index 8cffcdf..aadf043 100644
43997--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43998+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43999@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44000 */
44001 struct l2t_skb_cb {
44002 arp_failure_handler_func arp_failure_handler;
44003-};
44004+} __no_const;
44005
44006 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44007
44008diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44009index 9c89dc8..725ecc3 100644
44010--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
44011+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44012@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
44013 flits = skb_transport_offset(skb) / 8;
44014 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
44015 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
44016- skb->tail - skb->transport_header,
44017+ skb_tail_pointer(skb) - skb_transport_header(skb),
44018 adap->pdev);
44019 if (need_skb_unmap()) {
44020 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
44021diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44022index 4c83003..2a2a5b9 100644
44023--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44024+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44025@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44026 for (i=0; i<ETH_ALEN; i++) {
44027 tmp.addr[i] = dev->dev_addr[i];
44028 }
44029- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44030+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44031 break;
44032
44033 case DE4X5_SET_HWADDR: /* Set the hardware address */
44034@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44035 spin_lock_irqsave(&lp->lock, flags);
44036 memcpy(&statbuf, &lp->pktStats, ioc->len);
44037 spin_unlock_irqrestore(&lp->lock, flags);
44038- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44039+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44040 return -EFAULT;
44041 break;
44042 }
44043diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44044index 3d91a5e..1014702 100644
44045--- a/drivers/net/ethernet/emulex/benet/be_main.c
44046+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44047@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44048
44049 if (wrapped)
44050 newacc += 65536;
44051- ACCESS_ONCE(*acc) = newacc;
44052+ ACCESS_ONCE_RW(*acc) = newacc;
44053 }
44054
44055 void populate_erx_stats(struct be_adapter *adapter,
44056diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44057index 934e1ae..b262e6b 100644
44058--- a/drivers/net/ethernet/faraday/ftgmac100.c
44059+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44060@@ -31,6 +31,8 @@
44061 #include <linux/netdevice.h>
44062 #include <linux/phy.h>
44063 #include <linux/platform_device.h>
44064+#include <linux/interrupt.h>
44065+#include <linux/irqreturn.h>
44066 #include <net/ip.h>
44067
44068 #include "ftgmac100.h"
44069diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44070index 4658f4c..407d155 100644
44071--- a/drivers/net/ethernet/faraday/ftmac100.c
44072+++ b/drivers/net/ethernet/faraday/ftmac100.c
44073@@ -31,6 +31,8 @@
44074 #include <linux/module.h>
44075 #include <linux/netdevice.h>
44076 #include <linux/platform_device.h>
44077+#include <linux/interrupt.h>
44078+#include <linux/irqreturn.h>
44079
44080 #include "ftmac100.h"
44081
44082diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44083index 331987d..3be1135 100644
44084--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44085+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44086@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44087 }
44088
44089 /* update the base incval used to calculate frequency adjustment */
44090- ACCESS_ONCE(adapter->base_incval) = incval;
44091+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44092 smp_mb();
44093
44094 /* need lock to prevent incorrect read while modifying cyclecounter */
44095diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44096index fbe5363..266b4e3 100644
44097--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44098+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44099@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44100 struct __vxge_hw_fifo *fifo;
44101 struct vxge_hw_fifo_config *config;
44102 u32 txdl_size, txdl_per_memblock;
44103- struct vxge_hw_mempool_cbs fifo_mp_callback;
44104+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44105+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44106+ };
44107+
44108 struct __vxge_hw_virtualpath *vpath;
44109
44110 if ((vp == NULL) || (attr == NULL)) {
44111@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44112 goto exit;
44113 }
44114
44115- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44116-
44117 fifo->mempool =
44118 __vxge_hw_mempool_create(vpath->hldev,
44119 fifo->config->memblock_size,
44120diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44121index 345d987..af69721 100644
44122--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44123+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44124@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44125 op_mode = QLC_83XX_DEFAULT_OPMODE;
44126
44127 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44128- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44129+ pax_open_kernel();
44130+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44131+ pax_close_kernel();
44132 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44133 } else {
44134 return -EIO;
44135diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44136index 599d1fd..59868fe 100644
44137--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44138+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44139@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44140 case QLCNIC_NON_PRIV_FUNC:
44141 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44142 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44143- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44144+ pax_open_kernel();
44145+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44146+ pax_close_kernel();
44147 break;
44148 case QLCNIC_PRIV_FUNC:
44149 ahw->op_mode = QLCNIC_PRIV_FUNC;
44150 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44151- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44152+ pax_open_kernel();
44153+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44154+ pax_close_kernel();
44155 break;
44156 case QLCNIC_MGMT_FUNC:
44157 ahw->op_mode = QLCNIC_MGMT_FUNC;
44158 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44159- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44160+ pax_open_kernel();
44161+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44162+ pax_close_kernel();
44163 break;
44164 default:
44165 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44166diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44167index 7ba68e0..618c73d 100644
44168--- a/drivers/net/ethernet/realtek/r8169.c
44169+++ b/drivers/net/ethernet/realtek/r8169.c
44170@@ -759,22 +759,22 @@ struct rtl8169_private {
44171 struct mdio_ops {
44172 void (*write)(struct rtl8169_private *, int, int);
44173 int (*read)(struct rtl8169_private *, int);
44174- } mdio_ops;
44175+ } __no_const mdio_ops;
44176
44177 struct pll_power_ops {
44178 void (*down)(struct rtl8169_private *);
44179 void (*up)(struct rtl8169_private *);
44180- } pll_power_ops;
44181+ } __no_const pll_power_ops;
44182
44183 struct jumbo_ops {
44184 void (*enable)(struct rtl8169_private *);
44185 void (*disable)(struct rtl8169_private *);
44186- } jumbo_ops;
44187+ } __no_const jumbo_ops;
44188
44189 struct csi_ops {
44190 void (*write)(struct rtl8169_private *, int, int);
44191 u32 (*read)(struct rtl8169_private *, int);
44192- } csi_ops;
44193+ } __no_const csi_ops;
44194
44195 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44196 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44197diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44198index b495394..0748c54 100644
44199--- a/drivers/net/ethernet/sfc/ptp.c
44200+++ b/drivers/net/ethernet/sfc/ptp.c
44201@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44202 (u32)((u64)ptp->start.dma_addr >> 32));
44203
44204 /* Clear flag that signals MC ready */
44205- ACCESS_ONCE(*start) = 0;
44206+ ACCESS_ONCE_RW(*start) = 0;
44207 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44208 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44209
44210diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44211index 50617c5..b13724c 100644
44212--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44213+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44214@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44215
44216 writel(value, ioaddr + MMC_CNTRL);
44217
44218- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44219- MMC_CNTRL, value);
44220+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44221+// MMC_CNTRL, value);
44222 }
44223
44224 /* To mask all all interrupts.*/
44225diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44226index e6fe0d8..2b7d752 100644
44227--- a/drivers/net/hyperv/hyperv_net.h
44228+++ b/drivers/net/hyperv/hyperv_net.h
44229@@ -101,7 +101,7 @@ struct rndis_device {
44230
44231 enum rndis_device_state state;
44232 bool link_state;
44233- atomic_t new_req_id;
44234+ atomic_unchecked_t new_req_id;
44235
44236 spinlock_t request_lock;
44237 struct list_head req_list;
44238diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44239index 0775f0a..d4fb316 100644
44240--- a/drivers/net/hyperv/rndis_filter.c
44241+++ b/drivers/net/hyperv/rndis_filter.c
44242@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44243 * template
44244 */
44245 set = &rndis_msg->msg.set_req;
44246- set->req_id = atomic_inc_return(&dev->new_req_id);
44247+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44248
44249 /* Add to the request list */
44250 spin_lock_irqsave(&dev->request_lock, flags);
44251@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44252
44253 /* Setup the rndis set */
44254 halt = &request->request_msg.msg.halt_req;
44255- halt->req_id = atomic_inc_return(&dev->new_req_id);
44256+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44257
44258 /* Ignore return since this msg is optional. */
44259 rndis_filter_send_request(dev, request);
44260diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44261index bf0d55e..82bcfbd1 100644
44262--- a/drivers/net/ieee802154/fakehard.c
44263+++ b/drivers/net/ieee802154/fakehard.c
44264@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44265 phy->transmit_power = 0xbf;
44266
44267 dev->netdev_ops = &fake_ops;
44268- dev->ml_priv = &fake_mlme;
44269+ dev->ml_priv = (void *)&fake_mlme;
44270
44271 priv = netdev_priv(dev);
44272 priv->phy = phy;
44273diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44274index 16b43bf..ead0c35 100644
44275--- a/drivers/net/macvlan.c
44276+++ b/drivers/net/macvlan.c
44277@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44278 int macvlan_link_register(struct rtnl_link_ops *ops)
44279 {
44280 /* common fields */
44281- ops->priv_size = sizeof(struct macvlan_dev);
44282- ops->validate = macvlan_validate;
44283- ops->maxtype = IFLA_MACVLAN_MAX;
44284- ops->policy = macvlan_policy;
44285- ops->changelink = macvlan_changelink;
44286- ops->get_size = macvlan_get_size;
44287- ops->fill_info = macvlan_fill_info;
44288+ pax_open_kernel();
44289+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44290+ *(void **)&ops->validate = macvlan_validate;
44291+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44292+ *(const void **)&ops->policy = macvlan_policy;
44293+ *(void **)&ops->changelink = macvlan_changelink;
44294+ *(void **)&ops->get_size = macvlan_get_size;
44295+ *(void **)&ops->fill_info = macvlan_fill_info;
44296+ pax_close_kernel();
44297
44298 return rtnl_link_register(ops);
44299 };
44300@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44301 return NOTIFY_DONE;
44302 }
44303
44304-static struct notifier_block macvlan_notifier_block __read_mostly = {
44305+static struct notifier_block macvlan_notifier_block = {
44306 .notifier_call = macvlan_device_event,
44307 };
44308
44309diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44310index ea53abb..2e4d087 100644
44311--- a/drivers/net/macvtap.c
44312+++ b/drivers/net/macvtap.c
44313@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44314 return NOTIFY_DONE;
44315 }
44316
44317-static struct notifier_block macvtap_notifier_block __read_mostly = {
44318+static struct notifier_block macvtap_notifier_block = {
44319 .notifier_call = macvtap_device_event,
44320 };
44321
44322diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44323index daec9b0..6428fcb 100644
44324--- a/drivers/net/phy/mdio-bitbang.c
44325+++ b/drivers/net/phy/mdio-bitbang.c
44326@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44327 struct mdiobb_ctrl *ctrl = bus->priv;
44328
44329 module_put(ctrl->ops->owner);
44330+ mdiobus_unregister(bus);
44331 mdiobus_free(bus);
44332 }
44333 EXPORT_SYMBOL(free_mdio_bitbang);
44334diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44335index 72ff14b..11d442d 100644
44336--- a/drivers/net/ppp/ppp_generic.c
44337+++ b/drivers/net/ppp/ppp_generic.c
44338@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44339 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44340 struct ppp_stats stats;
44341 struct ppp_comp_stats cstats;
44342- char *vers;
44343
44344 switch (cmd) {
44345 case SIOCGPPPSTATS:
44346@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44347 break;
44348
44349 case SIOCGPPPVER:
44350- vers = PPP_VERSION;
44351- if (copy_to_user(addr, vers, strlen(vers) + 1))
44352+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44353 break;
44354 err = 0;
44355 break;
44356diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44357index 1252d9c..80e660b 100644
44358--- a/drivers/net/slip/slhc.c
44359+++ b/drivers/net/slip/slhc.c
44360@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44361 register struct tcphdr *thp;
44362 register struct iphdr *ip;
44363 register struct cstate *cs;
44364- int len, hdrlen;
44365+ long len, hdrlen;
44366 unsigned char *cp = icp;
44367
44368 /* We've got a compressed packet; read the change byte */
44369diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44370index bff7e0b..7315137 100644
44371--- a/drivers/net/team/team.c
44372+++ b/drivers/net/team/team.c
44373@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44374 return NOTIFY_DONE;
44375 }
44376
44377-static struct notifier_block team_notifier_block __read_mostly = {
44378+static struct notifier_block team_notifier_block = {
44379 .notifier_call = team_device_event,
44380 };
44381
44382diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44383index 68b9aa3..b3c20f3 100644
44384--- a/drivers/net/tun.c
44385+++ b/drivers/net/tun.c
44386@@ -1874,7 +1874,7 @@ unlock:
44387 }
44388
44389 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44390- unsigned long arg, int ifreq_len)
44391+ unsigned long arg, size_t ifreq_len)
44392 {
44393 struct tun_file *tfile = file->private_data;
44394 struct tun_struct *tun;
44395@@ -1886,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44396 int vnet_hdr_sz;
44397 int ret;
44398
44399+ if (ifreq_len > sizeof ifr)
44400+ return -EFAULT;
44401+
44402 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44403 if (copy_from_user(&ifr, argp, ifreq_len))
44404 return -EFAULT;
44405diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44406index 86292e6..8d34433 100644
44407--- a/drivers/net/usb/hso.c
44408+++ b/drivers/net/usb/hso.c
44409@@ -71,7 +71,7 @@
44410 #include <asm/byteorder.h>
44411 #include <linux/serial_core.h>
44412 #include <linux/serial.h>
44413-
44414+#include <asm/local.h>
44415
44416 #define MOD_AUTHOR "Option Wireless"
44417 #define MOD_DESCRIPTION "USB High Speed Option driver"
44418@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44419 struct urb *urb;
44420
44421 urb = serial->rx_urb[0];
44422- if (serial->port.count > 0) {
44423+ if (atomic_read(&serial->port.count) > 0) {
44424 count = put_rxbuf_data(urb, serial);
44425 if (count == -1)
44426 return;
44427@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44428 DUMP1(urb->transfer_buffer, urb->actual_length);
44429
44430 /* Anyone listening? */
44431- if (serial->port.count == 0)
44432+ if (atomic_read(&serial->port.count) == 0)
44433 return;
44434
44435 if (status == 0) {
44436@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44437 tty_port_tty_set(&serial->port, tty);
44438
44439 /* check for port already opened, if not set the termios */
44440- serial->port.count++;
44441- if (serial->port.count == 1) {
44442+ if (atomic_inc_return(&serial->port.count) == 1) {
44443 serial->rx_state = RX_IDLE;
44444 /* Force default termio settings */
44445 _hso_serial_set_termios(tty, NULL);
44446@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44447 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44448 if (result) {
44449 hso_stop_serial_device(serial->parent);
44450- serial->port.count--;
44451+ atomic_dec(&serial->port.count);
44452 kref_put(&serial->parent->ref, hso_serial_ref_free);
44453 }
44454 } else {
44455@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44456
44457 /* reset the rts and dtr */
44458 /* do the actual close */
44459- serial->port.count--;
44460+ atomic_dec(&serial->port.count);
44461
44462- if (serial->port.count <= 0) {
44463- serial->port.count = 0;
44464+ if (atomic_read(&serial->port.count) <= 0) {
44465+ atomic_set(&serial->port.count, 0);
44466 tty_port_tty_set(&serial->port, NULL);
44467 if (!usb_gone)
44468 hso_stop_serial_device(serial->parent);
44469@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44470
44471 /* the actual setup */
44472 spin_lock_irqsave(&serial->serial_lock, flags);
44473- if (serial->port.count)
44474+ if (atomic_read(&serial->port.count))
44475 _hso_serial_set_termios(tty, old);
44476 else
44477 tty->termios = *old;
44478@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44479 D1("Pending read interrupt on port %d\n", i);
44480 spin_lock(&serial->serial_lock);
44481 if (serial->rx_state == RX_IDLE &&
44482- serial->port.count > 0) {
44483+ atomic_read(&serial->port.count) > 0) {
44484 /* Setup and send a ctrl req read on
44485 * port i */
44486 if (!serial->rx_urb_filled[0]) {
44487@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44488 /* Start all serial ports */
44489 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44490 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44491- if (dev2ser(serial_table[i])->port.count) {
44492+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44493 result =
44494 hso_start_serial_device(serial_table[i], GFP_NOIO);
44495 hso_kick_transmit(dev2ser(serial_table[i]));
44496diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44497index a79e9d3..78cd4fa 100644
44498--- a/drivers/net/usb/sierra_net.c
44499+++ b/drivers/net/usb/sierra_net.c
44500@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44501 /* atomic counter partially included in MAC address to make sure 2 devices
44502 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44503 */
44504-static atomic_t iface_counter = ATOMIC_INIT(0);
44505+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44506
44507 /*
44508 * SYNC Timer Delay definition used to set the expiry time
44509@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44510 dev->net->netdev_ops = &sierra_net_device_ops;
44511
44512 /* change MAC addr to include, ifacenum, and to be unique */
44513- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44514+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44515 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44516
44517 /* we will have to manufacture ethernet headers, prepare template */
44518diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44519index 8a05d77..ba8b9c5 100644
44520--- a/drivers/net/vxlan.c
44521+++ b/drivers/net/vxlan.c
44522@@ -1870,7 +1870,7 @@ nla_put_failure:
44523 return -EMSGSIZE;
44524 }
44525
44526-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44527+static struct rtnl_link_ops vxlan_link_ops = {
44528 .kind = "vxlan",
44529 .maxtype = IFLA_VXLAN_MAX,
44530 .policy = vxlan_policy,
44531diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
44532index 3f0c4f2..bcfff0d 100644
44533--- a/drivers/net/wan/farsync.c
44534+++ b/drivers/net/wan/farsync.c
44535@@ -1972,6 +1972,7 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port,
44536 }
44537
44538 i = port->index;
44539+ memset(&sync, 0, sizeof(sync));
44540 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed);
44541 /* Lucky card and linux use same encoding here */
44542 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) ==
44543diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44544index 0b60295..b8bfa5b 100644
44545--- a/drivers/net/wimax/i2400m/rx.c
44546+++ b/drivers/net/wimax/i2400m/rx.c
44547@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44548 if (i2400m->rx_roq == NULL)
44549 goto error_roq_alloc;
44550
44551- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44552+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44553 GFP_KERNEL);
44554 if (rd == NULL) {
44555 result = -ENOMEM;
44556diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44557index 34c8a33..3261fdc 100644
44558--- a/drivers/net/wireless/at76c50x-usb.c
44559+++ b/drivers/net/wireless/at76c50x-usb.c
44560@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44561 }
44562
44563 /* Convert timeout from the DFU status to jiffies */
44564-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44565+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44566 {
44567 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44568 | (s->poll_timeout[1] << 8)
44569diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44570index 2b3426b..1f564be 100644
44571--- a/drivers/net/wireless/ath/ath10k/core.c
44572+++ b/drivers/net/wireless/ath/ath10k/core.c
44573@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44574
44575 int ath10k_core_register(struct ath10k *ar)
44576 {
44577- struct ath10k_htc_ops htc_ops;
44578+ static struct ath10k_htc_ops htc_ops = {
44579+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44580+ };
44581 struct bmi_target_info target_info;
44582 int status;
44583
44584@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44585 if (status)
44586 goto err;
44587
44588- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44589-
44590 ar->htc = ath10k_htc_create(ar, &htc_ops);
44591 if (IS_ERR(ar->htc)) {
44592 status = PTR_ERR(ar->htc);
44593diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44594index 74363c9..237b926 100644
44595--- a/drivers/net/wireless/ath/ath10k/htc.c
44596+++ b/drivers/net/wireless/ath/ath10k/htc.c
44597@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44598 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44599 struct ath10k_htc_ops *htc_ops)
44600 {
44601- struct ath10k_hif_cb htc_callbacks;
44602+ static struct ath10k_hif_cb htc_callbacks = {
44603+ .rx_completion = ath10k_htc_rx_completion_handler,
44604+ .tx_completion = ath10k_htc_tx_completion_handler,
44605+ };
44606 struct ath10k_htc_ep *ep = NULL;
44607 struct ath10k_htc *htc = NULL;
44608
44609@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44610 ath10k_htc_reset_endpoint_states(htc);
44611
44612 /* setup HIF layer callbacks */
44613- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44614- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44615 htc->ar = ar;
44616
44617 /* Get HIF default pipe for HTC message exchange */
44618diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44619index 8d78253..bebbb68 100644
44620--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44621+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44622@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44623 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44624 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44625
44626- ACCESS_ONCE(ads->ds_link) = i->link;
44627- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44628+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44629+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44630
44631 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44632 ctl6 = SM(i->keytype, AR_EncrType);
44633@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44634
44635 if ((i->is_first || i->is_last) &&
44636 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44637- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44638+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44639 | set11nTries(i->rates, 1)
44640 | set11nTries(i->rates, 2)
44641 | set11nTries(i->rates, 3)
44642 | (i->dur_update ? AR_DurUpdateEna : 0)
44643 | SM(0, AR_BurstDur);
44644
44645- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44646+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44647 | set11nRate(i->rates, 1)
44648 | set11nRate(i->rates, 2)
44649 | set11nRate(i->rates, 3);
44650 } else {
44651- ACCESS_ONCE(ads->ds_ctl2) = 0;
44652- ACCESS_ONCE(ads->ds_ctl3) = 0;
44653+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44654+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44655 }
44656
44657 if (!i->is_first) {
44658- ACCESS_ONCE(ads->ds_ctl0) = 0;
44659- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44660- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44661+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44662+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44663+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44664 return;
44665 }
44666
44667@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44668 break;
44669 }
44670
44671- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44672+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44673 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44674 | SM(i->txpower, AR_XmitPower)
44675 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44676@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44677 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44678 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44679
44680- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44681- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44682+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44683+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44684
44685 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44686 return;
44687
44688- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44689+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44690 | set11nPktDurRTSCTS(i->rates, 1);
44691
44692- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44693+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44694 | set11nPktDurRTSCTS(i->rates, 3);
44695
44696- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44697+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44698 | set11nRateFlags(i->rates, 1)
44699 | set11nRateFlags(i->rates, 2)
44700 | set11nRateFlags(i->rates, 3)
44701diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44702index 5163abd..3ada4c2 100644
44703--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44704+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44705@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44706 (i->qcu << AR_TxQcuNum_S) | desc_len;
44707
44708 checksum += val;
44709- ACCESS_ONCE(ads->info) = val;
44710+ ACCESS_ONCE_RW(ads->info) = val;
44711
44712 checksum += i->link;
44713- ACCESS_ONCE(ads->link) = i->link;
44714+ ACCESS_ONCE_RW(ads->link) = i->link;
44715
44716 checksum += i->buf_addr[0];
44717- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44718+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44719 checksum += i->buf_addr[1];
44720- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44721+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44722 checksum += i->buf_addr[2];
44723- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44724+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44725 checksum += i->buf_addr[3];
44726- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44727+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44728
44729 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44730- ACCESS_ONCE(ads->ctl3) = val;
44731+ ACCESS_ONCE_RW(ads->ctl3) = val;
44732 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44733- ACCESS_ONCE(ads->ctl5) = val;
44734+ ACCESS_ONCE_RW(ads->ctl5) = val;
44735 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44736- ACCESS_ONCE(ads->ctl7) = val;
44737+ ACCESS_ONCE_RW(ads->ctl7) = val;
44738 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44739- ACCESS_ONCE(ads->ctl9) = val;
44740+ ACCESS_ONCE_RW(ads->ctl9) = val;
44741
44742 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44743- ACCESS_ONCE(ads->ctl10) = checksum;
44744+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44745
44746 if (i->is_first || i->is_last) {
44747- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44748+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44749 | set11nTries(i->rates, 1)
44750 | set11nTries(i->rates, 2)
44751 | set11nTries(i->rates, 3)
44752 | (i->dur_update ? AR_DurUpdateEna : 0)
44753 | SM(0, AR_BurstDur);
44754
44755- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44756+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44757 | set11nRate(i->rates, 1)
44758 | set11nRate(i->rates, 2)
44759 | set11nRate(i->rates, 3);
44760 } else {
44761- ACCESS_ONCE(ads->ctl13) = 0;
44762- ACCESS_ONCE(ads->ctl14) = 0;
44763+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44764+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44765 }
44766
44767 ads->ctl20 = 0;
44768@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44769
44770 ctl17 = SM(i->keytype, AR_EncrType);
44771 if (!i->is_first) {
44772- ACCESS_ONCE(ads->ctl11) = 0;
44773- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44774- ACCESS_ONCE(ads->ctl15) = 0;
44775- ACCESS_ONCE(ads->ctl16) = 0;
44776- ACCESS_ONCE(ads->ctl17) = ctl17;
44777- ACCESS_ONCE(ads->ctl18) = 0;
44778- ACCESS_ONCE(ads->ctl19) = 0;
44779+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44780+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44781+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44782+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44783+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44784+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44785+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44786 return;
44787 }
44788
44789- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44790+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44791 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44792 | SM(i->txpower, AR_XmitPower)
44793 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44794@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44795 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44796 ctl12 |= SM(val, AR_PAPRDChainMask);
44797
44798- ACCESS_ONCE(ads->ctl12) = ctl12;
44799- ACCESS_ONCE(ads->ctl17) = ctl17;
44800+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44801+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44802
44803- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44804+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44805 | set11nPktDurRTSCTS(i->rates, 1);
44806
44807- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44808+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44809 | set11nPktDurRTSCTS(i->rates, 3);
44810
44811- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44812+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44813 | set11nRateFlags(i->rates, 1)
44814 | set11nRateFlags(i->rates, 2)
44815 | set11nRateFlags(i->rates, 3)
44816 | SM(i->rtscts_rate, AR_RTSCTSRate);
44817
44818- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44819+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44820 }
44821
44822 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44823diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44824index cd74b3a..6a28d24 100644
44825--- a/drivers/net/wireless/ath/ath9k/hw.h
44826+++ b/drivers/net/wireless/ath/ath9k/hw.h
44827@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44828
44829 /* ANI */
44830 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44831-};
44832+} __no_const;
44833
44834 /**
44835 * struct ath_spec_scan - parameters for Atheros spectral scan
44836@@ -721,7 +721,7 @@ struct ath_hw_ops {
44837 struct ath_spec_scan *param);
44838 void (*spectral_scan_trigger)(struct ath_hw *ah);
44839 void (*spectral_scan_wait)(struct ath_hw *ah);
44840-};
44841+} __no_const;
44842
44843 struct ath_nf_limits {
44844 s16 max;
44845diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44846index 9581d07..84f6a76 100644
44847--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44848+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44849@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44850 */
44851 if (il3945_mod_params.disable_hw_scan) {
44852 D_INFO("Disabling hw_scan\n");
44853- il3945_mac_ops.hw_scan = NULL;
44854+ pax_open_kernel();
44855+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44856+ pax_close_kernel();
44857 }
44858
44859 D_INFO("*** LOAD DRIVER ***\n");
44860diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44861index d532948..e0d8bb1 100644
44862--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44863+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44864@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44865 {
44866 struct iwl_priv *priv = file->private_data;
44867 char buf[64];
44868- int buf_size;
44869+ size_t buf_size;
44870 u32 offset, len;
44871
44872 memset(buf, 0, sizeof(buf));
44873@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44874 struct iwl_priv *priv = file->private_data;
44875
44876 char buf[8];
44877- int buf_size;
44878+ size_t buf_size;
44879 u32 reset_flag;
44880
44881 memset(buf, 0, sizeof(buf));
44882@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44883 {
44884 struct iwl_priv *priv = file->private_data;
44885 char buf[8];
44886- int buf_size;
44887+ size_t buf_size;
44888 int ht40;
44889
44890 memset(buf, 0, sizeof(buf));
44891@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44892 {
44893 struct iwl_priv *priv = file->private_data;
44894 char buf[8];
44895- int buf_size;
44896+ size_t buf_size;
44897 int value;
44898
44899 memset(buf, 0, sizeof(buf));
44900@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44901 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44902 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44903
44904-static const char *fmt_value = " %-30s %10u\n";
44905-static const char *fmt_hex = " %-30s 0x%02X\n";
44906-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44907-static const char *fmt_header =
44908+static const char fmt_value[] = " %-30s %10u\n";
44909+static const char fmt_hex[] = " %-30s 0x%02X\n";
44910+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44911+static const char fmt_header[] =
44912 "%-32s current cumulative delta max\n";
44913
44914 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44915@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44916 {
44917 struct iwl_priv *priv = file->private_data;
44918 char buf[8];
44919- int buf_size;
44920+ size_t buf_size;
44921 int clear;
44922
44923 memset(buf, 0, sizeof(buf));
44924@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44925 {
44926 struct iwl_priv *priv = file->private_data;
44927 char buf[8];
44928- int buf_size;
44929+ size_t buf_size;
44930 int trace;
44931
44932 memset(buf, 0, sizeof(buf));
44933@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44934 {
44935 struct iwl_priv *priv = file->private_data;
44936 char buf[8];
44937- int buf_size;
44938+ size_t buf_size;
44939 int missed;
44940
44941 memset(buf, 0, sizeof(buf));
44942@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44943
44944 struct iwl_priv *priv = file->private_data;
44945 char buf[8];
44946- int buf_size;
44947+ size_t buf_size;
44948 int plcp;
44949
44950 memset(buf, 0, sizeof(buf));
44951@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44952
44953 struct iwl_priv *priv = file->private_data;
44954 char buf[8];
44955- int buf_size;
44956+ size_t buf_size;
44957 int flush;
44958
44959 memset(buf, 0, sizeof(buf));
44960@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44961
44962 struct iwl_priv *priv = file->private_data;
44963 char buf[8];
44964- int buf_size;
44965+ size_t buf_size;
44966 int rts;
44967
44968 if (!priv->cfg->ht_params)
44969@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44970 {
44971 struct iwl_priv *priv = file->private_data;
44972 char buf[8];
44973- int buf_size;
44974+ size_t buf_size;
44975
44976 memset(buf, 0, sizeof(buf));
44977 buf_size = min(count, sizeof(buf) - 1);
44978@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44979 struct iwl_priv *priv = file->private_data;
44980 u32 event_log_flag;
44981 char buf[8];
44982- int buf_size;
44983+ size_t buf_size;
44984
44985 /* check that the interface is up */
44986 if (!iwl_is_ready(priv))
44987@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44988 struct iwl_priv *priv = file->private_data;
44989 char buf[8];
44990 u32 calib_disabled;
44991- int buf_size;
44992+ size_t buf_size;
44993
44994 memset(buf, 0, sizeof(buf));
44995 buf_size = min(count, sizeof(buf) - 1);
44996diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44997index 1531a4f..21d2641 100644
44998--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44999+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45000@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45001 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45002 {
45003 struct iwl_nvm_data *data = priv->nvm_data;
45004- char *debug_msg;
45005+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45006
45007 if (data->sku_cap_11n_enable &&
45008 !priv->cfg->ht_params) {
45009@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45010 return -EINVAL;
45011 }
45012
45013- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45014 IWL_DEBUG_INFO(priv, debug_msg,
45015 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45016 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45017diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45018index 390e2f0..75cfbaf 100644
45019--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45020+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45021@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45022 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45023
45024 char buf[8];
45025- int buf_size;
45026+ size_t buf_size;
45027 u32 reset_flag;
45028
45029 memset(buf, 0, sizeof(buf));
45030@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45031 {
45032 struct iwl_trans *trans = file->private_data;
45033 char buf[8];
45034- int buf_size;
45035+ size_t buf_size;
45036 int csr;
45037
45038 memset(buf, 0, sizeof(buf));
45039diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45040index cb34c78..9fec0dc 100644
45041--- a/drivers/net/wireless/mac80211_hwsim.c
45042+++ b/drivers/net/wireless/mac80211_hwsim.c
45043@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45044
45045 if (channels > 1) {
45046 hwsim_if_comb.num_different_channels = channels;
45047- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45048- mac80211_hwsim_ops.cancel_hw_scan =
45049- mac80211_hwsim_cancel_hw_scan;
45050- mac80211_hwsim_ops.sw_scan_start = NULL;
45051- mac80211_hwsim_ops.sw_scan_complete = NULL;
45052- mac80211_hwsim_ops.remain_on_channel =
45053- mac80211_hwsim_roc;
45054- mac80211_hwsim_ops.cancel_remain_on_channel =
45055- mac80211_hwsim_croc;
45056- mac80211_hwsim_ops.add_chanctx =
45057- mac80211_hwsim_add_chanctx;
45058- mac80211_hwsim_ops.remove_chanctx =
45059- mac80211_hwsim_remove_chanctx;
45060- mac80211_hwsim_ops.change_chanctx =
45061- mac80211_hwsim_change_chanctx;
45062- mac80211_hwsim_ops.assign_vif_chanctx =
45063- mac80211_hwsim_assign_vif_chanctx;
45064- mac80211_hwsim_ops.unassign_vif_chanctx =
45065- mac80211_hwsim_unassign_vif_chanctx;
45066+ pax_open_kernel();
45067+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45068+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45069+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45070+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45071+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45072+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45073+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45074+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45075+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45076+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45077+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45078+ pax_close_kernel();
45079 }
45080
45081 spin_lock_init(&hwsim_radio_lock);
45082diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45083index 8169a85..7fa3b47 100644
45084--- a/drivers/net/wireless/rndis_wlan.c
45085+++ b/drivers/net/wireless/rndis_wlan.c
45086@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45087
45088 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45089
45090- if (rts_threshold < 0 || rts_threshold > 2347)
45091+ if (rts_threshold > 2347)
45092 rts_threshold = 2347;
45093
45094 tmp = cpu_to_le32(rts_threshold);
45095diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45096index ee3fc57..ed5ddc9 100644
45097--- a/drivers/net/wireless/rt2x00/rt2x00.h
45098+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45099@@ -386,7 +386,7 @@ struct rt2x00_intf {
45100 * for hardware which doesn't support hardware
45101 * sequence counting.
45102 */
45103- atomic_t seqno;
45104+ atomic_unchecked_t seqno;
45105 };
45106
45107 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45108diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45109index aa95c6c..a59dd67 100644
45110--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45111+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45112@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45113 * sequence counter given by mac80211.
45114 */
45115 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45116- seqno = atomic_add_return(0x10, &intf->seqno);
45117+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45118 else
45119- seqno = atomic_read(&intf->seqno);
45120+ seqno = atomic_read_unchecked(&intf->seqno);
45121
45122 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45123 hdr->seq_ctrl |= cpu_to_le16(seqno);
45124diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45125index e2b3d9c..67a5184 100644
45126--- a/drivers/net/wireless/ti/wl1251/sdio.c
45127+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45128@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45129
45130 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45131
45132- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45133- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45134+ pax_open_kernel();
45135+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45136+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45137+ pax_close_kernel();
45138
45139 wl1251_info("using dedicated interrupt line");
45140 } else {
45141- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45142- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45143+ pax_open_kernel();
45144+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45145+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45146+ pax_close_kernel();
45147
45148 wl1251_info("using SDIO interrupt");
45149 }
45150diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45151index 1c627da..69f7d17 100644
45152--- a/drivers/net/wireless/ti/wl12xx/main.c
45153+++ b/drivers/net/wireless/ti/wl12xx/main.c
45154@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45155 sizeof(wl->conf.mem));
45156
45157 /* read data preparation is only needed by wl127x */
45158- wl->ops->prepare_read = wl127x_prepare_read;
45159+ pax_open_kernel();
45160+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45161+ pax_close_kernel();
45162
45163 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45164 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45165@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45166 sizeof(wl->conf.mem));
45167
45168 /* read data preparation is only needed by wl127x */
45169- wl->ops->prepare_read = wl127x_prepare_read;
45170+ pax_open_kernel();
45171+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45172+ pax_close_kernel();
45173
45174 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45175 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45176diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45177index 7aa0eb8..5a9ef38 100644
45178--- a/drivers/net/wireless/ti/wl18xx/main.c
45179+++ b/drivers/net/wireless/ti/wl18xx/main.c
45180@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45181 }
45182
45183 if (!checksum_param) {
45184- wl18xx_ops.set_rx_csum = NULL;
45185- wl18xx_ops.init_vif = NULL;
45186+ pax_open_kernel();
45187+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45188+ *(void **)&wl18xx_ops.init_vif = NULL;
45189+ pax_close_kernel();
45190 }
45191
45192 /* Enable 11a Band only if we have 5G antennas */
45193diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45194index 7ef0b4a..ff65c28 100644
45195--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45196+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45197@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45198 {
45199 struct zd_usb *usb = urb->context;
45200 struct zd_usb_interrupt *intr = &usb->intr;
45201- int len;
45202+ unsigned int len;
45203 u16 int_num;
45204
45205 ZD_ASSERT(in_interrupt());
45206diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45207index d93b2b6..ae50401 100644
45208--- a/drivers/oprofile/buffer_sync.c
45209+++ b/drivers/oprofile/buffer_sync.c
45210@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45211 if (cookie == NO_COOKIE)
45212 offset = pc;
45213 if (cookie == INVALID_COOKIE) {
45214- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45215+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45216 offset = pc;
45217 }
45218 if (cookie != last_cookie) {
45219@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45220 /* add userspace sample */
45221
45222 if (!mm) {
45223- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45224+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45225 return 0;
45226 }
45227
45228 cookie = lookup_dcookie(mm, s->eip, &offset);
45229
45230 if (cookie == INVALID_COOKIE) {
45231- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45232+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45233 return 0;
45234 }
45235
45236@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45237 /* ignore backtraces if failed to add a sample */
45238 if (state == sb_bt_start) {
45239 state = sb_bt_ignore;
45240- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45241+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45242 }
45243 }
45244 release_mm(mm);
45245diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45246index c0cc4e7..44d4e54 100644
45247--- a/drivers/oprofile/event_buffer.c
45248+++ b/drivers/oprofile/event_buffer.c
45249@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45250 }
45251
45252 if (buffer_pos == buffer_size) {
45253- atomic_inc(&oprofile_stats.event_lost_overflow);
45254+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45255 return;
45256 }
45257
45258diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45259index ed2c3ec..deda85a 100644
45260--- a/drivers/oprofile/oprof.c
45261+++ b/drivers/oprofile/oprof.c
45262@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45263 if (oprofile_ops.switch_events())
45264 return;
45265
45266- atomic_inc(&oprofile_stats.multiplex_counter);
45267+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45268 start_switch_worker();
45269 }
45270
45271diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45272index 84a208d..d61b0a1 100644
45273--- a/drivers/oprofile/oprofile_files.c
45274+++ b/drivers/oprofile/oprofile_files.c
45275@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45276
45277 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45278
45279-static ssize_t timeout_read(struct file *file, char __user *buf,
45280+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45281 size_t count, loff_t *offset)
45282 {
45283 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45284diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45285index 917d28e..d62d981 100644
45286--- a/drivers/oprofile/oprofile_stats.c
45287+++ b/drivers/oprofile/oprofile_stats.c
45288@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45289 cpu_buf->sample_invalid_eip = 0;
45290 }
45291
45292- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45293- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45294- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45295- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45296- atomic_set(&oprofile_stats.multiplex_counter, 0);
45297+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45298+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45299+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45300+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45301+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45302 }
45303
45304
45305diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45306index 38b6fc0..b5cbfce 100644
45307--- a/drivers/oprofile/oprofile_stats.h
45308+++ b/drivers/oprofile/oprofile_stats.h
45309@@ -13,11 +13,11 @@
45310 #include <linux/atomic.h>
45311
45312 struct oprofile_stat_struct {
45313- atomic_t sample_lost_no_mm;
45314- atomic_t sample_lost_no_mapping;
45315- atomic_t bt_lost_no_mapping;
45316- atomic_t event_lost_overflow;
45317- atomic_t multiplex_counter;
45318+ atomic_unchecked_t sample_lost_no_mm;
45319+ atomic_unchecked_t sample_lost_no_mapping;
45320+ atomic_unchecked_t bt_lost_no_mapping;
45321+ atomic_unchecked_t event_lost_overflow;
45322+ atomic_unchecked_t multiplex_counter;
45323 };
45324
45325 extern struct oprofile_stat_struct oprofile_stats;
45326diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45327index 7c12d9c..558bf3bb 100644
45328--- a/drivers/oprofile/oprofilefs.c
45329+++ b/drivers/oprofile/oprofilefs.c
45330@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45331
45332
45333 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45334- char const *name, atomic_t *val)
45335+ char const *name, atomic_unchecked_t *val)
45336 {
45337 return __oprofilefs_create_file(sb, root, name,
45338 &atomic_ro_fops, 0444, val);
45339diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45340index 61be1d9..dec05d7 100644
45341--- a/drivers/oprofile/timer_int.c
45342+++ b/drivers/oprofile/timer_int.c
45343@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45344 return NOTIFY_OK;
45345 }
45346
45347-static struct notifier_block __refdata oprofile_cpu_notifier = {
45348+static struct notifier_block oprofile_cpu_notifier = {
45349 .notifier_call = oprofile_cpu_notify,
45350 };
45351
45352diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45353index 92ed045..62d39bd7 100644
45354--- a/drivers/parport/procfs.c
45355+++ b/drivers/parport/procfs.c
45356@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45357
45358 *ppos += len;
45359
45360- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45361+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45362 }
45363
45364 #ifdef CONFIG_PARPORT_1284
45365@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45366
45367 *ppos += len;
45368
45369- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45370+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45371 }
45372 #endif /* IEEE1284.3 support. */
45373
45374diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45375index c35e8ad..fc33beb 100644
45376--- a/drivers/pci/hotplug/acpiphp_ibm.c
45377+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45378@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45379 goto init_cleanup;
45380 }
45381
45382- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45383+ pax_open_kernel();
45384+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45385+ pax_close_kernel();
45386 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45387
45388 return retval;
45389diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45390index a6a71c4..c91097b 100644
45391--- a/drivers/pci/hotplug/cpcihp_generic.c
45392+++ b/drivers/pci/hotplug/cpcihp_generic.c
45393@@ -73,7 +73,6 @@ static u16 port;
45394 static unsigned int enum_bit;
45395 static u8 enum_mask;
45396
45397-static struct cpci_hp_controller_ops generic_hpc_ops;
45398 static struct cpci_hp_controller generic_hpc;
45399
45400 static int __init validate_parameters(void)
45401@@ -139,6 +138,10 @@ static int query_enum(void)
45402 return ((value & enum_mask) == enum_mask);
45403 }
45404
45405+static struct cpci_hp_controller_ops generic_hpc_ops = {
45406+ .query_enum = query_enum,
45407+};
45408+
45409 static int __init cpcihp_generic_init(void)
45410 {
45411 int status;
45412@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45413 pci_dev_put(dev);
45414
45415 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45416- generic_hpc_ops.query_enum = query_enum;
45417 generic_hpc.ops = &generic_hpc_ops;
45418
45419 status = cpci_hp_register_controller(&generic_hpc);
45420diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45421index 449b4bb..257e2e8 100644
45422--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45423+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45424@@ -59,7 +59,6 @@
45425 /* local variables */
45426 static bool debug;
45427 static bool poll;
45428-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45429 static struct cpci_hp_controller zt5550_hpc;
45430
45431 /* Primary cPCI bus bridge device */
45432@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45433 return 0;
45434 }
45435
45436+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45437+ .query_enum = zt5550_hc_query_enum,
45438+};
45439+
45440 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45441 {
45442 int status;
45443@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45444 dbg("returned from zt5550_hc_config");
45445
45446 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45447- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45448 zt5550_hpc.ops = &zt5550_hpc_ops;
45449 if(!poll) {
45450 zt5550_hpc.irq = hc_dev->irq;
45451 zt5550_hpc.irq_flags = IRQF_SHARED;
45452 zt5550_hpc.dev_id = hc_dev;
45453
45454- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45455- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45456- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45457+ pax_open_kernel();
45458+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45459+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45460+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45461+ pax_open_kernel();
45462 } else {
45463 info("using ENUM# polling mode");
45464 }
45465diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45466index 76ba8a1..20ca857 100644
45467--- a/drivers/pci/hotplug/cpqphp_nvram.c
45468+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45469@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45470
45471 void compaq_nvram_init (void __iomem *rom_start)
45472 {
45473+
45474+#ifndef CONFIG_PAX_KERNEXEC
45475 if (rom_start) {
45476 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45477 }
45478+#endif
45479+
45480 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45481
45482 /* initialize our int15 lock */
45483diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45484index ec20f74..c1d961e 100644
45485--- a/drivers/pci/hotplug/pci_hotplug_core.c
45486+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45487@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45488 return -EINVAL;
45489 }
45490
45491- slot->ops->owner = owner;
45492- slot->ops->mod_name = mod_name;
45493+ pax_open_kernel();
45494+ *(struct module **)&slot->ops->owner = owner;
45495+ *(const char **)&slot->ops->mod_name = mod_name;
45496+ pax_close_kernel();
45497
45498 mutex_lock(&pci_hp_mutex);
45499 /*
45500diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45501index 7d72c5e..edce02c 100644
45502--- a/drivers/pci/hotplug/pciehp_core.c
45503+++ b/drivers/pci/hotplug/pciehp_core.c
45504@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45505 struct slot *slot = ctrl->slot;
45506 struct hotplug_slot *hotplug = NULL;
45507 struct hotplug_slot_info *info = NULL;
45508- struct hotplug_slot_ops *ops = NULL;
45509+ hotplug_slot_ops_no_const *ops = NULL;
45510 char name[SLOT_NAME_SIZE];
45511 int retval = -ENOMEM;
45512
45513diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45514index c0dbe1f..94cf3d8 100644
45515--- a/drivers/pci/pci-sysfs.c
45516+++ b/drivers/pci/pci-sysfs.c
45517@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45518 {
45519 /* allocate attribute structure, piggyback attribute name */
45520 int name_len = write_combine ? 13 : 10;
45521- struct bin_attribute *res_attr;
45522+ bin_attribute_no_const *res_attr;
45523 int retval;
45524
45525 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45526@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45527 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45528 {
45529 int retval;
45530- struct bin_attribute *attr;
45531+ bin_attribute_no_const *attr;
45532
45533 /* If the device has VPD, try to expose it in sysfs. */
45534 if (dev->vpd) {
45535@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45536 {
45537 int retval;
45538 int rom_size = 0;
45539- struct bin_attribute *attr;
45540+ bin_attribute_no_const *attr;
45541
45542 if (!sysfs_initialized)
45543 return -EACCES;
45544diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45545index d1182c4..2a138ec 100644
45546--- a/drivers/pci/pci.h
45547+++ b/drivers/pci/pci.h
45548@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45549 struct pci_vpd {
45550 unsigned int len;
45551 const struct pci_vpd_ops *ops;
45552- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45553+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45554 };
45555
45556 int pci_vpd_pci22_init(struct pci_dev *dev);
45557diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45558index 403a443..034e050 100644
45559--- a/drivers/pci/pcie/aspm.c
45560+++ b/drivers/pci/pcie/aspm.c
45561@@ -27,9 +27,9 @@
45562 #define MODULE_PARAM_PREFIX "pcie_aspm."
45563
45564 /* Note: those are not register definitions */
45565-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45566-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45567-#define ASPM_STATE_L1 (4) /* L1 state */
45568+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45569+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45570+#define ASPM_STATE_L1 (4U) /* L1 state */
45571 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45572 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45573
45574diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45575index 46ada5c..20da716 100644
45576--- a/drivers/pci/probe.c
45577+++ b/drivers/pci/probe.c
45578@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45579 struct pci_bus_region region, inverted_region;
45580 bool bar_too_big = false, bar_disabled = false;
45581
45582- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45583+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45584
45585 /* No printks while decoding is disabled! */
45586 if (!dev->mmio_always_on) {
45587diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45588index cdc7836..528635c 100644
45589--- a/drivers/pci/proc.c
45590+++ b/drivers/pci/proc.c
45591@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45592 static int __init pci_proc_init(void)
45593 {
45594 struct pci_dev *dev = NULL;
45595+
45596+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45597+#ifdef CONFIG_GRKERNSEC_PROC_USER
45598+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45599+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45600+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45601+#endif
45602+#else
45603 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45604+#endif
45605 proc_create("devices", 0, proc_bus_pci_dir,
45606 &proc_bus_pci_dev_operations);
45607 proc_initialized = 1;
45608diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45609index 3e5b4497..dcdfb70 100644
45610--- a/drivers/platform/x86/chromeos_laptop.c
45611+++ b/drivers/platform/x86/chromeos_laptop.c
45612@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45613 return 0;
45614 }
45615
45616-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45617+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45618 {
45619 .ident = "Samsung Series 5 550 - Touchpad",
45620 .matches = {
45621diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45622index 62f8030..c7f2a45 100644
45623--- a/drivers/platform/x86/msi-laptop.c
45624+++ b/drivers/platform/x86/msi-laptop.c
45625@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45626
45627 if (!quirks->ec_read_only) {
45628 /* allow userland write sysfs file */
45629- dev_attr_bluetooth.store = store_bluetooth;
45630- dev_attr_wlan.store = store_wlan;
45631- dev_attr_threeg.store = store_threeg;
45632- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45633- dev_attr_wlan.attr.mode |= S_IWUSR;
45634- dev_attr_threeg.attr.mode |= S_IWUSR;
45635+ pax_open_kernel();
45636+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45637+ *(void **)&dev_attr_wlan.store = store_wlan;
45638+ *(void **)&dev_attr_threeg.store = store_threeg;
45639+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45640+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45641+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45642+ pax_close_kernel();
45643 }
45644
45645 /* disable hardware control by fn key */
45646diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45647index 3a1b6bf..b453930 100644
45648--- a/drivers/platform/x86/sony-laptop.c
45649+++ b/drivers/platform/x86/sony-laptop.c
45650@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45651 }
45652
45653 /* High speed charging function */
45654-static struct device_attribute *hsc_handle;
45655+static device_attribute_no_const *hsc_handle;
45656
45657 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45658 struct device_attribute *attr,
45659diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45660index 54d31c0..3f896d3 100644
45661--- a/drivers/platform/x86/thinkpad_acpi.c
45662+++ b/drivers/platform/x86/thinkpad_acpi.c
45663@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45664 return 0;
45665 }
45666
45667-void static hotkey_mask_warn_incomplete_mask(void)
45668+static void hotkey_mask_warn_incomplete_mask(void)
45669 {
45670 /* log only what the user can fix... */
45671 const u32 wantedmask = hotkey_driver_mask &
45672@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45673 }
45674 }
45675
45676-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45677- struct tp_nvram_state *newn,
45678- const u32 event_mask)
45679-{
45680-
45681 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45682 do { \
45683 if ((event_mask & (1 << __scancode)) && \
45684@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45685 tpacpi_hotkey_send_key(__scancode); \
45686 } while (0)
45687
45688- void issue_volchange(const unsigned int oldvol,
45689- const unsigned int newvol)
45690- {
45691- unsigned int i = oldvol;
45692+static void issue_volchange(const unsigned int oldvol,
45693+ const unsigned int newvol,
45694+ const u32 event_mask)
45695+{
45696+ unsigned int i = oldvol;
45697
45698- while (i > newvol) {
45699- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45700- i--;
45701- }
45702- while (i < newvol) {
45703- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45704- i++;
45705- }
45706+ while (i > newvol) {
45707+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45708+ i--;
45709 }
45710+ while (i < newvol) {
45711+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45712+ i++;
45713+ }
45714+}
45715
45716- void issue_brightnesschange(const unsigned int oldbrt,
45717- const unsigned int newbrt)
45718- {
45719- unsigned int i = oldbrt;
45720+static void issue_brightnesschange(const unsigned int oldbrt,
45721+ const unsigned int newbrt,
45722+ const u32 event_mask)
45723+{
45724+ unsigned int i = oldbrt;
45725
45726- while (i > newbrt) {
45727- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45728- i--;
45729- }
45730- while (i < newbrt) {
45731- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45732- i++;
45733- }
45734+ while (i > newbrt) {
45735+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45736+ i--;
45737+ }
45738+ while (i < newbrt) {
45739+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45740+ i++;
45741 }
45742+}
45743
45744+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45745+ struct tp_nvram_state *newn,
45746+ const u32 event_mask)
45747+{
45748 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45749 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45750 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45751@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45752 oldn->volume_level != newn->volume_level) {
45753 /* recently muted, or repeated mute keypress, or
45754 * multiple presses ending in mute */
45755- issue_volchange(oldn->volume_level, newn->volume_level);
45756+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45757 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45758 }
45759 } else {
45760@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45761 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45762 }
45763 if (oldn->volume_level != newn->volume_level) {
45764- issue_volchange(oldn->volume_level, newn->volume_level);
45765+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45766 } else if (oldn->volume_toggle != newn->volume_toggle) {
45767 /* repeated vol up/down keypress at end of scale ? */
45768 if (newn->volume_level == 0)
45769@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45770 /* handle brightness */
45771 if (oldn->brightness_level != newn->brightness_level) {
45772 issue_brightnesschange(oldn->brightness_level,
45773- newn->brightness_level);
45774+ newn->brightness_level,
45775+ event_mask);
45776 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45777 /* repeated key presses that didn't change state */
45778 if (newn->brightness_level == 0)
45779@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45780 && !tp_features.bright_unkfw)
45781 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45782 }
45783+}
45784
45785 #undef TPACPI_COMPARE_KEY
45786 #undef TPACPI_MAY_SEND_KEY
45787-}
45788
45789 /*
45790 * Polling driver
45791diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45792index 769d265..a3a05ca 100644
45793--- a/drivers/pnp/pnpbios/bioscalls.c
45794+++ b/drivers/pnp/pnpbios/bioscalls.c
45795@@ -58,7 +58,7 @@ do { \
45796 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45797 } while(0)
45798
45799-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45800+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45801 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45802
45803 /*
45804@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45805
45806 cpu = get_cpu();
45807 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45808+
45809+ pax_open_kernel();
45810 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45811+ pax_close_kernel();
45812
45813 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45814 spin_lock_irqsave(&pnp_bios_lock, flags);
45815@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45816 :"memory");
45817 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45818
45819+ pax_open_kernel();
45820 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45821+ pax_close_kernel();
45822+
45823 put_cpu();
45824
45825 /* If we get here and this is set then the PnP BIOS faulted on us. */
45826@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45827 return status;
45828 }
45829
45830-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45831+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45832 {
45833 int i;
45834
45835@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45836 pnp_bios_callpoint.offset = header->fields.pm16offset;
45837 pnp_bios_callpoint.segment = PNP_CS16;
45838
45839+ pax_open_kernel();
45840+
45841 for_each_possible_cpu(i) {
45842 struct desc_struct *gdt = get_cpu_gdt_table(i);
45843 if (!gdt)
45844@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45845 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45846 (unsigned long)__va(header->fields.pm16dseg));
45847 }
45848+
45849+ pax_close_kernel();
45850 }
45851diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45852index d95e101..67f0c3f 100644
45853--- a/drivers/pnp/resource.c
45854+++ b/drivers/pnp/resource.c
45855@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45856 return 1;
45857
45858 /* check if the resource is valid */
45859- if (*irq < 0 || *irq > 15)
45860+ if (*irq > 15)
45861 return 0;
45862
45863 /* check if the resource is reserved */
45864@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45865 return 1;
45866
45867 /* check if the resource is valid */
45868- if (*dma < 0 || *dma == 4 || *dma > 7)
45869+ if (*dma == 4 || *dma > 7)
45870 return 0;
45871
45872 /* check if the resource is reserved */
45873diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45874index 0c52e2a..3421ab7 100644
45875--- a/drivers/power/pda_power.c
45876+++ b/drivers/power/pda_power.c
45877@@ -37,7 +37,11 @@ static int polling;
45878
45879 #if IS_ENABLED(CONFIG_USB_PHY)
45880 static struct usb_phy *transceiver;
45881-static struct notifier_block otg_nb;
45882+static int otg_handle_notification(struct notifier_block *nb,
45883+ unsigned long event, void *unused);
45884+static struct notifier_block otg_nb = {
45885+ .notifier_call = otg_handle_notification
45886+};
45887 #endif
45888
45889 static struct regulator *ac_draw;
45890@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45891
45892 #if IS_ENABLED(CONFIG_USB_PHY)
45893 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45894- otg_nb.notifier_call = otg_handle_notification;
45895 ret = usb_register_notifier(transceiver, &otg_nb);
45896 if (ret) {
45897 dev_err(dev, "failure to register otg notifier\n");
45898diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45899index cc439fd..8fa30df 100644
45900--- a/drivers/power/power_supply.h
45901+++ b/drivers/power/power_supply.h
45902@@ -16,12 +16,12 @@ struct power_supply;
45903
45904 #ifdef CONFIG_SYSFS
45905
45906-extern void power_supply_init_attrs(struct device_type *dev_type);
45907+extern void power_supply_init_attrs(void);
45908 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45909
45910 #else
45911
45912-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45913+static inline void power_supply_init_attrs(void) {}
45914 #define power_supply_uevent NULL
45915
45916 #endif /* CONFIG_SYSFS */
45917diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45918index 3b2d5df..3207114 100644
45919--- a/drivers/power/power_supply_core.c
45920+++ b/drivers/power/power_supply_core.c
45921@@ -24,7 +24,10 @@
45922 struct class *power_supply_class;
45923 EXPORT_SYMBOL_GPL(power_supply_class);
45924
45925-static struct device_type power_supply_dev_type;
45926+extern const struct attribute_group *power_supply_attr_groups[];
45927+static struct device_type power_supply_dev_type = {
45928+ .groups = power_supply_attr_groups,
45929+};
45930
45931 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45932 struct power_supply *supply)
45933@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45934 return PTR_ERR(power_supply_class);
45935
45936 power_supply_class->dev_uevent = power_supply_uevent;
45937- power_supply_init_attrs(&power_supply_dev_type);
45938+ power_supply_init_attrs();
45939
45940 return 0;
45941 }
45942diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45943index 29178f7..c65f324 100644
45944--- a/drivers/power/power_supply_sysfs.c
45945+++ b/drivers/power/power_supply_sysfs.c
45946@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45947 .is_visible = power_supply_attr_is_visible,
45948 };
45949
45950-static const struct attribute_group *power_supply_attr_groups[] = {
45951+const struct attribute_group *power_supply_attr_groups[] = {
45952 &power_supply_attr_group,
45953 NULL,
45954 };
45955
45956-void power_supply_init_attrs(struct device_type *dev_type)
45957+void power_supply_init_attrs(void)
45958 {
45959 int i;
45960
45961- dev_type->groups = power_supply_attr_groups;
45962-
45963 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45964 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45965 }
45966diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45967index 288c75a..065bc84 100644
45968--- a/drivers/regulator/core.c
45969+++ b/drivers/regulator/core.c
45970@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45971 {
45972 const struct regulation_constraints *constraints = NULL;
45973 const struct regulator_init_data *init_data;
45974- static atomic_t regulator_no = ATOMIC_INIT(0);
45975+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45976 struct regulator_dev *rdev;
45977 struct device *dev;
45978 int ret, i;
45979@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45980 rdev->dev.of_node = config->of_node;
45981 rdev->dev.parent = dev;
45982 dev_set_name(&rdev->dev, "regulator.%d",
45983- atomic_inc_return(&regulator_no) - 1);
45984+ atomic_inc_return_unchecked(&regulator_no) - 1);
45985 ret = device_register(&rdev->dev);
45986 if (ret != 0) {
45987 put_device(&rdev->dev);
45988diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45989index d428ef9..fdc0357 100644
45990--- a/drivers/regulator/max8660.c
45991+++ b/drivers/regulator/max8660.c
45992@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45993 max8660->shadow_regs[MAX8660_OVER1] = 5;
45994 } else {
45995 /* Otherwise devices can be toggled via software */
45996- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45997- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45998+ pax_open_kernel();
45999+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46000+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46001+ pax_close_kernel();
46002 }
46003
46004 /*
46005diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46006index 0c5195a..637a453d 100644
46007--- a/drivers/regulator/max8973-regulator.c
46008+++ b/drivers/regulator/max8973-regulator.c
46009@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46010 if (!pdata || !pdata->enable_ext_control) {
46011 max->desc.enable_reg = MAX8973_VOUT;
46012 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46013- max->ops.enable = regulator_enable_regmap;
46014- max->ops.disable = regulator_disable_regmap;
46015- max->ops.is_enabled = regulator_is_enabled_regmap;
46016+ pax_open_kernel();
46017+ *(void **)&max->ops.enable = regulator_enable_regmap;
46018+ *(void **)&max->ops.disable = regulator_disable_regmap;
46019+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46020+ pax_close_kernel();
46021 }
46022
46023 if (pdata) {
46024diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46025index 1037e07..e64dea1 100644
46026--- a/drivers/regulator/mc13892-regulator.c
46027+++ b/drivers/regulator/mc13892-regulator.c
46028@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46029 }
46030 mc13xxx_unlock(mc13892);
46031
46032- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46033+ pax_open_kernel();
46034+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46035 = mc13892_vcam_set_mode;
46036- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46037+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46038 = mc13892_vcam_get_mode;
46039+ pax_close_kernel();
46040
46041 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46042 ARRAY_SIZE(mc13892_regulators));
46043diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46044index be06d71..264aee9 100644
46045--- a/drivers/rtc/rtc-cmos.c
46046+++ b/drivers/rtc/rtc-cmos.c
46047@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46048 hpet_rtc_timer_init();
46049
46050 /* export at least the first block of NVRAM */
46051- nvram.size = address_space - NVRAM_OFFSET;
46052+ pax_open_kernel();
46053+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46054+ pax_close_kernel();
46055 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46056 if (retval < 0) {
46057 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46058diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46059index d049393..bb20be0 100644
46060--- a/drivers/rtc/rtc-dev.c
46061+++ b/drivers/rtc/rtc-dev.c
46062@@ -16,6 +16,7 @@
46063 #include <linux/module.h>
46064 #include <linux/rtc.h>
46065 #include <linux/sched.h>
46066+#include <linux/grsecurity.h>
46067 #include "rtc-core.h"
46068
46069 static dev_t rtc_devt;
46070@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46071 if (copy_from_user(&tm, uarg, sizeof(tm)))
46072 return -EFAULT;
46073
46074+ gr_log_timechange();
46075+
46076 return rtc_set_time(rtc, &tm);
46077
46078 case RTC_PIE_ON:
46079diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46080index ca18fd1..055e42d 100644
46081--- a/drivers/rtc/rtc-ds1307.c
46082+++ b/drivers/rtc/rtc-ds1307.c
46083@@ -107,7 +107,7 @@ struct ds1307 {
46084 u8 offset; /* register's offset */
46085 u8 regs[11];
46086 u16 nvram_offset;
46087- struct bin_attribute *nvram;
46088+ bin_attribute_no_const *nvram;
46089 enum ds_type type;
46090 unsigned long flags;
46091 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46092diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46093index fcb0329..d77b7f2 100644
46094--- a/drivers/rtc/rtc-m48t59.c
46095+++ b/drivers/rtc/rtc-m48t59.c
46096@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46097 if (IS_ERR(m48t59->rtc))
46098 return PTR_ERR(m48t59->rtc);
46099
46100- m48t59_nvram_attr.size = pdata->offset;
46101+ pax_open_kernel();
46102+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46103+ pax_close_kernel();
46104
46105 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46106 if (ret)
46107diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46108index e693af6..2e525b6 100644
46109--- a/drivers/scsi/bfa/bfa_fcpim.h
46110+++ b/drivers/scsi/bfa/bfa_fcpim.h
46111@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46112
46113 struct bfa_itn_s {
46114 bfa_isr_func_t isr;
46115-};
46116+} __no_const;
46117
46118 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46119 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46120diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46121index 90814fe..4384138 100644
46122--- a/drivers/scsi/bfa/bfa_ioc.h
46123+++ b/drivers/scsi/bfa/bfa_ioc.h
46124@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46125 bfa_ioc_disable_cbfn_t disable_cbfn;
46126 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46127 bfa_ioc_reset_cbfn_t reset_cbfn;
46128-};
46129+} __no_const;
46130
46131 /*
46132 * IOC event notification mechanism.
46133@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46134 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46135 enum bfi_ioc_state fwstate);
46136 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46137-};
46138+} __no_const;
46139
46140 /*
46141 * Queue element to wait for room in request queue. FIFO order is
46142diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46143index c9382d6..6619864 100644
46144--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46145+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46146@@ -33,8 +33,8 @@
46147 */
46148 #include "libfcoe.h"
46149
46150-static atomic_t ctlr_num;
46151-static atomic_t fcf_num;
46152+static atomic_unchecked_t ctlr_num;
46153+static atomic_unchecked_t fcf_num;
46154
46155 /*
46156 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46157@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46158 if (!ctlr)
46159 goto out;
46160
46161- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46162+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46163 ctlr->f = f;
46164 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46165 INIT_LIST_HEAD(&ctlr->fcfs);
46166@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46167 fcf->dev.parent = &ctlr->dev;
46168 fcf->dev.bus = &fcoe_bus_type;
46169 fcf->dev.type = &fcoe_fcf_device_type;
46170- fcf->id = atomic_inc_return(&fcf_num) - 1;
46171+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46172 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46173
46174 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46175@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46176 {
46177 int error;
46178
46179- atomic_set(&ctlr_num, 0);
46180- atomic_set(&fcf_num, 0);
46181+ atomic_set_unchecked(&ctlr_num, 0);
46182+ atomic_set_unchecked(&fcf_num, 0);
46183
46184 error = bus_register(&fcoe_bus_type);
46185 if (error)
46186diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46187index df0c3c7..b00e1d0 100644
46188--- a/drivers/scsi/hosts.c
46189+++ b/drivers/scsi/hosts.c
46190@@ -42,7 +42,7 @@
46191 #include "scsi_logging.h"
46192
46193
46194-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46195+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46196
46197
46198 static void scsi_host_cls_release(struct device *dev)
46199@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46200 * subtract one because we increment first then return, but we need to
46201 * know what the next host number was before increment
46202 */
46203- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46204+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46205 shost->dma_channel = 0xff;
46206
46207 /* These three are default values which can be overridden */
46208diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46209index 7f4f790..b75b92a 100644
46210--- a/drivers/scsi/hpsa.c
46211+++ b/drivers/scsi/hpsa.c
46212@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46213 unsigned long flags;
46214
46215 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46216- return h->access.command_completed(h, q);
46217+ return h->access->command_completed(h, q);
46218
46219 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46220 a = rq->head[rq->current_entry];
46221@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46222 while (!list_empty(&h->reqQ)) {
46223 c = list_entry(h->reqQ.next, struct CommandList, list);
46224 /* can't do anything if fifo is full */
46225- if ((h->access.fifo_full(h))) {
46226+ if ((h->access->fifo_full(h))) {
46227 dev_warn(&h->pdev->dev, "fifo full\n");
46228 break;
46229 }
46230@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46231
46232 /* Tell the controller execute command */
46233 spin_unlock_irqrestore(&h->lock, flags);
46234- h->access.submit_command(h, c);
46235+ h->access->submit_command(h, c);
46236 spin_lock_irqsave(&h->lock, flags);
46237 }
46238 spin_unlock_irqrestore(&h->lock, flags);
46239@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46240
46241 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46242 {
46243- return h->access.command_completed(h, q);
46244+ return h->access->command_completed(h, q);
46245 }
46246
46247 static inline bool interrupt_pending(struct ctlr_info *h)
46248 {
46249- return h->access.intr_pending(h);
46250+ return h->access->intr_pending(h);
46251 }
46252
46253 static inline long interrupt_not_for_us(struct ctlr_info *h)
46254 {
46255- return (h->access.intr_pending(h) == 0) ||
46256+ return (h->access->intr_pending(h) == 0) ||
46257 (h->interrupts_enabled == 0);
46258 }
46259
46260@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46261 if (prod_index < 0)
46262 return -ENODEV;
46263 h->product_name = products[prod_index].product_name;
46264- h->access = *(products[prod_index].access);
46265+ h->access = products[prod_index].access;
46266
46267 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46268 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46269@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46270
46271 assert_spin_locked(&lockup_detector_lock);
46272 remove_ctlr_from_lockup_detector_list(h);
46273- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46274+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46275 spin_lock_irqsave(&h->lock, flags);
46276 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46277 spin_unlock_irqrestore(&h->lock, flags);
46278@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46279 }
46280
46281 /* make sure the board interrupts are off */
46282- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46283+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46284
46285 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46286 goto clean2;
46287@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46288 * fake ones to scoop up any residual completions.
46289 */
46290 spin_lock_irqsave(&h->lock, flags);
46291- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46292+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46293 spin_unlock_irqrestore(&h->lock, flags);
46294 free_irqs(h);
46295 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46296@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46297 dev_info(&h->pdev->dev, "Board READY.\n");
46298 dev_info(&h->pdev->dev,
46299 "Waiting for stale completions to drain.\n");
46300- h->access.set_intr_mask(h, HPSA_INTR_ON);
46301+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46302 msleep(10000);
46303- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46304+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46305
46306 rc = controller_reset_failed(h->cfgtable);
46307 if (rc)
46308@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46309 }
46310
46311 /* Turn the interrupts on so we can service requests */
46312- h->access.set_intr_mask(h, HPSA_INTR_ON);
46313+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46314
46315 hpsa_hba_inquiry(h);
46316 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46317@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46318 * To write all data in the battery backed cache to disks
46319 */
46320 hpsa_flush_cache(h);
46321- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46322+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46323 hpsa_free_irqs_and_disable_msix(h);
46324 }
46325
46326@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46327 return;
46328 }
46329 /* Change the access methods to the performant access methods */
46330- h->access = SA5_performant_access;
46331+ h->access = &SA5_performant_access;
46332 h->transMethod = CFGTBL_Trans_Performant;
46333 }
46334
46335diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46336index 9816479..c5d4e97 100644
46337--- a/drivers/scsi/hpsa.h
46338+++ b/drivers/scsi/hpsa.h
46339@@ -79,7 +79,7 @@ struct ctlr_info {
46340 unsigned int msix_vector;
46341 unsigned int msi_vector;
46342 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46343- struct access_method access;
46344+ struct access_method *access;
46345
46346 /* queue and queue Info */
46347 struct list_head reqQ;
46348diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46349index 5879929..32b241d 100644
46350--- a/drivers/scsi/libfc/fc_exch.c
46351+++ b/drivers/scsi/libfc/fc_exch.c
46352@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46353 u16 pool_max_index;
46354
46355 struct {
46356- atomic_t no_free_exch;
46357- atomic_t no_free_exch_xid;
46358- atomic_t xid_not_found;
46359- atomic_t xid_busy;
46360- atomic_t seq_not_found;
46361- atomic_t non_bls_resp;
46362+ atomic_unchecked_t no_free_exch;
46363+ atomic_unchecked_t no_free_exch_xid;
46364+ atomic_unchecked_t xid_not_found;
46365+ atomic_unchecked_t xid_busy;
46366+ atomic_unchecked_t seq_not_found;
46367+ atomic_unchecked_t non_bls_resp;
46368 } stats;
46369 };
46370
46371@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46372 /* allocate memory for exchange */
46373 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46374 if (!ep) {
46375- atomic_inc(&mp->stats.no_free_exch);
46376+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46377 goto out;
46378 }
46379 memset(ep, 0, sizeof(*ep));
46380@@ -797,7 +797,7 @@ out:
46381 return ep;
46382 err:
46383 spin_unlock_bh(&pool->lock);
46384- atomic_inc(&mp->stats.no_free_exch_xid);
46385+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46386 mempool_free(ep, mp->ep_pool);
46387 return NULL;
46388 }
46389@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46390 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46391 ep = fc_exch_find(mp, xid);
46392 if (!ep) {
46393- atomic_inc(&mp->stats.xid_not_found);
46394+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46395 reject = FC_RJT_OX_ID;
46396 goto out;
46397 }
46398@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46399 ep = fc_exch_find(mp, xid);
46400 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46401 if (ep) {
46402- atomic_inc(&mp->stats.xid_busy);
46403+ atomic_inc_unchecked(&mp->stats.xid_busy);
46404 reject = FC_RJT_RX_ID;
46405 goto rel;
46406 }
46407@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46408 }
46409 xid = ep->xid; /* get our XID */
46410 } else if (!ep) {
46411- atomic_inc(&mp->stats.xid_not_found);
46412+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46413 reject = FC_RJT_RX_ID; /* XID not found */
46414 goto out;
46415 }
46416@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46417 } else {
46418 sp = &ep->seq;
46419 if (sp->id != fh->fh_seq_id) {
46420- atomic_inc(&mp->stats.seq_not_found);
46421+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46422 if (f_ctl & FC_FC_END_SEQ) {
46423 /*
46424 * Update sequence_id based on incoming last
46425@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46426
46427 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46428 if (!ep) {
46429- atomic_inc(&mp->stats.xid_not_found);
46430+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46431 goto out;
46432 }
46433 if (ep->esb_stat & ESB_ST_COMPLETE) {
46434- atomic_inc(&mp->stats.xid_not_found);
46435+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46436 goto rel;
46437 }
46438 if (ep->rxid == FC_XID_UNKNOWN)
46439 ep->rxid = ntohs(fh->fh_rx_id);
46440 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46441- atomic_inc(&mp->stats.xid_not_found);
46442+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46443 goto rel;
46444 }
46445 if (ep->did != ntoh24(fh->fh_s_id) &&
46446 ep->did != FC_FID_FLOGI) {
46447- atomic_inc(&mp->stats.xid_not_found);
46448+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46449 goto rel;
46450 }
46451 sof = fr_sof(fp);
46452@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46453 sp->ssb_stat |= SSB_ST_RESP;
46454 sp->id = fh->fh_seq_id;
46455 } else if (sp->id != fh->fh_seq_id) {
46456- atomic_inc(&mp->stats.seq_not_found);
46457+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46458 goto rel;
46459 }
46460
46461@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46462 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46463
46464 if (!sp)
46465- atomic_inc(&mp->stats.xid_not_found);
46466+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46467 else
46468- atomic_inc(&mp->stats.non_bls_resp);
46469+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46470
46471 fc_frame_free(fp);
46472 }
46473@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46474
46475 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46476 mp = ema->mp;
46477- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46478+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46479 st->fc_no_free_exch_xid +=
46480- atomic_read(&mp->stats.no_free_exch_xid);
46481- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46482- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46483- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46484- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46485+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46486+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46487+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46488+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46489+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46490 }
46491 }
46492 EXPORT_SYMBOL(fc_exch_update_stats);
46493diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46494index 161c98e..6d563b3 100644
46495--- a/drivers/scsi/libsas/sas_ata.c
46496+++ b/drivers/scsi/libsas/sas_ata.c
46497@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46498 .postreset = ata_std_postreset,
46499 .error_handler = ata_std_error_handler,
46500 .post_internal_cmd = sas_ata_post_internal,
46501- .qc_defer = ata_std_qc_defer,
46502+ .qc_defer = ata_std_qc_defer,
46503 .qc_prep = ata_noop_qc_prep,
46504 .qc_issue = sas_ata_qc_issue,
46505 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46506diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46507index 93f222d..73e977b 100644
46508--- a/drivers/scsi/lpfc/lpfc.h
46509+++ b/drivers/scsi/lpfc/lpfc.h
46510@@ -431,7 +431,7 @@ struct lpfc_vport {
46511 struct dentry *debug_nodelist;
46512 struct dentry *vport_debugfs_root;
46513 struct lpfc_debugfs_trc *disc_trc;
46514- atomic_t disc_trc_cnt;
46515+ atomic_unchecked_t disc_trc_cnt;
46516 #endif
46517 uint8_t stat_data_enabled;
46518 uint8_t stat_data_blocked;
46519@@ -865,8 +865,8 @@ struct lpfc_hba {
46520 struct timer_list fabric_block_timer;
46521 unsigned long bit_flags;
46522 #define FABRIC_COMANDS_BLOCKED 0
46523- atomic_t num_rsrc_err;
46524- atomic_t num_cmd_success;
46525+ atomic_unchecked_t num_rsrc_err;
46526+ atomic_unchecked_t num_cmd_success;
46527 unsigned long last_rsrc_error_time;
46528 unsigned long last_ramp_down_time;
46529 unsigned long last_ramp_up_time;
46530@@ -902,7 +902,7 @@ struct lpfc_hba {
46531
46532 struct dentry *debug_slow_ring_trc;
46533 struct lpfc_debugfs_trc *slow_ring_trc;
46534- atomic_t slow_ring_trc_cnt;
46535+ atomic_unchecked_t slow_ring_trc_cnt;
46536 /* iDiag debugfs sub-directory */
46537 struct dentry *idiag_root;
46538 struct dentry *idiag_pci_cfg;
46539diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46540index 60084e6..0e2e700 100644
46541--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46542+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46543@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46544
46545 #include <linux/debugfs.h>
46546
46547-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46548+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46549 static unsigned long lpfc_debugfs_start_time = 0L;
46550
46551 /* iDiag */
46552@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46553 lpfc_debugfs_enable = 0;
46554
46555 len = 0;
46556- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46557+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46558 (lpfc_debugfs_max_disc_trc - 1);
46559 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46560 dtp = vport->disc_trc + i;
46561@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46562 lpfc_debugfs_enable = 0;
46563
46564 len = 0;
46565- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46566+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46567 (lpfc_debugfs_max_slow_ring_trc - 1);
46568 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46569 dtp = phba->slow_ring_trc + i;
46570@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46571 !vport || !vport->disc_trc)
46572 return;
46573
46574- index = atomic_inc_return(&vport->disc_trc_cnt) &
46575+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46576 (lpfc_debugfs_max_disc_trc - 1);
46577 dtp = vport->disc_trc + index;
46578 dtp->fmt = fmt;
46579 dtp->data1 = data1;
46580 dtp->data2 = data2;
46581 dtp->data3 = data3;
46582- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46583+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46584 dtp->jif = jiffies;
46585 #endif
46586 return;
46587@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46588 !phba || !phba->slow_ring_trc)
46589 return;
46590
46591- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46592+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46593 (lpfc_debugfs_max_slow_ring_trc - 1);
46594 dtp = phba->slow_ring_trc + index;
46595 dtp->fmt = fmt;
46596 dtp->data1 = data1;
46597 dtp->data2 = data2;
46598 dtp->data3 = data3;
46599- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46600+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46601 dtp->jif = jiffies;
46602 #endif
46603 return;
46604@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46605 "slow_ring buffer\n");
46606 goto debug_failed;
46607 }
46608- atomic_set(&phba->slow_ring_trc_cnt, 0);
46609+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46610 memset(phba->slow_ring_trc, 0,
46611 (sizeof(struct lpfc_debugfs_trc) *
46612 lpfc_debugfs_max_slow_ring_trc));
46613@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46614 "buffer\n");
46615 goto debug_failed;
46616 }
46617- atomic_set(&vport->disc_trc_cnt, 0);
46618+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46619
46620 snprintf(name, sizeof(name), "discovery_trace");
46621 vport->debug_disc_trc =
46622diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46623index e0b20fa..30c2c0d 100644
46624--- a/drivers/scsi/lpfc/lpfc_init.c
46625+++ b/drivers/scsi/lpfc/lpfc_init.c
46626@@ -10936,8 +10936,10 @@ lpfc_init(void)
46627 "misc_register returned with status %d", error);
46628
46629 if (lpfc_enable_npiv) {
46630- lpfc_transport_functions.vport_create = lpfc_vport_create;
46631- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46632+ pax_open_kernel();
46633+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46634+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46635+ pax_close_kernel();
46636 }
46637 lpfc_transport_template =
46638 fc_attach_transport(&lpfc_transport_functions);
46639diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46640index 243de1d..f40e3e5 100644
46641--- a/drivers/scsi/lpfc/lpfc_scsi.c
46642+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46643@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46644 uint32_t evt_posted;
46645
46646 spin_lock_irqsave(&phba->hbalock, flags);
46647- atomic_inc(&phba->num_rsrc_err);
46648+ atomic_inc_unchecked(&phba->num_rsrc_err);
46649 phba->last_rsrc_error_time = jiffies;
46650
46651 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46652@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46653 unsigned long flags;
46654 struct lpfc_hba *phba = vport->phba;
46655 uint32_t evt_posted;
46656- atomic_inc(&phba->num_cmd_success);
46657+ atomic_inc_unchecked(&phba->num_cmd_success);
46658
46659 if (vport->cfg_lun_queue_depth <= queue_depth)
46660 return;
46661@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46662 unsigned long num_rsrc_err, num_cmd_success;
46663 int i;
46664
46665- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46666- num_cmd_success = atomic_read(&phba->num_cmd_success);
46667+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46668+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46669
46670 /*
46671 * The error and success command counters are global per
46672@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46673 }
46674 }
46675 lpfc_destroy_vport_work_array(phba, vports);
46676- atomic_set(&phba->num_rsrc_err, 0);
46677- atomic_set(&phba->num_cmd_success, 0);
46678+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46679+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46680 }
46681
46682 /**
46683@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46684 }
46685 }
46686 lpfc_destroy_vport_work_array(phba, vports);
46687- atomic_set(&phba->num_rsrc_err, 0);
46688- atomic_set(&phba->num_cmd_success, 0);
46689+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46690+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46691 }
46692
46693 /**
46694diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46695index 1eb7b028..b2a6080 100644
46696--- a/drivers/scsi/pmcraid.c
46697+++ b/drivers/scsi/pmcraid.c
46698@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46699 res->scsi_dev = scsi_dev;
46700 scsi_dev->hostdata = res;
46701 res->change_detected = 0;
46702- atomic_set(&res->read_failures, 0);
46703- atomic_set(&res->write_failures, 0);
46704+ atomic_set_unchecked(&res->read_failures, 0);
46705+ atomic_set_unchecked(&res->write_failures, 0);
46706 rc = 0;
46707 }
46708 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46709@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46710
46711 /* If this was a SCSI read/write command keep count of errors */
46712 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46713- atomic_inc(&res->read_failures);
46714+ atomic_inc_unchecked(&res->read_failures);
46715 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46716- atomic_inc(&res->write_failures);
46717+ atomic_inc_unchecked(&res->write_failures);
46718
46719 if (!RES_IS_GSCSI(res->cfg_entry) &&
46720 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46721@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46722 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46723 * hrrq_id assigned here in queuecommand
46724 */
46725- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46726+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46727 pinstance->num_hrrq;
46728 cmd->cmd_done = pmcraid_io_done;
46729
46730@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46731 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46732 * hrrq_id assigned here in queuecommand
46733 */
46734- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46735+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46736 pinstance->num_hrrq;
46737
46738 if (request_size) {
46739@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46740
46741 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46742 /* add resources only after host is added into system */
46743- if (!atomic_read(&pinstance->expose_resources))
46744+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46745 return;
46746
46747 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46748@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46749 init_waitqueue_head(&pinstance->reset_wait_q);
46750
46751 atomic_set(&pinstance->outstanding_cmds, 0);
46752- atomic_set(&pinstance->last_message_id, 0);
46753- atomic_set(&pinstance->expose_resources, 0);
46754+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46755+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46756
46757 INIT_LIST_HEAD(&pinstance->free_res_q);
46758 INIT_LIST_HEAD(&pinstance->used_res_q);
46759@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46760 /* Schedule worker thread to handle CCN and take care of adding and
46761 * removing devices to OS
46762 */
46763- atomic_set(&pinstance->expose_resources, 1);
46764+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46765 schedule_work(&pinstance->worker_q);
46766 return rc;
46767
46768diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46769index e1d150f..6c6df44 100644
46770--- a/drivers/scsi/pmcraid.h
46771+++ b/drivers/scsi/pmcraid.h
46772@@ -748,7 +748,7 @@ struct pmcraid_instance {
46773 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46774
46775 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46776- atomic_t last_message_id;
46777+ atomic_unchecked_t last_message_id;
46778
46779 /* configuration table */
46780 struct pmcraid_config_table *cfg_table;
46781@@ -777,7 +777,7 @@ struct pmcraid_instance {
46782 atomic_t outstanding_cmds;
46783
46784 /* should add/delete resources to mid-layer now ?*/
46785- atomic_t expose_resources;
46786+ atomic_unchecked_t expose_resources;
46787
46788
46789
46790@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46791 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46792 };
46793 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46794- atomic_t read_failures; /* count of failed READ commands */
46795- atomic_t write_failures; /* count of failed WRITE commands */
46796+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46797+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46798
46799 /* To indicate add/delete/modify during CCN */
46800 u8 change_detected;
46801diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46802index d7a99ae..801df70 100644
46803--- a/drivers/scsi/qla2xxx/qla_attr.c
46804+++ b/drivers/scsi/qla2xxx/qla_attr.c
46805@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46806 return 0;
46807 }
46808
46809-struct fc_function_template qla2xxx_transport_functions = {
46810+fc_function_template_no_const qla2xxx_transport_functions = {
46811
46812 .show_host_node_name = 1,
46813 .show_host_port_name = 1,
46814@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46815 .bsg_timeout = qla24xx_bsg_timeout,
46816 };
46817
46818-struct fc_function_template qla2xxx_transport_vport_functions = {
46819+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46820
46821 .show_host_node_name = 1,
46822 .show_host_port_name = 1,
46823diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46824index 2d98232..a84298e 100644
46825--- a/drivers/scsi/qla2xxx/qla_gbl.h
46826+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46827@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46828 struct device_attribute;
46829 extern struct device_attribute *qla2x00_host_attrs[];
46830 struct fc_function_template;
46831-extern struct fc_function_template qla2xxx_transport_functions;
46832-extern struct fc_function_template qla2xxx_transport_vport_functions;
46833+extern fc_function_template_no_const qla2xxx_transport_functions;
46834+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46835 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46836 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46837 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46838diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46839index 3e21e9f..426ba79 100644
46840--- a/drivers/scsi/qla2xxx/qla_os.c
46841+++ b/drivers/scsi/qla2xxx/qla_os.c
46842@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46843 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46844 /* Ok, a 64bit DMA mask is applicable. */
46845 ha->flags.enable_64bit_addressing = 1;
46846- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46847- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46848+ pax_open_kernel();
46849+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46850+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46851+ pax_close_kernel();
46852 return;
46853 }
46854 }
46855diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46856index ddf16a8..80f4dd0 100644
46857--- a/drivers/scsi/qla4xxx/ql4_def.h
46858+++ b/drivers/scsi/qla4xxx/ql4_def.h
46859@@ -291,7 +291,7 @@ struct ddb_entry {
46860 * (4000 only) */
46861 atomic_t relogin_timer; /* Max Time to wait for
46862 * relogin to complete */
46863- atomic_t relogin_retry_count; /* Num of times relogin has been
46864+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46865 * retried */
46866 uint32_t default_time2wait; /* Default Min time between
46867 * relogins (+aens) */
46868diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46869index b246b3c..897004d 100644
46870--- a/drivers/scsi/qla4xxx/ql4_os.c
46871+++ b/drivers/scsi/qla4xxx/ql4_os.c
46872@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46873 */
46874 if (!iscsi_is_session_online(cls_sess)) {
46875 /* Reset retry relogin timer */
46876- atomic_inc(&ddb_entry->relogin_retry_count);
46877+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46878 DEBUG2(ql4_printk(KERN_INFO, ha,
46879 "%s: index[%d] relogin timed out-retrying"
46880 " relogin (%d), retry (%d)\n", __func__,
46881 ddb_entry->fw_ddb_index,
46882- atomic_read(&ddb_entry->relogin_retry_count),
46883+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46884 ddb_entry->default_time2wait + 4));
46885 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46886 atomic_set(&ddb_entry->retry_relogin_timer,
46887@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46888
46889 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46890 atomic_set(&ddb_entry->relogin_timer, 0);
46891- atomic_set(&ddb_entry->relogin_retry_count, 0);
46892+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46893 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46894 ddb_entry->default_relogin_timeout =
46895 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46896diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46897index eaa808e..95f8841 100644
46898--- a/drivers/scsi/scsi.c
46899+++ b/drivers/scsi/scsi.c
46900@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46901 unsigned long timeout;
46902 int rtn = 0;
46903
46904- atomic_inc(&cmd->device->iorequest_cnt);
46905+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46906
46907 /* check if the device is still usable */
46908 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46909diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46910index 124392f..75eb43e 100644
46911--- a/drivers/scsi/scsi_lib.c
46912+++ b/drivers/scsi/scsi_lib.c
46913@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46914 shost = sdev->host;
46915 scsi_init_cmd_errh(cmd);
46916 cmd->result = DID_NO_CONNECT << 16;
46917- atomic_inc(&cmd->device->iorequest_cnt);
46918+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46919
46920 /*
46921 * SCSI request completion path will do scsi_device_unbusy(),
46922@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46923
46924 INIT_LIST_HEAD(&cmd->eh_entry);
46925
46926- atomic_inc(&cmd->device->iodone_cnt);
46927+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46928 if (cmd->result)
46929- atomic_inc(&cmd->device->ioerr_cnt);
46930+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46931
46932 disposition = scsi_decide_disposition(cmd);
46933 if (disposition != SUCCESS &&
46934diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46935index 7e50061..71db7a6 100644
46936--- a/drivers/scsi/scsi_sysfs.c
46937+++ b/drivers/scsi/scsi_sysfs.c
46938@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46939 char *buf) \
46940 { \
46941 struct scsi_device *sdev = to_scsi_device(dev); \
46942- unsigned long long count = atomic_read(&sdev->field); \
46943+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46944 return snprintf(buf, 20, "0x%llx\n", count); \
46945 } \
46946 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46947diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46948index 84a1fdf..693b0d6 100644
46949--- a/drivers/scsi/scsi_tgt_lib.c
46950+++ b/drivers/scsi/scsi_tgt_lib.c
46951@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46952 int err;
46953
46954 dprintk("%lx %u\n", uaddr, len);
46955- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46956+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46957 if (err) {
46958 /*
46959 * TODO: need to fixup sg_tablesize, max_segment_size,
46960diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46961index 4628fd5..a94a1c2 100644
46962--- a/drivers/scsi/scsi_transport_fc.c
46963+++ b/drivers/scsi/scsi_transport_fc.c
46964@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46965 * Netlink Infrastructure
46966 */
46967
46968-static atomic_t fc_event_seq;
46969+static atomic_unchecked_t fc_event_seq;
46970
46971 /**
46972 * fc_get_event_number - Obtain the next sequential FC event number
46973@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46974 u32
46975 fc_get_event_number(void)
46976 {
46977- return atomic_add_return(1, &fc_event_seq);
46978+ return atomic_add_return_unchecked(1, &fc_event_seq);
46979 }
46980 EXPORT_SYMBOL(fc_get_event_number);
46981
46982@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46983 {
46984 int error;
46985
46986- atomic_set(&fc_event_seq, 0);
46987+ atomic_set_unchecked(&fc_event_seq, 0);
46988
46989 error = transport_class_register(&fc_host_class);
46990 if (error)
46991@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46992 char *cp;
46993
46994 *val = simple_strtoul(buf, &cp, 0);
46995- if ((*cp && (*cp != '\n')) || (*val < 0))
46996+ if (*cp && (*cp != '\n'))
46997 return -EINVAL;
46998 /*
46999 * Check for overflow; dev_loss_tmo is u32
47000diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47001index abf7c40..c3240ed 100644
47002--- a/drivers/scsi/scsi_transport_iscsi.c
47003+++ b/drivers/scsi/scsi_transport_iscsi.c
47004@@ -80,7 +80,7 @@ struct iscsi_internal {
47005 struct transport_container session_cont;
47006 };
47007
47008-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47009+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47010 static struct workqueue_struct *iscsi_eh_timer_workq;
47011
47012 static DEFINE_IDA(iscsi_sess_ida);
47013@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47014 int err;
47015
47016 ihost = shost->shost_data;
47017- session->sid = atomic_add_return(1, &iscsi_session_nr);
47018+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47019
47020 if (target_id == ISCSI_MAX_TARGET) {
47021 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47022@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47023 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47024 ISCSI_TRANSPORT_VERSION);
47025
47026- atomic_set(&iscsi_session_nr, 0);
47027+ atomic_set_unchecked(&iscsi_session_nr, 0);
47028
47029 err = class_register(&iscsi_transport_class);
47030 if (err)
47031diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47032index f379c7f..e8fc69c 100644
47033--- a/drivers/scsi/scsi_transport_srp.c
47034+++ b/drivers/scsi/scsi_transport_srp.c
47035@@ -33,7 +33,7 @@
47036 #include "scsi_transport_srp_internal.h"
47037
47038 struct srp_host_attrs {
47039- atomic_t next_port_id;
47040+ atomic_unchecked_t next_port_id;
47041 };
47042 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47043
47044@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47045 struct Scsi_Host *shost = dev_to_shost(dev);
47046 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47047
47048- atomic_set(&srp_host->next_port_id, 0);
47049+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47050 return 0;
47051 }
47052
47053@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47054 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47055 rport->roles = ids->roles;
47056
47057- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47058+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47059 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47060
47061 transport_setup_device(&rport->dev);
47062diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47063index 2783dd7..d20395b 100644
47064--- a/drivers/scsi/sd.c
47065+++ b/drivers/scsi/sd.c
47066@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
47067 sdkp->disk = gd;
47068 sdkp->index = index;
47069 atomic_set(&sdkp->openers, 0);
47070- atomic_set(&sdkp->device->ioerr_cnt, 0);
47071+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47072
47073 if (!sdp->request_queue->rq_timeout) {
47074 if (sdp->type != TYPE_MOD)
47075diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47076index df5e961..df6b97f 100644
47077--- a/drivers/scsi/sg.c
47078+++ b/drivers/scsi/sg.c
47079@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47080 sdp->disk->disk_name,
47081 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47082 NULL,
47083- (char *)arg);
47084+ (char __user *)arg);
47085 case BLKTRACESTART:
47086 return blk_trace_startstop(sdp->device->request_queue, 1);
47087 case BLKTRACESTOP:
47088diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47089index 978dda2..cb19aa0 100644
47090--- a/drivers/spi/spi.c
47091+++ b/drivers/spi/spi.c
47092@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47093 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47094
47095 /* portable code must never pass more than 32 bytes */
47096-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47097+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47098
47099 static u8 *buf;
47100
47101diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47102index ee3a57f..18368c1 100644
47103--- a/drivers/staging/android/timed_output.c
47104+++ b/drivers/staging/android/timed_output.c
47105@@ -25,7 +25,7 @@
47106 #include "timed_output.h"
47107
47108 static struct class *timed_output_class;
47109-static atomic_t device_count;
47110+static atomic_unchecked_t device_count;
47111
47112 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47113 char *buf)
47114@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47115 timed_output_class = class_create(THIS_MODULE, "timed_output");
47116 if (IS_ERR(timed_output_class))
47117 return PTR_ERR(timed_output_class);
47118- atomic_set(&device_count, 0);
47119+ atomic_set_unchecked(&device_count, 0);
47120 }
47121
47122 return 0;
47123@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47124 if (ret < 0)
47125 return ret;
47126
47127- tdev->index = atomic_inc_return(&device_count);
47128+ tdev->index = atomic_inc_return_unchecked(&device_count);
47129 tdev->dev = device_create(timed_output_class, NULL,
47130 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47131 if (IS_ERR(tdev->dev))
47132diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47133index 3675020..e80d92c 100644
47134--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47135+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47136@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47137
47138 static int solo_sysfs_init(struct solo_dev *solo_dev)
47139 {
47140- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47141+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47142 struct device *dev = &solo_dev->dev;
47143 const char *driver;
47144 int i;
47145diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47146index 3335941..2b26186 100644
47147--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47148+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47149@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47150
47151 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47152 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47153- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47154+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47155 if (p2m_id < 0)
47156 p2m_id = -p2m_id;
47157 }
47158diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47159index 6f91d2e..3f011d2 100644
47160--- a/drivers/staging/media/solo6x10/solo6x10.h
47161+++ b/drivers/staging/media/solo6x10/solo6x10.h
47162@@ -238,7 +238,7 @@ struct solo_dev {
47163
47164 /* P2M DMA Engine */
47165 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47166- atomic_t p2m_count;
47167+ atomic_unchecked_t p2m_count;
47168 int p2m_jiffies;
47169 unsigned int p2m_timeouts;
47170
47171diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47172index 34afc16..ffe44dd 100644
47173--- a/drivers/staging/octeon/ethernet-rx.c
47174+++ b/drivers/staging/octeon/ethernet-rx.c
47175@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47176 /* Increment RX stats for virtual ports */
47177 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47178 #ifdef CONFIG_64BIT
47179- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47180- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47181+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47182+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47183 #else
47184- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47185- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47186+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47187+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47188 #endif
47189 }
47190 netif_receive_skb(skb);
47191@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47192 dev->name);
47193 */
47194 #ifdef CONFIG_64BIT
47195- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47196+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47197 #else
47198- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47199+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47200 #endif
47201 dev_kfree_skb_irq(skb);
47202 }
47203diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47204index c3a90e7..023619a 100644
47205--- a/drivers/staging/octeon/ethernet.c
47206+++ b/drivers/staging/octeon/ethernet.c
47207@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47208 * since the RX tasklet also increments it.
47209 */
47210 #ifdef CONFIG_64BIT
47211- atomic64_add(rx_status.dropped_packets,
47212- (atomic64_t *)&priv->stats.rx_dropped);
47213+ atomic64_add_unchecked(rx_status.dropped_packets,
47214+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47215 #else
47216- atomic_add(rx_status.dropped_packets,
47217- (atomic_t *)&priv->stats.rx_dropped);
47218+ atomic_add_unchecked(rx_status.dropped_packets,
47219+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47220 #endif
47221 }
47222
47223diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47224index dc23395..cf7e9b1 100644
47225--- a/drivers/staging/rtl8712/rtl871x_io.h
47226+++ b/drivers/staging/rtl8712/rtl871x_io.h
47227@@ -108,7 +108,7 @@ struct _io_ops {
47228 u8 *pmem);
47229 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47230 u8 *pmem);
47231-};
47232+} __no_const;
47233
47234 struct io_req {
47235 struct list_head list;
47236diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47237index 1f5088b..0e59820 100644
47238--- a/drivers/staging/sbe-2t3e3/netdev.c
47239+++ b/drivers/staging/sbe-2t3e3/netdev.c
47240@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47241 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47242
47243 if (rlen)
47244- if (copy_to_user(data, &resp, rlen))
47245+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47246 return -EFAULT;
47247
47248 return 0;
47249diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47250index a863a98..d272795 100644
47251--- a/drivers/staging/usbip/vhci.h
47252+++ b/drivers/staging/usbip/vhci.h
47253@@ -83,7 +83,7 @@ struct vhci_hcd {
47254 unsigned resuming:1;
47255 unsigned long re_timeout;
47256
47257- atomic_t seqnum;
47258+ atomic_unchecked_t seqnum;
47259
47260 /*
47261 * NOTE:
47262diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47263index d7974cb..d78076b 100644
47264--- a/drivers/staging/usbip/vhci_hcd.c
47265+++ b/drivers/staging/usbip/vhci_hcd.c
47266@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47267
47268 spin_lock(&vdev->priv_lock);
47269
47270- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47271+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47272 if (priv->seqnum == 0xffff)
47273 dev_info(&urb->dev->dev, "seqnum max\n");
47274
47275@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47276 return -ENOMEM;
47277 }
47278
47279- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47280+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47281 if (unlink->seqnum == 0xffff)
47282 pr_info("seqnum max\n");
47283
47284@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47285 vdev->rhport = rhport;
47286 }
47287
47288- atomic_set(&vhci->seqnum, 0);
47289+ atomic_set_unchecked(&vhci->seqnum, 0);
47290 spin_lock_init(&vhci->lock);
47291
47292 hcd->power_budget = 0; /* no limit */
47293diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47294index d07fcb5..358e1e1 100644
47295--- a/drivers/staging/usbip/vhci_rx.c
47296+++ b/drivers/staging/usbip/vhci_rx.c
47297@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47298 if (!urb) {
47299 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47300 pr_info("max seqnum %d\n",
47301- atomic_read(&the_controller->seqnum));
47302+ atomic_read_unchecked(&the_controller->seqnum));
47303 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47304 return;
47305 }
47306diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47307index 57a08c5..5b4bb7c 100644
47308--- a/drivers/staging/vt6655/hostap.c
47309+++ b/drivers/staging/vt6655/hostap.c
47310@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47311 *
47312 */
47313
47314+static net_device_ops_no_const apdev_netdev_ops;
47315+
47316 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47317 {
47318 PSDevice apdev_priv;
47319 struct net_device *dev = pDevice->dev;
47320 int ret;
47321- const struct net_device_ops apdev_netdev_ops = {
47322- .ndo_start_xmit = pDevice->tx_80211,
47323- };
47324
47325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47326
47327@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47328 *apdev_priv = *pDevice;
47329 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47330
47331+ /* only half broken now */
47332+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47333 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47334
47335 pDevice->apdev->type = ARPHRD_IEEE80211;
47336diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47337index c699a30..b90a5fd 100644
47338--- a/drivers/staging/vt6656/hostap.c
47339+++ b/drivers/staging/vt6656/hostap.c
47340@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47341 *
47342 */
47343
47344+static net_device_ops_no_const apdev_netdev_ops;
47345+
47346 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47347 {
47348 struct vnt_private *apdev_priv;
47349 struct net_device *dev = pDevice->dev;
47350 int ret;
47351- const struct net_device_ops apdev_netdev_ops = {
47352- .ndo_start_xmit = pDevice->tx_80211,
47353- };
47354
47355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47356
47357@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47358 *apdev_priv = *pDevice;
47359 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47360
47361+ /* only half broken now */
47362+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47363 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47364
47365 pDevice->apdev->type = ARPHRD_IEEE80211;
47366diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47367index d128ce2..fc1f9a1 100644
47368--- a/drivers/staging/zcache/tmem.h
47369+++ b/drivers/staging/zcache/tmem.h
47370@@ -225,7 +225,7 @@ struct tmem_pamops {
47371 bool (*is_remote)(void *);
47372 int (*replace_in_obj)(void *, struct tmem_obj *);
47373 #endif
47374-};
47375+} __no_const;
47376 extern void tmem_register_pamops(struct tmem_pamops *m);
47377
47378 /* memory allocation methods provided by the host implementation */
47379@@ -234,7 +234,7 @@ struct tmem_hostops {
47380 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47381 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47382 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47383-};
47384+} __no_const;
47385 extern void tmem_register_hostops(struct tmem_hostops *m);
47386
47387 /* core tmem accessor functions */
47388diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47389index e51b09a..5ebac31 100644
47390--- a/drivers/target/sbp/sbp_target.c
47391+++ b/drivers/target/sbp/sbp_target.c
47392@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47393
47394 #define SESSION_MAINTENANCE_INTERVAL HZ
47395
47396-static atomic_t login_id = ATOMIC_INIT(0);
47397+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47398
47399 static void session_maintenance_work(struct work_struct *);
47400 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47401@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47402 login->lun = se_lun;
47403 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47404 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47405- login->login_id = atomic_inc_return(&login_id);
47406+ login->login_id = atomic_inc_return_unchecked(&login_id);
47407
47408 login->tgt_agt = sbp_target_agent_register(login);
47409 if (IS_ERR(login->tgt_agt)) {
47410diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47411index 8f4142f..b127f7d 100644
47412--- a/drivers/target/target_core_device.c
47413+++ b/drivers/target/target_core_device.c
47414@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47415 spin_lock_init(&dev->se_port_lock);
47416 spin_lock_init(&dev->se_tmr_lock);
47417 spin_lock_init(&dev->qf_cmd_lock);
47418- atomic_set(&dev->dev_ordered_id, 0);
47419+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47420 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47421 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47422 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47423diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47424index d8e49d7..6fcfdec 100644
47425--- a/drivers/target/target_core_transport.c
47426+++ b/drivers/target/target_core_transport.c
47427@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47428 * Used to determine when ORDERED commands should go from
47429 * Dormant to Active status.
47430 */
47431- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47432+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47433 smp_mb__after_atomic_inc();
47434 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47435 cmd->se_ordered_id, cmd->sam_task_attr,
47436diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47437index 33f83fe..d80f8e1 100644
47438--- a/drivers/tty/cyclades.c
47439+++ b/drivers/tty/cyclades.c
47440@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47441 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47442 info->port.count);
47443 #endif
47444- info->port.count++;
47445+ atomic_inc(&info->port.count);
47446 #ifdef CY_DEBUG_COUNT
47447 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47448- current->pid, info->port.count);
47449+ current->pid, atomic_read(&info->port.count));
47450 #endif
47451
47452 /*
47453@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47454 for (j = 0; j < cy_card[i].nports; j++) {
47455 info = &cy_card[i].ports[j];
47456
47457- if (info->port.count) {
47458+ if (atomic_read(&info->port.count)) {
47459 /* XXX is the ldisc num worth this? */
47460 struct tty_struct *tty;
47461 struct tty_ldisc *ld;
47462diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47463index eb255e8..f637a57 100644
47464--- a/drivers/tty/hvc/hvc_console.c
47465+++ b/drivers/tty/hvc/hvc_console.c
47466@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47467
47468 spin_lock_irqsave(&hp->port.lock, flags);
47469 /* Check and then increment for fast path open. */
47470- if (hp->port.count++ > 0) {
47471+ if (atomic_inc_return(&hp->port.count) > 1) {
47472 spin_unlock_irqrestore(&hp->port.lock, flags);
47473 hvc_kick();
47474 return 0;
47475@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47476
47477 spin_lock_irqsave(&hp->port.lock, flags);
47478
47479- if (--hp->port.count == 0) {
47480+ if (atomic_dec_return(&hp->port.count) == 0) {
47481 spin_unlock_irqrestore(&hp->port.lock, flags);
47482 /* We are done with the tty pointer now. */
47483 tty_port_tty_set(&hp->port, NULL);
47484@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47485 */
47486 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47487 } else {
47488- if (hp->port.count < 0)
47489+ if (atomic_read(&hp->port.count) < 0)
47490 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47491- hp->vtermno, hp->port.count);
47492+ hp->vtermno, atomic_read(&hp->port.count));
47493 spin_unlock_irqrestore(&hp->port.lock, flags);
47494 }
47495 }
47496@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47497 * open->hangup case this can be called after the final close so prevent
47498 * that from happening for now.
47499 */
47500- if (hp->port.count <= 0) {
47501+ if (atomic_read(&hp->port.count) <= 0) {
47502 spin_unlock_irqrestore(&hp->port.lock, flags);
47503 return;
47504 }
47505
47506- hp->port.count = 0;
47507+ atomic_set(&hp->port.count, 0);
47508 spin_unlock_irqrestore(&hp->port.lock, flags);
47509 tty_port_tty_set(&hp->port, NULL);
47510
47511@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47512 return -EPIPE;
47513
47514 /* FIXME what's this (unprotected) check for? */
47515- if (hp->port.count <= 0)
47516+ if (atomic_read(&hp->port.count) <= 0)
47517 return -EIO;
47518
47519 spin_lock_irqsave(&hp->lock, flags);
47520diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47521index 81e939e..95ead10 100644
47522--- a/drivers/tty/hvc/hvcs.c
47523+++ b/drivers/tty/hvc/hvcs.c
47524@@ -83,6 +83,7 @@
47525 #include <asm/hvcserver.h>
47526 #include <asm/uaccess.h>
47527 #include <asm/vio.h>
47528+#include <asm/local.h>
47529
47530 /*
47531 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47532@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47533
47534 spin_lock_irqsave(&hvcsd->lock, flags);
47535
47536- if (hvcsd->port.count > 0) {
47537+ if (atomic_read(&hvcsd->port.count) > 0) {
47538 spin_unlock_irqrestore(&hvcsd->lock, flags);
47539 printk(KERN_INFO "HVCS: vterm state unchanged. "
47540 "The hvcs device node is still in use.\n");
47541@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47542 }
47543 }
47544
47545- hvcsd->port.count = 0;
47546+ atomic_set(&hvcsd->port.count, 0);
47547 hvcsd->port.tty = tty;
47548 tty->driver_data = hvcsd;
47549
47550@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47551 unsigned long flags;
47552
47553 spin_lock_irqsave(&hvcsd->lock, flags);
47554- hvcsd->port.count++;
47555+ atomic_inc(&hvcsd->port.count);
47556 hvcsd->todo_mask |= HVCS_SCHED_READ;
47557 spin_unlock_irqrestore(&hvcsd->lock, flags);
47558
47559@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47560 hvcsd = tty->driver_data;
47561
47562 spin_lock_irqsave(&hvcsd->lock, flags);
47563- if (--hvcsd->port.count == 0) {
47564+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47565
47566 vio_disable_interrupts(hvcsd->vdev);
47567
47568@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47569
47570 free_irq(irq, hvcsd);
47571 return;
47572- } else if (hvcsd->port.count < 0) {
47573+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47574 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47575 " is missmanaged.\n",
47576- hvcsd->vdev->unit_address, hvcsd->port.count);
47577+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47578 }
47579
47580 spin_unlock_irqrestore(&hvcsd->lock, flags);
47581@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47582
47583 spin_lock_irqsave(&hvcsd->lock, flags);
47584 /* Preserve this so that we know how many kref refs to put */
47585- temp_open_count = hvcsd->port.count;
47586+ temp_open_count = atomic_read(&hvcsd->port.count);
47587
47588 /*
47589 * Don't kref put inside the spinlock because the destruction
47590@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47591 tty->driver_data = NULL;
47592 hvcsd->port.tty = NULL;
47593
47594- hvcsd->port.count = 0;
47595+ atomic_set(&hvcsd->port.count, 0);
47596
47597 /* This will drop any buffered data on the floor which is OK in a hangup
47598 * scenario. */
47599@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47600 * the middle of a write operation? This is a crummy place to do this
47601 * but we want to keep it all in the spinlock.
47602 */
47603- if (hvcsd->port.count <= 0) {
47604+ if (atomic_read(&hvcsd->port.count) <= 0) {
47605 spin_unlock_irqrestore(&hvcsd->lock, flags);
47606 return -ENODEV;
47607 }
47608@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47609 {
47610 struct hvcs_struct *hvcsd = tty->driver_data;
47611
47612- if (!hvcsd || hvcsd->port.count <= 0)
47613+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47614 return 0;
47615
47616 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47617diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47618index 4190199..48f2920 100644
47619--- a/drivers/tty/hvc/hvsi.c
47620+++ b/drivers/tty/hvc/hvsi.c
47621@@ -85,7 +85,7 @@ struct hvsi_struct {
47622 int n_outbuf;
47623 uint32_t vtermno;
47624 uint32_t virq;
47625- atomic_t seqno; /* HVSI packet sequence number */
47626+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47627 uint16_t mctrl;
47628 uint8_t state; /* HVSI protocol state */
47629 uint8_t flags;
47630@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47631
47632 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47633 packet.hdr.len = sizeof(struct hvsi_query_response);
47634- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47635+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47636 packet.verb = VSV_SEND_VERSION_NUMBER;
47637 packet.u.version = HVSI_VERSION;
47638 packet.query_seqno = query_seqno+1;
47639@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47640
47641 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47642 packet.hdr.len = sizeof(struct hvsi_query);
47643- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47644+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47645 packet.verb = verb;
47646
47647 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47648@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47649 int wrote;
47650
47651 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47652- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47653+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47654 packet.hdr.len = sizeof(struct hvsi_control);
47655 packet.verb = VSV_SET_MODEM_CTL;
47656 packet.mask = HVSI_TSDTR;
47657@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47658 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47659
47660 packet.hdr.type = VS_DATA_PACKET_HEADER;
47661- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47662+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47663 packet.hdr.len = count + sizeof(struct hvsi_header);
47664 memcpy(&packet.data, buf, count);
47665
47666@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47667 struct hvsi_control packet __ALIGNED__;
47668
47669 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47670- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47671+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47672 packet.hdr.len = 6;
47673 packet.verb = VSV_CLOSE_PROTOCOL;
47674
47675diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47676index ac27671..0f627ee 100644
47677--- a/drivers/tty/hvc/hvsi_lib.c
47678+++ b/drivers/tty/hvc/hvsi_lib.c
47679@@ -9,7 +9,7 @@
47680
47681 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47682 {
47683- packet->seqno = atomic_inc_return(&pv->seqno);
47684+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47685
47686 /* Assumes that always succeeds, works in practice */
47687 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47688@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47689
47690 /* Reset state */
47691 pv->established = 0;
47692- atomic_set(&pv->seqno, 0);
47693+ atomic_set_unchecked(&pv->seqno, 0);
47694
47695 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47696
47697@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47698 pv->mctrl_update = 0;
47699 q.hdr.type = VS_QUERY_PACKET_HEADER;
47700 q.hdr.len = sizeof(struct hvsi_query);
47701- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47702+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47703 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47704 rc = hvsi_send_packet(pv, &q.hdr);
47705 if (rc <= 0) {
47706diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47707index 8fd72ff..34a0bed 100644
47708--- a/drivers/tty/ipwireless/tty.c
47709+++ b/drivers/tty/ipwireless/tty.c
47710@@ -29,6 +29,7 @@
47711 #include <linux/tty_driver.h>
47712 #include <linux/tty_flip.h>
47713 #include <linux/uaccess.h>
47714+#include <asm/local.h>
47715
47716 #include "tty.h"
47717 #include "network.h"
47718@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47719 mutex_unlock(&tty->ipw_tty_mutex);
47720 return -ENODEV;
47721 }
47722- if (tty->port.count == 0)
47723+ if (atomic_read(&tty->port.count) == 0)
47724 tty->tx_bytes_queued = 0;
47725
47726- tty->port.count++;
47727+ atomic_inc(&tty->port.count);
47728
47729 tty->port.tty = linux_tty;
47730 linux_tty->driver_data = tty;
47731@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47732
47733 static void do_ipw_close(struct ipw_tty *tty)
47734 {
47735- tty->port.count--;
47736-
47737- if (tty->port.count == 0) {
47738+ if (atomic_dec_return(&tty->port.count) == 0) {
47739 struct tty_struct *linux_tty = tty->port.tty;
47740
47741 if (linux_tty != NULL) {
47742@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47743 return;
47744
47745 mutex_lock(&tty->ipw_tty_mutex);
47746- if (tty->port.count == 0) {
47747+ if (atomic_read(&tty->port.count) == 0) {
47748 mutex_unlock(&tty->ipw_tty_mutex);
47749 return;
47750 }
47751@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47752
47753 mutex_lock(&tty->ipw_tty_mutex);
47754
47755- if (!tty->port.count) {
47756+ if (!atomic_read(&tty->port.count)) {
47757 mutex_unlock(&tty->ipw_tty_mutex);
47758 return;
47759 }
47760@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47761 return -ENODEV;
47762
47763 mutex_lock(&tty->ipw_tty_mutex);
47764- if (!tty->port.count) {
47765+ if (!atomic_read(&tty->port.count)) {
47766 mutex_unlock(&tty->ipw_tty_mutex);
47767 return -EINVAL;
47768 }
47769@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47770 if (!tty)
47771 return -ENODEV;
47772
47773- if (!tty->port.count)
47774+ if (!atomic_read(&tty->port.count))
47775 return -EINVAL;
47776
47777 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47778@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47779 if (!tty)
47780 return 0;
47781
47782- if (!tty->port.count)
47783+ if (!atomic_read(&tty->port.count))
47784 return 0;
47785
47786 return tty->tx_bytes_queued;
47787@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47788 if (!tty)
47789 return -ENODEV;
47790
47791- if (!tty->port.count)
47792+ if (!atomic_read(&tty->port.count))
47793 return -EINVAL;
47794
47795 return get_control_lines(tty);
47796@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47797 if (!tty)
47798 return -ENODEV;
47799
47800- if (!tty->port.count)
47801+ if (!atomic_read(&tty->port.count))
47802 return -EINVAL;
47803
47804 return set_control_lines(tty, set, clear);
47805@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47806 if (!tty)
47807 return -ENODEV;
47808
47809- if (!tty->port.count)
47810+ if (!atomic_read(&tty->port.count))
47811 return -EINVAL;
47812
47813 /* FIXME: Exactly how is the tty object locked here .. */
47814@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47815 * are gone */
47816 mutex_lock(&ttyj->ipw_tty_mutex);
47817 }
47818- while (ttyj->port.count)
47819+ while (atomic_read(&ttyj->port.count))
47820 do_ipw_close(ttyj);
47821 ipwireless_disassociate_network_ttys(network,
47822 ttyj->channel_idx);
47823diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47824index 1deaca4..c8582d4 100644
47825--- a/drivers/tty/moxa.c
47826+++ b/drivers/tty/moxa.c
47827@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47828 }
47829
47830 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47831- ch->port.count++;
47832+ atomic_inc(&ch->port.count);
47833 tty->driver_data = ch;
47834 tty_port_tty_set(&ch->port, tty);
47835 mutex_lock(&ch->port.mutex);
47836diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47837index 6422390..49003ac8 100644
47838--- a/drivers/tty/n_gsm.c
47839+++ b/drivers/tty/n_gsm.c
47840@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47841 spin_lock_init(&dlci->lock);
47842 mutex_init(&dlci->mutex);
47843 dlci->fifo = &dlci->_fifo;
47844- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47845+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47846 kfree(dlci);
47847 return NULL;
47848 }
47849@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47850 struct gsm_dlci *dlci = tty->driver_data;
47851 struct tty_port *port = &dlci->port;
47852
47853- port->count++;
47854+ atomic_inc(&port->count);
47855 dlci_get(dlci);
47856 dlci_get(dlci->gsm->dlci[0]);
47857 mux_get(dlci->gsm);
47858diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47859index 4bf0fc0..433bd58 100644
47860--- a/drivers/tty/n_tty.c
47861+++ b/drivers/tty/n_tty.c
47862@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47863 {
47864 *ops = tty_ldisc_N_TTY;
47865 ops->owner = NULL;
47866- ops->refcount = ops->flags = 0;
47867+ atomic_set(&ops->refcount, 0);
47868+ ops->flags = 0;
47869 }
47870 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47871diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47872index abfd990..5ab5da9 100644
47873--- a/drivers/tty/pty.c
47874+++ b/drivers/tty/pty.c
47875@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47876 panic("Couldn't register Unix98 pts driver");
47877
47878 /* Now create the /dev/ptmx special device */
47879+ pax_open_kernel();
47880 tty_default_fops(&ptmx_fops);
47881- ptmx_fops.open = ptmx_open;
47882+ *(void **)&ptmx_fops.open = ptmx_open;
47883+ pax_close_kernel();
47884
47885 cdev_init(&ptmx_cdev, &ptmx_fops);
47886 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47887diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47888index 354564e..fe50d9a 100644
47889--- a/drivers/tty/rocket.c
47890+++ b/drivers/tty/rocket.c
47891@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47892 tty->driver_data = info;
47893 tty_port_tty_set(port, tty);
47894
47895- if (port->count++ == 0) {
47896+ if (atomic_inc_return(&port->count) == 1) {
47897 atomic_inc(&rp_num_ports_open);
47898
47899 #ifdef ROCKET_DEBUG_OPEN
47900@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47901 #endif
47902 }
47903 #ifdef ROCKET_DEBUG_OPEN
47904- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47905+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47906 #endif
47907
47908 /*
47909@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47910 spin_unlock_irqrestore(&info->port.lock, flags);
47911 return;
47912 }
47913- if (info->port.count)
47914+ if (atomic_read(&info->port.count))
47915 atomic_dec(&rp_num_ports_open);
47916 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47917 spin_unlock_irqrestore(&info->port.lock, flags);
47918diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47919index e2520ab..034e20b 100644
47920--- a/drivers/tty/serial/ioc4_serial.c
47921+++ b/drivers/tty/serial/ioc4_serial.c
47922@@ -437,7 +437,7 @@ struct ioc4_soft {
47923 } is_intr_info[MAX_IOC4_INTR_ENTS];
47924
47925 /* Number of entries active in the above array */
47926- atomic_t is_num_intrs;
47927+ atomic_unchecked_t is_num_intrs;
47928 } is_intr_type[IOC4_NUM_INTR_TYPES];
47929
47930 /* is_ir_lock must be held while
47931@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47932 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47933 || (type == IOC4_OTHER_INTR_TYPE)));
47934
47935- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47936+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47937 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47938
47939 /* Save off the lower level interrupt handler */
47940@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47941
47942 soft = arg;
47943 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47944- num_intrs = (int)atomic_read(
47945+ num_intrs = (int)atomic_read_unchecked(
47946 &soft->is_intr_type[intr_type].is_num_intrs);
47947
47948 this_mir = this_ir = pending_intrs(soft, intr_type);
47949diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47950index 1002054..dd644a8 100644
47951--- a/drivers/tty/serial/kgdboc.c
47952+++ b/drivers/tty/serial/kgdboc.c
47953@@ -24,8 +24,9 @@
47954 #define MAX_CONFIG_LEN 40
47955
47956 static struct kgdb_io kgdboc_io_ops;
47957+static struct kgdb_io kgdboc_io_ops_console;
47958
47959-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47960+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47961 static int configured = -1;
47962
47963 static char config[MAX_CONFIG_LEN];
47964@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47965 kgdboc_unregister_kbd();
47966 if (configured == 1)
47967 kgdb_unregister_io_module(&kgdboc_io_ops);
47968+ else if (configured == 2)
47969+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47970 }
47971
47972 static int configure_kgdboc(void)
47973@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47974 int err;
47975 char *cptr = config;
47976 struct console *cons;
47977+ int is_console = 0;
47978
47979 err = kgdboc_option_setup(config);
47980 if (err || !strlen(config) || isspace(config[0]))
47981 goto noconfig;
47982
47983 err = -ENODEV;
47984- kgdboc_io_ops.is_console = 0;
47985 kgdb_tty_driver = NULL;
47986
47987 kgdboc_use_kms = 0;
47988@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47989 int idx;
47990 if (cons->device && cons->device(cons, &idx) == p &&
47991 idx == tty_line) {
47992- kgdboc_io_ops.is_console = 1;
47993+ is_console = 1;
47994 break;
47995 }
47996 cons = cons->next;
47997@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47998 kgdb_tty_line = tty_line;
47999
48000 do_register:
48001- err = kgdb_register_io_module(&kgdboc_io_ops);
48002+ if (is_console) {
48003+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48004+ configured = 2;
48005+ } else {
48006+ err = kgdb_register_io_module(&kgdboc_io_ops);
48007+ configured = 1;
48008+ }
48009 if (err)
48010 goto noconfig;
48011
48012@@ -205,8 +214,6 @@ do_register:
48013 if (err)
48014 goto nmi_con_failed;
48015
48016- configured = 1;
48017-
48018 return 0;
48019
48020 nmi_con_failed:
48021@@ -223,7 +230,7 @@ noconfig:
48022 static int __init init_kgdboc(void)
48023 {
48024 /* Already configured? */
48025- if (configured == 1)
48026+ if (configured >= 1)
48027 return 0;
48028
48029 return configure_kgdboc();
48030@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48031 if (config[len - 1] == '\n')
48032 config[len - 1] = '\0';
48033
48034- if (configured == 1)
48035+ if (configured >= 1)
48036 cleanup_kgdboc();
48037
48038 /* Go and configure with the new params. */
48039@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48040 .post_exception = kgdboc_post_exp_handler,
48041 };
48042
48043+static struct kgdb_io kgdboc_io_ops_console = {
48044+ .name = "kgdboc",
48045+ .read_char = kgdboc_get_char,
48046+ .write_char = kgdboc_put_char,
48047+ .pre_exception = kgdboc_pre_exp_handler,
48048+ .post_exception = kgdboc_post_exp_handler,
48049+ .is_console = 1
48050+};
48051+
48052 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48053 /* This is only available if kgdboc is a built in for early debugging */
48054 static int __init kgdboc_early_init(char *opt)
48055diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48056index 2c6cfb3..048274e 100644
48057--- a/drivers/tty/serial/msm_serial.c
48058+++ b/drivers/tty/serial/msm_serial.c
48059@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48060 .cons = MSM_CONSOLE,
48061 };
48062
48063-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48064+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48065
48066 static int __init msm_serial_probe(struct platform_device *pdev)
48067 {
48068@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48069 int irq;
48070
48071 if (pdev->id == -1)
48072- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48073+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48074
48075 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48076 return -ENXIO;
48077diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48078index 376079b..d8de7aa 100644
48079--- a/drivers/tty/serial/samsung.c
48080+++ b/drivers/tty/serial/samsung.c
48081@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48082 }
48083 }
48084
48085+static int s3c64xx_serial_startup(struct uart_port *port);
48086 static int s3c24xx_serial_startup(struct uart_port *port)
48087 {
48088 struct s3c24xx_uart_port *ourport = to_ourport(port);
48089 int ret;
48090
48091+ /* Startup sequence is different for s3c64xx and higher SoC's */
48092+ if (s3c24xx_serial_has_interrupt_mask(port))
48093+ return s3c64xx_serial_startup(port);
48094+
48095 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48096 port->mapbase, port->membase);
48097
48098@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48099 /* setup info for port */
48100 port->dev = &platdev->dev;
48101
48102- /* Startup sequence is different for s3c64xx and higher SoC's */
48103- if (s3c24xx_serial_has_interrupt_mask(port))
48104- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48105-
48106 port->uartclk = 1;
48107
48108 if (cfg->uart_flags & UPF_CONS_FLOW) {
48109diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48110index 28cdd28..56f1d60 100644
48111--- a/drivers/tty/serial/serial_core.c
48112+++ b/drivers/tty/serial/serial_core.c
48113@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48114 uart_flush_buffer(tty);
48115 uart_shutdown(tty, state);
48116 spin_lock_irqsave(&port->lock, flags);
48117- port->count = 0;
48118+ atomic_set(&port->count, 0);
48119 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48120 spin_unlock_irqrestore(&port->lock, flags);
48121 tty_port_tty_set(port, NULL);
48122@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48123 goto end;
48124 }
48125
48126- port->count++;
48127+ atomic_inc(&port->count);
48128 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48129 retval = -ENXIO;
48130 goto err_dec_count;
48131@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48132 /*
48133 * Make sure the device is in D0 state.
48134 */
48135- if (port->count == 1)
48136+ if (atomic_read(&port->count) == 1)
48137 uart_change_pm(state, UART_PM_STATE_ON);
48138
48139 /*
48140@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48141 end:
48142 return retval;
48143 err_dec_count:
48144- port->count--;
48145+ atomic_inc(&port->count);
48146 mutex_unlock(&port->mutex);
48147 goto end;
48148 }
48149diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48150index 8eaf1ab..85c030d 100644
48151--- a/drivers/tty/synclink.c
48152+++ b/drivers/tty/synclink.c
48153@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48154
48155 if (debug_level >= DEBUG_LEVEL_INFO)
48156 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48157- __FILE__,__LINE__, info->device_name, info->port.count);
48158+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48159
48160 if (tty_port_close_start(&info->port, tty, filp) == 0)
48161 goto cleanup;
48162@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48163 cleanup:
48164 if (debug_level >= DEBUG_LEVEL_INFO)
48165 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48166- tty->driver->name, info->port.count);
48167+ tty->driver->name, atomic_read(&info->port.count));
48168
48169 } /* end of mgsl_close() */
48170
48171@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48172
48173 mgsl_flush_buffer(tty);
48174 shutdown(info);
48175-
48176- info->port.count = 0;
48177+
48178+ atomic_set(&info->port.count, 0);
48179 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48180 info->port.tty = NULL;
48181
48182@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48183
48184 if (debug_level >= DEBUG_LEVEL_INFO)
48185 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48186- __FILE__,__LINE__, tty->driver->name, port->count );
48187+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48188
48189 spin_lock_irqsave(&info->irq_spinlock, flags);
48190 if (!tty_hung_up_p(filp)) {
48191 extra_count = true;
48192- port->count--;
48193+ atomic_dec(&port->count);
48194 }
48195 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48196 port->blocked_open++;
48197@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48198
48199 if (debug_level >= DEBUG_LEVEL_INFO)
48200 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48201- __FILE__,__LINE__, tty->driver->name, port->count );
48202+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48203
48204 tty_unlock(tty);
48205 schedule();
48206@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48207
48208 /* FIXME: Racy on hangup during close wait */
48209 if (extra_count)
48210- port->count++;
48211+ atomic_inc(&port->count);
48212 port->blocked_open--;
48213
48214 if (debug_level >= DEBUG_LEVEL_INFO)
48215 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48216- __FILE__,__LINE__, tty->driver->name, port->count );
48217+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48218
48219 if (!retval)
48220 port->flags |= ASYNC_NORMAL_ACTIVE;
48221@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48222
48223 if (debug_level >= DEBUG_LEVEL_INFO)
48224 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48225- __FILE__,__LINE__,tty->driver->name, info->port.count);
48226+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48227
48228 /* If port is closing, signal caller to try again */
48229 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48230@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48231 spin_unlock_irqrestore(&info->netlock, flags);
48232 goto cleanup;
48233 }
48234- info->port.count++;
48235+ atomic_inc(&info->port.count);
48236 spin_unlock_irqrestore(&info->netlock, flags);
48237
48238- if (info->port.count == 1) {
48239+ if (atomic_read(&info->port.count) == 1) {
48240 /* 1st open on this device, init hardware */
48241 retval = startup(info);
48242 if (retval < 0)
48243@@ -3446,8 +3446,8 @@ cleanup:
48244 if (retval) {
48245 if (tty->count == 1)
48246 info->port.tty = NULL; /* tty layer will release tty struct */
48247- if(info->port.count)
48248- info->port.count--;
48249+ if (atomic_read(&info->port.count))
48250+ atomic_dec(&info->port.count);
48251 }
48252
48253 return retval;
48254@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48255 unsigned short new_crctype;
48256
48257 /* return error if TTY interface open */
48258- if (info->port.count)
48259+ if (atomic_read(&info->port.count))
48260 return -EBUSY;
48261
48262 switch (encoding)
48263@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48264
48265 /* arbitrate between network and tty opens */
48266 spin_lock_irqsave(&info->netlock, flags);
48267- if (info->port.count != 0 || info->netcount != 0) {
48268+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48269 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48270 spin_unlock_irqrestore(&info->netlock, flags);
48271 return -EBUSY;
48272@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48273 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48274
48275 /* return error if TTY interface open */
48276- if (info->port.count)
48277+ if (atomic_read(&info->port.count))
48278 return -EBUSY;
48279
48280 if (cmd != SIOCWANDEV)
48281diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48282index 1abf946..1ee34fc 100644
48283--- a/drivers/tty/synclink_gt.c
48284+++ b/drivers/tty/synclink_gt.c
48285@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48286 tty->driver_data = info;
48287 info->port.tty = tty;
48288
48289- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48290+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48291
48292 /* If port is closing, signal caller to try again */
48293 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48294@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48295 mutex_unlock(&info->port.mutex);
48296 goto cleanup;
48297 }
48298- info->port.count++;
48299+ atomic_inc(&info->port.count);
48300 spin_unlock_irqrestore(&info->netlock, flags);
48301
48302- if (info->port.count == 1) {
48303+ if (atomic_read(&info->port.count) == 1) {
48304 /* 1st open on this device, init hardware */
48305 retval = startup(info);
48306 if (retval < 0) {
48307@@ -715,8 +715,8 @@ cleanup:
48308 if (retval) {
48309 if (tty->count == 1)
48310 info->port.tty = NULL; /* tty layer will release tty struct */
48311- if(info->port.count)
48312- info->port.count--;
48313+ if(atomic_read(&info->port.count))
48314+ atomic_dec(&info->port.count);
48315 }
48316
48317 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48318@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48319
48320 if (sanity_check(info, tty->name, "close"))
48321 return;
48322- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48323+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48324
48325 if (tty_port_close_start(&info->port, tty, filp) == 0)
48326 goto cleanup;
48327@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48328 tty_port_close_end(&info->port, tty);
48329 info->port.tty = NULL;
48330 cleanup:
48331- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48332+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48333 }
48334
48335 static void hangup(struct tty_struct *tty)
48336@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48337 shutdown(info);
48338
48339 spin_lock_irqsave(&info->port.lock, flags);
48340- info->port.count = 0;
48341+ atomic_set(&info->port.count, 0);
48342 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48343 info->port.tty = NULL;
48344 spin_unlock_irqrestore(&info->port.lock, flags);
48345@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48346 unsigned short new_crctype;
48347
48348 /* return error if TTY interface open */
48349- if (info->port.count)
48350+ if (atomic_read(&info->port.count))
48351 return -EBUSY;
48352
48353 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48354@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48355
48356 /* arbitrate between network and tty opens */
48357 spin_lock_irqsave(&info->netlock, flags);
48358- if (info->port.count != 0 || info->netcount != 0) {
48359+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48360 DBGINFO(("%s hdlc_open busy\n", dev->name));
48361 spin_unlock_irqrestore(&info->netlock, flags);
48362 return -EBUSY;
48363@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48364 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48365
48366 /* return error if TTY interface open */
48367- if (info->port.count)
48368+ if (atomic_read(&info->port.count))
48369 return -EBUSY;
48370
48371 if (cmd != SIOCWANDEV)
48372@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48373 if (port == NULL)
48374 continue;
48375 spin_lock(&port->lock);
48376- if ((port->port.count || port->netcount) &&
48377+ if ((atomic_read(&port->port.count) || port->netcount) &&
48378 port->pending_bh && !port->bh_running &&
48379 !port->bh_requested) {
48380 DBGISR(("%s bh queued\n", port->device_name));
48381@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48382 spin_lock_irqsave(&info->lock, flags);
48383 if (!tty_hung_up_p(filp)) {
48384 extra_count = true;
48385- port->count--;
48386+ atomic_dec(&port->count);
48387 }
48388 spin_unlock_irqrestore(&info->lock, flags);
48389 port->blocked_open++;
48390@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48391 remove_wait_queue(&port->open_wait, &wait);
48392
48393 if (extra_count)
48394- port->count++;
48395+ atomic_inc(&port->count);
48396 port->blocked_open--;
48397
48398 if (!retval)
48399diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48400index dc6e969..5dc8786 100644
48401--- a/drivers/tty/synclinkmp.c
48402+++ b/drivers/tty/synclinkmp.c
48403@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48404
48405 if (debug_level >= DEBUG_LEVEL_INFO)
48406 printk("%s(%d):%s open(), old ref count = %d\n",
48407- __FILE__,__LINE__,tty->driver->name, info->port.count);
48408+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48409
48410 /* If port is closing, signal caller to try again */
48411 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48412@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48413 spin_unlock_irqrestore(&info->netlock, flags);
48414 goto cleanup;
48415 }
48416- info->port.count++;
48417+ atomic_inc(&info->port.count);
48418 spin_unlock_irqrestore(&info->netlock, flags);
48419
48420- if (info->port.count == 1) {
48421+ if (atomic_read(&info->port.count) == 1) {
48422 /* 1st open on this device, init hardware */
48423 retval = startup(info);
48424 if (retval < 0)
48425@@ -796,8 +796,8 @@ cleanup:
48426 if (retval) {
48427 if (tty->count == 1)
48428 info->port.tty = NULL; /* tty layer will release tty struct */
48429- if(info->port.count)
48430- info->port.count--;
48431+ if(atomic_read(&info->port.count))
48432+ atomic_dec(&info->port.count);
48433 }
48434
48435 return retval;
48436@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48437
48438 if (debug_level >= DEBUG_LEVEL_INFO)
48439 printk("%s(%d):%s close() entry, count=%d\n",
48440- __FILE__,__LINE__, info->device_name, info->port.count);
48441+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48442
48443 if (tty_port_close_start(&info->port, tty, filp) == 0)
48444 goto cleanup;
48445@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48446 cleanup:
48447 if (debug_level >= DEBUG_LEVEL_INFO)
48448 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48449- tty->driver->name, info->port.count);
48450+ tty->driver->name, atomic_read(&info->port.count));
48451 }
48452
48453 /* Called by tty_hangup() when a hangup is signaled.
48454@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48455 shutdown(info);
48456
48457 spin_lock_irqsave(&info->port.lock, flags);
48458- info->port.count = 0;
48459+ atomic_set(&info->port.count, 0);
48460 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48461 info->port.tty = NULL;
48462 spin_unlock_irqrestore(&info->port.lock, flags);
48463@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48464 unsigned short new_crctype;
48465
48466 /* return error if TTY interface open */
48467- if (info->port.count)
48468+ if (atomic_read(&info->port.count))
48469 return -EBUSY;
48470
48471 switch (encoding)
48472@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48473
48474 /* arbitrate between network and tty opens */
48475 spin_lock_irqsave(&info->netlock, flags);
48476- if (info->port.count != 0 || info->netcount != 0) {
48477+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48478 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48479 spin_unlock_irqrestore(&info->netlock, flags);
48480 return -EBUSY;
48481@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48482 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48483
48484 /* return error if TTY interface open */
48485- if (info->port.count)
48486+ if (atomic_read(&info->port.count))
48487 return -EBUSY;
48488
48489 if (cmd != SIOCWANDEV)
48490@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48491 * do not request bottom half processing if the
48492 * device is not open in a normal mode.
48493 */
48494- if ( port && (port->port.count || port->netcount) &&
48495+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48496 port->pending_bh && !port->bh_running &&
48497 !port->bh_requested ) {
48498 if ( debug_level >= DEBUG_LEVEL_ISR )
48499@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48500
48501 if (debug_level >= DEBUG_LEVEL_INFO)
48502 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48503- __FILE__,__LINE__, tty->driver->name, port->count );
48504+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48505
48506 spin_lock_irqsave(&info->lock, flags);
48507 if (!tty_hung_up_p(filp)) {
48508 extra_count = true;
48509- port->count--;
48510+ atomic_dec(&port->count);
48511 }
48512 spin_unlock_irqrestore(&info->lock, flags);
48513 port->blocked_open++;
48514@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48515
48516 if (debug_level >= DEBUG_LEVEL_INFO)
48517 printk("%s(%d):%s block_til_ready() count=%d\n",
48518- __FILE__,__LINE__, tty->driver->name, port->count );
48519+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48520
48521 tty_unlock(tty);
48522 schedule();
48523@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48524 remove_wait_queue(&port->open_wait, &wait);
48525
48526 if (extra_count)
48527- port->count++;
48528+ atomic_inc(&port->count);
48529 port->blocked_open--;
48530
48531 if (debug_level >= DEBUG_LEVEL_INFO)
48532 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48533- __FILE__,__LINE__, tty->driver->name, port->count );
48534+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48535
48536 if (!retval)
48537 port->flags |= ASYNC_NORMAL_ACTIVE;
48538diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48539index d5cc3ac..3263411 100644
48540--- a/drivers/tty/sysrq.c
48541+++ b/drivers/tty/sysrq.c
48542@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48543 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48544 size_t count, loff_t *ppos)
48545 {
48546- if (count) {
48547+ if (count && capable(CAP_SYS_ADMIN)) {
48548 char c;
48549
48550 if (get_user(c, buf))
48551diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48552index 20689b9..7fd3a31 100644
48553--- a/drivers/tty/tty_io.c
48554+++ b/drivers/tty/tty_io.c
48555@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48556
48557 void tty_default_fops(struct file_operations *fops)
48558 {
48559- *fops = tty_fops;
48560+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48561 }
48562
48563 /*
48564diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48565index 1afe192..73d2c20 100644
48566--- a/drivers/tty/tty_ldisc.c
48567+++ b/drivers/tty/tty_ldisc.c
48568@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48569 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48570 tty_ldiscs[disc] = new_ldisc;
48571 new_ldisc->num = disc;
48572- new_ldisc->refcount = 0;
48573+ atomic_set(&new_ldisc->refcount, 0);
48574 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48575
48576 return ret;
48577@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48578 return -EINVAL;
48579
48580 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48581- if (tty_ldiscs[disc]->refcount)
48582+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48583 ret = -EBUSY;
48584 else
48585 tty_ldiscs[disc] = NULL;
48586@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48587 if (ldops) {
48588 ret = ERR_PTR(-EAGAIN);
48589 if (try_module_get(ldops->owner)) {
48590- ldops->refcount++;
48591+ atomic_inc(&ldops->refcount);
48592 ret = ldops;
48593 }
48594 }
48595@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48596 unsigned long flags;
48597
48598 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48599- ldops->refcount--;
48600+ atomic_dec(&ldops->refcount);
48601 module_put(ldops->owner);
48602 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48603 }
48604@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48605 /* unreleased reader reference(s) will cause this WARN */
48606 WARN_ON(!atomic_dec_and_test(&ld->users));
48607
48608- ld->ops->refcount--;
48609+ atomic_dec(&ld->ops->refcount);
48610 module_put(ld->ops->owner);
48611 kfree(ld);
48612 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48613diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48614index f597e88..b7f68ed 100644
48615--- a/drivers/tty/tty_port.c
48616+++ b/drivers/tty/tty_port.c
48617@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48618 unsigned long flags;
48619
48620 spin_lock_irqsave(&port->lock, flags);
48621- port->count = 0;
48622+ atomic_set(&port->count, 0);
48623 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48624 tty = port->tty;
48625 if (tty)
48626@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48627 /* The port lock protects the port counts */
48628 spin_lock_irqsave(&port->lock, flags);
48629 if (!tty_hung_up_p(filp))
48630- port->count--;
48631+ atomic_dec(&port->count);
48632 port->blocked_open++;
48633 spin_unlock_irqrestore(&port->lock, flags);
48634
48635@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48636 we must not mess that up further */
48637 spin_lock_irqsave(&port->lock, flags);
48638 if (!tty_hung_up_p(filp))
48639- port->count++;
48640+ atomic_inc(&port->count);
48641 port->blocked_open--;
48642 if (retval == 0)
48643 port->flags |= ASYNC_NORMAL_ACTIVE;
48644@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48645 return 0;
48646 }
48647
48648- if (tty->count == 1 && port->count != 1) {
48649+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48650 printk(KERN_WARNING
48651 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48652- port->count);
48653- port->count = 1;
48654+ atomic_read(&port->count));
48655+ atomic_set(&port->count, 1);
48656 }
48657- if (--port->count < 0) {
48658+ if (atomic_dec_return(&port->count) < 0) {
48659 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48660- port->count);
48661- port->count = 0;
48662+ atomic_read(&port->count));
48663+ atomic_set(&port->count, 0);
48664 }
48665
48666- if (port->count) {
48667+ if (atomic_read(&port->count)) {
48668 spin_unlock_irqrestore(&port->lock, flags);
48669 if (port->ops->drop)
48670 port->ops->drop(port);
48671@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48672 {
48673 spin_lock_irq(&port->lock);
48674 if (!tty_hung_up_p(filp))
48675- ++port->count;
48676+ atomic_inc(&port->count);
48677 spin_unlock_irq(&port->lock);
48678 tty_port_tty_set(port, tty);
48679
48680diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48681index a9af1b9a..1e08e7f 100644
48682--- a/drivers/tty/vt/keyboard.c
48683+++ b/drivers/tty/vt/keyboard.c
48684@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48685 kbd->kbdmode == VC_OFF) &&
48686 value != KVAL(K_SAK))
48687 return; /* SAK is allowed even in raw mode */
48688+
48689+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48690+ {
48691+ void *func = fn_handler[value];
48692+ if (func == fn_show_state || func == fn_show_ptregs ||
48693+ func == fn_show_mem)
48694+ return;
48695+ }
48696+#endif
48697+
48698 fn_handler[value](vc);
48699 }
48700
48701@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48702 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48703 return -EFAULT;
48704
48705- if (!capable(CAP_SYS_TTY_CONFIG))
48706- perm = 0;
48707-
48708 switch (cmd) {
48709 case KDGKBENT:
48710 /* Ensure another thread doesn't free it under us */
48711@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48712 spin_unlock_irqrestore(&kbd_event_lock, flags);
48713 return put_user(val, &user_kbe->kb_value);
48714 case KDSKBENT:
48715+ if (!capable(CAP_SYS_TTY_CONFIG))
48716+ perm = 0;
48717+
48718 if (!perm)
48719 return -EPERM;
48720 if (!i && v == K_NOSUCHMAP) {
48721@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48722 int i, j, k;
48723 int ret;
48724
48725- if (!capable(CAP_SYS_TTY_CONFIG))
48726- perm = 0;
48727-
48728 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48729 if (!kbs) {
48730 ret = -ENOMEM;
48731@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48732 kfree(kbs);
48733 return ((p && *p) ? -EOVERFLOW : 0);
48734 case KDSKBSENT:
48735+ if (!capable(CAP_SYS_TTY_CONFIG))
48736+ perm = 0;
48737+
48738 if (!perm) {
48739 ret = -EPERM;
48740 goto reterr;
48741diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48742index 3b96f18..026a9bf 100644
48743--- a/drivers/uio/uio.c
48744+++ b/drivers/uio/uio.c
48745@@ -25,6 +25,7 @@
48746 #include <linux/kobject.h>
48747 #include <linux/cdev.h>
48748 #include <linux/uio_driver.h>
48749+#include <asm/local.h>
48750
48751 #define UIO_MAX_DEVICES (1U << MINORBITS)
48752
48753@@ -32,10 +33,10 @@ struct uio_device {
48754 struct module *owner;
48755 struct device *dev;
48756 int minor;
48757- atomic_t event;
48758+ atomic_unchecked_t event;
48759 struct fasync_struct *async_queue;
48760 wait_queue_head_t wait;
48761- int vma_count;
48762+ local_t vma_count;
48763 struct uio_info *info;
48764 struct kobject *map_dir;
48765 struct kobject *portio_dir;
48766@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48767 struct device_attribute *attr, char *buf)
48768 {
48769 struct uio_device *idev = dev_get_drvdata(dev);
48770- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48771+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48772 }
48773
48774 static struct device_attribute uio_class_attributes[] = {
48775@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48776 {
48777 struct uio_device *idev = info->uio_dev;
48778
48779- atomic_inc(&idev->event);
48780+ atomic_inc_unchecked(&idev->event);
48781 wake_up_interruptible(&idev->wait);
48782 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48783 }
48784@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48785 }
48786
48787 listener->dev = idev;
48788- listener->event_count = atomic_read(&idev->event);
48789+ listener->event_count = atomic_read_unchecked(&idev->event);
48790 filep->private_data = listener;
48791
48792 if (idev->info->open) {
48793@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48794 return -EIO;
48795
48796 poll_wait(filep, &idev->wait, wait);
48797- if (listener->event_count != atomic_read(&idev->event))
48798+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48799 return POLLIN | POLLRDNORM;
48800 return 0;
48801 }
48802@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48803 do {
48804 set_current_state(TASK_INTERRUPTIBLE);
48805
48806- event_count = atomic_read(&idev->event);
48807+ event_count = atomic_read_unchecked(&idev->event);
48808 if (event_count != listener->event_count) {
48809 if (copy_to_user(buf, &event_count, count))
48810 retval = -EFAULT;
48811@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48812 static void uio_vma_open(struct vm_area_struct *vma)
48813 {
48814 struct uio_device *idev = vma->vm_private_data;
48815- idev->vma_count++;
48816+ local_inc(&idev->vma_count);
48817 }
48818
48819 static void uio_vma_close(struct vm_area_struct *vma)
48820 {
48821 struct uio_device *idev = vma->vm_private_data;
48822- idev->vma_count--;
48823+ local_dec(&idev->vma_count);
48824 }
48825
48826 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48827@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48828 idev->owner = owner;
48829 idev->info = info;
48830 init_waitqueue_head(&idev->wait);
48831- atomic_set(&idev->event, 0);
48832+ atomic_set_unchecked(&idev->event, 0);
48833
48834 ret = uio_get_minor(idev);
48835 if (ret)
48836diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48837index 8a7eb77..c00402f 100644
48838--- a/drivers/usb/atm/cxacru.c
48839+++ b/drivers/usb/atm/cxacru.c
48840@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48841 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48842 if (ret < 2)
48843 return -EINVAL;
48844- if (index < 0 || index > 0x7f)
48845+ if (index > 0x7f)
48846 return -EINVAL;
48847 pos += tmp;
48848
48849diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48850index 5e0d33a..cc10579 100644
48851--- a/drivers/usb/atm/usbatm.c
48852+++ b/drivers/usb/atm/usbatm.c
48853@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48854 if (printk_ratelimit())
48855 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48856 __func__, vpi, vci);
48857- atomic_inc(&vcc->stats->rx_err);
48858+ atomic_inc_unchecked(&vcc->stats->rx_err);
48859 return;
48860 }
48861
48862@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48863 if (length > ATM_MAX_AAL5_PDU) {
48864 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48865 __func__, length, vcc);
48866- atomic_inc(&vcc->stats->rx_err);
48867+ atomic_inc_unchecked(&vcc->stats->rx_err);
48868 goto out;
48869 }
48870
48871@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48872 if (sarb->len < pdu_length) {
48873 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48874 __func__, pdu_length, sarb->len, vcc);
48875- atomic_inc(&vcc->stats->rx_err);
48876+ atomic_inc_unchecked(&vcc->stats->rx_err);
48877 goto out;
48878 }
48879
48880 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48881 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48882 __func__, vcc);
48883- atomic_inc(&vcc->stats->rx_err);
48884+ atomic_inc_unchecked(&vcc->stats->rx_err);
48885 goto out;
48886 }
48887
48888@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48889 if (printk_ratelimit())
48890 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48891 __func__, length);
48892- atomic_inc(&vcc->stats->rx_drop);
48893+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48894 goto out;
48895 }
48896
48897@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48898
48899 vcc->push(vcc, skb);
48900
48901- atomic_inc(&vcc->stats->rx);
48902+ atomic_inc_unchecked(&vcc->stats->rx);
48903 out:
48904 skb_trim(sarb, 0);
48905 }
48906@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48907 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48908
48909 usbatm_pop(vcc, skb);
48910- atomic_inc(&vcc->stats->tx);
48911+ atomic_inc_unchecked(&vcc->stats->tx);
48912
48913 skb = skb_dequeue(&instance->sndqueue);
48914 }
48915@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48916 if (!left--)
48917 return sprintf(page,
48918 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48919- atomic_read(&atm_dev->stats.aal5.tx),
48920- atomic_read(&atm_dev->stats.aal5.tx_err),
48921- atomic_read(&atm_dev->stats.aal5.rx),
48922- atomic_read(&atm_dev->stats.aal5.rx_err),
48923- atomic_read(&atm_dev->stats.aal5.rx_drop));
48924+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48925+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48926+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48927+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48928+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48929
48930 if (!left--) {
48931 if (instance->disconnected)
48932diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48933index 2a3bbdf..91d72cf 100644
48934--- a/drivers/usb/core/devices.c
48935+++ b/drivers/usb/core/devices.c
48936@@ -126,7 +126,7 @@ static const char format_endpt[] =
48937 * time it gets called.
48938 */
48939 static struct device_connect_event {
48940- atomic_t count;
48941+ atomic_unchecked_t count;
48942 wait_queue_head_t wait;
48943 } device_event = {
48944 .count = ATOMIC_INIT(1),
48945@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48946
48947 void usbfs_conn_disc_event(void)
48948 {
48949- atomic_add(2, &device_event.count);
48950+ atomic_add_unchecked(2, &device_event.count);
48951 wake_up(&device_event.wait);
48952 }
48953
48954@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48955
48956 poll_wait(file, &device_event.wait, wait);
48957
48958- event_count = atomic_read(&device_event.count);
48959+ event_count = atomic_read_unchecked(&device_event.count);
48960 if (file->f_version != event_count) {
48961 file->f_version = event_count;
48962 return POLLIN | POLLRDNORM;
48963diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48964index 014dc99..4d25fd7 100644
48965--- a/drivers/usb/core/hcd.c
48966+++ b/drivers/usb/core/hcd.c
48967@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48968 */
48969 usb_get_urb(urb);
48970 atomic_inc(&urb->use_count);
48971- atomic_inc(&urb->dev->urbnum);
48972+ atomic_inc_unchecked(&urb->dev->urbnum);
48973 usbmon_urb_submit(&hcd->self, urb);
48974
48975 /* NOTE requirements on root-hub callers (usbfs and the hub
48976@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48977 urb->hcpriv = NULL;
48978 INIT_LIST_HEAD(&urb->urb_list);
48979 atomic_dec(&urb->use_count);
48980- atomic_dec(&urb->dev->urbnum);
48981+ atomic_dec_unchecked(&urb->dev->urbnum);
48982 if (atomic_read(&urb->reject))
48983 wake_up(&usb_kill_urb_queue);
48984 usb_put_urb(urb);
48985diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48986index 17c3785..deffb11 100644
48987--- a/drivers/usb/core/hub.c
48988+++ b/drivers/usb/core/hub.c
48989@@ -27,6 +27,7 @@
48990 #include <linux/freezer.h>
48991 #include <linux/random.h>
48992 #include <linux/pm_qos.h>
48993+#include <linux/grsecurity.h>
48994
48995 #include <asm/uaccess.h>
48996 #include <asm/byteorder.h>
48997@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48998 goto done;
48999 return;
49000 }
49001+
49002+ if (gr_handle_new_usb())
49003+ goto done;
49004+
49005 if (hub_is_superspeed(hub->hdev))
49006 unit_load = 150;
49007 else
49008diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49009index e7ee1e4..1dfc9ea4 100644
49010--- a/drivers/usb/core/message.c
49011+++ b/drivers/usb/core/message.c
49012@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49013 * method can wait for it to complete. Since you don't have a handle on the
49014 * URB used, you can't cancel the request.
49015 */
49016-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49017+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49018 __u8 requesttype, __u16 value, __u16 index, void *data,
49019 __u16 size, int timeout)
49020 {
49021diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49022index d9284b9..17023c7 100644
49023--- a/drivers/usb/core/sysfs.c
49024+++ b/drivers/usb/core/sysfs.c
49025@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49026 struct usb_device *udev;
49027
49028 udev = to_usb_device(dev);
49029- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49030+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49031 }
49032 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49033
49034diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49035index 7dad603..350f7a9 100644
49036--- a/drivers/usb/core/usb.c
49037+++ b/drivers/usb/core/usb.c
49038@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49039 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49040 dev->state = USB_STATE_ATTACHED;
49041 dev->lpm_disable_count = 1;
49042- atomic_set(&dev->urbnum, 0);
49043+ atomic_set_unchecked(&dev->urbnum, 0);
49044
49045 INIT_LIST_HEAD(&dev->ep0.urb_list);
49046 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49047diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49048index 14d28d6..5f511ac 100644
49049--- a/drivers/usb/dwc3/gadget.c
49050+++ b/drivers/usb/dwc3/gadget.c
49051@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49052 if (!usb_endpoint_xfer_isoc(desc))
49053 return 0;
49054
49055- memset(&trb_link, 0, sizeof(trb_link));
49056-
49057 /* Link TRB for ISOC. The HWO bit is never reset */
49058 trb_st_hw = &dep->trb_pool[0];
49059
49060diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49061index 5e29dde..eca992f 100644
49062--- a/drivers/usb/early/ehci-dbgp.c
49063+++ b/drivers/usb/early/ehci-dbgp.c
49064@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49065
49066 #ifdef CONFIG_KGDB
49067 static struct kgdb_io kgdbdbgp_io_ops;
49068-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49069+static struct kgdb_io kgdbdbgp_io_ops_console;
49070+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49071 #else
49072 #define dbgp_kgdb_mode (0)
49073 #endif
49074@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49075 .write_char = kgdbdbgp_write_char,
49076 };
49077
49078+static struct kgdb_io kgdbdbgp_io_ops_console = {
49079+ .name = "kgdbdbgp",
49080+ .read_char = kgdbdbgp_read_char,
49081+ .write_char = kgdbdbgp_write_char,
49082+ .is_console = 1
49083+};
49084+
49085 static int kgdbdbgp_wait_time;
49086
49087 static int __init kgdbdbgp_parse_config(char *str)
49088@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49089 ptr++;
49090 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49091 }
49092- kgdb_register_io_module(&kgdbdbgp_io_ops);
49093- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49094+ if (early_dbgp_console.index != -1)
49095+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49096+ else
49097+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49098
49099 return 0;
49100 }
49101diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49102index b369292..9f3ba40 100644
49103--- a/drivers/usb/gadget/u_serial.c
49104+++ b/drivers/usb/gadget/u_serial.c
49105@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49106 spin_lock_irq(&port->port_lock);
49107
49108 /* already open? Great. */
49109- if (port->port.count) {
49110+ if (atomic_read(&port->port.count)) {
49111 status = 0;
49112- port->port.count++;
49113+ atomic_inc(&port->port.count);
49114
49115 /* currently opening/closing? wait ... */
49116 } else if (port->openclose) {
49117@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49118 tty->driver_data = port;
49119 port->port.tty = tty;
49120
49121- port->port.count = 1;
49122+ atomic_set(&port->port.count, 1);
49123 port->openclose = false;
49124
49125 /* if connected, start the I/O stream */
49126@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49127
49128 spin_lock_irq(&port->port_lock);
49129
49130- if (port->port.count != 1) {
49131- if (port->port.count == 0)
49132+ if (atomic_read(&port->port.count) != 1) {
49133+ if (atomic_read(&port->port.count) == 0)
49134 WARN_ON(1);
49135 else
49136- --port->port.count;
49137+ atomic_dec(&port->port.count);
49138 goto exit;
49139 }
49140
49141@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49142 * and sleep if necessary
49143 */
49144 port->openclose = true;
49145- port->port.count = 0;
49146+ atomic_set(&port->port.count, 0);
49147
49148 gser = port->port_usb;
49149 if (gser && gser->disconnect)
49150@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49151 int cond;
49152
49153 spin_lock_irq(&port->port_lock);
49154- cond = (port->port.count == 0) && !port->openclose;
49155+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49156 spin_unlock_irq(&port->port_lock);
49157 return cond;
49158 }
49159@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49160 /* if it's already open, start I/O ... and notify the serial
49161 * protocol about open/close status (connect/disconnect).
49162 */
49163- if (port->port.count) {
49164+ if (atomic_read(&port->port.count)) {
49165 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49166 gs_start_io(port);
49167 if (gser->connect)
49168@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49169
49170 port->port_usb = NULL;
49171 gser->ioport = NULL;
49172- if (port->port.count > 0 || port->openclose) {
49173+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49174 wake_up_interruptible(&port->drain_wait);
49175 if (port->port.tty)
49176 tty_hangup(port->port.tty);
49177@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49178
49179 /* finally, free any unused/unusable I/O buffers */
49180 spin_lock_irqsave(&port->port_lock, flags);
49181- if (port->port.count == 0 && !port->openclose)
49182+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49183 gs_buf_free(&port->port_write_buf);
49184 gs_free_requests(gser->out, &port->read_pool, NULL);
49185 gs_free_requests(gser->out, &port->read_queue, NULL);
49186diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49187index ba6a5d6..f88f7f3 100644
49188--- a/drivers/usb/misc/appledisplay.c
49189+++ b/drivers/usb/misc/appledisplay.c
49190@@ -83,7 +83,7 @@ struct appledisplay {
49191 spinlock_t lock;
49192 };
49193
49194-static atomic_t count_displays = ATOMIC_INIT(0);
49195+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49196 static struct workqueue_struct *wq;
49197
49198 static void appledisplay_complete(struct urb *urb)
49199@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49200
49201 /* Register backlight device */
49202 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49203- atomic_inc_return(&count_displays) - 1);
49204+ atomic_inc_return_unchecked(&count_displays) - 1);
49205 memset(&props, 0, sizeof(struct backlight_properties));
49206 props.type = BACKLIGHT_RAW;
49207 props.max_brightness = 0xff;
49208diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49209index afb50ea..7b0b1cf 100644
49210--- a/drivers/usb/serial/console.c
49211+++ b/drivers/usb/serial/console.c
49212@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49213
49214 info->port = port;
49215
49216- ++port->port.count;
49217+ atomic_inc(&port->port.count);
49218 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49219 if (serial->type->set_termios) {
49220 /*
49221@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49222 }
49223 /* Now that any required fake tty operations are completed restore
49224 * the tty port count */
49225- --port->port.count;
49226+ atomic_dec(&port->port.count);
49227 /* The console is special in terms of closing the device so
49228 * indicate this port is now acting as a system console. */
49229 port->port.console = 1;
49230@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49231 free_tty:
49232 kfree(tty);
49233 reset_open_count:
49234- port->port.count = 0;
49235+ atomic_set(&port->port.count, 0);
49236 usb_autopm_put_interface(serial->interface);
49237 error_get_interface:
49238 usb_serial_put(serial);
49239diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49240index 75f70f0..d467e1a 100644
49241--- a/drivers/usb/storage/usb.h
49242+++ b/drivers/usb/storage/usb.h
49243@@ -63,7 +63,7 @@ struct us_unusual_dev {
49244 __u8 useProtocol;
49245 __u8 useTransport;
49246 int (*initFunction)(struct us_data *);
49247-};
49248+} __do_const;
49249
49250
49251 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49252diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49253index d6bea3e..60b250e 100644
49254--- a/drivers/usb/wusbcore/wa-hc.h
49255+++ b/drivers/usb/wusbcore/wa-hc.h
49256@@ -192,7 +192,7 @@ struct wahc {
49257 struct list_head xfer_delayed_list;
49258 spinlock_t xfer_list_lock;
49259 struct work_struct xfer_work;
49260- atomic_t xfer_id_count;
49261+ atomic_unchecked_t xfer_id_count;
49262 };
49263
49264
49265@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49266 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49267 spin_lock_init(&wa->xfer_list_lock);
49268 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49269- atomic_set(&wa->xfer_id_count, 1);
49270+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49271 }
49272
49273 /**
49274diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49275index d3493ca..0c33b7e 100644
49276--- a/drivers/usb/wusbcore/wa-xfer.c
49277+++ b/drivers/usb/wusbcore/wa-xfer.c
49278@@ -297,7 +297,7 @@ out:
49279 */
49280 static void wa_xfer_id_init(struct wa_xfer *xfer)
49281 {
49282- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49283+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49284 }
49285
49286 /*
49287diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49288index 842f450..d1d7409 100644
49289--- a/drivers/vfio/vfio.c
49290+++ b/drivers/vfio/vfio.c
49291@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49292 return 0;
49293
49294 /* TODO Prevent device auto probing */
49295- WARN("Device %s added to live group %d!\n", dev_name(dev),
49296+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49297 iommu_group_id(group->iommu_group));
49298
49299 return 0;
49300diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49301index 5174eba..86e764a 100644
49302--- a/drivers/vhost/vringh.c
49303+++ b/drivers/vhost/vringh.c
49304@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49305
49306 static inline int putu16_kern(u16 *p, u16 val)
49307 {
49308- ACCESS_ONCE(*p) = val;
49309+ ACCESS_ONCE_RW(*p) = val;
49310 return 0;
49311 }
49312
49313diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49314index a4dfe8c..297ddd9 100644
49315--- a/drivers/video/aty/aty128fb.c
49316+++ b/drivers/video/aty/aty128fb.c
49317@@ -149,7 +149,7 @@ enum {
49318 };
49319
49320 /* Must match above enum */
49321-static char * const r128_family[] = {
49322+static const char * const r128_family[] = {
49323 "AGP",
49324 "PCI",
49325 "PRO AGP",
49326diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49327index 9b0f12c..024673d 100644
49328--- a/drivers/video/aty/atyfb_base.c
49329+++ b/drivers/video/aty/atyfb_base.c
49330@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49331 par->accel_flags = var->accel_flags; /* hack */
49332
49333 if (var->accel_flags) {
49334- info->fbops->fb_sync = atyfb_sync;
49335+ pax_open_kernel();
49336+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49337+ pax_close_kernel();
49338 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49339 } else {
49340- info->fbops->fb_sync = NULL;
49341+ pax_open_kernel();
49342+ *(void **)&info->fbops->fb_sync = NULL;
49343+ pax_close_kernel();
49344 info->flags |= FBINFO_HWACCEL_DISABLED;
49345 }
49346
49347diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49348index 95ec042..e6affdd 100644
49349--- a/drivers/video/aty/mach64_cursor.c
49350+++ b/drivers/video/aty/mach64_cursor.c
49351@@ -7,6 +7,7 @@
49352 #include <linux/string.h>
49353
49354 #include <asm/io.h>
49355+#include <asm/pgtable.h>
49356
49357 #ifdef __sparc__
49358 #include <asm/fbio.h>
49359@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49360 info->sprite.buf_align = 16; /* and 64 lines tall. */
49361 info->sprite.flags = FB_PIXMAP_IO;
49362
49363- info->fbops->fb_cursor = atyfb_cursor;
49364+ pax_open_kernel();
49365+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49366+ pax_close_kernel();
49367
49368 return 0;
49369 }
49370diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49371index bca6ccc..252107e 100644
49372--- a/drivers/video/backlight/kb3886_bl.c
49373+++ b/drivers/video/backlight/kb3886_bl.c
49374@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49375 static unsigned long kb3886bl_flags;
49376 #define KB3886BL_SUSPENDED 0x01
49377
49378-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49379+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49380 {
49381 .ident = "Sahara Touch-iT",
49382 .matches = {
49383diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49384index 900aa4e..6d49418 100644
49385--- a/drivers/video/fb_defio.c
49386+++ b/drivers/video/fb_defio.c
49387@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49388
49389 BUG_ON(!fbdefio);
49390 mutex_init(&fbdefio->lock);
49391- info->fbops->fb_mmap = fb_deferred_io_mmap;
49392+ pax_open_kernel();
49393+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49394+ pax_close_kernel();
49395 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49396 INIT_LIST_HEAD(&fbdefio->pagelist);
49397 if (fbdefio->delay == 0) /* set a default of 1 s */
49398@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49399 page->mapping = NULL;
49400 }
49401
49402- info->fbops->fb_mmap = NULL;
49403+ *(void **)&info->fbops->fb_mmap = NULL;
49404 mutex_destroy(&fbdefio->lock);
49405 }
49406 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49407diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49408index 5c3960d..15cf8fc 100644
49409--- a/drivers/video/fbcmap.c
49410+++ b/drivers/video/fbcmap.c
49411@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49412 rc = -ENODEV;
49413 goto out;
49414 }
49415- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49416- !info->fbops->fb_setcmap)) {
49417+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49418 rc = -EINVAL;
49419 goto out1;
49420 }
49421diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49422index 36e1fe2..c744820 100644
49423--- a/drivers/video/fbmem.c
49424+++ b/drivers/video/fbmem.c
49425@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49426 image->dx += image->width + 8;
49427 }
49428 } else if (rotate == FB_ROTATE_UD) {
49429- for (x = 0; x < num && image->dx >= 0; x++) {
49430+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49431 info->fbops->fb_imageblit(info, image);
49432 image->dx -= image->width + 8;
49433 }
49434@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49435 image->dy += image->height + 8;
49436 }
49437 } else if (rotate == FB_ROTATE_CCW) {
49438- for (x = 0; x < num && image->dy >= 0; x++) {
49439+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49440 info->fbops->fb_imageblit(info, image);
49441 image->dy -= image->height + 8;
49442 }
49443@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49444 return -EFAULT;
49445 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49446 return -EINVAL;
49447- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49448+ if (con2fb.framebuffer >= FB_MAX)
49449 return -EINVAL;
49450 if (!registered_fb[con2fb.framebuffer])
49451 request_module("fb%d", con2fb.framebuffer);
49452diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49453index d4d2c5f..ebbd113 100644
49454--- a/drivers/video/hyperv_fb.c
49455+++ b/drivers/video/hyperv_fb.c
49456@@ -233,7 +233,7 @@ static uint screen_fb_size;
49457 static inline int synthvid_send(struct hv_device *hdev,
49458 struct synthvid_msg *msg)
49459 {
49460- static atomic64_t request_id = ATOMIC64_INIT(0);
49461+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49462 int ret;
49463
49464 msg->pipe_hdr.type = PIPE_MSG_DATA;
49465@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49466
49467 ret = vmbus_sendpacket(hdev->channel, msg,
49468 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49469- atomic64_inc_return(&request_id),
49470+ atomic64_inc_return_unchecked(&request_id),
49471 VM_PKT_DATA_INBAND, 0);
49472
49473 if (ret)
49474diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49475index 7672d2e..b56437f 100644
49476--- a/drivers/video/i810/i810_accel.c
49477+++ b/drivers/video/i810/i810_accel.c
49478@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49479 }
49480 }
49481 printk("ringbuffer lockup!!!\n");
49482+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49483 i810_report_error(mmio);
49484 par->dev_flags |= LOCKUP;
49485 info->pixmap.scan_align = 1;
49486diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49487index 285d552..eafa544 100644
49488--- a/drivers/video/logo/logo_linux_clut224.ppm
49489+++ b/drivers/video/logo/logo_linux_clut224.ppm
49490@@ -1,883 +1,1123 @@
49491 P3
49492 80 80
49493 255
49494-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49495-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49496-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49497-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49498-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49499-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49500-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49501-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49502-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49503-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49504-
49505-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49506-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49507-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49508-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49509-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49510-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49511-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49512-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49513-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49514-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49515-
49516-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49517-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49518-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49519-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49520-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49521-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49522-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49523-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49524-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49525-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49526-
49527-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49528-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49529-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49530-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49531-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49532-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49533-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49534-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49535-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49536-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49537-
49538-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49539-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49540-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49541-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49542-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49543-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49544-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49545-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49546-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49547-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49548-
49549-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49550-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49551-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49552-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49553-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49554-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49555-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49556-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49557-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49558-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49559-
49560-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49561-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49562-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49563-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49564-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49565-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49566-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49567-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49568-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49569-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49570-
49571-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49572-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49573-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49574-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49575-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49576-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49577-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49578-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49579-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49580-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49581-
49582-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49583-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49584-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49585-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49586-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49587-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49588-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49589-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49590-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49591-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49592-
49593-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49594-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49595-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49596-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49597-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49598-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49599-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49600-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49601-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49602-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49603-
49604-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49605-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49606-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49607-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49608-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49609-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49610-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49611-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49612-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49613-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49614-
49615-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49616-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49617-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49618-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49619-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49620-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49621-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49622-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49623-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49624-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49625-
49626-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49627-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49628-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49629-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49630-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49631-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49632-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49633-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49634-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49635-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49636-
49637-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49638-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49639-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49640-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49641-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49642-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49643-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49644-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49645-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49646-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49647-
49648-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49649-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49650-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49651-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49652-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49653-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49654-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49655-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49656-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49657-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49658-
49659-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49660-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49661-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49662-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49663-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49664-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49665-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49666-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49667-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49668-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49669-
49670-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49671-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49672-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49673-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49674-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49675-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49676-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49677-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49678-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49679-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49680-
49681-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49682-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49683-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49684-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49685-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49686-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49687-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49688-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49689-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49690-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49691-
49692-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49693-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49694-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49695-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49696-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49697-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49698-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49699-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49700-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49701-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49702-
49703-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49704-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49705-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49706-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49707-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49708-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49709-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49710-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49711-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49712-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49713-
49714-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49715-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49716-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49717-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49718-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49719-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49720-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49721-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49722-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49723-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49724-
49725-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49726-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49727-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49728-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49729-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49730-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49731-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49732-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49733-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49734-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49735-
49736-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49737-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49738-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49739-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49740-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49741-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49742-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49743-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49744-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49745-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49746-
49747-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49748-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49749-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49750-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49751-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49752-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49753-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49754-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49755-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49756-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49757-
49758-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49759-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49760-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49761-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49762-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49763-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49764-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49765-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49766-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49767-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49768-
49769-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49770-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49771-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49772-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49773-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49774-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49775-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49776-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49777-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49778-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49779-
49780-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49781-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49782-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49783-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49784-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49785-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49786-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49787-18 18 18 6 6 6 0 0 0 0 0 0 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 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 0 0 0 0 0 0 0 0 0 0 0 0
49790-
49791-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49792-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49793-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49794-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49795-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49796-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49797-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49798-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49799-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49801-
49802-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49803-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49805-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49806-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49807-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49808-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49809-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49810-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49811-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49812-
49813-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49814-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49817-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49818-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49819-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49820-74 74 74 34 34 34 14 14 14 0 0 0 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 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 0 0 0 0 0 0 0 0 0 0 0 0
49823-
49824-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49825-18 25 28 35 52 58 17 23 26 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49828-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49829-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49830-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49831-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49832-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49833-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49834-
49835-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49836-52 72 81 36 54 60 6 8 8 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49838-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49839-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49840-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49841-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49842-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49843-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49844-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49845-
49846-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49847-36 54 60 29 43 47 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 6 6 6
49849-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49850-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49851-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49852-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49853-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49854-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49855-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49856-
49857-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49858-21 30 33 35 52 58 6 8 12 0 0 0 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 0 0 0 0 0 0 0 0 0 14 14 14
49860-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49861-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
49862-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49863-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49864-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49865-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49867-
49868-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49869-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49870-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49871-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49872-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49873-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49874-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49875-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49876-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49878-
49879-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49880-0 0 0 21 30 33 35 52 58 6 8 12 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 0 0 0 6 6 6 22 22 22 50 50 50
49882-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49883-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49884-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49885-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49886-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49887-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49889-
49890-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49891-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49892-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49893-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49894-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49895-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49896-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49897-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49898-6 6 6 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49900-
49901-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49902-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49903-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49904-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49905-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49906-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49907-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49908-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49909-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49910-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49911-
49912-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49913-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49914-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49915-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49916-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49917-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49918-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49919-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49920-18 18 18 6 6 6 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49922-
49923-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49924-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
49925-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49926-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49927-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
49928-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
49929-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49930-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49931-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49932-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49933-
49934-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49935-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
49936-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49937-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
49938-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49939-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49940-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49941-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49942-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49943-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49944-
49945-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 12 17 20 33 49 54 17 23 26
49947-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49948-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49949-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49950-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49951-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49952-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49953-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49954-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49955-
49956-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 15 22 25 36 54 60
49958-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49959-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49960-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49961-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49962-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49963-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49964-78 78 78 30 30 30 10 10 10 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49966-
49967-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49968-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
49969-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49970-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49971-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49972-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49973-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
49974-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49975-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49976-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49977-
49978-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49980-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49981-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49982-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49983-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49984-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
49985-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49986-74 74 74 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0 0 0 0
49988-
49989-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49990-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49991-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49992-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49993-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49994-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49995-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
49996-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49997-42 42 42 74 74 74 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0 0 0 0
49999-
50000-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
50002-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50003-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50004-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50005-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50006-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50007-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50008-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50009-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50010-
50011-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50012-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50013-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50014-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50015-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50016-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50017-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50018-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50019-6 6 6 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0 0 0 0
50021-
50022-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50023-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50024-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50025-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50026-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50027-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50028-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50029-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50030-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50031-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50032-
50033-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50034-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50035-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50036-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50037-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50038-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50039-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50040-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50041-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50042-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50043-
50044-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 10 10 10
50046-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50047-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50048-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50049-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50050-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50051-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50052-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50053-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50054-
50055-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50056-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50057-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50058-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50059-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50060-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50061-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50062-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50063-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50064-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50065-
50066-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 6 6 6 18 18 18
50068-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50069-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50070-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50071-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50072-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50073-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50074-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50075-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50076-
50077-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 6 6 6 22 22 22
50079-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50080-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50081-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50082-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50083-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50084-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50085-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50086-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50087-
50088-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50089-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50090-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50091-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50092-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50093-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50094-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50095-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50096-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50097-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50098-
50099-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50100-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50101-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50102-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50103-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50104-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50105-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50106-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50107-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50108-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50109-
50110-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50111-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50112-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50113-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50114-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50115-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50116-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50117-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50118-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50119-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50120-
50121-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50122-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50123-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50124-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50125-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50126-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50127-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50128-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50129-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50130-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50131-
50132-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50133-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50134-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50135-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50136-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50137-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50138-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50139-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50140-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50141-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50142-
50143-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50144-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50145-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50146-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50147-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50148-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50149-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50150-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50151-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50152-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50153-
50154-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50155-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50156-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50157-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50158-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50159-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50160-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50161-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50162-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50163-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50164-
50165-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50166-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50167-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50168-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50169-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50170-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50171-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50172-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50173-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50174-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50175-
50176-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50177-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50178-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50179-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50180-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50181-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50182-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50183-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50184-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50185-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50186-
50187-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50188-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50189-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50190-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50191-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50192-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50193-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50194-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50195-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50196-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50197-
50198-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50199-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50200-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50201-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50202-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50203-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50204-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50205-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50206-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50207-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50208-
50209-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50210-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50211-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50212-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50213-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50214-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50215-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50216-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50217-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50218-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50219-
50220-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50221-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50222-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50223-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50224-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50225-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50226-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50227-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50228-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50229-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50230-
50231-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50232-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50233-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50234-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50235-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50236-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50237-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50238-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50239-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50240-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50241-
50242-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50243-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50244-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50245-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50246-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50247-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50248-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50249-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50250-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50251-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50252-
50253-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50254-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50255-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50256-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50257-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50258-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50259-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50260-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50261-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50262-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50263-
50264-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50265-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50266-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50267-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50268-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50269-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50270-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50271-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50272-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50273-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50274-
50275-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50276-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50277-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50278-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50279-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50280-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50281-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50282-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50283-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50284-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50285-
50286-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50287-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50288-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50289-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50290-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50291-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50292-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50293-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50294-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50295-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50296-
50297-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50298-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50299-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50300-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50301-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50302-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50303-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50304-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50305-50 50 50 30 30 30 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0 0 0
50307-
50308-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50309-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50310-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50311-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50312-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50313-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50314-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50315-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50316-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50317-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50318-
50319-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50320-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50321-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50322-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50323-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50324-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50325-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50326-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50327-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50328-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50329-
50330-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50331-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50332-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50333-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50334-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50335-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50336-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50337-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50338-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
50340-
50341-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
50343-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50344-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50345-30 30 30 14 14 14 6 6 6 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
50347-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50348-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50349-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50350-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50351-
50352-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50353-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50354-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50355-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50356-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50357-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50358-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50359-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50360-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50361-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50362-
50363-0 0 0 0 0 0 0 0 0 0 0 0 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 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 0 0 0 0 0 0 0 0 0 6 6 6
50366-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50367-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50368-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50369-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50370-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50371-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50372-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50373-
50374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50387+4 4 4 4 4 4
50388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50401+4 4 4 4 4 4
50402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50415+4 4 4 4 4 4
50416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50429+4 4 4 4 4 4
50430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50443+4 4 4 4 4 4
50444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50457+4 4 4 4 4 4
50458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50462+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50463+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
50464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50467+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50468+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50469+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50471+4 4 4 4 4 4
50472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50476+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50477+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50478+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50481+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50482+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50483+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50484+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50485+4 4 4 4 4 4
50486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50490+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50491+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50492+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50495+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50496+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50497+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50498+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50499+4 4 4 4 4 4
50500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50503+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50504+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50505+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50506+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50508+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50509+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50510+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50511+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50512+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50513+4 4 4 4 4 4
50514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50517+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50518+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50519+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50520+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50521+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50522+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50523+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50524+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50525+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50526+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50527+4 4 4 4 4 4
50528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50531+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50532+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50533+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50534+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50535+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50536+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50537+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50538+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50539+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50540+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50541+4 4 4 4 4 4
50542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50544+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50545+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50546+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50547+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50548+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50549+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50550+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50551+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50552+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50553+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50554+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50555+4 4 4 4 4 4
50556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50558+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50559+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50560+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50561+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50562+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50563+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50564+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50565+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50566+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50567+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50568+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50569+4 4 4 4 4 4
50570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50572+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50573+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50574+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50575+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50576+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50577+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50578+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50579+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50580+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50581+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50582+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50583+4 4 4 4 4 4
50584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50586+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50587+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50588+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50589+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50590+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50591+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50592+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50593+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50594+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50595+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50596+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50597+4 4 4 4 4 4
50598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50599+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50600+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50601+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50602+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50603+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50604+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50605+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50606+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50607+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50608+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50609+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50610+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50611+4 4 4 4 4 4
50612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50613+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50614+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50615+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50616+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50617+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50618+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50619+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50620+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50621+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50622+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50623+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50624+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50625+0 0 0 4 4 4
50626+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50627+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50628+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50629+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50630+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50631+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50632+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50633+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50634+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50635+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50636+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50637+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50638+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50639+2 0 0 0 0 0
50640+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50641+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50642+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50643+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50644+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50645+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50646+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50647+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50648+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50649+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50650+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50651+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50652+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50653+37 38 37 0 0 0
50654+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50655+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50656+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50657+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50658+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50659+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50660+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50661+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50662+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50663+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50664+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50665+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50666+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50667+85 115 134 4 0 0
50668+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50669+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50670+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50671+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50672+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50673+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50674+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50675+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50676+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50677+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50678+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50679+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50680+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50681+60 73 81 4 0 0
50682+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50683+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50684+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50685+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50686+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50687+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50688+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50689+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50690+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50691+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50692+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50693+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50694+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50695+16 19 21 4 0 0
50696+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50697+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50698+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50699+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50700+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50701+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50702+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50703+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50704+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50705+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50706+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50707+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50708+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50709+4 0 0 4 3 3
50710+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50711+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50712+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50714+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50715+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50716+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50717+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50718+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50719+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50720+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50721+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50722+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50723+3 2 2 4 4 4
50724+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50725+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50726+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50727+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50728+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50729+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50730+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50731+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50732+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50733+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50734+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50735+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50736+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50737+4 4 4 4 4 4
50738+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50739+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50740+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50741+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50742+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50743+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50744+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50745+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50746+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50747+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50748+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50749+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50750+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50751+4 4 4 4 4 4
50752+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50753+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50754+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50755+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50756+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50757+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50758+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50759+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50760+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50761+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50762+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50763+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50764+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50765+5 5 5 5 5 5
50766+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50767+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50768+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50769+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50770+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50771+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50772+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50773+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50774+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50775+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50776+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50777+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50778+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50779+5 5 5 4 4 4
50780+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50781+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50782+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50783+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50784+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50785+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50786+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50787+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50788+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50789+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50790+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50791+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50793+4 4 4 4 4 4
50794+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50795+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50796+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50797+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50798+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50799+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50800+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50801+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50802+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50803+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50804+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50805+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50807+4 4 4 4 4 4
50808+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50809+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50810+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50811+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50812+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50813+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50814+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50815+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50816+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50817+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50818+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50821+4 4 4 4 4 4
50822+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50823+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50824+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50825+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50826+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50827+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50828+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50829+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50830+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50831+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50832+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
50833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50835+4 4 4 4 4 4
50836+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50837+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50838+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50839+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50840+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50841+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50842+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50843+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50844+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50845+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50846+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50849+4 4 4 4 4 4
50850+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50851+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50852+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50853+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50854+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50855+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50856+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50857+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50858+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50859+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50860+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50863+4 4 4 4 4 4
50864+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50865+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50866+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50867+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50868+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50869+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50870+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50871+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50872+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50873+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50874+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50877+4 4 4 4 4 4
50878+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50879+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50880+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50881+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50882+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50883+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50884+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50885+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50886+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50887+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50888+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50891+4 4 4 4 4 4
50892+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50893+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50894+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50895+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50896+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50897+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50898+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50899+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50900+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50901+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50902+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50905+4 4 4 4 4 4
50906+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50907+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50908+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50909+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50910+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50911+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50912+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50913+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50914+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50915+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50916+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50919+4 4 4 4 4 4
50920+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50921+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50922+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50923+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50924+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50925+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50926+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50927+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50928+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50929+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50930+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50933+4 4 4 4 4 4
50934+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50935+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50936+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50937+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50938+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50939+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50940+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50941+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50942+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50943+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50944+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50947+4 4 4 4 4 4
50948+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50949+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50950+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50951+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50952+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50953+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50954+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50955+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50956+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50957+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50958+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50961+4 4 4 4 4 4
50962+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50963+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50964+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50965+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50966+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50967+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50968+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50969+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50970+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50971+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50972+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50975+4 4 4 4 4 4
50976+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50977+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50978+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50979+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50980+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50981+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50982+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50983+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50984+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50985+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50986+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50989+4 4 4 4 4 4
50990+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50991+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50992+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50993+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50994+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50995+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50996+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50997+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50998+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50999+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51000+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51003+4 4 4 4 4 4
51004+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51005+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51006+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51007+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51008+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51009+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51010+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51011+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51012+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51013+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51014+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51017+4 4 4 4 4 4
51018+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51019+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51020+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51021+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51022+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51023+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51024+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51025+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51026+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51027+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51028+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51031+4 4 4 4 4 4
51032+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51033+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51034+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51035+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51036+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51037+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51038+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51039+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51040+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51041+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51042+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51045+4 4 4 4 4 4
51046+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51047+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51048+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51049+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51050+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51051+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51052+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51053+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51054+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51055+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51056+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51059+4 4 4 4 4 4
51060+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51061+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51062+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51063+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51064+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51065+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51066+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51067+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51068+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51069+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51070+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51073+4 4 4 4 4 4
51074+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51075+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51076+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51077+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51078+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51079+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51080+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51081+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51082+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51083+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51084+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51087+4 4 4 4 4 4
51088+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51089+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51090+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51091+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51092+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51093+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51094+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51095+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51096+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51097+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51098+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51101+4 4 4 4 4 4
51102+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51103+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51104+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51105+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51106+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51107+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51108+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51109+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51110+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51111+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51112+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51115+4 4 4 4 4 4
51116+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51117+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51118+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51119+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51120+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51121+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51122+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51123+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51124+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51125+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51126+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51129+4 4 4 4 4 4
51130+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51131+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51132+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51133+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51134+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51135+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51136+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51137+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51138+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51139+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51140+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51143+4 4 4 4 4 4
51144+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51145+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51146+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51147+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51148+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51149+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51150+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51151+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51152+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51153+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51154+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51157+4 4 4 4 4 4
51158+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51159+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51160+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51161+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51162+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51163+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51164+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51165+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51166+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51167+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51168+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51171+4 4 4 4 4 4
51172+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51173+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51174+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51175+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51176+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51177+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51178+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51179+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51180+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51181+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51182+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51185+4 4 4 4 4 4
51186+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51187+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51188+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51189+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51190+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51191+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51192+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51193+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51194+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51195+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51199+4 4 4 4 4 4
51200+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51201+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51202+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51203+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51204+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51205+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51206+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51207+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51208+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51209+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51213+4 4 4 4 4 4
51214+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51215+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51216+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51217+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51218+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51219+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51220+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51221+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51222+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51223+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51227+4 4 4 4 4 4
51228+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51229+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51230+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51231+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51232+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51233+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51234+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51235+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51236+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51237+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51241+4 4 4 4 4 4
51242+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51243+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51244+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51245+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51246+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51247+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51248+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51249+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51250+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51255+4 4 4 4 4 4
51256+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51257+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51258+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51259+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51260+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51261+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51262+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51263+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51264+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51269+4 4 4 4 4 4
51270+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51271+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51272+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51273+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51274+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51275+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51276+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51277+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51278+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51283+4 4 4 4 4 4
51284+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51285+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51286+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51287+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51288+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51289+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51290+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51291+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51297+4 4 4 4 4 4
51298+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51299+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51300+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51301+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51302+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51303+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51304+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51305+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51311+4 4 4 4 4 4
51312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51313+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51314+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51315+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51316+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51317+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51318+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51319+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51325+4 4 4 4 4 4
51326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51327+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51328+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51329+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51330+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51331+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51332+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51333+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51339+4 4 4 4 4 4
51340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51341+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51342+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51343+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51344+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51345+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51346+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51347+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51353+4 4 4 4 4 4
51354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51356+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51357+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51358+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51359+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51360+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51361+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51367+4 4 4 4 4 4
51368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51371+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51372+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51373+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51374+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51381+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51386+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51387+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51388+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 5 5 5 4 3 3 5 5 5 6 6 6
51400+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51401+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51402+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 5 5 5 4 3 3 5 5 5
51414+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51415+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51416+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 5 5 5
51428+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51429+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51430+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51443+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51444+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51457+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51458+5 5 5 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 5 5 5 4 3 3 6 6 6
51471+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51479+4 4 4 4 4 4
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 4 4 4 4 4 4 5 5 5 4 3 3
51485+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51486+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
51490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51493+4 4 4 4 4 4
51494diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51495index fe92eed..106e085 100644
51496--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51497+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51498@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51499 struct mb862xxfb_par *par = info->par;
51500
51501 if (info->var.bits_per_pixel == 32) {
51502- info->fbops->fb_fillrect = cfb_fillrect;
51503- info->fbops->fb_copyarea = cfb_copyarea;
51504- info->fbops->fb_imageblit = cfb_imageblit;
51505+ pax_open_kernel();
51506+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51507+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51508+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51509+ pax_close_kernel();
51510 } else {
51511 outreg(disp, GC_L0EM, 3);
51512- info->fbops->fb_fillrect = mb86290fb_fillrect;
51513- info->fbops->fb_copyarea = mb86290fb_copyarea;
51514- info->fbops->fb_imageblit = mb86290fb_imageblit;
51515+ pax_open_kernel();
51516+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51517+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51518+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51519+ pax_close_kernel();
51520 }
51521 outreg(draw, GDC_REG_DRAW_BASE, 0);
51522 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51523diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51524index ff22871..b129bed 100644
51525--- a/drivers/video/nvidia/nvidia.c
51526+++ b/drivers/video/nvidia/nvidia.c
51527@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51528 info->fix.line_length = (info->var.xres_virtual *
51529 info->var.bits_per_pixel) >> 3;
51530 if (info->var.accel_flags) {
51531- info->fbops->fb_imageblit = nvidiafb_imageblit;
51532- info->fbops->fb_fillrect = nvidiafb_fillrect;
51533- info->fbops->fb_copyarea = nvidiafb_copyarea;
51534- info->fbops->fb_sync = nvidiafb_sync;
51535+ pax_open_kernel();
51536+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51537+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51538+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51539+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51540+ pax_close_kernel();
51541 info->pixmap.scan_align = 4;
51542 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51543 info->flags |= FBINFO_READS_FAST;
51544 NVResetGraphics(info);
51545 } else {
51546- info->fbops->fb_imageblit = cfb_imageblit;
51547- info->fbops->fb_fillrect = cfb_fillrect;
51548- info->fbops->fb_copyarea = cfb_copyarea;
51549- info->fbops->fb_sync = NULL;
51550+ pax_open_kernel();
51551+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51552+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51553+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51554+ *(void **)&info->fbops->fb_sync = NULL;
51555+ pax_close_kernel();
51556 info->pixmap.scan_align = 1;
51557 info->flags |= FBINFO_HWACCEL_DISABLED;
51558 info->flags &= ~FBINFO_READS_FAST;
51559@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51560 info->pixmap.size = 8 * 1024;
51561 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51562
51563- if (!hwcur)
51564- info->fbops->fb_cursor = NULL;
51565+ if (!hwcur) {
51566+ pax_open_kernel();
51567+ *(void **)&info->fbops->fb_cursor = NULL;
51568+ pax_close_kernel();
51569+ }
51570
51571 info->var.accel_flags = (!noaccel);
51572
51573diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51574index 05c2dc3..ea1f391 100644
51575--- a/drivers/video/s1d13xxxfb.c
51576+++ b/drivers/video/s1d13xxxfb.c
51577@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51578
51579 switch(prod_id) {
51580 case S1D13506_PROD_ID: /* activate acceleration */
51581- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51582- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51583+ pax_open_kernel();
51584+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51585+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51586+ pax_close_kernel();
51587 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51588 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51589 break;
51590diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51591index e188ada..aac63c8 100644
51592--- a/drivers/video/smscufx.c
51593+++ b/drivers/video/smscufx.c
51594@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51595 fb_deferred_io_cleanup(info);
51596 kfree(info->fbdefio);
51597 info->fbdefio = NULL;
51598- info->fbops->fb_mmap = ufx_ops_mmap;
51599+ pax_open_kernel();
51600+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51601+ pax_close_kernel();
51602 }
51603
51604 pr_debug("released /dev/fb%d user=%d count=%d",
51605diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51606index d2e5bc3..4cb05d1 100644
51607--- a/drivers/video/udlfb.c
51608+++ b/drivers/video/udlfb.c
51609@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51610 dlfb_urb_completion(urb);
51611
51612 error:
51613- atomic_add(bytes_sent, &dev->bytes_sent);
51614- atomic_add(bytes_identical, &dev->bytes_identical);
51615- atomic_add(width*height*2, &dev->bytes_rendered);
51616+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51617+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51618+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51619 end_cycles = get_cycles();
51620- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51621+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51622 >> 10)), /* Kcycles */
51623 &dev->cpu_kcycles_used);
51624
51625@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51626 dlfb_urb_completion(urb);
51627
51628 error:
51629- atomic_add(bytes_sent, &dev->bytes_sent);
51630- atomic_add(bytes_identical, &dev->bytes_identical);
51631- atomic_add(bytes_rendered, &dev->bytes_rendered);
51632+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51633+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51634+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51635 end_cycles = get_cycles();
51636- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51637+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51638 >> 10)), /* Kcycles */
51639 &dev->cpu_kcycles_used);
51640 }
51641@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51642 fb_deferred_io_cleanup(info);
51643 kfree(info->fbdefio);
51644 info->fbdefio = NULL;
51645- info->fbops->fb_mmap = dlfb_ops_mmap;
51646+ pax_open_kernel();
51647+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51648+ pax_close_kernel();
51649 }
51650
51651 pr_warn("released /dev/fb%d user=%d count=%d\n",
51652@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51653 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51654 struct dlfb_data *dev = fb_info->par;
51655 return snprintf(buf, PAGE_SIZE, "%u\n",
51656- atomic_read(&dev->bytes_rendered));
51657+ atomic_read_unchecked(&dev->bytes_rendered));
51658 }
51659
51660 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51661@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51662 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51663 struct dlfb_data *dev = fb_info->par;
51664 return snprintf(buf, PAGE_SIZE, "%u\n",
51665- atomic_read(&dev->bytes_identical));
51666+ atomic_read_unchecked(&dev->bytes_identical));
51667 }
51668
51669 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51670@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51671 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51672 struct dlfb_data *dev = fb_info->par;
51673 return snprintf(buf, PAGE_SIZE, "%u\n",
51674- atomic_read(&dev->bytes_sent));
51675+ atomic_read_unchecked(&dev->bytes_sent));
51676 }
51677
51678 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51679@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51680 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51681 struct dlfb_data *dev = fb_info->par;
51682 return snprintf(buf, PAGE_SIZE, "%u\n",
51683- atomic_read(&dev->cpu_kcycles_used));
51684+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51685 }
51686
51687 static ssize_t edid_show(
51688@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51689 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51690 struct dlfb_data *dev = fb_info->par;
51691
51692- atomic_set(&dev->bytes_rendered, 0);
51693- atomic_set(&dev->bytes_identical, 0);
51694- atomic_set(&dev->bytes_sent, 0);
51695- atomic_set(&dev->cpu_kcycles_used, 0);
51696+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51697+ atomic_set_unchecked(&dev->bytes_identical, 0);
51698+ atomic_set_unchecked(&dev->bytes_sent, 0);
51699+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51700
51701 return count;
51702 }
51703diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51704index 7aec6f3..e3b2d55 100644
51705--- a/drivers/video/uvesafb.c
51706+++ b/drivers/video/uvesafb.c
51707@@ -19,6 +19,7 @@
51708 #include <linux/io.h>
51709 #include <linux/mutex.h>
51710 #include <linux/slab.h>
51711+#include <linux/moduleloader.h>
51712 #include <video/edid.h>
51713 #include <video/uvesafb.h>
51714 #ifdef CONFIG_X86
51715@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51716 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51717 par->pmi_setpal = par->ypan = 0;
51718 } else {
51719+
51720+#ifdef CONFIG_PAX_KERNEXEC
51721+#ifdef CONFIG_MODULES
51722+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51723+#endif
51724+ if (!par->pmi_code) {
51725+ par->pmi_setpal = par->ypan = 0;
51726+ return 0;
51727+ }
51728+#endif
51729+
51730 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51731 + task->t.regs.edi);
51732+
51733+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51734+ pax_open_kernel();
51735+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51736+ pax_close_kernel();
51737+
51738+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51739+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51740+#else
51741 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51742 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51743+#endif
51744+
51745 printk(KERN_INFO "uvesafb: protected mode interface info at "
51746 "%04x:%04x\n",
51747 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51748@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51749 par->ypan = ypan;
51750
51751 if (par->pmi_setpal || par->ypan) {
51752+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51753 if (__supported_pte_mask & _PAGE_NX) {
51754 par->pmi_setpal = par->ypan = 0;
51755 printk(KERN_WARNING "uvesafb: NX protection is active, "
51756 "better not use the PMI.\n");
51757- } else {
51758+ } else
51759+#endif
51760 uvesafb_vbe_getpmi(task, par);
51761- }
51762 }
51763 #else
51764 /* The protected mode interface is not available on non-x86. */
51765@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51766 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51767
51768 /* Disable blanking if the user requested so. */
51769- if (!blank)
51770- info->fbops->fb_blank = NULL;
51771+ if (!blank) {
51772+ pax_open_kernel();
51773+ *(void **)&info->fbops->fb_blank = NULL;
51774+ pax_close_kernel();
51775+ }
51776
51777 /*
51778 * Find out how much IO memory is required for the mode with
51779@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51780 info->flags = FBINFO_FLAG_DEFAULT |
51781 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51782
51783- if (!par->ypan)
51784- info->fbops->fb_pan_display = NULL;
51785+ if (!par->ypan) {
51786+ pax_open_kernel();
51787+ *(void **)&info->fbops->fb_pan_display = NULL;
51788+ pax_close_kernel();
51789+ }
51790 }
51791
51792 static void uvesafb_init_mtrr(struct fb_info *info)
51793@@ -1796,6 +1826,11 @@ out:
51794 if (par->vbe_modes)
51795 kfree(par->vbe_modes);
51796
51797+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51798+ if (par->pmi_code)
51799+ module_free_exec(NULL, par->pmi_code);
51800+#endif
51801+
51802 framebuffer_release(info);
51803 return err;
51804 }
51805@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51806 kfree(par->vbe_state_orig);
51807 if (par->vbe_state_saved)
51808 kfree(par->vbe_state_saved);
51809+
51810+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51811+ if (par->pmi_code)
51812+ module_free_exec(NULL, par->pmi_code);
51813+#endif
51814+
51815 }
51816
51817 framebuffer_release(info);
51818diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51819index 501b340..d80aa17 100644
51820--- a/drivers/video/vesafb.c
51821+++ b/drivers/video/vesafb.c
51822@@ -9,6 +9,7 @@
51823 */
51824
51825 #include <linux/module.h>
51826+#include <linux/moduleloader.h>
51827 #include <linux/kernel.h>
51828 #include <linux/errno.h>
51829 #include <linux/string.h>
51830@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51831 static int vram_total __initdata; /* Set total amount of memory */
51832 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51833 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51834-static void (*pmi_start)(void) __read_mostly;
51835-static void (*pmi_pal) (void) __read_mostly;
51836+static void (*pmi_start)(void) __read_only;
51837+static void (*pmi_pal) (void) __read_only;
51838 static int depth __read_mostly;
51839 static int vga_compat __read_mostly;
51840 /* --------------------------------------------------------------------- */
51841@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51842 unsigned int size_vmode;
51843 unsigned int size_remap;
51844 unsigned int size_total;
51845+ void *pmi_code = NULL;
51846
51847 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51848 return -ENODEV;
51849@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51850 size_remap = size_total;
51851 vesafb_fix.smem_len = size_remap;
51852
51853-#ifndef __i386__
51854- screen_info.vesapm_seg = 0;
51855-#endif
51856-
51857 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51858 printk(KERN_WARNING
51859 "vesafb: cannot reserve video memory at 0x%lx\n",
51860@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51861 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51862 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51863
51864+#ifdef __i386__
51865+
51866+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51867+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51868+ if (!pmi_code)
51869+#elif !defined(CONFIG_PAX_KERNEXEC)
51870+ if (0)
51871+#endif
51872+
51873+#endif
51874+ screen_info.vesapm_seg = 0;
51875+
51876 if (screen_info.vesapm_seg) {
51877- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51878- screen_info.vesapm_seg,screen_info.vesapm_off);
51879+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51880+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51881 }
51882
51883 if (screen_info.vesapm_seg < 0xc000)
51884@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51885
51886 if (ypan || pmi_setpal) {
51887 unsigned short *pmi_base;
51888+
51889 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51890- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51891- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51892+
51893+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51894+ pax_open_kernel();
51895+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51896+#else
51897+ pmi_code = pmi_base;
51898+#endif
51899+
51900+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51901+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51902+
51903+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51904+ pmi_start = ktva_ktla(pmi_start);
51905+ pmi_pal = ktva_ktla(pmi_pal);
51906+ pax_close_kernel();
51907+#endif
51908+
51909 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51910 if (pmi_base[3]) {
51911 printk(KERN_INFO "vesafb: pmi: ports = ");
51912@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51913 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51914 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51915
51916- if (!ypan)
51917- info->fbops->fb_pan_display = NULL;
51918+ if (!ypan) {
51919+ pax_open_kernel();
51920+ *(void **)&info->fbops->fb_pan_display = NULL;
51921+ pax_close_kernel();
51922+ }
51923
51924 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51925 err = -ENOMEM;
51926@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51927 info->node, info->fix.id);
51928 return 0;
51929 err:
51930+
51931+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51932+ module_free_exec(NULL, pmi_code);
51933+#endif
51934+
51935 if (info->screen_base)
51936 iounmap(info->screen_base);
51937 framebuffer_release(info);
51938diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51939index 88714ae..16c2e11 100644
51940--- a/drivers/video/via/via_clock.h
51941+++ b/drivers/video/via/via_clock.h
51942@@ -56,7 +56,7 @@ struct via_clock {
51943
51944 void (*set_engine_pll_state)(u8 state);
51945 void (*set_engine_pll)(struct via_pll_config config);
51946-};
51947+} __no_const;
51948
51949
51950 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51951diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51952index fef20db..d28b1ab 100644
51953--- a/drivers/xen/xenfs/xenstored.c
51954+++ b/drivers/xen/xenfs/xenstored.c
51955@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51956 static int xsd_kva_open(struct inode *inode, struct file *file)
51957 {
51958 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51959+#ifdef CONFIG_GRKERNSEC_HIDESYM
51960+ NULL);
51961+#else
51962 xen_store_interface);
51963+#endif
51964+
51965 if (!file->private_data)
51966 return -ENOMEM;
51967 return 0;
51968diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51969index 9ff073f..05cef23 100644
51970--- a/fs/9p/vfs_addr.c
51971+++ b/fs/9p/vfs_addr.c
51972@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51973
51974 retval = v9fs_file_write_internal(inode,
51975 v9inode->writeback_fid,
51976- (__force const char __user *)buffer,
51977+ (const char __force_user *)buffer,
51978 len, &offset, 0);
51979 if (retval > 0)
51980 retval = 0;
51981diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51982index 25b018e..b941525 100644
51983--- a/fs/9p/vfs_inode.c
51984+++ b/fs/9p/vfs_inode.c
51985@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51986 void
51987 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51988 {
51989- char *s = nd_get_link(nd);
51990+ const char *s = nd_get_link(nd);
51991
51992 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51993 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51994diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51995index 370b24c..ff0be7b 100644
51996--- a/fs/Kconfig.binfmt
51997+++ b/fs/Kconfig.binfmt
51998@@ -103,7 +103,7 @@ config HAVE_AOUT
51999
52000 config BINFMT_AOUT
52001 tristate "Kernel support for a.out and ECOFF binaries"
52002- depends on HAVE_AOUT
52003+ depends on HAVE_AOUT && BROKEN
52004 ---help---
52005 A.out (Assembler.OUTput) is a set of formats for libraries and
52006 executables used in the earliest versions of UNIX. Linux used
52007diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52008index 789bc25..fafaeea 100644
52009--- a/fs/afs/inode.c
52010+++ b/fs/afs/inode.c
52011@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52012 struct afs_vnode *vnode;
52013 struct super_block *sb;
52014 struct inode *inode;
52015- static atomic_t afs_autocell_ino;
52016+ static atomic_unchecked_t afs_autocell_ino;
52017
52018 _enter("{%x:%u},%*.*s,",
52019 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52020@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52021 data.fid.unique = 0;
52022 data.fid.vnode = 0;
52023
52024- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52025+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52026 afs_iget5_autocell_test, afs_iget5_set,
52027 &data);
52028 if (!inode) {
52029diff --git a/fs/aio.c b/fs/aio.c
52030index 9b5ca11..c530886 100644
52031--- a/fs/aio.c
52032+++ b/fs/aio.c
52033@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52034 size += sizeof(struct io_event) * nr_events;
52035 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52036
52037- if (nr_pages < 0)
52038+ if (nr_pages <= 0)
52039 return -EINVAL;
52040
52041 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52042@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52043 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52044 {
52045 ssize_t ret;
52046+ struct iovec iovstack;
52047
52048 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52049
52050@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52051 if (compat)
52052 ret = compat_rw_copy_check_uvector(rw,
52053 (struct compat_iovec __user *)kiocb->ki_buf,
52054- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52055+ kiocb->ki_nr_segs, 1, &iovstack,
52056 &kiocb->ki_iovec);
52057 else
52058 #endif
52059 ret = rw_copy_check_uvector(rw,
52060 (struct iovec __user *)kiocb->ki_buf,
52061- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52062+ kiocb->ki_nr_segs, 1, &iovstack,
52063 &kiocb->ki_iovec);
52064 if (ret < 0)
52065 return ret;
52066
52067+ if (kiocb->ki_iovec == &iovstack) {
52068+ kiocb->ki_inline_vec = iovstack;
52069+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52070+ }
52071+
52072 /* ki_nbytes now reflect bytes instead of segs */
52073 kiocb->ki_nbytes = ret;
52074 return 0;
52075diff --git a/fs/attr.c b/fs/attr.c
52076index 1449adb..a2038c2 100644
52077--- a/fs/attr.c
52078+++ b/fs/attr.c
52079@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52080 unsigned long limit;
52081
52082 limit = rlimit(RLIMIT_FSIZE);
52083+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52084 if (limit != RLIM_INFINITY && offset > limit)
52085 goto out_sig;
52086 if (offset > inode->i_sb->s_maxbytes)
52087diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52088index 3db70da..7aeec5b 100644
52089--- a/fs/autofs4/waitq.c
52090+++ b/fs/autofs4/waitq.c
52091@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52092 {
52093 unsigned long sigpipe, flags;
52094 mm_segment_t fs;
52095- const char *data = (const char *)addr;
52096+ const char __user *data = (const char __force_user *)addr;
52097 ssize_t wr = 0;
52098
52099 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52100@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52101 return 1;
52102 }
52103
52104+#ifdef CONFIG_GRKERNSEC_HIDESYM
52105+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52106+#endif
52107+
52108 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52109 enum autofs_notify notify)
52110 {
52111@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52112
52113 /* If this is a direct mount request create a dummy name */
52114 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52115+#ifdef CONFIG_GRKERNSEC_HIDESYM
52116+ /* this name does get written to userland via autofs4_write() */
52117+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52118+#else
52119 qstr.len = sprintf(name, "%p", dentry);
52120+#endif
52121 else {
52122 qstr.len = autofs4_getpath(sbi, dentry, &name);
52123 if (!qstr.len) {
52124diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52125index 2722387..c8dd2a7 100644
52126--- a/fs/befs/endian.h
52127+++ b/fs/befs/endian.h
52128@@ -11,7 +11,7 @@
52129
52130 #include <asm/byteorder.h>
52131
52132-static inline u64
52133+static inline u64 __intentional_overflow(-1)
52134 fs64_to_cpu(const struct super_block *sb, fs64 n)
52135 {
52136 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52137@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52138 return (__force fs64)cpu_to_be64(n);
52139 }
52140
52141-static inline u32
52142+static inline u32 __intentional_overflow(-1)
52143 fs32_to_cpu(const struct super_block *sb, fs32 n)
52144 {
52145 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52146diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52147index e9c75e2..1baece1 100644
52148--- a/fs/befs/linuxvfs.c
52149+++ b/fs/befs/linuxvfs.c
52150@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52151 {
52152 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52153 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52154- char *link = nd_get_link(nd);
52155+ const char *link = nd_get_link(nd);
52156 if (!IS_ERR(link))
52157 kfree(link);
52158 }
52159diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52160index 89dec7f..361b0d75 100644
52161--- a/fs/binfmt_aout.c
52162+++ b/fs/binfmt_aout.c
52163@@ -16,6 +16,7 @@
52164 #include <linux/string.h>
52165 #include <linux/fs.h>
52166 #include <linux/file.h>
52167+#include <linux/security.h>
52168 #include <linux/stat.h>
52169 #include <linux/fcntl.h>
52170 #include <linux/ptrace.h>
52171@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52172 #endif
52173 # define START_STACK(u) ((void __user *)u.start_stack)
52174
52175+ memset(&dump, 0, sizeof(dump));
52176+
52177 fs = get_fs();
52178 set_fs(KERNEL_DS);
52179 has_dumped = 1;
52180@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52181
52182 /* If the size of the dump file exceeds the rlimit, then see what would happen
52183 if we wrote the stack, but not the data area. */
52184+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52185 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52186 dump.u_dsize = 0;
52187
52188 /* Make sure we have enough room to write the stack and data areas. */
52189+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52190 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52191 dump.u_ssize = 0;
52192
52193@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52194 rlim = rlimit(RLIMIT_DATA);
52195 if (rlim >= RLIM_INFINITY)
52196 rlim = ~0;
52197+
52198+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52199 if (ex.a_data + ex.a_bss > rlim)
52200 return -ENOMEM;
52201
52202@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52203
52204 install_exec_creds(bprm);
52205
52206+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52207+ current->mm->pax_flags = 0UL;
52208+#endif
52209+
52210+#ifdef CONFIG_PAX_PAGEEXEC
52211+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52212+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52213+
52214+#ifdef CONFIG_PAX_EMUTRAMP
52215+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52216+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52217+#endif
52218+
52219+#ifdef CONFIG_PAX_MPROTECT
52220+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52221+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52222+#endif
52223+
52224+ }
52225+#endif
52226+
52227 if (N_MAGIC(ex) == OMAGIC) {
52228 unsigned long text_addr, map_size;
52229 loff_t pos;
52230@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52231 }
52232
52233 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52234- PROT_READ | PROT_WRITE | PROT_EXEC,
52235+ PROT_READ | PROT_WRITE,
52236 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52237 fd_offset + ex.a_text);
52238 if (error != N_DATADDR(ex)) {
52239diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52240index 4c94a79..f428019 100644
52241--- a/fs/binfmt_elf.c
52242+++ b/fs/binfmt_elf.c
52243@@ -34,6 +34,7 @@
52244 #include <linux/utsname.h>
52245 #include <linux/coredump.h>
52246 #include <linux/sched.h>
52247+#include <linux/xattr.h>
52248 #include <asm/uaccess.h>
52249 #include <asm/param.h>
52250 #include <asm/page.h>
52251@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52252 #define elf_core_dump NULL
52253 #endif
52254
52255+#ifdef CONFIG_PAX_MPROTECT
52256+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52257+#endif
52258+
52259+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52260+static void elf_handle_mmap(struct file *file);
52261+#endif
52262+
52263 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52264 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52265 #else
52266@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52267 .load_binary = load_elf_binary,
52268 .load_shlib = load_elf_library,
52269 .core_dump = elf_core_dump,
52270+
52271+#ifdef CONFIG_PAX_MPROTECT
52272+ .handle_mprotect= elf_handle_mprotect,
52273+#endif
52274+
52275+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52276+ .handle_mmap = elf_handle_mmap,
52277+#endif
52278+
52279 .min_coredump = ELF_EXEC_PAGESIZE,
52280 };
52281
52282@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52283
52284 static int set_brk(unsigned long start, unsigned long end)
52285 {
52286+ unsigned long e = end;
52287+
52288 start = ELF_PAGEALIGN(start);
52289 end = ELF_PAGEALIGN(end);
52290 if (end > start) {
52291@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52292 if (BAD_ADDR(addr))
52293 return addr;
52294 }
52295- current->mm->start_brk = current->mm->brk = end;
52296+ current->mm->start_brk = current->mm->brk = e;
52297 return 0;
52298 }
52299
52300@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52301 elf_addr_t __user *u_rand_bytes;
52302 const char *k_platform = ELF_PLATFORM;
52303 const char *k_base_platform = ELF_BASE_PLATFORM;
52304- unsigned char k_rand_bytes[16];
52305+ u32 k_rand_bytes[4];
52306 int items;
52307 elf_addr_t *elf_info;
52308 int ei_index = 0;
52309 const struct cred *cred = current_cred();
52310 struct vm_area_struct *vma;
52311+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52312
52313 /*
52314 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52315@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52316 * Generate 16 random bytes for userspace PRNG seeding.
52317 */
52318 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52319- u_rand_bytes = (elf_addr_t __user *)
52320- STACK_ALLOC(p, sizeof(k_rand_bytes));
52321+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52322+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52323+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52324+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52325+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52326+ u_rand_bytes = (elf_addr_t __user *) p;
52327 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52328 return -EFAULT;
52329
52330@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52331 return -EFAULT;
52332 current->mm->env_end = p;
52333
52334+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52335+
52336 /* Put the elf_info on the stack in the right place. */
52337 sp = (elf_addr_t __user *)envp + 1;
52338- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52339+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52340 return -EFAULT;
52341 return 0;
52342 }
52343@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52344 an ELF header */
52345
52346 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52347- struct file *interpreter, unsigned long *interp_map_addr,
52348- unsigned long no_base)
52349+ struct file *interpreter, unsigned long no_base)
52350 {
52351 struct elf_phdr *elf_phdata;
52352 struct elf_phdr *eppnt;
52353- unsigned long load_addr = 0;
52354+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52355 int load_addr_set = 0;
52356 unsigned long last_bss = 0, elf_bss = 0;
52357- unsigned long error = ~0UL;
52358+ unsigned long error = -EINVAL;
52359 unsigned long total_size;
52360 int retval, i, size;
52361
52362@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52363 goto out_close;
52364 }
52365
52366+#ifdef CONFIG_PAX_SEGMEXEC
52367+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52368+ pax_task_size = SEGMEXEC_TASK_SIZE;
52369+#endif
52370+
52371 eppnt = elf_phdata;
52372 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52373 if (eppnt->p_type == PT_LOAD) {
52374@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52375 map_addr = elf_map(interpreter, load_addr + vaddr,
52376 eppnt, elf_prot, elf_type, total_size);
52377 total_size = 0;
52378- if (!*interp_map_addr)
52379- *interp_map_addr = map_addr;
52380 error = map_addr;
52381 if (BAD_ADDR(map_addr))
52382 goto out_close;
52383@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52384 k = load_addr + eppnt->p_vaddr;
52385 if (BAD_ADDR(k) ||
52386 eppnt->p_filesz > eppnt->p_memsz ||
52387- eppnt->p_memsz > TASK_SIZE ||
52388- TASK_SIZE - eppnt->p_memsz < k) {
52389+ eppnt->p_memsz > pax_task_size ||
52390+ pax_task_size - eppnt->p_memsz < k) {
52391 error = -ENOMEM;
52392 goto out_close;
52393 }
52394@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52395 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52396
52397 /* Map the last of the bss segment */
52398- error = vm_brk(elf_bss, last_bss - elf_bss);
52399- if (BAD_ADDR(error))
52400- goto out_close;
52401+ if (last_bss > elf_bss) {
52402+ error = vm_brk(elf_bss, last_bss - elf_bss);
52403+ if (BAD_ADDR(error))
52404+ goto out_close;
52405+ }
52406 }
52407
52408 error = load_addr;
52409@@ -538,6 +569,315 @@ out:
52410 return error;
52411 }
52412
52413+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52414+#ifdef CONFIG_PAX_SOFTMODE
52415+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52416+{
52417+ unsigned long pax_flags = 0UL;
52418+
52419+#ifdef CONFIG_PAX_PAGEEXEC
52420+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52421+ pax_flags |= MF_PAX_PAGEEXEC;
52422+#endif
52423+
52424+#ifdef CONFIG_PAX_SEGMEXEC
52425+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52426+ pax_flags |= MF_PAX_SEGMEXEC;
52427+#endif
52428+
52429+#ifdef CONFIG_PAX_EMUTRAMP
52430+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52431+ pax_flags |= MF_PAX_EMUTRAMP;
52432+#endif
52433+
52434+#ifdef CONFIG_PAX_MPROTECT
52435+ if (elf_phdata->p_flags & PF_MPROTECT)
52436+ pax_flags |= MF_PAX_MPROTECT;
52437+#endif
52438+
52439+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52440+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52441+ pax_flags |= MF_PAX_RANDMMAP;
52442+#endif
52443+
52444+ return pax_flags;
52445+}
52446+#endif
52447+
52448+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52449+{
52450+ unsigned long pax_flags = 0UL;
52451+
52452+#ifdef CONFIG_PAX_PAGEEXEC
52453+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52454+ pax_flags |= MF_PAX_PAGEEXEC;
52455+#endif
52456+
52457+#ifdef CONFIG_PAX_SEGMEXEC
52458+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52459+ pax_flags |= MF_PAX_SEGMEXEC;
52460+#endif
52461+
52462+#ifdef CONFIG_PAX_EMUTRAMP
52463+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52464+ pax_flags |= MF_PAX_EMUTRAMP;
52465+#endif
52466+
52467+#ifdef CONFIG_PAX_MPROTECT
52468+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52469+ pax_flags |= MF_PAX_MPROTECT;
52470+#endif
52471+
52472+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52473+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52474+ pax_flags |= MF_PAX_RANDMMAP;
52475+#endif
52476+
52477+ return pax_flags;
52478+}
52479+#endif
52480+
52481+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52482+#ifdef CONFIG_PAX_SOFTMODE
52483+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52484+{
52485+ unsigned long pax_flags = 0UL;
52486+
52487+#ifdef CONFIG_PAX_PAGEEXEC
52488+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52489+ pax_flags |= MF_PAX_PAGEEXEC;
52490+#endif
52491+
52492+#ifdef CONFIG_PAX_SEGMEXEC
52493+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52494+ pax_flags |= MF_PAX_SEGMEXEC;
52495+#endif
52496+
52497+#ifdef CONFIG_PAX_EMUTRAMP
52498+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52499+ pax_flags |= MF_PAX_EMUTRAMP;
52500+#endif
52501+
52502+#ifdef CONFIG_PAX_MPROTECT
52503+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52504+ pax_flags |= MF_PAX_MPROTECT;
52505+#endif
52506+
52507+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52508+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52509+ pax_flags |= MF_PAX_RANDMMAP;
52510+#endif
52511+
52512+ return pax_flags;
52513+}
52514+#endif
52515+
52516+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52517+{
52518+ unsigned long pax_flags = 0UL;
52519+
52520+#ifdef CONFIG_PAX_PAGEEXEC
52521+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52522+ pax_flags |= MF_PAX_PAGEEXEC;
52523+#endif
52524+
52525+#ifdef CONFIG_PAX_SEGMEXEC
52526+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52527+ pax_flags |= MF_PAX_SEGMEXEC;
52528+#endif
52529+
52530+#ifdef CONFIG_PAX_EMUTRAMP
52531+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52532+ pax_flags |= MF_PAX_EMUTRAMP;
52533+#endif
52534+
52535+#ifdef CONFIG_PAX_MPROTECT
52536+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52537+ pax_flags |= MF_PAX_MPROTECT;
52538+#endif
52539+
52540+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52541+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52542+ pax_flags |= MF_PAX_RANDMMAP;
52543+#endif
52544+
52545+ return pax_flags;
52546+}
52547+#endif
52548+
52549+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52550+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52551+{
52552+ unsigned long pax_flags = 0UL;
52553+
52554+#ifdef CONFIG_PAX_EI_PAX
52555+
52556+#ifdef CONFIG_PAX_PAGEEXEC
52557+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52558+ pax_flags |= MF_PAX_PAGEEXEC;
52559+#endif
52560+
52561+#ifdef CONFIG_PAX_SEGMEXEC
52562+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52563+ pax_flags |= MF_PAX_SEGMEXEC;
52564+#endif
52565+
52566+#ifdef CONFIG_PAX_EMUTRAMP
52567+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52568+ pax_flags |= MF_PAX_EMUTRAMP;
52569+#endif
52570+
52571+#ifdef CONFIG_PAX_MPROTECT
52572+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52573+ pax_flags |= MF_PAX_MPROTECT;
52574+#endif
52575+
52576+#ifdef CONFIG_PAX_ASLR
52577+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52578+ pax_flags |= MF_PAX_RANDMMAP;
52579+#endif
52580+
52581+#else
52582+
52583+#ifdef CONFIG_PAX_PAGEEXEC
52584+ pax_flags |= MF_PAX_PAGEEXEC;
52585+#endif
52586+
52587+#ifdef CONFIG_PAX_SEGMEXEC
52588+ pax_flags |= MF_PAX_SEGMEXEC;
52589+#endif
52590+
52591+#ifdef CONFIG_PAX_MPROTECT
52592+ pax_flags |= MF_PAX_MPROTECT;
52593+#endif
52594+
52595+#ifdef CONFIG_PAX_RANDMMAP
52596+ if (randomize_va_space)
52597+ pax_flags |= MF_PAX_RANDMMAP;
52598+#endif
52599+
52600+#endif
52601+
52602+ return pax_flags;
52603+}
52604+
52605+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52606+{
52607+
52608+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52609+ unsigned long i;
52610+
52611+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52612+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52613+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52614+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52615+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52616+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52617+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52618+ return ~0UL;
52619+
52620+#ifdef CONFIG_PAX_SOFTMODE
52621+ if (pax_softmode)
52622+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52623+ else
52624+#endif
52625+
52626+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52627+ break;
52628+ }
52629+#endif
52630+
52631+ return ~0UL;
52632+}
52633+
52634+static unsigned long pax_parse_xattr_pax(struct file * const file)
52635+{
52636+
52637+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52638+ ssize_t xattr_size, i;
52639+ unsigned char xattr_value[sizeof("pemrs") - 1];
52640+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52641+
52642+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52643+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52644+ return ~0UL;
52645+
52646+ for (i = 0; i < xattr_size; i++)
52647+ switch (xattr_value[i]) {
52648+ default:
52649+ return ~0UL;
52650+
52651+#define parse_flag(option1, option2, flag) \
52652+ case option1: \
52653+ if (pax_flags_hardmode & MF_PAX_##flag) \
52654+ return ~0UL; \
52655+ pax_flags_hardmode |= MF_PAX_##flag; \
52656+ break; \
52657+ case option2: \
52658+ if (pax_flags_softmode & MF_PAX_##flag) \
52659+ return ~0UL; \
52660+ pax_flags_softmode |= MF_PAX_##flag; \
52661+ break;
52662+
52663+ parse_flag('p', 'P', PAGEEXEC);
52664+ parse_flag('e', 'E', EMUTRAMP);
52665+ parse_flag('m', 'M', MPROTECT);
52666+ parse_flag('r', 'R', RANDMMAP);
52667+ parse_flag('s', 'S', SEGMEXEC);
52668+
52669+#undef parse_flag
52670+ }
52671+
52672+ if (pax_flags_hardmode & pax_flags_softmode)
52673+ return ~0UL;
52674+
52675+#ifdef CONFIG_PAX_SOFTMODE
52676+ if (pax_softmode)
52677+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52678+ else
52679+#endif
52680+
52681+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52682+#else
52683+ return ~0UL;
52684+#endif
52685+
52686+}
52687+
52688+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52689+{
52690+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52691+
52692+ pax_flags = pax_parse_ei_pax(elf_ex);
52693+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52694+ xattr_pax_flags = pax_parse_xattr_pax(file);
52695+
52696+ if (pt_pax_flags == ~0UL)
52697+ pt_pax_flags = xattr_pax_flags;
52698+ else if (xattr_pax_flags == ~0UL)
52699+ xattr_pax_flags = pt_pax_flags;
52700+ if (pt_pax_flags != xattr_pax_flags)
52701+ return -EINVAL;
52702+ if (pt_pax_flags != ~0UL)
52703+ pax_flags = pt_pax_flags;
52704+
52705+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52706+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52707+ if ((__supported_pte_mask & _PAGE_NX))
52708+ pax_flags &= ~MF_PAX_SEGMEXEC;
52709+ else
52710+ pax_flags &= ~MF_PAX_PAGEEXEC;
52711+ }
52712+#endif
52713+
52714+ if (0 > pax_check_flags(&pax_flags))
52715+ return -EINVAL;
52716+
52717+ current->mm->pax_flags = pax_flags;
52718+ return 0;
52719+}
52720+#endif
52721+
52722 /*
52723 * These are the functions used to load ELF style executables and shared
52724 * libraries. There is no binary dependent code anywhere else.
52725@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52726 {
52727 unsigned int random_variable = 0;
52728
52729+#ifdef CONFIG_PAX_RANDUSTACK
52730+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52731+ return stack_top - current->mm->delta_stack;
52732+#endif
52733+
52734 if ((current->flags & PF_RANDOMIZE) &&
52735 !(current->personality & ADDR_NO_RANDOMIZE)) {
52736 random_variable = get_random_int() & STACK_RND_MASK;
52737@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52738 unsigned long load_addr = 0, load_bias = 0;
52739 int load_addr_set = 0;
52740 char * elf_interpreter = NULL;
52741- unsigned long error;
52742+ unsigned long error = 0;
52743 struct elf_phdr *elf_ppnt, *elf_phdata;
52744 unsigned long elf_bss, elf_brk;
52745 int retval, i;
52746@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52747 unsigned long start_code, end_code, start_data, end_data;
52748 unsigned long reloc_func_desc __maybe_unused = 0;
52749 int executable_stack = EXSTACK_DEFAULT;
52750- unsigned long def_flags = 0;
52751 struct pt_regs *regs = current_pt_regs();
52752 struct {
52753 struct elfhdr elf_ex;
52754 struct elfhdr interp_elf_ex;
52755 } *loc;
52756+ unsigned long pax_task_size = TASK_SIZE;
52757
52758 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52759 if (!loc) {
52760@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52761 goto out_free_dentry;
52762
52763 /* OK, This is the point of no return */
52764- current->mm->def_flags = def_flags;
52765+
52766+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52767+ current->mm->pax_flags = 0UL;
52768+#endif
52769+
52770+#ifdef CONFIG_PAX_DLRESOLVE
52771+ current->mm->call_dl_resolve = 0UL;
52772+#endif
52773+
52774+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52775+ current->mm->call_syscall = 0UL;
52776+#endif
52777+
52778+#ifdef CONFIG_PAX_ASLR
52779+ current->mm->delta_mmap = 0UL;
52780+ current->mm->delta_stack = 0UL;
52781+#endif
52782+
52783+ current->mm->def_flags = 0;
52784+
52785+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52786+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52787+ send_sig(SIGKILL, current, 0);
52788+ goto out_free_dentry;
52789+ }
52790+#endif
52791+
52792+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52793+ pax_set_initial_flags(bprm);
52794+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52795+ if (pax_set_initial_flags_func)
52796+ (pax_set_initial_flags_func)(bprm);
52797+#endif
52798+
52799+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52800+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52801+ current->mm->context.user_cs_limit = PAGE_SIZE;
52802+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52803+ }
52804+#endif
52805+
52806+#ifdef CONFIG_PAX_SEGMEXEC
52807+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52808+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52809+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52810+ pax_task_size = SEGMEXEC_TASK_SIZE;
52811+ current->mm->def_flags |= VM_NOHUGEPAGE;
52812+ }
52813+#endif
52814+
52815+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52816+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52817+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52818+ put_cpu();
52819+ }
52820+#endif
52821
52822 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52823 may depend on the personality. */
52824 SET_PERSONALITY(loc->elf_ex);
52825+
52826+#ifdef CONFIG_PAX_ASLR
52827+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52828+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52829+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52830+ }
52831+#endif
52832+
52833+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52834+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52835+ executable_stack = EXSTACK_DISABLE_X;
52836+ current->personality &= ~READ_IMPLIES_EXEC;
52837+ } else
52838+#endif
52839+
52840 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52841 current->personality |= READ_IMPLIES_EXEC;
52842
52843@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52844 #else
52845 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52846 #endif
52847+
52848+#ifdef CONFIG_PAX_RANDMMAP
52849+ /* PaX: randomize base address at the default exe base if requested */
52850+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52851+#ifdef CONFIG_SPARC64
52852+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52853+#else
52854+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52855+#endif
52856+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52857+ elf_flags |= MAP_FIXED;
52858+ }
52859+#endif
52860+
52861 }
52862
52863 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52864@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52865 * allowed task size. Note that p_filesz must always be
52866 * <= p_memsz so it is only necessary to check p_memsz.
52867 */
52868- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52869- elf_ppnt->p_memsz > TASK_SIZE ||
52870- TASK_SIZE - elf_ppnt->p_memsz < k) {
52871+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52872+ elf_ppnt->p_memsz > pax_task_size ||
52873+ pax_task_size - elf_ppnt->p_memsz < k) {
52874 /* set_brk can never work. Avoid overflows. */
52875 send_sig(SIGKILL, current, 0);
52876 retval = -EINVAL;
52877@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52878 goto out_free_dentry;
52879 }
52880 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52881- send_sig(SIGSEGV, current, 0);
52882- retval = -EFAULT; /* Nobody gets to see this, but.. */
52883- goto out_free_dentry;
52884+ /*
52885+ * This bss-zeroing can fail if the ELF
52886+ * file specifies odd protections. So
52887+ * we don't check the return value
52888+ */
52889 }
52890
52891+#ifdef CONFIG_PAX_RANDMMAP
52892+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52893+ unsigned long start, size, flags;
52894+ vm_flags_t vm_flags;
52895+
52896+ start = ELF_PAGEALIGN(elf_brk);
52897+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52898+ flags = MAP_FIXED | MAP_PRIVATE;
52899+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52900+
52901+ down_write(&current->mm->mmap_sem);
52902+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52903+ retval = -ENOMEM;
52904+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52905+// if (current->personality & ADDR_NO_RANDOMIZE)
52906+// vm_flags |= VM_READ | VM_MAYREAD;
52907+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52908+ retval = IS_ERR_VALUE(start) ? start : 0;
52909+ }
52910+ up_write(&current->mm->mmap_sem);
52911+ if (retval == 0)
52912+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52913+ if (retval < 0) {
52914+ send_sig(SIGKILL, current, 0);
52915+ goto out_free_dentry;
52916+ }
52917+ }
52918+#endif
52919+
52920 if (elf_interpreter) {
52921- unsigned long interp_map_addr = 0;
52922-
52923 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52924 interpreter,
52925- &interp_map_addr,
52926 load_bias);
52927 if (!IS_ERR((void *)elf_entry)) {
52928 /*
52929@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52930 * Decide what to dump of a segment, part, all or none.
52931 */
52932 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52933- unsigned long mm_flags)
52934+ unsigned long mm_flags, long signr)
52935 {
52936 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52937
52938@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52939 if (vma->vm_file == NULL)
52940 return 0;
52941
52942- if (FILTER(MAPPED_PRIVATE))
52943+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52944 goto whole;
52945
52946 /*
52947@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52948 {
52949 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52950 int i = 0;
52951- do
52952+ do {
52953 i += 2;
52954- while (auxv[i - 2] != AT_NULL);
52955+ } while (auxv[i - 2] != AT_NULL);
52956 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52957 }
52958
52959@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52960 {
52961 mm_segment_t old_fs = get_fs();
52962 set_fs(KERNEL_DS);
52963- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52964+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52965 set_fs(old_fs);
52966 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52967 }
52968@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52969 }
52970
52971 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52972- unsigned long mm_flags)
52973+ struct coredump_params *cprm)
52974 {
52975 struct vm_area_struct *vma;
52976 size_t size = 0;
52977
52978 for (vma = first_vma(current, gate_vma); vma != NULL;
52979 vma = next_vma(vma, gate_vma))
52980- size += vma_dump_size(vma, mm_flags);
52981+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52982 return size;
52983 }
52984
52985@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52986
52987 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52988
52989- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52990+ offset += elf_core_vma_data_size(gate_vma, cprm);
52991 offset += elf_core_extra_data_size();
52992 e_shoff = offset;
52993
52994@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52995 offset = dataoff;
52996
52997 size += sizeof(*elf);
52998+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52999 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53000 goto end_coredump;
53001
53002 size += sizeof(*phdr4note);
53003+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53004 if (size > cprm->limit
53005 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53006 goto end_coredump;
53007@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53008 phdr.p_offset = offset;
53009 phdr.p_vaddr = vma->vm_start;
53010 phdr.p_paddr = 0;
53011- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53012+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53013 phdr.p_memsz = vma->vm_end - vma->vm_start;
53014 offset += phdr.p_filesz;
53015 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53016@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53017 phdr.p_align = ELF_EXEC_PAGESIZE;
53018
53019 size += sizeof(phdr);
53020+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53021 if (size > cprm->limit
53022 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53023 goto end_coredump;
53024@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53025 unsigned long addr;
53026 unsigned long end;
53027
53028- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53029+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53030
53031 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53032 struct page *page;
53033@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53034 page = get_dump_page(addr);
53035 if (page) {
53036 void *kaddr = kmap(page);
53037+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53038 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53039 !dump_write(cprm->file, kaddr,
53040 PAGE_SIZE);
53041@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53042
53043 if (e_phnum == PN_XNUM) {
53044 size += sizeof(*shdr4extnum);
53045+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53046 if (size > cprm->limit
53047 || !dump_write(cprm->file, shdr4extnum,
53048 sizeof(*shdr4extnum)))
53049@@ -2235,6 +2697,167 @@ out:
53050
53051 #endif /* CONFIG_ELF_CORE */
53052
53053+#ifdef CONFIG_PAX_MPROTECT
53054+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53055+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53056+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53057+ *
53058+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53059+ * basis because we want to allow the common case and not the special ones.
53060+ */
53061+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53062+{
53063+ struct elfhdr elf_h;
53064+ struct elf_phdr elf_p;
53065+ unsigned long i;
53066+ unsigned long oldflags;
53067+ bool is_textrel_rw, is_textrel_rx, is_relro;
53068+
53069+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53070+ return;
53071+
53072+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53073+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53074+
53075+#ifdef CONFIG_PAX_ELFRELOCS
53076+ /* possible TEXTREL */
53077+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53078+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53079+#else
53080+ is_textrel_rw = false;
53081+ is_textrel_rx = false;
53082+#endif
53083+
53084+ /* possible RELRO */
53085+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53086+
53087+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53088+ return;
53089+
53090+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53091+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53092+
53093+#ifdef CONFIG_PAX_ETEXECRELOCS
53094+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53095+#else
53096+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53097+#endif
53098+
53099+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53100+ !elf_check_arch(&elf_h) ||
53101+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53102+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53103+ return;
53104+
53105+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53106+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53107+ return;
53108+ switch (elf_p.p_type) {
53109+ case PT_DYNAMIC:
53110+ if (!is_textrel_rw && !is_textrel_rx)
53111+ continue;
53112+ i = 0UL;
53113+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53114+ elf_dyn dyn;
53115+
53116+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53117+ break;
53118+ if (dyn.d_tag == DT_NULL)
53119+ break;
53120+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53121+ gr_log_textrel(vma);
53122+ if (is_textrel_rw)
53123+ vma->vm_flags |= VM_MAYWRITE;
53124+ else
53125+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53126+ vma->vm_flags &= ~VM_MAYWRITE;
53127+ break;
53128+ }
53129+ i++;
53130+ }
53131+ is_textrel_rw = false;
53132+ is_textrel_rx = false;
53133+ continue;
53134+
53135+ case PT_GNU_RELRO:
53136+ if (!is_relro)
53137+ continue;
53138+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53139+ vma->vm_flags &= ~VM_MAYWRITE;
53140+ is_relro = false;
53141+ continue;
53142+
53143+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53144+ case PT_PAX_FLAGS: {
53145+ const char *msg_mprotect = "", *msg_emutramp = "";
53146+ char *buffer_lib, *buffer_exe;
53147+
53148+ if (elf_p.p_flags & PF_NOMPROTECT)
53149+ msg_mprotect = "MPROTECT disabled";
53150+
53151+#ifdef CONFIG_PAX_EMUTRAMP
53152+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53153+ msg_emutramp = "EMUTRAMP enabled";
53154+#endif
53155+
53156+ if (!msg_mprotect[0] && !msg_emutramp[0])
53157+ continue;
53158+
53159+ if (!printk_ratelimit())
53160+ continue;
53161+
53162+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53163+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53164+ if (buffer_lib && buffer_exe) {
53165+ char *path_lib, *path_exe;
53166+
53167+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53168+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53169+
53170+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53171+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53172+
53173+ }
53174+ free_page((unsigned long)buffer_exe);
53175+ free_page((unsigned long)buffer_lib);
53176+ continue;
53177+ }
53178+#endif
53179+
53180+ }
53181+ }
53182+}
53183+#endif
53184+
53185+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53186+
53187+extern int grsec_enable_log_rwxmaps;
53188+
53189+static void elf_handle_mmap(struct file *file)
53190+{
53191+ struct elfhdr elf_h;
53192+ struct elf_phdr elf_p;
53193+ unsigned long i;
53194+
53195+ if (!grsec_enable_log_rwxmaps)
53196+ return;
53197+
53198+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53199+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53200+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53201+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53202+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53203+ return;
53204+
53205+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53206+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53207+ return;
53208+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53209+ gr_log_ptgnustack(file);
53210+ }
53211+}
53212+#endif
53213+
53214 static int __init init_elf_binfmt(void)
53215 {
53216 register_binfmt(&elf_format);
53217diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53218index d50bbe5..af3b649 100644
53219--- a/fs/binfmt_flat.c
53220+++ b/fs/binfmt_flat.c
53221@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53222 realdatastart = (unsigned long) -ENOMEM;
53223 printk("Unable to allocate RAM for process data, errno %d\n",
53224 (int)-realdatastart);
53225+ down_write(&current->mm->mmap_sem);
53226 vm_munmap(textpos, text_len);
53227+ up_write(&current->mm->mmap_sem);
53228 ret = realdatastart;
53229 goto err;
53230 }
53231@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53232 }
53233 if (IS_ERR_VALUE(result)) {
53234 printk("Unable to read data+bss, errno %d\n", (int)-result);
53235+ down_write(&current->mm->mmap_sem);
53236 vm_munmap(textpos, text_len);
53237 vm_munmap(realdatastart, len);
53238+ up_write(&current->mm->mmap_sem);
53239 ret = result;
53240 goto err;
53241 }
53242@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53243 }
53244 if (IS_ERR_VALUE(result)) {
53245 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53246+ down_write(&current->mm->mmap_sem);
53247 vm_munmap(textpos, text_len + data_len + extra +
53248 MAX_SHARED_LIBS * sizeof(unsigned long));
53249+ up_write(&current->mm->mmap_sem);
53250 ret = result;
53251 goto err;
53252 }
53253diff --git a/fs/bio.c b/fs/bio.c
53254index 5e7507d..418c639 100644
53255--- a/fs/bio.c
53256+++ b/fs/bio.c
53257@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53258 /*
53259 * Overflow, abort
53260 */
53261- if (end < start)
53262+ if (end < start || end - start > INT_MAX - nr_pages)
53263 return ERR_PTR(-EINVAL);
53264
53265 nr_pages += end - start;
53266@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53267 /*
53268 * Overflow, abort
53269 */
53270- if (end < start)
53271+ if (end < start || end - start > INT_MAX - nr_pages)
53272 return ERR_PTR(-EINVAL);
53273
53274 nr_pages += end - start;
53275@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53276 const int read = bio_data_dir(bio) == READ;
53277 struct bio_map_data *bmd = bio->bi_private;
53278 int i;
53279- char *p = bmd->sgvecs[0].iov_base;
53280+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53281
53282 bio_for_each_segment_all(bvec, bio, i) {
53283 char *addr = page_address(bvec->bv_page);
53284diff --git a/fs/block_dev.c b/fs/block_dev.c
53285index c7bda5c..2121e94 100644
53286--- a/fs/block_dev.c
53287+++ b/fs/block_dev.c
53288@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53289 else if (bdev->bd_contains == bdev)
53290 return true; /* is a whole device which isn't held */
53291
53292- else if (whole->bd_holder == bd_may_claim)
53293+ else if (whole->bd_holder == (void *)bd_may_claim)
53294 return true; /* is a partition of a device that is being partitioned */
53295 else if (whole->bd_holder != NULL)
53296 return false; /* is a partition of a held device */
53297diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53298index ed50460..fe84385 100644
53299--- a/fs/btrfs/ctree.c
53300+++ b/fs/btrfs/ctree.c
53301@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53302 free_extent_buffer(buf);
53303 add_root_to_dirty_list(root);
53304 } else {
53305- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53306- parent_start = parent->start;
53307- else
53308+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53309+ if (parent)
53310+ parent_start = parent->start;
53311+ else
53312+ parent_start = 0;
53313+ } else
53314 parent_start = 0;
53315
53316 WARN_ON(trans->transid != btrfs_header_generation(parent));
53317diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53318index 3755109..e3d457f 100644
53319--- a/fs/btrfs/delayed-inode.c
53320+++ b/fs/btrfs/delayed-inode.c
53321@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53322
53323 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53324 {
53325- int seq = atomic_inc_return(&delayed_root->items_seq);
53326+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53327 if ((atomic_dec_return(&delayed_root->items) <
53328 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53329 waitqueue_active(&delayed_root->wait))
53330@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53331 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53332 int seq, int count)
53333 {
53334- int val = atomic_read(&delayed_root->items_seq);
53335+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53336
53337 if (val < seq || val >= seq + count)
53338 return 1;
53339@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53340 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53341 return;
53342
53343- seq = atomic_read(&delayed_root->items_seq);
53344+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53345
53346 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53347 int ret;
53348diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53349index a4b38f9..f86a509 100644
53350--- a/fs/btrfs/delayed-inode.h
53351+++ b/fs/btrfs/delayed-inode.h
53352@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53353 */
53354 struct list_head prepare_list;
53355 atomic_t items; /* for delayed items */
53356- atomic_t items_seq; /* for delayed items */
53357+ atomic_unchecked_t items_seq; /* for delayed items */
53358 int nodes; /* for delayed nodes */
53359 wait_queue_head_t wait;
53360 };
53361@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53362 struct btrfs_delayed_root *delayed_root)
53363 {
53364 atomic_set(&delayed_root->items, 0);
53365- atomic_set(&delayed_root->items_seq, 0);
53366+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53367 delayed_root->nodes = 0;
53368 spin_lock_init(&delayed_root->lock);
53369 init_waitqueue_head(&delayed_root->wait);
53370diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53371index 9877a2a..7ebf9ab 100644
53372--- a/fs/btrfs/ioctl.c
53373+++ b/fs/btrfs/ioctl.c
53374@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53375 for (i = 0; i < num_types; i++) {
53376 struct btrfs_space_info *tmp;
53377
53378+ /* Don't copy in more than we allocated */
53379 if (!slot_count)
53380 break;
53381
53382+ slot_count--;
53383+
53384 info = NULL;
53385 rcu_read_lock();
53386 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53387@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53388 memcpy(dest, &space, sizeof(space));
53389 dest++;
53390 space_args.total_spaces++;
53391- slot_count--;
53392 }
53393- if (!slot_count)
53394- break;
53395 }
53396 up_read(&info->groups_sem);
53397 }
53398diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53399index 8eb6191..eda91e2 100644
53400--- a/fs/btrfs/super.c
53401+++ b/fs/btrfs/super.c
53402@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53403 function, line, errstr);
53404 return;
53405 }
53406- ACCESS_ONCE(trans->transaction->aborted) = errno;
53407+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53408 /* Wake up anybody who may be waiting on this transaction */
53409 wake_up(&root->fs_info->transaction_wait);
53410 wake_up(&root->fs_info->transaction_blocked_wait);
53411diff --git a/fs/buffer.c b/fs/buffer.c
53412index 4d74335..b0df7f9 100644
53413--- a/fs/buffer.c
53414+++ b/fs/buffer.c
53415@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53416 bh_cachep = kmem_cache_create("buffer_head",
53417 sizeof(struct buffer_head), 0,
53418 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53419- SLAB_MEM_SPREAD),
53420+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53421 NULL);
53422
53423 /*
53424diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53425index 622f469..e8d2d55 100644
53426--- a/fs/cachefiles/bind.c
53427+++ b/fs/cachefiles/bind.c
53428@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53429 args);
53430
53431 /* start by checking things over */
53432- ASSERT(cache->fstop_percent >= 0 &&
53433- cache->fstop_percent < cache->fcull_percent &&
53434+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53435 cache->fcull_percent < cache->frun_percent &&
53436 cache->frun_percent < 100);
53437
53438- ASSERT(cache->bstop_percent >= 0 &&
53439- cache->bstop_percent < cache->bcull_percent &&
53440+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53441 cache->bcull_percent < cache->brun_percent &&
53442 cache->brun_percent < 100);
53443
53444diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53445index 0a1467b..6a53245 100644
53446--- a/fs/cachefiles/daemon.c
53447+++ b/fs/cachefiles/daemon.c
53448@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53449 if (n > buflen)
53450 return -EMSGSIZE;
53451
53452- if (copy_to_user(_buffer, buffer, n) != 0)
53453+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53454 return -EFAULT;
53455
53456 return n;
53457@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53458 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53459 return -EIO;
53460
53461- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53462+ if (datalen > PAGE_SIZE - 1)
53463 return -EOPNOTSUPP;
53464
53465 /* drag the command string into the kernel so we can parse it */
53466@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53467 if (args[0] != '%' || args[1] != '\0')
53468 return -EINVAL;
53469
53470- if (fstop < 0 || fstop >= cache->fcull_percent)
53471+ if (fstop >= cache->fcull_percent)
53472 return cachefiles_daemon_range_error(cache, args);
53473
53474 cache->fstop_percent = fstop;
53475@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53476 if (args[0] != '%' || args[1] != '\0')
53477 return -EINVAL;
53478
53479- if (bstop < 0 || bstop >= cache->bcull_percent)
53480+ if (bstop >= cache->bcull_percent)
53481 return cachefiles_daemon_range_error(cache, args);
53482
53483 cache->bstop_percent = bstop;
53484diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53485index 4938251..7e01445 100644
53486--- a/fs/cachefiles/internal.h
53487+++ b/fs/cachefiles/internal.h
53488@@ -59,7 +59,7 @@ struct cachefiles_cache {
53489 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53490 struct rb_root active_nodes; /* active nodes (can't be culled) */
53491 rwlock_t active_lock; /* lock for active_nodes */
53492- atomic_t gravecounter; /* graveyard uniquifier */
53493+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53494 unsigned frun_percent; /* when to stop culling (% files) */
53495 unsigned fcull_percent; /* when to start culling (% files) */
53496 unsigned fstop_percent; /* when to stop allocating (% files) */
53497@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53498 * proc.c
53499 */
53500 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53501-extern atomic_t cachefiles_lookup_histogram[HZ];
53502-extern atomic_t cachefiles_mkdir_histogram[HZ];
53503-extern atomic_t cachefiles_create_histogram[HZ];
53504+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53505+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53506+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53507
53508 extern int __init cachefiles_proc_init(void);
53509 extern void cachefiles_proc_cleanup(void);
53510 static inline
53511-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53512+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53513 {
53514 unsigned long jif = jiffies - start_jif;
53515 if (jif >= HZ)
53516 jif = HZ - 1;
53517- atomic_inc(&histogram[jif]);
53518+ atomic_inc_unchecked(&histogram[jif]);
53519 }
53520
53521 #else
53522diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53523index 25badd1..d70d918 100644
53524--- a/fs/cachefiles/namei.c
53525+++ b/fs/cachefiles/namei.c
53526@@ -317,7 +317,7 @@ try_again:
53527 /* first step is to make up a grave dentry in the graveyard */
53528 sprintf(nbuffer, "%08x%08x",
53529 (uint32_t) get_seconds(),
53530- (uint32_t) atomic_inc_return(&cache->gravecounter));
53531+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53532
53533 /* do the multiway lock magic */
53534 trap = lock_rename(cache->graveyard, dir);
53535diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53536index eccd339..4c1d995 100644
53537--- a/fs/cachefiles/proc.c
53538+++ b/fs/cachefiles/proc.c
53539@@ -14,9 +14,9 @@
53540 #include <linux/seq_file.h>
53541 #include "internal.h"
53542
53543-atomic_t cachefiles_lookup_histogram[HZ];
53544-atomic_t cachefiles_mkdir_histogram[HZ];
53545-atomic_t cachefiles_create_histogram[HZ];
53546+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53547+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53548+atomic_unchecked_t cachefiles_create_histogram[HZ];
53549
53550 /*
53551 * display the latency histogram
53552@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53553 return 0;
53554 default:
53555 index = (unsigned long) v - 3;
53556- x = atomic_read(&cachefiles_lookup_histogram[index]);
53557- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53558- z = atomic_read(&cachefiles_create_histogram[index]);
53559+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53560+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53561+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53562 if (x == 0 && y == 0 && z == 0)
53563 return 0;
53564
53565diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53566index ebaff36..7e3ea26 100644
53567--- a/fs/cachefiles/rdwr.c
53568+++ b/fs/cachefiles/rdwr.c
53569@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53570 old_fs = get_fs();
53571 set_fs(KERNEL_DS);
53572 ret = file->f_op->write(
53573- file, (const void __user *) data, len, &pos);
53574+ file, (const void __force_user *) data, len, &pos);
53575 set_fs(old_fs);
53576 kunmap(page);
53577 file_end_write(file);
53578diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53579index a40ceda..f43d17c 100644
53580--- a/fs/ceph/dir.c
53581+++ b/fs/ceph/dir.c
53582@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53583 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53584 struct ceph_mds_client *mdsc = fsc->mdsc;
53585 unsigned frag = fpos_frag(ctx->pos);
53586- int off = fpos_off(ctx->pos);
53587+ unsigned int off = fpos_off(ctx->pos);
53588 int err;
53589 u32 ftype;
53590 struct ceph_mds_reply_info_parsed *rinfo;
53591diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53592index 6627b26..634ec4b 100644
53593--- a/fs/ceph/super.c
53594+++ b/fs/ceph/super.c
53595@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53596 /*
53597 * construct our own bdi so we can control readahead, etc.
53598 */
53599-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53600+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53601
53602 static int ceph_register_bdi(struct super_block *sb,
53603 struct ceph_fs_client *fsc)
53604@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53605 default_backing_dev_info.ra_pages;
53606
53607 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53608- atomic_long_inc_return(&bdi_seq));
53609+ atomic_long_inc_return_unchecked(&bdi_seq));
53610 if (!err)
53611 sb->s_bdi = &fsc->backing_dev_info;
53612 return err;
53613diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53614index f3ac415..3d2420c 100644
53615--- a/fs/cifs/cifs_debug.c
53616+++ b/fs/cifs/cifs_debug.c
53617@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53618
53619 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53620 #ifdef CONFIG_CIFS_STATS2
53621- atomic_set(&totBufAllocCount, 0);
53622- atomic_set(&totSmBufAllocCount, 0);
53623+ atomic_set_unchecked(&totBufAllocCount, 0);
53624+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53625 #endif /* CONFIG_CIFS_STATS2 */
53626 spin_lock(&cifs_tcp_ses_lock);
53627 list_for_each(tmp1, &cifs_tcp_ses_list) {
53628@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53629 tcon = list_entry(tmp3,
53630 struct cifs_tcon,
53631 tcon_list);
53632- atomic_set(&tcon->num_smbs_sent, 0);
53633+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53634 if (server->ops->clear_stats)
53635 server->ops->clear_stats(tcon);
53636 }
53637@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53638 smBufAllocCount.counter, cifs_min_small);
53639 #ifdef CONFIG_CIFS_STATS2
53640 seq_printf(m, "Total Large %d Small %d Allocations\n",
53641- atomic_read(&totBufAllocCount),
53642- atomic_read(&totSmBufAllocCount));
53643+ atomic_read_unchecked(&totBufAllocCount),
53644+ atomic_read_unchecked(&totSmBufAllocCount));
53645 #endif /* CONFIG_CIFS_STATS2 */
53646
53647 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53648@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53649 if (tcon->need_reconnect)
53650 seq_puts(m, "\tDISCONNECTED ");
53651 seq_printf(m, "\nSMBs: %d",
53652- atomic_read(&tcon->num_smbs_sent));
53653+ atomic_read_unchecked(&tcon->num_smbs_sent));
53654 if (server->ops->print_stats)
53655 server->ops->print_stats(m, tcon);
53656 }
53657diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53658index 85ea98d..b3ed4d6 100644
53659--- a/fs/cifs/cifsfs.c
53660+++ b/fs/cifs/cifsfs.c
53661@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53662 */
53663 cifs_req_cachep = kmem_cache_create("cifs_request",
53664 CIFSMaxBufSize + max_hdr_size, 0,
53665- SLAB_HWCACHE_ALIGN, NULL);
53666+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53667 if (cifs_req_cachep == NULL)
53668 return -ENOMEM;
53669
53670@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53671 efficient to alloc 1 per page off the slab compared to 17K (5page)
53672 alloc of large cifs buffers even when page debugging is on */
53673 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53674- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53675+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53676 NULL);
53677 if (cifs_sm_req_cachep == NULL) {
53678 mempool_destroy(cifs_req_poolp);
53679@@ -1149,8 +1149,8 @@ init_cifs(void)
53680 atomic_set(&bufAllocCount, 0);
53681 atomic_set(&smBufAllocCount, 0);
53682 #ifdef CONFIG_CIFS_STATS2
53683- atomic_set(&totBufAllocCount, 0);
53684- atomic_set(&totSmBufAllocCount, 0);
53685+ atomic_set_unchecked(&totBufAllocCount, 0);
53686+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53687 #endif /* CONFIG_CIFS_STATS2 */
53688
53689 atomic_set(&midCount, 0);
53690diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53691index 52ca861..47f309c 100644
53692--- a/fs/cifs/cifsglob.h
53693+++ b/fs/cifs/cifsglob.h
53694@@ -756,35 +756,35 @@ struct cifs_tcon {
53695 __u16 Flags; /* optional support bits */
53696 enum statusEnum tidStatus;
53697 #ifdef CONFIG_CIFS_STATS
53698- atomic_t num_smbs_sent;
53699+ atomic_unchecked_t num_smbs_sent;
53700 union {
53701 struct {
53702- atomic_t num_writes;
53703- atomic_t num_reads;
53704- atomic_t num_flushes;
53705- atomic_t num_oplock_brks;
53706- atomic_t num_opens;
53707- atomic_t num_closes;
53708- atomic_t num_deletes;
53709- atomic_t num_mkdirs;
53710- atomic_t num_posixopens;
53711- atomic_t num_posixmkdirs;
53712- atomic_t num_rmdirs;
53713- atomic_t num_renames;
53714- atomic_t num_t2renames;
53715- atomic_t num_ffirst;
53716- atomic_t num_fnext;
53717- atomic_t num_fclose;
53718- atomic_t num_hardlinks;
53719- atomic_t num_symlinks;
53720- atomic_t num_locks;
53721- atomic_t num_acl_get;
53722- atomic_t num_acl_set;
53723+ atomic_unchecked_t num_writes;
53724+ atomic_unchecked_t num_reads;
53725+ atomic_unchecked_t num_flushes;
53726+ atomic_unchecked_t num_oplock_brks;
53727+ atomic_unchecked_t num_opens;
53728+ atomic_unchecked_t num_closes;
53729+ atomic_unchecked_t num_deletes;
53730+ atomic_unchecked_t num_mkdirs;
53731+ atomic_unchecked_t num_posixopens;
53732+ atomic_unchecked_t num_posixmkdirs;
53733+ atomic_unchecked_t num_rmdirs;
53734+ atomic_unchecked_t num_renames;
53735+ atomic_unchecked_t num_t2renames;
53736+ atomic_unchecked_t num_ffirst;
53737+ atomic_unchecked_t num_fnext;
53738+ atomic_unchecked_t num_fclose;
53739+ atomic_unchecked_t num_hardlinks;
53740+ atomic_unchecked_t num_symlinks;
53741+ atomic_unchecked_t num_locks;
53742+ atomic_unchecked_t num_acl_get;
53743+ atomic_unchecked_t num_acl_set;
53744 } cifs_stats;
53745 #ifdef CONFIG_CIFS_SMB2
53746 struct {
53747- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53748- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53749+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53750+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53751 } smb2_stats;
53752 #endif /* CONFIG_CIFS_SMB2 */
53753 } stats;
53754@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53755 }
53756
53757 #ifdef CONFIG_CIFS_STATS
53758-#define cifs_stats_inc atomic_inc
53759+#define cifs_stats_inc atomic_inc_unchecked
53760
53761 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53762 unsigned int bytes)
53763@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53764 /* Various Debug counters */
53765 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53766 #ifdef CONFIG_CIFS_STATS2
53767-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53768-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53769+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53770+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53771 #endif
53772 GLOBAL_EXTERN atomic_t smBufAllocCount;
53773 GLOBAL_EXTERN atomic_t midCount;
53774diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53775index 562044f..4af6a17 100644
53776--- a/fs/cifs/link.c
53777+++ b/fs/cifs/link.c
53778@@ -638,7 +638,7 @@ symlink_exit:
53779
53780 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53781 {
53782- char *p = nd_get_link(nd);
53783+ const char *p = nd_get_link(nd);
53784 if (!IS_ERR(p))
53785 kfree(p);
53786 }
53787diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53788index f7d4b22..1254377 100644
53789--- a/fs/cifs/misc.c
53790+++ b/fs/cifs/misc.c
53791@@ -169,7 +169,7 @@ cifs_buf_get(void)
53792 memset(ret_buf, 0, buf_size + 3);
53793 atomic_inc(&bufAllocCount);
53794 #ifdef CONFIG_CIFS_STATS2
53795- atomic_inc(&totBufAllocCount);
53796+ atomic_inc_unchecked(&totBufAllocCount);
53797 #endif /* CONFIG_CIFS_STATS2 */
53798 }
53799
53800@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53801 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53802 atomic_inc(&smBufAllocCount);
53803 #ifdef CONFIG_CIFS_STATS2
53804- atomic_inc(&totSmBufAllocCount);
53805+ atomic_inc_unchecked(&totSmBufAllocCount);
53806 #endif /* CONFIG_CIFS_STATS2 */
53807
53808 }
53809diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53810index 6094397..51e576f 100644
53811--- a/fs/cifs/smb1ops.c
53812+++ b/fs/cifs/smb1ops.c
53813@@ -590,27 +590,27 @@ static void
53814 cifs_clear_stats(struct cifs_tcon *tcon)
53815 {
53816 #ifdef CONFIG_CIFS_STATS
53817- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53818- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53819- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53820- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53821- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53822- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53823- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53824- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53825- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53826- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53827- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53828- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53829- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53830- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53831- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53832- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53833- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53834- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53835- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53836- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53837- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53838+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53839+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53840+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53841+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53842+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53843+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53844+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53845+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53846+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53847+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53848+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53849+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53850+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53851+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53852+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53853+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53854+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53855+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53856+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53857+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53858+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53859 #endif
53860 }
53861
53862@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53863 {
53864 #ifdef CONFIG_CIFS_STATS
53865 seq_printf(m, " Oplocks breaks: %d",
53866- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53867+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53868 seq_printf(m, "\nReads: %d Bytes: %llu",
53869- atomic_read(&tcon->stats.cifs_stats.num_reads),
53870+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53871 (long long)(tcon->bytes_read));
53872 seq_printf(m, "\nWrites: %d Bytes: %llu",
53873- atomic_read(&tcon->stats.cifs_stats.num_writes),
53874+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53875 (long long)(tcon->bytes_written));
53876 seq_printf(m, "\nFlushes: %d",
53877- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53878+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53879 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53880- atomic_read(&tcon->stats.cifs_stats.num_locks),
53881- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53882- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53883+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53884+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53885+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53886 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53887- atomic_read(&tcon->stats.cifs_stats.num_opens),
53888- atomic_read(&tcon->stats.cifs_stats.num_closes),
53889- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53890+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53891+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53892+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53893 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53894- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53895- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53897+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53898 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53899- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53900- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53901+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53902+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53903 seq_printf(m, "\nRenames: %d T2 Renames %d",
53904- atomic_read(&tcon->stats.cifs_stats.num_renames),
53905- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53906+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53907+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53908 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53909- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53910- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53911- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53912+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53913+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53914+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53915 #endif
53916 }
53917
53918diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53919index f259e6c..ca948ff 100644
53920--- a/fs/cifs/smb2ops.c
53921+++ b/fs/cifs/smb2ops.c
53922@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53923 #ifdef CONFIG_CIFS_STATS
53924 int i;
53925 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53926- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53927- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53928+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53929+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53930 }
53931 #endif
53932 }
53933@@ -310,65 +310,65 @@ static void
53934 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53935 {
53936 #ifdef CONFIG_CIFS_STATS
53937- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53938- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53939+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53940+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53941 seq_printf(m, "\nNegotiates: %d sent %d failed",
53942- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
53943- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
53944+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
53945+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
53946 seq_printf(m, "\nSessionSetups: %d sent %d failed",
53947- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
53948- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
53949+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
53950+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
53951 seq_printf(m, "\nLogoffs: %d sent %d failed",
53952- atomic_read(&sent[SMB2_LOGOFF_HE]),
53953- atomic_read(&failed[SMB2_LOGOFF_HE]));
53954+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
53955+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
53956 seq_printf(m, "\nTreeConnects: %d sent %d failed",
53957- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
53958- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
53959+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
53960+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
53961 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
53962- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
53963- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
53964+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
53965+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
53966 seq_printf(m, "\nCreates: %d sent %d failed",
53967- atomic_read(&sent[SMB2_CREATE_HE]),
53968- atomic_read(&failed[SMB2_CREATE_HE]));
53969+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
53970+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
53971 seq_printf(m, "\nCloses: %d sent %d failed",
53972- atomic_read(&sent[SMB2_CLOSE_HE]),
53973- atomic_read(&failed[SMB2_CLOSE_HE]));
53974+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
53975+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
53976 seq_printf(m, "\nFlushes: %d sent %d failed",
53977- atomic_read(&sent[SMB2_FLUSH_HE]),
53978- atomic_read(&failed[SMB2_FLUSH_HE]));
53979+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
53980+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
53981 seq_printf(m, "\nReads: %d sent %d failed",
53982- atomic_read(&sent[SMB2_READ_HE]),
53983- atomic_read(&failed[SMB2_READ_HE]));
53984+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
53985+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
53986 seq_printf(m, "\nWrites: %d sent %d failed",
53987- atomic_read(&sent[SMB2_WRITE_HE]),
53988- atomic_read(&failed[SMB2_WRITE_HE]));
53989+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
53990+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
53991 seq_printf(m, "\nLocks: %d sent %d failed",
53992- atomic_read(&sent[SMB2_LOCK_HE]),
53993- atomic_read(&failed[SMB2_LOCK_HE]));
53994+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
53995+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
53996 seq_printf(m, "\nIOCTLs: %d sent %d failed",
53997- atomic_read(&sent[SMB2_IOCTL_HE]),
53998- atomic_read(&failed[SMB2_IOCTL_HE]));
53999+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54000+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54001 seq_printf(m, "\nCancels: %d sent %d failed",
54002- atomic_read(&sent[SMB2_CANCEL_HE]),
54003- atomic_read(&failed[SMB2_CANCEL_HE]));
54004+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54005+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54006 seq_printf(m, "\nEchos: %d sent %d failed",
54007- atomic_read(&sent[SMB2_ECHO_HE]),
54008- atomic_read(&failed[SMB2_ECHO_HE]));
54009+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54010+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54011 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54012- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54013- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54014+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54015+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54016 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54017- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54018- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54019+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54020+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54021 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54022- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54023- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54024+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54025+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54026 seq_printf(m, "\nSetInfos: %d sent %d failed",
54027- atomic_read(&sent[SMB2_SET_INFO_HE]),
54028- atomic_read(&failed[SMB2_SET_INFO_HE]));
54029+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54030+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54031 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54032- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54033- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54034+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54035+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54036 #endif
54037 }
54038
54039diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54040index abc9c28..3fdae28 100644
54041--- a/fs/cifs/smb2pdu.c
54042+++ b/fs/cifs/smb2pdu.c
54043@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54044 default:
54045 cifs_dbg(VFS, "info level %u isn't supported\n",
54046 srch_inf->info_level);
54047- rc = -EINVAL;
54048- goto qdir_exit;
54049+ return -EINVAL;
54050 }
54051
54052 req->FileIndex = cpu_to_le32(index);
54053diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54054index 1da168c..8bc7ff6 100644
54055--- a/fs/coda/cache.c
54056+++ b/fs/coda/cache.c
54057@@ -24,7 +24,7 @@
54058 #include "coda_linux.h"
54059 #include "coda_cache.h"
54060
54061-static atomic_t permission_epoch = ATOMIC_INIT(0);
54062+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54063
54064 /* replace or extend an acl cache hit */
54065 void coda_cache_enter(struct inode *inode, int mask)
54066@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54067 struct coda_inode_info *cii = ITOC(inode);
54068
54069 spin_lock(&cii->c_lock);
54070- cii->c_cached_epoch = atomic_read(&permission_epoch);
54071+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54072 if (!uid_eq(cii->c_uid, current_fsuid())) {
54073 cii->c_uid = current_fsuid();
54074 cii->c_cached_perm = mask;
54075@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54076 {
54077 struct coda_inode_info *cii = ITOC(inode);
54078 spin_lock(&cii->c_lock);
54079- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54080+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54081 spin_unlock(&cii->c_lock);
54082 }
54083
54084 /* remove all acl caches */
54085 void coda_cache_clear_all(struct super_block *sb)
54086 {
54087- atomic_inc(&permission_epoch);
54088+ atomic_inc_unchecked(&permission_epoch);
54089 }
54090
54091
54092@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54093 spin_lock(&cii->c_lock);
54094 hit = (mask & cii->c_cached_perm) == mask &&
54095 uid_eq(cii->c_uid, current_fsuid()) &&
54096- cii->c_cached_epoch == atomic_read(&permission_epoch);
54097+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54098 spin_unlock(&cii->c_lock);
54099
54100 return hit;
54101diff --git a/fs/compat.c b/fs/compat.c
54102index 6af20de..fec3fbb 100644
54103--- a/fs/compat.c
54104+++ b/fs/compat.c
54105@@ -54,7 +54,7 @@
54106 #include <asm/ioctls.h>
54107 #include "internal.h"
54108
54109-int compat_log = 1;
54110+int compat_log = 0;
54111
54112 int compat_printk(const char *fmt, ...)
54113 {
54114@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54115
54116 set_fs(KERNEL_DS);
54117 /* The __user pointer cast is valid because of the set_fs() */
54118- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54119+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54120 set_fs(oldfs);
54121 /* truncating is ok because it's a user address */
54122 if (!ret)
54123@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54124 goto out;
54125
54126 ret = -EINVAL;
54127- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54128+ if (nr_segs > UIO_MAXIOV)
54129 goto out;
54130 if (nr_segs > fast_segs) {
54131 ret = -ENOMEM;
54132@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54133 struct compat_readdir_callback {
54134 struct dir_context ctx;
54135 struct compat_old_linux_dirent __user *dirent;
54136+ struct file * file;
54137 int result;
54138 };
54139
54140@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54141 buf->result = -EOVERFLOW;
54142 return -EOVERFLOW;
54143 }
54144+
54145+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54146+ return 0;
54147+
54148 buf->result++;
54149 dirent = buf->dirent;
54150 if (!access_ok(VERIFY_WRITE, dirent,
54151@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54152 if (!f.file)
54153 return -EBADF;
54154
54155+ buf.file = f.file;
54156 error = iterate_dir(f.file, &buf.ctx);
54157 if (buf.result)
54158 error = buf.result;
54159@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54160 struct dir_context ctx;
54161 struct compat_linux_dirent __user *current_dir;
54162 struct compat_linux_dirent __user *previous;
54163+ struct file * file;
54164 int count;
54165 int error;
54166 };
54167@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54168 buf->error = -EOVERFLOW;
54169 return -EOVERFLOW;
54170 }
54171+
54172+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54173+ return 0;
54174+
54175 dirent = buf->previous;
54176 if (dirent) {
54177 if (__put_user(offset, &dirent->d_off))
54178@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54179 if (!f.file)
54180 return -EBADF;
54181
54182+ buf.file = f.file;
54183 error = iterate_dir(f.file, &buf.ctx);
54184 if (error >= 0)
54185 error = buf.error;
54186@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54187 struct dir_context ctx;
54188 struct linux_dirent64 __user *current_dir;
54189 struct linux_dirent64 __user *previous;
54190+ struct file * file;
54191 int count;
54192 int error;
54193 };
54194@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54195 buf->error = -EINVAL; /* only used if we fail.. */
54196 if (reclen > buf->count)
54197 return -EINVAL;
54198+
54199+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54200+ return 0;
54201+
54202 dirent = buf->previous;
54203
54204 if (dirent) {
54205@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54206 if (!f.file)
54207 return -EBADF;
54208
54209+ buf.file = f.file;
54210 error = iterate_dir(f.file, &buf.ctx);
54211 if (error >= 0)
54212 error = buf.error;
54213diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54214index a81147e..20bf2b5 100644
54215--- a/fs/compat_binfmt_elf.c
54216+++ b/fs/compat_binfmt_elf.c
54217@@ -30,11 +30,13 @@
54218 #undef elf_phdr
54219 #undef elf_shdr
54220 #undef elf_note
54221+#undef elf_dyn
54222 #undef elf_addr_t
54223 #define elfhdr elf32_hdr
54224 #define elf_phdr elf32_phdr
54225 #define elf_shdr elf32_shdr
54226 #define elf_note elf32_note
54227+#define elf_dyn Elf32_Dyn
54228 #define elf_addr_t Elf32_Addr
54229
54230 /*
54231diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54232index 5d19acf..9ab093b 100644
54233--- a/fs/compat_ioctl.c
54234+++ b/fs/compat_ioctl.c
54235@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54236 return -EFAULT;
54237 if (__get_user(udata, &ss32->iomem_base))
54238 return -EFAULT;
54239- ss.iomem_base = compat_ptr(udata);
54240+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54241 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54242 __get_user(ss.port_high, &ss32->port_high))
54243 return -EFAULT;
54244@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54245 for (i = 0; i < nmsgs; i++) {
54246 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54247 return -EFAULT;
54248- if (get_user(datap, &umsgs[i].buf) ||
54249- put_user(compat_ptr(datap), &tmsgs[i].buf))
54250+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54251+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54252 return -EFAULT;
54253 }
54254 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54255@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54256 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54257 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54258 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54259- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54260+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54261 return -EFAULT;
54262
54263 return ioctl_preallocate(file, p);
54264@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54265 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54266 {
54267 unsigned int a, b;
54268- a = *(unsigned int *)p;
54269- b = *(unsigned int *)q;
54270+ a = *(const unsigned int *)p;
54271+ b = *(const unsigned int *)q;
54272 if (a > b)
54273 return 1;
54274 if (a < b)
54275diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54276index 277bd1b..f312c9e 100644
54277--- a/fs/configfs/dir.c
54278+++ b/fs/configfs/dir.c
54279@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54280 }
54281 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54282 struct configfs_dirent *next;
54283- const char *name;
54284+ const unsigned char * name;
54285+ char d_name[sizeof(next->s_dentry->d_iname)];
54286 int len;
54287 struct inode *inode = NULL;
54288
54289@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54290 continue;
54291
54292 name = configfs_get_name(next);
54293- len = strlen(name);
54294+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54295+ len = next->s_dentry->d_name.len;
54296+ memcpy(d_name, name, len);
54297+ name = d_name;
54298+ } else
54299+ len = strlen(name);
54300
54301 /*
54302 * We'll have a dentry and an inode for
54303diff --git a/fs/coredump.c b/fs/coredump.c
54304index 72f816d..1ba8eff 100644
54305--- a/fs/coredump.c
54306+++ b/fs/coredump.c
54307@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54308 struct pipe_inode_info *pipe = file->private_data;
54309
54310 pipe_lock(pipe);
54311- pipe->readers++;
54312- pipe->writers--;
54313+ atomic_inc(&pipe->readers);
54314+ atomic_dec(&pipe->writers);
54315 wake_up_interruptible_sync(&pipe->wait);
54316 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54317 pipe_unlock(pipe);
54318@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54319 * We actually want wait_event_freezable() but then we need
54320 * to clear TIF_SIGPENDING and improve dump_interrupted().
54321 */
54322- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54323+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54324
54325 pipe_lock(pipe);
54326- pipe->readers--;
54327- pipe->writers++;
54328+ atomic_dec(&pipe->readers);
54329+ atomic_inc(&pipe->writers);
54330 pipe_unlock(pipe);
54331 }
54332
54333@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54334 struct files_struct *displaced;
54335 bool need_nonrelative = false;
54336 bool core_dumped = false;
54337- static atomic_t core_dump_count = ATOMIC_INIT(0);
54338+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54339+ long signr = siginfo->si_signo;
54340 struct coredump_params cprm = {
54341 .siginfo = siginfo,
54342 .regs = signal_pt_regs(),
54343@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54344 .mm_flags = mm->flags,
54345 };
54346
54347- audit_core_dumps(siginfo->si_signo);
54348+ audit_core_dumps(signr);
54349+
54350+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54351+ gr_handle_brute_attach(cprm.mm_flags);
54352
54353 binfmt = mm->binfmt;
54354 if (!binfmt || !binfmt->core_dump)
54355@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54356 need_nonrelative = true;
54357 }
54358
54359- retval = coredump_wait(siginfo->si_signo, &core_state);
54360+ retval = coredump_wait(signr, &core_state);
54361 if (retval < 0)
54362 goto fail_creds;
54363
54364@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54365 }
54366 cprm.limit = RLIM_INFINITY;
54367
54368- dump_count = atomic_inc_return(&core_dump_count);
54369+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54370 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54371 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54372 task_tgid_vnr(current), current->comm);
54373@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54374 } else {
54375 struct inode *inode;
54376
54377+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54378+
54379 if (cprm.limit < binfmt->min_coredump)
54380 goto fail_unlock;
54381
54382@@ -664,7 +670,7 @@ close_fail:
54383 filp_close(cprm.file, NULL);
54384 fail_dropcount:
54385 if (ispipe)
54386- atomic_dec(&core_dump_count);
54387+ atomic_dec_unchecked(&core_dump_count);
54388 fail_unlock:
54389 kfree(cn.corename);
54390 coredump_finish(mm, core_dumped);
54391@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54392 {
54393 return !dump_interrupted() &&
54394 access_ok(VERIFY_READ, addr, nr) &&
54395- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54396+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54397 }
54398 EXPORT_SYMBOL(dump_write);
54399
54400diff --git a/fs/dcache.c b/fs/dcache.c
54401index b949af8..5978926 100644
54402--- a/fs/dcache.c
54403+++ b/fs/dcache.c
54404@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54405 mempages -= reserve;
54406
54407 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54408- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54409+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54410+ SLAB_NO_SANITIZE, NULL);
54411
54412 dcache_init();
54413 inode_init();
54414diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54415index c7c83ff..bda9461 100644
54416--- a/fs/debugfs/inode.c
54417+++ b/fs/debugfs/inode.c
54418@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54419 */
54420 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54421 {
54422+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54423+ return __create_file(name, S_IFDIR | S_IRWXU,
54424+#else
54425 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54426+#endif
54427 parent, NULL, NULL);
54428 }
54429 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54430diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54431index 67e9b63..a9adb68 100644
54432--- a/fs/ecryptfs/inode.c
54433+++ b/fs/ecryptfs/inode.c
54434@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54435 old_fs = get_fs();
54436 set_fs(get_ds());
54437 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54438- (char __user *)lower_buf,
54439+ (char __force_user *)lower_buf,
54440 PATH_MAX);
54441 set_fs(old_fs);
54442 if (rc < 0)
54443@@ -706,7 +706,7 @@ out:
54444 static void
54445 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54446 {
54447- char *buf = nd_get_link(nd);
54448+ const char *buf = nd_get_link(nd);
54449 if (!IS_ERR(buf)) {
54450 /* Free the char* */
54451 kfree(buf);
54452diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54453index e4141f2..d8263e8 100644
54454--- a/fs/ecryptfs/miscdev.c
54455+++ b/fs/ecryptfs/miscdev.c
54456@@ -304,7 +304,7 @@ check_list:
54457 goto out_unlock_msg_ctx;
54458 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54459 if (msg_ctx->msg) {
54460- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54461+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54462 goto out_unlock_msg_ctx;
54463 i += packet_length_size;
54464 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54465diff --git a/fs/exec.c b/fs/exec.c
54466index fd774c7..1c6a7bf 100644
54467--- a/fs/exec.c
54468+++ b/fs/exec.c
54469@@ -55,8 +55,20 @@
54470 #include <linux/pipe_fs_i.h>
54471 #include <linux/oom.h>
54472 #include <linux/compat.h>
54473+#include <linux/random.h>
54474+#include <linux/seq_file.h>
54475+#include <linux/coredump.h>
54476+#include <linux/mman.h>
54477+
54478+#ifdef CONFIG_PAX_REFCOUNT
54479+#include <linux/kallsyms.h>
54480+#include <linux/kdebug.h>
54481+#endif
54482+
54483+#include <trace/events/fs.h>
54484
54485 #include <asm/uaccess.h>
54486+#include <asm/sections.h>
54487 #include <asm/mmu_context.h>
54488 #include <asm/tlb.h>
54489
54490@@ -66,17 +78,32 @@
54491
54492 #include <trace/events/sched.h>
54493
54494+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54495+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54496+{
54497+ 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");
54498+}
54499+#endif
54500+
54501+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54502+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54503+EXPORT_SYMBOL(pax_set_initial_flags_func);
54504+#endif
54505+
54506 int suid_dumpable = 0;
54507
54508 static LIST_HEAD(formats);
54509 static DEFINE_RWLOCK(binfmt_lock);
54510
54511+extern int gr_process_kernel_exec_ban(void);
54512+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54513+
54514 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54515 {
54516 BUG_ON(!fmt);
54517 write_lock(&binfmt_lock);
54518- insert ? list_add(&fmt->lh, &formats) :
54519- list_add_tail(&fmt->lh, &formats);
54520+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54521+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54522 write_unlock(&binfmt_lock);
54523 }
54524
54525@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54526 void unregister_binfmt(struct linux_binfmt * fmt)
54527 {
54528 write_lock(&binfmt_lock);
54529- list_del(&fmt->lh);
54530+ pax_list_del((struct list_head *)&fmt->lh);
54531 write_unlock(&binfmt_lock);
54532 }
54533
54534@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54535 int write)
54536 {
54537 struct page *page;
54538- int ret;
54539
54540-#ifdef CONFIG_STACK_GROWSUP
54541- if (write) {
54542- ret = expand_downwards(bprm->vma, pos);
54543- if (ret < 0)
54544- return NULL;
54545- }
54546-#endif
54547- ret = get_user_pages(current, bprm->mm, pos,
54548- 1, write, 1, &page, NULL);
54549- if (ret <= 0)
54550+ if (0 > expand_downwards(bprm->vma, pos))
54551+ return NULL;
54552+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54553 return NULL;
54554
54555 if (write) {
54556@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54557 if (size <= ARG_MAX)
54558 return page;
54559
54560+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54561+ // only allow 512KB for argv+env on suid/sgid binaries
54562+ // to prevent easy ASLR exhaustion
54563+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54564+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54565+ (size > (512 * 1024))) {
54566+ put_page(page);
54567+ return NULL;
54568+ }
54569+#endif
54570+
54571 /*
54572 * Limit to 1/4-th the stack size for the argv+env strings.
54573 * This ensures that:
54574@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54575 vma->vm_end = STACK_TOP_MAX;
54576 vma->vm_start = vma->vm_end - PAGE_SIZE;
54577 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54578+
54579+#ifdef CONFIG_PAX_SEGMEXEC
54580+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54581+#endif
54582+
54583 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54584 INIT_LIST_HEAD(&vma->anon_vma_chain);
54585
54586@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54587 mm->stack_vm = mm->total_vm = 1;
54588 up_write(&mm->mmap_sem);
54589 bprm->p = vma->vm_end - sizeof(void *);
54590+
54591+#ifdef CONFIG_PAX_RANDUSTACK
54592+ if (randomize_va_space)
54593+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54594+#endif
54595+
54596 return 0;
54597 err:
54598 up_write(&mm->mmap_sem);
54599@@ -397,7 +438,7 @@ struct user_arg_ptr {
54600 } ptr;
54601 };
54602
54603-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54604+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54605 {
54606 const char __user *native;
54607
54608@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54609 compat_uptr_t compat;
54610
54611 if (get_user(compat, argv.ptr.compat + nr))
54612- return ERR_PTR(-EFAULT);
54613+ return (const char __force_user *)ERR_PTR(-EFAULT);
54614
54615 return compat_ptr(compat);
54616 }
54617 #endif
54618
54619 if (get_user(native, argv.ptr.native + nr))
54620- return ERR_PTR(-EFAULT);
54621+ return (const char __force_user *)ERR_PTR(-EFAULT);
54622
54623 return native;
54624 }
54625@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54626 if (!p)
54627 break;
54628
54629- if (IS_ERR(p))
54630+ if (IS_ERR((const char __force_kernel *)p))
54631 return -EFAULT;
54632
54633 if (i >= max)
54634@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54635
54636 ret = -EFAULT;
54637 str = get_user_arg_ptr(argv, argc);
54638- if (IS_ERR(str))
54639+ if (IS_ERR((const char __force_kernel *)str))
54640 goto out;
54641
54642 len = strnlen_user(str, MAX_ARG_STRLEN);
54643@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54644 int r;
54645 mm_segment_t oldfs = get_fs();
54646 struct user_arg_ptr argv = {
54647- .ptr.native = (const char __user *const __user *)__argv,
54648+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54649 };
54650
54651 set_fs(KERNEL_DS);
54652@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54653 unsigned long new_end = old_end - shift;
54654 struct mmu_gather tlb;
54655
54656- BUG_ON(new_start > new_end);
54657+ if (new_start >= new_end || new_start < mmap_min_addr)
54658+ return -ENOMEM;
54659
54660 /*
54661 * ensure there are no vmas between where we want to go
54662@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54663 if (vma != find_vma(mm, new_start))
54664 return -EFAULT;
54665
54666+#ifdef CONFIG_PAX_SEGMEXEC
54667+ BUG_ON(pax_find_mirror_vma(vma));
54668+#endif
54669+
54670 /*
54671 * cover the whole range: [new_start, old_end)
54672 */
54673@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54674 stack_top = arch_align_stack(stack_top);
54675 stack_top = PAGE_ALIGN(stack_top);
54676
54677- if (unlikely(stack_top < mmap_min_addr) ||
54678- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54679- return -ENOMEM;
54680-
54681 stack_shift = vma->vm_end - stack_top;
54682
54683 bprm->p -= stack_shift;
54684@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54685 bprm->exec -= stack_shift;
54686
54687 down_write(&mm->mmap_sem);
54688+
54689+ /* Move stack pages down in memory. */
54690+ if (stack_shift) {
54691+ ret = shift_arg_pages(vma, stack_shift);
54692+ if (ret)
54693+ goto out_unlock;
54694+ }
54695+
54696 vm_flags = VM_STACK_FLAGS;
54697
54698+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54699+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54700+ vm_flags &= ~VM_EXEC;
54701+
54702+#ifdef CONFIG_PAX_MPROTECT
54703+ if (mm->pax_flags & MF_PAX_MPROTECT)
54704+ vm_flags &= ~VM_MAYEXEC;
54705+#endif
54706+
54707+ }
54708+#endif
54709+
54710 /*
54711 * Adjust stack execute permissions; explicitly enable for
54712 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54713@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54714 goto out_unlock;
54715 BUG_ON(prev != vma);
54716
54717- /* Move stack pages down in memory. */
54718- if (stack_shift) {
54719- ret = shift_arg_pages(vma, stack_shift);
54720- if (ret)
54721- goto out_unlock;
54722- }
54723-
54724 /* mprotect_fixup is overkill to remove the temporary stack flags */
54725 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54726
54727@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54728 #endif
54729 current->mm->start_stack = bprm->p;
54730 ret = expand_stack(vma, stack_base);
54731+
54732+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54733+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54734+ unsigned long size;
54735+ vm_flags_t vm_flags;
54736+
54737+ size = STACK_TOP - vma->vm_end;
54738+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54739+
54740+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54741+
54742+#ifdef CONFIG_X86
54743+ if (!ret) {
54744+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54745+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54746+ }
54747+#endif
54748+
54749+ }
54750+#endif
54751+
54752 if (ret)
54753 ret = -EFAULT;
54754
54755@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54756
54757 fsnotify_open(file);
54758
54759+ trace_open_exec(name);
54760+
54761 err = deny_write_access(file);
54762 if (err)
54763 goto exit;
54764@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54765 old_fs = get_fs();
54766 set_fs(get_ds());
54767 /* The cast to a user pointer is valid due to the set_fs() */
54768- result = vfs_read(file, (void __user *)addr, count, &pos);
54769+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54770 set_fs(old_fs);
54771 return result;
54772 }
54773@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54774 }
54775 rcu_read_unlock();
54776
54777- if (p->fs->users > n_fs) {
54778+ if (atomic_read(&p->fs->users) > n_fs) {
54779 bprm->unsafe |= LSM_UNSAFE_SHARE;
54780 } else {
54781 res = -EAGAIN;
54782@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54783
54784 EXPORT_SYMBOL(search_binary_handler);
54785
54786+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54787+static DEFINE_PER_CPU(u64, exec_counter);
54788+static int __init init_exec_counters(void)
54789+{
54790+ unsigned int cpu;
54791+
54792+ for_each_possible_cpu(cpu) {
54793+ per_cpu(exec_counter, cpu) = (u64)cpu;
54794+ }
54795+
54796+ return 0;
54797+}
54798+early_initcall(init_exec_counters);
54799+static inline void increment_exec_counter(void)
54800+{
54801+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54802+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54803+}
54804+#else
54805+static inline void increment_exec_counter(void) {}
54806+#endif
54807+
54808+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54809+ struct user_arg_ptr argv);
54810+
54811 /*
54812 * sys_execve() executes a new program.
54813 */
54814@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54815 struct user_arg_ptr argv,
54816 struct user_arg_ptr envp)
54817 {
54818+#ifdef CONFIG_GRKERNSEC
54819+ struct file *old_exec_file;
54820+ struct acl_subject_label *old_acl;
54821+ struct rlimit old_rlim[RLIM_NLIMITS];
54822+#endif
54823 struct linux_binprm *bprm;
54824 struct file *file;
54825 struct files_struct *displaced;
54826 bool clear_in_exec;
54827 int retval;
54828
54829+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54830+
54831 /*
54832 * We move the actual failure in case of RLIMIT_NPROC excess from
54833 * set*uid() to execve() because too many poorly written programs
54834@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54835 if (IS_ERR(file))
54836 goto out_unmark;
54837
54838+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54839+ retval = -EPERM;
54840+ goto out_file;
54841+ }
54842+
54843 sched_exec();
54844
54845 bprm->file = file;
54846 bprm->filename = filename;
54847 bprm->interp = filename;
54848
54849+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54850+ retval = -EACCES;
54851+ goto out_file;
54852+ }
54853+
54854 retval = bprm_mm_init(bprm);
54855 if (retval)
54856 goto out_file;
54857@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54858 if (retval < 0)
54859 goto out;
54860
54861+#ifdef CONFIG_GRKERNSEC
54862+ old_acl = current->acl;
54863+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54864+ old_exec_file = current->exec_file;
54865+ get_file(file);
54866+ current->exec_file = file;
54867+#endif
54868+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54869+ /* limit suid stack to 8MB
54870+ * we saved the old limits above and will restore them if this exec fails
54871+ */
54872+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54873+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54874+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54875+#endif
54876+
54877+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54878+ retval = -EPERM;
54879+ goto out_fail;
54880+ }
54881+
54882+ if (!gr_tpe_allow(file)) {
54883+ retval = -EACCES;
54884+ goto out_fail;
54885+ }
54886+
54887+ if (gr_check_crash_exec(file)) {
54888+ retval = -EACCES;
54889+ goto out_fail;
54890+ }
54891+
54892+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54893+ bprm->unsafe);
54894+ if (retval < 0)
54895+ goto out_fail;
54896+
54897 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54898 if (retval < 0)
54899- goto out;
54900+ goto out_fail;
54901
54902 bprm->exec = bprm->p;
54903 retval = copy_strings(bprm->envc, envp, bprm);
54904 if (retval < 0)
54905- goto out;
54906+ goto out_fail;
54907
54908 retval = copy_strings(bprm->argc, argv, bprm);
54909 if (retval < 0)
54910- goto out;
54911+ goto out_fail;
54912+
54913+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
54914+
54915+ gr_handle_exec_args(bprm, argv);
54916
54917 retval = search_binary_handler(bprm);
54918 if (retval < 0)
54919- goto out;
54920+ goto out_fail;
54921+#ifdef CONFIG_GRKERNSEC
54922+ if (old_exec_file)
54923+ fput(old_exec_file);
54924+#endif
54925
54926 /* execve succeeded */
54927+
54928+ increment_exec_counter();
54929 current->fs->in_exec = 0;
54930 current->in_execve = 0;
54931 acct_update_integrals(current);
54932@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
54933 put_files_struct(displaced);
54934 return retval;
54935
54936+out_fail:
54937+#ifdef CONFIG_GRKERNSEC
54938+ current->acl = old_acl;
54939+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
54940+ fput(current->exec_file);
54941+ current->exec_file = old_exec_file;
54942+#endif
54943+
54944 out:
54945 if (bprm->mm) {
54946 acct_arg_size(bprm, 0);
54947@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
54948 return error;
54949 }
54950 #endif
54951+
54952+int pax_check_flags(unsigned long *flags)
54953+{
54954+ int retval = 0;
54955+
54956+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
54957+ if (*flags & MF_PAX_SEGMEXEC)
54958+ {
54959+ *flags &= ~MF_PAX_SEGMEXEC;
54960+ retval = -EINVAL;
54961+ }
54962+#endif
54963+
54964+ if ((*flags & MF_PAX_PAGEEXEC)
54965+
54966+#ifdef CONFIG_PAX_PAGEEXEC
54967+ && (*flags & MF_PAX_SEGMEXEC)
54968+#endif
54969+
54970+ )
54971+ {
54972+ *flags &= ~MF_PAX_PAGEEXEC;
54973+ retval = -EINVAL;
54974+ }
54975+
54976+ if ((*flags & MF_PAX_MPROTECT)
54977+
54978+#ifdef CONFIG_PAX_MPROTECT
54979+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
54980+#endif
54981+
54982+ )
54983+ {
54984+ *flags &= ~MF_PAX_MPROTECT;
54985+ retval = -EINVAL;
54986+ }
54987+
54988+ if ((*flags & MF_PAX_EMUTRAMP)
54989+
54990+#ifdef CONFIG_PAX_EMUTRAMP
54991+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
54992+#endif
54993+
54994+ )
54995+ {
54996+ *flags &= ~MF_PAX_EMUTRAMP;
54997+ retval = -EINVAL;
54998+ }
54999+
55000+ return retval;
55001+}
55002+
55003+EXPORT_SYMBOL(pax_check_flags);
55004+
55005+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55006+char *pax_get_path(const struct path *path, char *buf, int buflen)
55007+{
55008+ char *pathname = d_path(path, buf, buflen);
55009+
55010+ if (IS_ERR(pathname))
55011+ goto toolong;
55012+
55013+ pathname = mangle_path(buf, pathname, "\t\n\\");
55014+ if (!pathname)
55015+ goto toolong;
55016+
55017+ *pathname = 0;
55018+ return buf;
55019+
55020+toolong:
55021+ return "<path too long>";
55022+}
55023+EXPORT_SYMBOL(pax_get_path);
55024+
55025+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55026+{
55027+ struct task_struct *tsk = current;
55028+ struct mm_struct *mm = current->mm;
55029+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55030+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55031+ char *path_exec = NULL;
55032+ char *path_fault = NULL;
55033+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55034+ siginfo_t info = { };
55035+
55036+ if (buffer_exec && buffer_fault) {
55037+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55038+
55039+ down_read(&mm->mmap_sem);
55040+ vma = mm->mmap;
55041+ while (vma && (!vma_exec || !vma_fault)) {
55042+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55043+ vma_exec = vma;
55044+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55045+ vma_fault = vma;
55046+ vma = vma->vm_next;
55047+ }
55048+ if (vma_exec)
55049+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55050+ if (vma_fault) {
55051+ start = vma_fault->vm_start;
55052+ end = vma_fault->vm_end;
55053+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55054+ if (vma_fault->vm_file)
55055+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55056+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55057+ path_fault = "<heap>";
55058+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55059+ path_fault = "<stack>";
55060+ else
55061+ path_fault = "<anonymous mapping>";
55062+ }
55063+ up_read(&mm->mmap_sem);
55064+ }
55065+ if (tsk->signal->curr_ip)
55066+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55067+ else
55068+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55069+ 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),
55070+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55071+ free_page((unsigned long)buffer_exec);
55072+ free_page((unsigned long)buffer_fault);
55073+ pax_report_insns(regs, pc, sp);
55074+ info.si_signo = SIGKILL;
55075+ info.si_errno = 0;
55076+ info.si_code = SI_KERNEL;
55077+ info.si_pid = 0;
55078+ info.si_uid = 0;
55079+ do_coredump(&info);
55080+}
55081+#endif
55082+
55083+#ifdef CONFIG_PAX_REFCOUNT
55084+void pax_report_refcount_overflow(struct pt_regs *regs)
55085+{
55086+ if (current->signal->curr_ip)
55087+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55088+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55089+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55090+ else
55091+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55092+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55093+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55094+ preempt_disable();
55095+ show_regs(regs);
55096+ preempt_enable();
55097+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55098+}
55099+#endif
55100+
55101+#ifdef CONFIG_PAX_USERCOPY
55102+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55103+static noinline int check_stack_object(const void *obj, unsigned long len)
55104+{
55105+ const void * const stack = task_stack_page(current);
55106+ const void * const stackend = stack + THREAD_SIZE;
55107+
55108+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55109+ const void *frame = NULL;
55110+ const void *oldframe;
55111+#endif
55112+
55113+ if (obj + len < obj)
55114+ return -1;
55115+
55116+ if (obj + len <= stack || stackend <= obj)
55117+ return 0;
55118+
55119+ if (obj < stack || stackend < obj + len)
55120+ return -1;
55121+
55122+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55123+ oldframe = __builtin_frame_address(1);
55124+ if (oldframe)
55125+ frame = __builtin_frame_address(2);
55126+ /*
55127+ low ----------------------------------------------> high
55128+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55129+ ^----------------^
55130+ allow copies only within here
55131+ */
55132+ while (stack <= frame && frame < stackend) {
55133+ /* if obj + len extends past the last frame, this
55134+ check won't pass and the next frame will be 0,
55135+ causing us to bail out and correctly report
55136+ the copy as invalid
55137+ */
55138+ if (obj + len <= frame)
55139+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55140+ oldframe = frame;
55141+ frame = *(const void * const *)frame;
55142+ }
55143+ return -1;
55144+#else
55145+ return 1;
55146+#endif
55147+}
55148+
55149+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55150+{
55151+ if (current->signal->curr_ip)
55152+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55153+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55154+ else
55155+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55156+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55157+ dump_stack();
55158+ gr_handle_kernel_exploit();
55159+ do_group_exit(SIGKILL);
55160+}
55161+#endif
55162+
55163+#ifdef CONFIG_PAX_USERCOPY
55164+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55165+{
55166+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55167+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55168+#ifdef CONFIG_MODULES
55169+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55170+#else
55171+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55172+#endif
55173+
55174+#else
55175+ unsigned long textlow = (unsigned long)_stext;
55176+ unsigned long texthigh = (unsigned long)_etext;
55177+#endif
55178+
55179+ if (high <= textlow || low > texthigh)
55180+ return false;
55181+ else
55182+ return true;
55183+}
55184+#endif
55185+
55186+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55187+{
55188+
55189+#ifdef CONFIG_PAX_USERCOPY
55190+ const char *type;
55191+
55192+ if (!n)
55193+ return;
55194+
55195+ type = check_heap_object(ptr, n);
55196+ if (!type) {
55197+ int ret = check_stack_object(ptr, n);
55198+ if (ret == 1 || ret == 2)
55199+ return;
55200+ if (ret == 0) {
55201+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55202+ type = "<kernel text>";
55203+ else
55204+ return;
55205+ } else
55206+ type = "<process stack>";
55207+ }
55208+
55209+ pax_report_usercopy(ptr, n, to_user, type);
55210+#endif
55211+
55212+}
55213+EXPORT_SYMBOL(__check_object_size);
55214+
55215+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55216+void pax_track_stack(void)
55217+{
55218+ unsigned long sp = (unsigned long)&sp;
55219+ if (sp < current_thread_info()->lowest_stack &&
55220+ sp > (unsigned long)task_stack_page(current))
55221+ current_thread_info()->lowest_stack = sp;
55222+}
55223+EXPORT_SYMBOL(pax_track_stack);
55224+#endif
55225+
55226+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55227+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55228+{
55229+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55230+ dump_stack();
55231+ do_group_exit(SIGKILL);
55232+}
55233+EXPORT_SYMBOL(report_size_overflow);
55234+#endif
55235diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55236index 9f9992b..8b59411 100644
55237--- a/fs/ext2/balloc.c
55238+++ b/fs/ext2/balloc.c
55239@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55240
55241 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55242 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55243- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55244+ if (free_blocks < root_blocks + 1 &&
55245 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55246 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55247- !in_group_p (sbi->s_resgid))) {
55248+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55249 return 0;
55250 }
55251 return 1;
55252diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55253index 22548f5..41521d8 100644
55254--- a/fs/ext3/balloc.c
55255+++ b/fs/ext3/balloc.c
55256@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55257
55258 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55259 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55260- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55261+ if (free_blocks < root_blocks + 1 &&
55262 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55263 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55264- !in_group_p (sbi->s_resgid))) {
55265+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55266 return 0;
55267 }
55268 return 1;
55269diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55270index ddd715e..c772f88 100644
55271--- a/fs/ext4/balloc.c
55272+++ b/fs/ext4/balloc.c
55273@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55274 /* Hm, nope. Are (enough) root reserved clusters available? */
55275 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55276 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55277- capable(CAP_SYS_RESOURCE) ||
55278- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55279+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55280+ capable_nolog(CAP_SYS_RESOURCE)) {
55281
55282 if (free_clusters >= (nclusters + dirty_clusters +
55283 resv_clusters))
55284diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55285index 0ab26fb..b6ecb39 100644
55286--- a/fs/ext4/ext4.h
55287+++ b/fs/ext4/ext4.h
55288@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55289 unsigned long s_mb_last_start;
55290
55291 /* stats for buddy allocator */
55292- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55293- atomic_t s_bal_success; /* we found long enough chunks */
55294- atomic_t s_bal_allocated; /* in blocks */
55295- atomic_t s_bal_ex_scanned; /* total extents scanned */
55296- atomic_t s_bal_goals; /* goal hits */
55297- atomic_t s_bal_breaks; /* too long searches */
55298- atomic_t s_bal_2orders; /* 2^order hits */
55299+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55300+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55301+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55302+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55303+ atomic_unchecked_t s_bal_goals; /* goal hits */
55304+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55305+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55306 spinlock_t s_bal_lock;
55307 unsigned long s_mb_buddies_generated;
55308 unsigned long long s_mb_generation_time;
55309- atomic_t s_mb_lost_chunks;
55310- atomic_t s_mb_preallocated;
55311- atomic_t s_mb_discarded;
55312+ atomic_unchecked_t s_mb_lost_chunks;
55313+ atomic_unchecked_t s_mb_preallocated;
55314+ atomic_unchecked_t s_mb_discarded;
55315 atomic_t s_lock_busy;
55316
55317 /* locality groups */
55318diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55319index 4bbbf13b..dcceaeb 100644
55320--- a/fs/ext4/mballoc.c
55321+++ b/fs/ext4/mballoc.c
55322@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55323 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55324
55325 if (EXT4_SB(sb)->s_mb_stats)
55326- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55327+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55328
55329 break;
55330 }
55331@@ -2171,7 +2171,7 @@ repeat:
55332 ac->ac_status = AC_STATUS_CONTINUE;
55333 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55334 cr = 3;
55335- atomic_inc(&sbi->s_mb_lost_chunks);
55336+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55337 goto repeat;
55338 }
55339 }
55340@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55341 if (sbi->s_mb_stats) {
55342 ext4_msg(sb, KERN_INFO,
55343 "mballoc: %u blocks %u reqs (%u success)",
55344- atomic_read(&sbi->s_bal_allocated),
55345- atomic_read(&sbi->s_bal_reqs),
55346- atomic_read(&sbi->s_bal_success));
55347+ atomic_read_unchecked(&sbi->s_bal_allocated),
55348+ atomic_read_unchecked(&sbi->s_bal_reqs),
55349+ atomic_read_unchecked(&sbi->s_bal_success));
55350 ext4_msg(sb, KERN_INFO,
55351 "mballoc: %u extents scanned, %u goal hits, "
55352 "%u 2^N hits, %u breaks, %u lost",
55353- atomic_read(&sbi->s_bal_ex_scanned),
55354- atomic_read(&sbi->s_bal_goals),
55355- atomic_read(&sbi->s_bal_2orders),
55356- atomic_read(&sbi->s_bal_breaks),
55357- atomic_read(&sbi->s_mb_lost_chunks));
55358+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55359+ atomic_read_unchecked(&sbi->s_bal_goals),
55360+ atomic_read_unchecked(&sbi->s_bal_2orders),
55361+ atomic_read_unchecked(&sbi->s_bal_breaks),
55362+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55363 ext4_msg(sb, KERN_INFO,
55364 "mballoc: %lu generated and it took %Lu",
55365 sbi->s_mb_buddies_generated,
55366 sbi->s_mb_generation_time);
55367 ext4_msg(sb, KERN_INFO,
55368 "mballoc: %u preallocated, %u discarded",
55369- atomic_read(&sbi->s_mb_preallocated),
55370- atomic_read(&sbi->s_mb_discarded));
55371+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55372+ atomic_read_unchecked(&sbi->s_mb_discarded));
55373 }
55374
55375 free_percpu(sbi->s_locality_groups);
55376@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55377 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55378
55379 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55380- atomic_inc(&sbi->s_bal_reqs);
55381- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55382+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55383+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55384 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55385- atomic_inc(&sbi->s_bal_success);
55386- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55387+ atomic_inc_unchecked(&sbi->s_bal_success);
55388+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55389 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55390 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55391- atomic_inc(&sbi->s_bal_goals);
55392+ atomic_inc_unchecked(&sbi->s_bal_goals);
55393 if (ac->ac_found > sbi->s_mb_max_to_scan)
55394- atomic_inc(&sbi->s_bal_breaks);
55395+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55396 }
55397
55398 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55399@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55400 trace_ext4_mb_new_inode_pa(ac, pa);
55401
55402 ext4_mb_use_inode_pa(ac, pa);
55403- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55404+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55405
55406 ei = EXT4_I(ac->ac_inode);
55407 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55408@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55409 trace_ext4_mb_new_group_pa(ac, pa);
55410
55411 ext4_mb_use_group_pa(ac, pa);
55412- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55413+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55414
55415 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55416 lg = ac->ac_lg;
55417@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55418 * from the bitmap and continue.
55419 */
55420 }
55421- atomic_add(free, &sbi->s_mb_discarded);
55422+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55423
55424 return err;
55425 }
55426@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55427 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55428 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55429 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55430- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55431+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55432 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55433
55434 return 0;
55435diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55436index 214461e..3614c89 100644
55437--- a/fs/ext4/mmp.c
55438+++ b/fs/ext4/mmp.c
55439@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55440 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55441 const char *function, unsigned int line, const char *msg)
55442 {
55443- __ext4_warning(sb, function, line, msg);
55444+ __ext4_warning(sb, function, line, "%s", msg);
55445 __ext4_warning(sb, function, line,
55446 "MMP failure info: last update time: %llu, last update "
55447 "node: %s, last update device: %s\n",
55448diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55449index b59373b..f41c2b5 100644
55450--- a/fs/ext4/super.c
55451+++ b/fs/ext4/super.c
55452@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55453 }
55454
55455 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55456-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55457+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55458 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55459
55460 #ifdef CONFIG_QUOTA
55461@@ -2394,7 +2394,7 @@ struct ext4_attr {
55462 int offset;
55463 int deprecated_val;
55464 } u;
55465-};
55466+} __do_const;
55467
55468 static int parse_strtoull(const char *buf,
55469 unsigned long long max, unsigned long long *value)
55470diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
55471index c081e34..03e9beb 100644
55472--- a/fs/ext4/xattr.c
55473+++ b/fs/ext4/xattr.c
55474@@ -1350,6 +1350,8 @@ retry:
55475 s_min_extra_isize) {
55476 tried_min_extra_isize++;
55477 new_extra_isize = s_min_extra_isize;
55478+ kfree(is); is = NULL;
55479+ kfree(bs); bs = NULL;
55480 goto retry;
55481 }
55482 error = -1;
55483diff --git a/fs/fcntl.c b/fs/fcntl.c
55484index 65343c3..9969dcf 100644
55485--- a/fs/fcntl.c
55486+++ b/fs/fcntl.c
55487@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55488 if (err)
55489 return err;
55490
55491+ if (gr_handle_chroot_fowner(pid, type))
55492+ return -ENOENT;
55493+ if (gr_check_protected_task_fowner(pid, type))
55494+ return -EACCES;
55495+
55496 f_modown(filp, pid, type, force);
55497 return 0;
55498 }
55499diff --git a/fs/fhandle.c b/fs/fhandle.c
55500index 999ff5c..41f4109 100644
55501--- a/fs/fhandle.c
55502+++ b/fs/fhandle.c
55503@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55504 } else
55505 retval = 0;
55506 /* copy the mount id */
55507- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55508- sizeof(*mnt_id)) ||
55509+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55510 copy_to_user(ufh, handle,
55511 sizeof(struct file_handle) + handle_bytes))
55512 retval = -EFAULT;
55513diff --git a/fs/file.c b/fs/file.c
55514index 4a78f98..9447397 100644
55515--- a/fs/file.c
55516+++ b/fs/file.c
55517@@ -16,6 +16,7 @@
55518 #include <linux/slab.h>
55519 #include <linux/vmalloc.h>
55520 #include <linux/file.h>
55521+#include <linux/security.h>
55522 #include <linux/fdtable.h>
55523 #include <linux/bitops.h>
55524 #include <linux/interrupt.h>
55525@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55526 if (!file)
55527 return __close_fd(files, fd);
55528
55529+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55530 if (fd >= rlimit(RLIMIT_NOFILE))
55531 return -EBADF;
55532
55533@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55534 if (unlikely(oldfd == newfd))
55535 return -EINVAL;
55536
55537+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55538 if (newfd >= rlimit(RLIMIT_NOFILE))
55539 return -EBADF;
55540
55541@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55542 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55543 {
55544 int err;
55545+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55546 if (from >= rlimit(RLIMIT_NOFILE))
55547 return -EINVAL;
55548 err = alloc_fd(from, flags);
55549diff --git a/fs/filesystems.c b/fs/filesystems.c
55550index 92567d9..fcd8cbf 100644
55551--- a/fs/filesystems.c
55552+++ b/fs/filesystems.c
55553@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55554 int len = dot ? dot - name : strlen(name);
55555
55556 fs = __get_fs_type(name, len);
55557+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55558+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55559+#else
55560 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55561+#endif
55562 fs = __get_fs_type(name, len);
55563
55564 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55565diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55566index d8ac61d..79a36f0 100644
55567--- a/fs/fs_struct.c
55568+++ b/fs/fs_struct.c
55569@@ -4,6 +4,7 @@
55570 #include <linux/path.h>
55571 #include <linux/slab.h>
55572 #include <linux/fs_struct.h>
55573+#include <linux/grsecurity.h>
55574 #include "internal.h"
55575
55576 /*
55577@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55578 write_seqcount_begin(&fs->seq);
55579 old_root = fs->root;
55580 fs->root = *path;
55581+ gr_set_chroot_entries(current, path);
55582 write_seqcount_end(&fs->seq);
55583 spin_unlock(&fs->lock);
55584 if (old_root.dentry)
55585@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55586 int hits = 0;
55587 spin_lock(&fs->lock);
55588 write_seqcount_begin(&fs->seq);
55589+ /* this root replacement is only done by pivot_root,
55590+ leave grsec's chroot tagging alone for this task
55591+ so that a pivoted root isn't treated as a chroot
55592+ */
55593 hits += replace_path(&fs->root, old_root, new_root);
55594 hits += replace_path(&fs->pwd, old_root, new_root);
55595 write_seqcount_end(&fs->seq);
55596@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55597 task_lock(tsk);
55598 spin_lock(&fs->lock);
55599 tsk->fs = NULL;
55600- kill = !--fs->users;
55601+ gr_clear_chroot_entries(tsk);
55602+ kill = !atomic_dec_return(&fs->users);
55603 spin_unlock(&fs->lock);
55604 task_unlock(tsk);
55605 if (kill)
55606@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55607 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55608 /* We don't need to lock fs - think why ;-) */
55609 if (fs) {
55610- fs->users = 1;
55611+ atomic_set(&fs->users, 1);
55612 fs->in_exec = 0;
55613 spin_lock_init(&fs->lock);
55614 seqcount_init(&fs->seq);
55615@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55616 spin_lock(&old->lock);
55617 fs->root = old->root;
55618 path_get(&fs->root);
55619+ /* instead of calling gr_set_chroot_entries here,
55620+ we call it from every caller of this function
55621+ */
55622 fs->pwd = old->pwd;
55623 path_get(&fs->pwd);
55624 spin_unlock(&old->lock);
55625@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55626
55627 task_lock(current);
55628 spin_lock(&fs->lock);
55629- kill = !--fs->users;
55630+ kill = !atomic_dec_return(&fs->users);
55631 current->fs = new_fs;
55632+ gr_set_chroot_entries(current, &new_fs->root);
55633 spin_unlock(&fs->lock);
55634 task_unlock(current);
55635
55636@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55637
55638 int current_umask(void)
55639 {
55640- return current->fs->umask;
55641+ return current->fs->umask | gr_acl_umask();
55642 }
55643 EXPORT_SYMBOL(current_umask);
55644
55645 /* to be mentioned only in INIT_TASK */
55646 struct fs_struct init_fs = {
55647- .users = 1,
55648+ .users = ATOMIC_INIT(1),
55649 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55650 .seq = SEQCNT_ZERO,
55651 .umask = 0022,
55652diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55653index 0e91a3c..6c6d2e0 100644
55654--- a/fs/fscache/cookie.c
55655+++ b/fs/fscache/cookie.c
55656@@ -19,7 +19,7 @@
55657
55658 struct kmem_cache *fscache_cookie_jar;
55659
55660-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55661+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55662
55663 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55664 static int fscache_alloc_object(struct fscache_cache *cache,
55665@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55666 parent ? (char *) parent->def->name : "<no-parent>",
55667 def->name, netfs_data);
55668
55669- fscache_stat(&fscache_n_acquires);
55670+ fscache_stat_unchecked(&fscache_n_acquires);
55671
55672 /* if there's no parent cookie, then we don't create one here either */
55673 if (!parent) {
55674- fscache_stat(&fscache_n_acquires_null);
55675+ fscache_stat_unchecked(&fscache_n_acquires_null);
55676 _leave(" [no parent]");
55677 return NULL;
55678 }
55679@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55680 /* allocate and initialise a cookie */
55681 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55682 if (!cookie) {
55683- fscache_stat(&fscache_n_acquires_oom);
55684+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55685 _leave(" [ENOMEM]");
55686 return NULL;
55687 }
55688@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55689
55690 switch (cookie->def->type) {
55691 case FSCACHE_COOKIE_TYPE_INDEX:
55692- fscache_stat(&fscache_n_cookie_index);
55693+ fscache_stat_unchecked(&fscache_n_cookie_index);
55694 break;
55695 case FSCACHE_COOKIE_TYPE_DATAFILE:
55696- fscache_stat(&fscache_n_cookie_data);
55697+ fscache_stat_unchecked(&fscache_n_cookie_data);
55698 break;
55699 default:
55700- fscache_stat(&fscache_n_cookie_special);
55701+ fscache_stat_unchecked(&fscache_n_cookie_special);
55702 break;
55703 }
55704
55705@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55706 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55707 atomic_dec(&parent->n_children);
55708 __fscache_cookie_put(cookie);
55709- fscache_stat(&fscache_n_acquires_nobufs);
55710+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55711 _leave(" = NULL");
55712 return NULL;
55713 }
55714 }
55715
55716- fscache_stat(&fscache_n_acquires_ok);
55717+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55718 _leave(" = %p", cookie);
55719 return cookie;
55720 }
55721@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55722 cache = fscache_select_cache_for_object(cookie->parent);
55723 if (!cache) {
55724 up_read(&fscache_addremove_sem);
55725- fscache_stat(&fscache_n_acquires_no_cache);
55726+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55727 _leave(" = -ENOMEDIUM [no cache]");
55728 return -ENOMEDIUM;
55729 }
55730@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55731 object = cache->ops->alloc_object(cache, cookie);
55732 fscache_stat_d(&fscache_n_cop_alloc_object);
55733 if (IS_ERR(object)) {
55734- fscache_stat(&fscache_n_object_no_alloc);
55735+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55736 ret = PTR_ERR(object);
55737 goto error;
55738 }
55739
55740- fscache_stat(&fscache_n_object_alloc);
55741+ fscache_stat_unchecked(&fscache_n_object_alloc);
55742
55743- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55744+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55745
55746 _debug("ALLOC OBJ%x: %s {%lx}",
55747 object->debug_id, cookie->def->name, object->events);
55748@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55749
55750 _enter("{%s}", cookie->def->name);
55751
55752- fscache_stat(&fscache_n_invalidates);
55753+ fscache_stat_unchecked(&fscache_n_invalidates);
55754
55755 /* Only permit invalidation of data files. Invalidating an index will
55756 * require the caller to release all its attachments to the tree rooted
55757@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55758 {
55759 struct fscache_object *object;
55760
55761- fscache_stat(&fscache_n_updates);
55762+ fscache_stat_unchecked(&fscache_n_updates);
55763
55764 if (!cookie) {
55765- fscache_stat(&fscache_n_updates_null);
55766+ fscache_stat_unchecked(&fscache_n_updates_null);
55767 _leave(" [no cookie]");
55768 return;
55769 }
55770@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55771 {
55772 struct fscache_object *object;
55773
55774- fscache_stat(&fscache_n_relinquishes);
55775+ fscache_stat_unchecked(&fscache_n_relinquishes);
55776 if (retire)
55777- fscache_stat(&fscache_n_relinquishes_retire);
55778+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55779
55780 if (!cookie) {
55781- fscache_stat(&fscache_n_relinquishes_null);
55782+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55783 _leave(" [no cookie]");
55784 return;
55785 }
55786diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55787index 12d505b..86473a3 100644
55788--- a/fs/fscache/internal.h
55789+++ b/fs/fscache/internal.h
55790@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55791 * stats.c
55792 */
55793 #ifdef CONFIG_FSCACHE_STATS
55794-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55795-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55796+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55797+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55798
55799-extern atomic_t fscache_n_op_pend;
55800-extern atomic_t fscache_n_op_run;
55801-extern atomic_t fscache_n_op_enqueue;
55802-extern atomic_t fscache_n_op_deferred_release;
55803-extern atomic_t fscache_n_op_release;
55804-extern atomic_t fscache_n_op_gc;
55805-extern atomic_t fscache_n_op_cancelled;
55806-extern atomic_t fscache_n_op_rejected;
55807+extern atomic_unchecked_t fscache_n_op_pend;
55808+extern atomic_unchecked_t fscache_n_op_run;
55809+extern atomic_unchecked_t fscache_n_op_enqueue;
55810+extern atomic_unchecked_t fscache_n_op_deferred_release;
55811+extern atomic_unchecked_t fscache_n_op_release;
55812+extern atomic_unchecked_t fscache_n_op_gc;
55813+extern atomic_unchecked_t fscache_n_op_cancelled;
55814+extern atomic_unchecked_t fscache_n_op_rejected;
55815
55816-extern atomic_t fscache_n_attr_changed;
55817-extern atomic_t fscache_n_attr_changed_ok;
55818-extern atomic_t fscache_n_attr_changed_nobufs;
55819-extern atomic_t fscache_n_attr_changed_nomem;
55820-extern atomic_t fscache_n_attr_changed_calls;
55821+extern atomic_unchecked_t fscache_n_attr_changed;
55822+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55823+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55824+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55825+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55826
55827-extern atomic_t fscache_n_allocs;
55828-extern atomic_t fscache_n_allocs_ok;
55829-extern atomic_t fscache_n_allocs_wait;
55830-extern atomic_t fscache_n_allocs_nobufs;
55831-extern atomic_t fscache_n_allocs_intr;
55832-extern atomic_t fscache_n_allocs_object_dead;
55833-extern atomic_t fscache_n_alloc_ops;
55834-extern atomic_t fscache_n_alloc_op_waits;
55835+extern atomic_unchecked_t fscache_n_allocs;
55836+extern atomic_unchecked_t fscache_n_allocs_ok;
55837+extern atomic_unchecked_t fscache_n_allocs_wait;
55838+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55839+extern atomic_unchecked_t fscache_n_allocs_intr;
55840+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55841+extern atomic_unchecked_t fscache_n_alloc_ops;
55842+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55843
55844-extern atomic_t fscache_n_retrievals;
55845-extern atomic_t fscache_n_retrievals_ok;
55846-extern atomic_t fscache_n_retrievals_wait;
55847-extern atomic_t fscache_n_retrievals_nodata;
55848-extern atomic_t fscache_n_retrievals_nobufs;
55849-extern atomic_t fscache_n_retrievals_intr;
55850-extern atomic_t fscache_n_retrievals_nomem;
55851-extern atomic_t fscache_n_retrievals_object_dead;
55852-extern atomic_t fscache_n_retrieval_ops;
55853-extern atomic_t fscache_n_retrieval_op_waits;
55854+extern atomic_unchecked_t fscache_n_retrievals;
55855+extern atomic_unchecked_t fscache_n_retrievals_ok;
55856+extern atomic_unchecked_t fscache_n_retrievals_wait;
55857+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55858+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55859+extern atomic_unchecked_t fscache_n_retrievals_intr;
55860+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55861+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55862+extern atomic_unchecked_t fscache_n_retrieval_ops;
55863+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55864
55865-extern atomic_t fscache_n_stores;
55866-extern atomic_t fscache_n_stores_ok;
55867-extern atomic_t fscache_n_stores_again;
55868-extern atomic_t fscache_n_stores_nobufs;
55869-extern atomic_t fscache_n_stores_oom;
55870-extern atomic_t fscache_n_store_ops;
55871-extern atomic_t fscache_n_store_calls;
55872-extern atomic_t fscache_n_store_pages;
55873-extern atomic_t fscache_n_store_radix_deletes;
55874-extern atomic_t fscache_n_store_pages_over_limit;
55875+extern atomic_unchecked_t fscache_n_stores;
55876+extern atomic_unchecked_t fscache_n_stores_ok;
55877+extern atomic_unchecked_t fscache_n_stores_again;
55878+extern atomic_unchecked_t fscache_n_stores_nobufs;
55879+extern atomic_unchecked_t fscache_n_stores_oom;
55880+extern atomic_unchecked_t fscache_n_store_ops;
55881+extern atomic_unchecked_t fscache_n_store_calls;
55882+extern atomic_unchecked_t fscache_n_store_pages;
55883+extern atomic_unchecked_t fscache_n_store_radix_deletes;
55884+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
55885
55886-extern atomic_t fscache_n_store_vmscan_not_storing;
55887-extern atomic_t fscache_n_store_vmscan_gone;
55888-extern atomic_t fscache_n_store_vmscan_busy;
55889-extern atomic_t fscache_n_store_vmscan_cancelled;
55890-extern atomic_t fscache_n_store_vmscan_wait;
55891+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55892+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
55893+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
55894+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55895+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
55896
55897-extern atomic_t fscache_n_marks;
55898-extern atomic_t fscache_n_uncaches;
55899+extern atomic_unchecked_t fscache_n_marks;
55900+extern atomic_unchecked_t fscache_n_uncaches;
55901
55902-extern atomic_t fscache_n_acquires;
55903-extern atomic_t fscache_n_acquires_null;
55904-extern atomic_t fscache_n_acquires_no_cache;
55905-extern atomic_t fscache_n_acquires_ok;
55906-extern atomic_t fscache_n_acquires_nobufs;
55907-extern atomic_t fscache_n_acquires_oom;
55908+extern atomic_unchecked_t fscache_n_acquires;
55909+extern atomic_unchecked_t fscache_n_acquires_null;
55910+extern atomic_unchecked_t fscache_n_acquires_no_cache;
55911+extern atomic_unchecked_t fscache_n_acquires_ok;
55912+extern atomic_unchecked_t fscache_n_acquires_nobufs;
55913+extern atomic_unchecked_t fscache_n_acquires_oom;
55914
55915-extern atomic_t fscache_n_invalidates;
55916-extern atomic_t fscache_n_invalidates_run;
55917+extern atomic_unchecked_t fscache_n_invalidates;
55918+extern atomic_unchecked_t fscache_n_invalidates_run;
55919
55920-extern atomic_t fscache_n_updates;
55921-extern atomic_t fscache_n_updates_null;
55922-extern atomic_t fscache_n_updates_run;
55923+extern atomic_unchecked_t fscache_n_updates;
55924+extern atomic_unchecked_t fscache_n_updates_null;
55925+extern atomic_unchecked_t fscache_n_updates_run;
55926
55927-extern atomic_t fscache_n_relinquishes;
55928-extern atomic_t fscache_n_relinquishes_null;
55929-extern atomic_t fscache_n_relinquishes_waitcrt;
55930-extern atomic_t fscache_n_relinquishes_retire;
55931+extern atomic_unchecked_t fscache_n_relinquishes;
55932+extern atomic_unchecked_t fscache_n_relinquishes_null;
55933+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
55934+extern atomic_unchecked_t fscache_n_relinquishes_retire;
55935
55936-extern atomic_t fscache_n_cookie_index;
55937-extern atomic_t fscache_n_cookie_data;
55938-extern atomic_t fscache_n_cookie_special;
55939+extern atomic_unchecked_t fscache_n_cookie_index;
55940+extern atomic_unchecked_t fscache_n_cookie_data;
55941+extern atomic_unchecked_t fscache_n_cookie_special;
55942
55943-extern atomic_t fscache_n_object_alloc;
55944-extern atomic_t fscache_n_object_no_alloc;
55945-extern atomic_t fscache_n_object_lookups;
55946-extern atomic_t fscache_n_object_lookups_negative;
55947-extern atomic_t fscache_n_object_lookups_positive;
55948-extern atomic_t fscache_n_object_lookups_timed_out;
55949-extern atomic_t fscache_n_object_created;
55950-extern atomic_t fscache_n_object_avail;
55951-extern atomic_t fscache_n_object_dead;
55952+extern atomic_unchecked_t fscache_n_object_alloc;
55953+extern atomic_unchecked_t fscache_n_object_no_alloc;
55954+extern atomic_unchecked_t fscache_n_object_lookups;
55955+extern atomic_unchecked_t fscache_n_object_lookups_negative;
55956+extern atomic_unchecked_t fscache_n_object_lookups_positive;
55957+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
55958+extern atomic_unchecked_t fscache_n_object_created;
55959+extern atomic_unchecked_t fscache_n_object_avail;
55960+extern atomic_unchecked_t fscache_n_object_dead;
55961
55962-extern atomic_t fscache_n_checkaux_none;
55963-extern atomic_t fscache_n_checkaux_okay;
55964-extern atomic_t fscache_n_checkaux_update;
55965-extern atomic_t fscache_n_checkaux_obsolete;
55966+extern atomic_unchecked_t fscache_n_checkaux_none;
55967+extern atomic_unchecked_t fscache_n_checkaux_okay;
55968+extern atomic_unchecked_t fscache_n_checkaux_update;
55969+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
55970
55971 extern atomic_t fscache_n_cop_alloc_object;
55972 extern atomic_t fscache_n_cop_lookup_object;
55973@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
55974 atomic_inc(stat);
55975 }
55976
55977+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
55978+{
55979+ atomic_inc_unchecked(stat);
55980+}
55981+
55982 static inline void fscache_stat_d(atomic_t *stat)
55983 {
55984 atomic_dec(stat);
55985@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
55986
55987 #define __fscache_stat(stat) (NULL)
55988 #define fscache_stat(stat) do {} while (0)
55989+#define fscache_stat_unchecked(stat) do {} while (0)
55990 #define fscache_stat_d(stat) do {} while (0)
55991 #endif
55992
55993diff --git a/fs/fscache/object.c b/fs/fscache/object.c
55994index 86d75a6..5f3d7a0 100644
55995--- a/fs/fscache/object.c
55996+++ b/fs/fscache/object.c
55997@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
55998 _debug("LOOKUP \"%s\" in \"%s\"",
55999 cookie->def->name, object->cache->tag->name);
56000
56001- fscache_stat(&fscache_n_object_lookups);
56002+ fscache_stat_unchecked(&fscache_n_object_lookups);
56003 fscache_stat(&fscache_n_cop_lookup_object);
56004 ret = object->cache->ops->lookup_object(object);
56005 fscache_stat_d(&fscache_n_cop_lookup_object);
56006@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56007 if (ret == -ETIMEDOUT) {
56008 /* probably stuck behind another object, so move this one to
56009 * the back of the queue */
56010- fscache_stat(&fscache_n_object_lookups_timed_out);
56011+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56012 _leave(" [timeout]");
56013 return NO_TRANSIT;
56014 }
56015@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56016 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56017
56018 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56019- fscache_stat(&fscache_n_object_lookups_negative);
56020+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56021
56022 /* Allow write requests to begin stacking up and read requests to begin
56023 * returning ENODATA.
56024@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56025 /* if we were still looking up, then we must have a positive lookup
56026 * result, in which case there may be data available */
56027 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56028- fscache_stat(&fscache_n_object_lookups_positive);
56029+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56030
56031 /* We do (presumably) have data */
56032 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56033@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56034 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56035 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56036 } else {
56037- fscache_stat(&fscache_n_object_created);
56038+ fscache_stat_unchecked(&fscache_n_object_created);
56039 }
56040
56041 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56042@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56043 fscache_stat_d(&fscache_n_cop_lookup_complete);
56044
56045 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56046- fscache_stat(&fscache_n_object_avail);
56047+ fscache_stat_unchecked(&fscache_n_object_avail);
56048
56049 _leave("");
56050 return transit_to(JUMPSTART_DEPS);
56051@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56052
56053 /* this just shifts the object release to the work processor */
56054 fscache_put_object(object);
56055- fscache_stat(&fscache_n_object_dead);
56056+ fscache_stat_unchecked(&fscache_n_object_dead);
56057
56058 _leave("");
56059 return transit_to(OBJECT_DEAD);
56060@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56061 enum fscache_checkaux result;
56062
56063 if (!object->cookie->def->check_aux) {
56064- fscache_stat(&fscache_n_checkaux_none);
56065+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56066 return FSCACHE_CHECKAUX_OKAY;
56067 }
56068
56069@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56070 switch (result) {
56071 /* entry okay as is */
56072 case FSCACHE_CHECKAUX_OKAY:
56073- fscache_stat(&fscache_n_checkaux_okay);
56074+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56075 break;
56076
56077 /* entry requires update */
56078 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56079- fscache_stat(&fscache_n_checkaux_update);
56080+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56081 break;
56082
56083 /* entry requires deletion */
56084 case FSCACHE_CHECKAUX_OBSOLETE:
56085- fscache_stat(&fscache_n_checkaux_obsolete);
56086+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56087 break;
56088
56089 default:
56090@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56091 {
56092 const struct fscache_state *s;
56093
56094- fscache_stat(&fscache_n_invalidates_run);
56095+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56096 fscache_stat(&fscache_n_cop_invalidate_object);
56097 s = _fscache_invalidate_object(object, event);
56098 fscache_stat_d(&fscache_n_cop_invalidate_object);
56099@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56100 {
56101 _enter("{OBJ%x},%d", object->debug_id, event);
56102
56103- fscache_stat(&fscache_n_updates_run);
56104+ fscache_stat_unchecked(&fscache_n_updates_run);
56105 fscache_stat(&fscache_n_cop_update_object);
56106 object->cache->ops->update_object(object);
56107 fscache_stat_d(&fscache_n_cop_update_object);
56108diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56109index 318071a..379938b 100644
56110--- a/fs/fscache/operation.c
56111+++ b/fs/fscache/operation.c
56112@@ -17,7 +17,7 @@
56113 #include <linux/slab.h>
56114 #include "internal.h"
56115
56116-atomic_t fscache_op_debug_id;
56117+atomic_unchecked_t fscache_op_debug_id;
56118 EXPORT_SYMBOL(fscache_op_debug_id);
56119
56120 /**
56121@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56122 ASSERTCMP(atomic_read(&op->usage), >, 0);
56123 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56124
56125- fscache_stat(&fscache_n_op_enqueue);
56126+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56127 switch (op->flags & FSCACHE_OP_TYPE) {
56128 case FSCACHE_OP_ASYNC:
56129 _debug("queue async");
56130@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56131 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56132 if (op->processor)
56133 fscache_enqueue_operation(op);
56134- fscache_stat(&fscache_n_op_run);
56135+ fscache_stat_unchecked(&fscache_n_op_run);
56136 }
56137
56138 /*
56139@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56140 if (object->n_in_progress > 0) {
56141 atomic_inc(&op->usage);
56142 list_add_tail(&op->pend_link, &object->pending_ops);
56143- fscache_stat(&fscache_n_op_pend);
56144+ fscache_stat_unchecked(&fscache_n_op_pend);
56145 } else if (!list_empty(&object->pending_ops)) {
56146 atomic_inc(&op->usage);
56147 list_add_tail(&op->pend_link, &object->pending_ops);
56148- fscache_stat(&fscache_n_op_pend);
56149+ fscache_stat_unchecked(&fscache_n_op_pend);
56150 fscache_start_operations(object);
56151 } else {
56152 ASSERTCMP(object->n_in_progress, ==, 0);
56153@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56154 object->n_exclusive++; /* reads and writes must wait */
56155 atomic_inc(&op->usage);
56156 list_add_tail(&op->pend_link, &object->pending_ops);
56157- fscache_stat(&fscache_n_op_pend);
56158+ fscache_stat_unchecked(&fscache_n_op_pend);
56159 ret = 0;
56160 } else {
56161 /* If we're in any other state, there must have been an I/O
56162@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56163 if (object->n_exclusive > 0) {
56164 atomic_inc(&op->usage);
56165 list_add_tail(&op->pend_link, &object->pending_ops);
56166- fscache_stat(&fscache_n_op_pend);
56167+ fscache_stat_unchecked(&fscache_n_op_pend);
56168 } else if (!list_empty(&object->pending_ops)) {
56169 atomic_inc(&op->usage);
56170 list_add_tail(&op->pend_link, &object->pending_ops);
56171- fscache_stat(&fscache_n_op_pend);
56172+ fscache_stat_unchecked(&fscache_n_op_pend);
56173 fscache_start_operations(object);
56174 } else {
56175 ASSERTCMP(object->n_exclusive, ==, 0);
56176@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56177 object->n_ops++;
56178 atomic_inc(&op->usage);
56179 list_add_tail(&op->pend_link, &object->pending_ops);
56180- fscache_stat(&fscache_n_op_pend);
56181+ fscache_stat_unchecked(&fscache_n_op_pend);
56182 ret = 0;
56183 } else if (fscache_object_is_dying(object)) {
56184- fscache_stat(&fscache_n_op_rejected);
56185+ fscache_stat_unchecked(&fscache_n_op_rejected);
56186 op->state = FSCACHE_OP_ST_CANCELLED;
56187 ret = -ENOBUFS;
56188 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56189@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56190 ret = -EBUSY;
56191 if (op->state == FSCACHE_OP_ST_PENDING) {
56192 ASSERT(!list_empty(&op->pend_link));
56193- fscache_stat(&fscache_n_op_cancelled);
56194+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56195 list_del_init(&op->pend_link);
56196 if (do_cancel)
56197 do_cancel(op);
56198@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56199 while (!list_empty(&object->pending_ops)) {
56200 op = list_entry(object->pending_ops.next,
56201 struct fscache_operation, pend_link);
56202- fscache_stat(&fscache_n_op_cancelled);
56203+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56204 list_del_init(&op->pend_link);
56205
56206 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56207@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56208 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56209 op->state = FSCACHE_OP_ST_DEAD;
56210
56211- fscache_stat(&fscache_n_op_release);
56212+ fscache_stat_unchecked(&fscache_n_op_release);
56213
56214 if (op->release) {
56215 op->release(op);
56216@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56217 * lock, and defer it otherwise */
56218 if (!spin_trylock(&object->lock)) {
56219 _debug("defer put");
56220- fscache_stat(&fscache_n_op_deferred_release);
56221+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56222
56223 cache = object->cache;
56224 spin_lock(&cache->op_gc_list_lock);
56225@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56226
56227 _debug("GC DEFERRED REL OBJ%x OP%x",
56228 object->debug_id, op->debug_id);
56229- fscache_stat(&fscache_n_op_gc);
56230+ fscache_stat_unchecked(&fscache_n_op_gc);
56231
56232 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56233 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56234diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56235index d479ab3..727a7f2 100644
56236--- a/fs/fscache/page.c
56237+++ b/fs/fscache/page.c
56238@@ -61,7 +61,7 @@ try_again:
56239 val = radix_tree_lookup(&cookie->stores, page->index);
56240 if (!val) {
56241 rcu_read_unlock();
56242- fscache_stat(&fscache_n_store_vmscan_not_storing);
56243+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56244 __fscache_uncache_page(cookie, page);
56245 return true;
56246 }
56247@@ -91,11 +91,11 @@ try_again:
56248 spin_unlock(&cookie->stores_lock);
56249
56250 if (xpage) {
56251- fscache_stat(&fscache_n_store_vmscan_cancelled);
56252- fscache_stat(&fscache_n_store_radix_deletes);
56253+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56254+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56255 ASSERTCMP(xpage, ==, page);
56256 } else {
56257- fscache_stat(&fscache_n_store_vmscan_gone);
56258+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56259 }
56260
56261 wake_up_bit(&cookie->flags, 0);
56262@@ -110,11 +110,11 @@ page_busy:
56263 * sleeping on memory allocation, so we may need to impose a timeout
56264 * too. */
56265 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56266- fscache_stat(&fscache_n_store_vmscan_busy);
56267+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56268 return false;
56269 }
56270
56271- fscache_stat(&fscache_n_store_vmscan_wait);
56272+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56273 __fscache_wait_on_page_write(cookie, page);
56274 gfp &= ~__GFP_WAIT;
56275 goto try_again;
56276@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56277 FSCACHE_COOKIE_STORING_TAG);
56278 if (!radix_tree_tag_get(&cookie->stores, page->index,
56279 FSCACHE_COOKIE_PENDING_TAG)) {
56280- fscache_stat(&fscache_n_store_radix_deletes);
56281+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56282 xpage = radix_tree_delete(&cookie->stores, page->index);
56283 }
56284 spin_unlock(&cookie->stores_lock);
56285@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56286
56287 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56288
56289- fscache_stat(&fscache_n_attr_changed_calls);
56290+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56291
56292 if (fscache_object_is_active(object) &&
56293 fscache_use_cookie(object)) {
56294@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56295
56296 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56297
56298- fscache_stat(&fscache_n_attr_changed);
56299+ fscache_stat_unchecked(&fscache_n_attr_changed);
56300
56301 op = kzalloc(sizeof(*op), GFP_KERNEL);
56302 if (!op) {
56303- fscache_stat(&fscache_n_attr_changed_nomem);
56304+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56305 _leave(" = -ENOMEM");
56306 return -ENOMEM;
56307 }
56308@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56309 if (fscache_submit_exclusive_op(object, op) < 0)
56310 goto nobufs;
56311 spin_unlock(&cookie->lock);
56312- fscache_stat(&fscache_n_attr_changed_ok);
56313+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56314 fscache_put_operation(op);
56315 _leave(" = 0");
56316 return 0;
56317@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56318 nobufs:
56319 spin_unlock(&cookie->lock);
56320 kfree(op);
56321- fscache_stat(&fscache_n_attr_changed_nobufs);
56322+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56323 _leave(" = %d", -ENOBUFS);
56324 return -ENOBUFS;
56325 }
56326@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56327 /* allocate a retrieval operation and attempt to submit it */
56328 op = kzalloc(sizeof(*op), GFP_NOIO);
56329 if (!op) {
56330- fscache_stat(&fscache_n_retrievals_nomem);
56331+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56332 return NULL;
56333 }
56334
56335@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56336 return 0;
56337 }
56338
56339- fscache_stat(&fscache_n_retrievals_wait);
56340+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56341
56342 jif = jiffies;
56343 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56344 fscache_wait_bit_interruptible,
56345 TASK_INTERRUPTIBLE) != 0) {
56346- fscache_stat(&fscache_n_retrievals_intr);
56347+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56348 _leave(" = -ERESTARTSYS");
56349 return -ERESTARTSYS;
56350 }
56351@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56352 */
56353 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56354 struct fscache_retrieval *op,
56355- atomic_t *stat_op_waits,
56356- atomic_t *stat_object_dead)
56357+ atomic_unchecked_t *stat_op_waits,
56358+ atomic_unchecked_t *stat_object_dead)
56359 {
56360 int ret;
56361
56362@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56363 goto check_if_dead;
56364
56365 _debug(">>> WT");
56366- fscache_stat(stat_op_waits);
56367+ fscache_stat_unchecked(stat_op_waits);
56368 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56369 fscache_wait_bit_interruptible,
56370 TASK_INTERRUPTIBLE) != 0) {
56371@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56372
56373 check_if_dead:
56374 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56375- fscache_stat(stat_object_dead);
56376+ fscache_stat_unchecked(stat_object_dead);
56377 _leave(" = -ENOBUFS [cancelled]");
56378 return -ENOBUFS;
56379 }
56380 if (unlikely(fscache_object_is_dead(object))) {
56381 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56382 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56383- fscache_stat(stat_object_dead);
56384+ fscache_stat_unchecked(stat_object_dead);
56385 return -ENOBUFS;
56386 }
56387 return 0;
56388@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56389
56390 _enter("%p,%p,,,", cookie, page);
56391
56392- fscache_stat(&fscache_n_retrievals);
56393+ fscache_stat_unchecked(&fscache_n_retrievals);
56394
56395 if (hlist_empty(&cookie->backing_objects))
56396 goto nobufs;
56397@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56398 goto nobufs_unlock_dec;
56399 spin_unlock(&cookie->lock);
56400
56401- fscache_stat(&fscache_n_retrieval_ops);
56402+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56403
56404 /* pin the netfs read context in case we need to do the actual netfs
56405 * read because we've encountered a cache read failure */
56406@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56407
56408 error:
56409 if (ret == -ENOMEM)
56410- fscache_stat(&fscache_n_retrievals_nomem);
56411+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56412 else if (ret == -ERESTARTSYS)
56413- fscache_stat(&fscache_n_retrievals_intr);
56414+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56415 else if (ret == -ENODATA)
56416- fscache_stat(&fscache_n_retrievals_nodata);
56417+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56418 else if (ret < 0)
56419- fscache_stat(&fscache_n_retrievals_nobufs);
56420+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56421 else
56422- fscache_stat(&fscache_n_retrievals_ok);
56423+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56424
56425 fscache_put_retrieval(op);
56426 _leave(" = %d", ret);
56427@@ -475,7 +475,7 @@ nobufs_unlock:
56428 atomic_dec(&cookie->n_active);
56429 kfree(op);
56430 nobufs:
56431- fscache_stat(&fscache_n_retrievals_nobufs);
56432+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56433 _leave(" = -ENOBUFS");
56434 return -ENOBUFS;
56435 }
56436@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56437
56438 _enter("%p,,%d,,,", cookie, *nr_pages);
56439
56440- fscache_stat(&fscache_n_retrievals);
56441+ fscache_stat_unchecked(&fscache_n_retrievals);
56442
56443 if (hlist_empty(&cookie->backing_objects))
56444 goto nobufs;
56445@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56446 goto nobufs_unlock_dec;
56447 spin_unlock(&cookie->lock);
56448
56449- fscache_stat(&fscache_n_retrieval_ops);
56450+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56451
56452 /* pin the netfs read context in case we need to do the actual netfs
56453 * read because we've encountered a cache read failure */
56454@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56455
56456 error:
56457 if (ret == -ENOMEM)
56458- fscache_stat(&fscache_n_retrievals_nomem);
56459+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56460 else if (ret == -ERESTARTSYS)
56461- fscache_stat(&fscache_n_retrievals_intr);
56462+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56463 else if (ret == -ENODATA)
56464- fscache_stat(&fscache_n_retrievals_nodata);
56465+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56466 else if (ret < 0)
56467- fscache_stat(&fscache_n_retrievals_nobufs);
56468+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56469 else
56470- fscache_stat(&fscache_n_retrievals_ok);
56471+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56472
56473 fscache_put_retrieval(op);
56474 _leave(" = %d", ret);
56475@@ -600,7 +600,7 @@ nobufs_unlock:
56476 atomic_dec(&cookie->n_active);
56477 kfree(op);
56478 nobufs:
56479- fscache_stat(&fscache_n_retrievals_nobufs);
56480+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56481 _leave(" = -ENOBUFS");
56482 return -ENOBUFS;
56483 }
56484@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56485
56486 _enter("%p,%p,,,", cookie, page);
56487
56488- fscache_stat(&fscache_n_allocs);
56489+ fscache_stat_unchecked(&fscache_n_allocs);
56490
56491 if (hlist_empty(&cookie->backing_objects))
56492 goto nobufs;
56493@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56494 goto nobufs_unlock;
56495 spin_unlock(&cookie->lock);
56496
56497- fscache_stat(&fscache_n_alloc_ops);
56498+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56499
56500 ret = fscache_wait_for_retrieval_activation(
56501 object, op,
56502@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56503
56504 error:
56505 if (ret == -ERESTARTSYS)
56506- fscache_stat(&fscache_n_allocs_intr);
56507+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56508 else if (ret < 0)
56509- fscache_stat(&fscache_n_allocs_nobufs);
56510+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56511 else
56512- fscache_stat(&fscache_n_allocs_ok);
56513+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56514
56515 fscache_put_retrieval(op);
56516 _leave(" = %d", ret);
56517@@ -687,7 +687,7 @@ nobufs_unlock:
56518 atomic_dec(&cookie->n_active);
56519 kfree(op);
56520 nobufs:
56521- fscache_stat(&fscache_n_allocs_nobufs);
56522+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56523 _leave(" = -ENOBUFS");
56524 return -ENOBUFS;
56525 }
56526@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56527
56528 spin_lock(&cookie->stores_lock);
56529
56530- fscache_stat(&fscache_n_store_calls);
56531+ fscache_stat_unchecked(&fscache_n_store_calls);
56532
56533 /* find a page to store */
56534 page = NULL;
56535@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56536 page = results[0];
56537 _debug("gang %d [%lx]", n, page->index);
56538 if (page->index > op->store_limit) {
56539- fscache_stat(&fscache_n_store_pages_over_limit);
56540+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56541 goto superseded;
56542 }
56543
56544@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56545 spin_unlock(&cookie->stores_lock);
56546 spin_unlock(&object->lock);
56547
56548- fscache_stat(&fscache_n_store_pages);
56549+ fscache_stat_unchecked(&fscache_n_store_pages);
56550 fscache_stat(&fscache_n_cop_write_page);
56551 ret = object->cache->ops->write_page(op, page);
56552 fscache_stat_d(&fscache_n_cop_write_page);
56553@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56554 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56555 ASSERT(PageFsCache(page));
56556
56557- fscache_stat(&fscache_n_stores);
56558+ fscache_stat_unchecked(&fscache_n_stores);
56559
56560 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56561 _leave(" = -ENOBUFS [invalidating]");
56562@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56563 spin_unlock(&cookie->stores_lock);
56564 spin_unlock(&object->lock);
56565
56566- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56567+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56568 op->store_limit = object->store_limit;
56569
56570 atomic_inc(&cookie->n_active);
56571@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56572
56573 spin_unlock(&cookie->lock);
56574 radix_tree_preload_end();
56575- fscache_stat(&fscache_n_store_ops);
56576- fscache_stat(&fscache_n_stores_ok);
56577+ fscache_stat_unchecked(&fscache_n_store_ops);
56578+ fscache_stat_unchecked(&fscache_n_stores_ok);
56579
56580 /* the work queue now carries its own ref on the object */
56581 fscache_put_operation(&op->op);
56582@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56583 return 0;
56584
56585 already_queued:
56586- fscache_stat(&fscache_n_stores_again);
56587+ fscache_stat_unchecked(&fscache_n_stores_again);
56588 already_pending:
56589 spin_unlock(&cookie->stores_lock);
56590 spin_unlock(&object->lock);
56591 spin_unlock(&cookie->lock);
56592 radix_tree_preload_end();
56593 kfree(op);
56594- fscache_stat(&fscache_n_stores_ok);
56595+ fscache_stat_unchecked(&fscache_n_stores_ok);
56596 _leave(" = 0");
56597 return 0;
56598
56599@@ -976,14 +976,14 @@ nobufs:
56600 spin_unlock(&cookie->lock);
56601 radix_tree_preload_end();
56602 kfree(op);
56603- fscache_stat(&fscache_n_stores_nobufs);
56604+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56605 _leave(" = -ENOBUFS");
56606 return -ENOBUFS;
56607
56608 nomem_free:
56609 kfree(op);
56610 nomem:
56611- fscache_stat(&fscache_n_stores_oom);
56612+ fscache_stat_unchecked(&fscache_n_stores_oom);
56613 _leave(" = -ENOMEM");
56614 return -ENOMEM;
56615 }
56616@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56617 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56618 ASSERTCMP(page, !=, NULL);
56619
56620- fscache_stat(&fscache_n_uncaches);
56621+ fscache_stat_unchecked(&fscache_n_uncaches);
56622
56623 /* cache withdrawal may beat us to it */
56624 if (!PageFsCache(page))
56625@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56626 struct fscache_cookie *cookie = op->op.object->cookie;
56627
56628 #ifdef CONFIG_FSCACHE_STATS
56629- atomic_inc(&fscache_n_marks);
56630+ atomic_inc_unchecked(&fscache_n_marks);
56631 #endif
56632
56633 _debug("- mark %p{%lx}", page, page->index);
56634diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56635index 40d13c7..ddf52b9 100644
56636--- a/fs/fscache/stats.c
56637+++ b/fs/fscache/stats.c
56638@@ -18,99 +18,99 @@
56639 /*
56640 * operation counters
56641 */
56642-atomic_t fscache_n_op_pend;
56643-atomic_t fscache_n_op_run;
56644-atomic_t fscache_n_op_enqueue;
56645-atomic_t fscache_n_op_requeue;
56646-atomic_t fscache_n_op_deferred_release;
56647-atomic_t fscache_n_op_release;
56648-atomic_t fscache_n_op_gc;
56649-atomic_t fscache_n_op_cancelled;
56650-atomic_t fscache_n_op_rejected;
56651+atomic_unchecked_t fscache_n_op_pend;
56652+atomic_unchecked_t fscache_n_op_run;
56653+atomic_unchecked_t fscache_n_op_enqueue;
56654+atomic_unchecked_t fscache_n_op_requeue;
56655+atomic_unchecked_t fscache_n_op_deferred_release;
56656+atomic_unchecked_t fscache_n_op_release;
56657+atomic_unchecked_t fscache_n_op_gc;
56658+atomic_unchecked_t fscache_n_op_cancelled;
56659+atomic_unchecked_t fscache_n_op_rejected;
56660
56661-atomic_t fscache_n_attr_changed;
56662-atomic_t fscache_n_attr_changed_ok;
56663-atomic_t fscache_n_attr_changed_nobufs;
56664-atomic_t fscache_n_attr_changed_nomem;
56665-atomic_t fscache_n_attr_changed_calls;
56666+atomic_unchecked_t fscache_n_attr_changed;
56667+atomic_unchecked_t fscache_n_attr_changed_ok;
56668+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56669+atomic_unchecked_t fscache_n_attr_changed_nomem;
56670+atomic_unchecked_t fscache_n_attr_changed_calls;
56671
56672-atomic_t fscache_n_allocs;
56673-atomic_t fscache_n_allocs_ok;
56674-atomic_t fscache_n_allocs_wait;
56675-atomic_t fscache_n_allocs_nobufs;
56676-atomic_t fscache_n_allocs_intr;
56677-atomic_t fscache_n_allocs_object_dead;
56678-atomic_t fscache_n_alloc_ops;
56679-atomic_t fscache_n_alloc_op_waits;
56680+atomic_unchecked_t fscache_n_allocs;
56681+atomic_unchecked_t fscache_n_allocs_ok;
56682+atomic_unchecked_t fscache_n_allocs_wait;
56683+atomic_unchecked_t fscache_n_allocs_nobufs;
56684+atomic_unchecked_t fscache_n_allocs_intr;
56685+atomic_unchecked_t fscache_n_allocs_object_dead;
56686+atomic_unchecked_t fscache_n_alloc_ops;
56687+atomic_unchecked_t fscache_n_alloc_op_waits;
56688
56689-atomic_t fscache_n_retrievals;
56690-atomic_t fscache_n_retrievals_ok;
56691-atomic_t fscache_n_retrievals_wait;
56692-atomic_t fscache_n_retrievals_nodata;
56693-atomic_t fscache_n_retrievals_nobufs;
56694-atomic_t fscache_n_retrievals_intr;
56695-atomic_t fscache_n_retrievals_nomem;
56696-atomic_t fscache_n_retrievals_object_dead;
56697-atomic_t fscache_n_retrieval_ops;
56698-atomic_t fscache_n_retrieval_op_waits;
56699+atomic_unchecked_t fscache_n_retrievals;
56700+atomic_unchecked_t fscache_n_retrievals_ok;
56701+atomic_unchecked_t fscache_n_retrievals_wait;
56702+atomic_unchecked_t fscache_n_retrievals_nodata;
56703+atomic_unchecked_t fscache_n_retrievals_nobufs;
56704+atomic_unchecked_t fscache_n_retrievals_intr;
56705+atomic_unchecked_t fscache_n_retrievals_nomem;
56706+atomic_unchecked_t fscache_n_retrievals_object_dead;
56707+atomic_unchecked_t fscache_n_retrieval_ops;
56708+atomic_unchecked_t fscache_n_retrieval_op_waits;
56709
56710-atomic_t fscache_n_stores;
56711-atomic_t fscache_n_stores_ok;
56712-atomic_t fscache_n_stores_again;
56713-atomic_t fscache_n_stores_nobufs;
56714-atomic_t fscache_n_stores_oom;
56715-atomic_t fscache_n_store_ops;
56716-atomic_t fscache_n_store_calls;
56717-atomic_t fscache_n_store_pages;
56718-atomic_t fscache_n_store_radix_deletes;
56719-atomic_t fscache_n_store_pages_over_limit;
56720+atomic_unchecked_t fscache_n_stores;
56721+atomic_unchecked_t fscache_n_stores_ok;
56722+atomic_unchecked_t fscache_n_stores_again;
56723+atomic_unchecked_t fscache_n_stores_nobufs;
56724+atomic_unchecked_t fscache_n_stores_oom;
56725+atomic_unchecked_t fscache_n_store_ops;
56726+atomic_unchecked_t fscache_n_store_calls;
56727+atomic_unchecked_t fscache_n_store_pages;
56728+atomic_unchecked_t fscache_n_store_radix_deletes;
56729+atomic_unchecked_t fscache_n_store_pages_over_limit;
56730
56731-atomic_t fscache_n_store_vmscan_not_storing;
56732-atomic_t fscache_n_store_vmscan_gone;
56733-atomic_t fscache_n_store_vmscan_busy;
56734-atomic_t fscache_n_store_vmscan_cancelled;
56735-atomic_t fscache_n_store_vmscan_wait;
56736+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56737+atomic_unchecked_t fscache_n_store_vmscan_gone;
56738+atomic_unchecked_t fscache_n_store_vmscan_busy;
56739+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56740+atomic_unchecked_t fscache_n_store_vmscan_wait;
56741
56742-atomic_t fscache_n_marks;
56743-atomic_t fscache_n_uncaches;
56744+atomic_unchecked_t fscache_n_marks;
56745+atomic_unchecked_t fscache_n_uncaches;
56746
56747-atomic_t fscache_n_acquires;
56748-atomic_t fscache_n_acquires_null;
56749-atomic_t fscache_n_acquires_no_cache;
56750-atomic_t fscache_n_acquires_ok;
56751-atomic_t fscache_n_acquires_nobufs;
56752-atomic_t fscache_n_acquires_oom;
56753+atomic_unchecked_t fscache_n_acquires;
56754+atomic_unchecked_t fscache_n_acquires_null;
56755+atomic_unchecked_t fscache_n_acquires_no_cache;
56756+atomic_unchecked_t fscache_n_acquires_ok;
56757+atomic_unchecked_t fscache_n_acquires_nobufs;
56758+atomic_unchecked_t fscache_n_acquires_oom;
56759
56760-atomic_t fscache_n_invalidates;
56761-atomic_t fscache_n_invalidates_run;
56762+atomic_unchecked_t fscache_n_invalidates;
56763+atomic_unchecked_t fscache_n_invalidates_run;
56764
56765-atomic_t fscache_n_updates;
56766-atomic_t fscache_n_updates_null;
56767-atomic_t fscache_n_updates_run;
56768+atomic_unchecked_t fscache_n_updates;
56769+atomic_unchecked_t fscache_n_updates_null;
56770+atomic_unchecked_t fscache_n_updates_run;
56771
56772-atomic_t fscache_n_relinquishes;
56773-atomic_t fscache_n_relinquishes_null;
56774-atomic_t fscache_n_relinquishes_waitcrt;
56775-atomic_t fscache_n_relinquishes_retire;
56776+atomic_unchecked_t fscache_n_relinquishes;
56777+atomic_unchecked_t fscache_n_relinquishes_null;
56778+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56779+atomic_unchecked_t fscache_n_relinquishes_retire;
56780
56781-atomic_t fscache_n_cookie_index;
56782-atomic_t fscache_n_cookie_data;
56783-atomic_t fscache_n_cookie_special;
56784+atomic_unchecked_t fscache_n_cookie_index;
56785+atomic_unchecked_t fscache_n_cookie_data;
56786+atomic_unchecked_t fscache_n_cookie_special;
56787
56788-atomic_t fscache_n_object_alloc;
56789-atomic_t fscache_n_object_no_alloc;
56790-atomic_t fscache_n_object_lookups;
56791-atomic_t fscache_n_object_lookups_negative;
56792-atomic_t fscache_n_object_lookups_positive;
56793-atomic_t fscache_n_object_lookups_timed_out;
56794-atomic_t fscache_n_object_created;
56795-atomic_t fscache_n_object_avail;
56796-atomic_t fscache_n_object_dead;
56797+atomic_unchecked_t fscache_n_object_alloc;
56798+atomic_unchecked_t fscache_n_object_no_alloc;
56799+atomic_unchecked_t fscache_n_object_lookups;
56800+atomic_unchecked_t fscache_n_object_lookups_negative;
56801+atomic_unchecked_t fscache_n_object_lookups_positive;
56802+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56803+atomic_unchecked_t fscache_n_object_created;
56804+atomic_unchecked_t fscache_n_object_avail;
56805+atomic_unchecked_t fscache_n_object_dead;
56806
56807-atomic_t fscache_n_checkaux_none;
56808-atomic_t fscache_n_checkaux_okay;
56809-atomic_t fscache_n_checkaux_update;
56810-atomic_t fscache_n_checkaux_obsolete;
56811+atomic_unchecked_t fscache_n_checkaux_none;
56812+atomic_unchecked_t fscache_n_checkaux_okay;
56813+atomic_unchecked_t fscache_n_checkaux_update;
56814+atomic_unchecked_t fscache_n_checkaux_obsolete;
56815
56816 atomic_t fscache_n_cop_alloc_object;
56817 atomic_t fscache_n_cop_lookup_object;
56818@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56819 seq_puts(m, "FS-Cache statistics\n");
56820
56821 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56822- atomic_read(&fscache_n_cookie_index),
56823- atomic_read(&fscache_n_cookie_data),
56824- atomic_read(&fscache_n_cookie_special));
56825+ atomic_read_unchecked(&fscache_n_cookie_index),
56826+ atomic_read_unchecked(&fscache_n_cookie_data),
56827+ atomic_read_unchecked(&fscache_n_cookie_special));
56828
56829 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56830- atomic_read(&fscache_n_object_alloc),
56831- atomic_read(&fscache_n_object_no_alloc),
56832- atomic_read(&fscache_n_object_avail),
56833- atomic_read(&fscache_n_object_dead));
56834+ atomic_read_unchecked(&fscache_n_object_alloc),
56835+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56836+ atomic_read_unchecked(&fscache_n_object_avail),
56837+ atomic_read_unchecked(&fscache_n_object_dead));
56838 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56839- atomic_read(&fscache_n_checkaux_none),
56840- atomic_read(&fscache_n_checkaux_okay),
56841- atomic_read(&fscache_n_checkaux_update),
56842- atomic_read(&fscache_n_checkaux_obsolete));
56843+ atomic_read_unchecked(&fscache_n_checkaux_none),
56844+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56845+ atomic_read_unchecked(&fscache_n_checkaux_update),
56846+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56847
56848 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56849- atomic_read(&fscache_n_marks),
56850- atomic_read(&fscache_n_uncaches));
56851+ atomic_read_unchecked(&fscache_n_marks),
56852+ atomic_read_unchecked(&fscache_n_uncaches));
56853
56854 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56855 " oom=%u\n",
56856- atomic_read(&fscache_n_acquires),
56857- atomic_read(&fscache_n_acquires_null),
56858- atomic_read(&fscache_n_acquires_no_cache),
56859- atomic_read(&fscache_n_acquires_ok),
56860- atomic_read(&fscache_n_acquires_nobufs),
56861- atomic_read(&fscache_n_acquires_oom));
56862+ atomic_read_unchecked(&fscache_n_acquires),
56863+ atomic_read_unchecked(&fscache_n_acquires_null),
56864+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56865+ atomic_read_unchecked(&fscache_n_acquires_ok),
56866+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56867+ atomic_read_unchecked(&fscache_n_acquires_oom));
56868
56869 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56870- atomic_read(&fscache_n_object_lookups),
56871- atomic_read(&fscache_n_object_lookups_negative),
56872- atomic_read(&fscache_n_object_lookups_positive),
56873- atomic_read(&fscache_n_object_created),
56874- atomic_read(&fscache_n_object_lookups_timed_out));
56875+ atomic_read_unchecked(&fscache_n_object_lookups),
56876+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56877+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56878+ atomic_read_unchecked(&fscache_n_object_created),
56879+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56880
56881 seq_printf(m, "Invals : n=%u run=%u\n",
56882- atomic_read(&fscache_n_invalidates),
56883- atomic_read(&fscache_n_invalidates_run));
56884+ atomic_read_unchecked(&fscache_n_invalidates),
56885+ atomic_read_unchecked(&fscache_n_invalidates_run));
56886
56887 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
56888- atomic_read(&fscache_n_updates),
56889- atomic_read(&fscache_n_updates_null),
56890- atomic_read(&fscache_n_updates_run));
56891+ atomic_read_unchecked(&fscache_n_updates),
56892+ atomic_read_unchecked(&fscache_n_updates_null),
56893+ atomic_read_unchecked(&fscache_n_updates_run));
56894
56895 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
56896- atomic_read(&fscache_n_relinquishes),
56897- atomic_read(&fscache_n_relinquishes_null),
56898- atomic_read(&fscache_n_relinquishes_waitcrt),
56899- atomic_read(&fscache_n_relinquishes_retire));
56900+ atomic_read_unchecked(&fscache_n_relinquishes),
56901+ atomic_read_unchecked(&fscache_n_relinquishes_null),
56902+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
56903+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
56904
56905 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
56906- atomic_read(&fscache_n_attr_changed),
56907- atomic_read(&fscache_n_attr_changed_ok),
56908- atomic_read(&fscache_n_attr_changed_nobufs),
56909- atomic_read(&fscache_n_attr_changed_nomem),
56910- atomic_read(&fscache_n_attr_changed_calls));
56911+ atomic_read_unchecked(&fscache_n_attr_changed),
56912+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
56913+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
56914+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
56915+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
56916
56917 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
56918- atomic_read(&fscache_n_allocs),
56919- atomic_read(&fscache_n_allocs_ok),
56920- atomic_read(&fscache_n_allocs_wait),
56921- atomic_read(&fscache_n_allocs_nobufs),
56922- atomic_read(&fscache_n_allocs_intr));
56923+ atomic_read_unchecked(&fscache_n_allocs),
56924+ atomic_read_unchecked(&fscache_n_allocs_ok),
56925+ atomic_read_unchecked(&fscache_n_allocs_wait),
56926+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
56927+ atomic_read_unchecked(&fscache_n_allocs_intr));
56928 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
56929- atomic_read(&fscache_n_alloc_ops),
56930- atomic_read(&fscache_n_alloc_op_waits),
56931- atomic_read(&fscache_n_allocs_object_dead));
56932+ atomic_read_unchecked(&fscache_n_alloc_ops),
56933+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
56934+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
56935
56936 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
56937 " int=%u oom=%u\n",
56938- atomic_read(&fscache_n_retrievals),
56939- atomic_read(&fscache_n_retrievals_ok),
56940- atomic_read(&fscache_n_retrievals_wait),
56941- atomic_read(&fscache_n_retrievals_nodata),
56942- atomic_read(&fscache_n_retrievals_nobufs),
56943- atomic_read(&fscache_n_retrievals_intr),
56944- atomic_read(&fscache_n_retrievals_nomem));
56945+ atomic_read_unchecked(&fscache_n_retrievals),
56946+ atomic_read_unchecked(&fscache_n_retrievals_ok),
56947+ atomic_read_unchecked(&fscache_n_retrievals_wait),
56948+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
56949+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
56950+ atomic_read_unchecked(&fscache_n_retrievals_intr),
56951+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
56952 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
56953- atomic_read(&fscache_n_retrieval_ops),
56954- atomic_read(&fscache_n_retrieval_op_waits),
56955- atomic_read(&fscache_n_retrievals_object_dead));
56956+ atomic_read_unchecked(&fscache_n_retrieval_ops),
56957+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
56958+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
56959
56960 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
56961- atomic_read(&fscache_n_stores),
56962- atomic_read(&fscache_n_stores_ok),
56963- atomic_read(&fscache_n_stores_again),
56964- atomic_read(&fscache_n_stores_nobufs),
56965- atomic_read(&fscache_n_stores_oom));
56966+ atomic_read_unchecked(&fscache_n_stores),
56967+ atomic_read_unchecked(&fscache_n_stores_ok),
56968+ atomic_read_unchecked(&fscache_n_stores_again),
56969+ atomic_read_unchecked(&fscache_n_stores_nobufs),
56970+ atomic_read_unchecked(&fscache_n_stores_oom));
56971 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
56972- atomic_read(&fscache_n_store_ops),
56973- atomic_read(&fscache_n_store_calls),
56974- atomic_read(&fscache_n_store_pages),
56975- atomic_read(&fscache_n_store_radix_deletes),
56976- atomic_read(&fscache_n_store_pages_over_limit));
56977+ atomic_read_unchecked(&fscache_n_store_ops),
56978+ atomic_read_unchecked(&fscache_n_store_calls),
56979+ atomic_read_unchecked(&fscache_n_store_pages),
56980+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
56981+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
56982
56983 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
56984- atomic_read(&fscache_n_store_vmscan_not_storing),
56985- atomic_read(&fscache_n_store_vmscan_gone),
56986- atomic_read(&fscache_n_store_vmscan_busy),
56987- atomic_read(&fscache_n_store_vmscan_cancelled),
56988- atomic_read(&fscache_n_store_vmscan_wait));
56989+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
56990+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
56991+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
56992+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
56993+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
56994
56995 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
56996- atomic_read(&fscache_n_op_pend),
56997- atomic_read(&fscache_n_op_run),
56998- atomic_read(&fscache_n_op_enqueue),
56999- atomic_read(&fscache_n_op_cancelled),
57000- atomic_read(&fscache_n_op_rejected));
57001+ atomic_read_unchecked(&fscache_n_op_pend),
57002+ atomic_read_unchecked(&fscache_n_op_run),
57003+ atomic_read_unchecked(&fscache_n_op_enqueue),
57004+ atomic_read_unchecked(&fscache_n_op_cancelled),
57005+ atomic_read_unchecked(&fscache_n_op_rejected));
57006 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57007- atomic_read(&fscache_n_op_deferred_release),
57008- atomic_read(&fscache_n_op_release),
57009- atomic_read(&fscache_n_op_gc));
57010+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57011+ atomic_read_unchecked(&fscache_n_op_release),
57012+ atomic_read_unchecked(&fscache_n_op_gc));
57013
57014 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57015 atomic_read(&fscache_n_cop_alloc_object),
57016diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57017index aef34b1..59bfd7b 100644
57018--- a/fs/fuse/cuse.c
57019+++ b/fs/fuse/cuse.c
57020@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57021 INIT_LIST_HEAD(&cuse_conntbl[i]);
57022
57023 /* inherit and extend fuse_dev_operations */
57024- cuse_channel_fops = fuse_dev_operations;
57025- cuse_channel_fops.owner = THIS_MODULE;
57026- cuse_channel_fops.open = cuse_channel_open;
57027- cuse_channel_fops.release = cuse_channel_release;
57028+ pax_open_kernel();
57029+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57030+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57031+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57032+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57033+ pax_close_kernel();
57034
57035 cuse_class = class_create(THIS_MODULE, "cuse");
57036 if (IS_ERR(cuse_class))
57037diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57038index 1d55f94..088da65 100644
57039--- a/fs/fuse/dev.c
57040+++ b/fs/fuse/dev.c
57041@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57042 ret = 0;
57043 pipe_lock(pipe);
57044
57045- if (!pipe->readers) {
57046+ if (!atomic_read(&pipe->readers)) {
57047 send_sig(SIGPIPE, current, 0);
57048 if (!ret)
57049 ret = -EPIPE;
57050@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57051 page_nr++;
57052 ret += buf->len;
57053
57054- if (pipe->files)
57055+ if (atomic_read(&pipe->files))
57056 do_wakeup = 1;
57057 }
57058
57059diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57060index 8fec28f..cd40dba 100644
57061--- a/fs/fuse/dir.c
57062+++ b/fs/fuse/dir.c
57063@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
57064 return link;
57065 }
57066
57067-static void free_link(char *link)
57068+static void free_link(const char *link)
57069 {
57070 if (!IS_ERR(link))
57071 free_page((unsigned long) link);
57072diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57073index 64915ee..6bed500 100644
57074--- a/fs/gfs2/inode.c
57075+++ b/fs/gfs2/inode.c
57076@@ -1506,7 +1506,7 @@ out:
57077
57078 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57079 {
57080- char *s = nd_get_link(nd);
57081+ const char *s = nd_get_link(nd);
57082 if (!IS_ERR(s))
57083 kfree(s);
57084 }
57085diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57086index d19b30a..ef89c36 100644
57087--- a/fs/hugetlbfs/inode.c
57088+++ b/fs/hugetlbfs/inode.c
57089@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57090 struct mm_struct *mm = current->mm;
57091 struct vm_area_struct *vma;
57092 struct hstate *h = hstate_file(file);
57093+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57094 struct vm_unmapped_area_info info;
57095
57096 if (len & ~huge_page_mask(h))
57097@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57098 return addr;
57099 }
57100
57101+#ifdef CONFIG_PAX_RANDMMAP
57102+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57103+#endif
57104+
57105 if (addr) {
57106 addr = ALIGN(addr, huge_page_size(h));
57107 vma = find_vma(mm, addr);
57108- if (TASK_SIZE - len >= addr &&
57109- (!vma || addr + len <= vma->vm_start))
57110+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57111 return addr;
57112 }
57113
57114 info.flags = 0;
57115 info.length = len;
57116 info.low_limit = TASK_UNMAPPED_BASE;
57117+
57118+#ifdef CONFIG_PAX_RANDMMAP
57119+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57120+ info.low_limit += mm->delta_mmap;
57121+#endif
57122+
57123 info.high_limit = TASK_SIZE;
57124 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57125 info.align_offset = 0;
57126@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57127 };
57128 MODULE_ALIAS_FS("hugetlbfs");
57129
57130-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57131+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57132
57133 static int can_do_hugetlb_shm(void)
57134 {
57135diff --git a/fs/inode.c b/fs/inode.c
57136index d6dfb09..602e77e 100644
57137--- a/fs/inode.c
57138+++ b/fs/inode.c
57139@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57140
57141 #ifdef CONFIG_SMP
57142 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57143- static atomic_t shared_last_ino;
57144- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57145+ static atomic_unchecked_t shared_last_ino;
57146+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57147
57148 res = next - LAST_INO_BATCH;
57149 }
57150diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57151index 4a6cf28..d3a29d3 100644
57152--- a/fs/jffs2/erase.c
57153+++ b/fs/jffs2/erase.c
57154@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57155 struct jffs2_unknown_node marker = {
57156 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57157 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57158- .totlen = cpu_to_je32(c->cleanmarker_size)
57159+ .totlen = cpu_to_je32(c->cleanmarker_size),
57160+ .hdr_crc = cpu_to_je32(0)
57161 };
57162
57163 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57164diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57165index a6597d6..41b30ec 100644
57166--- a/fs/jffs2/wbuf.c
57167+++ b/fs/jffs2/wbuf.c
57168@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57169 {
57170 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57171 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57172- .totlen = constant_cpu_to_je32(8)
57173+ .totlen = constant_cpu_to_je32(8),
57174+ .hdr_crc = constant_cpu_to_je32(0)
57175 };
57176
57177 /*
57178diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57179index 6669aa2..36b033d 100644
57180--- a/fs/jfs/super.c
57181+++ b/fs/jfs/super.c
57182@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57183
57184 jfs_inode_cachep =
57185 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57186- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57187+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57188 init_once);
57189 if (jfs_inode_cachep == NULL)
57190 return -ENOMEM;
57191diff --git a/fs/libfs.c b/fs/libfs.c
57192index 3a3a9b5..3a9b074 100644
57193--- a/fs/libfs.c
57194+++ b/fs/libfs.c
57195@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57196
57197 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57198 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57199+ char d_name[sizeof(next->d_iname)];
57200+ const unsigned char *name;
57201+
57202 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57203 if (!simple_positive(next)) {
57204 spin_unlock(&next->d_lock);
57205@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57206
57207 spin_unlock(&next->d_lock);
57208 spin_unlock(&dentry->d_lock);
57209- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57210+ name = next->d_name.name;
57211+ if (name == next->d_iname) {
57212+ memcpy(d_name, name, next->d_name.len);
57213+ name = d_name;
57214+ }
57215+ if (!dir_emit(ctx, name, next->d_name.len,
57216 next->d_inode->i_ino, dt_type(next->d_inode)))
57217 return 0;
57218 spin_lock(&dentry->d_lock);
57219diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57220index acd3947..1f896e2 100644
57221--- a/fs/lockd/clntproc.c
57222+++ b/fs/lockd/clntproc.c
57223@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57224 /*
57225 * Cookie counter for NLM requests
57226 */
57227-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57228+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57229
57230 void nlmclnt_next_cookie(struct nlm_cookie *c)
57231 {
57232- u32 cookie = atomic_inc_return(&nlm_cookie);
57233+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57234
57235 memcpy(c->data, &cookie, 4);
57236 c->len=4;
57237diff --git a/fs/locks.c b/fs/locks.c
57238index b27a300..4156d0b 100644
57239--- a/fs/locks.c
57240+++ b/fs/locks.c
57241@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57242 return;
57243
57244 if (filp->f_op && filp->f_op->flock) {
57245- struct file_lock fl = {
57246+ struct file_lock flock = {
57247 .fl_pid = current->tgid,
57248 .fl_file = filp,
57249 .fl_flags = FL_FLOCK,
57250 .fl_type = F_UNLCK,
57251 .fl_end = OFFSET_MAX,
57252 };
57253- filp->f_op->flock(filp, F_SETLKW, &fl);
57254- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57255- fl.fl_ops->fl_release_private(&fl);
57256+ filp->f_op->flock(filp, F_SETLKW, &flock);
57257+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57258+ flock.fl_ops->fl_release_private(&flock);
57259 }
57260
57261 spin_lock(&inode->i_lock);
57262diff --git a/fs/namei.c b/fs/namei.c
57263index 7720fbd..7934bb2 100644
57264--- a/fs/namei.c
57265+++ b/fs/namei.c
57266@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57267 if (ret != -EACCES)
57268 return ret;
57269
57270+#ifdef CONFIG_GRKERNSEC
57271+ /* we'll block if we have to log due to a denied capability use */
57272+ if (mask & MAY_NOT_BLOCK)
57273+ return -ECHILD;
57274+#endif
57275+
57276 if (S_ISDIR(inode->i_mode)) {
57277 /* DACs are overridable for directories */
57278- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57279- return 0;
57280 if (!(mask & MAY_WRITE))
57281- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57282+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57283+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57284 return 0;
57285+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57286+ return 0;
57287 return -EACCES;
57288 }
57289 /*
57290+ * Searching includes executable on directories, else just read.
57291+ */
57292+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57293+ if (mask == MAY_READ)
57294+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57295+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57296+ return 0;
57297+
57298+ /*
57299 * Read/write DACs are always overridable.
57300 * Executable DACs are overridable when there is
57301 * at least one exec bit set.
57302@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57303 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57304 return 0;
57305
57306- /*
57307- * Searching includes executable on directories, else just read.
57308- */
57309- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57310- if (mask == MAY_READ)
57311- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57312- return 0;
57313-
57314 return -EACCES;
57315 }
57316
57317@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57318 {
57319 struct dentry *dentry = link->dentry;
57320 int error;
57321- char *s;
57322+ const char *s;
57323
57324 BUG_ON(nd->flags & LOOKUP_RCU);
57325
57326@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57327 if (error)
57328 goto out_put_nd_path;
57329
57330+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57331+ dentry->d_inode, dentry, nd->path.mnt)) {
57332+ error = -EACCES;
57333+ goto out_put_nd_path;
57334+ }
57335+
57336 nd->last_type = LAST_BIND;
57337 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57338 error = PTR_ERR(*p);
57339@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57340 if (res)
57341 break;
57342 res = walk_component(nd, path, LOOKUP_FOLLOW);
57343+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57344+ res = -EACCES;
57345 put_link(nd, &link, cookie);
57346 } while (res > 0);
57347
57348@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57349 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57350 {
57351 unsigned long a, b, adata, bdata, mask, hash, len;
57352- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57353+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57354
57355 hash = a = 0;
57356 len = -sizeof(unsigned long);
57357@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57358 if (err)
57359 break;
57360 err = lookup_last(nd, &path);
57361+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57362+ err = -EACCES;
57363 put_link(nd, &link, cookie);
57364 }
57365 }
57366@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57367 if (!err)
57368 err = complete_walk(nd);
57369
57370+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57371+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57372+ path_put(&nd->path);
57373+ err = -ENOENT;
57374+ }
57375+ }
57376+
57377 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57378 if (!can_lookup(nd->inode)) {
57379 path_put(&nd->path);
57380@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57381 retval = path_lookupat(dfd, name->name,
57382 flags | LOOKUP_REVAL, nd);
57383
57384- if (likely(!retval))
57385+ if (likely(!retval)) {
57386 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57387+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57388+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57389+ path_put(&nd->path);
57390+ return -ENOENT;
57391+ }
57392+ }
57393+ }
57394 return retval;
57395 }
57396
57397@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57398 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57399 return -EPERM;
57400
57401+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57402+ return -EPERM;
57403+ if (gr_handle_rawio(inode))
57404+ return -EPERM;
57405+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57406+ return -EACCES;
57407+
57408 return 0;
57409 }
57410
57411@@ -2601,7 +2640,7 @@ looked_up:
57412 * cleared otherwise prior to returning.
57413 */
57414 static int lookup_open(struct nameidata *nd, struct path *path,
57415- struct file *file,
57416+ struct path *link, struct file *file,
57417 const struct open_flags *op,
57418 bool got_write, int *opened)
57419 {
57420@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57421 /* Negative dentry, just create the file */
57422 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57423 umode_t mode = op->mode;
57424+
57425+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57426+ error = -EACCES;
57427+ goto out_dput;
57428+ }
57429+
57430+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57431+ error = -EACCES;
57432+ goto out_dput;
57433+ }
57434+
57435 if (!IS_POSIXACL(dir->d_inode))
57436 mode &= ~current_umask();
57437 /*
57438@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57439 nd->flags & LOOKUP_EXCL);
57440 if (error)
57441 goto out_dput;
57442+ else
57443+ gr_handle_create(dentry, nd->path.mnt);
57444 }
57445 out_no_open:
57446 path->dentry = dentry;
57447@@ -2671,7 +2723,7 @@ out_dput:
57448 /*
57449 * Handle the last step of open()
57450 */
57451-static int do_last(struct nameidata *nd, struct path *path,
57452+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57453 struct file *file, const struct open_flags *op,
57454 int *opened, struct filename *name)
57455 {
57456@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57457 if (error)
57458 return error;
57459
57460+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57461+ error = -ENOENT;
57462+ goto out;
57463+ }
57464+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57465+ error = -EACCES;
57466+ goto out;
57467+ }
57468+
57469 audit_inode(name, dir, LOOKUP_PARENT);
57470 error = -EISDIR;
57471 /* trailing slashes? */
57472@@ -2740,7 +2801,7 @@ retry_lookup:
57473 */
57474 }
57475 mutex_lock(&dir->d_inode->i_mutex);
57476- error = lookup_open(nd, path, file, op, got_write, opened);
57477+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57478 mutex_unlock(&dir->d_inode->i_mutex);
57479
57480 if (error <= 0) {
57481@@ -2764,11 +2825,28 @@ retry_lookup:
57482 goto finish_open_created;
57483 }
57484
57485+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57486+ error = -ENOENT;
57487+ goto exit_dput;
57488+ }
57489+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57490+ error = -EACCES;
57491+ goto exit_dput;
57492+ }
57493+
57494 /*
57495 * create/update audit record if it already exists.
57496 */
57497- if (path->dentry->d_inode)
57498+ if (path->dentry->d_inode) {
57499+ /* only check if O_CREAT is specified, all other checks need to go
57500+ into may_open */
57501+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57502+ error = -EACCES;
57503+ goto exit_dput;
57504+ }
57505+
57506 audit_inode(name, path->dentry, 0);
57507+ }
57508
57509 /*
57510 * If atomic_open() acquired write access it is dropped now due to
57511@@ -2809,6 +2887,11 @@ finish_lookup:
57512 }
57513 }
57514 BUG_ON(inode != path->dentry->d_inode);
57515+ /* if we're resolving a symlink to another symlink */
57516+ if (link && gr_handle_symlink_owner(link, inode)) {
57517+ error = -EACCES;
57518+ goto out;
57519+ }
57520 return 1;
57521 }
57522
57523@@ -2818,7 +2901,6 @@ finish_lookup:
57524 save_parent.dentry = nd->path.dentry;
57525 save_parent.mnt = mntget(path->mnt);
57526 nd->path.dentry = path->dentry;
57527-
57528 }
57529 nd->inode = inode;
57530 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57531@@ -2828,7 +2910,18 @@ finish_open:
57532 path_put(&save_parent);
57533 return error;
57534 }
57535+
57536+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57537+ error = -ENOENT;
57538+ goto out;
57539+ }
57540+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57541+ error = -EACCES;
57542+ goto out;
57543+ }
57544+
57545 audit_inode(name, nd->path.dentry, 0);
57546+
57547 error = -EISDIR;
57548 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57549 goto out;
57550@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57551 if (unlikely(error))
57552 goto out;
57553
57554- error = do_last(nd, &path, file, op, &opened, pathname);
57555+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57556 while (unlikely(error > 0)) { /* trailing symlink */
57557 struct path link = path;
57558 void *cookie;
57559@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57560 error = follow_link(&link, nd, &cookie);
57561 if (unlikely(error))
57562 break;
57563- error = do_last(nd, &path, file, op, &opened, pathname);
57564+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57565 put_link(nd, &link, cookie);
57566 }
57567 out:
57568@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57569 goto unlock;
57570
57571 error = -EEXIST;
57572- if (dentry->d_inode)
57573+ if (dentry->d_inode) {
57574+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57575+ error = -ENOENT;
57576+ }
57577 goto fail;
57578+ }
57579 /*
57580 * Special case - lookup gave negative, but... we had foo/bar/
57581 * From the vfs_mknod() POV we just have a negative dentry -
57582@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57583 }
57584 EXPORT_SYMBOL(user_path_create);
57585
57586+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57587+{
57588+ struct filename *tmp = getname(pathname);
57589+ struct dentry *res;
57590+ if (IS_ERR(tmp))
57591+ return ERR_CAST(tmp);
57592+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57593+ if (IS_ERR(res))
57594+ putname(tmp);
57595+ else
57596+ *to = tmp;
57597+ return res;
57598+}
57599+
57600 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57601 {
57602 int error = may_create(dir, dentry);
57603@@ -3224,6 +3335,17 @@ retry:
57604
57605 if (!IS_POSIXACL(path.dentry->d_inode))
57606 mode &= ~current_umask();
57607+
57608+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57609+ error = -EPERM;
57610+ goto out;
57611+ }
57612+
57613+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57614+ error = -EACCES;
57615+ goto out;
57616+ }
57617+
57618 error = security_path_mknod(&path, dentry, mode, dev);
57619 if (error)
57620 goto out;
57621@@ -3240,6 +3362,8 @@ retry:
57622 break;
57623 }
57624 out:
57625+ if (!error)
57626+ gr_handle_create(dentry, path.mnt);
57627 done_path_create(&path, dentry);
57628 if (retry_estale(error, lookup_flags)) {
57629 lookup_flags |= LOOKUP_REVAL;
57630@@ -3292,9 +3416,16 @@ retry:
57631
57632 if (!IS_POSIXACL(path.dentry->d_inode))
57633 mode &= ~current_umask();
57634+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57635+ error = -EACCES;
57636+ goto out;
57637+ }
57638 error = security_path_mkdir(&path, dentry, mode);
57639 if (!error)
57640 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57641+ if (!error)
57642+ gr_handle_create(dentry, path.mnt);
57643+out:
57644 done_path_create(&path, dentry);
57645 if (retry_estale(error, lookup_flags)) {
57646 lookup_flags |= LOOKUP_REVAL;
57647@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57648 struct filename *name;
57649 struct dentry *dentry;
57650 struct nameidata nd;
57651+ ino_t saved_ino = 0;
57652+ dev_t saved_dev = 0;
57653 unsigned int lookup_flags = 0;
57654 retry:
57655 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57656@@ -3407,10 +3540,21 @@ retry:
57657 error = -ENOENT;
57658 goto exit3;
57659 }
57660+
57661+ saved_ino = dentry->d_inode->i_ino;
57662+ saved_dev = gr_get_dev_from_dentry(dentry);
57663+
57664+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57665+ error = -EACCES;
57666+ goto exit3;
57667+ }
57668+
57669 error = security_path_rmdir(&nd.path, dentry);
57670 if (error)
57671 goto exit3;
57672 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57673+ if (!error && (saved_dev || saved_ino))
57674+ gr_handle_delete(saved_ino, saved_dev);
57675 exit3:
57676 dput(dentry);
57677 exit2:
57678@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57679 struct dentry *dentry;
57680 struct nameidata nd;
57681 struct inode *inode = NULL;
57682+ ino_t saved_ino = 0;
57683+ dev_t saved_dev = 0;
57684 unsigned int lookup_flags = 0;
57685 retry:
57686 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57687@@ -3502,10 +3648,22 @@ retry:
57688 if (!inode)
57689 goto slashes;
57690 ihold(inode);
57691+
57692+ if (inode->i_nlink <= 1) {
57693+ saved_ino = inode->i_ino;
57694+ saved_dev = gr_get_dev_from_dentry(dentry);
57695+ }
57696+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57697+ error = -EACCES;
57698+ goto exit2;
57699+ }
57700+
57701 error = security_path_unlink(&nd.path, dentry);
57702 if (error)
57703 goto exit2;
57704 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57705+ if (!error && (saved_ino || saved_dev))
57706+ gr_handle_delete(saved_ino, saved_dev);
57707 exit2:
57708 dput(dentry);
57709 }
57710@@ -3583,9 +3741,17 @@ retry:
57711 if (IS_ERR(dentry))
57712 goto out_putname;
57713
57714+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57715+ error = -EACCES;
57716+ goto out;
57717+ }
57718+
57719 error = security_path_symlink(&path, dentry, from->name);
57720 if (!error)
57721 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57722+ if (!error)
57723+ gr_handle_create(dentry, path.mnt);
57724+out:
57725 done_path_create(&path, dentry);
57726 if (retry_estale(error, lookup_flags)) {
57727 lookup_flags |= LOOKUP_REVAL;
57728@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57729 {
57730 struct dentry *new_dentry;
57731 struct path old_path, new_path;
57732+ struct filename *to = NULL;
57733 int how = 0;
57734 int error;
57735
57736@@ -3688,7 +3855,7 @@ retry:
57737 if (error)
57738 return error;
57739
57740- new_dentry = user_path_create(newdfd, newname, &new_path,
57741+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57742 (how & LOOKUP_REVAL));
57743 error = PTR_ERR(new_dentry);
57744 if (IS_ERR(new_dentry))
57745@@ -3700,11 +3867,28 @@ retry:
57746 error = may_linkat(&old_path);
57747 if (unlikely(error))
57748 goto out_dput;
57749+
57750+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57751+ old_path.dentry->d_inode,
57752+ old_path.dentry->d_inode->i_mode, to)) {
57753+ error = -EACCES;
57754+ goto out_dput;
57755+ }
57756+
57757+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57758+ old_path.dentry, old_path.mnt, to)) {
57759+ error = -EACCES;
57760+ goto out_dput;
57761+ }
57762+
57763 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57764 if (error)
57765 goto out_dput;
57766 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57767+ if (!error)
57768+ gr_handle_create(new_dentry, new_path.mnt);
57769 out_dput:
57770+ putname(to);
57771 done_path_create(&new_path, new_dentry);
57772 if (retry_estale(error, how)) {
57773 how |= LOOKUP_REVAL;
57774@@ -3950,12 +4134,21 @@ retry:
57775 if (new_dentry == trap)
57776 goto exit5;
57777
57778+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57779+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57780+ to);
57781+ if (error)
57782+ goto exit5;
57783+
57784 error = security_path_rename(&oldnd.path, old_dentry,
57785 &newnd.path, new_dentry);
57786 if (error)
57787 goto exit5;
57788 error = vfs_rename(old_dir->d_inode, old_dentry,
57789 new_dir->d_inode, new_dentry);
57790+ if (!error)
57791+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57792+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57793 exit5:
57794 dput(new_dentry);
57795 exit4:
57796@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57797
57798 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57799 {
57800+ char tmpbuf[64];
57801+ const char *newlink;
57802 int len;
57803
57804 len = PTR_ERR(link);
57805@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57806 len = strlen(link);
57807 if (len > (unsigned) buflen)
57808 len = buflen;
57809- if (copy_to_user(buffer, link, len))
57810+
57811+ if (len < sizeof(tmpbuf)) {
57812+ memcpy(tmpbuf, link, len);
57813+ newlink = tmpbuf;
57814+ } else
57815+ newlink = link;
57816+
57817+ if (copy_to_user(buffer, newlink, len))
57818 len = -EFAULT;
57819 out:
57820 return len;
57821diff --git a/fs/namespace.c b/fs/namespace.c
57822index a45ba4f..b4c7d07 100644
57823--- a/fs/namespace.c
57824+++ b/fs/namespace.c
57825@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57826 if (!(sb->s_flags & MS_RDONLY))
57827 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57828 up_write(&sb->s_umount);
57829+
57830+ gr_log_remount(mnt->mnt_devname, retval);
57831+
57832 return retval;
57833 }
57834
57835@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57836 }
57837 br_write_unlock(&vfsmount_lock);
57838 namespace_unlock();
57839+
57840+ gr_log_unmount(mnt->mnt_devname, retval);
57841+
57842 return retval;
57843 }
57844
57845@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57846 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57847 */
57848
57849-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57850+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57851 {
57852 struct path path;
57853 struct mount *mnt;
57854@@ -1342,7 +1348,7 @@ out:
57855 /*
57856 * The 2.0 compatible umount. No flags.
57857 */
57858-SYSCALL_DEFINE1(oldumount, char __user *, name)
57859+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57860 {
57861 return sys_umount(name, 0);
57862 }
57863@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57864 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57865 MS_STRICTATIME);
57866
57867+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57868+ retval = -EPERM;
57869+ goto dput_out;
57870+ }
57871+
57872+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57873+ retval = -EPERM;
57874+ goto dput_out;
57875+ }
57876+
57877 if (flags & MS_REMOUNT)
57878 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57879 data_page);
57880@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57881 dev_name, data_page);
57882 dput_out:
57883 path_put(&path);
57884+
57885+ gr_log_mount(dev_name, dir_name, retval);
57886+
57887 return retval;
57888 }
57889
57890@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
57891 * number incrementing at 10Ghz will take 12,427 years to wrap which
57892 * is effectively never, so we can ignore the possibility.
57893 */
57894-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
57895+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
57896
57897 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57898 {
57899@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57900 kfree(new_ns);
57901 return ERR_PTR(ret);
57902 }
57903- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
57904+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
57905 atomic_set(&new_ns->count, 1);
57906 new_ns->root = NULL;
57907 INIT_LIST_HEAD(&new_ns->list);
57908@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57909 * Allocate a new namespace structure and populate it with contents
57910 * copied from the namespace of the passed in task structure.
57911 */
57912-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57913+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57914 struct user_namespace *user_ns, struct fs_struct *fs)
57915 {
57916 struct mnt_namespace *new_ns;
57917@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
57918 }
57919 EXPORT_SYMBOL(mount_subtree);
57920
57921-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
57922- char __user *, type, unsigned long, flags, void __user *, data)
57923+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
57924+ const char __user *, type, unsigned long, flags, void __user *, data)
57925 {
57926 int ret;
57927 char *kernel_type;
57928@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
57929 if (error)
57930 goto out2;
57931
57932+ if (gr_handle_chroot_pivot()) {
57933+ error = -EPERM;
57934+ goto out2;
57935+ }
57936+
57937 get_fs_root(current->fs, &root);
57938 old_mp = lock_mount(&old);
57939 error = PTR_ERR(old_mp);
57940@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
57941 !nsown_capable(CAP_SYS_ADMIN))
57942 return -EPERM;
57943
57944- if (fs->users != 1)
57945+ if (atomic_read(&fs->users) != 1)
57946 return -EINVAL;
57947
57948 get_mnt_ns(mnt_ns);
57949diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
57950index f4ccfe6..a5cf064 100644
57951--- a/fs/nfs/callback_xdr.c
57952+++ b/fs/nfs/callback_xdr.c
57953@@ -51,7 +51,7 @@ struct callback_op {
57954 callback_decode_arg_t decode_args;
57955 callback_encode_res_t encode_res;
57956 long res_maxsize;
57957-};
57958+} __do_const;
57959
57960 static struct callback_op callback_ops[];
57961
57962diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
57963index 941246f..17d8724 100644
57964--- a/fs/nfs/inode.c
57965+++ b/fs/nfs/inode.c
57966@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
57967 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
57968 }
57969
57970-static atomic_long_t nfs_attr_generation_counter;
57971+static atomic_long_unchecked_t nfs_attr_generation_counter;
57972
57973 static unsigned long nfs_read_attr_generation_counter(void)
57974 {
57975- return atomic_long_read(&nfs_attr_generation_counter);
57976+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
57977 }
57978
57979 unsigned long nfs_inc_attr_generation_counter(void)
57980 {
57981- return atomic_long_inc_return(&nfs_attr_generation_counter);
57982+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
57983 }
57984
57985 void nfs_fattr_init(struct nfs_fattr *fattr)
57986diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
57987index 419572f..5414a23 100644
57988--- a/fs/nfsd/nfs4proc.c
57989+++ b/fs/nfsd/nfs4proc.c
57990@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
57991 nfsd4op_rsize op_rsize_bop;
57992 stateid_getter op_get_currentstateid;
57993 stateid_setter op_set_currentstateid;
57994-};
57995+} __do_const;
57996
57997 static struct nfsd4_operation nfsd4_ops[];
57998
57999diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58000index c2a4701..fd80e29 100644
58001--- a/fs/nfsd/nfs4xdr.c
58002+++ b/fs/nfsd/nfs4xdr.c
58003@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58004
58005 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58006
58007-static nfsd4_dec nfsd4_dec_ops[] = {
58008+static const nfsd4_dec nfsd4_dec_ops[] = {
58009 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58010 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58011 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58012@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58013 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58014 };
58015
58016-static nfsd4_dec nfsd41_dec_ops[] = {
58017+static const nfsd4_dec nfsd41_dec_ops[] = {
58018 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58019 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58020 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58021@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58022 };
58023
58024 struct nfsd4_minorversion_ops {
58025- nfsd4_dec *decoders;
58026+ const nfsd4_dec *decoders;
58027 int nops;
58028 };
58029
58030diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58031index e76244e..9fe8f2f1 100644
58032--- a/fs/nfsd/nfscache.c
58033+++ b/fs/nfsd/nfscache.c
58034@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58035 {
58036 struct svc_cacherep *rp = rqstp->rq_cacherep;
58037 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58038- int len;
58039+ long len;
58040 size_t bufsize = 0;
58041
58042 if (!rp)
58043 return;
58044
58045- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58046- len >>= 2;
58047+ if (statp) {
58048+ len = (char*)statp - (char*)resv->iov_base;
58049+ len = resv->iov_len - len;
58050+ len >>= 2;
58051+ }
58052
58053 /* Don't cache excessive amounts of data and XDR failures */
58054 if (!statp || len > (256 >> 2)) {
58055diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58056index c827acb..b253b77 100644
58057--- a/fs/nfsd/vfs.c
58058+++ b/fs/nfsd/vfs.c
58059@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58060 } else {
58061 oldfs = get_fs();
58062 set_fs(KERNEL_DS);
58063- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58064+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58065 set_fs(oldfs);
58066 }
58067
58068@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58069
58070 /* Write the data. */
58071 oldfs = get_fs(); set_fs(KERNEL_DS);
58072- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58073+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58074 set_fs(oldfs);
58075 if (host_err < 0)
58076 goto out_nfserr;
58077@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58078 */
58079
58080 oldfs = get_fs(); set_fs(KERNEL_DS);
58081- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58082+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58083 set_fs(oldfs);
58084
58085 if (host_err < 0)
58086diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58087index fea6bd5..8ee9d81 100644
58088--- a/fs/nls/nls_base.c
58089+++ b/fs/nls/nls_base.c
58090@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58091
58092 int register_nls(struct nls_table * nls)
58093 {
58094- struct nls_table ** tmp = &tables;
58095+ struct nls_table *tmp = tables;
58096
58097 if (nls->next)
58098 return -EBUSY;
58099
58100 spin_lock(&nls_lock);
58101- while (*tmp) {
58102- if (nls == *tmp) {
58103+ while (tmp) {
58104+ if (nls == tmp) {
58105 spin_unlock(&nls_lock);
58106 return -EBUSY;
58107 }
58108- tmp = &(*tmp)->next;
58109+ tmp = tmp->next;
58110 }
58111- nls->next = tables;
58112+ pax_open_kernel();
58113+ *(struct nls_table **)&nls->next = tables;
58114+ pax_close_kernel();
58115 tables = nls;
58116 spin_unlock(&nls_lock);
58117 return 0;
58118@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58119
58120 int unregister_nls(struct nls_table * nls)
58121 {
58122- struct nls_table ** tmp = &tables;
58123+ struct nls_table * const * tmp = &tables;
58124
58125 spin_lock(&nls_lock);
58126 while (*tmp) {
58127 if (nls == *tmp) {
58128- *tmp = nls->next;
58129+ pax_open_kernel();
58130+ *(struct nls_table **)tmp = nls->next;
58131+ pax_close_kernel();
58132 spin_unlock(&nls_lock);
58133 return 0;
58134 }
58135diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58136index 7424929..35f6be5 100644
58137--- a/fs/nls/nls_euc-jp.c
58138+++ b/fs/nls/nls_euc-jp.c
58139@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58140 p_nls = load_nls("cp932");
58141
58142 if (p_nls) {
58143- table.charset2upper = p_nls->charset2upper;
58144- table.charset2lower = p_nls->charset2lower;
58145+ pax_open_kernel();
58146+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58147+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58148+ pax_close_kernel();
58149 return register_nls(&table);
58150 }
58151
58152diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58153index e7bc1d7..06bd4bb 100644
58154--- a/fs/nls/nls_koi8-ru.c
58155+++ b/fs/nls/nls_koi8-ru.c
58156@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58157 p_nls = load_nls("koi8-u");
58158
58159 if (p_nls) {
58160- table.charset2upper = p_nls->charset2upper;
58161- table.charset2lower = p_nls->charset2lower;
58162+ pax_open_kernel();
58163+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58164+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58165+ pax_close_kernel();
58166 return register_nls(&table);
58167 }
58168
58169diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58170index e44cb64..4807084 100644
58171--- a/fs/notify/fanotify/fanotify_user.c
58172+++ b/fs/notify/fanotify/fanotify_user.c
58173@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58174
58175 fd = fanotify_event_metadata.fd;
58176 ret = -EFAULT;
58177- if (copy_to_user(buf, &fanotify_event_metadata,
58178- fanotify_event_metadata.event_len))
58179+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58180+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58181 goto out_close_fd;
58182
58183 ret = prepare_for_access_response(group, event, fd);
58184diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58185index 7b51b05..5ea5ef6 100644
58186--- a/fs/notify/notification.c
58187+++ b/fs/notify/notification.c
58188@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58189 * get set to 0 so it will never get 'freed'
58190 */
58191 static struct fsnotify_event *q_overflow_event;
58192-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58193+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58194
58195 /**
58196 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58197@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58198 */
58199 u32 fsnotify_get_cookie(void)
58200 {
58201- return atomic_inc_return(&fsnotify_sync_cookie);
58202+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58203 }
58204 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58205
58206diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58207index 9e38daf..5727cae 100644
58208--- a/fs/ntfs/dir.c
58209+++ b/fs/ntfs/dir.c
58210@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58211 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58212 ~(s64)(ndir->itype.index.block_size - 1)));
58213 /* Bounds checks. */
58214- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58215+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58216 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58217 "inode 0x%lx or driver bug.", vdir->i_ino);
58218 goto err_out;
58219diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58220index c5670b8..d590213 100644
58221--- a/fs/ntfs/file.c
58222+++ b/fs/ntfs/file.c
58223@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58224 char *addr;
58225 size_t total = 0;
58226 unsigned len;
58227- int left;
58228+ unsigned left;
58229
58230 do {
58231 len = PAGE_CACHE_SIZE - ofs;
58232diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58233index 82650d5..db37dcf 100644
58234--- a/fs/ntfs/super.c
58235+++ b/fs/ntfs/super.c
58236@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58237 if (!silent)
58238 ntfs_error(sb, "Primary boot sector is invalid.");
58239 } else if (!silent)
58240- ntfs_error(sb, read_err_str, "primary");
58241+ ntfs_error(sb, read_err_str, "%s", "primary");
58242 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58243 if (bh_primary)
58244 brelse(bh_primary);
58245@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58246 goto hotfix_primary_boot_sector;
58247 brelse(bh_backup);
58248 } else if (!silent)
58249- ntfs_error(sb, read_err_str, "backup");
58250+ ntfs_error(sb, read_err_str, "%s", "backup");
58251 /* Try to read NT3.51- backup boot sector. */
58252 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58253 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58254@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58255 "sector.");
58256 brelse(bh_backup);
58257 } else if (!silent)
58258- ntfs_error(sb, read_err_str, "backup");
58259+ ntfs_error(sb, read_err_str, "%s", "backup");
58260 /* We failed. Cleanup and return. */
58261 if (bh_primary)
58262 brelse(bh_primary);
58263diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58264index aebeacd..0dcdd26 100644
58265--- a/fs/ocfs2/localalloc.c
58266+++ b/fs/ocfs2/localalloc.c
58267@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58268 goto bail;
58269 }
58270
58271- atomic_inc(&osb->alloc_stats.moves);
58272+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58273
58274 bail:
58275 if (handle)
58276diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58277index 3a90347..c40bef8 100644
58278--- a/fs/ocfs2/ocfs2.h
58279+++ b/fs/ocfs2/ocfs2.h
58280@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58281
58282 struct ocfs2_alloc_stats
58283 {
58284- atomic_t moves;
58285- atomic_t local_data;
58286- atomic_t bitmap_data;
58287- atomic_t bg_allocs;
58288- atomic_t bg_extends;
58289+ atomic_unchecked_t moves;
58290+ atomic_unchecked_t local_data;
58291+ atomic_unchecked_t bitmap_data;
58292+ atomic_unchecked_t bg_allocs;
58293+ atomic_unchecked_t bg_extends;
58294 };
58295
58296 enum ocfs2_local_alloc_state
58297diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58298index 5397c07..54afc55 100644
58299--- a/fs/ocfs2/suballoc.c
58300+++ b/fs/ocfs2/suballoc.c
58301@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58302 mlog_errno(status);
58303 goto bail;
58304 }
58305- atomic_inc(&osb->alloc_stats.bg_extends);
58306+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58307
58308 /* You should never ask for this much metadata */
58309 BUG_ON(bits_wanted >
58310@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58311 mlog_errno(status);
58312 goto bail;
58313 }
58314- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58315+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58316
58317 *suballoc_loc = res.sr_bg_blkno;
58318 *suballoc_bit_start = res.sr_bit_offset;
58319@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58320 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58321 res->sr_bits);
58322
58323- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58324+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58325
58326 BUG_ON(res->sr_bits != 1);
58327
58328@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58329 mlog_errno(status);
58330 goto bail;
58331 }
58332- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58333+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58334
58335 BUG_ON(res.sr_bits != 1);
58336
58337@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58338 cluster_start,
58339 num_clusters);
58340 if (!status)
58341- atomic_inc(&osb->alloc_stats.local_data);
58342+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58343 } else {
58344 if (min_clusters > (osb->bitmap_cpg - 1)) {
58345 /* The only paths asking for contiguousness
58346@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58347 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58348 res.sr_bg_blkno,
58349 res.sr_bit_offset);
58350- atomic_inc(&osb->alloc_stats.bitmap_data);
58351+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58352 *num_clusters = res.sr_bits;
58353 }
58354 }
58355diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58356index 121da2d..a0232bc 100644
58357--- a/fs/ocfs2/super.c
58358+++ b/fs/ocfs2/super.c
58359@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58360 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58361 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58362 "Stats",
58363- atomic_read(&osb->alloc_stats.bitmap_data),
58364- atomic_read(&osb->alloc_stats.local_data),
58365- atomic_read(&osb->alloc_stats.bg_allocs),
58366- atomic_read(&osb->alloc_stats.moves),
58367- atomic_read(&osb->alloc_stats.bg_extends));
58368+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58369+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58370+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58371+ atomic_read_unchecked(&osb->alloc_stats.moves),
58372+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58373
58374 out += snprintf(buf + out, len - out,
58375 "%10s => State: %u Descriptor: %llu Size: %u bits "
58376@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58377 spin_lock_init(&osb->osb_xattr_lock);
58378 ocfs2_init_steal_slots(osb);
58379
58380- atomic_set(&osb->alloc_stats.moves, 0);
58381- atomic_set(&osb->alloc_stats.local_data, 0);
58382- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58383- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58384- atomic_set(&osb->alloc_stats.bg_extends, 0);
58385+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58386+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58387+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58388+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58389+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58390
58391 /* Copy the blockcheck stats from the superblock probe */
58392 osb->osb_ecc_stats = *stats;
58393diff --git a/fs/open.c b/fs/open.c
58394index 7931f76..7b03f3b 100644
58395--- a/fs/open.c
58396+++ b/fs/open.c
58397@@ -32,6 +32,8 @@
58398 #include <linux/dnotify.h>
58399 #include <linux/compat.h>
58400
58401+#define CREATE_TRACE_POINTS
58402+#include <trace/events/fs.h>
58403 #include "internal.h"
58404
58405 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58406@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58407 error = locks_verify_truncate(inode, NULL, length);
58408 if (!error)
58409 error = security_path_truncate(path);
58410+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58411+ error = -EACCES;
58412 if (!error)
58413 error = do_truncate(path->dentry, length, 0, NULL);
58414
58415@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58416 error = locks_verify_truncate(inode, f.file, length);
58417 if (!error)
58418 error = security_path_truncate(&f.file->f_path);
58419+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58420+ error = -EACCES;
58421 if (!error)
58422 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58423 sb_end_write(inode->i_sb);
58424@@ -360,6 +366,9 @@ retry:
58425 if (__mnt_is_readonly(path.mnt))
58426 res = -EROFS;
58427
58428+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58429+ res = -EACCES;
58430+
58431 out_path_release:
58432 path_put(&path);
58433 if (retry_estale(res, lookup_flags)) {
58434@@ -391,6 +400,8 @@ retry:
58435 if (error)
58436 goto dput_and_out;
58437
58438+ gr_log_chdir(path.dentry, path.mnt);
58439+
58440 set_fs_pwd(current->fs, &path);
58441
58442 dput_and_out:
58443@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58444 goto out_putf;
58445
58446 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58447+
58448+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58449+ error = -EPERM;
58450+
58451+ if (!error)
58452+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58453+
58454 if (!error)
58455 set_fs_pwd(current->fs, &f.file->f_path);
58456 out_putf:
58457@@ -449,7 +467,13 @@ retry:
58458 if (error)
58459 goto dput_and_out;
58460
58461+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58462+ goto dput_and_out;
58463+
58464 set_fs_root(current->fs, &path);
58465+
58466+ gr_handle_chroot_chdir(&path);
58467+
58468 error = 0;
58469 dput_and_out:
58470 path_put(&path);
58471@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58472 if (error)
58473 return error;
58474 mutex_lock(&inode->i_mutex);
58475+
58476+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58477+ error = -EACCES;
58478+ goto out_unlock;
58479+ }
58480+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58481+ error = -EACCES;
58482+ goto out_unlock;
58483+ }
58484+
58485 error = security_path_chmod(path, mode);
58486 if (error)
58487 goto out_unlock;
58488@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58489 uid = make_kuid(current_user_ns(), user);
58490 gid = make_kgid(current_user_ns(), group);
58491
58492+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58493+ return -EACCES;
58494+
58495 newattrs.ia_valid = ATTR_CTIME;
58496 if (user != (uid_t) -1) {
58497 if (!uid_valid(uid))
58498@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58499 } else {
58500 fsnotify_open(f);
58501 fd_install(fd, f);
58502+ trace_do_sys_open(tmp->name, flags, mode);
58503 }
58504 }
58505 putname(tmp);
58506diff --git a/fs/pipe.c b/fs/pipe.c
58507index d2c45e1..009fe1c 100644
58508--- a/fs/pipe.c
58509+++ b/fs/pipe.c
58510@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58511
58512 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58513 {
58514- if (pipe->files)
58515+ if (atomic_read(&pipe->files))
58516 mutex_lock_nested(&pipe->mutex, subclass);
58517 }
58518
58519@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58520
58521 void pipe_unlock(struct pipe_inode_info *pipe)
58522 {
58523- if (pipe->files)
58524+ if (atomic_read(&pipe->files))
58525 mutex_unlock(&pipe->mutex);
58526 }
58527 EXPORT_SYMBOL(pipe_unlock);
58528@@ -449,9 +449,9 @@ redo:
58529 }
58530 if (bufs) /* More to do? */
58531 continue;
58532- if (!pipe->writers)
58533+ if (!atomic_read(&pipe->writers))
58534 break;
58535- if (!pipe->waiting_writers) {
58536+ if (!atomic_read(&pipe->waiting_writers)) {
58537 /* syscall merging: Usually we must not sleep
58538 * if O_NONBLOCK is set, or if we got some data.
58539 * But if a writer sleeps in kernel space, then
58540@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58541 ret = 0;
58542 __pipe_lock(pipe);
58543
58544- if (!pipe->readers) {
58545+ if (!atomic_read(&pipe->readers)) {
58546 send_sig(SIGPIPE, current, 0);
58547 ret = -EPIPE;
58548 goto out;
58549@@ -562,7 +562,7 @@ redo1:
58550 for (;;) {
58551 int bufs;
58552
58553- if (!pipe->readers) {
58554+ if (!atomic_read(&pipe->readers)) {
58555 send_sig(SIGPIPE, current, 0);
58556 if (!ret)
58557 ret = -EPIPE;
58558@@ -653,9 +653,9 @@ redo2:
58559 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58560 do_wakeup = 0;
58561 }
58562- pipe->waiting_writers++;
58563+ atomic_inc(&pipe->waiting_writers);
58564 pipe_wait(pipe);
58565- pipe->waiting_writers--;
58566+ atomic_dec(&pipe->waiting_writers);
58567 }
58568 out:
58569 __pipe_unlock(pipe);
58570@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58571 mask = 0;
58572 if (filp->f_mode & FMODE_READ) {
58573 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58574- if (!pipe->writers && filp->f_version != pipe->w_counter)
58575+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58576 mask |= POLLHUP;
58577 }
58578
58579@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58580 * Most Unices do not set POLLERR for FIFOs but on Linux they
58581 * behave exactly like pipes for poll().
58582 */
58583- if (!pipe->readers)
58584+ if (!atomic_read(&pipe->readers))
58585 mask |= POLLERR;
58586 }
58587
58588@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58589
58590 __pipe_lock(pipe);
58591 if (file->f_mode & FMODE_READ)
58592- pipe->readers--;
58593+ atomic_dec(&pipe->readers);
58594 if (file->f_mode & FMODE_WRITE)
58595- pipe->writers--;
58596+ atomic_dec(&pipe->writers);
58597
58598- if (pipe->readers || pipe->writers) {
58599+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58600 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58601 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58602 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58603 }
58604 spin_lock(&inode->i_lock);
58605- if (!--pipe->files) {
58606+ if (atomic_dec_and_test(&pipe->files)) {
58607 inode->i_pipe = NULL;
58608 kill = 1;
58609 }
58610@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58611 kfree(pipe);
58612 }
58613
58614-static struct vfsmount *pipe_mnt __read_mostly;
58615+struct vfsmount *pipe_mnt __read_mostly;
58616
58617 /*
58618 * pipefs_dname() is called from d_path().
58619@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58620 goto fail_iput;
58621
58622 inode->i_pipe = pipe;
58623- pipe->files = 2;
58624- pipe->readers = pipe->writers = 1;
58625+ atomic_set(&pipe->files, 2);
58626+ atomic_set(&pipe->readers, 1);
58627+ atomic_set(&pipe->writers, 1);
58628 inode->i_fop = &pipefifo_fops;
58629
58630 /*
58631@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58632 spin_lock(&inode->i_lock);
58633 if (inode->i_pipe) {
58634 pipe = inode->i_pipe;
58635- pipe->files++;
58636+ atomic_inc(&pipe->files);
58637 spin_unlock(&inode->i_lock);
58638 } else {
58639 spin_unlock(&inode->i_lock);
58640 pipe = alloc_pipe_info();
58641 if (!pipe)
58642 return -ENOMEM;
58643- pipe->files = 1;
58644+ atomic_set(&pipe->files, 1);
58645 spin_lock(&inode->i_lock);
58646 if (unlikely(inode->i_pipe)) {
58647- inode->i_pipe->files++;
58648+ atomic_inc(&inode->i_pipe->files);
58649 spin_unlock(&inode->i_lock);
58650 free_pipe_info(pipe);
58651 pipe = inode->i_pipe;
58652@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58653 * opened, even when there is no process writing the FIFO.
58654 */
58655 pipe->r_counter++;
58656- if (pipe->readers++ == 0)
58657+ if (atomic_inc_return(&pipe->readers) == 1)
58658 wake_up_partner(pipe);
58659
58660- if (!is_pipe && !pipe->writers) {
58661+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58662 if ((filp->f_flags & O_NONBLOCK)) {
58663 /* suppress POLLHUP until we have
58664 * seen a writer */
58665@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58666 * errno=ENXIO when there is no process reading the FIFO.
58667 */
58668 ret = -ENXIO;
58669- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58670+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58671 goto err;
58672
58673 pipe->w_counter++;
58674- if (!pipe->writers++)
58675+ if (atomic_inc_return(&pipe->writers) == 1)
58676 wake_up_partner(pipe);
58677
58678- if (!is_pipe && !pipe->readers) {
58679+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58680 if (wait_for_partner(pipe, &pipe->r_counter))
58681 goto err_wr;
58682 }
58683@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58684 * the process can at least talk to itself.
58685 */
58686
58687- pipe->readers++;
58688- pipe->writers++;
58689+ atomic_inc(&pipe->readers);
58690+ atomic_inc(&pipe->writers);
58691 pipe->r_counter++;
58692 pipe->w_counter++;
58693- if (pipe->readers == 1 || pipe->writers == 1)
58694+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58695 wake_up_partner(pipe);
58696 break;
58697
58698@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58699 return 0;
58700
58701 err_rd:
58702- if (!--pipe->readers)
58703+ if (atomic_dec_and_test(&pipe->readers))
58704 wake_up_interruptible(&pipe->wait);
58705 ret = -ERESTARTSYS;
58706 goto err;
58707
58708 err_wr:
58709- if (!--pipe->writers)
58710+ if (atomic_dec_and_test(&pipe->writers))
58711 wake_up_interruptible(&pipe->wait);
58712 ret = -ERESTARTSYS;
58713 goto err;
58714
58715 err:
58716 spin_lock(&inode->i_lock);
58717- if (!--pipe->files) {
58718+ if (atomic_dec_and_test(&pipe->files)) {
58719 inode->i_pipe = NULL;
58720 kill = 1;
58721 }
58722diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58723index 15af622..0e9f4467 100644
58724--- a/fs/proc/Kconfig
58725+++ b/fs/proc/Kconfig
58726@@ -30,12 +30,12 @@ config PROC_FS
58727
58728 config PROC_KCORE
58729 bool "/proc/kcore support" if !ARM
58730- depends on PROC_FS && MMU
58731+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58732
58733 config PROC_VMCORE
58734 bool "/proc/vmcore support"
58735- depends on PROC_FS && CRASH_DUMP
58736- default y
58737+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58738+ default n
58739 help
58740 Exports the dump image of crashed kernel in ELF format.
58741
58742@@ -59,8 +59,8 @@ config PROC_SYSCTL
58743 limited in memory.
58744
58745 config PROC_PAGE_MONITOR
58746- default y
58747- depends on PROC_FS && MMU
58748+ default n
58749+ depends on PROC_FS && MMU && !GRKERNSEC
58750 bool "Enable /proc page monitoring" if EXPERT
58751 help
58752 Various /proc files exist to monitor process memory utilization:
58753diff --git a/fs/proc/array.c b/fs/proc/array.c
58754index cbd0f1b..adec3f0 100644
58755--- a/fs/proc/array.c
58756+++ b/fs/proc/array.c
58757@@ -60,6 +60,7 @@
58758 #include <linux/tty.h>
58759 #include <linux/string.h>
58760 #include <linux/mman.h>
58761+#include <linux/grsecurity.h>
58762 #include <linux/proc_fs.h>
58763 #include <linux/ioport.h>
58764 #include <linux/uaccess.h>
58765@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58766 seq_putc(m, '\n');
58767 }
58768
58769+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58770+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58771+{
58772+ if (p->mm)
58773+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58774+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58775+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58776+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58777+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58778+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58779+ else
58780+ seq_printf(m, "PaX:\t-----\n");
58781+}
58782+#endif
58783+
58784 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58785 struct pid *pid, struct task_struct *task)
58786 {
58787@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58788 task_cpus_allowed(m, task);
58789 cpuset_task_status_allowed(m, task);
58790 task_context_switch_counts(m, task);
58791+
58792+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58793+ task_pax(m, task);
58794+#endif
58795+
58796+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58797+ task_grsec_rbac(m, task);
58798+#endif
58799+
58800 return 0;
58801 }
58802
58803+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58804+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58805+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58806+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58807+#endif
58808+
58809 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58810 struct pid *pid, struct task_struct *task, int whole)
58811 {
58812@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58813 char tcomm[sizeof(task->comm)];
58814 unsigned long flags;
58815
58816+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58817+ if (current->exec_id != m->exec_id) {
58818+ gr_log_badprocpid("stat");
58819+ return 0;
58820+ }
58821+#endif
58822+
58823 state = *get_task_state(task);
58824 vsize = eip = esp = 0;
58825 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58826@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58827 gtime = task_gtime(task);
58828 }
58829
58830+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58831+ if (PAX_RAND_FLAGS(mm)) {
58832+ eip = 0;
58833+ esp = 0;
58834+ wchan = 0;
58835+ }
58836+#endif
58837+#ifdef CONFIG_GRKERNSEC_HIDESYM
58838+ wchan = 0;
58839+ eip =0;
58840+ esp =0;
58841+#endif
58842+
58843 /* scale priority and nice values from timeslices to -20..20 */
58844 /* to make it look like a "normal" Unix priority/nice value */
58845 priority = task_prio(task);
58846@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58847 seq_put_decimal_ull(m, ' ', vsize);
58848 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58849 seq_put_decimal_ull(m, ' ', rsslim);
58850+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58851+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58852+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58853+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58854+#else
58855 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58856 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58857 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58858+#endif
58859 seq_put_decimal_ull(m, ' ', esp);
58860 seq_put_decimal_ull(m, ' ', eip);
58861 /* The signal information here is obsolete.
58862@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58863 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58864 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58865
58866- if (mm && permitted) {
58867+ if (mm && permitted
58868+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58869+ && !PAX_RAND_FLAGS(mm)
58870+#endif
58871+ ) {
58872 seq_put_decimal_ull(m, ' ', mm->start_data);
58873 seq_put_decimal_ull(m, ' ', mm->end_data);
58874 seq_put_decimal_ull(m, ' ', mm->start_brk);
58875@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58876 struct pid *pid, struct task_struct *task)
58877 {
58878 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58879- struct mm_struct *mm = get_task_mm(task);
58880+ struct mm_struct *mm;
58881
58882+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58883+ if (current->exec_id != m->exec_id) {
58884+ gr_log_badprocpid("statm");
58885+ return 0;
58886+ }
58887+#endif
58888+ mm = get_task_mm(task);
58889 if (mm) {
58890 size = task_statm(mm, &shared, &text, &data, &resident);
58891 mmput(mm);
58892@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58893 return 0;
58894 }
58895
58896+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58897+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
58898+{
58899+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
58900+}
58901+#endif
58902+
58903 #ifdef CONFIG_CHECKPOINT_RESTORE
58904 static struct pid *
58905 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
58906diff --git a/fs/proc/base.c b/fs/proc/base.c
58907index 1485e38..8ad4236 100644
58908--- a/fs/proc/base.c
58909+++ b/fs/proc/base.c
58910@@ -113,6 +113,14 @@ struct pid_entry {
58911 union proc_op op;
58912 };
58913
58914+struct getdents_callback {
58915+ struct linux_dirent __user * current_dir;
58916+ struct linux_dirent __user * previous;
58917+ struct file * file;
58918+ int count;
58919+ int error;
58920+};
58921+
58922 #define NOD(NAME, MODE, IOP, FOP, OP) { \
58923 .name = (NAME), \
58924 .len = sizeof(NAME) - 1, \
58925@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
58926 if (!mm->arg_end)
58927 goto out_mm; /* Shh! No looking before we're done */
58928
58929+ if (gr_acl_handle_procpidmem(task))
58930+ goto out_mm;
58931+
58932 len = mm->arg_end - mm->arg_start;
58933
58934 if (len > PAGE_SIZE)
58935@@ -237,12 +248,28 @@ out:
58936 return res;
58937 }
58938
58939+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58940+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58941+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58942+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58943+#endif
58944+
58945 static int proc_pid_auxv(struct task_struct *task, char *buffer)
58946 {
58947 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
58948 int res = PTR_ERR(mm);
58949 if (mm && !IS_ERR(mm)) {
58950 unsigned int nwords = 0;
58951+
58952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58953+ /* allow if we're currently ptracing this task */
58954+ if (PAX_RAND_FLAGS(mm) &&
58955+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
58956+ mmput(mm);
58957+ return 0;
58958+ }
58959+#endif
58960+
58961 do {
58962 nwords += 2;
58963 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
58964@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
58965 }
58966
58967
58968-#ifdef CONFIG_KALLSYMS
58969+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58970 /*
58971 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
58972 * Returns the resolved symbol. If that fails, simply return the address.
58973@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
58974 mutex_unlock(&task->signal->cred_guard_mutex);
58975 }
58976
58977-#ifdef CONFIG_STACKTRACE
58978+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58979
58980 #define MAX_STACK_TRACE_DEPTH 64
58981
58982@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
58983 return count;
58984 }
58985
58986-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
58987+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
58988 static int proc_pid_syscall(struct task_struct *task, char *buffer)
58989 {
58990 long nr;
58991@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
58992 /************************************************************************/
58993
58994 /* permission checks */
58995-static int proc_fd_access_allowed(struct inode *inode)
58996+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
58997 {
58998 struct task_struct *task;
58999 int allowed = 0;
59000@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59001 */
59002 task = get_proc_task(inode);
59003 if (task) {
59004- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59005+ if (log)
59006+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59007+ else
59008+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59009 put_task_struct(task);
59010 }
59011 return allowed;
59012@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59013 struct task_struct *task,
59014 int hide_pid_min)
59015 {
59016+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59017+ return false;
59018+
59019+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59020+ rcu_read_lock();
59021+ {
59022+ const struct cred *tmpcred = current_cred();
59023+ const struct cred *cred = __task_cred(task);
59024+
59025+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59026+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59027+ || in_group_p(grsec_proc_gid)
59028+#endif
59029+ ) {
59030+ rcu_read_unlock();
59031+ return true;
59032+ }
59033+ }
59034+ rcu_read_unlock();
59035+
59036+ if (!pid->hide_pid)
59037+ return false;
59038+#endif
59039+
59040 if (pid->hide_pid < hide_pid_min)
59041 return true;
59042 if (in_group_p(pid->pid_gid))
59043 return true;
59044+
59045 return ptrace_may_access(task, PTRACE_MODE_READ);
59046 }
59047
59048@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59049 put_task_struct(task);
59050
59051 if (!has_perms) {
59052+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59053+ {
59054+#else
59055 if (pid->hide_pid == 2) {
59056+#endif
59057 /*
59058 * Let's make getdents(), stat(), and open()
59059 * consistent with each other. If a process
59060@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59061 if (!task)
59062 return -ESRCH;
59063
59064+ if (gr_acl_handle_procpidmem(task)) {
59065+ put_task_struct(task);
59066+ return -EPERM;
59067+ }
59068+
59069 mm = mm_access(task, mode);
59070 put_task_struct(task);
59071
59072@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59073
59074 file->private_data = mm;
59075
59076+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59077+ file->f_version = current->exec_id;
59078+#endif
59079+
59080 return 0;
59081 }
59082
59083@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59084 ssize_t copied;
59085 char *page;
59086
59087+#ifdef CONFIG_GRKERNSEC
59088+ if (write)
59089+ return -EPERM;
59090+#endif
59091+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59092+ if (file->f_version != current->exec_id) {
59093+ gr_log_badprocpid("mem");
59094+ return 0;
59095+ }
59096+#endif
59097+
59098 if (!mm)
59099 return 0;
59100
59101@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59102 goto free;
59103
59104 while (count > 0) {
59105- int this_len = min_t(int, count, PAGE_SIZE);
59106+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59107
59108 if (write && copy_from_user(page, buf, this_len)) {
59109 copied = -EFAULT;
59110@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59111 if (!mm)
59112 return 0;
59113
59114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59115+ if (file->f_version != current->exec_id) {
59116+ gr_log_badprocpid("environ");
59117+ return 0;
59118+ }
59119+#endif
59120+
59121 page = (char *)__get_free_page(GFP_TEMPORARY);
59122 if (!page)
59123 return -ENOMEM;
59124@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59125 goto free;
59126 while (count > 0) {
59127 size_t this_len, max_len;
59128- int retval;
59129+ ssize_t retval;
59130
59131 if (src >= (mm->env_end - mm->env_start))
59132 break;
59133@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59134 int error = -EACCES;
59135
59136 /* Are we allowed to snoop on the tasks file descriptors? */
59137- if (!proc_fd_access_allowed(inode))
59138+ if (!proc_fd_access_allowed(inode, 0))
59139 goto out;
59140
59141 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59142@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59143 struct path path;
59144
59145 /* Are we allowed to snoop on the tasks file descriptors? */
59146- if (!proc_fd_access_allowed(inode))
59147- goto out;
59148+ /* logging this is needed for learning on chromium to work properly,
59149+ but we don't want to flood the logs from 'ps' which does a readlink
59150+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59151+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59152+ */
59153+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59154+ if (!proc_fd_access_allowed(inode,0))
59155+ goto out;
59156+ } else {
59157+ if (!proc_fd_access_allowed(inode,1))
59158+ goto out;
59159+ }
59160
59161 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59162 if (error)
59163@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59164 rcu_read_lock();
59165 cred = __task_cred(task);
59166 inode->i_uid = cred->euid;
59167+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59168+ inode->i_gid = grsec_proc_gid;
59169+#else
59170 inode->i_gid = cred->egid;
59171+#endif
59172 rcu_read_unlock();
59173 }
59174 security_task_to_inode(task, inode);
59175@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59176 return -ENOENT;
59177 }
59178 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59179+#ifdef CONFIG_GRKERNSEC_PROC_USER
59180+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59181+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59182+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59183+#endif
59184 task_dumpable(task)) {
59185 cred = __task_cred(task);
59186 stat->uid = cred->euid;
59187+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59188+ stat->gid = grsec_proc_gid;
59189+#else
59190 stat->gid = cred->egid;
59191+#endif
59192 }
59193 }
59194 rcu_read_unlock();
59195@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59196
59197 if (task) {
59198 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59199+#ifdef CONFIG_GRKERNSEC_PROC_USER
59200+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59201+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59202+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59203+#endif
59204 task_dumpable(task)) {
59205 rcu_read_lock();
59206 cred = __task_cred(task);
59207 inode->i_uid = cred->euid;
59208+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59209+ inode->i_gid = grsec_proc_gid;
59210+#else
59211 inode->i_gid = cred->egid;
59212+#endif
59213 rcu_read_unlock();
59214 } else {
59215 inode->i_uid = GLOBAL_ROOT_UID;
59216@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59217 if (!task)
59218 goto out_no_task;
59219
59220+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59221+ goto out;
59222+
59223 /*
59224 * Yes, it does not scale. And it should not. Don't add
59225 * new entries into /proc/<tgid>/ without very good reasons.
59226@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59227 if (!task)
59228 return -ENOENT;
59229
59230+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59231+ goto out;
59232+
59233 if (!dir_emit_dots(file, ctx))
59234 goto out;
59235
59236@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59237 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59238 #endif
59239 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59240-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59241+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59242 INF("syscall", S_IRUGO, proc_pid_syscall),
59243 #endif
59244 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59245@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59246 #ifdef CONFIG_SECURITY
59247 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59248 #endif
59249-#ifdef CONFIG_KALLSYMS
59250+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59251 INF("wchan", S_IRUGO, proc_pid_wchan),
59252 #endif
59253-#ifdef CONFIG_STACKTRACE
59254+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59255 ONE("stack", S_IRUGO, proc_pid_stack),
59256 #endif
59257 #ifdef CONFIG_SCHEDSTATS
59258@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59259 #ifdef CONFIG_HARDWALL
59260 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59261 #endif
59262+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59263+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59264+#endif
59265 #ifdef CONFIG_USER_NS
59266 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59267 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59268@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59269 if (!inode)
59270 goto out;
59271
59272+#ifdef CONFIG_GRKERNSEC_PROC_USER
59273+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59274+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59275+ inode->i_gid = grsec_proc_gid;
59276+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59277+#else
59278 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59279+#endif
59280 inode->i_op = &proc_tgid_base_inode_operations;
59281 inode->i_fop = &proc_tgid_base_operations;
59282 inode->i_flags|=S_IMMUTABLE;
59283@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59284 if (!task)
59285 goto out;
59286
59287+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59288+ goto out_put_task;
59289+
59290 result = proc_pid_instantiate(dir, dentry, task, NULL);
59291+out_put_task:
59292 put_task_struct(task);
59293 out:
59294 return ERR_PTR(result);
59295@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59296 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59297 #endif
59298 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59299-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59300+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59301 INF("syscall", S_IRUGO, proc_pid_syscall),
59302 #endif
59303 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59304@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59305 #ifdef CONFIG_SECURITY
59306 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59307 #endif
59308-#ifdef CONFIG_KALLSYMS
59309+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59310 INF("wchan", S_IRUGO, proc_pid_wchan),
59311 #endif
59312-#ifdef CONFIG_STACKTRACE
59313+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59314 ONE("stack", S_IRUGO, proc_pid_stack),
59315 #endif
59316 #ifdef CONFIG_SCHEDSTATS
59317diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59318index 82676e3..5f8518a 100644
59319--- a/fs/proc/cmdline.c
59320+++ b/fs/proc/cmdline.c
59321@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59322
59323 static int __init proc_cmdline_init(void)
59324 {
59325+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59326+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59327+#else
59328 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59329+#endif
59330 return 0;
59331 }
59332 module_init(proc_cmdline_init);
59333diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59334index b143471..bb105e5 100644
59335--- a/fs/proc/devices.c
59336+++ b/fs/proc/devices.c
59337@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59338
59339 static int __init proc_devices_init(void)
59340 {
59341+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59342+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59343+#else
59344 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59345+#endif
59346 return 0;
59347 }
59348 module_init(proc_devices_init);
59349diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59350index 0ff80f9..a1d7500 100644
59351--- a/fs/proc/fd.c
59352+++ b/fs/proc/fd.c
59353@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59354 if (!task)
59355 return -ENOENT;
59356
59357- files = get_files_struct(task);
59358+ if (!gr_acl_handle_procpidmem(task))
59359+ files = get_files_struct(task);
59360 put_task_struct(task);
59361
59362 if (files) {
59363@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59364 */
59365 int proc_fd_permission(struct inode *inode, int mask)
59366 {
59367+ struct task_struct *task;
59368 int rv = generic_permission(inode, mask);
59369- if (rv == 0)
59370- return 0;
59371+
59372 if (task_pid(current) == proc_pid(inode))
59373 rv = 0;
59374+
59375+ task = get_proc_task(inode);
59376+ if (task == NULL)
59377+ return rv;
59378+
59379+ if (gr_acl_handle_procpidmem(task))
59380+ rv = -EACCES;
59381+
59382+ put_task_struct(task);
59383+
59384 return rv;
59385 }
59386
59387diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59388index 073aea6..0630370 100644
59389--- a/fs/proc/inode.c
59390+++ b/fs/proc/inode.c
59391@@ -23,11 +23,17 @@
59392 #include <linux/slab.h>
59393 #include <linux/mount.h>
59394 #include <linux/magic.h>
59395+#include <linux/grsecurity.h>
59396
59397 #include <asm/uaccess.h>
59398
59399 #include "internal.h"
59400
59401+#ifdef CONFIG_PROC_SYSCTL
59402+extern const struct inode_operations proc_sys_inode_operations;
59403+extern const struct inode_operations proc_sys_dir_operations;
59404+#endif
59405+
59406 static void proc_evict_inode(struct inode *inode)
59407 {
59408 struct proc_dir_entry *de;
59409@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59410 ns = PROC_I(inode)->ns.ns;
59411 if (ns_ops && ns)
59412 ns_ops->put(ns);
59413+
59414+#ifdef CONFIG_PROC_SYSCTL
59415+ if (inode->i_op == &proc_sys_inode_operations ||
59416+ inode->i_op == &proc_sys_dir_operations)
59417+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59418+#endif
59419+
59420 }
59421
59422 static struct kmem_cache * proc_inode_cachep;
59423@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59424 if (de->mode) {
59425 inode->i_mode = de->mode;
59426 inode->i_uid = de->uid;
59427+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59428+ inode->i_gid = grsec_proc_gid;
59429+#else
59430 inode->i_gid = de->gid;
59431+#endif
59432 }
59433 if (de->size)
59434 inode->i_size = de->size;
59435diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59436index 651d09a..60c73ae 100644
59437--- a/fs/proc/internal.h
59438+++ b/fs/proc/internal.h
59439@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59440 struct pid *, struct task_struct *);
59441 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59442 struct pid *, struct task_struct *);
59443+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59444+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59445+#endif
59446
59447 /*
59448 * base.c
59449diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59450index 06ea155..9a798c7 100644
59451--- a/fs/proc/kcore.c
59452+++ b/fs/proc/kcore.c
59453@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59454 * the addresses in the elf_phdr on our list.
59455 */
59456 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59457- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59458+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59459+ if (tsz > buflen)
59460 tsz = buflen;
59461-
59462+
59463 while (buflen) {
59464 struct kcore_list *m;
59465
59466@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59467 kfree(elf_buf);
59468 } else {
59469 if (kern_addr_valid(start)) {
59470- unsigned long n;
59471+ char *elf_buf;
59472+ mm_segment_t oldfs;
59473
59474- n = copy_to_user(buffer, (char *)start, tsz);
59475- /*
59476- * We cannot distinguish between fault on source
59477- * and fault on destination. When this happens
59478- * we clear too and hope it will trigger the
59479- * EFAULT again.
59480- */
59481- if (n) {
59482- if (clear_user(buffer + tsz - n,
59483- n))
59484+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59485+ if (!elf_buf)
59486+ return -ENOMEM;
59487+ oldfs = get_fs();
59488+ set_fs(KERNEL_DS);
59489+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59490+ set_fs(oldfs);
59491+ if (copy_to_user(buffer, elf_buf, tsz)) {
59492+ kfree(elf_buf);
59493 return -EFAULT;
59494+ }
59495 }
59496+ set_fs(oldfs);
59497+ kfree(elf_buf);
59498 } else {
59499 if (clear_user(buffer, tsz))
59500 return -EFAULT;
59501@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59502
59503 static int open_kcore(struct inode *inode, struct file *filp)
59504 {
59505+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59506+ return -EPERM;
59507+#endif
59508 if (!capable(CAP_SYS_RAWIO))
59509 return -EPERM;
59510 if (kcore_need_update)
59511diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59512index 5aa847a..f77c8d4 100644
59513--- a/fs/proc/meminfo.c
59514+++ b/fs/proc/meminfo.c
59515@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59516 vmi.used >> 10,
59517 vmi.largest_chunk >> 10
59518 #ifdef CONFIG_MEMORY_FAILURE
59519- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59520+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59521 #endif
59522 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59523 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59524diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59525index ccfd99b..1b7e255 100644
59526--- a/fs/proc/nommu.c
59527+++ b/fs/proc/nommu.c
59528@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59529 if (len < 1)
59530 len = 1;
59531 seq_printf(m, "%*c", len, ' ');
59532- seq_path(m, &file->f_path, "");
59533+ seq_path(m, &file->f_path, "\n\\");
59534 }
59535
59536 seq_putc(m, '\n');
59537diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59538index 4677bb7..408e936 100644
59539--- a/fs/proc/proc_net.c
59540+++ b/fs/proc/proc_net.c
59541@@ -23,6 +23,7 @@
59542 #include <linux/nsproxy.h>
59543 #include <net/net_namespace.h>
59544 #include <linux/seq_file.h>
59545+#include <linux/grsecurity.h>
59546
59547 #include "internal.h"
59548
59549@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59550 struct task_struct *task;
59551 struct nsproxy *ns;
59552 struct net *net = NULL;
59553+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59554+ const struct cred *cred = current_cred();
59555+#endif
59556+
59557+#ifdef CONFIG_GRKERNSEC_PROC_USER
59558+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59559+ return net;
59560+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59561+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59562+ return net;
59563+#endif
59564
59565 rcu_read_lock();
59566 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59567diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59568index 7129046..f2779c6 100644
59569--- a/fs/proc/proc_sysctl.c
59570+++ b/fs/proc/proc_sysctl.c
59571@@ -13,11 +13,15 @@
59572 #include <linux/module.h>
59573 #include "internal.h"
59574
59575+extern int gr_handle_chroot_sysctl(const int op);
59576+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59577+ const int op);
59578+
59579 static const struct dentry_operations proc_sys_dentry_operations;
59580 static const struct file_operations proc_sys_file_operations;
59581-static const struct inode_operations proc_sys_inode_operations;
59582+const struct inode_operations proc_sys_inode_operations;
59583 static const struct file_operations proc_sys_dir_file_operations;
59584-static const struct inode_operations proc_sys_dir_operations;
59585+const struct inode_operations proc_sys_dir_operations;
59586
59587 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59588 {
59589@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59590
59591 err = NULL;
59592 d_set_d_op(dentry, &proc_sys_dentry_operations);
59593+
59594+ gr_handle_proc_create(dentry, inode);
59595+
59596 d_add(dentry, inode);
59597
59598 out:
59599@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59600 struct inode *inode = file_inode(filp);
59601 struct ctl_table_header *head = grab_header(inode);
59602 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59603+ int op = write ? MAY_WRITE : MAY_READ;
59604 ssize_t error;
59605 size_t res;
59606
59607@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59608 * and won't be until we finish.
59609 */
59610 error = -EPERM;
59611- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59612+ if (sysctl_perm(head, table, op))
59613 goto out;
59614
59615 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59616@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59617 if (!table->proc_handler)
59618 goto out;
59619
59620+#ifdef CONFIG_GRKERNSEC
59621+ error = -EPERM;
59622+ if (gr_handle_chroot_sysctl(op))
59623+ goto out;
59624+ dget(filp->f_path.dentry);
59625+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59626+ dput(filp->f_path.dentry);
59627+ goto out;
59628+ }
59629+ dput(filp->f_path.dentry);
59630+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59631+ goto out;
59632+ if (write && !capable(CAP_SYS_ADMIN))
59633+ goto out;
59634+#endif
59635+
59636 /* careful: calling conventions are nasty here */
59637 res = count;
59638 error = table->proc_handler(table, write, buf, &res, ppos);
59639@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59640 return false;
59641 } else {
59642 d_set_d_op(child, &proc_sys_dentry_operations);
59643+
59644+ gr_handle_proc_create(child, inode);
59645+
59646 d_add(child, inode);
59647 }
59648 } else {
59649@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59650 if ((*pos)++ < ctx->pos)
59651 return true;
59652
59653+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59654+ return 0;
59655+
59656 if (unlikely(S_ISLNK(table->mode)))
59657 res = proc_sys_link_fill_cache(file, ctx, head, table);
59658 else
59659@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59660 if (IS_ERR(head))
59661 return PTR_ERR(head);
59662
59663+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59664+ return -ENOENT;
59665+
59666 generic_fillattr(inode, stat);
59667 if (table)
59668 stat->mode = (stat->mode & S_IFMT) | table->mode;
59669@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59670 .llseek = generic_file_llseek,
59671 };
59672
59673-static const struct inode_operations proc_sys_inode_operations = {
59674+const struct inode_operations proc_sys_inode_operations = {
59675 .permission = proc_sys_permission,
59676 .setattr = proc_sys_setattr,
59677 .getattr = proc_sys_getattr,
59678 };
59679
59680-static const struct inode_operations proc_sys_dir_operations = {
59681+const struct inode_operations proc_sys_dir_operations = {
59682 .lookup = proc_sys_lookup,
59683 .permission = proc_sys_permission,
59684 .setattr = proc_sys_setattr,
59685@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59686 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59687 const char *name, int namelen)
59688 {
59689- struct ctl_table *table;
59690+ ctl_table_no_const *table;
59691 struct ctl_dir *new;
59692 struct ctl_node *node;
59693 char *new_name;
59694@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59695 return NULL;
59696
59697 node = (struct ctl_node *)(new + 1);
59698- table = (struct ctl_table *)(node + 1);
59699+ table = (ctl_table_no_const *)(node + 1);
59700 new_name = (char *)(table + 2);
59701 memcpy(new_name, name, namelen);
59702 new_name[namelen] = '\0';
59703@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59704 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59705 struct ctl_table_root *link_root)
59706 {
59707- struct ctl_table *link_table, *entry, *link;
59708+ ctl_table_no_const *link_table, *link;
59709+ struct ctl_table *entry;
59710 struct ctl_table_header *links;
59711 struct ctl_node *node;
59712 char *link_name;
59713@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59714 return NULL;
59715
59716 node = (struct ctl_node *)(links + 1);
59717- link_table = (struct ctl_table *)(node + nr_entries);
59718+ link_table = (ctl_table_no_const *)(node + nr_entries);
59719 link_name = (char *)&link_table[nr_entries + 1];
59720
59721 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59722@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59723 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59724 struct ctl_table *table)
59725 {
59726- struct ctl_table *ctl_table_arg = NULL;
59727- struct ctl_table *entry, *files;
59728+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59729+ struct ctl_table *entry;
59730 int nr_files = 0;
59731 int nr_dirs = 0;
59732 int err = -ENOMEM;
59733@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59734 nr_files++;
59735 }
59736
59737- files = table;
59738 /* If there are mixed files and directories we need a new table */
59739 if (nr_dirs && nr_files) {
59740- struct ctl_table *new;
59741+ ctl_table_no_const *new;
59742 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59743 GFP_KERNEL);
59744 if (!files)
59745@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59746 /* Register everything except a directory full of subdirectories */
59747 if (nr_files || !nr_dirs) {
59748 struct ctl_table_header *header;
59749- header = __register_sysctl_table(set, path, files);
59750+ header = __register_sysctl_table(set, path, files ? files : table);
59751 if (!header) {
59752 kfree(ctl_table_arg);
59753 goto out;
59754diff --git a/fs/proc/root.c b/fs/proc/root.c
59755index 0e0e83c..005ba6a 100644
59756--- a/fs/proc/root.c
59757+++ b/fs/proc/root.c
59758@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59759 #ifdef CONFIG_PROC_DEVICETREE
59760 proc_device_tree_init();
59761 #endif
59762+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59763+#ifdef CONFIG_GRKERNSEC_PROC_USER
59764+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59765+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59766+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59767+#endif
59768+#else
59769 proc_mkdir("bus", NULL);
59770+#endif
59771 proc_sys_init();
59772 }
59773
59774diff --git a/fs/proc/self.c b/fs/proc/self.c
59775index 6b6a993..807cccc 100644
59776--- a/fs/proc/self.c
59777+++ b/fs/proc/self.c
59778@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59779 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59780 void *cookie)
59781 {
59782- char *s = nd_get_link(nd);
59783+ const char *s = nd_get_link(nd);
59784 if (!IS_ERR(s))
59785 kfree(s);
59786 }
59787diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59788index 107d026..c715aeb 100644
59789--- a/fs/proc/task_mmu.c
59790+++ b/fs/proc/task_mmu.c
59791@@ -12,12 +12,19 @@
59792 #include <linux/swap.h>
59793 #include <linux/swapops.h>
59794 #include <linux/mmu_notifier.h>
59795+#include <linux/grsecurity.h>
59796
59797 #include <asm/elf.h>
59798 #include <asm/uaccess.h>
59799 #include <asm/tlbflush.h>
59800 #include "internal.h"
59801
59802+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59803+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59804+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59805+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59806+#endif
59807+
59808 void task_mem(struct seq_file *m, struct mm_struct *mm)
59809 {
59810 unsigned long data, text, lib, swap;
59811@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59812 "VmExe:\t%8lu kB\n"
59813 "VmLib:\t%8lu kB\n"
59814 "VmPTE:\t%8lu kB\n"
59815- "VmSwap:\t%8lu kB\n",
59816- hiwater_vm << (PAGE_SHIFT-10),
59817+ "VmSwap:\t%8lu kB\n"
59818+
59819+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59820+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59821+#endif
59822+
59823+ ,hiwater_vm << (PAGE_SHIFT-10),
59824 total_vm << (PAGE_SHIFT-10),
59825 mm->locked_vm << (PAGE_SHIFT-10),
59826 mm->pinned_vm << (PAGE_SHIFT-10),
59827@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59828 data << (PAGE_SHIFT-10),
59829 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59830 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59831- swap << (PAGE_SHIFT-10));
59832+ swap << (PAGE_SHIFT-10)
59833+
59834+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59835+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59836+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59837+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59838+#else
59839+ , mm->context.user_cs_base
59840+ , mm->context.user_cs_limit
59841+#endif
59842+#endif
59843+
59844+ );
59845 }
59846
59847 unsigned long task_vsize(struct mm_struct *mm)
59848@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59849 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59850 }
59851
59852- /* We don't show the stack guard page in /proc/maps */
59853+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59854+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59855+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59856+#else
59857 start = vma->vm_start;
59858- if (stack_guard_page_start(vma, start))
59859- start += PAGE_SIZE;
59860 end = vma->vm_end;
59861- if (stack_guard_page_end(vma, end))
59862- end -= PAGE_SIZE;
59863+#endif
59864
59865 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59866 start,
59867@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59868 flags & VM_WRITE ? 'w' : '-',
59869 flags & VM_EXEC ? 'x' : '-',
59870 flags & VM_MAYSHARE ? 's' : 'p',
59871+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59872+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59873+#else
59874 pgoff,
59875+#endif
59876 MAJOR(dev), MINOR(dev), ino, &len);
59877
59878 /*
59879@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59880 */
59881 if (file) {
59882 pad_len_spaces(m, len);
59883- seq_path(m, &file->f_path, "\n");
59884+ seq_path(m, &file->f_path, "\n\\");
59885 goto done;
59886 }
59887
59888@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59889 * Thread stack in /proc/PID/task/TID/maps or
59890 * the main process stack.
59891 */
59892- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59893- vma->vm_end >= mm->start_stack)) {
59894+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59895+ (vma->vm_start <= mm->start_stack &&
59896+ vma->vm_end >= mm->start_stack)) {
59897 name = "[stack]";
59898 } else {
59899 /* Thread stack in /proc/PID/maps */
59900@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59901 struct proc_maps_private *priv = m->private;
59902 struct task_struct *task = priv->task;
59903
59904+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59905+ if (current->exec_id != m->exec_id) {
59906+ gr_log_badprocpid("maps");
59907+ return 0;
59908+ }
59909+#endif
59910+
59911 show_map_vma(m, vma, is_pid);
59912
59913 if (m->count < m->size) /* vma is copied successfully */
59914@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59915 .private = &mss,
59916 };
59917
59918+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59919+ if (current->exec_id != m->exec_id) {
59920+ gr_log_badprocpid("smaps");
59921+ return 0;
59922+ }
59923+#endif
59924 memset(&mss, 0, sizeof mss);
59925- mss.vma = vma;
59926- /* mmap_sem is held in m_start */
59927- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59928- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59929-
59930+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59931+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
59932+#endif
59933+ mss.vma = vma;
59934+ /* mmap_sem is held in m_start */
59935+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59936+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59937+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59938+ }
59939+#endif
59940 show_map_vma(m, vma, is_pid);
59941
59942 seq_printf(m,
59943@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59944 "KernelPageSize: %8lu kB\n"
59945 "MMUPageSize: %8lu kB\n"
59946 "Locked: %8lu kB\n",
59947+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59948+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
59949+#else
59950 (vma->vm_end - vma->vm_start) >> 10,
59951+#endif
59952 mss.resident >> 10,
59953 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
59954 mss.shared_clean >> 10,
59955@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
59956 int n;
59957 char buffer[50];
59958
59959+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59960+ if (current->exec_id != m->exec_id) {
59961+ gr_log_badprocpid("numa_maps");
59962+ return 0;
59963+ }
59964+#endif
59965+
59966 if (!mm)
59967 return 0;
59968
59969@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
59970 mpol_to_str(buffer, sizeof(buffer), pol);
59971 mpol_cond_put(pol);
59972
59973+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59974+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
59975+#else
59976 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
59977+#endif
59978
59979 if (file) {
59980 seq_printf(m, " file=");
59981- seq_path(m, &file->f_path, "\n\t= ");
59982+ seq_path(m, &file->f_path, "\n\t\\= ");
59983 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
59984 seq_printf(m, " heap");
59985 } else {
59986diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
59987index 56123a6..5a2f6ec 100644
59988--- a/fs/proc/task_nommu.c
59989+++ b/fs/proc/task_nommu.c
59990@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59991 else
59992 bytes += kobjsize(mm);
59993
59994- if (current->fs && current->fs->users > 1)
59995+ if (current->fs && atomic_read(&current->fs->users) > 1)
59996 sbytes += kobjsize(current->fs);
59997 else
59998 bytes += kobjsize(current->fs);
59999@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60000
60001 if (file) {
60002 pad_len_spaces(m, len);
60003- seq_path(m, &file->f_path, "");
60004+ seq_path(m, &file->f_path, "\n\\");
60005 } else if (mm) {
60006 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60007
60008diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60009index a1a16eb..6be46ed 100644
60010--- a/fs/proc/vmcore.c
60011+++ b/fs/proc/vmcore.c
60012@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60013 nr_bytes = count;
60014
60015 /* If pfn is not ram, return zeros for sparse dump files */
60016- if (pfn_is_ram(pfn) == 0)
60017- memset(buf, 0, nr_bytes);
60018- else {
60019+ if (pfn_is_ram(pfn) == 0) {
60020+ if (userbuf) {
60021+ if (clear_user((char __force_user *)buf, nr_bytes))
60022+ return -EFAULT;
60023+ } else
60024+ memset(buf, 0, nr_bytes);
60025+ } else {
60026 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60027 offset, userbuf);
60028 if (tmp < 0)
60029@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60030 if (*fpos < m->offset + m->size) {
60031 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60032 start = m->paddr + *fpos - m->offset;
60033- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60034+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60035 if (tmp < 0)
60036 return tmp;
60037 buflen -= tsz;
60038diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60039index b00fcc9..e0c6381 100644
60040--- a/fs/qnx6/qnx6.h
60041+++ b/fs/qnx6/qnx6.h
60042@@ -74,7 +74,7 @@ enum {
60043 BYTESEX_BE,
60044 };
60045
60046-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60047+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60048 {
60049 if (sbi->s_bytesex == BYTESEX_LE)
60050 return le64_to_cpu((__force __le64)n);
60051@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60052 return (__force __fs64)cpu_to_be64(n);
60053 }
60054
60055-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60056+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60057 {
60058 if (sbi->s_bytesex == BYTESEX_LE)
60059 return le32_to_cpu((__force __le32)n);
60060diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60061index 16e8abb..2dcf914 100644
60062--- a/fs/quota/netlink.c
60063+++ b/fs/quota/netlink.c
60064@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60065 void quota_send_warning(struct kqid qid, dev_t dev,
60066 const char warntype)
60067 {
60068- static atomic_t seq;
60069+ static atomic_unchecked_t seq;
60070 struct sk_buff *skb;
60071 void *msg_head;
60072 int ret;
60073@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60074 "VFS: Not enough memory to send quota warning.\n");
60075 return;
60076 }
60077- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60078+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60079 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60080 if (!msg_head) {
60081 printk(KERN_ERR
60082diff --git a/fs/read_write.c b/fs/read_write.c
60083index 122a384..0b7ecf2 100644
60084--- a/fs/read_write.c
60085+++ b/fs/read_write.c
60086@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60087
60088 old_fs = get_fs();
60089 set_fs(get_ds());
60090- p = (__force const char __user *)buf;
60091+ p = (const char __force_user *)buf;
60092 if (count > MAX_RW_COUNT)
60093 count = MAX_RW_COUNT;
60094 if (file->f_op->write)
60095diff --git a/fs/readdir.c b/fs/readdir.c
60096index 93d71e5..6a14be8 100644
60097--- a/fs/readdir.c
60098+++ b/fs/readdir.c
60099@@ -17,6 +17,7 @@
60100 #include <linux/security.h>
60101 #include <linux/syscalls.h>
60102 #include <linux/unistd.h>
60103+#include <linux/namei.h>
60104
60105 #include <asm/uaccess.h>
60106
60107@@ -69,6 +70,7 @@ struct old_linux_dirent {
60108 struct readdir_callback {
60109 struct dir_context ctx;
60110 struct old_linux_dirent __user * dirent;
60111+ struct file * file;
60112 int result;
60113 };
60114
60115@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60116 buf->result = -EOVERFLOW;
60117 return -EOVERFLOW;
60118 }
60119+
60120+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60121+ return 0;
60122+
60123 buf->result++;
60124 dirent = buf->dirent;
60125 if (!access_ok(VERIFY_WRITE, dirent,
60126@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60127 if (!f.file)
60128 return -EBADF;
60129
60130+ buf.file = f.file;
60131 error = iterate_dir(f.file, &buf.ctx);
60132 if (buf.result)
60133 error = buf.result;
60134@@ -142,6 +149,7 @@ struct getdents_callback {
60135 struct dir_context ctx;
60136 struct linux_dirent __user * current_dir;
60137 struct linux_dirent __user * previous;
60138+ struct file * file;
60139 int count;
60140 int error;
60141 };
60142@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60143 buf->error = -EOVERFLOW;
60144 return -EOVERFLOW;
60145 }
60146+
60147+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60148+ return 0;
60149+
60150 dirent = buf->previous;
60151 if (dirent) {
60152 if (__put_user(offset, &dirent->d_off))
60153@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60154 if (!f.file)
60155 return -EBADF;
60156
60157+ buf.file = f.file;
60158 error = iterate_dir(f.file, &buf.ctx);
60159 if (error >= 0)
60160 error = buf.error;
60161@@ -226,6 +239,7 @@ struct getdents_callback64 {
60162 struct dir_context ctx;
60163 struct linux_dirent64 __user * current_dir;
60164 struct linux_dirent64 __user * previous;
60165+ struct file *file;
60166 int count;
60167 int error;
60168 };
60169@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60170 buf->error = -EINVAL; /* only used if we fail.. */
60171 if (reclen > buf->count)
60172 return -EINVAL;
60173+
60174+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60175+ return 0;
60176+
60177 dirent = buf->previous;
60178 if (dirent) {
60179 if (__put_user(offset, &dirent->d_off))
60180@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60181 if (!f.file)
60182 return -EBADF;
60183
60184+ buf.file = f.file;
60185 error = iterate_dir(f.file, &buf.ctx);
60186 if (error >= 0)
60187 error = buf.error;
60188diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60189index 2b7882b..1c5ef48 100644
60190--- a/fs/reiserfs/do_balan.c
60191+++ b/fs/reiserfs/do_balan.c
60192@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60193 return;
60194 }
60195
60196- atomic_inc(&(fs_generation(tb->tb_sb)));
60197+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60198 do_balance_starts(tb);
60199
60200 /* balance leaf returns 0 except if combining L R and S into
60201diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60202index a958444..42b2323 100644
60203--- a/fs/reiserfs/procfs.c
60204+++ b/fs/reiserfs/procfs.c
60205@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60206 "SMALL_TAILS " : "NO_TAILS ",
60207 replay_only(sb) ? "REPLAY_ONLY " : "",
60208 convert_reiserfs(sb) ? "CONV " : "",
60209- atomic_read(&r->s_generation_counter),
60210+ atomic_read_unchecked(&r->s_generation_counter),
60211 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60212 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60213 SF(s_good_search_by_key_reada), SF(s_bmaps),
60214diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60215index 3df5ce6..8c0f4b0 100644
60216--- a/fs/reiserfs/reiserfs.h
60217+++ b/fs/reiserfs/reiserfs.h
60218@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60219 /* Comment? -Hans */
60220 wait_queue_head_t s_wait;
60221 /* To be obsoleted soon by per buffer seals.. -Hans */
60222- atomic_t s_generation_counter; // increased by one every time the
60223+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60224 // tree gets re-balanced
60225 unsigned long s_properties; /* File system properties. Currently holds
60226 on-disk FS format */
60227@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60228 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60229
60230 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60231-#define get_generation(s) atomic_read (&fs_generation(s))
60232+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60233 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60234 #define __fs_changed(gen,s) (gen != get_generation (s))
60235 #define fs_changed(gen,s) \
60236diff --git a/fs/select.c b/fs/select.c
60237index 35d4adc7..d6c60db 100644
60238--- a/fs/select.c
60239+++ b/fs/select.c
60240@@ -20,6 +20,7 @@
60241 #include <linux/export.h>
60242 #include <linux/slab.h>
60243 #include <linux/poll.h>
60244+#include <linux/security.h>
60245 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60246 #include <linux/file.h>
60247 #include <linux/fdtable.h>
60248@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60249 struct poll_list *walk = head;
60250 unsigned long todo = nfds;
60251
60252+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60253 if (nfds > rlimit(RLIMIT_NOFILE))
60254 return -EINVAL;
60255
60256diff --git a/fs/seq_file.c b/fs/seq_file.c
60257index 3135c25..d0395dd 100644
60258--- a/fs/seq_file.c
60259+++ b/fs/seq_file.c
60260@@ -10,6 +10,7 @@
60261 #include <linux/seq_file.h>
60262 #include <linux/slab.h>
60263 #include <linux/cred.h>
60264+#include <linux/sched.h>
60265
60266 #include <asm/uaccess.h>
60267 #include <asm/page.h>
60268@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60269 #ifdef CONFIG_USER_NS
60270 p->user_ns = file->f_cred->user_ns;
60271 #endif
60272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60273+ p->exec_id = current->exec_id;
60274+#endif
60275
60276 /*
60277 * Wrappers around seq_open(e.g. swaps_open) need to be
60278@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60279 return 0;
60280 }
60281 if (!m->buf) {
60282- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60283+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60284 if (!m->buf)
60285 return -ENOMEM;
60286 }
60287@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60288 Eoverflow:
60289 m->op->stop(m, p);
60290 kfree(m->buf);
60291- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60292+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60293 return !m->buf ? -ENOMEM : -EAGAIN;
60294 }
60295
60296@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60297
60298 /* grab buffer if we didn't have one */
60299 if (!m->buf) {
60300- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60301+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60302 if (!m->buf)
60303 goto Enomem;
60304 }
60305@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60306 goto Fill;
60307 m->op->stop(m, p);
60308 kfree(m->buf);
60309- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60310+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60311 if (!m->buf)
60312 goto Enomem;
60313 m->count = 0;
60314@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60315 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60316 void *data)
60317 {
60318- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60319+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60320 int res = -ENOMEM;
60321
60322 if (op) {
60323diff --git a/fs/splice.c b/fs/splice.c
60324index 3b7ee65..87fc2e4 100644
60325--- a/fs/splice.c
60326+++ b/fs/splice.c
60327@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60328 pipe_lock(pipe);
60329
60330 for (;;) {
60331- if (!pipe->readers) {
60332+ if (!atomic_read(&pipe->readers)) {
60333 send_sig(SIGPIPE, current, 0);
60334 if (!ret)
60335 ret = -EPIPE;
60336@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60337 page_nr++;
60338 ret += buf->len;
60339
60340- if (pipe->files)
60341+ if (atomic_read(&pipe->files))
60342 do_wakeup = 1;
60343
60344 if (!--spd->nr_pages)
60345@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60346 do_wakeup = 0;
60347 }
60348
60349- pipe->waiting_writers++;
60350+ atomic_inc(&pipe->waiting_writers);
60351 pipe_wait(pipe);
60352- pipe->waiting_writers--;
60353+ atomic_dec(&pipe->waiting_writers);
60354 }
60355
60356 pipe_unlock(pipe);
60357@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60358 old_fs = get_fs();
60359 set_fs(get_ds());
60360 /* The cast to a user pointer is valid due to the set_fs() */
60361- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60362+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60363 set_fs(old_fs);
60364
60365 return res;
60366@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60367 old_fs = get_fs();
60368 set_fs(get_ds());
60369 /* The cast to a user pointer is valid due to the set_fs() */
60370- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60371+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60372 set_fs(old_fs);
60373
60374 return res;
60375@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60376 goto err;
60377
60378 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60379- vec[i].iov_base = (void __user *) page_address(page);
60380+ vec[i].iov_base = (void __force_user *) page_address(page);
60381 vec[i].iov_len = this_len;
60382 spd.pages[i] = page;
60383 spd.nr_pages++;
60384@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60385 ops->release(pipe, buf);
60386 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60387 pipe->nrbufs--;
60388- if (pipe->files)
60389+ if (atomic_read(&pipe->files))
60390 sd->need_wakeup = true;
60391 }
60392
60393@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60394 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60395 {
60396 while (!pipe->nrbufs) {
60397- if (!pipe->writers)
60398+ if (!atomic_read(&pipe->writers))
60399 return 0;
60400
60401- if (!pipe->waiting_writers && sd->num_spliced)
60402+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60403 return 0;
60404
60405 if (sd->flags & SPLICE_F_NONBLOCK)
60406@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60407 * out of the pipe right after the splice_to_pipe(). So set
60408 * PIPE_READERS appropriately.
60409 */
60410- pipe->readers = 1;
60411+ atomic_set(&pipe->readers, 1);
60412
60413 current->splice_pipe = pipe;
60414 }
60415@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60416
60417 partial[buffers].offset = off;
60418 partial[buffers].len = plen;
60419+ partial[buffers].private = 0;
60420
60421 off = 0;
60422 len -= plen;
60423@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60424 ret = -ERESTARTSYS;
60425 break;
60426 }
60427- if (!pipe->writers)
60428+ if (!atomic_read(&pipe->writers))
60429 break;
60430- if (!pipe->waiting_writers) {
60431+ if (!atomic_read(&pipe->waiting_writers)) {
60432 if (flags & SPLICE_F_NONBLOCK) {
60433 ret = -EAGAIN;
60434 break;
60435@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60436 pipe_lock(pipe);
60437
60438 while (pipe->nrbufs >= pipe->buffers) {
60439- if (!pipe->readers) {
60440+ if (!atomic_read(&pipe->readers)) {
60441 send_sig(SIGPIPE, current, 0);
60442 ret = -EPIPE;
60443 break;
60444@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60445 ret = -ERESTARTSYS;
60446 break;
60447 }
60448- pipe->waiting_writers++;
60449+ atomic_inc(&pipe->waiting_writers);
60450 pipe_wait(pipe);
60451- pipe->waiting_writers--;
60452+ atomic_dec(&pipe->waiting_writers);
60453 }
60454
60455 pipe_unlock(pipe);
60456@@ -1862,14 +1863,14 @@ retry:
60457 pipe_double_lock(ipipe, opipe);
60458
60459 do {
60460- if (!opipe->readers) {
60461+ if (!atomic_read(&opipe->readers)) {
60462 send_sig(SIGPIPE, current, 0);
60463 if (!ret)
60464 ret = -EPIPE;
60465 break;
60466 }
60467
60468- if (!ipipe->nrbufs && !ipipe->writers)
60469+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60470 break;
60471
60472 /*
60473@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60474 pipe_double_lock(ipipe, opipe);
60475
60476 do {
60477- if (!opipe->readers) {
60478+ if (!atomic_read(&opipe->readers)) {
60479 send_sig(SIGPIPE, current, 0);
60480 if (!ret)
60481 ret = -EPIPE;
60482@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60483 * return EAGAIN if we have the potential of some data in the
60484 * future, otherwise just return 0
60485 */
60486- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60487+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60488 ret = -EAGAIN;
60489
60490 pipe_unlock(ipipe);
60491diff --git a/fs/stat.c b/fs/stat.c
60492index 04ce1ac..a13dd1e 100644
60493--- a/fs/stat.c
60494+++ b/fs/stat.c
60495@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60496 stat->gid = inode->i_gid;
60497 stat->rdev = inode->i_rdev;
60498 stat->size = i_size_read(inode);
60499- stat->atime = inode->i_atime;
60500- stat->mtime = inode->i_mtime;
60501+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60502+ stat->atime = inode->i_ctime;
60503+ stat->mtime = inode->i_ctime;
60504+ } else {
60505+ stat->atime = inode->i_atime;
60506+ stat->mtime = inode->i_mtime;
60507+ }
60508 stat->ctime = inode->i_ctime;
60509 stat->blksize = (1 << inode->i_blkbits);
60510 stat->blocks = inode->i_blocks;
60511@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60512 if (retval)
60513 return retval;
60514
60515- if (inode->i_op->getattr)
60516- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60517+ if (inode->i_op->getattr) {
60518+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60519+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60520+ stat->atime = stat->ctime;
60521+ stat->mtime = stat->ctime;
60522+ }
60523+ return retval;
60524+ }
60525
60526 generic_fillattr(inode, stat);
60527 return 0;
60528diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60529index 15c68f9..36a8b3e 100644
60530--- a/fs/sysfs/bin.c
60531+++ b/fs/sysfs/bin.c
60532@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60533 return ret;
60534 }
60535
60536-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60537- void *buf, int len, int write)
60538+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60539+ void *buf, size_t len, int write)
60540 {
60541 struct file *file = vma->vm_file;
60542 struct bin_buffer *bb = file->private_data;
60543 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60544- int ret;
60545+ ssize_t ret;
60546
60547 if (!bb->vm_ops)
60548 return -EINVAL;
60549diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60550index e068e74..92edeb8 100644
60551--- a/fs/sysfs/dir.c
60552+++ b/fs/sysfs/dir.c
60553@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60554 *
60555 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60556 */
60557-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60558+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60559 {
60560 unsigned long hash = init_name_hash();
60561 unsigned int len = strlen(name);
60562@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60563 struct sysfs_dirent *sd;
60564 int rc;
60565
60566+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60567+ const char *parent_name = parent_sd->s_name;
60568+
60569+ mode = S_IFDIR | S_IRWXU;
60570+
60571+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60572+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60573+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60574+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60575+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60576+#endif
60577+
60578 /* allocate */
60579 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60580 if (!sd)
60581diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60582index d2bb7ed..fe8c331 100644
60583--- a/fs/sysfs/file.c
60584+++ b/fs/sysfs/file.c
60585@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60586
60587 struct sysfs_open_dirent {
60588 atomic_t refcnt;
60589- atomic_t event;
60590+ atomic_unchecked_t event;
60591 wait_queue_head_t poll;
60592 struct list_head buffers; /* goes through sysfs_buffer.list */
60593 };
60594@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60595 if (!sysfs_get_active(attr_sd))
60596 return -ENODEV;
60597
60598- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60599+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60600 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60601
60602 sysfs_put_active(attr_sd);
60603@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60604 return -ENOMEM;
60605
60606 atomic_set(&new_od->refcnt, 0);
60607- atomic_set(&new_od->event, 1);
60608+ atomic_set_unchecked(&new_od->event, 1);
60609 init_waitqueue_head(&new_od->poll);
60610 INIT_LIST_HEAD(&new_od->buffers);
60611 goto retry;
60612@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60613
60614 sysfs_put_active(attr_sd);
60615
60616- if (buffer->event != atomic_read(&od->event))
60617+ if (buffer->event != atomic_read_unchecked(&od->event))
60618 goto trigger;
60619
60620 return DEFAULT_POLLMASK;
60621@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60622 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60623 od = sd->s_attr.open;
60624 if (od) {
60625- atomic_inc(&od->event);
60626+ atomic_inc_unchecked(&od->event);
60627 wake_up_interruptible(&od->poll);
60628 }
60629 }
60630diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60631index 8c940df..25b733e 100644
60632--- a/fs/sysfs/symlink.c
60633+++ b/fs/sysfs/symlink.c
60634@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60635
60636 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60637 {
60638- char *page = nd_get_link(nd);
60639+ const char *page = nd_get_link(nd);
60640 if (!IS_ERR(page))
60641 free_page((unsigned long)page);
60642 }
60643diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60644index 69d4889..a810bd4 100644
60645--- a/fs/sysv/sysv.h
60646+++ b/fs/sysv/sysv.h
60647@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60648 #endif
60649 }
60650
60651-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60652+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60653 {
60654 if (sbi->s_bytesex == BYTESEX_PDP)
60655 return PDP_swab((__force __u32)n);
60656diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60657index e18b988..f1d4ad0f 100644
60658--- a/fs/ubifs/io.c
60659+++ b/fs/ubifs/io.c
60660@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60661 return err;
60662 }
60663
60664-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60665+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60666 {
60667 int err;
60668
60669diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60670index c175b4d..8f36a16 100644
60671--- a/fs/udf/misc.c
60672+++ b/fs/udf/misc.c
60673@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60674
60675 u8 udf_tag_checksum(const struct tag *t)
60676 {
60677- u8 *data = (u8 *)t;
60678+ const u8 *data = (const u8 *)t;
60679 u8 checksum = 0;
60680 int i;
60681 for (i = 0; i < sizeof(struct tag); ++i)
60682diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60683index 8d974c4..b82f6ec 100644
60684--- a/fs/ufs/swab.h
60685+++ b/fs/ufs/swab.h
60686@@ -22,7 +22,7 @@ enum {
60687 BYTESEX_BE
60688 };
60689
60690-static inline u64
60691+static inline u64 __intentional_overflow(-1)
60692 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60693 {
60694 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60695@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60696 return (__force __fs64)cpu_to_be64(n);
60697 }
60698
60699-static inline u32
60700+static inline u32 __intentional_overflow(-1)
60701 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60702 {
60703 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60704diff --git a/fs/utimes.c b/fs/utimes.c
60705index f4fb7ec..3fe03c0 100644
60706--- a/fs/utimes.c
60707+++ b/fs/utimes.c
60708@@ -1,6 +1,7 @@
60709 #include <linux/compiler.h>
60710 #include <linux/file.h>
60711 #include <linux/fs.h>
60712+#include <linux/security.h>
60713 #include <linux/linkage.h>
60714 #include <linux/mount.h>
60715 #include <linux/namei.h>
60716@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60717 goto mnt_drop_write_and_out;
60718 }
60719 }
60720+
60721+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60722+ error = -EACCES;
60723+ goto mnt_drop_write_and_out;
60724+ }
60725+
60726 mutex_lock(&inode->i_mutex);
60727 error = notify_change(path->dentry, &newattrs);
60728 mutex_unlock(&inode->i_mutex);
60729diff --git a/fs/xattr.c b/fs/xattr.c
60730index 3377dff..4d074d9 100644
60731--- a/fs/xattr.c
60732+++ b/fs/xattr.c
60733@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60734 return rc;
60735 }
60736
60737+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60738+ssize_t
60739+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60740+{
60741+ struct inode *inode = dentry->d_inode;
60742+ ssize_t error;
60743+
60744+ error = inode_permission(inode, MAY_EXEC);
60745+ if (error)
60746+ return error;
60747+
60748+ if (inode->i_op->getxattr)
60749+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60750+ else
60751+ error = -EOPNOTSUPP;
60752+
60753+ return error;
60754+}
60755+EXPORT_SYMBOL(pax_getxattr);
60756+#endif
60757+
60758 ssize_t
60759 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60760 {
60761@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60762 * Extended attribute SET operations
60763 */
60764 static long
60765-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60766+setxattr(struct path *path, const char __user *name, const void __user *value,
60767 size_t size, int flags)
60768 {
60769 int error;
60770@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60771 posix_acl_fix_xattr_from_user(kvalue, size);
60772 }
60773
60774- error = vfs_setxattr(d, kname, kvalue, size, flags);
60775+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60776+ error = -EACCES;
60777+ goto out;
60778+ }
60779+
60780+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60781 out:
60782 if (vvalue)
60783 vfree(vvalue);
60784@@ -377,7 +403,7 @@ retry:
60785 return error;
60786 error = mnt_want_write(path.mnt);
60787 if (!error) {
60788- error = setxattr(path.dentry, name, value, size, flags);
60789+ error = setxattr(&path, name, value, size, flags);
60790 mnt_drop_write(path.mnt);
60791 }
60792 path_put(&path);
60793@@ -401,7 +427,7 @@ retry:
60794 return error;
60795 error = mnt_want_write(path.mnt);
60796 if (!error) {
60797- error = setxattr(path.dentry, name, value, size, flags);
60798+ error = setxattr(&path, name, value, size, flags);
60799 mnt_drop_write(path.mnt);
60800 }
60801 path_put(&path);
60802@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60803 const void __user *,value, size_t, size, int, flags)
60804 {
60805 struct fd f = fdget(fd);
60806- struct dentry *dentry;
60807 int error = -EBADF;
60808
60809 if (!f.file)
60810 return error;
60811- dentry = f.file->f_path.dentry;
60812- audit_inode(NULL, dentry, 0);
60813+ audit_inode(NULL, f.file->f_path.dentry, 0);
60814 error = mnt_want_write_file(f.file);
60815 if (!error) {
60816- error = setxattr(dentry, name, value, size, flags);
60817+ error = setxattr(&f.file->f_path, name, value, size, flags);
60818 mnt_drop_write_file(f.file);
60819 }
60820 fdput(f);
60821diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60822index 9fbea87..6b19972 100644
60823--- a/fs/xattr_acl.c
60824+++ b/fs/xattr_acl.c
60825@@ -76,8 +76,8 @@ struct posix_acl *
60826 posix_acl_from_xattr(struct user_namespace *user_ns,
60827 const void *value, size_t size)
60828 {
60829- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60830- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60831+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60832+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60833 int count;
60834 struct posix_acl *acl;
60835 struct posix_acl_entry *acl_e;
60836diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60837index 05c698c..6b918af 100644
60838--- a/fs/xfs/xfs_bmap.c
60839+++ b/fs/xfs/xfs_bmap.c
60840@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60841
60842 #else
60843 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60844-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60845+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60846 #endif /* DEBUG */
60847
60848 /*
60849diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60850index 97676a3..399a75d 100644
60851--- a/fs/xfs/xfs_dir2_sf.c
60852+++ b/fs/xfs/xfs_dir2_sf.c
60853@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60854
60855 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60856 ctx->pos = off & 0x7fffffff;
60857- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60858+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60859+ char name[sfep->namelen];
60860+ memcpy(name, sfep->name, sfep->namelen);
60861+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60862+ return 0;
60863+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60864 ino, DT_UNKNOWN))
60865 return 0;
60866 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60867diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60868index 6e2bca5..6ce80d3 100644
60869--- a/fs/xfs/xfs_ioctl.c
60870+++ b/fs/xfs/xfs_ioctl.c
60871@@ -127,7 +127,7 @@ xfs_find_handle(
60872 }
60873
60874 error = -EFAULT;
60875- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60876+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60877 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60878 goto out_put;
60879
60880diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60881index 96dda62..d6c6a52 100644
60882--- a/fs/xfs/xfs_iops.c
60883+++ b/fs/xfs/xfs_iops.c
60884@@ -395,7 +395,7 @@ xfs_vn_put_link(
60885 struct nameidata *nd,
60886 void *p)
60887 {
60888- char *s = nd_get_link(nd);
60889+ const char *s = nd_get_link(nd);
60890
60891 if (!IS_ERR(s))
60892 kfree(s);
60893diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60894new file mode 100644
60895index 0000000..0fd7c82
60896--- /dev/null
60897+++ b/grsecurity/Kconfig
60898@@ -0,0 +1,1080 @@
60899+#
60900+# grecurity configuration
60901+#
60902+menu "Memory Protections"
60903+depends on GRKERNSEC
60904+
60905+config GRKERNSEC_KMEM
60906+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60907+ default y if GRKERNSEC_CONFIG_AUTO
60908+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60909+ help
60910+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60911+ be written to or read from to modify or leak the contents of the running
60912+ kernel. /dev/port will also not be allowed to be opened and support
60913+ for /dev/cpu/*/msr will be removed. If you have module
60914+ support disabled, enabling this will close up five ways that are
60915+ currently used to insert malicious code into the running kernel.
60916+
60917+ Even with all these features enabled, we still highly recommend that
60918+ you use the RBAC system, as it is still possible for an attacker to
60919+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60920+
60921+ If you are not using XFree86, you may be able to stop this additional
60922+ case by enabling the 'Disable privileged I/O' option. Though nothing
60923+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60924+ but only to video memory, which is the only writing we allow in this
60925+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60926+ not be allowed to mprotect it with PROT_WRITE later.
60927+ Enabling this feature will prevent the "cpupower" and "powertop" tools
60928+ from working.
60929+
60930+ It is highly recommended that you say Y here if you meet all the
60931+ conditions above.
60932+
60933+config GRKERNSEC_VM86
60934+ bool "Restrict VM86 mode"
60935+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60936+ depends on X86_32
60937+
60938+ help
60939+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60940+ make use of a special execution mode on 32bit x86 processors called
60941+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60942+ video cards and will still work with this option enabled. The purpose
60943+ of the option is to prevent exploitation of emulation errors in
60944+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
60945+ Nearly all users should be able to enable this option.
60946+
60947+config GRKERNSEC_IO
60948+ bool "Disable privileged I/O"
60949+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60950+ depends on X86
60951+ select RTC_CLASS
60952+ select RTC_INTF_DEV
60953+ select RTC_DRV_CMOS
60954+
60955+ help
60956+ If you say Y here, all ioperm and iopl calls will return an error.
60957+ Ioperm and iopl can be used to modify the running kernel.
60958+ Unfortunately, some programs need this access to operate properly,
60959+ the most notable of which are XFree86 and hwclock. hwclock can be
60960+ remedied by having RTC support in the kernel, so real-time
60961+ clock support is enabled if this option is enabled, to ensure
60962+ that hwclock operates correctly. XFree86 still will not
60963+ operate correctly with this option enabled, so DO NOT CHOOSE Y
60964+ IF YOU USE XFree86. If you use XFree86 and you still want to
60965+ protect your kernel against modification, use the RBAC system.
60966+
60967+config GRKERNSEC_JIT_HARDEN
60968+ bool "Harden BPF JIT against spray attacks"
60969+ default y if GRKERNSEC_CONFIG_AUTO
60970+ depends on BPF_JIT
60971+ help
60972+ If you say Y here, the native code generated by the kernel's Berkeley
60973+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
60974+ attacks that attempt to fit attacker-beneficial instructions in
60975+ 32bit immediate fields of JIT-generated native instructions. The
60976+ attacker will generally aim to cause an unintended instruction sequence
60977+ of JIT-generated native code to execute by jumping into the middle of
60978+ a generated instruction. This feature effectively randomizes the 32bit
60979+ immediate constants present in the generated code to thwart such attacks.
60980+
60981+ If you're using KERNEXEC, it's recommended that you enable this option
60982+ to supplement the hardening of the kernel.
60983+
60984+config GRKERNSEC_PERF_HARDEN
60985+ bool "Disable unprivileged PERF_EVENTS usage by default"
60986+ default y if GRKERNSEC_CONFIG_AUTO
60987+ depends on PERF_EVENTS
60988+ help
60989+ If you say Y here, the range of acceptable values for the
60990+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
60991+ default to a new value: 3. When the sysctl is set to this value, no
60992+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
60993+
60994+ Though PERF_EVENTS can be used legitimately for performance monitoring
60995+ and low-level application profiling, it is forced on regardless of
60996+ configuration, has been at fault for several vulnerabilities, and
60997+ creates new opportunities for side channels and other information leaks.
60998+
60999+ This feature puts PERF_EVENTS into a secure default state and permits
61000+ the administrator to change out of it temporarily if unprivileged
61001+ application profiling is needed.
61002+
61003+config GRKERNSEC_RAND_THREADSTACK
61004+ bool "Insert random gaps between thread stacks"
61005+ default y if GRKERNSEC_CONFIG_AUTO
61006+ depends on PAX_RANDMMAP && !PPC
61007+ help
61008+ If you say Y here, a random-sized gap will be enforced between allocated
61009+ thread stacks. Glibc's NPTL and other threading libraries that
61010+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61011+ The implementation currently provides 8 bits of entropy for the gap.
61012+
61013+ Many distributions do not compile threaded remote services with the
61014+ -fstack-check argument to GCC, causing the variable-sized stack-based
61015+ allocator, alloca(), to not probe the stack on allocation. This
61016+ permits an unbounded alloca() to skip over any guard page and potentially
61017+ modify another thread's stack reliably. An enforced random gap
61018+ reduces the reliability of such an attack and increases the chance
61019+ that such a read/write to another thread's stack instead lands in
61020+ an unmapped area, causing a crash and triggering grsecurity's
61021+ anti-bruteforcing logic.
61022+
61023+config GRKERNSEC_PROC_MEMMAP
61024+ bool "Harden ASLR against information leaks and entropy reduction"
61025+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61026+ depends on PAX_NOEXEC || PAX_ASLR
61027+ help
61028+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61029+ give no information about the addresses of its mappings if
61030+ PaX features that rely on random addresses are enabled on the task.
61031+ In addition to sanitizing this information and disabling other
61032+ dangerous sources of information, this option causes reads of sensitive
61033+ /proc/<pid> entries where the file descriptor was opened in a different
61034+ task than the one performing the read. Such attempts are logged.
61035+ This option also limits argv/env strings for suid/sgid binaries
61036+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61037+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61038+ binaries to prevent alternative mmap layouts from being abused.
61039+
61040+ If you use PaX it is essential that you say Y here as it closes up
61041+ several holes that make full ASLR useless locally.
61042+
61043+config GRKERNSEC_BRUTE
61044+ bool "Deter exploit bruteforcing"
61045+ default y if GRKERNSEC_CONFIG_AUTO
61046+ help
61047+ If you say Y here, attempts to bruteforce exploits against forking
61048+ daemons such as apache or sshd, as well as against suid/sgid binaries
61049+ will be deterred. When a child of a forking daemon is killed by PaX
61050+ or crashes due to an illegal instruction or other suspicious signal,
61051+ the parent process will be delayed 30 seconds upon every subsequent
61052+ fork until the administrator is able to assess the situation and
61053+ restart the daemon.
61054+ In the suid/sgid case, the attempt is logged, the user has all their
61055+ existing instances of the suid/sgid binary terminated and will
61056+ be unable to execute any suid/sgid binaries for 15 minutes.
61057+
61058+ It is recommended that you also enable signal logging in the auditing
61059+ section so that logs are generated when a process triggers a suspicious
61060+ signal.
61061+ If the sysctl option is enabled, a sysctl option with name
61062+ "deter_bruteforce" is created.
61063+
61064+
61065+config GRKERNSEC_MODHARDEN
61066+ bool "Harden module auto-loading"
61067+ default y if GRKERNSEC_CONFIG_AUTO
61068+ depends on MODULES
61069+ help
61070+ If you say Y here, module auto-loading in response to use of some
61071+ feature implemented by an unloaded module will be restricted to
61072+ root users. Enabling this option helps defend against attacks
61073+ by unprivileged users who abuse the auto-loading behavior to
61074+ cause a vulnerable module to load that is then exploited.
61075+
61076+ If this option prevents a legitimate use of auto-loading for a
61077+ non-root user, the administrator can execute modprobe manually
61078+ with the exact name of the module mentioned in the alert log.
61079+ Alternatively, the administrator can add the module to the list
61080+ of modules loaded at boot by modifying init scripts.
61081+
61082+ Modification of init scripts will most likely be needed on
61083+ Ubuntu servers with encrypted home directory support enabled,
61084+ as the first non-root user logging in will cause the ecb(aes),
61085+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61086+
61087+config GRKERNSEC_HIDESYM
61088+ bool "Hide kernel symbols"
61089+ default y if GRKERNSEC_CONFIG_AUTO
61090+ select PAX_USERCOPY_SLABS
61091+ help
61092+ If you say Y here, getting information on loaded modules, and
61093+ displaying all kernel symbols through a syscall will be restricted
61094+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61095+ /proc/kallsyms will be restricted to the root user. The RBAC
61096+ system can hide that entry even from root.
61097+
61098+ This option also prevents leaking of kernel addresses through
61099+ several /proc entries.
61100+
61101+ Note that this option is only effective provided the following
61102+ conditions are met:
61103+ 1) The kernel using grsecurity is not precompiled by some distribution
61104+ 2) You have also enabled GRKERNSEC_DMESG
61105+ 3) You are using the RBAC system and hiding other files such as your
61106+ kernel image and System.map. Alternatively, enabling this option
61107+ causes the permissions on /boot, /lib/modules, and the kernel
61108+ source directory to change at compile time to prevent
61109+ reading by non-root users.
61110+ If the above conditions are met, this option will aid in providing a
61111+ useful protection against local kernel exploitation of overflows
61112+ and arbitrary read/write vulnerabilities.
61113+
61114+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61115+ in addition to this feature.
61116+
61117+config GRKERNSEC_KERN_LOCKOUT
61118+ bool "Active kernel exploit response"
61119+ default y if GRKERNSEC_CONFIG_AUTO
61120+ depends on X86 || ARM || PPC || SPARC
61121+ help
61122+ If you say Y here, when a PaX alert is triggered due to suspicious
61123+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61124+ or an OOPS occurs due to bad memory accesses, instead of just
61125+ terminating the offending process (and potentially allowing
61126+ a subsequent exploit from the same user), we will take one of two
61127+ actions:
61128+ If the user was root, we will panic the system
61129+ If the user was non-root, we will log the attempt, terminate
61130+ all processes owned by the user, then prevent them from creating
61131+ any new processes until the system is restarted
61132+ This deters repeated kernel exploitation/bruteforcing attempts
61133+ and is useful for later forensics.
61134+
61135+endmenu
61136+menu "Role Based Access Control Options"
61137+depends on GRKERNSEC
61138+
61139+config GRKERNSEC_RBAC_DEBUG
61140+ bool
61141+
61142+config GRKERNSEC_NO_RBAC
61143+ bool "Disable RBAC system"
61144+ help
61145+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61146+ preventing the RBAC system from being enabled. You should only say Y
61147+ here if you have no intention of using the RBAC system, so as to prevent
61148+ an attacker with root access from misusing the RBAC system to hide files
61149+ and processes when loadable module support and /dev/[k]mem have been
61150+ locked down.
61151+
61152+config GRKERNSEC_ACL_HIDEKERN
61153+ bool "Hide kernel processes"
61154+ help
61155+ If you say Y here, all kernel threads will be hidden to all
61156+ processes but those whose subject has the "view hidden processes"
61157+ flag.
61158+
61159+config GRKERNSEC_ACL_MAXTRIES
61160+ int "Maximum tries before password lockout"
61161+ default 3
61162+ help
61163+ This option enforces the maximum number of times a user can attempt
61164+ to authorize themselves with the grsecurity RBAC system before being
61165+ denied the ability to attempt authorization again for a specified time.
61166+ The lower the number, the harder it will be to brute-force a password.
61167+
61168+config GRKERNSEC_ACL_TIMEOUT
61169+ int "Time to wait after max password tries, in seconds"
61170+ default 30
61171+ help
61172+ This option specifies the time the user must wait after attempting to
61173+ authorize to the RBAC system with the maximum number of invalid
61174+ passwords. The higher the number, the harder it will be to brute-force
61175+ a password.
61176+
61177+endmenu
61178+menu "Filesystem Protections"
61179+depends on GRKERNSEC
61180+
61181+config GRKERNSEC_PROC
61182+ bool "Proc restrictions"
61183+ default y if GRKERNSEC_CONFIG_AUTO
61184+ help
61185+ If you say Y here, the permissions of the /proc filesystem
61186+ will be altered to enhance system security and privacy. You MUST
61187+ choose either a user only restriction or a user and group restriction.
61188+ Depending upon the option you choose, you can either restrict users to
61189+ see only the processes they themselves run, or choose a group that can
61190+ view all processes and files normally restricted to root if you choose
61191+ the "restrict to user only" option. NOTE: If you're running identd or
61192+ ntpd as a non-root user, you will have to run it as the group you
61193+ specify here.
61194+
61195+config GRKERNSEC_PROC_USER
61196+ bool "Restrict /proc to user only"
61197+ depends on GRKERNSEC_PROC
61198+ help
61199+ If you say Y here, non-root users will only be able to view their own
61200+ processes, and restricts them from viewing network-related information,
61201+ and viewing kernel symbol and module information.
61202+
61203+config GRKERNSEC_PROC_USERGROUP
61204+ bool "Allow special group"
61205+ default y if GRKERNSEC_CONFIG_AUTO
61206+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61207+ help
61208+ If you say Y here, you will be able to select a group that will be
61209+ able to view all processes and network-related information. If you've
61210+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61211+ remain hidden. This option is useful if you want to run identd as
61212+ a non-root user. The group you select may also be chosen at boot time
61213+ via "grsec_proc_gid=" on the kernel commandline.
61214+
61215+config GRKERNSEC_PROC_GID
61216+ int "GID for special group"
61217+ depends on GRKERNSEC_PROC_USERGROUP
61218+ default 1001
61219+
61220+config GRKERNSEC_PROC_ADD
61221+ bool "Additional restrictions"
61222+ default y if GRKERNSEC_CONFIG_AUTO
61223+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61224+ help
61225+ If you say Y here, additional restrictions will be placed on
61226+ /proc that keep normal users from viewing device information and
61227+ slabinfo information that could be useful for exploits.
61228+
61229+config GRKERNSEC_LINK
61230+ bool "Linking restrictions"
61231+ default y if GRKERNSEC_CONFIG_AUTO
61232+ help
61233+ If you say Y here, /tmp race exploits will be prevented, since users
61234+ will no longer be able to follow symlinks owned by other users in
61235+ world-writable +t directories (e.g. /tmp), unless the owner of the
61236+ symlink is the owner of the directory. users will also not be
61237+ able to hardlink to files they do not own. If the sysctl option is
61238+ enabled, a sysctl option with name "linking_restrictions" is created.
61239+
61240+config GRKERNSEC_SYMLINKOWN
61241+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61242+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61243+ help
61244+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61245+ that prevents it from being used as a security feature. As Apache
61246+ verifies the symlink by performing a stat() against the target of
61247+ the symlink before it is followed, an attacker can setup a symlink
61248+ to point to a same-owned file, then replace the symlink with one
61249+ that targets another user's file just after Apache "validates" the
61250+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61251+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61252+ will be in place for the group you specify. If the sysctl option
61253+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61254+ created.
61255+
61256+config GRKERNSEC_SYMLINKOWN_GID
61257+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61258+ depends on GRKERNSEC_SYMLINKOWN
61259+ default 1006
61260+ help
61261+ Setting this GID determines what group kernel-enforced
61262+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61263+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61264+
61265+config GRKERNSEC_FIFO
61266+ bool "FIFO restrictions"
61267+ default y if GRKERNSEC_CONFIG_AUTO
61268+ help
61269+ If you say Y here, users will not be able to write to FIFOs they don't
61270+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61271+ the FIFO is the same owner of the directory it's held in. If the sysctl
61272+ option is enabled, a sysctl option with name "fifo_restrictions" is
61273+ created.
61274+
61275+config GRKERNSEC_SYSFS_RESTRICT
61276+ bool "Sysfs/debugfs restriction"
61277+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61278+ depends on SYSFS
61279+ help
61280+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61281+ any filesystem normally mounted under it (e.g. debugfs) will be
61282+ mostly accessible only by root. These filesystems generally provide access
61283+ to hardware and debug information that isn't appropriate for unprivileged
61284+ users of the system. Sysfs and debugfs have also become a large source
61285+ of new vulnerabilities, ranging from infoleaks to local compromise.
61286+ There has been very little oversight with an eye toward security involved
61287+ in adding new exporters of information to these filesystems, so their
61288+ use is discouraged.
61289+ For reasons of compatibility, a few directories have been whitelisted
61290+ for access by non-root users:
61291+ /sys/fs/selinux
61292+ /sys/fs/fuse
61293+ /sys/devices/system/cpu
61294+
61295+config GRKERNSEC_ROFS
61296+ bool "Runtime read-only mount protection"
61297+ depends on SYSCTL
61298+ help
61299+ If you say Y here, a sysctl option with name "romount_protect" will
61300+ be created. By setting this option to 1 at runtime, filesystems
61301+ will be protected in the following ways:
61302+ * No new writable mounts will be allowed
61303+ * Existing read-only mounts won't be able to be remounted read/write
61304+ * Write operations will be denied on all block devices
61305+ This option acts independently of grsec_lock: once it is set to 1,
61306+ it cannot be turned off. Therefore, please be mindful of the resulting
61307+ behavior if this option is enabled in an init script on a read-only
61308+ filesystem. This feature is mainly intended for secure embedded systems.
61309+
61310+config GRKERNSEC_DEVICE_SIDECHANNEL
61311+ bool "Eliminate stat/notify-based device sidechannels"
61312+ default y if GRKERNSEC_CONFIG_AUTO
61313+ help
61314+ If you say Y here, timing analyses on block or character
61315+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61316+ will be thwarted for unprivileged users. If a process without
61317+ CAP_MKNOD stats such a device, the last access and last modify times
61318+ will match the device's create time. No access or modify events
61319+ will be triggered through inotify/dnotify/fanotify for such devices.
61320+ This feature will prevent attacks that may at a minimum
61321+ allow an attacker to determine the administrator's password length.
61322+
61323+config GRKERNSEC_CHROOT
61324+ bool "Chroot jail restrictions"
61325+ default y if GRKERNSEC_CONFIG_AUTO
61326+ help
61327+ If you say Y here, you will be able to choose several options that will
61328+ make breaking out of a chrooted jail much more difficult. If you
61329+ encounter no software incompatibilities with the following options, it
61330+ is recommended that you enable each one.
61331+
61332+config GRKERNSEC_CHROOT_MOUNT
61333+ bool "Deny mounts"
61334+ default y if GRKERNSEC_CONFIG_AUTO
61335+ depends on GRKERNSEC_CHROOT
61336+ help
61337+ If you say Y here, processes inside a chroot will not be able to
61338+ mount or remount filesystems. If the sysctl option is enabled, a
61339+ sysctl option with name "chroot_deny_mount" is created.
61340+
61341+config GRKERNSEC_CHROOT_DOUBLE
61342+ bool "Deny double-chroots"
61343+ default y if GRKERNSEC_CONFIG_AUTO
61344+ depends on GRKERNSEC_CHROOT
61345+ help
61346+ If you say Y here, processes inside a chroot will not be able to chroot
61347+ again outside the chroot. This is a widely used method of breaking
61348+ out of a chroot jail and should not be allowed. If the sysctl
61349+ option is enabled, a sysctl option with name
61350+ "chroot_deny_chroot" is created.
61351+
61352+config GRKERNSEC_CHROOT_PIVOT
61353+ bool "Deny pivot_root in chroot"
61354+ default y if GRKERNSEC_CONFIG_AUTO
61355+ depends on GRKERNSEC_CHROOT
61356+ help
61357+ If you say Y here, processes inside a chroot will not be able to use
61358+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61359+ works similar to chroot in that it changes the root filesystem. This
61360+ function could be misused in a chrooted process to attempt to break out
61361+ of the chroot, and therefore should not be allowed. If the sysctl
61362+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61363+ created.
61364+
61365+config GRKERNSEC_CHROOT_CHDIR
61366+ bool "Enforce chdir(\"/\") on all chroots"
61367+ default y if GRKERNSEC_CONFIG_AUTO
61368+ depends on GRKERNSEC_CHROOT
61369+ help
61370+ If you say Y here, the current working directory of all newly-chrooted
61371+ applications will be set to the the root directory of the chroot.
61372+ The man page on chroot(2) states:
61373+ Note that this call does not change the current working
61374+ directory, so that `.' can be outside the tree rooted at
61375+ `/'. In particular, the super-user can escape from a
61376+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61377+
61378+ It is recommended that you say Y here, since it's not known to break
61379+ any software. If the sysctl option is enabled, a sysctl option with
61380+ name "chroot_enforce_chdir" is created.
61381+
61382+config GRKERNSEC_CHROOT_CHMOD
61383+ bool "Deny (f)chmod +s"
61384+ default y if GRKERNSEC_CONFIG_AUTO
61385+ depends on GRKERNSEC_CHROOT
61386+ help
61387+ If you say Y here, processes inside a chroot will not be able to chmod
61388+ or fchmod files to make them have suid or sgid bits. This protects
61389+ against another published method of breaking a chroot. If the sysctl
61390+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61391+ created.
61392+
61393+config GRKERNSEC_CHROOT_FCHDIR
61394+ bool "Deny fchdir out of chroot"
61395+ default y if GRKERNSEC_CONFIG_AUTO
61396+ depends on GRKERNSEC_CHROOT
61397+ help
61398+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61399+ to a file descriptor of the chrooting process that points to a directory
61400+ outside the filesystem will be stopped. If the sysctl option
61401+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61402+
61403+config GRKERNSEC_CHROOT_MKNOD
61404+ bool "Deny mknod"
61405+ default y if GRKERNSEC_CONFIG_AUTO
61406+ depends on GRKERNSEC_CHROOT
61407+ help
61408+ If you say Y here, processes inside a chroot will not be allowed to
61409+ mknod. The problem with using mknod inside a chroot is that it
61410+ would allow an attacker to create a device entry that is the same
61411+ as one on the physical root of your system, which could range from
61412+ anything from the console device to a device for your harddrive (which
61413+ they could then use to wipe the drive or steal data). It is recommended
61414+ that you say Y here, unless you run into software incompatibilities.
61415+ If the sysctl option is enabled, a sysctl option with name
61416+ "chroot_deny_mknod" is created.
61417+
61418+config GRKERNSEC_CHROOT_SHMAT
61419+ bool "Deny shmat() out of chroot"
61420+ default y if GRKERNSEC_CONFIG_AUTO
61421+ depends on GRKERNSEC_CHROOT
61422+ help
61423+ If you say Y here, processes inside a chroot will not be able to attach
61424+ to shared memory segments that were created outside of the chroot jail.
61425+ It is recommended that you say Y here. If the sysctl option is enabled,
61426+ a sysctl option with name "chroot_deny_shmat" is created.
61427+
61428+config GRKERNSEC_CHROOT_UNIX
61429+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61430+ default y if GRKERNSEC_CONFIG_AUTO
61431+ depends on GRKERNSEC_CHROOT
61432+ help
61433+ If you say Y here, processes inside a chroot will not be able to
61434+ connect to abstract (meaning not belonging to a filesystem) Unix
61435+ domain sockets that were bound outside of a chroot. It is recommended
61436+ that you say Y here. If the sysctl option is enabled, a sysctl option
61437+ with name "chroot_deny_unix" is created.
61438+
61439+config GRKERNSEC_CHROOT_FINDTASK
61440+ bool "Protect outside processes"
61441+ default y if GRKERNSEC_CONFIG_AUTO
61442+ depends on GRKERNSEC_CHROOT
61443+ help
61444+ If you say Y here, processes inside a chroot will not be able to
61445+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61446+ getsid, or view any process outside of the chroot. If the sysctl
61447+ option is enabled, a sysctl option with name "chroot_findtask" is
61448+ created.
61449+
61450+config GRKERNSEC_CHROOT_NICE
61451+ bool "Restrict priority changes"
61452+ default y if GRKERNSEC_CONFIG_AUTO
61453+ depends on GRKERNSEC_CHROOT
61454+ help
61455+ If you say Y here, processes inside a chroot will not be able to raise
61456+ the priority of processes in the chroot, or alter the priority of
61457+ processes outside the chroot. This provides more security than simply
61458+ removing CAP_SYS_NICE from the process' capability set. If the
61459+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61460+ is created.
61461+
61462+config GRKERNSEC_CHROOT_SYSCTL
61463+ bool "Deny sysctl writes"
61464+ default y if GRKERNSEC_CONFIG_AUTO
61465+ depends on GRKERNSEC_CHROOT
61466+ help
61467+ If you say Y here, an attacker in a chroot will not be able to
61468+ write to sysctl entries, either by sysctl(2) or through a /proc
61469+ interface. It is strongly recommended that you say Y here. If the
61470+ sysctl option is enabled, a sysctl option with name
61471+ "chroot_deny_sysctl" is created.
61472+
61473+config GRKERNSEC_CHROOT_CAPS
61474+ bool "Capability restrictions"
61475+ default y if GRKERNSEC_CONFIG_AUTO
61476+ depends on GRKERNSEC_CHROOT
61477+ help
61478+ If you say Y here, the capabilities on all processes within a
61479+ chroot jail will be lowered to stop module insertion, raw i/o,
61480+ system and net admin tasks, rebooting the system, modifying immutable
61481+ files, modifying IPC owned by another, and changing the system time.
61482+ This is left an option because it can break some apps. Disable this
61483+ if your chrooted apps are having problems performing those kinds of
61484+ tasks. If the sysctl option is enabled, a sysctl option with
61485+ name "chroot_caps" is created.
61486+
61487+config GRKERNSEC_CHROOT_INITRD
61488+ bool "Exempt initrd tasks from restrictions"
61489+ default y if GRKERNSEC_CONFIG_AUTO
61490+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61491+ help
61492+ If you say Y here, tasks started prior to init will be exempted from
61493+ grsecurity's chroot restrictions. This option is mainly meant to
61494+ resolve Plymouth's performing privileged operations unnecessarily
61495+ in a chroot.
61496+
61497+endmenu
61498+menu "Kernel Auditing"
61499+depends on GRKERNSEC
61500+
61501+config GRKERNSEC_AUDIT_GROUP
61502+ bool "Single group for auditing"
61503+ help
61504+ If you say Y here, the exec and chdir logging features will only operate
61505+ on a group you specify. This option is recommended if you only want to
61506+ watch certain users instead of having a large amount of logs from the
61507+ entire system. If the sysctl option is enabled, a sysctl option with
61508+ name "audit_group" is created.
61509+
61510+config GRKERNSEC_AUDIT_GID
61511+ int "GID for auditing"
61512+ depends on GRKERNSEC_AUDIT_GROUP
61513+ default 1007
61514+
61515+config GRKERNSEC_EXECLOG
61516+ bool "Exec logging"
61517+ help
61518+ If you say Y here, all execve() calls will be logged (since the
61519+ other exec*() calls are frontends to execve(), all execution
61520+ will be logged). Useful for shell-servers that like to keep track
61521+ of their users. If the sysctl option is enabled, a sysctl option with
61522+ name "exec_logging" is created.
61523+ WARNING: This option when enabled will produce a LOT of logs, especially
61524+ on an active system.
61525+
61526+config GRKERNSEC_RESLOG
61527+ bool "Resource logging"
61528+ default y if GRKERNSEC_CONFIG_AUTO
61529+ help
61530+ If you say Y here, all attempts to overstep resource limits will
61531+ be logged with the resource name, the requested size, and the current
61532+ limit. It is highly recommended that you say Y here. If the sysctl
61533+ option is enabled, a sysctl option with name "resource_logging" is
61534+ created. If the RBAC system is enabled, the sysctl value is ignored.
61535+
61536+config GRKERNSEC_CHROOT_EXECLOG
61537+ bool "Log execs within chroot"
61538+ help
61539+ If you say Y here, all executions inside a chroot jail will be logged
61540+ to syslog. This can cause a large amount of logs if certain
61541+ applications (eg. djb's daemontools) are installed on the system, and
61542+ is therefore left as an option. If the sysctl option is enabled, a
61543+ sysctl option with name "chroot_execlog" is created.
61544+
61545+config GRKERNSEC_AUDIT_PTRACE
61546+ bool "Ptrace logging"
61547+ help
61548+ If you say Y here, all attempts to attach to a process via ptrace
61549+ will be logged. If the sysctl option is enabled, a sysctl option
61550+ with name "audit_ptrace" is created.
61551+
61552+config GRKERNSEC_AUDIT_CHDIR
61553+ bool "Chdir logging"
61554+ help
61555+ If you say Y here, all chdir() calls will be logged. If the sysctl
61556+ option is enabled, a sysctl option with name "audit_chdir" is created.
61557+
61558+config GRKERNSEC_AUDIT_MOUNT
61559+ bool "(Un)Mount logging"
61560+ help
61561+ If you say Y here, all mounts and unmounts will be logged. If the
61562+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61563+ created.
61564+
61565+config GRKERNSEC_SIGNAL
61566+ bool "Signal logging"
61567+ default y if GRKERNSEC_CONFIG_AUTO
61568+ help
61569+ If you say Y here, certain important signals will be logged, such as
61570+ SIGSEGV, which will as a result inform you of when a error in a program
61571+ occurred, which in some cases could mean a possible exploit attempt.
61572+ If the sysctl option is enabled, a sysctl option with name
61573+ "signal_logging" is created.
61574+
61575+config GRKERNSEC_FORKFAIL
61576+ bool "Fork failure logging"
61577+ help
61578+ If you say Y here, all failed fork() attempts will be logged.
61579+ This could suggest a fork bomb, or someone attempting to overstep
61580+ their process limit. If the sysctl option is enabled, a sysctl option
61581+ with name "forkfail_logging" is created.
61582+
61583+config GRKERNSEC_TIME
61584+ bool "Time change logging"
61585+ default y if GRKERNSEC_CONFIG_AUTO
61586+ help
61587+ If you say Y here, any changes of the system clock will be logged.
61588+ If the sysctl option is enabled, a sysctl option with name
61589+ "timechange_logging" is created.
61590+
61591+config GRKERNSEC_PROC_IPADDR
61592+ bool "/proc/<pid>/ipaddr support"
61593+ default y if GRKERNSEC_CONFIG_AUTO
61594+ help
61595+ If you say Y here, a new entry will be added to each /proc/<pid>
61596+ directory that contains the IP address of the person using the task.
61597+ The IP is carried across local TCP and AF_UNIX stream sockets.
61598+ This information can be useful for IDS/IPSes to perform remote response
61599+ to a local attack. The entry is readable by only the owner of the
61600+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61601+ the RBAC system), and thus does not create privacy concerns.
61602+
61603+config GRKERNSEC_RWXMAP_LOG
61604+ bool 'Denied RWX mmap/mprotect logging'
61605+ default y if GRKERNSEC_CONFIG_AUTO
61606+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61607+ help
61608+ If you say Y here, calls to mmap() and mprotect() with explicit
61609+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61610+ denied by the PAX_MPROTECT feature. This feature will also
61611+ log other problematic scenarios that can occur when PAX_MPROTECT
61612+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61613+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61614+ is created.
61615+
61616+endmenu
61617+
61618+menu "Executable Protections"
61619+depends on GRKERNSEC
61620+
61621+config GRKERNSEC_DMESG
61622+ bool "Dmesg(8) restriction"
61623+ default y if GRKERNSEC_CONFIG_AUTO
61624+ help
61625+ If you say Y here, non-root users will not be able to use dmesg(8)
61626+ to view the contents of the kernel's circular log buffer.
61627+ The kernel's log buffer often contains kernel addresses and other
61628+ identifying information useful to an attacker in fingerprinting a
61629+ system for a targeted exploit.
61630+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61631+ created.
61632+
61633+config GRKERNSEC_HARDEN_PTRACE
61634+ bool "Deter ptrace-based process snooping"
61635+ default y if GRKERNSEC_CONFIG_AUTO
61636+ help
61637+ If you say Y here, TTY sniffers and other malicious monitoring
61638+ programs implemented through ptrace will be defeated. If you
61639+ have been using the RBAC system, this option has already been
61640+ enabled for several years for all users, with the ability to make
61641+ fine-grained exceptions.
61642+
61643+ This option only affects the ability of non-root users to ptrace
61644+ processes that are not a descendent of the ptracing process.
61645+ This means that strace ./binary and gdb ./binary will still work,
61646+ but attaching to arbitrary processes will not. If the sysctl
61647+ option is enabled, a sysctl option with name "harden_ptrace" is
61648+ created.
61649+
61650+config GRKERNSEC_PTRACE_READEXEC
61651+ bool "Require read access to ptrace sensitive binaries"
61652+ default y if GRKERNSEC_CONFIG_AUTO
61653+ help
61654+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61655+ binaries. This option is useful in environments that
61656+ remove the read bits (e.g. file mode 4711) from suid binaries to
61657+ prevent infoleaking of their contents. This option adds
61658+ consistency to the use of that file mode, as the binary could normally
61659+ be read out when run without privileges while ptracing.
61660+
61661+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61662+ is created.
61663+
61664+config GRKERNSEC_SETXID
61665+ bool "Enforce consistent multithreaded privileges"
61666+ default y if GRKERNSEC_CONFIG_AUTO
61667+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61668+ help
61669+ If you say Y here, a change from a root uid to a non-root uid
61670+ in a multithreaded application will cause the resulting uids,
61671+ gids, supplementary groups, and capabilities in that thread
61672+ to be propagated to the other threads of the process. In most
61673+ cases this is unnecessary, as glibc will emulate this behavior
61674+ on behalf of the application. Other libcs do not act in the
61675+ same way, allowing the other threads of the process to continue
61676+ running with root privileges. If the sysctl option is enabled,
61677+ a sysctl option with name "consistent_setxid" is created.
61678+
61679+config GRKERNSEC_TPE
61680+ bool "Trusted Path Execution (TPE)"
61681+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61682+ help
61683+ If you say Y here, you will be able to choose a gid to add to the
61684+ supplementary groups of users you want to mark as "untrusted."
61685+ These users will not be able to execute any files that are not in
61686+ root-owned directories writable only by root. If the sysctl option
61687+ is enabled, a sysctl option with name "tpe" is created.
61688+
61689+config GRKERNSEC_TPE_ALL
61690+ bool "Partially restrict all non-root users"
61691+ depends on GRKERNSEC_TPE
61692+ help
61693+ If you say Y here, all non-root users will be covered under
61694+ a weaker TPE restriction. This is separate from, and in addition to,
61695+ the main TPE options that you have selected elsewhere. Thus, if a
61696+ "trusted" GID is chosen, this restriction applies to even that GID.
61697+ Under this restriction, all non-root users will only be allowed to
61698+ execute files in directories they own that are not group or
61699+ world-writable, or in directories owned by root and writable only by
61700+ root. If the sysctl option is enabled, a sysctl option with name
61701+ "tpe_restrict_all" is created.
61702+
61703+config GRKERNSEC_TPE_INVERT
61704+ bool "Invert GID option"
61705+ depends on GRKERNSEC_TPE
61706+ help
61707+ If you say Y here, the group you specify in the TPE configuration will
61708+ decide what group TPE restrictions will be *disabled* for. This
61709+ option is useful if you want TPE restrictions to be applied to most
61710+ users on the system. If the sysctl option is enabled, a sysctl option
61711+ with name "tpe_invert" is created. Unlike other sysctl options, this
61712+ entry will default to on for backward-compatibility.
61713+
61714+config GRKERNSEC_TPE_GID
61715+ int
61716+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61717+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61718+
61719+config GRKERNSEC_TPE_UNTRUSTED_GID
61720+ int "GID for TPE-untrusted users"
61721+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61722+ default 1005
61723+ help
61724+ Setting this GID determines what group TPE restrictions will be
61725+ *enabled* for. If the sysctl option is enabled, a sysctl option
61726+ with name "tpe_gid" is created.
61727+
61728+config GRKERNSEC_TPE_TRUSTED_GID
61729+ int "GID for TPE-trusted users"
61730+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61731+ default 1005
61732+ help
61733+ Setting this GID determines what group TPE restrictions will be
61734+ *disabled* for. If the sysctl option is enabled, a sysctl option
61735+ with name "tpe_gid" is created.
61736+
61737+endmenu
61738+menu "Network Protections"
61739+depends on GRKERNSEC
61740+
61741+config GRKERNSEC_RANDNET
61742+ bool "Larger entropy pools"
61743+ default y if GRKERNSEC_CONFIG_AUTO
61744+ help
61745+ If you say Y here, the entropy pools used for many features of Linux
61746+ and grsecurity will be doubled in size. Since several grsecurity
61747+ features use additional randomness, it is recommended that you say Y
61748+ here. Saying Y here has a similar effect as modifying
61749+ /proc/sys/kernel/random/poolsize.
61750+
61751+config GRKERNSEC_BLACKHOLE
61752+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61753+ default y if GRKERNSEC_CONFIG_AUTO
61754+ depends on NET
61755+ help
61756+ If you say Y here, neither TCP resets nor ICMP
61757+ destination-unreachable packets will be sent in response to packets
61758+ sent to ports for which no associated listening process exists.
61759+ This feature supports both IPV4 and IPV6 and exempts the
61760+ loopback interface from blackholing. Enabling this feature
61761+ makes a host more resilient to DoS attacks and reduces network
61762+ visibility against scanners.
61763+
61764+ The blackhole feature as-implemented is equivalent to the FreeBSD
61765+ blackhole feature, as it prevents RST responses to all packets, not
61766+ just SYNs. Under most application behavior this causes no
61767+ problems, but applications (like haproxy) may not close certain
61768+ connections in a way that cleanly terminates them on the remote
61769+ end, leaving the remote host in LAST_ACK state. Because of this
61770+ side-effect and to prevent intentional LAST_ACK DoSes, this
61771+ feature also adds automatic mitigation against such attacks.
61772+ The mitigation drastically reduces the amount of time a socket
61773+ can spend in LAST_ACK state. If you're using haproxy and not
61774+ all servers it connects to have this option enabled, consider
61775+ disabling this feature on the haproxy host.
61776+
61777+ If the sysctl option is enabled, two sysctl options with names
61778+ "ip_blackhole" and "lastack_retries" will be created.
61779+ While "ip_blackhole" takes the standard zero/non-zero on/off
61780+ toggle, "lastack_retries" uses the same kinds of values as
61781+ "tcp_retries1" and "tcp_retries2". The default value of 4
61782+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61783+ state.
61784+
61785+config GRKERNSEC_NO_SIMULT_CONNECT
61786+ bool "Disable TCP Simultaneous Connect"
61787+ default y if GRKERNSEC_CONFIG_AUTO
61788+ depends on NET
61789+ help
61790+ If you say Y here, a feature by Willy Tarreau will be enabled that
61791+ removes a weakness in Linux's strict implementation of TCP that
61792+ allows two clients to connect to each other without either entering
61793+ a listening state. The weakness allows an attacker to easily prevent
61794+ a client from connecting to a known server provided the source port
61795+ for the connection is guessed correctly.
61796+
61797+ As the weakness could be used to prevent an antivirus or IPS from
61798+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61799+ it should be eliminated by enabling this option. Though Linux is
61800+ one of few operating systems supporting simultaneous connect, it
61801+ has no legitimate use in practice and is rarely supported by firewalls.
61802+
61803+config GRKERNSEC_SOCKET
61804+ bool "Socket restrictions"
61805+ depends on NET
61806+ help
61807+ If you say Y here, you will be able to choose from several options.
61808+ If you assign a GID on your system and add it to the supplementary
61809+ groups of users you want to restrict socket access to, this patch
61810+ will perform up to three things, based on the option(s) you choose.
61811+
61812+config GRKERNSEC_SOCKET_ALL
61813+ bool "Deny any sockets to group"
61814+ depends on GRKERNSEC_SOCKET
61815+ help
61816+ If you say Y here, you will be able to choose a GID of whose users will
61817+ be unable to connect to other hosts from your machine or run server
61818+ applications from your machine. If the sysctl option is enabled, a
61819+ sysctl option with name "socket_all" is created.
61820+
61821+config GRKERNSEC_SOCKET_ALL_GID
61822+ int "GID to deny all sockets for"
61823+ depends on GRKERNSEC_SOCKET_ALL
61824+ default 1004
61825+ help
61826+ Here you can choose the GID to disable socket access for. Remember to
61827+ add the users you want socket access disabled for to the GID
61828+ specified here. If the sysctl option is enabled, a sysctl option
61829+ with name "socket_all_gid" is created.
61830+
61831+config GRKERNSEC_SOCKET_CLIENT
61832+ bool "Deny client sockets to group"
61833+ depends on GRKERNSEC_SOCKET
61834+ help
61835+ If you say Y here, you will be able to choose a GID of whose users will
61836+ be unable to connect to other hosts from your machine, but will be
61837+ able to run servers. If this option is enabled, all users in the group
61838+ you specify will have to use passive mode when initiating ftp transfers
61839+ from the shell on your machine. If the sysctl option is enabled, a
61840+ sysctl option with name "socket_client" is created.
61841+
61842+config GRKERNSEC_SOCKET_CLIENT_GID
61843+ int "GID to deny client sockets for"
61844+ depends on GRKERNSEC_SOCKET_CLIENT
61845+ default 1003
61846+ help
61847+ Here you can choose the GID to disable client socket access for.
61848+ Remember to add the users you want client socket access disabled for to
61849+ the GID specified here. If the sysctl option is enabled, a sysctl
61850+ option with name "socket_client_gid" is created.
61851+
61852+config GRKERNSEC_SOCKET_SERVER
61853+ bool "Deny server sockets to group"
61854+ depends on GRKERNSEC_SOCKET
61855+ help
61856+ If you say Y here, you will be able to choose a GID of whose users will
61857+ be unable to run server applications from your machine. If the sysctl
61858+ option is enabled, a sysctl option with name "socket_server" is created.
61859+
61860+config GRKERNSEC_SOCKET_SERVER_GID
61861+ int "GID to deny server sockets for"
61862+ depends on GRKERNSEC_SOCKET_SERVER
61863+ default 1002
61864+ help
61865+ Here you can choose the GID to disable server socket access for.
61866+ Remember to add the users you want server socket access disabled for to
61867+ the GID specified here. If the sysctl option is enabled, a sysctl
61868+ option with name "socket_server_gid" is created.
61869+
61870+endmenu
61871+
61872+menu "Physical Protections"
61873+depends on GRKERNSEC
61874+
61875+config GRKERNSEC_DENYUSB
61876+ bool "Deny new USB connections after toggle"
61877+ default y if GRKERNSEC_CONFIG_AUTO
61878+ depends on SYSCTL && USB_SUPPORT
61879+ help
61880+ If you say Y here, a new sysctl option with name "deny_new_usb"
61881+ will be created. Setting its value to 1 will prevent any new
61882+ USB devices from being recognized by the OS. Any attempted USB
61883+ device insertion will be logged. This option is intended to be
61884+ used against custom USB devices designed to exploit vulnerabilities
61885+ in various USB device drivers.
61886+
61887+ For greatest effectiveness, this sysctl should be set after any
61888+ relevant init scripts. This option is safe to enable in distros
61889+ as each user can choose whether or not to toggle the sysctl.
61890+
61891+config GRKERNSEC_DENYUSB_FORCE
61892+ bool "Reject all USB devices not connected at boot"
61893+ select USB
61894+ depends on GRKERNSEC_DENYUSB
61895+ help
61896+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
61897+ that doesn't involve a sysctl entry. This option should only be
61898+ enabled if you're sure you want to deny all new USB connections
61899+ at runtime and don't want to modify init scripts. This should not
61900+ be enabled by distros. It forces the core USB code to be built
61901+ into the kernel image so that all devices connected at boot time
61902+ can be recognized and new USB device connections can be prevented
61903+ prior to init running.
61904+
61905+endmenu
61906+
61907+menu "Sysctl Support"
61908+depends on GRKERNSEC && SYSCTL
61909+
61910+config GRKERNSEC_SYSCTL
61911+ bool "Sysctl support"
61912+ default y if GRKERNSEC_CONFIG_AUTO
61913+ help
61914+ If you say Y here, you will be able to change the options that
61915+ grsecurity runs with at bootup, without having to recompile your
61916+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
61917+ to enable (1) or disable (0) various features. All the sysctl entries
61918+ are mutable until the "grsec_lock" entry is set to a non-zero value.
61919+ All features enabled in the kernel configuration are disabled at boot
61920+ if you do not say Y to the "Turn on features by default" option.
61921+ All options should be set at startup, and the grsec_lock entry should
61922+ be set to a non-zero value after all the options are set.
61923+ *THIS IS EXTREMELY IMPORTANT*
61924+
61925+config GRKERNSEC_SYSCTL_DISTRO
61926+ bool "Extra sysctl support for distro makers (READ HELP)"
61927+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
61928+ help
61929+ If you say Y here, additional sysctl options will be created
61930+ for features that affect processes running as root. Therefore,
61931+ it is critical when using this option that the grsec_lock entry be
61932+ enabled after boot. Only distros with prebuilt kernel packages
61933+ with this option enabled that can ensure grsec_lock is enabled
61934+ after boot should use this option.
61935+ *Failure to set grsec_lock after boot makes all grsec features
61936+ this option covers useless*
61937+
61938+ Currently this option creates the following sysctl entries:
61939+ "Disable Privileged I/O": "disable_priv_io"
61940+
61941+config GRKERNSEC_SYSCTL_ON
61942+ bool "Turn on features by default"
61943+ default y if GRKERNSEC_CONFIG_AUTO
61944+ depends on GRKERNSEC_SYSCTL
61945+ help
61946+ If you say Y here, instead of having all features enabled in the
61947+ kernel configuration disabled at boot time, the features will be
61948+ enabled at boot time. It is recommended you say Y here unless
61949+ there is some reason you would want all sysctl-tunable features to
61950+ be disabled by default. As mentioned elsewhere, it is important
61951+ to enable the grsec_lock entry once you have finished modifying
61952+ the sysctl entries.
61953+
61954+endmenu
61955+menu "Logging Options"
61956+depends on GRKERNSEC
61957+
61958+config GRKERNSEC_FLOODTIME
61959+ int "Seconds in between log messages (minimum)"
61960+ default 10
61961+ help
61962+ This option allows you to enforce the number of seconds between
61963+ grsecurity log messages. The default should be suitable for most
61964+ people, however, if you choose to change it, choose a value small enough
61965+ to allow informative logs to be produced, but large enough to
61966+ prevent flooding.
61967+
61968+config GRKERNSEC_FLOODBURST
61969+ int "Number of messages in a burst (maximum)"
61970+ default 6
61971+ help
61972+ This option allows you to choose the maximum number of messages allowed
61973+ within the flood time interval you chose in a separate option. The
61974+ default should be suitable for most people, however if you find that
61975+ many of your logs are being interpreted as flooding, you may want to
61976+ raise this value.
61977+
61978+endmenu
61979diff --git a/grsecurity/Makefile b/grsecurity/Makefile
61980new file mode 100644
61981index 0000000..b0b77d5
61982--- /dev/null
61983+++ b/grsecurity/Makefile
61984@@ -0,0 +1,43 @@
61985+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
61986+# during 2001-2009 it has been completely redesigned by Brad Spengler
61987+# into an RBAC system
61988+#
61989+# All code in this directory and various hooks inserted throughout the kernel
61990+# are copyright Brad Spengler - Open Source Security, Inc., and released
61991+# under the GPL v2 or higher
61992+
61993+KBUILD_CFLAGS += -Werror
61994+
61995+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
61996+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
61997+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
61998+ grsec_usb.o
61999+
62000+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62001+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62002+ gracl_learn.o grsec_log.o
62003+ifdef CONFIG_COMPAT
62004+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62005+endif
62006+
62007+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62008+
62009+ifdef CONFIG_NET
62010+obj-y += grsec_sock.o
62011+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62012+endif
62013+
62014+ifndef CONFIG_GRKERNSEC
62015+obj-y += grsec_disabled.o
62016+endif
62017+
62018+ifdef CONFIG_GRKERNSEC_HIDESYM
62019+extra-y := grsec_hidesym.o
62020+$(obj)/grsec_hidesym.o:
62021+ @-chmod -f 500 /boot
62022+ @-chmod -f 500 /lib/modules
62023+ @-chmod -f 500 /lib64/modules
62024+ @-chmod -f 500 /lib32/modules
62025+ @-chmod -f 700 .
62026+ @echo ' grsec: protected kernel image paths'
62027+endif
62028diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62029new file mode 100644
62030index 0000000..c0793fd
62031--- /dev/null
62032+++ b/grsecurity/gracl.c
62033@@ -0,0 +1,4178 @@
62034+#include <linux/kernel.h>
62035+#include <linux/module.h>
62036+#include <linux/sched.h>
62037+#include <linux/mm.h>
62038+#include <linux/file.h>
62039+#include <linux/fs.h>
62040+#include <linux/namei.h>
62041+#include <linux/mount.h>
62042+#include <linux/tty.h>
62043+#include <linux/proc_fs.h>
62044+#include <linux/lglock.h>
62045+#include <linux/slab.h>
62046+#include <linux/vmalloc.h>
62047+#include <linux/types.h>
62048+#include <linux/sysctl.h>
62049+#include <linux/netdevice.h>
62050+#include <linux/ptrace.h>
62051+#include <linux/gracl.h>
62052+#include <linux/gralloc.h>
62053+#include <linux/security.h>
62054+#include <linux/grinternal.h>
62055+#include <linux/pid_namespace.h>
62056+#include <linux/stop_machine.h>
62057+#include <linux/fdtable.h>
62058+#include <linux/percpu.h>
62059+#include <linux/lglock.h>
62060+#include <linux/hugetlb.h>
62061+#include <linux/posix-timers.h>
62062+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62063+#include <linux/magic.h>
62064+#include <linux/pagemap.h>
62065+#include "../fs/btrfs/async-thread.h"
62066+#include "../fs/btrfs/ctree.h"
62067+#include "../fs/btrfs/btrfs_inode.h"
62068+#endif
62069+#include "../fs/mount.h"
62070+
62071+#include <asm/uaccess.h>
62072+#include <asm/errno.h>
62073+#include <asm/mman.h>
62074+
62075+extern struct lglock vfsmount_lock;
62076+
62077+static struct acl_role_db acl_role_set;
62078+static struct name_db name_set;
62079+static struct inodev_db inodev_set;
62080+
62081+/* for keeping track of userspace pointers used for subjects, so we
62082+ can share references in the kernel as well
62083+*/
62084+
62085+static struct path real_root;
62086+
62087+static struct acl_subj_map_db subj_map_set;
62088+
62089+static struct acl_role_label *default_role;
62090+
62091+static struct acl_role_label *role_list;
62092+
62093+static u16 acl_sp_role_value;
62094+
62095+extern char *gr_shared_page[4];
62096+static DEFINE_MUTEX(gr_dev_mutex);
62097+DEFINE_RWLOCK(gr_inode_lock);
62098+
62099+struct gr_arg *gr_usermode;
62100+
62101+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62102+
62103+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62104+extern void gr_clear_learn_entries(void);
62105+
62106+unsigned char *gr_system_salt;
62107+unsigned char *gr_system_sum;
62108+
62109+static struct sprole_pw **acl_special_roles = NULL;
62110+static __u16 num_sprole_pws = 0;
62111+
62112+static struct acl_role_label *kernel_role = NULL;
62113+
62114+static unsigned int gr_auth_attempts = 0;
62115+static unsigned long gr_auth_expires = 0UL;
62116+
62117+#ifdef CONFIG_NET
62118+extern struct vfsmount *sock_mnt;
62119+#endif
62120+
62121+extern struct vfsmount *pipe_mnt;
62122+extern struct vfsmount *shm_mnt;
62123+
62124+#ifdef CONFIG_HUGETLBFS
62125+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62126+#endif
62127+
62128+static struct acl_object_label *fakefs_obj_rw;
62129+static struct acl_object_label *fakefs_obj_rwx;
62130+
62131+extern int gr_init_uidset(void);
62132+extern void gr_free_uidset(void);
62133+extern void gr_remove_uid(uid_t uid);
62134+extern int gr_find_uid(uid_t uid);
62135+
62136+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62137+{
62138+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62139+ return -EFAULT;
62140+
62141+ return 0;
62142+}
62143+
62144+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62145+{
62146+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62147+ return -EFAULT;
62148+
62149+ return 0;
62150+}
62151+
62152+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62153+{
62154+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62155+ return -EFAULT;
62156+
62157+ return 0;
62158+}
62159+
62160+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62161+{
62162+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62163+ return -EFAULT;
62164+
62165+ return 0;
62166+}
62167+
62168+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62169+{
62170+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62171+ return -EFAULT;
62172+
62173+ return 0;
62174+}
62175+
62176+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62177+{
62178+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62179+ return -EFAULT;
62180+
62181+ return 0;
62182+}
62183+
62184+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62185+{
62186+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62187+ return -EFAULT;
62188+
62189+ return 0;
62190+}
62191+
62192+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62193+{
62194+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62195+ return -EFAULT;
62196+
62197+ return 0;
62198+}
62199+
62200+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62201+{
62202+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62203+ return -EFAULT;
62204+
62205+ return 0;
62206+}
62207+
62208+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62209+{
62210+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62211+ return -EFAULT;
62212+
62213+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62214+ return -EINVAL;
62215+
62216+ return 0;
62217+}
62218+
62219+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62220+{
62221+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62222+ return -EFAULT;
62223+
62224+ return 0;
62225+}
62226+
62227+static size_t get_gr_arg_wrapper_size_normal(void)
62228+{
62229+ return sizeof(struct gr_arg_wrapper);
62230+}
62231+
62232+#ifdef CONFIG_COMPAT
62233+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62234+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62235+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62236+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62237+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62238+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62239+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62240+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62241+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62242+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62243+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62244+extern size_t get_gr_arg_wrapper_size_compat(void);
62245+
62246+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62247+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62248+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62249+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62250+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62251+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62252+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62253+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62254+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62255+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62256+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62257+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62258+
62259+#else
62260+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62261+#define copy_gr_arg copy_gr_arg_normal
62262+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62263+#define copy_acl_object_label copy_acl_object_label_normal
62264+#define copy_acl_subject_label copy_acl_subject_label_normal
62265+#define copy_acl_role_label copy_acl_role_label_normal
62266+#define copy_acl_ip_label copy_acl_ip_label_normal
62267+#define copy_pointer_from_array copy_pointer_from_array_normal
62268+#define copy_sprole_pw copy_sprole_pw_normal
62269+#define copy_role_transition copy_role_transition_normal
62270+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62271+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62272+#endif
62273+
62274+__inline__ int
62275+gr_acl_is_enabled(void)
62276+{
62277+ return (gr_status & GR_READY);
62278+}
62279+
62280+static inline dev_t __get_dev(const struct dentry *dentry)
62281+{
62282+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62283+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62284+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62285+ else
62286+#endif
62287+ return dentry->d_sb->s_dev;
62288+}
62289+
62290+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62291+{
62292+ return __get_dev(dentry);
62293+}
62294+
62295+static char gr_task_roletype_to_char(struct task_struct *task)
62296+{
62297+ switch (task->role->roletype &
62298+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62299+ GR_ROLE_SPECIAL)) {
62300+ case GR_ROLE_DEFAULT:
62301+ return 'D';
62302+ case GR_ROLE_USER:
62303+ return 'U';
62304+ case GR_ROLE_GROUP:
62305+ return 'G';
62306+ case GR_ROLE_SPECIAL:
62307+ return 'S';
62308+ }
62309+
62310+ return 'X';
62311+}
62312+
62313+char gr_roletype_to_char(void)
62314+{
62315+ return gr_task_roletype_to_char(current);
62316+}
62317+
62318+__inline__ int
62319+gr_acl_tpe_check(void)
62320+{
62321+ if (unlikely(!(gr_status & GR_READY)))
62322+ return 0;
62323+ if (current->role->roletype & GR_ROLE_TPE)
62324+ return 1;
62325+ else
62326+ return 0;
62327+}
62328+
62329+int
62330+gr_handle_rawio(const struct inode *inode)
62331+{
62332+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62333+ if (inode && S_ISBLK(inode->i_mode) &&
62334+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62335+ !capable(CAP_SYS_RAWIO))
62336+ return 1;
62337+#endif
62338+ return 0;
62339+}
62340+
62341+static int
62342+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62343+{
62344+ if (likely(lena != lenb))
62345+ return 0;
62346+
62347+ return !memcmp(a, b, lena);
62348+}
62349+
62350+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62351+{
62352+ *buflen -= namelen;
62353+ if (*buflen < 0)
62354+ return -ENAMETOOLONG;
62355+ *buffer -= namelen;
62356+ memcpy(*buffer, str, namelen);
62357+ return 0;
62358+}
62359+
62360+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62361+{
62362+ return prepend(buffer, buflen, name->name, name->len);
62363+}
62364+
62365+static int prepend_path(const struct path *path, struct path *root,
62366+ char **buffer, int *buflen)
62367+{
62368+ struct dentry *dentry = path->dentry;
62369+ struct vfsmount *vfsmnt = path->mnt;
62370+ struct mount *mnt = real_mount(vfsmnt);
62371+ bool slash = false;
62372+ int error = 0;
62373+
62374+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62375+ struct dentry * parent;
62376+
62377+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62378+ /* Global root? */
62379+ if (!mnt_has_parent(mnt)) {
62380+ goto out;
62381+ }
62382+ dentry = mnt->mnt_mountpoint;
62383+ mnt = mnt->mnt_parent;
62384+ vfsmnt = &mnt->mnt;
62385+ continue;
62386+ }
62387+ parent = dentry->d_parent;
62388+ prefetch(parent);
62389+ spin_lock(&dentry->d_lock);
62390+ error = prepend_name(buffer, buflen, &dentry->d_name);
62391+ spin_unlock(&dentry->d_lock);
62392+ if (!error)
62393+ error = prepend(buffer, buflen, "/", 1);
62394+ if (error)
62395+ break;
62396+
62397+ slash = true;
62398+ dentry = parent;
62399+ }
62400+
62401+out:
62402+ if (!error && !slash)
62403+ error = prepend(buffer, buflen, "/", 1);
62404+
62405+ return error;
62406+}
62407+
62408+/* this must be called with vfsmount_lock and rename_lock held */
62409+
62410+static char *__our_d_path(const struct path *path, struct path *root,
62411+ char *buf, int buflen)
62412+{
62413+ char *res = buf + buflen;
62414+ int error;
62415+
62416+ prepend(&res, &buflen, "\0", 1);
62417+ error = prepend_path(path, root, &res, &buflen);
62418+ if (error)
62419+ return ERR_PTR(error);
62420+
62421+ return res;
62422+}
62423+
62424+static char *
62425+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62426+{
62427+ char *retval;
62428+
62429+ retval = __our_d_path(path, root, buf, buflen);
62430+ if (unlikely(IS_ERR(retval)))
62431+ retval = strcpy(buf, "<path too long>");
62432+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62433+ retval[1] = '\0';
62434+
62435+ return retval;
62436+}
62437+
62438+static char *
62439+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62440+ char *buf, int buflen)
62441+{
62442+ struct path path;
62443+ char *res;
62444+
62445+ path.dentry = (struct dentry *)dentry;
62446+ path.mnt = (struct vfsmount *)vfsmnt;
62447+
62448+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62449+ by the RBAC system */
62450+ res = gen_full_path(&path, &real_root, buf, buflen);
62451+
62452+ return res;
62453+}
62454+
62455+static char *
62456+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62457+ char *buf, int buflen)
62458+{
62459+ char *res;
62460+ struct path path;
62461+ struct path root;
62462+ struct task_struct *reaper = init_pid_ns.child_reaper;
62463+
62464+ path.dentry = (struct dentry *)dentry;
62465+ path.mnt = (struct vfsmount *)vfsmnt;
62466+
62467+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62468+ get_fs_root(reaper->fs, &root);
62469+
62470+ br_read_lock(&vfsmount_lock);
62471+ write_seqlock(&rename_lock);
62472+ res = gen_full_path(&path, &root, buf, buflen);
62473+ write_sequnlock(&rename_lock);
62474+ br_read_unlock(&vfsmount_lock);
62475+
62476+ path_put(&root);
62477+ return res;
62478+}
62479+
62480+static char *
62481+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62482+{
62483+ char *ret;
62484+ br_read_lock(&vfsmount_lock);
62485+ write_seqlock(&rename_lock);
62486+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62487+ PAGE_SIZE);
62488+ write_sequnlock(&rename_lock);
62489+ br_read_unlock(&vfsmount_lock);
62490+ return ret;
62491+}
62492+
62493+static char *
62494+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62495+{
62496+ char *ret;
62497+ char *buf;
62498+ int buflen;
62499+
62500+ br_read_lock(&vfsmount_lock);
62501+ write_seqlock(&rename_lock);
62502+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62503+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62504+ buflen = (int)(ret - buf);
62505+ if (buflen >= 5)
62506+ prepend(&ret, &buflen, "/proc", 5);
62507+ else
62508+ ret = strcpy(buf, "<path too long>");
62509+ write_sequnlock(&rename_lock);
62510+ br_read_unlock(&vfsmount_lock);
62511+ return ret;
62512+}
62513+
62514+char *
62515+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62516+{
62517+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62518+ PAGE_SIZE);
62519+}
62520+
62521+char *
62522+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62523+{
62524+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62525+ PAGE_SIZE);
62526+}
62527+
62528+char *
62529+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62530+{
62531+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62532+ PAGE_SIZE);
62533+}
62534+
62535+char *
62536+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62537+{
62538+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62539+ PAGE_SIZE);
62540+}
62541+
62542+char *
62543+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62544+{
62545+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62546+ PAGE_SIZE);
62547+}
62548+
62549+__inline__ __u32
62550+to_gr_audit(const __u32 reqmode)
62551+{
62552+ /* masks off auditable permission flags, then shifts them to create
62553+ auditing flags, and adds the special case of append auditing if
62554+ we're requesting write */
62555+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62556+}
62557+
62558+struct acl_subject_label *
62559+lookup_subject_map(const struct acl_subject_label *userp)
62560+{
62561+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62562+ struct subject_map *match;
62563+
62564+ match = subj_map_set.s_hash[index];
62565+
62566+ while (match && match->user != userp)
62567+ match = match->next;
62568+
62569+ if (match != NULL)
62570+ return match->kernel;
62571+ else
62572+ return NULL;
62573+}
62574+
62575+static void
62576+insert_subj_map_entry(struct subject_map *subjmap)
62577+{
62578+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62579+ struct subject_map **curr;
62580+
62581+ subjmap->prev = NULL;
62582+
62583+ curr = &subj_map_set.s_hash[index];
62584+ if (*curr != NULL)
62585+ (*curr)->prev = subjmap;
62586+
62587+ subjmap->next = *curr;
62588+ *curr = subjmap;
62589+
62590+ return;
62591+}
62592+
62593+static struct acl_role_label *
62594+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62595+ const gid_t gid)
62596+{
62597+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62598+ struct acl_role_label *match;
62599+ struct role_allowed_ip *ipp;
62600+ unsigned int x;
62601+ u32 curr_ip = task->signal->curr_ip;
62602+
62603+ task->signal->saved_ip = curr_ip;
62604+
62605+ match = acl_role_set.r_hash[index];
62606+
62607+ while (match) {
62608+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62609+ for (x = 0; x < match->domain_child_num; x++) {
62610+ if (match->domain_children[x] == uid)
62611+ goto found;
62612+ }
62613+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62614+ break;
62615+ match = match->next;
62616+ }
62617+found:
62618+ if (match == NULL) {
62619+ try_group:
62620+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62621+ match = acl_role_set.r_hash[index];
62622+
62623+ while (match) {
62624+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62625+ for (x = 0; x < match->domain_child_num; x++) {
62626+ if (match->domain_children[x] == gid)
62627+ goto found2;
62628+ }
62629+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62630+ break;
62631+ match = match->next;
62632+ }
62633+found2:
62634+ if (match == NULL)
62635+ match = default_role;
62636+ if (match->allowed_ips == NULL)
62637+ return match;
62638+ else {
62639+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62640+ if (likely
62641+ ((ntohl(curr_ip) & ipp->netmask) ==
62642+ (ntohl(ipp->addr) & ipp->netmask)))
62643+ return match;
62644+ }
62645+ match = default_role;
62646+ }
62647+ } else if (match->allowed_ips == NULL) {
62648+ return match;
62649+ } else {
62650+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62651+ if (likely
62652+ ((ntohl(curr_ip) & ipp->netmask) ==
62653+ (ntohl(ipp->addr) & ipp->netmask)))
62654+ return match;
62655+ }
62656+ goto try_group;
62657+ }
62658+
62659+ return match;
62660+}
62661+
62662+struct acl_subject_label *
62663+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62664+ const struct acl_role_label *role)
62665+{
62666+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62667+ struct acl_subject_label *match;
62668+
62669+ match = role->subj_hash[index];
62670+
62671+ while (match && (match->inode != ino || match->device != dev ||
62672+ (match->mode & GR_DELETED))) {
62673+ match = match->next;
62674+ }
62675+
62676+ if (match && !(match->mode & GR_DELETED))
62677+ return match;
62678+ else
62679+ return NULL;
62680+}
62681+
62682+struct acl_subject_label *
62683+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62684+ const struct acl_role_label *role)
62685+{
62686+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62687+ struct acl_subject_label *match;
62688+
62689+ match = role->subj_hash[index];
62690+
62691+ while (match && (match->inode != ino || match->device != dev ||
62692+ !(match->mode & GR_DELETED))) {
62693+ match = match->next;
62694+ }
62695+
62696+ if (match && (match->mode & GR_DELETED))
62697+ return match;
62698+ else
62699+ return NULL;
62700+}
62701+
62702+static struct acl_object_label *
62703+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62704+ const struct acl_subject_label *subj)
62705+{
62706+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62707+ struct acl_object_label *match;
62708+
62709+ match = subj->obj_hash[index];
62710+
62711+ while (match && (match->inode != ino || match->device != dev ||
62712+ (match->mode & GR_DELETED))) {
62713+ match = match->next;
62714+ }
62715+
62716+ if (match && !(match->mode & GR_DELETED))
62717+ return match;
62718+ else
62719+ return NULL;
62720+}
62721+
62722+static struct acl_object_label *
62723+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62724+ const struct acl_subject_label *subj)
62725+{
62726+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62727+ struct acl_object_label *match;
62728+
62729+ match = subj->obj_hash[index];
62730+
62731+ while (match && (match->inode != ino || match->device != dev ||
62732+ !(match->mode & GR_DELETED))) {
62733+ match = match->next;
62734+ }
62735+
62736+ if (match && (match->mode & GR_DELETED))
62737+ return match;
62738+
62739+ match = subj->obj_hash[index];
62740+
62741+ while (match && (match->inode != ino || match->device != dev ||
62742+ (match->mode & GR_DELETED))) {
62743+ match = match->next;
62744+ }
62745+
62746+ if (match && !(match->mode & GR_DELETED))
62747+ return match;
62748+ else
62749+ return NULL;
62750+}
62751+
62752+static struct name_entry *
62753+lookup_name_entry(const char *name)
62754+{
62755+ unsigned int len = strlen(name);
62756+ unsigned int key = full_name_hash(name, len);
62757+ unsigned int index = key % name_set.n_size;
62758+ struct name_entry *match;
62759+
62760+ match = name_set.n_hash[index];
62761+
62762+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62763+ match = match->next;
62764+
62765+ return match;
62766+}
62767+
62768+static struct name_entry *
62769+lookup_name_entry_create(const char *name)
62770+{
62771+ unsigned int len = strlen(name);
62772+ unsigned int key = full_name_hash(name, len);
62773+ unsigned int index = key % name_set.n_size;
62774+ struct name_entry *match;
62775+
62776+ match = name_set.n_hash[index];
62777+
62778+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62779+ !match->deleted))
62780+ match = match->next;
62781+
62782+ if (match && match->deleted)
62783+ return match;
62784+
62785+ match = name_set.n_hash[index];
62786+
62787+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62788+ match->deleted))
62789+ match = match->next;
62790+
62791+ if (match && !match->deleted)
62792+ return match;
62793+ else
62794+ return NULL;
62795+}
62796+
62797+static struct inodev_entry *
62798+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62799+{
62800+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62801+ struct inodev_entry *match;
62802+
62803+ match = inodev_set.i_hash[index];
62804+
62805+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62806+ match = match->next;
62807+
62808+ return match;
62809+}
62810+
62811+static void
62812+insert_inodev_entry(struct inodev_entry *entry)
62813+{
62814+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62815+ inodev_set.i_size);
62816+ struct inodev_entry **curr;
62817+
62818+ entry->prev = NULL;
62819+
62820+ curr = &inodev_set.i_hash[index];
62821+ if (*curr != NULL)
62822+ (*curr)->prev = entry;
62823+
62824+ entry->next = *curr;
62825+ *curr = entry;
62826+
62827+ return;
62828+}
62829+
62830+static void
62831+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62832+{
62833+ unsigned int index =
62834+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62835+ struct acl_role_label **curr;
62836+ struct acl_role_label *tmp, *tmp2;
62837+
62838+ curr = &acl_role_set.r_hash[index];
62839+
62840+ /* simple case, slot is empty, just set it to our role */
62841+ if (*curr == NULL) {
62842+ *curr = role;
62843+ } else {
62844+ /* example:
62845+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62846+ 2 -> 3
62847+ */
62848+ /* first check to see if we can already be reached via this slot */
62849+ tmp = *curr;
62850+ while (tmp && tmp != role)
62851+ tmp = tmp->next;
62852+ if (tmp == role) {
62853+ /* we don't need to add ourselves to this slot's chain */
62854+ return;
62855+ }
62856+ /* we need to add ourselves to this chain, two cases */
62857+ if (role->next == NULL) {
62858+ /* simple case, append the current chain to our role */
62859+ role->next = *curr;
62860+ *curr = role;
62861+ } else {
62862+ /* 1 -> 2 -> 3 -> 4
62863+ 2 -> 3 -> 4
62864+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62865+ */
62866+ /* trickier case: walk our role's chain until we find
62867+ the role for the start of the current slot's chain */
62868+ tmp = role;
62869+ tmp2 = *curr;
62870+ while (tmp->next && tmp->next != tmp2)
62871+ tmp = tmp->next;
62872+ if (tmp->next == tmp2) {
62873+ /* from example above, we found 3, so just
62874+ replace this slot's chain with ours */
62875+ *curr = role;
62876+ } else {
62877+ /* we didn't find a subset of our role's chain
62878+ in the current slot's chain, so append their
62879+ chain to ours, and set us as the first role in
62880+ the slot's chain
62881+
62882+ we could fold this case with the case above,
62883+ but making it explicit for clarity
62884+ */
62885+ tmp->next = tmp2;
62886+ *curr = role;
62887+ }
62888+ }
62889+ }
62890+
62891+ return;
62892+}
62893+
62894+static void
62895+insert_acl_role_label(struct acl_role_label *role)
62896+{
62897+ int i;
62898+
62899+ if (role_list == NULL) {
62900+ role_list = role;
62901+ role->prev = NULL;
62902+ } else {
62903+ role->prev = role_list;
62904+ role_list = role;
62905+ }
62906+
62907+ /* used for hash chains */
62908+ role->next = NULL;
62909+
62910+ if (role->roletype & GR_ROLE_DOMAIN) {
62911+ for (i = 0; i < role->domain_child_num; i++)
62912+ __insert_acl_role_label(role, role->domain_children[i]);
62913+ } else
62914+ __insert_acl_role_label(role, role->uidgid);
62915+}
62916+
62917+static int
62918+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
62919+{
62920+ struct name_entry **curr, *nentry;
62921+ struct inodev_entry *ientry;
62922+ unsigned int len = strlen(name);
62923+ unsigned int key = full_name_hash(name, len);
62924+ unsigned int index = key % name_set.n_size;
62925+
62926+ curr = &name_set.n_hash[index];
62927+
62928+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
62929+ curr = &((*curr)->next);
62930+
62931+ if (*curr != NULL)
62932+ return 1;
62933+
62934+ nentry = acl_alloc(sizeof (struct name_entry));
62935+ if (nentry == NULL)
62936+ return 0;
62937+ ientry = acl_alloc(sizeof (struct inodev_entry));
62938+ if (ientry == NULL)
62939+ return 0;
62940+ ientry->nentry = nentry;
62941+
62942+ nentry->key = key;
62943+ nentry->name = name;
62944+ nentry->inode = inode;
62945+ nentry->device = device;
62946+ nentry->len = len;
62947+ nentry->deleted = deleted;
62948+
62949+ nentry->prev = NULL;
62950+ curr = &name_set.n_hash[index];
62951+ if (*curr != NULL)
62952+ (*curr)->prev = nentry;
62953+ nentry->next = *curr;
62954+ *curr = nentry;
62955+
62956+ /* insert us into the table searchable by inode/dev */
62957+ insert_inodev_entry(ientry);
62958+
62959+ return 1;
62960+}
62961+
62962+static void
62963+insert_acl_obj_label(struct acl_object_label *obj,
62964+ struct acl_subject_label *subj)
62965+{
62966+ unsigned int index =
62967+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
62968+ struct acl_object_label **curr;
62969+
62970+
62971+ obj->prev = NULL;
62972+
62973+ curr = &subj->obj_hash[index];
62974+ if (*curr != NULL)
62975+ (*curr)->prev = obj;
62976+
62977+ obj->next = *curr;
62978+ *curr = obj;
62979+
62980+ return;
62981+}
62982+
62983+static void
62984+insert_acl_subj_label(struct acl_subject_label *obj,
62985+ struct acl_role_label *role)
62986+{
62987+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
62988+ struct acl_subject_label **curr;
62989+
62990+ obj->prev = NULL;
62991+
62992+ curr = &role->subj_hash[index];
62993+ if (*curr != NULL)
62994+ (*curr)->prev = obj;
62995+
62996+ obj->next = *curr;
62997+ *curr = obj;
62998+
62999+ return;
63000+}
63001+
63002+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63003+
63004+static void *
63005+create_table(__u32 * len, int elementsize)
63006+{
63007+ unsigned int table_sizes[] = {
63008+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63009+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63010+ 4194301, 8388593, 16777213, 33554393, 67108859
63011+ };
63012+ void *newtable = NULL;
63013+ unsigned int pwr = 0;
63014+
63015+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63016+ table_sizes[pwr] <= *len)
63017+ pwr++;
63018+
63019+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63020+ return newtable;
63021+
63022+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63023+ newtable =
63024+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63025+ else
63026+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63027+
63028+ *len = table_sizes[pwr];
63029+
63030+ return newtable;
63031+}
63032+
63033+static int
63034+init_variables(const struct gr_arg *arg)
63035+{
63036+ struct task_struct *reaper = init_pid_ns.child_reaper;
63037+ unsigned int stacksize;
63038+
63039+ subj_map_set.s_size = arg->role_db.num_subjects;
63040+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63041+ name_set.n_size = arg->role_db.num_objects;
63042+ inodev_set.i_size = arg->role_db.num_objects;
63043+
63044+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63045+ !name_set.n_size || !inodev_set.i_size)
63046+ return 1;
63047+
63048+ if (!gr_init_uidset())
63049+ return 1;
63050+
63051+ /* set up the stack that holds allocation info */
63052+
63053+ stacksize = arg->role_db.num_pointers + 5;
63054+
63055+ if (!acl_alloc_stack_init(stacksize))
63056+ return 1;
63057+
63058+ /* grab reference for the real root dentry and vfsmount */
63059+ get_fs_root(reaper->fs, &real_root);
63060+
63061+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63062+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63063+#endif
63064+
63065+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63066+ if (fakefs_obj_rw == NULL)
63067+ return 1;
63068+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63069+
63070+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63071+ if (fakefs_obj_rwx == NULL)
63072+ return 1;
63073+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63074+
63075+ subj_map_set.s_hash =
63076+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63077+ acl_role_set.r_hash =
63078+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63079+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63080+ inodev_set.i_hash =
63081+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63082+
63083+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63084+ !name_set.n_hash || !inodev_set.i_hash)
63085+ return 1;
63086+
63087+ memset(subj_map_set.s_hash, 0,
63088+ sizeof(struct subject_map *) * subj_map_set.s_size);
63089+ memset(acl_role_set.r_hash, 0,
63090+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63091+ memset(name_set.n_hash, 0,
63092+ sizeof (struct name_entry *) * name_set.n_size);
63093+ memset(inodev_set.i_hash, 0,
63094+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63095+
63096+ return 0;
63097+}
63098+
63099+/* free information not needed after startup
63100+ currently contains user->kernel pointer mappings for subjects
63101+*/
63102+
63103+static void
63104+free_init_variables(void)
63105+{
63106+ __u32 i;
63107+
63108+ if (subj_map_set.s_hash) {
63109+ for (i = 0; i < subj_map_set.s_size; i++) {
63110+ if (subj_map_set.s_hash[i]) {
63111+ kfree(subj_map_set.s_hash[i]);
63112+ subj_map_set.s_hash[i] = NULL;
63113+ }
63114+ }
63115+
63116+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63117+ PAGE_SIZE)
63118+ kfree(subj_map_set.s_hash);
63119+ else
63120+ vfree(subj_map_set.s_hash);
63121+ }
63122+
63123+ return;
63124+}
63125+
63126+static void
63127+free_variables(void)
63128+{
63129+ struct acl_subject_label *s;
63130+ struct acl_role_label *r;
63131+ struct task_struct *task, *task2;
63132+ unsigned int x;
63133+
63134+ gr_clear_learn_entries();
63135+
63136+ read_lock(&tasklist_lock);
63137+ do_each_thread(task2, task) {
63138+ task->acl_sp_role = 0;
63139+ task->acl_role_id = 0;
63140+ task->acl = NULL;
63141+ task->role = NULL;
63142+ } while_each_thread(task2, task);
63143+ read_unlock(&tasklist_lock);
63144+
63145+ /* release the reference to the real root dentry and vfsmount */
63146+ path_put(&real_root);
63147+ memset(&real_root, 0, sizeof(real_root));
63148+
63149+ /* free all object hash tables */
63150+
63151+ FOR_EACH_ROLE_START(r)
63152+ if (r->subj_hash == NULL)
63153+ goto next_role;
63154+ FOR_EACH_SUBJECT_START(r, s, x)
63155+ if (s->obj_hash == NULL)
63156+ break;
63157+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63158+ kfree(s->obj_hash);
63159+ else
63160+ vfree(s->obj_hash);
63161+ FOR_EACH_SUBJECT_END(s, x)
63162+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63163+ if (s->obj_hash == NULL)
63164+ break;
63165+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63166+ kfree(s->obj_hash);
63167+ else
63168+ vfree(s->obj_hash);
63169+ FOR_EACH_NESTED_SUBJECT_END(s)
63170+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63171+ kfree(r->subj_hash);
63172+ else
63173+ vfree(r->subj_hash);
63174+ r->subj_hash = NULL;
63175+next_role:
63176+ FOR_EACH_ROLE_END(r)
63177+
63178+ acl_free_all();
63179+
63180+ if (acl_role_set.r_hash) {
63181+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63182+ PAGE_SIZE)
63183+ kfree(acl_role_set.r_hash);
63184+ else
63185+ vfree(acl_role_set.r_hash);
63186+ }
63187+ if (name_set.n_hash) {
63188+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63189+ PAGE_SIZE)
63190+ kfree(name_set.n_hash);
63191+ else
63192+ vfree(name_set.n_hash);
63193+ }
63194+
63195+ if (inodev_set.i_hash) {
63196+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63197+ PAGE_SIZE)
63198+ kfree(inodev_set.i_hash);
63199+ else
63200+ vfree(inodev_set.i_hash);
63201+ }
63202+
63203+ gr_free_uidset();
63204+
63205+ memset(&name_set, 0, sizeof (struct name_db));
63206+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63207+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63208+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63209+
63210+ default_role = NULL;
63211+ kernel_role = NULL;
63212+ role_list = NULL;
63213+
63214+ return;
63215+}
63216+
63217+static struct acl_subject_label *
63218+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63219+
63220+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63221+{
63222+ unsigned int len = strnlen_user(*name, maxlen);
63223+ char *tmp;
63224+
63225+ if (!len || len >= maxlen)
63226+ return -EINVAL;
63227+
63228+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63229+ return -ENOMEM;
63230+
63231+ if (copy_from_user(tmp, *name, len))
63232+ return -EFAULT;
63233+
63234+ tmp[len-1] = '\0';
63235+ *name = tmp;
63236+
63237+ return 0;
63238+}
63239+
63240+static int
63241+copy_user_glob(struct acl_object_label *obj)
63242+{
63243+ struct acl_object_label *g_tmp, **guser;
63244+ int error;
63245+
63246+ if (obj->globbed == NULL)
63247+ return 0;
63248+
63249+ guser = &obj->globbed;
63250+ while (*guser) {
63251+ g_tmp = (struct acl_object_label *)
63252+ acl_alloc(sizeof (struct acl_object_label));
63253+ if (g_tmp == NULL)
63254+ return -ENOMEM;
63255+
63256+ if (copy_acl_object_label(g_tmp, *guser))
63257+ return -EFAULT;
63258+
63259+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63260+ if (error)
63261+ return error;
63262+
63263+ *guser = g_tmp;
63264+ guser = &(g_tmp->next);
63265+ }
63266+
63267+ return 0;
63268+}
63269+
63270+static int
63271+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63272+ struct acl_role_label *role)
63273+{
63274+ struct acl_object_label *o_tmp;
63275+ int ret;
63276+
63277+ while (userp) {
63278+ if ((o_tmp = (struct acl_object_label *)
63279+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63280+ return -ENOMEM;
63281+
63282+ if (copy_acl_object_label(o_tmp, userp))
63283+ return -EFAULT;
63284+
63285+ userp = o_tmp->prev;
63286+
63287+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63288+ if (ret)
63289+ return ret;
63290+
63291+ insert_acl_obj_label(o_tmp, subj);
63292+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63293+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63294+ return -ENOMEM;
63295+
63296+ ret = copy_user_glob(o_tmp);
63297+ if (ret)
63298+ return ret;
63299+
63300+ if (o_tmp->nested) {
63301+ int already_copied;
63302+
63303+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63304+ if (IS_ERR(o_tmp->nested))
63305+ return PTR_ERR(o_tmp->nested);
63306+
63307+ /* insert into nested subject list if we haven't copied this one yet
63308+ to prevent duplicate entries */
63309+ if (!already_copied) {
63310+ o_tmp->nested->next = role->hash->first;
63311+ role->hash->first = o_tmp->nested;
63312+ }
63313+ }
63314+ }
63315+
63316+ return 0;
63317+}
63318+
63319+static __u32
63320+count_user_subjs(struct acl_subject_label *userp)
63321+{
63322+ struct acl_subject_label s_tmp;
63323+ __u32 num = 0;
63324+
63325+ while (userp) {
63326+ if (copy_acl_subject_label(&s_tmp, userp))
63327+ break;
63328+
63329+ userp = s_tmp.prev;
63330+ }
63331+
63332+ return num;
63333+}
63334+
63335+static int
63336+copy_user_allowedips(struct acl_role_label *rolep)
63337+{
63338+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63339+
63340+ ruserip = rolep->allowed_ips;
63341+
63342+ while (ruserip) {
63343+ rlast = rtmp;
63344+
63345+ if ((rtmp = (struct role_allowed_ip *)
63346+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63347+ return -ENOMEM;
63348+
63349+ if (copy_role_allowed_ip(rtmp, ruserip))
63350+ return -EFAULT;
63351+
63352+ ruserip = rtmp->prev;
63353+
63354+ if (!rlast) {
63355+ rtmp->prev = NULL;
63356+ rolep->allowed_ips = rtmp;
63357+ } else {
63358+ rlast->next = rtmp;
63359+ rtmp->prev = rlast;
63360+ }
63361+
63362+ if (!ruserip)
63363+ rtmp->next = NULL;
63364+ }
63365+
63366+ return 0;
63367+}
63368+
63369+static int
63370+copy_user_transitions(struct acl_role_label *rolep)
63371+{
63372+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63373+ int error;
63374+
63375+ rusertp = rolep->transitions;
63376+
63377+ while (rusertp) {
63378+ rlast = rtmp;
63379+
63380+ if ((rtmp = (struct role_transition *)
63381+ acl_alloc(sizeof (struct role_transition))) == NULL)
63382+ return -ENOMEM;
63383+
63384+ if (copy_role_transition(rtmp, rusertp))
63385+ return -EFAULT;
63386+
63387+ rusertp = rtmp->prev;
63388+
63389+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63390+ if (error)
63391+ return error;
63392+
63393+ if (!rlast) {
63394+ rtmp->prev = NULL;
63395+ rolep->transitions = rtmp;
63396+ } else {
63397+ rlast->next = rtmp;
63398+ rtmp->prev = rlast;
63399+ }
63400+
63401+ if (!rusertp)
63402+ rtmp->next = NULL;
63403+ }
63404+
63405+ return 0;
63406+}
63407+
63408+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63409+{
63410+ struct acl_object_label o_tmp;
63411+ __u32 num = 0;
63412+
63413+ while (userp) {
63414+ if (copy_acl_object_label(&o_tmp, userp))
63415+ break;
63416+
63417+ userp = o_tmp.prev;
63418+ num++;
63419+ }
63420+
63421+ return num;
63422+}
63423+
63424+static struct acl_subject_label *
63425+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63426+{
63427+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63428+ __u32 num_objs;
63429+ struct acl_ip_label **i_tmp, *i_utmp2;
63430+ struct gr_hash_struct ghash;
63431+ struct subject_map *subjmap;
63432+ unsigned int i_num;
63433+ int err;
63434+
63435+ if (already_copied != NULL)
63436+ *already_copied = 0;
63437+
63438+ s_tmp = lookup_subject_map(userp);
63439+
63440+ /* we've already copied this subject into the kernel, just return
63441+ the reference to it, and don't copy it over again
63442+ */
63443+ if (s_tmp) {
63444+ if (already_copied != NULL)
63445+ *already_copied = 1;
63446+ return(s_tmp);
63447+ }
63448+
63449+ if ((s_tmp = (struct acl_subject_label *)
63450+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63451+ return ERR_PTR(-ENOMEM);
63452+
63453+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63454+ if (subjmap == NULL)
63455+ return ERR_PTR(-ENOMEM);
63456+
63457+ subjmap->user = userp;
63458+ subjmap->kernel = s_tmp;
63459+ insert_subj_map_entry(subjmap);
63460+
63461+ if (copy_acl_subject_label(s_tmp, userp))
63462+ return ERR_PTR(-EFAULT);
63463+
63464+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63465+ if (err)
63466+ return ERR_PTR(err);
63467+
63468+ if (!strcmp(s_tmp->filename, "/"))
63469+ role->root_label = s_tmp;
63470+
63471+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63472+ return ERR_PTR(-EFAULT);
63473+
63474+ /* copy user and group transition tables */
63475+
63476+ if (s_tmp->user_trans_num) {
63477+ uid_t *uidlist;
63478+
63479+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63480+ if (uidlist == NULL)
63481+ return ERR_PTR(-ENOMEM);
63482+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63483+ return ERR_PTR(-EFAULT);
63484+
63485+ s_tmp->user_transitions = uidlist;
63486+ }
63487+
63488+ if (s_tmp->group_trans_num) {
63489+ gid_t *gidlist;
63490+
63491+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63492+ if (gidlist == NULL)
63493+ return ERR_PTR(-ENOMEM);
63494+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63495+ return ERR_PTR(-EFAULT);
63496+
63497+ s_tmp->group_transitions = gidlist;
63498+ }
63499+
63500+ /* set up object hash table */
63501+ num_objs = count_user_objs(ghash.first);
63502+
63503+ s_tmp->obj_hash_size = num_objs;
63504+ s_tmp->obj_hash =
63505+ (struct acl_object_label **)
63506+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63507+
63508+ if (!s_tmp->obj_hash)
63509+ return ERR_PTR(-ENOMEM);
63510+
63511+ memset(s_tmp->obj_hash, 0,
63512+ s_tmp->obj_hash_size *
63513+ sizeof (struct acl_object_label *));
63514+
63515+ /* add in objects */
63516+ err = copy_user_objs(ghash.first, s_tmp, role);
63517+
63518+ if (err)
63519+ return ERR_PTR(err);
63520+
63521+ /* set pointer for parent subject */
63522+ if (s_tmp->parent_subject) {
63523+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63524+
63525+ if (IS_ERR(s_tmp2))
63526+ return s_tmp2;
63527+
63528+ s_tmp->parent_subject = s_tmp2;
63529+ }
63530+
63531+ /* add in ip acls */
63532+
63533+ if (!s_tmp->ip_num) {
63534+ s_tmp->ips = NULL;
63535+ goto insert;
63536+ }
63537+
63538+ i_tmp =
63539+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63540+ sizeof (struct acl_ip_label *));
63541+
63542+ if (!i_tmp)
63543+ return ERR_PTR(-ENOMEM);
63544+
63545+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63546+ *(i_tmp + i_num) =
63547+ (struct acl_ip_label *)
63548+ acl_alloc(sizeof (struct acl_ip_label));
63549+ if (!*(i_tmp + i_num))
63550+ return ERR_PTR(-ENOMEM);
63551+
63552+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63553+ return ERR_PTR(-EFAULT);
63554+
63555+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63556+ return ERR_PTR(-EFAULT);
63557+
63558+ if ((*(i_tmp + i_num))->iface == NULL)
63559+ continue;
63560+
63561+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63562+ if (err)
63563+ return ERR_PTR(err);
63564+ }
63565+
63566+ s_tmp->ips = i_tmp;
63567+
63568+insert:
63569+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63570+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63571+ return ERR_PTR(-ENOMEM);
63572+
63573+ return s_tmp;
63574+}
63575+
63576+static int
63577+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63578+{
63579+ struct acl_subject_label s_pre;
63580+ struct acl_subject_label * ret;
63581+ int err;
63582+
63583+ while (userp) {
63584+ if (copy_acl_subject_label(&s_pre, userp))
63585+ return -EFAULT;
63586+
63587+ ret = do_copy_user_subj(userp, role, NULL);
63588+
63589+ err = PTR_ERR(ret);
63590+ if (IS_ERR(ret))
63591+ return err;
63592+
63593+ insert_acl_subj_label(ret, role);
63594+
63595+ userp = s_pre.prev;
63596+ }
63597+
63598+ return 0;
63599+}
63600+
63601+static int
63602+copy_user_acl(struct gr_arg *arg)
63603+{
63604+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63605+ struct acl_subject_label *subj_list;
63606+ struct sprole_pw *sptmp;
63607+ struct gr_hash_struct *ghash;
63608+ uid_t *domainlist;
63609+ unsigned int r_num;
63610+ int err = 0;
63611+ __u16 i;
63612+ __u32 num_subjs;
63613+
63614+ /* we need a default and kernel role */
63615+ if (arg->role_db.num_roles < 2)
63616+ return -EINVAL;
63617+
63618+ /* copy special role authentication info from userspace */
63619+
63620+ num_sprole_pws = arg->num_sprole_pws;
63621+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63622+
63623+ if (!acl_special_roles && num_sprole_pws)
63624+ return -ENOMEM;
63625+
63626+ for (i = 0; i < num_sprole_pws; i++) {
63627+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63628+ if (!sptmp)
63629+ return -ENOMEM;
63630+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63631+ return -EFAULT;
63632+
63633+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63634+ if (err)
63635+ return err;
63636+
63637+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63638+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63639+#endif
63640+
63641+ acl_special_roles[i] = sptmp;
63642+ }
63643+
63644+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63645+
63646+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63647+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63648+
63649+ if (!r_tmp)
63650+ return -ENOMEM;
63651+
63652+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63653+ return -EFAULT;
63654+
63655+ if (copy_acl_role_label(r_tmp, r_utmp2))
63656+ return -EFAULT;
63657+
63658+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63659+ if (err)
63660+ return err;
63661+
63662+ if (!strcmp(r_tmp->rolename, "default")
63663+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63664+ default_role = r_tmp;
63665+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63666+ kernel_role = r_tmp;
63667+ }
63668+
63669+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63670+ return -ENOMEM;
63671+
63672+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63673+ return -EFAULT;
63674+
63675+ r_tmp->hash = ghash;
63676+
63677+ num_subjs = count_user_subjs(r_tmp->hash->first);
63678+
63679+ r_tmp->subj_hash_size = num_subjs;
63680+ r_tmp->subj_hash =
63681+ (struct acl_subject_label **)
63682+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63683+
63684+ if (!r_tmp->subj_hash)
63685+ return -ENOMEM;
63686+
63687+ err = copy_user_allowedips(r_tmp);
63688+ if (err)
63689+ return err;
63690+
63691+ /* copy domain info */
63692+ if (r_tmp->domain_children != NULL) {
63693+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63694+ if (domainlist == NULL)
63695+ return -ENOMEM;
63696+
63697+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63698+ return -EFAULT;
63699+
63700+ r_tmp->domain_children = domainlist;
63701+ }
63702+
63703+ err = copy_user_transitions(r_tmp);
63704+ if (err)
63705+ return err;
63706+
63707+ memset(r_tmp->subj_hash, 0,
63708+ r_tmp->subj_hash_size *
63709+ sizeof (struct acl_subject_label *));
63710+
63711+ /* acquire the list of subjects, then NULL out
63712+ the list prior to parsing the subjects for this role,
63713+ as during this parsing the list is replaced with a list
63714+ of *nested* subjects for the role
63715+ */
63716+ subj_list = r_tmp->hash->first;
63717+
63718+ /* set nested subject list to null */
63719+ r_tmp->hash->first = NULL;
63720+
63721+ err = copy_user_subjs(subj_list, r_tmp);
63722+
63723+ if (err)
63724+ return err;
63725+
63726+ insert_acl_role_label(r_tmp);
63727+ }
63728+
63729+ if (default_role == NULL || kernel_role == NULL)
63730+ return -EINVAL;
63731+
63732+ return err;
63733+}
63734+
63735+static int
63736+gracl_init(struct gr_arg *args)
63737+{
63738+ int error = 0;
63739+
63740+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63741+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63742+
63743+ if (init_variables(args)) {
63744+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63745+ error = -ENOMEM;
63746+ free_variables();
63747+ goto out;
63748+ }
63749+
63750+ error = copy_user_acl(args);
63751+ free_init_variables();
63752+ if (error) {
63753+ free_variables();
63754+ goto out;
63755+ }
63756+
63757+ if ((error = gr_set_acls(0))) {
63758+ free_variables();
63759+ goto out;
63760+ }
63761+
63762+ pax_open_kernel();
63763+ gr_status |= GR_READY;
63764+ pax_close_kernel();
63765+
63766+ out:
63767+ return error;
63768+}
63769+
63770+/* derived from glibc fnmatch() 0: match, 1: no match*/
63771+
63772+static int
63773+glob_match(const char *p, const char *n)
63774+{
63775+ char c;
63776+
63777+ while ((c = *p++) != '\0') {
63778+ switch (c) {
63779+ case '?':
63780+ if (*n == '\0')
63781+ return 1;
63782+ else if (*n == '/')
63783+ return 1;
63784+ break;
63785+ case '\\':
63786+ if (*n != c)
63787+ return 1;
63788+ break;
63789+ case '*':
63790+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63791+ if (*n == '/')
63792+ return 1;
63793+ else if (c == '?') {
63794+ if (*n == '\0')
63795+ return 1;
63796+ else
63797+ ++n;
63798+ }
63799+ }
63800+ if (c == '\0') {
63801+ return 0;
63802+ } else {
63803+ const char *endp;
63804+
63805+ if ((endp = strchr(n, '/')) == NULL)
63806+ endp = n + strlen(n);
63807+
63808+ if (c == '[') {
63809+ for (--p; n < endp; ++n)
63810+ if (!glob_match(p, n))
63811+ return 0;
63812+ } else if (c == '/') {
63813+ while (*n != '\0' && *n != '/')
63814+ ++n;
63815+ if (*n == '/' && !glob_match(p, n + 1))
63816+ return 0;
63817+ } else {
63818+ for (--p; n < endp; ++n)
63819+ if (*n == c && !glob_match(p, n))
63820+ return 0;
63821+ }
63822+
63823+ return 1;
63824+ }
63825+ case '[':
63826+ {
63827+ int not;
63828+ char cold;
63829+
63830+ if (*n == '\0' || *n == '/')
63831+ return 1;
63832+
63833+ not = (*p == '!' || *p == '^');
63834+ if (not)
63835+ ++p;
63836+
63837+ c = *p++;
63838+ for (;;) {
63839+ unsigned char fn = (unsigned char)*n;
63840+
63841+ if (c == '\0')
63842+ return 1;
63843+ else {
63844+ if (c == fn)
63845+ goto matched;
63846+ cold = c;
63847+ c = *p++;
63848+
63849+ if (c == '-' && *p != ']') {
63850+ unsigned char cend = *p++;
63851+
63852+ if (cend == '\0')
63853+ return 1;
63854+
63855+ if (cold <= fn && fn <= cend)
63856+ goto matched;
63857+
63858+ c = *p++;
63859+ }
63860+ }
63861+
63862+ if (c == ']')
63863+ break;
63864+ }
63865+ if (!not)
63866+ return 1;
63867+ break;
63868+ matched:
63869+ while (c != ']') {
63870+ if (c == '\0')
63871+ return 1;
63872+
63873+ c = *p++;
63874+ }
63875+ if (not)
63876+ return 1;
63877+ }
63878+ break;
63879+ default:
63880+ if (c != *n)
63881+ return 1;
63882+ }
63883+
63884+ ++n;
63885+ }
63886+
63887+ if (*n == '\0')
63888+ return 0;
63889+
63890+ if (*n == '/')
63891+ return 0;
63892+
63893+ return 1;
63894+}
63895+
63896+static struct acl_object_label *
63897+chk_glob_label(struct acl_object_label *globbed,
63898+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63899+{
63900+ struct acl_object_label *tmp;
63901+
63902+ if (*path == NULL)
63903+ *path = gr_to_filename_nolock(dentry, mnt);
63904+
63905+ tmp = globbed;
63906+
63907+ while (tmp) {
63908+ if (!glob_match(tmp->filename, *path))
63909+ return tmp;
63910+ tmp = tmp->next;
63911+ }
63912+
63913+ return NULL;
63914+}
63915+
63916+static struct acl_object_label *
63917+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63918+ const ino_t curr_ino, const dev_t curr_dev,
63919+ const struct acl_subject_label *subj, char **path, const int checkglob)
63920+{
63921+ struct acl_subject_label *tmpsubj;
63922+ struct acl_object_label *retval;
63923+ struct acl_object_label *retval2;
63924+
63925+ tmpsubj = (struct acl_subject_label *) subj;
63926+ read_lock(&gr_inode_lock);
63927+ do {
63928+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63929+ if (retval) {
63930+ if (checkglob && retval->globbed) {
63931+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63932+ if (retval2)
63933+ retval = retval2;
63934+ }
63935+ break;
63936+ }
63937+ } while ((tmpsubj = tmpsubj->parent_subject));
63938+ read_unlock(&gr_inode_lock);
63939+
63940+ return retval;
63941+}
63942+
63943+static __inline__ struct acl_object_label *
63944+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63945+ struct dentry *curr_dentry,
63946+ const struct acl_subject_label *subj, char **path, const int checkglob)
63947+{
63948+ int newglob = checkglob;
63949+ ino_t inode;
63950+ dev_t device;
63951+
63952+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
63953+ as we don't want a / * rule to match instead of the / object
63954+ don't do this for create lookups that call this function though, since they're looking up
63955+ on the parent and thus need globbing checks on all paths
63956+ */
63957+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
63958+ newglob = GR_NO_GLOB;
63959+
63960+ spin_lock(&curr_dentry->d_lock);
63961+ inode = curr_dentry->d_inode->i_ino;
63962+ device = __get_dev(curr_dentry);
63963+ spin_unlock(&curr_dentry->d_lock);
63964+
63965+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
63966+}
63967+
63968+#ifdef CONFIG_HUGETLBFS
63969+static inline bool
63970+is_hugetlbfs_mnt(const struct vfsmount *mnt)
63971+{
63972+ int i;
63973+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
63974+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
63975+ return true;
63976+ }
63977+
63978+ return false;
63979+}
63980+#endif
63981+
63982+static struct acl_object_label *
63983+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63984+ const struct acl_subject_label *subj, char *path, const int checkglob)
63985+{
63986+ struct dentry *dentry = (struct dentry *) l_dentry;
63987+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63988+ struct mount *real_mnt = real_mount(mnt);
63989+ struct acl_object_label *retval;
63990+ struct dentry *parent;
63991+
63992+ br_read_lock(&vfsmount_lock);
63993+ write_seqlock(&rename_lock);
63994+
63995+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
63996+#ifdef CONFIG_NET
63997+ mnt == sock_mnt ||
63998+#endif
63999+#ifdef CONFIG_HUGETLBFS
64000+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64001+#endif
64002+ /* ignore Eric Biederman */
64003+ IS_PRIVATE(l_dentry->d_inode))) {
64004+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64005+ goto out;
64006+ }
64007+
64008+ for (;;) {
64009+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64010+ break;
64011+
64012+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64013+ if (!mnt_has_parent(real_mnt))
64014+ break;
64015+
64016+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64017+ if (retval != NULL)
64018+ goto out;
64019+
64020+ dentry = real_mnt->mnt_mountpoint;
64021+ real_mnt = real_mnt->mnt_parent;
64022+ mnt = &real_mnt->mnt;
64023+ continue;
64024+ }
64025+
64026+ parent = dentry->d_parent;
64027+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64028+ if (retval != NULL)
64029+ goto out;
64030+
64031+ dentry = parent;
64032+ }
64033+
64034+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64035+
64036+ /* real_root is pinned so we don't have to hold a reference */
64037+ if (retval == NULL)
64038+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64039+out:
64040+ write_sequnlock(&rename_lock);
64041+ br_read_unlock(&vfsmount_lock);
64042+
64043+ BUG_ON(retval == NULL);
64044+
64045+ return retval;
64046+}
64047+
64048+static __inline__ struct acl_object_label *
64049+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64050+ const struct acl_subject_label *subj)
64051+{
64052+ char *path = NULL;
64053+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64054+}
64055+
64056+static __inline__ struct acl_object_label *
64057+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64058+ const struct acl_subject_label *subj)
64059+{
64060+ char *path = NULL;
64061+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64062+}
64063+
64064+static __inline__ struct acl_object_label *
64065+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64066+ const struct acl_subject_label *subj, char *path)
64067+{
64068+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64069+}
64070+
64071+static struct acl_subject_label *
64072+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64073+ const struct acl_role_label *role)
64074+{
64075+ struct dentry *dentry = (struct dentry *) l_dentry;
64076+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64077+ struct mount *real_mnt = real_mount(mnt);
64078+ struct acl_subject_label *retval;
64079+ struct dentry *parent;
64080+
64081+ br_read_lock(&vfsmount_lock);
64082+ write_seqlock(&rename_lock);
64083+
64084+ for (;;) {
64085+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64086+ break;
64087+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64088+ if (!mnt_has_parent(real_mnt))
64089+ break;
64090+
64091+ spin_lock(&dentry->d_lock);
64092+ read_lock(&gr_inode_lock);
64093+ retval =
64094+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64095+ __get_dev(dentry), role);
64096+ read_unlock(&gr_inode_lock);
64097+ spin_unlock(&dentry->d_lock);
64098+ if (retval != NULL)
64099+ goto out;
64100+
64101+ dentry = real_mnt->mnt_mountpoint;
64102+ real_mnt = real_mnt->mnt_parent;
64103+ mnt = &real_mnt->mnt;
64104+ continue;
64105+ }
64106+
64107+ spin_lock(&dentry->d_lock);
64108+ read_lock(&gr_inode_lock);
64109+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64110+ __get_dev(dentry), role);
64111+ read_unlock(&gr_inode_lock);
64112+ parent = dentry->d_parent;
64113+ spin_unlock(&dentry->d_lock);
64114+
64115+ if (retval != NULL)
64116+ goto out;
64117+
64118+ dentry = parent;
64119+ }
64120+
64121+ spin_lock(&dentry->d_lock);
64122+ read_lock(&gr_inode_lock);
64123+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64124+ __get_dev(dentry), role);
64125+ read_unlock(&gr_inode_lock);
64126+ spin_unlock(&dentry->d_lock);
64127+
64128+ if (unlikely(retval == NULL)) {
64129+ /* real_root is pinned, we don't need to hold a reference */
64130+ read_lock(&gr_inode_lock);
64131+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64132+ __get_dev(real_root.dentry), role);
64133+ read_unlock(&gr_inode_lock);
64134+ }
64135+out:
64136+ write_sequnlock(&rename_lock);
64137+ br_read_unlock(&vfsmount_lock);
64138+
64139+ BUG_ON(retval == NULL);
64140+
64141+ return retval;
64142+}
64143+
64144+static void
64145+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64146+{
64147+ struct task_struct *task = current;
64148+ const struct cred *cred = current_cred();
64149+
64150+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64151+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64152+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64153+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64154+
64155+ return;
64156+}
64157+
64158+static void
64159+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64160+{
64161+ struct task_struct *task = current;
64162+ const struct cred *cred = current_cred();
64163+
64164+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64165+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64166+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64167+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64168+
64169+ return;
64170+}
64171+
64172+static void
64173+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64174+{
64175+ struct task_struct *task = current;
64176+ const struct cred *cred = current_cred();
64177+
64178+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64179+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64180+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64181+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64182+
64183+ return;
64184+}
64185+
64186+__u32
64187+gr_search_file(const struct dentry * dentry, const __u32 mode,
64188+ const struct vfsmount * mnt)
64189+{
64190+ __u32 retval = mode;
64191+ struct acl_subject_label *curracl;
64192+ struct acl_object_label *currobj;
64193+
64194+ if (unlikely(!(gr_status & GR_READY)))
64195+ return (mode & ~GR_AUDITS);
64196+
64197+ curracl = current->acl;
64198+
64199+ currobj = chk_obj_label(dentry, mnt, curracl);
64200+ retval = currobj->mode & mode;
64201+
64202+ /* if we're opening a specified transfer file for writing
64203+ (e.g. /dev/initctl), then transfer our role to init
64204+ */
64205+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64206+ current->role->roletype & GR_ROLE_PERSIST)) {
64207+ struct task_struct *task = init_pid_ns.child_reaper;
64208+
64209+ if (task->role != current->role) {
64210+ task->acl_sp_role = 0;
64211+ task->acl_role_id = current->acl_role_id;
64212+ task->role = current->role;
64213+ rcu_read_lock();
64214+ read_lock(&grsec_exec_file_lock);
64215+ gr_apply_subject_to_task(task);
64216+ read_unlock(&grsec_exec_file_lock);
64217+ rcu_read_unlock();
64218+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64219+ }
64220+ }
64221+
64222+ if (unlikely
64223+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64224+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64225+ __u32 new_mode = mode;
64226+
64227+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64228+
64229+ retval = new_mode;
64230+
64231+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64232+ new_mode |= GR_INHERIT;
64233+
64234+ if (!(mode & GR_NOLEARN))
64235+ gr_log_learn(dentry, mnt, new_mode);
64236+ }
64237+
64238+ return retval;
64239+}
64240+
64241+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64242+ const struct dentry *parent,
64243+ const struct vfsmount *mnt)
64244+{
64245+ struct name_entry *match;
64246+ struct acl_object_label *matchpo;
64247+ struct acl_subject_label *curracl;
64248+ char *path;
64249+
64250+ if (unlikely(!(gr_status & GR_READY)))
64251+ return NULL;
64252+
64253+ preempt_disable();
64254+ path = gr_to_filename_rbac(new_dentry, mnt);
64255+ match = lookup_name_entry_create(path);
64256+
64257+ curracl = current->acl;
64258+
64259+ if (match) {
64260+ read_lock(&gr_inode_lock);
64261+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64262+ read_unlock(&gr_inode_lock);
64263+
64264+ if (matchpo) {
64265+ preempt_enable();
64266+ return matchpo;
64267+ }
64268+ }
64269+
64270+ // lookup parent
64271+
64272+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64273+
64274+ preempt_enable();
64275+ return matchpo;
64276+}
64277+
64278+__u32
64279+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64280+ const struct vfsmount * mnt, const __u32 mode)
64281+{
64282+ struct acl_object_label *matchpo;
64283+ __u32 retval;
64284+
64285+ if (unlikely(!(gr_status & GR_READY)))
64286+ return (mode & ~GR_AUDITS);
64287+
64288+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64289+
64290+ retval = matchpo->mode & mode;
64291+
64292+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64293+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64294+ __u32 new_mode = mode;
64295+
64296+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64297+
64298+ gr_log_learn(new_dentry, mnt, new_mode);
64299+ return new_mode;
64300+ }
64301+
64302+ return retval;
64303+}
64304+
64305+__u32
64306+gr_check_link(const struct dentry * new_dentry,
64307+ const struct dentry * parent_dentry,
64308+ const struct vfsmount * parent_mnt,
64309+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64310+{
64311+ struct acl_object_label *obj;
64312+ __u32 oldmode, newmode;
64313+ __u32 needmode;
64314+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64315+ GR_DELETE | GR_INHERIT;
64316+
64317+ if (unlikely(!(gr_status & GR_READY)))
64318+ return (GR_CREATE | GR_LINK);
64319+
64320+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64321+ oldmode = obj->mode;
64322+
64323+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64324+ newmode = obj->mode;
64325+
64326+ needmode = newmode & checkmodes;
64327+
64328+ // old name for hardlink must have at least the permissions of the new name
64329+ if ((oldmode & needmode) != needmode)
64330+ goto bad;
64331+
64332+ // if old name had restrictions/auditing, make sure the new name does as well
64333+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64334+
64335+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64336+ if (is_privileged_binary(old_dentry))
64337+ needmode |= GR_SETID;
64338+
64339+ if ((newmode & needmode) != needmode)
64340+ goto bad;
64341+
64342+ // enforce minimum permissions
64343+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64344+ return newmode;
64345+bad:
64346+ needmode = oldmode;
64347+ if (is_privileged_binary(old_dentry))
64348+ needmode |= GR_SETID;
64349+
64350+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64351+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64352+ return (GR_CREATE | GR_LINK);
64353+ } else if (newmode & GR_SUPPRESS)
64354+ return GR_SUPPRESS;
64355+ else
64356+ return 0;
64357+}
64358+
64359+int
64360+gr_check_hidden_task(const struct task_struct *task)
64361+{
64362+ if (unlikely(!(gr_status & GR_READY)))
64363+ return 0;
64364+
64365+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64366+ return 1;
64367+
64368+ return 0;
64369+}
64370+
64371+int
64372+gr_check_protected_task(const struct task_struct *task)
64373+{
64374+ if (unlikely(!(gr_status & GR_READY) || !task))
64375+ return 0;
64376+
64377+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64378+ task->acl != current->acl)
64379+ return 1;
64380+
64381+ return 0;
64382+}
64383+
64384+int
64385+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64386+{
64387+ struct task_struct *p;
64388+ int ret = 0;
64389+
64390+ if (unlikely(!(gr_status & GR_READY) || !pid))
64391+ return ret;
64392+
64393+ read_lock(&tasklist_lock);
64394+ do_each_pid_task(pid, type, p) {
64395+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64396+ p->acl != current->acl) {
64397+ ret = 1;
64398+ goto out;
64399+ }
64400+ } while_each_pid_task(pid, type, p);
64401+out:
64402+ read_unlock(&tasklist_lock);
64403+
64404+ return ret;
64405+}
64406+
64407+void
64408+gr_copy_label(struct task_struct *tsk)
64409+{
64410+ tsk->signal->used_accept = 0;
64411+ tsk->acl_sp_role = 0;
64412+ tsk->acl_role_id = current->acl_role_id;
64413+ tsk->acl = current->acl;
64414+ tsk->role = current->role;
64415+ tsk->signal->curr_ip = current->signal->curr_ip;
64416+ tsk->signal->saved_ip = current->signal->saved_ip;
64417+ if (current->exec_file)
64418+ get_file(current->exec_file);
64419+ tsk->exec_file = current->exec_file;
64420+ tsk->is_writable = current->is_writable;
64421+ if (unlikely(current->signal->used_accept)) {
64422+ current->signal->curr_ip = 0;
64423+ current->signal->saved_ip = 0;
64424+ }
64425+
64426+ return;
64427+}
64428+
64429+static void
64430+gr_set_proc_res(struct task_struct *task)
64431+{
64432+ struct acl_subject_label *proc;
64433+ unsigned short i;
64434+
64435+ proc = task->acl;
64436+
64437+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64438+ return;
64439+
64440+ for (i = 0; i < RLIM_NLIMITS; i++) {
64441+ if (!(proc->resmask & (1U << i)))
64442+ continue;
64443+
64444+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64445+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64446+
64447+ if (i == RLIMIT_CPU)
64448+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64449+ }
64450+
64451+ return;
64452+}
64453+
64454+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64455+
64456+int
64457+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64458+{
64459+ unsigned int i;
64460+ __u16 num;
64461+ uid_t *uidlist;
64462+ uid_t curuid;
64463+ int realok = 0;
64464+ int effectiveok = 0;
64465+ int fsok = 0;
64466+ uid_t globalreal, globaleffective, globalfs;
64467+
64468+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64469+ struct user_struct *user;
64470+
64471+ if (!uid_valid(real))
64472+ goto skipit;
64473+
64474+ /* find user based on global namespace */
64475+
64476+ globalreal = GR_GLOBAL_UID(real);
64477+
64478+ user = find_user(make_kuid(&init_user_ns, globalreal));
64479+ if (user == NULL)
64480+ goto skipit;
64481+
64482+ if (gr_process_kernel_setuid_ban(user)) {
64483+ /* for find_user */
64484+ free_uid(user);
64485+ return 1;
64486+ }
64487+
64488+ /* for find_user */
64489+ free_uid(user);
64490+
64491+skipit:
64492+#endif
64493+
64494+ if (unlikely(!(gr_status & GR_READY)))
64495+ return 0;
64496+
64497+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64498+ gr_log_learn_uid_change(real, effective, fs);
64499+
64500+ num = current->acl->user_trans_num;
64501+ uidlist = current->acl->user_transitions;
64502+
64503+ if (uidlist == NULL)
64504+ return 0;
64505+
64506+ if (!uid_valid(real)) {
64507+ realok = 1;
64508+ globalreal = (uid_t)-1;
64509+ } else {
64510+ globalreal = GR_GLOBAL_UID(real);
64511+ }
64512+ if (!uid_valid(effective)) {
64513+ effectiveok = 1;
64514+ globaleffective = (uid_t)-1;
64515+ } else {
64516+ globaleffective = GR_GLOBAL_UID(effective);
64517+ }
64518+ if (!uid_valid(fs)) {
64519+ fsok = 1;
64520+ globalfs = (uid_t)-1;
64521+ } else {
64522+ globalfs = GR_GLOBAL_UID(fs);
64523+ }
64524+
64525+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64526+ for (i = 0; i < num; i++) {
64527+ curuid = uidlist[i];
64528+ if (globalreal == curuid)
64529+ realok = 1;
64530+ if (globaleffective == curuid)
64531+ effectiveok = 1;
64532+ if (globalfs == curuid)
64533+ fsok = 1;
64534+ }
64535+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64536+ for (i = 0; i < num; i++) {
64537+ curuid = uidlist[i];
64538+ if (globalreal == curuid)
64539+ break;
64540+ if (globaleffective == curuid)
64541+ break;
64542+ if (globalfs == curuid)
64543+ break;
64544+ }
64545+ /* not in deny list */
64546+ if (i == num) {
64547+ realok = 1;
64548+ effectiveok = 1;
64549+ fsok = 1;
64550+ }
64551+ }
64552+
64553+ if (realok && effectiveok && fsok)
64554+ return 0;
64555+ else {
64556+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64557+ return 1;
64558+ }
64559+}
64560+
64561+int
64562+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64563+{
64564+ unsigned int i;
64565+ __u16 num;
64566+ gid_t *gidlist;
64567+ gid_t curgid;
64568+ int realok = 0;
64569+ int effectiveok = 0;
64570+ int fsok = 0;
64571+ gid_t globalreal, globaleffective, globalfs;
64572+
64573+ if (unlikely(!(gr_status & GR_READY)))
64574+ return 0;
64575+
64576+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64577+ gr_log_learn_gid_change(real, effective, fs);
64578+
64579+ num = current->acl->group_trans_num;
64580+ gidlist = current->acl->group_transitions;
64581+
64582+ if (gidlist == NULL)
64583+ return 0;
64584+
64585+ if (!gid_valid(real)) {
64586+ realok = 1;
64587+ globalreal = (gid_t)-1;
64588+ } else {
64589+ globalreal = GR_GLOBAL_GID(real);
64590+ }
64591+ if (!gid_valid(effective)) {
64592+ effectiveok = 1;
64593+ globaleffective = (gid_t)-1;
64594+ } else {
64595+ globaleffective = GR_GLOBAL_GID(effective);
64596+ }
64597+ if (!gid_valid(fs)) {
64598+ fsok = 1;
64599+ globalfs = (gid_t)-1;
64600+ } else {
64601+ globalfs = GR_GLOBAL_GID(fs);
64602+ }
64603+
64604+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64605+ for (i = 0; i < num; i++) {
64606+ curgid = gidlist[i];
64607+ if (globalreal == curgid)
64608+ realok = 1;
64609+ if (globaleffective == curgid)
64610+ effectiveok = 1;
64611+ if (globalfs == curgid)
64612+ fsok = 1;
64613+ }
64614+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64615+ for (i = 0; i < num; i++) {
64616+ curgid = gidlist[i];
64617+ if (globalreal == curgid)
64618+ break;
64619+ if (globaleffective == curgid)
64620+ break;
64621+ if (globalfs == curgid)
64622+ break;
64623+ }
64624+ /* not in deny list */
64625+ if (i == num) {
64626+ realok = 1;
64627+ effectiveok = 1;
64628+ fsok = 1;
64629+ }
64630+ }
64631+
64632+ if (realok && effectiveok && fsok)
64633+ return 0;
64634+ else {
64635+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64636+ return 1;
64637+ }
64638+}
64639+
64640+extern int gr_acl_is_capable(const int cap);
64641+
64642+void
64643+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64644+{
64645+ struct acl_role_label *role = task->role;
64646+ struct acl_subject_label *subj = NULL;
64647+ struct acl_object_label *obj;
64648+ struct file *filp;
64649+ uid_t uid;
64650+ gid_t gid;
64651+
64652+ if (unlikely(!(gr_status & GR_READY)))
64653+ return;
64654+
64655+ uid = GR_GLOBAL_UID(kuid);
64656+ gid = GR_GLOBAL_GID(kgid);
64657+
64658+ filp = task->exec_file;
64659+
64660+ /* kernel process, we'll give them the kernel role */
64661+ if (unlikely(!filp)) {
64662+ task->role = kernel_role;
64663+ task->acl = kernel_role->root_label;
64664+ return;
64665+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64666+ role = lookup_acl_role_label(task, uid, gid);
64667+
64668+ /* don't change the role if we're not a privileged process */
64669+ if (role && task->role != role &&
64670+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64671+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64672+ return;
64673+
64674+ /* perform subject lookup in possibly new role
64675+ we can use this result below in the case where role == task->role
64676+ */
64677+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64678+
64679+ /* if we changed uid/gid, but result in the same role
64680+ and are using inheritance, don't lose the inherited subject
64681+ if current subject is other than what normal lookup
64682+ would result in, we arrived via inheritance, don't
64683+ lose subject
64684+ */
64685+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64686+ (subj == task->acl)))
64687+ task->acl = subj;
64688+
64689+ task->role = role;
64690+
64691+ task->is_writable = 0;
64692+
64693+ /* ignore additional mmap checks for processes that are writable
64694+ by the default ACL */
64695+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64696+ if (unlikely(obj->mode & GR_WRITE))
64697+ task->is_writable = 1;
64698+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64699+ if (unlikely(obj->mode & GR_WRITE))
64700+ task->is_writable = 1;
64701+
64702+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64703+ 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);
64704+#endif
64705+
64706+ gr_set_proc_res(task);
64707+
64708+ return;
64709+}
64710+
64711+int
64712+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64713+ const int unsafe_flags)
64714+{
64715+ struct task_struct *task = current;
64716+ struct acl_subject_label *newacl;
64717+ struct acl_object_label *obj;
64718+ __u32 retmode;
64719+
64720+ if (unlikely(!(gr_status & GR_READY)))
64721+ return 0;
64722+
64723+ newacl = chk_subj_label(dentry, mnt, task->role);
64724+
64725+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64726+ did an exec
64727+ */
64728+ rcu_read_lock();
64729+ read_lock(&tasklist_lock);
64730+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64731+ (task->parent->acl->mode & GR_POVERRIDE))) {
64732+ read_unlock(&tasklist_lock);
64733+ rcu_read_unlock();
64734+ goto skip_check;
64735+ }
64736+ read_unlock(&tasklist_lock);
64737+ rcu_read_unlock();
64738+
64739+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64740+ !(task->role->roletype & GR_ROLE_GOD) &&
64741+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64742+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64743+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64744+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64745+ else
64746+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64747+ return -EACCES;
64748+ }
64749+
64750+skip_check:
64751+
64752+ obj = chk_obj_label(dentry, mnt, task->acl);
64753+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64754+
64755+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64756+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64757+ if (obj->nested)
64758+ task->acl = obj->nested;
64759+ else
64760+ task->acl = newacl;
64761+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64762+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64763+
64764+ task->is_writable = 0;
64765+
64766+ /* ignore additional mmap checks for processes that are writable
64767+ by the default ACL */
64768+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64769+ if (unlikely(obj->mode & GR_WRITE))
64770+ task->is_writable = 1;
64771+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64772+ if (unlikely(obj->mode & GR_WRITE))
64773+ task->is_writable = 1;
64774+
64775+ gr_set_proc_res(task);
64776+
64777+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64778+ 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);
64779+#endif
64780+ return 0;
64781+}
64782+
64783+/* always called with valid inodev ptr */
64784+static void
64785+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64786+{
64787+ struct acl_object_label *matchpo;
64788+ struct acl_subject_label *matchps;
64789+ struct acl_subject_label *subj;
64790+ struct acl_role_label *role;
64791+ unsigned int x;
64792+
64793+ FOR_EACH_ROLE_START(role)
64794+ FOR_EACH_SUBJECT_START(role, subj, x)
64795+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64796+ matchpo->mode |= GR_DELETED;
64797+ FOR_EACH_SUBJECT_END(subj,x)
64798+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64799+ /* nested subjects aren't in the role's subj_hash table */
64800+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64801+ matchpo->mode |= GR_DELETED;
64802+ FOR_EACH_NESTED_SUBJECT_END(subj)
64803+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64804+ matchps->mode |= GR_DELETED;
64805+ FOR_EACH_ROLE_END(role)
64806+
64807+ inodev->nentry->deleted = 1;
64808+
64809+ return;
64810+}
64811+
64812+void
64813+gr_handle_delete(const ino_t ino, const dev_t dev)
64814+{
64815+ struct inodev_entry *inodev;
64816+
64817+ if (unlikely(!(gr_status & GR_READY)))
64818+ return;
64819+
64820+ write_lock(&gr_inode_lock);
64821+ inodev = lookup_inodev_entry(ino, dev);
64822+ if (inodev != NULL)
64823+ do_handle_delete(inodev, ino, dev);
64824+ write_unlock(&gr_inode_lock);
64825+
64826+ return;
64827+}
64828+
64829+static void
64830+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64831+ const ino_t newinode, const dev_t newdevice,
64832+ struct acl_subject_label *subj)
64833+{
64834+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64835+ struct acl_object_label *match;
64836+
64837+ match = subj->obj_hash[index];
64838+
64839+ while (match && (match->inode != oldinode ||
64840+ match->device != olddevice ||
64841+ !(match->mode & GR_DELETED)))
64842+ match = match->next;
64843+
64844+ if (match && (match->inode == oldinode)
64845+ && (match->device == olddevice)
64846+ && (match->mode & GR_DELETED)) {
64847+ if (match->prev == NULL) {
64848+ subj->obj_hash[index] = match->next;
64849+ if (match->next != NULL)
64850+ match->next->prev = NULL;
64851+ } else {
64852+ match->prev->next = match->next;
64853+ if (match->next != NULL)
64854+ match->next->prev = match->prev;
64855+ }
64856+ match->prev = NULL;
64857+ match->next = NULL;
64858+ match->inode = newinode;
64859+ match->device = newdevice;
64860+ match->mode &= ~GR_DELETED;
64861+
64862+ insert_acl_obj_label(match, subj);
64863+ }
64864+
64865+ return;
64866+}
64867+
64868+static void
64869+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64870+ const ino_t newinode, const dev_t newdevice,
64871+ struct acl_role_label *role)
64872+{
64873+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64874+ struct acl_subject_label *match;
64875+
64876+ match = role->subj_hash[index];
64877+
64878+ while (match && (match->inode != oldinode ||
64879+ match->device != olddevice ||
64880+ !(match->mode & GR_DELETED)))
64881+ match = match->next;
64882+
64883+ if (match && (match->inode == oldinode)
64884+ && (match->device == olddevice)
64885+ && (match->mode & GR_DELETED)) {
64886+ if (match->prev == NULL) {
64887+ role->subj_hash[index] = match->next;
64888+ if (match->next != NULL)
64889+ match->next->prev = NULL;
64890+ } else {
64891+ match->prev->next = match->next;
64892+ if (match->next != NULL)
64893+ match->next->prev = match->prev;
64894+ }
64895+ match->prev = NULL;
64896+ match->next = NULL;
64897+ match->inode = newinode;
64898+ match->device = newdevice;
64899+ match->mode &= ~GR_DELETED;
64900+
64901+ insert_acl_subj_label(match, role);
64902+ }
64903+
64904+ return;
64905+}
64906+
64907+static void
64908+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64909+ const ino_t newinode, const dev_t newdevice)
64910+{
64911+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
64912+ struct inodev_entry *match;
64913+
64914+ match = inodev_set.i_hash[index];
64915+
64916+ while (match && (match->nentry->inode != oldinode ||
64917+ match->nentry->device != olddevice || !match->nentry->deleted))
64918+ match = match->next;
64919+
64920+ if (match && (match->nentry->inode == oldinode)
64921+ && (match->nentry->device == olddevice) &&
64922+ match->nentry->deleted) {
64923+ if (match->prev == NULL) {
64924+ inodev_set.i_hash[index] = match->next;
64925+ if (match->next != NULL)
64926+ match->next->prev = NULL;
64927+ } else {
64928+ match->prev->next = match->next;
64929+ if (match->next != NULL)
64930+ match->next->prev = match->prev;
64931+ }
64932+ match->prev = NULL;
64933+ match->next = NULL;
64934+ match->nentry->inode = newinode;
64935+ match->nentry->device = newdevice;
64936+ match->nentry->deleted = 0;
64937+
64938+ insert_inodev_entry(match);
64939+ }
64940+
64941+ return;
64942+}
64943+
64944+static void
64945+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
64946+{
64947+ struct acl_subject_label *subj;
64948+ struct acl_role_label *role;
64949+ unsigned int x;
64950+
64951+ FOR_EACH_ROLE_START(role)
64952+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
64953+
64954+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64955+ if ((subj->inode == ino) && (subj->device == dev)) {
64956+ subj->inode = ino;
64957+ subj->device = dev;
64958+ }
64959+ /* nested subjects aren't in the role's subj_hash table */
64960+ update_acl_obj_label(matchn->inode, matchn->device,
64961+ ino, dev, subj);
64962+ FOR_EACH_NESTED_SUBJECT_END(subj)
64963+ FOR_EACH_SUBJECT_START(role, subj, x)
64964+ update_acl_obj_label(matchn->inode, matchn->device,
64965+ ino, dev, subj);
64966+ FOR_EACH_SUBJECT_END(subj,x)
64967+ FOR_EACH_ROLE_END(role)
64968+
64969+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
64970+
64971+ return;
64972+}
64973+
64974+static void
64975+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
64976+ const struct vfsmount *mnt)
64977+{
64978+ ino_t ino = dentry->d_inode->i_ino;
64979+ dev_t dev = __get_dev(dentry);
64980+
64981+ __do_handle_create(matchn, ino, dev);
64982+
64983+ return;
64984+}
64985+
64986+void
64987+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64988+{
64989+ struct name_entry *matchn;
64990+
64991+ if (unlikely(!(gr_status & GR_READY)))
64992+ return;
64993+
64994+ preempt_disable();
64995+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
64996+
64997+ if (unlikely((unsigned long)matchn)) {
64998+ write_lock(&gr_inode_lock);
64999+ do_handle_create(matchn, dentry, mnt);
65000+ write_unlock(&gr_inode_lock);
65001+ }
65002+ preempt_enable();
65003+
65004+ return;
65005+}
65006+
65007+void
65008+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65009+{
65010+ struct name_entry *matchn;
65011+
65012+ if (unlikely(!(gr_status & GR_READY)))
65013+ return;
65014+
65015+ preempt_disable();
65016+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65017+
65018+ if (unlikely((unsigned long)matchn)) {
65019+ write_lock(&gr_inode_lock);
65020+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65021+ write_unlock(&gr_inode_lock);
65022+ }
65023+ preempt_enable();
65024+
65025+ return;
65026+}
65027+
65028+void
65029+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65030+ struct dentry *old_dentry,
65031+ struct dentry *new_dentry,
65032+ struct vfsmount *mnt, const __u8 replace)
65033+{
65034+ struct name_entry *matchn;
65035+ struct inodev_entry *inodev;
65036+ struct inode *inode = new_dentry->d_inode;
65037+ ino_t old_ino = old_dentry->d_inode->i_ino;
65038+ dev_t old_dev = __get_dev(old_dentry);
65039+
65040+ /* vfs_rename swaps the name and parent link for old_dentry and
65041+ new_dentry
65042+ at this point, old_dentry has the new name, parent link, and inode
65043+ for the renamed file
65044+ if a file is being replaced by a rename, new_dentry has the inode
65045+ and name for the replaced file
65046+ */
65047+
65048+ if (unlikely(!(gr_status & GR_READY)))
65049+ return;
65050+
65051+ preempt_disable();
65052+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65053+
65054+ /* we wouldn't have to check d_inode if it weren't for
65055+ NFS silly-renaming
65056+ */
65057+
65058+ write_lock(&gr_inode_lock);
65059+ if (unlikely(replace && inode)) {
65060+ ino_t new_ino = inode->i_ino;
65061+ dev_t new_dev = __get_dev(new_dentry);
65062+
65063+ inodev = lookup_inodev_entry(new_ino, new_dev);
65064+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65065+ do_handle_delete(inodev, new_ino, new_dev);
65066+ }
65067+
65068+ inodev = lookup_inodev_entry(old_ino, old_dev);
65069+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65070+ do_handle_delete(inodev, old_ino, old_dev);
65071+
65072+ if (unlikely((unsigned long)matchn))
65073+ do_handle_create(matchn, old_dentry, mnt);
65074+
65075+ write_unlock(&gr_inode_lock);
65076+ preempt_enable();
65077+
65078+ return;
65079+}
65080+
65081+static int
65082+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65083+ unsigned char **sum)
65084+{
65085+ struct acl_role_label *r;
65086+ struct role_allowed_ip *ipp;
65087+ struct role_transition *trans;
65088+ unsigned int i;
65089+ int found = 0;
65090+ u32 curr_ip = current->signal->curr_ip;
65091+
65092+ current->signal->saved_ip = curr_ip;
65093+
65094+ /* check transition table */
65095+
65096+ for (trans = current->role->transitions; trans; trans = trans->next) {
65097+ if (!strcmp(rolename, trans->rolename)) {
65098+ found = 1;
65099+ break;
65100+ }
65101+ }
65102+
65103+ if (!found)
65104+ return 0;
65105+
65106+ /* handle special roles that do not require authentication
65107+ and check ip */
65108+
65109+ FOR_EACH_ROLE_START(r)
65110+ if (!strcmp(rolename, r->rolename) &&
65111+ (r->roletype & GR_ROLE_SPECIAL)) {
65112+ found = 0;
65113+ if (r->allowed_ips != NULL) {
65114+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65115+ if ((ntohl(curr_ip) & ipp->netmask) ==
65116+ (ntohl(ipp->addr) & ipp->netmask))
65117+ found = 1;
65118+ }
65119+ } else
65120+ found = 2;
65121+ if (!found)
65122+ return 0;
65123+
65124+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65125+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65126+ *salt = NULL;
65127+ *sum = NULL;
65128+ return 1;
65129+ }
65130+ }
65131+ FOR_EACH_ROLE_END(r)
65132+
65133+ for (i = 0; i < num_sprole_pws; i++) {
65134+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65135+ *salt = acl_special_roles[i]->salt;
65136+ *sum = acl_special_roles[i]->sum;
65137+ return 1;
65138+ }
65139+ }
65140+
65141+ return 0;
65142+}
65143+
65144+static void
65145+assign_special_role(char *rolename)
65146+{
65147+ struct acl_object_label *obj;
65148+ struct acl_role_label *r;
65149+ struct acl_role_label *assigned = NULL;
65150+ struct task_struct *tsk;
65151+ struct file *filp;
65152+
65153+ FOR_EACH_ROLE_START(r)
65154+ if (!strcmp(rolename, r->rolename) &&
65155+ (r->roletype & GR_ROLE_SPECIAL)) {
65156+ assigned = r;
65157+ break;
65158+ }
65159+ FOR_EACH_ROLE_END(r)
65160+
65161+ if (!assigned)
65162+ return;
65163+
65164+ read_lock(&tasklist_lock);
65165+ read_lock(&grsec_exec_file_lock);
65166+
65167+ tsk = current->real_parent;
65168+ if (tsk == NULL)
65169+ goto out_unlock;
65170+
65171+ filp = tsk->exec_file;
65172+ if (filp == NULL)
65173+ goto out_unlock;
65174+
65175+ tsk->is_writable = 0;
65176+
65177+ tsk->acl_sp_role = 1;
65178+ tsk->acl_role_id = ++acl_sp_role_value;
65179+ tsk->role = assigned;
65180+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65181+
65182+ /* ignore additional mmap checks for processes that are writable
65183+ by the default ACL */
65184+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65185+ if (unlikely(obj->mode & GR_WRITE))
65186+ tsk->is_writable = 1;
65187+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65188+ if (unlikely(obj->mode & GR_WRITE))
65189+ tsk->is_writable = 1;
65190+
65191+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65192+ 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));
65193+#endif
65194+
65195+out_unlock:
65196+ read_unlock(&grsec_exec_file_lock);
65197+ read_unlock(&tasklist_lock);
65198+ return;
65199+}
65200+
65201+int gr_check_secure_terminal(struct task_struct *task)
65202+{
65203+ struct task_struct *p, *p2, *p3;
65204+ struct files_struct *files;
65205+ struct fdtable *fdt;
65206+ struct file *our_file = NULL, *file;
65207+ int i;
65208+
65209+ if (task->signal->tty == NULL)
65210+ return 1;
65211+
65212+ files = get_files_struct(task);
65213+ if (files != NULL) {
65214+ rcu_read_lock();
65215+ fdt = files_fdtable(files);
65216+ for (i=0; i < fdt->max_fds; i++) {
65217+ file = fcheck_files(files, i);
65218+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65219+ get_file(file);
65220+ our_file = file;
65221+ }
65222+ }
65223+ rcu_read_unlock();
65224+ put_files_struct(files);
65225+ }
65226+
65227+ if (our_file == NULL)
65228+ return 1;
65229+
65230+ read_lock(&tasklist_lock);
65231+ do_each_thread(p2, p) {
65232+ files = get_files_struct(p);
65233+ if (files == NULL ||
65234+ (p->signal && p->signal->tty == task->signal->tty)) {
65235+ if (files != NULL)
65236+ put_files_struct(files);
65237+ continue;
65238+ }
65239+ rcu_read_lock();
65240+ fdt = files_fdtable(files);
65241+ for (i=0; i < fdt->max_fds; i++) {
65242+ file = fcheck_files(files, i);
65243+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65244+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65245+ p3 = task;
65246+ while (task_pid_nr(p3) > 0) {
65247+ if (p3 == p)
65248+ break;
65249+ p3 = p3->real_parent;
65250+ }
65251+ if (p3 == p)
65252+ break;
65253+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65254+ gr_handle_alertkill(p);
65255+ rcu_read_unlock();
65256+ put_files_struct(files);
65257+ read_unlock(&tasklist_lock);
65258+ fput(our_file);
65259+ return 0;
65260+ }
65261+ }
65262+ rcu_read_unlock();
65263+ put_files_struct(files);
65264+ } while_each_thread(p2, p);
65265+ read_unlock(&tasklist_lock);
65266+
65267+ fput(our_file);
65268+ return 1;
65269+}
65270+
65271+static int gr_rbac_disable(void *unused)
65272+{
65273+ pax_open_kernel();
65274+ gr_status &= ~GR_READY;
65275+ pax_close_kernel();
65276+
65277+ return 0;
65278+}
65279+
65280+ssize_t
65281+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65282+{
65283+ struct gr_arg_wrapper uwrap;
65284+ unsigned char *sprole_salt = NULL;
65285+ unsigned char *sprole_sum = NULL;
65286+ int error = 0;
65287+ int error2 = 0;
65288+ size_t req_count = 0;
65289+
65290+ mutex_lock(&gr_dev_mutex);
65291+
65292+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65293+ error = -EPERM;
65294+ goto out;
65295+ }
65296+
65297+#ifdef CONFIG_COMPAT
65298+ pax_open_kernel();
65299+ if (is_compat_task()) {
65300+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65301+ copy_gr_arg = &copy_gr_arg_compat;
65302+ copy_acl_object_label = &copy_acl_object_label_compat;
65303+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65304+ copy_acl_role_label = &copy_acl_role_label_compat;
65305+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65306+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65307+ copy_role_transition = &copy_role_transition_compat;
65308+ copy_sprole_pw = &copy_sprole_pw_compat;
65309+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65310+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65311+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65312+ } else {
65313+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65314+ copy_gr_arg = &copy_gr_arg_normal;
65315+ copy_acl_object_label = &copy_acl_object_label_normal;
65316+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65317+ copy_acl_role_label = &copy_acl_role_label_normal;
65318+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65319+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65320+ copy_role_transition = &copy_role_transition_normal;
65321+ copy_sprole_pw = &copy_sprole_pw_normal;
65322+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65323+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65324+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65325+ }
65326+ pax_close_kernel();
65327+#endif
65328+
65329+ req_count = get_gr_arg_wrapper_size();
65330+
65331+ if (count != req_count) {
65332+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65333+ error = -EINVAL;
65334+ goto out;
65335+ }
65336+
65337+
65338+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65339+ gr_auth_expires = 0;
65340+ gr_auth_attempts = 0;
65341+ }
65342+
65343+ error = copy_gr_arg_wrapper(buf, &uwrap);
65344+ if (error)
65345+ goto out;
65346+
65347+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65348+ if (error)
65349+ goto out;
65350+
65351+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65352+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65353+ time_after(gr_auth_expires, get_seconds())) {
65354+ error = -EBUSY;
65355+ goto out;
65356+ }
65357+
65358+ /* if non-root trying to do anything other than use a special role,
65359+ do not attempt authentication, do not count towards authentication
65360+ locking
65361+ */
65362+
65363+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65364+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65365+ gr_is_global_nonroot(current_uid())) {
65366+ error = -EPERM;
65367+ goto out;
65368+ }
65369+
65370+ /* ensure pw and special role name are null terminated */
65371+
65372+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65373+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65374+
65375+ /* Okay.
65376+ * We have our enough of the argument structure..(we have yet
65377+ * to copy_from_user the tables themselves) . Copy the tables
65378+ * only if we need them, i.e. for loading operations. */
65379+
65380+ switch (gr_usermode->mode) {
65381+ case GR_STATUS:
65382+ if (gr_status & GR_READY) {
65383+ error = 1;
65384+ if (!gr_check_secure_terminal(current))
65385+ error = 3;
65386+ } else
65387+ error = 2;
65388+ goto out;
65389+ case GR_SHUTDOWN:
65390+ if ((gr_status & GR_READY)
65391+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65392+ stop_machine(gr_rbac_disable, NULL, NULL);
65393+ free_variables();
65394+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65395+ memset(gr_system_salt, 0, GR_SALT_LEN);
65396+ memset(gr_system_sum, 0, GR_SHA_LEN);
65397+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65398+ } else if (gr_status & GR_READY) {
65399+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65400+ error = -EPERM;
65401+ } else {
65402+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65403+ error = -EAGAIN;
65404+ }
65405+ break;
65406+ case GR_ENABLE:
65407+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65408+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65409+ else {
65410+ if (gr_status & GR_READY)
65411+ error = -EAGAIN;
65412+ else
65413+ error = error2;
65414+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65415+ }
65416+ break;
65417+ case GR_RELOAD:
65418+ if (!(gr_status & GR_READY)) {
65419+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65420+ error = -EAGAIN;
65421+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65422+ stop_machine(gr_rbac_disable, NULL, NULL);
65423+ free_variables();
65424+ error2 = gracl_init(gr_usermode);
65425+ if (!error2)
65426+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65427+ else {
65428+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65429+ error = error2;
65430+ }
65431+ } else {
65432+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65433+ error = -EPERM;
65434+ }
65435+ break;
65436+ case GR_SEGVMOD:
65437+ if (unlikely(!(gr_status & GR_READY))) {
65438+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65439+ error = -EAGAIN;
65440+ break;
65441+ }
65442+
65443+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65444+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65445+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65446+ struct acl_subject_label *segvacl;
65447+ segvacl =
65448+ lookup_acl_subj_label(gr_usermode->segv_inode,
65449+ gr_usermode->segv_device,
65450+ current->role);
65451+ if (segvacl) {
65452+ segvacl->crashes = 0;
65453+ segvacl->expires = 0;
65454+ }
65455+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65456+ gr_remove_uid(gr_usermode->segv_uid);
65457+ }
65458+ } else {
65459+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65460+ error = -EPERM;
65461+ }
65462+ break;
65463+ case GR_SPROLE:
65464+ case GR_SPROLEPAM:
65465+ if (unlikely(!(gr_status & GR_READY))) {
65466+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65467+ error = -EAGAIN;
65468+ break;
65469+ }
65470+
65471+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65472+ current->role->expires = 0;
65473+ current->role->auth_attempts = 0;
65474+ }
65475+
65476+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65477+ time_after(current->role->expires, get_seconds())) {
65478+ error = -EBUSY;
65479+ goto out;
65480+ }
65481+
65482+ if (lookup_special_role_auth
65483+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65484+ && ((!sprole_salt && !sprole_sum)
65485+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65486+ char *p = "";
65487+ assign_special_role(gr_usermode->sp_role);
65488+ read_lock(&tasklist_lock);
65489+ if (current->real_parent)
65490+ p = current->real_parent->role->rolename;
65491+ read_unlock(&tasklist_lock);
65492+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65493+ p, acl_sp_role_value);
65494+ } else {
65495+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65496+ error = -EPERM;
65497+ if(!(current->role->auth_attempts++))
65498+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65499+
65500+ goto out;
65501+ }
65502+ break;
65503+ case GR_UNSPROLE:
65504+ if (unlikely(!(gr_status & GR_READY))) {
65505+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65506+ error = -EAGAIN;
65507+ break;
65508+ }
65509+
65510+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65511+ char *p = "";
65512+ int i = 0;
65513+
65514+ read_lock(&tasklist_lock);
65515+ if (current->real_parent) {
65516+ p = current->real_parent->role->rolename;
65517+ i = current->real_parent->acl_role_id;
65518+ }
65519+ read_unlock(&tasklist_lock);
65520+
65521+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65522+ gr_set_acls(1);
65523+ } else {
65524+ error = -EPERM;
65525+ goto out;
65526+ }
65527+ break;
65528+ default:
65529+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65530+ error = -EINVAL;
65531+ break;
65532+ }
65533+
65534+ if (error != -EPERM)
65535+ goto out;
65536+
65537+ if(!(gr_auth_attempts++))
65538+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65539+
65540+ out:
65541+ mutex_unlock(&gr_dev_mutex);
65542+
65543+ if (!error)
65544+ error = req_count;
65545+
65546+ return error;
65547+}
65548+
65549+/* must be called with
65550+ rcu_read_lock();
65551+ read_lock(&tasklist_lock);
65552+ read_lock(&grsec_exec_file_lock);
65553+*/
65554+int gr_apply_subject_to_task(struct task_struct *task)
65555+{
65556+ struct acl_object_label *obj;
65557+ char *tmpname;
65558+ struct acl_subject_label *tmpsubj;
65559+ struct file *filp;
65560+ struct name_entry *nmatch;
65561+
65562+ filp = task->exec_file;
65563+ if (filp == NULL)
65564+ return 0;
65565+
65566+ /* the following is to apply the correct subject
65567+ on binaries running when the RBAC system
65568+ is enabled, when the binaries have been
65569+ replaced or deleted since their execution
65570+ -----
65571+ when the RBAC system starts, the inode/dev
65572+ from exec_file will be one the RBAC system
65573+ is unaware of. It only knows the inode/dev
65574+ of the present file on disk, or the absence
65575+ of it.
65576+ */
65577+ preempt_disable();
65578+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65579+
65580+ nmatch = lookup_name_entry(tmpname);
65581+ preempt_enable();
65582+ tmpsubj = NULL;
65583+ if (nmatch) {
65584+ if (nmatch->deleted)
65585+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65586+ else
65587+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65588+ if (tmpsubj != NULL)
65589+ task->acl = tmpsubj;
65590+ }
65591+ if (tmpsubj == NULL)
65592+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65593+ task->role);
65594+ if (task->acl) {
65595+ task->is_writable = 0;
65596+ /* ignore additional mmap checks for processes that are writable
65597+ by the default ACL */
65598+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65599+ if (unlikely(obj->mode & GR_WRITE))
65600+ task->is_writable = 1;
65601+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65602+ if (unlikely(obj->mode & GR_WRITE))
65603+ task->is_writable = 1;
65604+
65605+ gr_set_proc_res(task);
65606+
65607+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65608+ 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);
65609+#endif
65610+ } else {
65611+ return 1;
65612+ }
65613+
65614+ return 0;
65615+}
65616+
65617+int
65618+gr_set_acls(const int type)
65619+{
65620+ struct task_struct *task, *task2;
65621+ struct acl_role_label *role = current->role;
65622+ __u16 acl_role_id = current->acl_role_id;
65623+ const struct cred *cred;
65624+ int ret;
65625+
65626+ rcu_read_lock();
65627+ read_lock(&tasklist_lock);
65628+ read_lock(&grsec_exec_file_lock);
65629+ do_each_thread(task2, task) {
65630+ /* check to see if we're called from the exit handler,
65631+ if so, only replace ACLs that have inherited the admin
65632+ ACL */
65633+
65634+ if (type && (task->role != role ||
65635+ task->acl_role_id != acl_role_id))
65636+ continue;
65637+
65638+ task->acl_role_id = 0;
65639+ task->acl_sp_role = 0;
65640+
65641+ if (task->exec_file) {
65642+ cred = __task_cred(task);
65643+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65644+ ret = gr_apply_subject_to_task(task);
65645+ if (ret) {
65646+ read_unlock(&grsec_exec_file_lock);
65647+ read_unlock(&tasklist_lock);
65648+ rcu_read_unlock();
65649+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65650+ return ret;
65651+ }
65652+ } else {
65653+ // it's a kernel process
65654+ task->role = kernel_role;
65655+ task->acl = kernel_role->root_label;
65656+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65657+ task->acl->mode &= ~GR_PROCFIND;
65658+#endif
65659+ }
65660+ } while_each_thread(task2, task);
65661+ read_unlock(&grsec_exec_file_lock);
65662+ read_unlock(&tasklist_lock);
65663+ rcu_read_unlock();
65664+
65665+ return 0;
65666+}
65667+
65668+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65669+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65670+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65671+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65672+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65673+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65674+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65675+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65676+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65677+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65678+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65679+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65680+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65681+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65682+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65683+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65684+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65685+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65686+};
65687+
65688+void
65689+gr_learn_resource(const struct task_struct *task,
65690+ const int res, const unsigned long wanted, const int gt)
65691+{
65692+ struct acl_subject_label *acl;
65693+ const struct cred *cred;
65694+
65695+ if (unlikely((gr_status & GR_READY) &&
65696+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65697+ goto skip_reslog;
65698+
65699+ gr_log_resource(task, res, wanted, gt);
65700+skip_reslog:
65701+
65702+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65703+ return;
65704+
65705+ acl = task->acl;
65706+
65707+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65708+ !(acl->resmask & (1U << (unsigned short) res))))
65709+ return;
65710+
65711+ if (wanted >= acl->res[res].rlim_cur) {
65712+ unsigned long res_add;
65713+
65714+ res_add = wanted + res_learn_bumps[res];
65715+
65716+ acl->res[res].rlim_cur = res_add;
65717+
65718+ if (wanted > acl->res[res].rlim_max)
65719+ acl->res[res].rlim_max = res_add;
65720+
65721+ /* only log the subject filename, since resource logging is supported for
65722+ single-subject learning only */
65723+ rcu_read_lock();
65724+ cred = __task_cred(task);
65725+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65726+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65727+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65728+ "", (unsigned long) res, &task->signal->saved_ip);
65729+ rcu_read_unlock();
65730+ }
65731+
65732+ return;
65733+}
65734+EXPORT_SYMBOL(gr_learn_resource);
65735+#endif
65736+
65737+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65738+void
65739+pax_set_initial_flags(struct linux_binprm *bprm)
65740+{
65741+ struct task_struct *task = current;
65742+ struct acl_subject_label *proc;
65743+ unsigned long flags;
65744+
65745+ if (unlikely(!(gr_status & GR_READY)))
65746+ return;
65747+
65748+ flags = pax_get_flags(task);
65749+
65750+ proc = task->acl;
65751+
65752+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65753+ flags &= ~MF_PAX_PAGEEXEC;
65754+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65755+ flags &= ~MF_PAX_SEGMEXEC;
65756+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65757+ flags &= ~MF_PAX_RANDMMAP;
65758+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65759+ flags &= ~MF_PAX_EMUTRAMP;
65760+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65761+ flags &= ~MF_PAX_MPROTECT;
65762+
65763+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65764+ flags |= MF_PAX_PAGEEXEC;
65765+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65766+ flags |= MF_PAX_SEGMEXEC;
65767+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65768+ flags |= MF_PAX_RANDMMAP;
65769+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65770+ flags |= MF_PAX_EMUTRAMP;
65771+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65772+ flags |= MF_PAX_MPROTECT;
65773+
65774+ pax_set_flags(task, flags);
65775+
65776+ return;
65777+}
65778+#endif
65779+
65780+int
65781+gr_handle_proc_ptrace(struct task_struct *task)
65782+{
65783+ struct file *filp;
65784+ struct task_struct *tmp = task;
65785+ struct task_struct *curtemp = current;
65786+ __u32 retmode;
65787+
65788+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65789+ if (unlikely(!(gr_status & GR_READY)))
65790+ return 0;
65791+#endif
65792+
65793+ read_lock(&tasklist_lock);
65794+ read_lock(&grsec_exec_file_lock);
65795+ filp = task->exec_file;
65796+
65797+ while (task_pid_nr(tmp) > 0) {
65798+ if (tmp == curtemp)
65799+ break;
65800+ tmp = tmp->real_parent;
65801+ }
65802+
65803+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65804+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65805+ read_unlock(&grsec_exec_file_lock);
65806+ read_unlock(&tasklist_lock);
65807+ return 1;
65808+ }
65809+
65810+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65811+ if (!(gr_status & GR_READY)) {
65812+ read_unlock(&grsec_exec_file_lock);
65813+ read_unlock(&tasklist_lock);
65814+ return 0;
65815+ }
65816+#endif
65817+
65818+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65819+ read_unlock(&grsec_exec_file_lock);
65820+ read_unlock(&tasklist_lock);
65821+
65822+ if (retmode & GR_NOPTRACE)
65823+ return 1;
65824+
65825+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65826+ && (current->acl != task->acl || (current->acl != current->role->root_label
65827+ && task_pid_nr(current) != task_pid_nr(task))))
65828+ return 1;
65829+
65830+ return 0;
65831+}
65832+
65833+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65834+{
65835+ if (unlikely(!(gr_status & GR_READY)))
65836+ return;
65837+
65838+ if (!(current->role->roletype & GR_ROLE_GOD))
65839+ return;
65840+
65841+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65842+ p->role->rolename, gr_task_roletype_to_char(p),
65843+ p->acl->filename);
65844+}
65845+
65846+int
65847+gr_handle_ptrace(struct task_struct *task, const long request)
65848+{
65849+ struct task_struct *tmp = task;
65850+ struct task_struct *curtemp = current;
65851+ __u32 retmode;
65852+
65853+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65854+ if (unlikely(!(gr_status & GR_READY)))
65855+ return 0;
65856+#endif
65857+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65858+ read_lock(&tasklist_lock);
65859+ while (task_pid_nr(tmp) > 0) {
65860+ if (tmp == curtemp)
65861+ break;
65862+ tmp = tmp->real_parent;
65863+ }
65864+
65865+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65866+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65867+ read_unlock(&tasklist_lock);
65868+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65869+ return 1;
65870+ }
65871+ read_unlock(&tasklist_lock);
65872+ }
65873+
65874+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65875+ if (!(gr_status & GR_READY))
65876+ return 0;
65877+#endif
65878+
65879+ read_lock(&grsec_exec_file_lock);
65880+ if (unlikely(!task->exec_file)) {
65881+ read_unlock(&grsec_exec_file_lock);
65882+ return 0;
65883+ }
65884+
65885+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65886+ read_unlock(&grsec_exec_file_lock);
65887+
65888+ if (retmode & GR_NOPTRACE) {
65889+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65890+ return 1;
65891+ }
65892+
65893+ if (retmode & GR_PTRACERD) {
65894+ switch (request) {
65895+ case PTRACE_SEIZE:
65896+ case PTRACE_POKETEXT:
65897+ case PTRACE_POKEDATA:
65898+ case PTRACE_POKEUSR:
65899+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65900+ case PTRACE_SETREGS:
65901+ case PTRACE_SETFPREGS:
65902+#endif
65903+#ifdef CONFIG_X86
65904+ case PTRACE_SETFPXREGS:
65905+#endif
65906+#ifdef CONFIG_ALTIVEC
65907+ case PTRACE_SETVRREGS:
65908+#endif
65909+ return 1;
65910+ default:
65911+ return 0;
65912+ }
65913+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65914+ !(current->role->roletype & GR_ROLE_GOD) &&
65915+ (current->acl != task->acl)) {
65916+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65917+ return 1;
65918+ }
65919+
65920+ return 0;
65921+}
65922+
65923+static int is_writable_mmap(const struct file *filp)
65924+{
65925+ struct task_struct *task = current;
65926+ struct acl_object_label *obj, *obj2;
65927+
65928+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65929+ !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))) {
65930+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65931+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65932+ task->role->root_label);
65933+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65934+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65935+ return 1;
65936+ }
65937+ }
65938+ return 0;
65939+}
65940+
65941+int
65942+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
65943+{
65944+ __u32 mode;
65945+
65946+ if (unlikely(!file || !(prot & PROT_EXEC)))
65947+ return 1;
65948+
65949+ if (is_writable_mmap(file))
65950+ return 0;
65951+
65952+ mode =
65953+ gr_search_file(file->f_path.dentry,
65954+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65955+ file->f_path.mnt);
65956+
65957+ if (!gr_tpe_allow(file))
65958+ return 0;
65959+
65960+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65961+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65962+ return 0;
65963+ } else if (unlikely(!(mode & GR_EXEC))) {
65964+ return 0;
65965+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65966+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65967+ return 1;
65968+ }
65969+
65970+ return 1;
65971+}
65972+
65973+int
65974+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65975+{
65976+ __u32 mode;
65977+
65978+ if (unlikely(!file || !(prot & PROT_EXEC)))
65979+ return 1;
65980+
65981+ if (is_writable_mmap(file))
65982+ return 0;
65983+
65984+ mode =
65985+ gr_search_file(file->f_path.dentry,
65986+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65987+ file->f_path.mnt);
65988+
65989+ if (!gr_tpe_allow(file))
65990+ return 0;
65991+
65992+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65993+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65994+ return 0;
65995+ } else if (unlikely(!(mode & GR_EXEC))) {
65996+ return 0;
65997+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65998+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65999+ return 1;
66000+ }
66001+
66002+ return 1;
66003+}
66004+
66005+void
66006+gr_acl_handle_psacct(struct task_struct *task, const long code)
66007+{
66008+ unsigned long runtime;
66009+ unsigned long cputime;
66010+ unsigned int wday, cday;
66011+ __u8 whr, chr;
66012+ __u8 wmin, cmin;
66013+ __u8 wsec, csec;
66014+ struct timespec timeval;
66015+
66016+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66017+ !(task->acl->mode & GR_PROCACCT)))
66018+ return;
66019+
66020+ do_posix_clock_monotonic_gettime(&timeval);
66021+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66022+ wday = runtime / (3600 * 24);
66023+ runtime -= wday * (3600 * 24);
66024+ whr = runtime / 3600;
66025+ runtime -= whr * 3600;
66026+ wmin = runtime / 60;
66027+ runtime -= wmin * 60;
66028+ wsec = runtime;
66029+
66030+ cputime = (task->utime + task->stime) / HZ;
66031+ cday = cputime / (3600 * 24);
66032+ cputime -= cday * (3600 * 24);
66033+ chr = cputime / 3600;
66034+ cputime -= chr * 3600;
66035+ cmin = cputime / 60;
66036+ cputime -= cmin * 60;
66037+ csec = cputime;
66038+
66039+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66040+
66041+ return;
66042+}
66043+
66044+void gr_set_kernel_label(struct task_struct *task)
66045+{
66046+ if (gr_status & GR_READY) {
66047+ task->role = kernel_role;
66048+ task->acl = kernel_role->root_label;
66049+ }
66050+ return;
66051+}
66052+
66053+#ifdef CONFIG_TASKSTATS
66054+int gr_is_taskstats_denied(int pid)
66055+{
66056+ struct task_struct *task;
66057+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66058+ const struct cred *cred;
66059+#endif
66060+ int ret = 0;
66061+
66062+ /* restrict taskstats viewing to un-chrooted root users
66063+ who have the 'view' subject flag if the RBAC system is enabled
66064+ */
66065+
66066+ rcu_read_lock();
66067+ read_lock(&tasklist_lock);
66068+ task = find_task_by_vpid(pid);
66069+ if (task) {
66070+#ifdef CONFIG_GRKERNSEC_CHROOT
66071+ if (proc_is_chrooted(task))
66072+ ret = -EACCES;
66073+#endif
66074+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66075+ cred = __task_cred(task);
66076+#ifdef CONFIG_GRKERNSEC_PROC_USER
66077+ if (gr_is_global_nonroot(cred->uid))
66078+ ret = -EACCES;
66079+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66080+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66081+ ret = -EACCES;
66082+#endif
66083+#endif
66084+ if (gr_status & GR_READY) {
66085+ if (!(task->acl->mode & GR_VIEW))
66086+ ret = -EACCES;
66087+ }
66088+ } else
66089+ ret = -ENOENT;
66090+
66091+ read_unlock(&tasklist_lock);
66092+ rcu_read_unlock();
66093+
66094+ return ret;
66095+}
66096+#endif
66097+
66098+/* AUXV entries are filled via a descendant of search_binary_handler
66099+ after we've already applied the subject for the target
66100+*/
66101+int gr_acl_enable_at_secure(void)
66102+{
66103+ if (unlikely(!(gr_status & GR_READY)))
66104+ return 0;
66105+
66106+ if (current->acl->mode & GR_ATSECURE)
66107+ return 1;
66108+
66109+ return 0;
66110+}
66111+
66112+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66113+{
66114+ struct task_struct *task = current;
66115+ struct dentry *dentry = file->f_path.dentry;
66116+ struct vfsmount *mnt = file->f_path.mnt;
66117+ struct acl_object_label *obj, *tmp;
66118+ struct acl_subject_label *subj;
66119+ unsigned int bufsize;
66120+ int is_not_root;
66121+ char *path;
66122+ dev_t dev = __get_dev(dentry);
66123+
66124+ if (unlikely(!(gr_status & GR_READY)))
66125+ return 1;
66126+
66127+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66128+ return 1;
66129+
66130+ /* ignore Eric Biederman */
66131+ if (IS_PRIVATE(dentry->d_inode))
66132+ return 1;
66133+
66134+ subj = task->acl;
66135+ read_lock(&gr_inode_lock);
66136+ do {
66137+ obj = lookup_acl_obj_label(ino, dev, subj);
66138+ if (obj != NULL) {
66139+ read_unlock(&gr_inode_lock);
66140+ return (obj->mode & GR_FIND) ? 1 : 0;
66141+ }
66142+ } while ((subj = subj->parent_subject));
66143+ read_unlock(&gr_inode_lock);
66144+
66145+ /* this is purely an optimization since we're looking for an object
66146+ for the directory we're doing a readdir on
66147+ if it's possible for any globbed object to match the entry we're
66148+ filling into the directory, then the object we find here will be
66149+ an anchor point with attached globbed objects
66150+ */
66151+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66152+ if (obj->globbed == NULL)
66153+ return (obj->mode & GR_FIND) ? 1 : 0;
66154+
66155+ is_not_root = ((obj->filename[0] == '/') &&
66156+ (obj->filename[1] == '\0')) ? 0 : 1;
66157+ bufsize = PAGE_SIZE - namelen - is_not_root;
66158+
66159+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66160+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66161+ return 1;
66162+
66163+ preempt_disable();
66164+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66165+ bufsize);
66166+
66167+ bufsize = strlen(path);
66168+
66169+ /* if base is "/", don't append an additional slash */
66170+ if (is_not_root)
66171+ *(path + bufsize) = '/';
66172+ memcpy(path + bufsize + is_not_root, name, namelen);
66173+ *(path + bufsize + namelen + is_not_root) = '\0';
66174+
66175+ tmp = obj->globbed;
66176+ while (tmp) {
66177+ if (!glob_match(tmp->filename, path)) {
66178+ preempt_enable();
66179+ return (tmp->mode & GR_FIND) ? 1 : 0;
66180+ }
66181+ tmp = tmp->next;
66182+ }
66183+ preempt_enable();
66184+ return (obj->mode & GR_FIND) ? 1 : 0;
66185+}
66186+
66187+void gr_put_exec_file(struct task_struct *task)
66188+{
66189+ struct file *filp;
66190+
66191+ write_lock(&grsec_exec_file_lock);
66192+ filp = task->exec_file;
66193+ task->exec_file = NULL;
66194+ write_unlock(&grsec_exec_file_lock);
66195+
66196+ if (filp)
66197+ fput(filp);
66198+
66199+ return;
66200+}
66201+
66202+
66203+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66204+EXPORT_SYMBOL(gr_acl_is_enabled);
66205+#endif
66206+EXPORT_SYMBOL(gr_set_kernel_label);
66207+#ifdef CONFIG_SECURITY
66208+EXPORT_SYMBOL(gr_check_user_change);
66209+EXPORT_SYMBOL(gr_check_group_change);
66210+#endif
66211+
66212diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66213new file mode 100644
66214index 0000000..34fefda
66215--- /dev/null
66216+++ b/grsecurity/gracl_alloc.c
66217@@ -0,0 +1,105 @@
66218+#include <linux/kernel.h>
66219+#include <linux/mm.h>
66220+#include <linux/slab.h>
66221+#include <linux/vmalloc.h>
66222+#include <linux/gracl.h>
66223+#include <linux/grsecurity.h>
66224+
66225+static unsigned long alloc_stack_next = 1;
66226+static unsigned long alloc_stack_size = 1;
66227+static void **alloc_stack;
66228+
66229+static __inline__ int
66230+alloc_pop(void)
66231+{
66232+ if (alloc_stack_next == 1)
66233+ return 0;
66234+
66235+ kfree(alloc_stack[alloc_stack_next - 2]);
66236+
66237+ alloc_stack_next--;
66238+
66239+ return 1;
66240+}
66241+
66242+static __inline__ int
66243+alloc_push(void *buf)
66244+{
66245+ if (alloc_stack_next >= alloc_stack_size)
66246+ return 1;
66247+
66248+ alloc_stack[alloc_stack_next - 1] = buf;
66249+
66250+ alloc_stack_next++;
66251+
66252+ return 0;
66253+}
66254+
66255+void *
66256+acl_alloc(unsigned long len)
66257+{
66258+ void *ret = NULL;
66259+
66260+ if (!len || len > PAGE_SIZE)
66261+ goto out;
66262+
66263+ ret = kmalloc(len, GFP_KERNEL);
66264+
66265+ if (ret) {
66266+ if (alloc_push(ret)) {
66267+ kfree(ret);
66268+ ret = NULL;
66269+ }
66270+ }
66271+
66272+out:
66273+ return ret;
66274+}
66275+
66276+void *
66277+acl_alloc_num(unsigned long num, unsigned long len)
66278+{
66279+ if (!len || (num > (PAGE_SIZE / len)))
66280+ return NULL;
66281+
66282+ return acl_alloc(num * len);
66283+}
66284+
66285+void
66286+acl_free_all(void)
66287+{
66288+ if (gr_acl_is_enabled() || !alloc_stack)
66289+ return;
66290+
66291+ while (alloc_pop()) ;
66292+
66293+ if (alloc_stack) {
66294+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66295+ kfree(alloc_stack);
66296+ else
66297+ vfree(alloc_stack);
66298+ }
66299+
66300+ alloc_stack = NULL;
66301+ alloc_stack_size = 1;
66302+ alloc_stack_next = 1;
66303+
66304+ return;
66305+}
66306+
66307+int
66308+acl_alloc_stack_init(unsigned long size)
66309+{
66310+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66311+ alloc_stack =
66312+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66313+ else
66314+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66315+
66316+ alloc_stack_size = size;
66317+
66318+ if (!alloc_stack)
66319+ return 0;
66320+ else
66321+ return 1;
66322+}
66323diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66324new file mode 100644
66325index 0000000..bdd51ea
66326--- /dev/null
66327+++ b/grsecurity/gracl_cap.c
66328@@ -0,0 +1,110 @@
66329+#include <linux/kernel.h>
66330+#include <linux/module.h>
66331+#include <linux/sched.h>
66332+#include <linux/gracl.h>
66333+#include <linux/grsecurity.h>
66334+#include <linux/grinternal.h>
66335+
66336+extern const char *captab_log[];
66337+extern int captab_log_entries;
66338+
66339+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66340+{
66341+ struct acl_subject_label *curracl;
66342+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66343+ kernel_cap_t cap_audit = __cap_empty_set;
66344+
66345+ if (!gr_acl_is_enabled())
66346+ return 1;
66347+
66348+ curracl = task->acl;
66349+
66350+ cap_drop = curracl->cap_lower;
66351+ cap_mask = curracl->cap_mask;
66352+ cap_audit = curracl->cap_invert_audit;
66353+
66354+ while ((curracl = curracl->parent_subject)) {
66355+ /* if the cap isn't specified in the current computed mask but is specified in the
66356+ current level subject, and is lowered in the current level subject, then add
66357+ it to the set of dropped capabilities
66358+ otherwise, add the current level subject's mask to the current computed mask
66359+ */
66360+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66361+ cap_raise(cap_mask, cap);
66362+ if (cap_raised(curracl->cap_lower, cap))
66363+ cap_raise(cap_drop, cap);
66364+ if (cap_raised(curracl->cap_invert_audit, cap))
66365+ cap_raise(cap_audit, cap);
66366+ }
66367+ }
66368+
66369+ if (!cap_raised(cap_drop, cap)) {
66370+ if (cap_raised(cap_audit, cap))
66371+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66372+ return 1;
66373+ }
66374+
66375+ curracl = task->acl;
66376+
66377+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66378+ && cap_raised(cred->cap_effective, cap)) {
66379+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66380+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66381+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66382+ gr_to_filename(task->exec_file->f_path.dentry,
66383+ task->exec_file->f_path.mnt) : curracl->filename,
66384+ curracl->filename, 0UL,
66385+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66386+ return 1;
66387+ }
66388+
66389+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66390+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66391+
66392+ return 0;
66393+}
66394+
66395+int
66396+gr_acl_is_capable(const int cap)
66397+{
66398+ return gr_task_acl_is_capable(current, current_cred(), cap);
66399+}
66400+
66401+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66402+{
66403+ struct acl_subject_label *curracl;
66404+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66405+
66406+ if (!gr_acl_is_enabled())
66407+ return 1;
66408+
66409+ curracl = task->acl;
66410+
66411+ cap_drop = curracl->cap_lower;
66412+ cap_mask = curracl->cap_mask;
66413+
66414+ while ((curracl = curracl->parent_subject)) {
66415+ /* if the cap isn't specified in the current computed mask but is specified in the
66416+ current level subject, and is lowered in the current level subject, then add
66417+ it to the set of dropped capabilities
66418+ otherwise, add the current level subject's mask to the current computed mask
66419+ */
66420+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66421+ cap_raise(cap_mask, cap);
66422+ if (cap_raised(curracl->cap_lower, cap))
66423+ cap_raise(cap_drop, cap);
66424+ }
66425+ }
66426+
66427+ if (!cap_raised(cap_drop, cap))
66428+ return 1;
66429+
66430+ return 0;
66431+}
66432+
66433+int
66434+gr_acl_is_capable_nolog(const int cap)
66435+{
66436+ return gr_task_acl_is_capable_nolog(current, cap);
66437+}
66438+
66439diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66440new file mode 100644
66441index 0000000..a43dd06
66442--- /dev/null
66443+++ b/grsecurity/gracl_compat.c
66444@@ -0,0 +1,269 @@
66445+#include <linux/kernel.h>
66446+#include <linux/gracl.h>
66447+#include <linux/compat.h>
66448+#include <linux/gracl_compat.h>
66449+
66450+#include <asm/uaccess.h>
66451+
66452+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66453+{
66454+ struct gr_arg_wrapper_compat uwrapcompat;
66455+
66456+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66457+ return -EFAULT;
66458+
66459+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66460+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66461+ return -EINVAL;
66462+
66463+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66464+ uwrap->version = uwrapcompat.version;
66465+ uwrap->size = sizeof(struct gr_arg);
66466+
66467+ return 0;
66468+}
66469+
66470+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66471+{
66472+ struct gr_arg_compat argcompat;
66473+
66474+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66475+ return -EFAULT;
66476+
66477+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66478+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66479+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66480+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66481+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66482+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66483+
66484+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66485+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66486+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66487+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66488+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66489+ arg->segv_device = argcompat.segv_device;
66490+ arg->segv_inode = argcompat.segv_inode;
66491+ arg->segv_uid = argcompat.segv_uid;
66492+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66493+ arg->mode = argcompat.mode;
66494+
66495+ return 0;
66496+}
66497+
66498+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66499+{
66500+ struct acl_object_label_compat objcompat;
66501+
66502+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66503+ return -EFAULT;
66504+
66505+ obj->filename = compat_ptr(objcompat.filename);
66506+ obj->inode = objcompat.inode;
66507+ obj->device = objcompat.device;
66508+ obj->mode = objcompat.mode;
66509+
66510+ obj->nested = compat_ptr(objcompat.nested);
66511+ obj->globbed = compat_ptr(objcompat.globbed);
66512+
66513+ obj->prev = compat_ptr(objcompat.prev);
66514+ obj->next = compat_ptr(objcompat.next);
66515+
66516+ return 0;
66517+}
66518+
66519+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66520+{
66521+ unsigned int i;
66522+ struct acl_subject_label_compat subjcompat;
66523+
66524+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66525+ return -EFAULT;
66526+
66527+ subj->filename = compat_ptr(subjcompat.filename);
66528+ subj->inode = subjcompat.inode;
66529+ subj->device = subjcompat.device;
66530+ subj->mode = subjcompat.mode;
66531+ subj->cap_mask = subjcompat.cap_mask;
66532+ subj->cap_lower = subjcompat.cap_lower;
66533+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66534+
66535+ for (i = 0; i < GR_NLIMITS; i++) {
66536+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66537+ subj->res[i].rlim_cur = RLIM_INFINITY;
66538+ else
66539+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66540+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66541+ subj->res[i].rlim_max = RLIM_INFINITY;
66542+ else
66543+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66544+ }
66545+ subj->resmask = subjcompat.resmask;
66546+
66547+ subj->user_trans_type = subjcompat.user_trans_type;
66548+ subj->group_trans_type = subjcompat.group_trans_type;
66549+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66550+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66551+ subj->user_trans_num = subjcompat.user_trans_num;
66552+ subj->group_trans_num = subjcompat.group_trans_num;
66553+
66554+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66555+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66556+ subj->ip_type = subjcompat.ip_type;
66557+ subj->ips = compat_ptr(subjcompat.ips);
66558+ subj->ip_num = subjcompat.ip_num;
66559+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66560+
66561+ subj->crashes = subjcompat.crashes;
66562+ subj->expires = subjcompat.expires;
66563+
66564+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66565+ subj->hash = compat_ptr(subjcompat.hash);
66566+ subj->prev = compat_ptr(subjcompat.prev);
66567+ subj->next = compat_ptr(subjcompat.next);
66568+
66569+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66570+ subj->obj_hash_size = subjcompat.obj_hash_size;
66571+ subj->pax_flags = subjcompat.pax_flags;
66572+
66573+ return 0;
66574+}
66575+
66576+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66577+{
66578+ struct acl_role_label_compat rolecompat;
66579+
66580+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66581+ return -EFAULT;
66582+
66583+ role->rolename = compat_ptr(rolecompat.rolename);
66584+ role->uidgid = rolecompat.uidgid;
66585+ role->roletype = rolecompat.roletype;
66586+
66587+ role->auth_attempts = rolecompat.auth_attempts;
66588+ role->expires = rolecompat.expires;
66589+
66590+ role->root_label = compat_ptr(rolecompat.root_label);
66591+ role->hash = compat_ptr(rolecompat.hash);
66592+
66593+ role->prev = compat_ptr(rolecompat.prev);
66594+ role->next = compat_ptr(rolecompat.next);
66595+
66596+ role->transitions = compat_ptr(rolecompat.transitions);
66597+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66598+ role->domain_children = compat_ptr(rolecompat.domain_children);
66599+ role->domain_child_num = rolecompat.domain_child_num;
66600+
66601+ role->umask = rolecompat.umask;
66602+
66603+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66604+ role->subj_hash_size = rolecompat.subj_hash_size;
66605+
66606+ return 0;
66607+}
66608+
66609+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66610+{
66611+ struct role_allowed_ip_compat roleip_compat;
66612+
66613+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66614+ return -EFAULT;
66615+
66616+ roleip->addr = roleip_compat.addr;
66617+ roleip->netmask = roleip_compat.netmask;
66618+
66619+ roleip->prev = compat_ptr(roleip_compat.prev);
66620+ roleip->next = compat_ptr(roleip_compat.next);
66621+
66622+ return 0;
66623+}
66624+
66625+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66626+{
66627+ struct role_transition_compat trans_compat;
66628+
66629+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66630+ return -EFAULT;
66631+
66632+ trans->rolename = compat_ptr(trans_compat.rolename);
66633+
66634+ trans->prev = compat_ptr(trans_compat.prev);
66635+ trans->next = compat_ptr(trans_compat.next);
66636+
66637+ return 0;
66638+
66639+}
66640+
66641+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66642+{
66643+ struct gr_hash_struct_compat hash_compat;
66644+
66645+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66646+ return -EFAULT;
66647+
66648+ hash->table = compat_ptr(hash_compat.table);
66649+ hash->nametable = compat_ptr(hash_compat.nametable);
66650+ hash->first = compat_ptr(hash_compat.first);
66651+
66652+ hash->table_size = hash_compat.table_size;
66653+ hash->used_size = hash_compat.used_size;
66654+
66655+ hash->type = hash_compat.type;
66656+
66657+ return 0;
66658+}
66659+
66660+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66661+{
66662+ compat_uptr_t ptrcompat;
66663+
66664+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66665+ return -EFAULT;
66666+
66667+ *(void **)ptr = compat_ptr(ptrcompat);
66668+
66669+ return 0;
66670+}
66671+
66672+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66673+{
66674+ struct acl_ip_label_compat ip_compat;
66675+
66676+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66677+ return -EFAULT;
66678+
66679+ ip->iface = compat_ptr(ip_compat.iface);
66680+ ip->addr = ip_compat.addr;
66681+ ip->netmask = ip_compat.netmask;
66682+ ip->low = ip_compat.low;
66683+ ip->high = ip_compat.high;
66684+ ip->mode = ip_compat.mode;
66685+ ip->type = ip_compat.type;
66686+
66687+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66688+
66689+ ip->prev = compat_ptr(ip_compat.prev);
66690+ ip->next = compat_ptr(ip_compat.next);
66691+
66692+ return 0;
66693+}
66694+
66695+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66696+{
66697+ struct sprole_pw_compat pw_compat;
66698+
66699+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66700+ return -EFAULT;
66701+
66702+ pw->rolename = compat_ptr(pw_compat.rolename);
66703+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66704+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66705+
66706+ return 0;
66707+}
66708+
66709+size_t get_gr_arg_wrapper_size_compat(void)
66710+{
66711+ return sizeof(struct gr_arg_wrapper_compat);
66712+}
66713+
66714diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66715new file mode 100644
66716index 0000000..a340c17
66717--- /dev/null
66718+++ b/grsecurity/gracl_fs.c
66719@@ -0,0 +1,431 @@
66720+#include <linux/kernel.h>
66721+#include <linux/sched.h>
66722+#include <linux/types.h>
66723+#include <linux/fs.h>
66724+#include <linux/file.h>
66725+#include <linux/stat.h>
66726+#include <linux/grsecurity.h>
66727+#include <linux/grinternal.h>
66728+#include <linux/gracl.h>
66729+
66730+umode_t
66731+gr_acl_umask(void)
66732+{
66733+ if (unlikely(!gr_acl_is_enabled()))
66734+ return 0;
66735+
66736+ return current->role->umask;
66737+}
66738+
66739+__u32
66740+gr_acl_handle_hidden_file(const struct dentry * dentry,
66741+ const struct vfsmount * mnt)
66742+{
66743+ __u32 mode;
66744+
66745+ if (unlikely(!dentry->d_inode))
66746+ return GR_FIND;
66747+
66748+ mode =
66749+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66750+
66751+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66752+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66753+ return mode;
66754+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66755+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66756+ return 0;
66757+ } else if (unlikely(!(mode & GR_FIND)))
66758+ return 0;
66759+
66760+ return GR_FIND;
66761+}
66762+
66763+__u32
66764+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66765+ int acc_mode)
66766+{
66767+ __u32 reqmode = GR_FIND;
66768+ __u32 mode;
66769+
66770+ if (unlikely(!dentry->d_inode))
66771+ return reqmode;
66772+
66773+ if (acc_mode & MAY_APPEND)
66774+ reqmode |= GR_APPEND;
66775+ else if (acc_mode & MAY_WRITE)
66776+ reqmode |= GR_WRITE;
66777+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66778+ reqmode |= GR_READ;
66779+
66780+ mode =
66781+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66782+ mnt);
66783+
66784+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66785+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66786+ reqmode & GR_READ ? " reading" : "",
66787+ reqmode & GR_WRITE ? " writing" : reqmode &
66788+ GR_APPEND ? " appending" : "");
66789+ return reqmode;
66790+ } else
66791+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66792+ {
66793+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66794+ reqmode & GR_READ ? " reading" : "",
66795+ reqmode & GR_WRITE ? " writing" : reqmode &
66796+ GR_APPEND ? " appending" : "");
66797+ return 0;
66798+ } else if (unlikely((mode & reqmode) != reqmode))
66799+ return 0;
66800+
66801+ return reqmode;
66802+}
66803+
66804+__u32
66805+gr_acl_handle_creat(const struct dentry * dentry,
66806+ const struct dentry * p_dentry,
66807+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66808+ const int imode)
66809+{
66810+ __u32 reqmode = GR_WRITE | GR_CREATE;
66811+ __u32 mode;
66812+
66813+ if (acc_mode & MAY_APPEND)
66814+ reqmode |= GR_APPEND;
66815+ // if a directory was required or the directory already exists, then
66816+ // don't count this open as a read
66817+ if ((acc_mode & MAY_READ) &&
66818+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66819+ reqmode |= GR_READ;
66820+ if ((open_flags & O_CREAT) &&
66821+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66822+ reqmode |= GR_SETID;
66823+
66824+ mode =
66825+ gr_check_create(dentry, p_dentry, p_mnt,
66826+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66827+
66828+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66829+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66830+ reqmode & GR_READ ? " reading" : "",
66831+ reqmode & GR_WRITE ? " writing" : reqmode &
66832+ GR_APPEND ? " appending" : "");
66833+ return reqmode;
66834+ } else
66835+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66836+ {
66837+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66838+ reqmode & GR_READ ? " reading" : "",
66839+ reqmode & GR_WRITE ? " writing" : reqmode &
66840+ GR_APPEND ? " appending" : "");
66841+ return 0;
66842+ } else if (unlikely((mode & reqmode) != reqmode))
66843+ return 0;
66844+
66845+ return reqmode;
66846+}
66847+
66848+__u32
66849+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66850+ const int fmode)
66851+{
66852+ __u32 mode, reqmode = GR_FIND;
66853+
66854+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66855+ reqmode |= GR_EXEC;
66856+ if (fmode & S_IWOTH)
66857+ reqmode |= GR_WRITE;
66858+ if (fmode & S_IROTH)
66859+ reqmode |= GR_READ;
66860+
66861+ mode =
66862+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66863+ mnt);
66864+
66865+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66866+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66867+ reqmode & GR_READ ? " reading" : "",
66868+ reqmode & GR_WRITE ? " writing" : "",
66869+ reqmode & GR_EXEC ? " executing" : "");
66870+ return reqmode;
66871+ } else
66872+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66873+ {
66874+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66875+ reqmode & GR_READ ? " reading" : "",
66876+ reqmode & GR_WRITE ? " writing" : "",
66877+ reqmode & GR_EXEC ? " executing" : "");
66878+ return 0;
66879+ } else if (unlikely((mode & reqmode) != reqmode))
66880+ return 0;
66881+
66882+ return reqmode;
66883+}
66884+
66885+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66886+{
66887+ __u32 mode;
66888+
66889+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66890+
66891+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66892+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66893+ return mode;
66894+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66895+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66896+ return 0;
66897+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66898+ return 0;
66899+
66900+ return (reqmode);
66901+}
66902+
66903+__u32
66904+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66905+{
66906+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66907+}
66908+
66909+__u32
66910+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66911+{
66912+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66913+}
66914+
66915+__u32
66916+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66917+{
66918+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66919+}
66920+
66921+__u32
66922+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66923+{
66924+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66925+}
66926+
66927+__u32
66928+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66929+ umode_t *modeptr)
66930+{
66931+ umode_t mode;
66932+
66933+ *modeptr &= ~gr_acl_umask();
66934+ mode = *modeptr;
66935+
66936+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66937+ return 1;
66938+
66939+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
66940+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
66941+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
66942+ GR_CHMOD_ACL_MSG);
66943+ } else {
66944+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
66945+ }
66946+}
66947+
66948+__u32
66949+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
66950+{
66951+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
66952+}
66953+
66954+__u32
66955+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
66956+{
66957+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
66958+}
66959+
66960+__u32
66961+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
66962+{
66963+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
66964+}
66965+
66966+__u32
66967+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
66968+{
66969+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
66970+ GR_UNIXCONNECT_ACL_MSG);
66971+}
66972+
66973+/* hardlinks require at minimum create and link permission,
66974+ any additional privilege required is based on the
66975+ privilege of the file being linked to
66976+*/
66977+__u32
66978+gr_acl_handle_link(const struct dentry * new_dentry,
66979+ const struct dentry * parent_dentry,
66980+ const struct vfsmount * parent_mnt,
66981+ const struct dentry * old_dentry,
66982+ const struct vfsmount * old_mnt, const struct filename *to)
66983+{
66984+ __u32 mode;
66985+ __u32 needmode = GR_CREATE | GR_LINK;
66986+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
66987+
66988+ mode =
66989+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
66990+ old_mnt);
66991+
66992+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
66993+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66994+ return mode;
66995+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66996+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66997+ return 0;
66998+ } else if (unlikely((mode & needmode) != needmode))
66999+ return 0;
67000+
67001+ return 1;
67002+}
67003+
67004+__u32
67005+gr_acl_handle_symlink(const struct dentry * new_dentry,
67006+ const struct dentry * parent_dentry,
67007+ const struct vfsmount * parent_mnt, const struct filename *from)
67008+{
67009+ __u32 needmode = GR_WRITE | GR_CREATE;
67010+ __u32 mode;
67011+
67012+ mode =
67013+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67014+ GR_CREATE | GR_AUDIT_CREATE |
67015+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67016+
67017+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67018+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67019+ return mode;
67020+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67021+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67022+ return 0;
67023+ } else if (unlikely((mode & needmode) != needmode))
67024+ return 0;
67025+
67026+ return (GR_WRITE | GR_CREATE);
67027+}
67028+
67029+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)
67030+{
67031+ __u32 mode;
67032+
67033+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67034+
67035+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67036+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67037+ return mode;
67038+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67039+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67040+ return 0;
67041+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67042+ return 0;
67043+
67044+ return (reqmode);
67045+}
67046+
67047+__u32
67048+gr_acl_handle_mknod(const struct dentry * new_dentry,
67049+ const struct dentry * parent_dentry,
67050+ const struct vfsmount * parent_mnt,
67051+ const int mode)
67052+{
67053+ __u32 reqmode = GR_WRITE | GR_CREATE;
67054+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67055+ reqmode |= GR_SETID;
67056+
67057+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67058+ reqmode, GR_MKNOD_ACL_MSG);
67059+}
67060+
67061+__u32
67062+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67063+ const struct dentry *parent_dentry,
67064+ const struct vfsmount *parent_mnt)
67065+{
67066+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67067+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67068+}
67069+
67070+#define RENAME_CHECK_SUCCESS(old, new) \
67071+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67072+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67073+
67074+int
67075+gr_acl_handle_rename(struct dentry *new_dentry,
67076+ struct dentry *parent_dentry,
67077+ const struct vfsmount *parent_mnt,
67078+ struct dentry *old_dentry,
67079+ struct inode *old_parent_inode,
67080+ struct vfsmount *old_mnt, const struct filename *newname)
67081+{
67082+ __u32 comp1, comp2;
67083+ int error = 0;
67084+
67085+ if (unlikely(!gr_acl_is_enabled()))
67086+ return 0;
67087+
67088+ if (!new_dentry->d_inode) {
67089+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67090+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67091+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67092+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67093+ GR_DELETE | GR_AUDIT_DELETE |
67094+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67095+ GR_SUPPRESS, old_mnt);
67096+ } else {
67097+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67098+ GR_CREATE | GR_DELETE |
67099+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67100+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67101+ GR_SUPPRESS, parent_mnt);
67102+ comp2 =
67103+ gr_search_file(old_dentry,
67104+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67105+ GR_DELETE | GR_AUDIT_DELETE |
67106+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67107+ }
67108+
67109+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67110+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67111+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67112+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67113+ && !(comp2 & GR_SUPPRESS)) {
67114+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67115+ error = -EACCES;
67116+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67117+ error = -EACCES;
67118+
67119+ return error;
67120+}
67121+
67122+void
67123+gr_acl_handle_exit(void)
67124+{
67125+ u16 id;
67126+ char *rolename;
67127+
67128+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67129+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67130+ id = current->acl_role_id;
67131+ rolename = current->role->rolename;
67132+ gr_set_acls(1);
67133+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67134+ }
67135+
67136+ gr_put_exec_file(current);
67137+ return;
67138+}
67139+
67140+int
67141+gr_acl_handle_procpidmem(const struct task_struct *task)
67142+{
67143+ if (unlikely(!gr_acl_is_enabled()))
67144+ return 0;
67145+
67146+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67147+ return -EACCES;
67148+
67149+ return 0;
67150+}
67151diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67152new file mode 100644
67153index 0000000..f056b81
67154--- /dev/null
67155+++ b/grsecurity/gracl_ip.c
67156@@ -0,0 +1,386 @@
67157+#include <linux/kernel.h>
67158+#include <asm/uaccess.h>
67159+#include <asm/errno.h>
67160+#include <net/sock.h>
67161+#include <linux/file.h>
67162+#include <linux/fs.h>
67163+#include <linux/net.h>
67164+#include <linux/in.h>
67165+#include <linux/skbuff.h>
67166+#include <linux/ip.h>
67167+#include <linux/udp.h>
67168+#include <linux/types.h>
67169+#include <linux/sched.h>
67170+#include <linux/netdevice.h>
67171+#include <linux/inetdevice.h>
67172+#include <linux/gracl.h>
67173+#include <linux/grsecurity.h>
67174+#include <linux/grinternal.h>
67175+
67176+#define GR_BIND 0x01
67177+#define GR_CONNECT 0x02
67178+#define GR_INVERT 0x04
67179+#define GR_BINDOVERRIDE 0x08
67180+#define GR_CONNECTOVERRIDE 0x10
67181+#define GR_SOCK_FAMILY 0x20
67182+
67183+static const char * gr_protocols[IPPROTO_MAX] = {
67184+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67185+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67186+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67187+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67188+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67189+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67190+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67191+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67192+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67193+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67194+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67195+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67196+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67197+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67198+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67199+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67200+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67201+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67202+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67203+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67204+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67205+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67206+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67207+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67208+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67209+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67210+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67211+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67212+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67213+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67214+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67215+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67216+ };
67217+
67218+static const char * gr_socktypes[SOCK_MAX] = {
67219+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67220+ "unknown:7", "unknown:8", "unknown:9", "packet"
67221+ };
67222+
67223+static const char * gr_sockfamilies[AF_MAX+1] = {
67224+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67225+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67226+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67227+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67228+ };
67229+
67230+const char *
67231+gr_proto_to_name(unsigned char proto)
67232+{
67233+ return gr_protocols[proto];
67234+}
67235+
67236+const char *
67237+gr_socktype_to_name(unsigned char type)
67238+{
67239+ return gr_socktypes[type];
67240+}
67241+
67242+const char *
67243+gr_sockfamily_to_name(unsigned char family)
67244+{
67245+ return gr_sockfamilies[family];
67246+}
67247+
67248+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67249+
67250+int
67251+gr_search_socket(const int domain, const int type, const int protocol)
67252+{
67253+ struct acl_subject_label *curr;
67254+ const struct cred *cred = current_cred();
67255+
67256+ if (unlikely(!gr_acl_is_enabled()))
67257+ goto exit;
67258+
67259+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67260+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67261+ goto exit; // let the kernel handle it
67262+
67263+ curr = current->acl;
67264+
67265+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67266+ /* the family is allowed, if this is PF_INET allow it only if
67267+ the extra sock type/protocol checks pass */
67268+ if (domain == PF_INET)
67269+ goto inet_check;
67270+ goto exit;
67271+ } else {
67272+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67273+ __u32 fakeip = 0;
67274+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67275+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67276+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67277+ gr_to_filename(current->exec_file->f_path.dentry,
67278+ current->exec_file->f_path.mnt) :
67279+ curr->filename, curr->filename,
67280+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67281+ &current->signal->saved_ip);
67282+ goto exit;
67283+ }
67284+ goto exit_fail;
67285+ }
67286+
67287+inet_check:
67288+ /* the rest of this checking is for IPv4 only */
67289+ if (!curr->ips)
67290+ goto exit;
67291+
67292+ if ((curr->ip_type & (1U << type)) &&
67293+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67294+ goto exit;
67295+
67296+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67297+ /* we don't place acls on raw sockets , and sometimes
67298+ dgram/ip sockets are opened for ioctl and not
67299+ bind/connect, so we'll fake a bind learn log */
67300+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67301+ __u32 fakeip = 0;
67302+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67303+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67304+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67305+ gr_to_filename(current->exec_file->f_path.dentry,
67306+ current->exec_file->f_path.mnt) :
67307+ curr->filename, curr->filename,
67308+ &fakeip, 0, type,
67309+ protocol, GR_CONNECT, &current->signal->saved_ip);
67310+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67311+ __u32 fakeip = 0;
67312+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67313+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67314+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67315+ gr_to_filename(current->exec_file->f_path.dentry,
67316+ current->exec_file->f_path.mnt) :
67317+ curr->filename, curr->filename,
67318+ &fakeip, 0, type,
67319+ protocol, GR_BIND, &current->signal->saved_ip);
67320+ }
67321+ /* we'll log when they use connect or bind */
67322+ goto exit;
67323+ }
67324+
67325+exit_fail:
67326+ if (domain == PF_INET)
67327+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67328+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67329+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67330+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67331+ gr_socktype_to_name(type), protocol);
67332+
67333+ return 0;
67334+exit:
67335+ return 1;
67336+}
67337+
67338+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)
67339+{
67340+ if ((ip->mode & mode) &&
67341+ (ip_port >= ip->low) &&
67342+ (ip_port <= ip->high) &&
67343+ ((ntohl(ip_addr) & our_netmask) ==
67344+ (ntohl(our_addr) & our_netmask))
67345+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67346+ && (ip->type & (1U << type))) {
67347+ if (ip->mode & GR_INVERT)
67348+ return 2; // specifically denied
67349+ else
67350+ return 1; // allowed
67351+ }
67352+
67353+ return 0; // not specifically allowed, may continue parsing
67354+}
67355+
67356+static int
67357+gr_search_connectbind(const int full_mode, struct sock *sk,
67358+ struct sockaddr_in *addr, const int type)
67359+{
67360+ char iface[IFNAMSIZ] = {0};
67361+ struct acl_subject_label *curr;
67362+ struct acl_ip_label *ip;
67363+ struct inet_sock *isk;
67364+ struct net_device *dev;
67365+ struct in_device *idev;
67366+ unsigned long i;
67367+ int ret;
67368+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67369+ __u32 ip_addr = 0;
67370+ __u32 our_addr;
67371+ __u32 our_netmask;
67372+ char *p;
67373+ __u16 ip_port = 0;
67374+ const struct cred *cred = current_cred();
67375+
67376+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67377+ return 0;
67378+
67379+ curr = current->acl;
67380+ isk = inet_sk(sk);
67381+
67382+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67383+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67384+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67385+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67386+ struct sockaddr_in saddr;
67387+ int err;
67388+
67389+ saddr.sin_family = AF_INET;
67390+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67391+ saddr.sin_port = isk->inet_sport;
67392+
67393+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67394+ if (err)
67395+ return err;
67396+
67397+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67398+ if (err)
67399+ return err;
67400+ }
67401+
67402+ if (!curr->ips)
67403+ return 0;
67404+
67405+ ip_addr = addr->sin_addr.s_addr;
67406+ ip_port = ntohs(addr->sin_port);
67407+
67408+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67409+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67410+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67411+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67412+ gr_to_filename(current->exec_file->f_path.dentry,
67413+ current->exec_file->f_path.mnt) :
67414+ curr->filename, curr->filename,
67415+ &ip_addr, ip_port, type,
67416+ sk->sk_protocol, mode, &current->signal->saved_ip);
67417+ return 0;
67418+ }
67419+
67420+ for (i = 0; i < curr->ip_num; i++) {
67421+ ip = *(curr->ips + i);
67422+ if (ip->iface != NULL) {
67423+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67424+ p = strchr(iface, ':');
67425+ if (p != NULL)
67426+ *p = '\0';
67427+ dev = dev_get_by_name(sock_net(sk), iface);
67428+ if (dev == NULL)
67429+ continue;
67430+ idev = in_dev_get(dev);
67431+ if (idev == NULL) {
67432+ dev_put(dev);
67433+ continue;
67434+ }
67435+ rcu_read_lock();
67436+ for_ifa(idev) {
67437+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67438+ our_addr = ifa->ifa_address;
67439+ our_netmask = 0xffffffff;
67440+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67441+ if (ret == 1) {
67442+ rcu_read_unlock();
67443+ in_dev_put(idev);
67444+ dev_put(dev);
67445+ return 0;
67446+ } else if (ret == 2) {
67447+ rcu_read_unlock();
67448+ in_dev_put(idev);
67449+ dev_put(dev);
67450+ goto denied;
67451+ }
67452+ }
67453+ } endfor_ifa(idev);
67454+ rcu_read_unlock();
67455+ in_dev_put(idev);
67456+ dev_put(dev);
67457+ } else {
67458+ our_addr = ip->addr;
67459+ our_netmask = ip->netmask;
67460+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67461+ if (ret == 1)
67462+ return 0;
67463+ else if (ret == 2)
67464+ goto denied;
67465+ }
67466+ }
67467+
67468+denied:
67469+ if (mode == GR_BIND)
67470+ 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));
67471+ else if (mode == GR_CONNECT)
67472+ 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));
67473+
67474+ return -EACCES;
67475+}
67476+
67477+int
67478+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67479+{
67480+ /* always allow disconnection of dgram sockets with connect */
67481+ if (addr->sin_family == AF_UNSPEC)
67482+ return 0;
67483+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67484+}
67485+
67486+int
67487+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67488+{
67489+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67490+}
67491+
67492+int gr_search_listen(struct socket *sock)
67493+{
67494+ struct sock *sk = sock->sk;
67495+ struct sockaddr_in addr;
67496+
67497+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67498+ addr.sin_port = inet_sk(sk)->inet_sport;
67499+
67500+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67501+}
67502+
67503+int gr_search_accept(struct socket *sock)
67504+{
67505+ struct sock *sk = sock->sk;
67506+ struct sockaddr_in addr;
67507+
67508+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67509+ addr.sin_port = inet_sk(sk)->inet_sport;
67510+
67511+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67512+}
67513+
67514+int
67515+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67516+{
67517+ if (addr)
67518+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67519+ else {
67520+ struct sockaddr_in sin;
67521+ const struct inet_sock *inet = inet_sk(sk);
67522+
67523+ sin.sin_addr.s_addr = inet->inet_daddr;
67524+ sin.sin_port = inet->inet_dport;
67525+
67526+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67527+ }
67528+}
67529+
67530+int
67531+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67532+{
67533+ struct sockaddr_in sin;
67534+
67535+ if (unlikely(skb->len < sizeof (struct udphdr)))
67536+ return 0; // skip this packet
67537+
67538+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67539+ sin.sin_port = udp_hdr(skb)->source;
67540+
67541+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67542+}
67543diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67544new file mode 100644
67545index 0000000..25f54ef
67546--- /dev/null
67547+++ b/grsecurity/gracl_learn.c
67548@@ -0,0 +1,207 @@
67549+#include <linux/kernel.h>
67550+#include <linux/mm.h>
67551+#include <linux/sched.h>
67552+#include <linux/poll.h>
67553+#include <linux/string.h>
67554+#include <linux/file.h>
67555+#include <linux/types.h>
67556+#include <linux/vmalloc.h>
67557+#include <linux/grinternal.h>
67558+
67559+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67560+ size_t count, loff_t *ppos);
67561+extern int gr_acl_is_enabled(void);
67562+
67563+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67564+static int gr_learn_attached;
67565+
67566+/* use a 512k buffer */
67567+#define LEARN_BUFFER_SIZE (512 * 1024)
67568+
67569+static DEFINE_SPINLOCK(gr_learn_lock);
67570+static DEFINE_MUTEX(gr_learn_user_mutex);
67571+
67572+/* we need to maintain two buffers, so that the kernel context of grlearn
67573+ uses a semaphore around the userspace copying, and the other kernel contexts
67574+ use a spinlock when copying into the buffer, since they cannot sleep
67575+*/
67576+static char *learn_buffer;
67577+static char *learn_buffer_user;
67578+static int learn_buffer_len;
67579+static int learn_buffer_user_len;
67580+
67581+static ssize_t
67582+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67583+{
67584+ DECLARE_WAITQUEUE(wait, current);
67585+ ssize_t retval = 0;
67586+
67587+ add_wait_queue(&learn_wait, &wait);
67588+ set_current_state(TASK_INTERRUPTIBLE);
67589+ do {
67590+ mutex_lock(&gr_learn_user_mutex);
67591+ spin_lock(&gr_learn_lock);
67592+ if (learn_buffer_len)
67593+ break;
67594+ spin_unlock(&gr_learn_lock);
67595+ mutex_unlock(&gr_learn_user_mutex);
67596+ if (file->f_flags & O_NONBLOCK) {
67597+ retval = -EAGAIN;
67598+ goto out;
67599+ }
67600+ if (signal_pending(current)) {
67601+ retval = -ERESTARTSYS;
67602+ goto out;
67603+ }
67604+
67605+ schedule();
67606+ } while (1);
67607+
67608+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67609+ learn_buffer_user_len = learn_buffer_len;
67610+ retval = learn_buffer_len;
67611+ learn_buffer_len = 0;
67612+
67613+ spin_unlock(&gr_learn_lock);
67614+
67615+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67616+ retval = -EFAULT;
67617+
67618+ mutex_unlock(&gr_learn_user_mutex);
67619+out:
67620+ set_current_state(TASK_RUNNING);
67621+ remove_wait_queue(&learn_wait, &wait);
67622+ return retval;
67623+}
67624+
67625+static unsigned int
67626+poll_learn(struct file * file, poll_table * wait)
67627+{
67628+ poll_wait(file, &learn_wait, wait);
67629+
67630+ if (learn_buffer_len)
67631+ return (POLLIN | POLLRDNORM);
67632+
67633+ return 0;
67634+}
67635+
67636+void
67637+gr_clear_learn_entries(void)
67638+{
67639+ char *tmp;
67640+
67641+ mutex_lock(&gr_learn_user_mutex);
67642+ spin_lock(&gr_learn_lock);
67643+ tmp = learn_buffer;
67644+ learn_buffer = NULL;
67645+ spin_unlock(&gr_learn_lock);
67646+ if (tmp)
67647+ vfree(tmp);
67648+ if (learn_buffer_user != NULL) {
67649+ vfree(learn_buffer_user);
67650+ learn_buffer_user = NULL;
67651+ }
67652+ learn_buffer_len = 0;
67653+ mutex_unlock(&gr_learn_user_mutex);
67654+
67655+ return;
67656+}
67657+
67658+void
67659+gr_add_learn_entry(const char *fmt, ...)
67660+{
67661+ va_list args;
67662+ unsigned int len;
67663+
67664+ if (!gr_learn_attached)
67665+ return;
67666+
67667+ spin_lock(&gr_learn_lock);
67668+
67669+ /* leave a gap at the end so we know when it's "full" but don't have to
67670+ compute the exact length of the string we're trying to append
67671+ */
67672+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67673+ spin_unlock(&gr_learn_lock);
67674+ wake_up_interruptible(&learn_wait);
67675+ return;
67676+ }
67677+ if (learn_buffer == NULL) {
67678+ spin_unlock(&gr_learn_lock);
67679+ return;
67680+ }
67681+
67682+ va_start(args, fmt);
67683+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67684+ va_end(args);
67685+
67686+ learn_buffer_len += len + 1;
67687+
67688+ spin_unlock(&gr_learn_lock);
67689+ wake_up_interruptible(&learn_wait);
67690+
67691+ return;
67692+}
67693+
67694+static int
67695+open_learn(struct inode *inode, struct file *file)
67696+{
67697+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67698+ return -EBUSY;
67699+ if (file->f_mode & FMODE_READ) {
67700+ int retval = 0;
67701+ mutex_lock(&gr_learn_user_mutex);
67702+ if (learn_buffer == NULL)
67703+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67704+ if (learn_buffer_user == NULL)
67705+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67706+ if (learn_buffer == NULL) {
67707+ retval = -ENOMEM;
67708+ goto out_error;
67709+ }
67710+ if (learn_buffer_user == NULL) {
67711+ retval = -ENOMEM;
67712+ goto out_error;
67713+ }
67714+ learn_buffer_len = 0;
67715+ learn_buffer_user_len = 0;
67716+ gr_learn_attached = 1;
67717+out_error:
67718+ mutex_unlock(&gr_learn_user_mutex);
67719+ return retval;
67720+ }
67721+ return 0;
67722+}
67723+
67724+static int
67725+close_learn(struct inode *inode, struct file *file)
67726+{
67727+ if (file->f_mode & FMODE_READ) {
67728+ char *tmp = NULL;
67729+ mutex_lock(&gr_learn_user_mutex);
67730+ spin_lock(&gr_learn_lock);
67731+ tmp = learn_buffer;
67732+ learn_buffer = NULL;
67733+ spin_unlock(&gr_learn_lock);
67734+ if (tmp)
67735+ vfree(tmp);
67736+ if (learn_buffer_user != NULL) {
67737+ vfree(learn_buffer_user);
67738+ learn_buffer_user = NULL;
67739+ }
67740+ learn_buffer_len = 0;
67741+ learn_buffer_user_len = 0;
67742+ gr_learn_attached = 0;
67743+ mutex_unlock(&gr_learn_user_mutex);
67744+ }
67745+
67746+ return 0;
67747+}
67748+
67749+const struct file_operations grsec_fops = {
67750+ .read = read_learn,
67751+ .write = write_grsec_handler,
67752+ .open = open_learn,
67753+ .release = close_learn,
67754+ .poll = poll_learn,
67755+};
67756diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67757new file mode 100644
67758index 0000000..39645c9
67759--- /dev/null
67760+++ b/grsecurity/gracl_res.c
67761@@ -0,0 +1,68 @@
67762+#include <linux/kernel.h>
67763+#include <linux/sched.h>
67764+#include <linux/gracl.h>
67765+#include <linux/grinternal.h>
67766+
67767+static const char *restab_log[] = {
67768+ [RLIMIT_CPU] = "RLIMIT_CPU",
67769+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67770+ [RLIMIT_DATA] = "RLIMIT_DATA",
67771+ [RLIMIT_STACK] = "RLIMIT_STACK",
67772+ [RLIMIT_CORE] = "RLIMIT_CORE",
67773+ [RLIMIT_RSS] = "RLIMIT_RSS",
67774+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67775+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67776+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67777+ [RLIMIT_AS] = "RLIMIT_AS",
67778+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67779+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67780+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67781+ [RLIMIT_NICE] = "RLIMIT_NICE",
67782+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67783+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67784+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67785+};
67786+
67787+void
67788+gr_log_resource(const struct task_struct *task,
67789+ const int res, const unsigned long wanted, const int gt)
67790+{
67791+ const struct cred *cred;
67792+ unsigned long rlim;
67793+
67794+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67795+ return;
67796+
67797+ // not yet supported resource
67798+ if (unlikely(!restab_log[res]))
67799+ return;
67800+
67801+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67802+ rlim = task_rlimit_max(task, res);
67803+ else
67804+ rlim = task_rlimit(task, res);
67805+
67806+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67807+ return;
67808+
67809+ rcu_read_lock();
67810+ cred = __task_cred(task);
67811+
67812+ if (res == RLIMIT_NPROC &&
67813+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67814+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67815+ goto out_rcu_unlock;
67816+ else if (res == RLIMIT_MEMLOCK &&
67817+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67818+ goto out_rcu_unlock;
67819+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67820+ goto out_rcu_unlock;
67821+ rcu_read_unlock();
67822+
67823+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67824+
67825+ return;
67826+out_rcu_unlock:
67827+ rcu_read_unlock();
67828+ return;
67829+}
67830diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67831new file mode 100644
67832index 0000000..3c38bfe
67833--- /dev/null
67834+++ b/grsecurity/gracl_segv.c
67835@@ -0,0 +1,305 @@
67836+#include <linux/kernel.h>
67837+#include <linux/mm.h>
67838+#include <asm/uaccess.h>
67839+#include <asm/errno.h>
67840+#include <asm/mman.h>
67841+#include <net/sock.h>
67842+#include <linux/file.h>
67843+#include <linux/fs.h>
67844+#include <linux/net.h>
67845+#include <linux/in.h>
67846+#include <linux/slab.h>
67847+#include <linux/types.h>
67848+#include <linux/sched.h>
67849+#include <linux/timer.h>
67850+#include <linux/gracl.h>
67851+#include <linux/grsecurity.h>
67852+#include <linux/grinternal.h>
67853+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67854+#include <linux/magic.h>
67855+#include <linux/pagemap.h>
67856+#include "../fs/btrfs/async-thread.h"
67857+#include "../fs/btrfs/ctree.h"
67858+#include "../fs/btrfs/btrfs_inode.h"
67859+#endif
67860+
67861+static struct crash_uid *uid_set;
67862+static unsigned short uid_used;
67863+static DEFINE_SPINLOCK(gr_uid_lock);
67864+extern rwlock_t gr_inode_lock;
67865+extern struct acl_subject_label *
67866+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67867+ struct acl_role_label *role);
67868+
67869+static inline dev_t __get_dev(const struct dentry *dentry)
67870+{
67871+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67872+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67873+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67874+ else
67875+#endif
67876+ return dentry->d_sb->s_dev;
67877+}
67878+
67879+int
67880+gr_init_uidset(void)
67881+{
67882+ uid_set =
67883+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67884+ uid_used = 0;
67885+
67886+ return uid_set ? 1 : 0;
67887+}
67888+
67889+void
67890+gr_free_uidset(void)
67891+{
67892+ if (uid_set)
67893+ kfree(uid_set);
67894+
67895+ return;
67896+}
67897+
67898+int
67899+gr_find_uid(const uid_t uid)
67900+{
67901+ struct crash_uid *tmp = uid_set;
67902+ uid_t buid;
67903+ int low = 0, high = uid_used - 1, mid;
67904+
67905+ while (high >= low) {
67906+ mid = (low + high) >> 1;
67907+ buid = tmp[mid].uid;
67908+ if (buid == uid)
67909+ return mid;
67910+ if (buid > uid)
67911+ high = mid - 1;
67912+ if (buid < uid)
67913+ low = mid + 1;
67914+ }
67915+
67916+ return -1;
67917+}
67918+
67919+static __inline__ void
67920+gr_insertsort(void)
67921+{
67922+ unsigned short i, j;
67923+ struct crash_uid index;
67924+
67925+ for (i = 1; i < uid_used; i++) {
67926+ index = uid_set[i];
67927+ j = i;
67928+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
67929+ uid_set[j] = uid_set[j - 1];
67930+ j--;
67931+ }
67932+ uid_set[j] = index;
67933+ }
67934+
67935+ return;
67936+}
67937+
67938+static __inline__ void
67939+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
67940+{
67941+ int loc;
67942+ uid_t uid = GR_GLOBAL_UID(kuid);
67943+
67944+ if (uid_used == GR_UIDTABLE_MAX)
67945+ return;
67946+
67947+ loc = gr_find_uid(uid);
67948+
67949+ if (loc >= 0) {
67950+ uid_set[loc].expires = expires;
67951+ return;
67952+ }
67953+
67954+ uid_set[uid_used].uid = uid;
67955+ uid_set[uid_used].expires = expires;
67956+ uid_used++;
67957+
67958+ gr_insertsort();
67959+
67960+ return;
67961+}
67962+
67963+void
67964+gr_remove_uid(const unsigned short loc)
67965+{
67966+ unsigned short i;
67967+
67968+ for (i = loc + 1; i < uid_used; i++)
67969+ uid_set[i - 1] = uid_set[i];
67970+
67971+ uid_used--;
67972+
67973+ return;
67974+}
67975+
67976+int
67977+gr_check_crash_uid(const kuid_t kuid)
67978+{
67979+ int loc;
67980+ int ret = 0;
67981+ uid_t uid;
67982+
67983+ if (unlikely(!gr_acl_is_enabled()))
67984+ return 0;
67985+
67986+ uid = GR_GLOBAL_UID(kuid);
67987+
67988+ spin_lock(&gr_uid_lock);
67989+ loc = gr_find_uid(uid);
67990+
67991+ if (loc < 0)
67992+ goto out_unlock;
67993+
67994+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
67995+ gr_remove_uid(loc);
67996+ else
67997+ ret = 1;
67998+
67999+out_unlock:
68000+ spin_unlock(&gr_uid_lock);
68001+ return ret;
68002+}
68003+
68004+static __inline__ int
68005+proc_is_setxid(const struct cred *cred)
68006+{
68007+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68008+ !uid_eq(cred->uid, cred->fsuid))
68009+ return 1;
68010+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68011+ !gid_eq(cred->gid, cred->fsgid))
68012+ return 1;
68013+
68014+ return 0;
68015+}
68016+
68017+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68018+
68019+void
68020+gr_handle_crash(struct task_struct *task, const int sig)
68021+{
68022+ struct acl_subject_label *curr;
68023+ struct task_struct *tsk, *tsk2;
68024+ const struct cred *cred;
68025+ const struct cred *cred2;
68026+
68027+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68028+ return;
68029+
68030+ if (unlikely(!gr_acl_is_enabled()))
68031+ return;
68032+
68033+ curr = task->acl;
68034+
68035+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68036+ return;
68037+
68038+ if (time_before_eq(curr->expires, get_seconds())) {
68039+ curr->expires = 0;
68040+ curr->crashes = 0;
68041+ }
68042+
68043+ curr->crashes++;
68044+
68045+ if (!curr->expires)
68046+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68047+
68048+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68049+ time_after(curr->expires, get_seconds())) {
68050+ rcu_read_lock();
68051+ cred = __task_cred(task);
68052+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68053+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68054+ spin_lock(&gr_uid_lock);
68055+ gr_insert_uid(cred->uid, curr->expires);
68056+ spin_unlock(&gr_uid_lock);
68057+ curr->expires = 0;
68058+ curr->crashes = 0;
68059+ read_lock(&tasklist_lock);
68060+ do_each_thread(tsk2, tsk) {
68061+ cred2 = __task_cred(tsk);
68062+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68063+ gr_fake_force_sig(SIGKILL, tsk);
68064+ } while_each_thread(tsk2, tsk);
68065+ read_unlock(&tasklist_lock);
68066+ } else {
68067+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68068+ read_lock(&tasklist_lock);
68069+ read_lock(&grsec_exec_file_lock);
68070+ do_each_thread(tsk2, tsk) {
68071+ if (likely(tsk != task)) {
68072+ // if this thread has the same subject as the one that triggered
68073+ // RES_CRASH and it's the same binary, kill it
68074+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68075+ gr_fake_force_sig(SIGKILL, tsk);
68076+ }
68077+ } while_each_thread(tsk2, tsk);
68078+ read_unlock(&grsec_exec_file_lock);
68079+ read_unlock(&tasklist_lock);
68080+ }
68081+ rcu_read_unlock();
68082+ }
68083+
68084+ return;
68085+}
68086+
68087+int
68088+gr_check_crash_exec(const struct file *filp)
68089+{
68090+ struct acl_subject_label *curr;
68091+
68092+ if (unlikely(!gr_acl_is_enabled()))
68093+ return 0;
68094+
68095+ read_lock(&gr_inode_lock);
68096+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68097+ __get_dev(filp->f_path.dentry),
68098+ current->role);
68099+ read_unlock(&gr_inode_lock);
68100+
68101+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68102+ (!curr->crashes && !curr->expires))
68103+ return 0;
68104+
68105+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68106+ time_after(curr->expires, get_seconds()))
68107+ return 1;
68108+ else if (time_before_eq(curr->expires, get_seconds())) {
68109+ curr->crashes = 0;
68110+ curr->expires = 0;
68111+ }
68112+
68113+ return 0;
68114+}
68115+
68116+void
68117+gr_handle_alertkill(struct task_struct *task)
68118+{
68119+ struct acl_subject_label *curracl;
68120+ __u32 curr_ip;
68121+ struct task_struct *p, *p2;
68122+
68123+ if (unlikely(!gr_acl_is_enabled()))
68124+ return;
68125+
68126+ curracl = task->acl;
68127+ curr_ip = task->signal->curr_ip;
68128+
68129+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68130+ read_lock(&tasklist_lock);
68131+ do_each_thread(p2, p) {
68132+ if (p->signal->curr_ip == curr_ip)
68133+ gr_fake_force_sig(SIGKILL, p);
68134+ } while_each_thread(p2, p);
68135+ read_unlock(&tasklist_lock);
68136+ } else if (curracl->mode & GR_KILLPROC)
68137+ gr_fake_force_sig(SIGKILL, task);
68138+
68139+ return;
68140+}
68141diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68142new file mode 100644
68143index 0000000..98011b0
68144--- /dev/null
68145+++ b/grsecurity/gracl_shm.c
68146@@ -0,0 +1,40 @@
68147+#include <linux/kernel.h>
68148+#include <linux/mm.h>
68149+#include <linux/sched.h>
68150+#include <linux/file.h>
68151+#include <linux/ipc.h>
68152+#include <linux/gracl.h>
68153+#include <linux/grsecurity.h>
68154+#include <linux/grinternal.h>
68155+
68156+int
68157+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68158+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68159+{
68160+ struct task_struct *task;
68161+
68162+ if (!gr_acl_is_enabled())
68163+ return 1;
68164+
68165+ rcu_read_lock();
68166+ read_lock(&tasklist_lock);
68167+
68168+ task = find_task_by_vpid(shm_cprid);
68169+
68170+ if (unlikely(!task))
68171+ task = find_task_by_vpid(shm_lapid);
68172+
68173+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68174+ (task_pid_nr(task) == shm_lapid)) &&
68175+ (task->acl->mode & GR_PROTSHM) &&
68176+ (task->acl != current->acl))) {
68177+ read_unlock(&tasklist_lock);
68178+ rcu_read_unlock();
68179+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68180+ return 0;
68181+ }
68182+ read_unlock(&tasklist_lock);
68183+ rcu_read_unlock();
68184+
68185+ return 1;
68186+}
68187diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68188new file mode 100644
68189index 0000000..bc0be01
68190--- /dev/null
68191+++ b/grsecurity/grsec_chdir.c
68192@@ -0,0 +1,19 @@
68193+#include <linux/kernel.h>
68194+#include <linux/sched.h>
68195+#include <linux/fs.h>
68196+#include <linux/file.h>
68197+#include <linux/grsecurity.h>
68198+#include <linux/grinternal.h>
68199+
68200+void
68201+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68202+{
68203+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68204+ if ((grsec_enable_chdir && grsec_enable_group &&
68205+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68206+ !grsec_enable_group)) {
68207+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68208+ }
68209+#endif
68210+ return;
68211+}
68212diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68213new file mode 100644
68214index 0000000..bd6e105
68215--- /dev/null
68216+++ b/grsecurity/grsec_chroot.c
68217@@ -0,0 +1,370 @@
68218+#include <linux/kernel.h>
68219+#include <linux/module.h>
68220+#include <linux/sched.h>
68221+#include <linux/file.h>
68222+#include <linux/fs.h>
68223+#include <linux/mount.h>
68224+#include <linux/types.h>
68225+#include "../fs/mount.h"
68226+#include <linux/grsecurity.h>
68227+#include <linux/grinternal.h>
68228+
68229+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68230+static int gr_init_ran;
68231+#endif
68232+
68233+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68234+{
68235+#ifdef CONFIG_GRKERNSEC
68236+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68237+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68238+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68239+ && gr_init_ran
68240+#endif
68241+ )
68242+ task->gr_is_chrooted = 1;
68243+ else {
68244+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68245+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68246+ gr_init_ran = 1;
68247+#endif
68248+ task->gr_is_chrooted = 0;
68249+ }
68250+
68251+ task->gr_chroot_dentry = path->dentry;
68252+#endif
68253+ return;
68254+}
68255+
68256+void gr_clear_chroot_entries(struct task_struct *task)
68257+{
68258+#ifdef CONFIG_GRKERNSEC
68259+ task->gr_is_chrooted = 0;
68260+ task->gr_chroot_dentry = NULL;
68261+#endif
68262+ return;
68263+}
68264+
68265+int
68266+gr_handle_chroot_unix(const pid_t pid)
68267+{
68268+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68269+ struct task_struct *p;
68270+
68271+ if (unlikely(!grsec_enable_chroot_unix))
68272+ return 1;
68273+
68274+ if (likely(!proc_is_chrooted(current)))
68275+ return 1;
68276+
68277+ rcu_read_lock();
68278+ read_lock(&tasklist_lock);
68279+ p = find_task_by_vpid_unrestricted(pid);
68280+ if (unlikely(p && !have_same_root(current, p))) {
68281+ read_unlock(&tasklist_lock);
68282+ rcu_read_unlock();
68283+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68284+ return 0;
68285+ }
68286+ read_unlock(&tasklist_lock);
68287+ rcu_read_unlock();
68288+#endif
68289+ return 1;
68290+}
68291+
68292+int
68293+gr_handle_chroot_nice(void)
68294+{
68295+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68296+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68297+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68298+ return -EPERM;
68299+ }
68300+#endif
68301+ return 0;
68302+}
68303+
68304+int
68305+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68306+{
68307+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68308+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68309+ && proc_is_chrooted(current)) {
68310+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68311+ return -EACCES;
68312+ }
68313+#endif
68314+ return 0;
68315+}
68316+
68317+int
68318+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68319+{
68320+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68321+ struct task_struct *p;
68322+ int ret = 0;
68323+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68324+ return ret;
68325+
68326+ read_lock(&tasklist_lock);
68327+ do_each_pid_task(pid, type, p) {
68328+ if (!have_same_root(current, p)) {
68329+ ret = 1;
68330+ goto out;
68331+ }
68332+ } while_each_pid_task(pid, type, p);
68333+out:
68334+ read_unlock(&tasklist_lock);
68335+ return ret;
68336+#endif
68337+ return 0;
68338+}
68339+
68340+int
68341+gr_pid_is_chrooted(struct task_struct *p)
68342+{
68343+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68344+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68345+ return 0;
68346+
68347+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68348+ !have_same_root(current, p)) {
68349+ return 1;
68350+ }
68351+#endif
68352+ return 0;
68353+}
68354+
68355+EXPORT_SYMBOL(gr_pid_is_chrooted);
68356+
68357+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68358+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68359+{
68360+ struct path path, currentroot;
68361+ int ret = 0;
68362+
68363+ path.dentry = (struct dentry *)u_dentry;
68364+ path.mnt = (struct vfsmount *)u_mnt;
68365+ get_fs_root(current->fs, &currentroot);
68366+ if (path_is_under(&path, &currentroot))
68367+ ret = 1;
68368+ path_put(&currentroot);
68369+
68370+ return ret;
68371+}
68372+#endif
68373+
68374+int
68375+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68376+{
68377+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68378+ if (!grsec_enable_chroot_fchdir)
68379+ return 1;
68380+
68381+ if (!proc_is_chrooted(current))
68382+ return 1;
68383+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68384+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68385+ return 0;
68386+ }
68387+#endif
68388+ return 1;
68389+}
68390+
68391+int
68392+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68393+ const time_t shm_createtime)
68394+{
68395+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68396+ struct task_struct *p;
68397+ time_t starttime;
68398+
68399+ if (unlikely(!grsec_enable_chroot_shmat))
68400+ return 1;
68401+
68402+ if (likely(!proc_is_chrooted(current)))
68403+ return 1;
68404+
68405+ rcu_read_lock();
68406+ read_lock(&tasklist_lock);
68407+
68408+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68409+ starttime = p->start_time.tv_sec;
68410+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68411+ if (have_same_root(current, p)) {
68412+ goto allow;
68413+ } else {
68414+ read_unlock(&tasklist_lock);
68415+ rcu_read_unlock();
68416+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68417+ return 0;
68418+ }
68419+ }
68420+ /* creator exited, pid reuse, fall through to next check */
68421+ }
68422+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68423+ if (unlikely(!have_same_root(current, p))) {
68424+ read_unlock(&tasklist_lock);
68425+ rcu_read_unlock();
68426+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68427+ return 0;
68428+ }
68429+ }
68430+
68431+allow:
68432+ read_unlock(&tasklist_lock);
68433+ rcu_read_unlock();
68434+#endif
68435+ return 1;
68436+}
68437+
68438+void
68439+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68440+{
68441+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68442+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68443+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68444+#endif
68445+ return;
68446+}
68447+
68448+int
68449+gr_handle_chroot_mknod(const struct dentry *dentry,
68450+ const struct vfsmount *mnt, const int mode)
68451+{
68452+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68453+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68454+ proc_is_chrooted(current)) {
68455+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68456+ return -EPERM;
68457+ }
68458+#endif
68459+ return 0;
68460+}
68461+
68462+int
68463+gr_handle_chroot_mount(const struct dentry *dentry,
68464+ const struct vfsmount *mnt, const char *dev_name)
68465+{
68466+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68467+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68468+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68469+ return -EPERM;
68470+ }
68471+#endif
68472+ return 0;
68473+}
68474+
68475+int
68476+gr_handle_chroot_pivot(void)
68477+{
68478+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68479+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68480+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68481+ return -EPERM;
68482+ }
68483+#endif
68484+ return 0;
68485+}
68486+
68487+int
68488+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68489+{
68490+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68491+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68492+ !gr_is_outside_chroot(dentry, mnt)) {
68493+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68494+ return -EPERM;
68495+ }
68496+#endif
68497+ return 0;
68498+}
68499+
68500+extern const char *captab_log[];
68501+extern int captab_log_entries;
68502+
68503+int
68504+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68505+{
68506+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68507+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68508+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68509+ if (cap_raised(chroot_caps, cap)) {
68510+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68511+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68512+ }
68513+ return 0;
68514+ }
68515+ }
68516+#endif
68517+ return 1;
68518+}
68519+
68520+int
68521+gr_chroot_is_capable(const int cap)
68522+{
68523+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68524+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68525+#endif
68526+ return 1;
68527+}
68528+
68529+int
68530+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68531+{
68532+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68533+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68534+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68535+ if (cap_raised(chroot_caps, cap)) {
68536+ return 0;
68537+ }
68538+ }
68539+#endif
68540+ return 1;
68541+}
68542+
68543+int
68544+gr_chroot_is_capable_nolog(const int cap)
68545+{
68546+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68547+ return gr_task_chroot_is_capable_nolog(current, cap);
68548+#endif
68549+ return 1;
68550+}
68551+
68552+int
68553+gr_handle_chroot_sysctl(const int op)
68554+{
68555+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68556+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68557+ proc_is_chrooted(current))
68558+ return -EACCES;
68559+#endif
68560+ return 0;
68561+}
68562+
68563+void
68564+gr_handle_chroot_chdir(const struct path *path)
68565+{
68566+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68567+ if (grsec_enable_chroot_chdir)
68568+ set_fs_pwd(current->fs, path);
68569+#endif
68570+ return;
68571+}
68572+
68573+int
68574+gr_handle_chroot_chmod(const struct dentry *dentry,
68575+ const struct vfsmount *mnt, const int mode)
68576+{
68577+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68578+ /* allow chmod +s on directories, but not files */
68579+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68580+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68581+ proc_is_chrooted(current)) {
68582+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68583+ return -EPERM;
68584+ }
68585+#endif
68586+ return 0;
68587+}
68588diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68589new file mode 100644
68590index 0000000..ce65ceb
68591--- /dev/null
68592+++ b/grsecurity/grsec_disabled.c
68593@@ -0,0 +1,434 @@
68594+#include <linux/kernel.h>
68595+#include <linux/module.h>
68596+#include <linux/sched.h>
68597+#include <linux/file.h>
68598+#include <linux/fs.h>
68599+#include <linux/kdev_t.h>
68600+#include <linux/net.h>
68601+#include <linux/in.h>
68602+#include <linux/ip.h>
68603+#include <linux/skbuff.h>
68604+#include <linux/sysctl.h>
68605+
68606+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68607+void
68608+pax_set_initial_flags(struct linux_binprm *bprm)
68609+{
68610+ return;
68611+}
68612+#endif
68613+
68614+#ifdef CONFIG_SYSCTL
68615+__u32
68616+gr_handle_sysctl(const struct ctl_table * table, const int op)
68617+{
68618+ return 0;
68619+}
68620+#endif
68621+
68622+#ifdef CONFIG_TASKSTATS
68623+int gr_is_taskstats_denied(int pid)
68624+{
68625+ return 0;
68626+}
68627+#endif
68628+
68629+int
68630+gr_acl_is_enabled(void)
68631+{
68632+ return 0;
68633+}
68634+
68635+void
68636+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68637+{
68638+ return;
68639+}
68640+
68641+int
68642+gr_handle_rawio(const struct inode *inode)
68643+{
68644+ return 0;
68645+}
68646+
68647+void
68648+gr_acl_handle_psacct(struct task_struct *task, const long code)
68649+{
68650+ return;
68651+}
68652+
68653+int
68654+gr_handle_ptrace(struct task_struct *task, const long request)
68655+{
68656+ return 0;
68657+}
68658+
68659+int
68660+gr_handle_proc_ptrace(struct task_struct *task)
68661+{
68662+ return 0;
68663+}
68664+
68665+int
68666+gr_set_acls(const int type)
68667+{
68668+ return 0;
68669+}
68670+
68671+int
68672+gr_check_hidden_task(const struct task_struct *tsk)
68673+{
68674+ return 0;
68675+}
68676+
68677+int
68678+gr_check_protected_task(const struct task_struct *task)
68679+{
68680+ return 0;
68681+}
68682+
68683+int
68684+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68685+{
68686+ return 0;
68687+}
68688+
68689+void
68690+gr_copy_label(struct task_struct *tsk)
68691+{
68692+ return;
68693+}
68694+
68695+void
68696+gr_set_pax_flags(struct task_struct *task)
68697+{
68698+ return;
68699+}
68700+
68701+int
68702+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68703+ const int unsafe_share)
68704+{
68705+ return 0;
68706+}
68707+
68708+void
68709+gr_handle_delete(const ino_t ino, const dev_t dev)
68710+{
68711+ return;
68712+}
68713+
68714+void
68715+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68716+{
68717+ return;
68718+}
68719+
68720+void
68721+gr_handle_crash(struct task_struct *task, const int sig)
68722+{
68723+ return;
68724+}
68725+
68726+int
68727+gr_check_crash_exec(const struct file *filp)
68728+{
68729+ return 0;
68730+}
68731+
68732+int
68733+gr_check_crash_uid(const kuid_t uid)
68734+{
68735+ return 0;
68736+}
68737+
68738+void
68739+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68740+ struct dentry *old_dentry,
68741+ struct dentry *new_dentry,
68742+ struct vfsmount *mnt, const __u8 replace)
68743+{
68744+ return;
68745+}
68746+
68747+int
68748+gr_search_socket(const int family, const int type, const int protocol)
68749+{
68750+ return 1;
68751+}
68752+
68753+int
68754+gr_search_connectbind(const int mode, const struct socket *sock,
68755+ const struct sockaddr_in *addr)
68756+{
68757+ return 0;
68758+}
68759+
68760+void
68761+gr_handle_alertkill(struct task_struct *task)
68762+{
68763+ return;
68764+}
68765+
68766+__u32
68767+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68768+{
68769+ return 1;
68770+}
68771+
68772+__u32
68773+gr_acl_handle_hidden_file(const struct dentry * dentry,
68774+ const struct vfsmount * mnt)
68775+{
68776+ return 1;
68777+}
68778+
68779+__u32
68780+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68781+ int acc_mode)
68782+{
68783+ return 1;
68784+}
68785+
68786+__u32
68787+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68788+{
68789+ return 1;
68790+}
68791+
68792+__u32
68793+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68794+{
68795+ return 1;
68796+}
68797+
68798+int
68799+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68800+ unsigned int *vm_flags)
68801+{
68802+ return 1;
68803+}
68804+
68805+__u32
68806+gr_acl_handle_truncate(const struct dentry * dentry,
68807+ const struct vfsmount * mnt)
68808+{
68809+ return 1;
68810+}
68811+
68812+__u32
68813+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68814+{
68815+ return 1;
68816+}
68817+
68818+__u32
68819+gr_acl_handle_access(const struct dentry * dentry,
68820+ const struct vfsmount * mnt, const int fmode)
68821+{
68822+ return 1;
68823+}
68824+
68825+__u32
68826+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68827+ umode_t *mode)
68828+{
68829+ return 1;
68830+}
68831+
68832+__u32
68833+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68834+{
68835+ return 1;
68836+}
68837+
68838+__u32
68839+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68840+{
68841+ return 1;
68842+}
68843+
68844+void
68845+grsecurity_init(void)
68846+{
68847+ return;
68848+}
68849+
68850+umode_t gr_acl_umask(void)
68851+{
68852+ return 0;
68853+}
68854+
68855+__u32
68856+gr_acl_handle_mknod(const struct dentry * new_dentry,
68857+ const struct dentry * parent_dentry,
68858+ const struct vfsmount * parent_mnt,
68859+ const int mode)
68860+{
68861+ return 1;
68862+}
68863+
68864+__u32
68865+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68866+ const struct dentry * parent_dentry,
68867+ const struct vfsmount * parent_mnt)
68868+{
68869+ return 1;
68870+}
68871+
68872+__u32
68873+gr_acl_handle_symlink(const struct dentry * new_dentry,
68874+ const struct dentry * parent_dentry,
68875+ const struct vfsmount * parent_mnt, const struct filename *from)
68876+{
68877+ return 1;
68878+}
68879+
68880+__u32
68881+gr_acl_handle_link(const struct dentry * new_dentry,
68882+ const struct dentry * parent_dentry,
68883+ const struct vfsmount * parent_mnt,
68884+ const struct dentry * old_dentry,
68885+ const struct vfsmount * old_mnt, const struct filename *to)
68886+{
68887+ return 1;
68888+}
68889+
68890+int
68891+gr_acl_handle_rename(const struct dentry *new_dentry,
68892+ const struct dentry *parent_dentry,
68893+ const struct vfsmount *parent_mnt,
68894+ const struct dentry *old_dentry,
68895+ const struct inode *old_parent_inode,
68896+ const struct vfsmount *old_mnt, const struct filename *newname)
68897+{
68898+ return 0;
68899+}
68900+
68901+int
68902+gr_acl_handle_filldir(const struct file *file, const char *name,
68903+ const int namelen, const ino_t ino)
68904+{
68905+ return 1;
68906+}
68907+
68908+int
68909+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68910+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68911+{
68912+ return 1;
68913+}
68914+
68915+int
68916+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
68917+{
68918+ return 0;
68919+}
68920+
68921+int
68922+gr_search_accept(const struct socket *sock)
68923+{
68924+ return 0;
68925+}
68926+
68927+int
68928+gr_search_listen(const struct socket *sock)
68929+{
68930+ return 0;
68931+}
68932+
68933+int
68934+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
68935+{
68936+ return 0;
68937+}
68938+
68939+__u32
68940+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
68941+{
68942+ return 1;
68943+}
68944+
68945+__u32
68946+gr_acl_handle_creat(const struct dentry * dentry,
68947+ const struct dentry * p_dentry,
68948+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68949+ const int imode)
68950+{
68951+ return 1;
68952+}
68953+
68954+void
68955+gr_acl_handle_exit(void)
68956+{
68957+ return;
68958+}
68959+
68960+int
68961+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68962+{
68963+ return 1;
68964+}
68965+
68966+void
68967+gr_set_role_label(const kuid_t uid, const kgid_t gid)
68968+{
68969+ return;
68970+}
68971+
68972+int
68973+gr_acl_handle_procpidmem(const struct task_struct *task)
68974+{
68975+ return 0;
68976+}
68977+
68978+int
68979+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
68980+{
68981+ return 0;
68982+}
68983+
68984+int
68985+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
68986+{
68987+ return 0;
68988+}
68989+
68990+void
68991+gr_set_kernel_label(struct task_struct *task)
68992+{
68993+ return;
68994+}
68995+
68996+int
68997+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68998+{
68999+ return 0;
69000+}
69001+
69002+int
69003+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69004+{
69005+ return 0;
69006+}
69007+
69008+int gr_acl_enable_at_secure(void)
69009+{
69010+ return 0;
69011+}
69012+
69013+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69014+{
69015+ return dentry->d_sb->s_dev;
69016+}
69017+
69018+void gr_put_exec_file(struct task_struct *task)
69019+{
69020+ return;
69021+}
69022+
69023+EXPORT_SYMBOL(gr_set_kernel_label);
69024+#ifdef CONFIG_SECURITY
69025+EXPORT_SYMBOL(gr_check_user_change);
69026+EXPORT_SYMBOL(gr_check_group_change);
69027+#endif
69028diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69029new file mode 100644
69030index 0000000..387032b
69031--- /dev/null
69032+++ b/grsecurity/grsec_exec.c
69033@@ -0,0 +1,187 @@
69034+#include <linux/kernel.h>
69035+#include <linux/sched.h>
69036+#include <linux/file.h>
69037+#include <linux/binfmts.h>
69038+#include <linux/fs.h>
69039+#include <linux/types.h>
69040+#include <linux/grdefs.h>
69041+#include <linux/grsecurity.h>
69042+#include <linux/grinternal.h>
69043+#include <linux/capability.h>
69044+#include <linux/module.h>
69045+#include <linux/compat.h>
69046+
69047+#include <asm/uaccess.h>
69048+
69049+#ifdef CONFIG_GRKERNSEC_EXECLOG
69050+static char gr_exec_arg_buf[132];
69051+static DEFINE_MUTEX(gr_exec_arg_mutex);
69052+#endif
69053+
69054+struct user_arg_ptr {
69055+#ifdef CONFIG_COMPAT
69056+ bool is_compat;
69057+#endif
69058+ union {
69059+ const char __user *const __user *native;
69060+#ifdef CONFIG_COMPAT
69061+ const compat_uptr_t __user *compat;
69062+#endif
69063+ } ptr;
69064+};
69065+
69066+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69067+
69068+void
69069+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69070+{
69071+#ifdef CONFIG_GRKERNSEC_EXECLOG
69072+ char *grarg = gr_exec_arg_buf;
69073+ unsigned int i, x, execlen = 0;
69074+ char c;
69075+
69076+ if (!((grsec_enable_execlog && grsec_enable_group &&
69077+ in_group_p(grsec_audit_gid))
69078+ || (grsec_enable_execlog && !grsec_enable_group)))
69079+ return;
69080+
69081+ mutex_lock(&gr_exec_arg_mutex);
69082+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69083+
69084+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69085+ const char __user *p;
69086+ unsigned int len;
69087+
69088+ p = get_user_arg_ptr(argv, i);
69089+ if (IS_ERR(p))
69090+ goto log;
69091+
69092+ len = strnlen_user(p, 128 - execlen);
69093+ if (len > 128 - execlen)
69094+ len = 128 - execlen;
69095+ else if (len > 0)
69096+ len--;
69097+ if (copy_from_user(grarg + execlen, p, len))
69098+ goto log;
69099+
69100+ /* rewrite unprintable characters */
69101+ for (x = 0; x < len; x++) {
69102+ c = *(grarg + execlen + x);
69103+ if (c < 32 || c > 126)
69104+ *(grarg + execlen + x) = ' ';
69105+ }
69106+
69107+ execlen += len;
69108+ *(grarg + execlen) = ' ';
69109+ *(grarg + execlen + 1) = '\0';
69110+ execlen++;
69111+ }
69112+
69113+ log:
69114+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69115+ bprm->file->f_path.mnt, grarg);
69116+ mutex_unlock(&gr_exec_arg_mutex);
69117+#endif
69118+ return;
69119+}
69120+
69121+#ifdef CONFIG_GRKERNSEC
69122+extern int gr_acl_is_capable(const int cap);
69123+extern int gr_acl_is_capable_nolog(const int cap);
69124+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69125+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69126+extern int gr_chroot_is_capable(const int cap);
69127+extern int gr_chroot_is_capable_nolog(const int cap);
69128+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69129+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69130+#endif
69131+
69132+const char *captab_log[] = {
69133+ "CAP_CHOWN",
69134+ "CAP_DAC_OVERRIDE",
69135+ "CAP_DAC_READ_SEARCH",
69136+ "CAP_FOWNER",
69137+ "CAP_FSETID",
69138+ "CAP_KILL",
69139+ "CAP_SETGID",
69140+ "CAP_SETUID",
69141+ "CAP_SETPCAP",
69142+ "CAP_LINUX_IMMUTABLE",
69143+ "CAP_NET_BIND_SERVICE",
69144+ "CAP_NET_BROADCAST",
69145+ "CAP_NET_ADMIN",
69146+ "CAP_NET_RAW",
69147+ "CAP_IPC_LOCK",
69148+ "CAP_IPC_OWNER",
69149+ "CAP_SYS_MODULE",
69150+ "CAP_SYS_RAWIO",
69151+ "CAP_SYS_CHROOT",
69152+ "CAP_SYS_PTRACE",
69153+ "CAP_SYS_PACCT",
69154+ "CAP_SYS_ADMIN",
69155+ "CAP_SYS_BOOT",
69156+ "CAP_SYS_NICE",
69157+ "CAP_SYS_RESOURCE",
69158+ "CAP_SYS_TIME",
69159+ "CAP_SYS_TTY_CONFIG",
69160+ "CAP_MKNOD",
69161+ "CAP_LEASE",
69162+ "CAP_AUDIT_WRITE",
69163+ "CAP_AUDIT_CONTROL",
69164+ "CAP_SETFCAP",
69165+ "CAP_MAC_OVERRIDE",
69166+ "CAP_MAC_ADMIN",
69167+ "CAP_SYSLOG",
69168+ "CAP_WAKE_ALARM"
69169+};
69170+
69171+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69172+
69173+int gr_is_capable(const int cap)
69174+{
69175+#ifdef CONFIG_GRKERNSEC
69176+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69177+ return 1;
69178+ return 0;
69179+#else
69180+ return 1;
69181+#endif
69182+}
69183+
69184+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69185+{
69186+#ifdef CONFIG_GRKERNSEC
69187+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69188+ return 1;
69189+ return 0;
69190+#else
69191+ return 1;
69192+#endif
69193+}
69194+
69195+int gr_is_capable_nolog(const int cap)
69196+{
69197+#ifdef CONFIG_GRKERNSEC
69198+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69199+ return 1;
69200+ return 0;
69201+#else
69202+ return 1;
69203+#endif
69204+}
69205+
69206+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69207+{
69208+#ifdef CONFIG_GRKERNSEC
69209+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69210+ return 1;
69211+ return 0;
69212+#else
69213+ return 1;
69214+#endif
69215+}
69216+
69217+EXPORT_SYMBOL(gr_is_capable);
69218+EXPORT_SYMBOL(gr_is_capable_nolog);
69219+EXPORT_SYMBOL(gr_task_is_capable);
69220+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69221diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69222new file mode 100644
69223index 0000000..06cc6ea
69224--- /dev/null
69225+++ b/grsecurity/grsec_fifo.c
69226@@ -0,0 +1,24 @@
69227+#include <linux/kernel.h>
69228+#include <linux/sched.h>
69229+#include <linux/fs.h>
69230+#include <linux/file.h>
69231+#include <linux/grinternal.h>
69232+
69233+int
69234+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69235+ const struct dentry *dir, const int flag, const int acc_mode)
69236+{
69237+#ifdef CONFIG_GRKERNSEC_FIFO
69238+ const struct cred *cred = current_cred();
69239+
69240+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69241+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69242+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69243+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69244+ if (!inode_permission(dentry->d_inode, acc_mode))
69245+ 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));
69246+ return -EACCES;
69247+ }
69248+#endif
69249+ return 0;
69250+}
69251diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69252new file mode 100644
69253index 0000000..8ca18bf
69254--- /dev/null
69255+++ b/grsecurity/grsec_fork.c
69256@@ -0,0 +1,23 @@
69257+#include <linux/kernel.h>
69258+#include <linux/sched.h>
69259+#include <linux/grsecurity.h>
69260+#include <linux/grinternal.h>
69261+#include <linux/errno.h>
69262+
69263+void
69264+gr_log_forkfail(const int retval)
69265+{
69266+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69267+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69268+ switch (retval) {
69269+ case -EAGAIN:
69270+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69271+ break;
69272+ case -ENOMEM:
69273+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69274+ break;
69275+ }
69276+ }
69277+#endif
69278+ return;
69279+}
69280diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69281new file mode 100644
69282index 0000000..99a0cb9
69283--- /dev/null
69284+++ b/grsecurity/grsec_init.c
69285@@ -0,0 +1,283 @@
69286+#include <linux/kernel.h>
69287+#include <linux/sched.h>
69288+#include <linux/mm.h>
69289+#include <linux/gracl.h>
69290+#include <linux/slab.h>
69291+#include <linux/vmalloc.h>
69292+#include <linux/percpu.h>
69293+#include <linux/module.h>
69294+
69295+int grsec_enable_ptrace_readexec;
69296+int grsec_enable_setxid;
69297+int grsec_enable_symlinkown;
69298+kgid_t grsec_symlinkown_gid;
69299+int grsec_enable_brute;
69300+int grsec_enable_link;
69301+int grsec_enable_dmesg;
69302+int grsec_enable_harden_ptrace;
69303+int grsec_enable_fifo;
69304+int grsec_enable_execlog;
69305+int grsec_enable_signal;
69306+int grsec_enable_forkfail;
69307+int grsec_enable_audit_ptrace;
69308+int grsec_enable_time;
69309+int grsec_enable_group;
69310+kgid_t grsec_audit_gid;
69311+int grsec_enable_chdir;
69312+int grsec_enable_mount;
69313+int grsec_enable_rofs;
69314+int grsec_deny_new_usb;
69315+int grsec_enable_chroot_findtask;
69316+int grsec_enable_chroot_mount;
69317+int grsec_enable_chroot_shmat;
69318+int grsec_enable_chroot_fchdir;
69319+int grsec_enable_chroot_double;
69320+int grsec_enable_chroot_pivot;
69321+int grsec_enable_chroot_chdir;
69322+int grsec_enable_chroot_chmod;
69323+int grsec_enable_chroot_mknod;
69324+int grsec_enable_chroot_nice;
69325+int grsec_enable_chroot_execlog;
69326+int grsec_enable_chroot_caps;
69327+int grsec_enable_chroot_sysctl;
69328+int grsec_enable_chroot_unix;
69329+int grsec_enable_tpe;
69330+kgid_t grsec_tpe_gid;
69331+int grsec_enable_blackhole;
69332+#ifdef CONFIG_IPV6_MODULE
69333+EXPORT_SYMBOL(grsec_enable_blackhole);
69334+#endif
69335+int grsec_lastack_retries;
69336+int grsec_enable_tpe_all;
69337+int grsec_enable_tpe_invert;
69338+int grsec_enable_socket_all;
69339+kgid_t grsec_socket_all_gid;
69340+int grsec_enable_socket_client;
69341+kgid_t grsec_socket_client_gid;
69342+int grsec_enable_socket_server;
69343+kgid_t grsec_socket_server_gid;
69344+int grsec_resource_logging;
69345+int grsec_disable_privio;
69346+int grsec_enable_log_rwxmaps;
69347+int grsec_lock;
69348+
69349+DEFINE_SPINLOCK(grsec_alert_lock);
69350+unsigned long grsec_alert_wtime = 0;
69351+unsigned long grsec_alert_fyet = 0;
69352+
69353+DEFINE_SPINLOCK(grsec_audit_lock);
69354+
69355+DEFINE_RWLOCK(grsec_exec_file_lock);
69356+
69357+char *gr_shared_page[4];
69358+
69359+char *gr_alert_log_fmt;
69360+char *gr_audit_log_fmt;
69361+char *gr_alert_log_buf;
69362+char *gr_audit_log_buf;
69363+
69364+extern struct gr_arg *gr_usermode;
69365+extern unsigned char *gr_system_salt;
69366+extern unsigned char *gr_system_sum;
69367+
69368+void __init
69369+grsecurity_init(void)
69370+{
69371+ int j;
69372+ /* create the per-cpu shared pages */
69373+
69374+#ifdef CONFIG_X86
69375+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69376+#endif
69377+
69378+ for (j = 0; j < 4; j++) {
69379+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69380+ if (gr_shared_page[j] == NULL) {
69381+ panic("Unable to allocate grsecurity shared page");
69382+ return;
69383+ }
69384+ }
69385+
69386+ /* allocate log buffers */
69387+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69388+ if (!gr_alert_log_fmt) {
69389+ panic("Unable to allocate grsecurity alert log format buffer");
69390+ return;
69391+ }
69392+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69393+ if (!gr_audit_log_fmt) {
69394+ panic("Unable to allocate grsecurity audit log format buffer");
69395+ return;
69396+ }
69397+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69398+ if (!gr_alert_log_buf) {
69399+ panic("Unable to allocate grsecurity alert log buffer");
69400+ return;
69401+ }
69402+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69403+ if (!gr_audit_log_buf) {
69404+ panic("Unable to allocate grsecurity audit log buffer");
69405+ return;
69406+ }
69407+
69408+ /* allocate memory for authentication structure */
69409+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69410+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69411+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69412+
69413+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69414+ panic("Unable to allocate grsecurity authentication structure");
69415+ return;
69416+ }
69417+
69418+
69419+#ifdef CONFIG_GRKERNSEC_IO
69420+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69421+ grsec_disable_privio = 1;
69422+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69423+ grsec_disable_privio = 1;
69424+#else
69425+ grsec_disable_privio = 0;
69426+#endif
69427+#endif
69428+
69429+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69430+ /* for backward compatibility, tpe_invert always defaults to on if
69431+ enabled in the kernel
69432+ */
69433+ grsec_enable_tpe_invert = 1;
69434+#endif
69435+
69436+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69437+#ifndef CONFIG_GRKERNSEC_SYSCTL
69438+ grsec_lock = 1;
69439+#endif
69440+
69441+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69442+ grsec_enable_log_rwxmaps = 1;
69443+#endif
69444+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69445+ grsec_enable_group = 1;
69446+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69447+#endif
69448+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69449+ grsec_enable_ptrace_readexec = 1;
69450+#endif
69451+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69452+ grsec_enable_chdir = 1;
69453+#endif
69454+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69455+ grsec_enable_harden_ptrace = 1;
69456+#endif
69457+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69458+ grsec_enable_mount = 1;
69459+#endif
69460+#ifdef CONFIG_GRKERNSEC_LINK
69461+ grsec_enable_link = 1;
69462+#endif
69463+#ifdef CONFIG_GRKERNSEC_BRUTE
69464+ grsec_enable_brute = 1;
69465+#endif
69466+#ifdef CONFIG_GRKERNSEC_DMESG
69467+ grsec_enable_dmesg = 1;
69468+#endif
69469+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69470+ grsec_enable_blackhole = 1;
69471+ grsec_lastack_retries = 4;
69472+#endif
69473+#ifdef CONFIG_GRKERNSEC_FIFO
69474+ grsec_enable_fifo = 1;
69475+#endif
69476+#ifdef CONFIG_GRKERNSEC_EXECLOG
69477+ grsec_enable_execlog = 1;
69478+#endif
69479+#ifdef CONFIG_GRKERNSEC_SETXID
69480+ grsec_enable_setxid = 1;
69481+#endif
69482+#ifdef CONFIG_GRKERNSEC_SIGNAL
69483+ grsec_enable_signal = 1;
69484+#endif
69485+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69486+ grsec_enable_forkfail = 1;
69487+#endif
69488+#ifdef CONFIG_GRKERNSEC_TIME
69489+ grsec_enable_time = 1;
69490+#endif
69491+#ifdef CONFIG_GRKERNSEC_RESLOG
69492+ grsec_resource_logging = 1;
69493+#endif
69494+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69495+ grsec_enable_chroot_findtask = 1;
69496+#endif
69497+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69498+ grsec_enable_chroot_unix = 1;
69499+#endif
69500+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69501+ grsec_enable_chroot_mount = 1;
69502+#endif
69503+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69504+ grsec_enable_chroot_fchdir = 1;
69505+#endif
69506+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69507+ grsec_enable_chroot_shmat = 1;
69508+#endif
69509+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69510+ grsec_enable_audit_ptrace = 1;
69511+#endif
69512+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69513+ grsec_enable_chroot_double = 1;
69514+#endif
69515+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69516+ grsec_enable_chroot_pivot = 1;
69517+#endif
69518+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69519+ grsec_enable_chroot_chdir = 1;
69520+#endif
69521+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69522+ grsec_enable_chroot_chmod = 1;
69523+#endif
69524+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69525+ grsec_enable_chroot_mknod = 1;
69526+#endif
69527+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69528+ grsec_enable_chroot_nice = 1;
69529+#endif
69530+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69531+ grsec_enable_chroot_execlog = 1;
69532+#endif
69533+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69534+ grsec_enable_chroot_caps = 1;
69535+#endif
69536+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69537+ grsec_enable_chroot_sysctl = 1;
69538+#endif
69539+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69540+ grsec_enable_symlinkown = 1;
69541+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69542+#endif
69543+#ifdef CONFIG_GRKERNSEC_TPE
69544+ grsec_enable_tpe = 1;
69545+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69546+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69547+ grsec_enable_tpe_all = 1;
69548+#endif
69549+#endif
69550+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69551+ grsec_enable_socket_all = 1;
69552+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69553+#endif
69554+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69555+ grsec_enable_socket_client = 1;
69556+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69557+#endif
69558+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69559+ grsec_enable_socket_server = 1;
69560+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69561+#endif
69562+#endif
69563+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69564+ grsec_deny_new_usb = 1;
69565+#endif
69566+
69567+ return;
69568+}
69569diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69570new file mode 100644
69571index 0000000..5e05e20
69572--- /dev/null
69573+++ b/grsecurity/grsec_link.c
69574@@ -0,0 +1,58 @@
69575+#include <linux/kernel.h>
69576+#include <linux/sched.h>
69577+#include <linux/fs.h>
69578+#include <linux/file.h>
69579+#include <linux/grinternal.h>
69580+
69581+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69582+{
69583+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69584+ const struct inode *link_inode = link->dentry->d_inode;
69585+
69586+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69587+ /* ignore root-owned links, e.g. /proc/self */
69588+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69589+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69590+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69591+ return 1;
69592+ }
69593+#endif
69594+ return 0;
69595+}
69596+
69597+int
69598+gr_handle_follow_link(const struct inode *parent,
69599+ const struct inode *inode,
69600+ const struct dentry *dentry, const struct vfsmount *mnt)
69601+{
69602+#ifdef CONFIG_GRKERNSEC_LINK
69603+ const struct cred *cred = current_cred();
69604+
69605+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69606+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69607+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69608+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69609+ return -EACCES;
69610+ }
69611+#endif
69612+ return 0;
69613+}
69614+
69615+int
69616+gr_handle_hardlink(const struct dentry *dentry,
69617+ const struct vfsmount *mnt,
69618+ struct inode *inode, const int mode, const struct filename *to)
69619+{
69620+#ifdef CONFIG_GRKERNSEC_LINK
69621+ const struct cred *cred = current_cred();
69622+
69623+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69624+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69625+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69626+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69627+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69628+ return -EPERM;
69629+ }
69630+#endif
69631+ return 0;
69632+}
69633diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69634new file mode 100644
69635index 0000000..dbe0a6b
69636--- /dev/null
69637+++ b/grsecurity/grsec_log.c
69638@@ -0,0 +1,341 @@
69639+#include <linux/kernel.h>
69640+#include <linux/sched.h>
69641+#include <linux/file.h>
69642+#include <linux/tty.h>
69643+#include <linux/fs.h>
69644+#include <linux/mm.h>
69645+#include <linux/grinternal.h>
69646+
69647+#ifdef CONFIG_TREE_PREEMPT_RCU
69648+#define DISABLE_PREEMPT() preempt_disable()
69649+#define ENABLE_PREEMPT() preempt_enable()
69650+#else
69651+#define DISABLE_PREEMPT()
69652+#define ENABLE_PREEMPT()
69653+#endif
69654+
69655+#define BEGIN_LOCKS(x) \
69656+ DISABLE_PREEMPT(); \
69657+ rcu_read_lock(); \
69658+ read_lock(&tasklist_lock); \
69659+ read_lock(&grsec_exec_file_lock); \
69660+ if (x != GR_DO_AUDIT) \
69661+ spin_lock(&grsec_alert_lock); \
69662+ else \
69663+ spin_lock(&grsec_audit_lock)
69664+
69665+#define END_LOCKS(x) \
69666+ if (x != GR_DO_AUDIT) \
69667+ spin_unlock(&grsec_alert_lock); \
69668+ else \
69669+ spin_unlock(&grsec_audit_lock); \
69670+ read_unlock(&grsec_exec_file_lock); \
69671+ read_unlock(&tasklist_lock); \
69672+ rcu_read_unlock(); \
69673+ ENABLE_PREEMPT(); \
69674+ if (x == GR_DONT_AUDIT) \
69675+ gr_handle_alertkill(current)
69676+
69677+enum {
69678+ FLOODING,
69679+ NO_FLOODING
69680+};
69681+
69682+extern char *gr_alert_log_fmt;
69683+extern char *gr_audit_log_fmt;
69684+extern char *gr_alert_log_buf;
69685+extern char *gr_audit_log_buf;
69686+
69687+static int gr_log_start(int audit)
69688+{
69689+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69690+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69691+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69692+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69693+ unsigned long curr_secs = get_seconds();
69694+
69695+ if (audit == GR_DO_AUDIT)
69696+ goto set_fmt;
69697+
69698+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69699+ grsec_alert_wtime = curr_secs;
69700+ grsec_alert_fyet = 0;
69701+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69702+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69703+ grsec_alert_fyet++;
69704+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69705+ grsec_alert_wtime = curr_secs;
69706+ grsec_alert_fyet++;
69707+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69708+ return FLOODING;
69709+ }
69710+ else return FLOODING;
69711+
69712+set_fmt:
69713+#endif
69714+ memset(buf, 0, PAGE_SIZE);
69715+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69716+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69717+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69718+ } else if (current->signal->curr_ip) {
69719+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69720+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69721+ } else if (gr_acl_is_enabled()) {
69722+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69723+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69724+ } else {
69725+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69726+ strcpy(buf, fmt);
69727+ }
69728+
69729+ return NO_FLOODING;
69730+}
69731+
69732+static void gr_log_middle(int audit, const char *msg, va_list ap)
69733+ __attribute__ ((format (printf, 2, 0)));
69734+
69735+static void gr_log_middle(int audit, const char *msg, va_list ap)
69736+{
69737+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69738+ unsigned int len = strlen(buf);
69739+
69740+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69741+
69742+ return;
69743+}
69744+
69745+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69746+ __attribute__ ((format (printf, 2, 3)));
69747+
69748+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69749+{
69750+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69751+ unsigned int len = strlen(buf);
69752+ va_list ap;
69753+
69754+ va_start(ap, msg);
69755+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69756+ va_end(ap);
69757+
69758+ return;
69759+}
69760+
69761+static void gr_log_end(int audit, int append_default)
69762+{
69763+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69764+ if (append_default) {
69765+ struct task_struct *task = current;
69766+ struct task_struct *parent = task->real_parent;
69767+ const struct cred *cred = __task_cred(task);
69768+ const struct cred *pcred = __task_cred(parent);
69769+ unsigned int len = strlen(buf);
69770+
69771+ 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));
69772+ }
69773+
69774+ printk("%s\n", buf);
69775+
69776+ return;
69777+}
69778+
69779+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69780+{
69781+ int logtype;
69782+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69783+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69784+ void *voidptr = NULL;
69785+ int num1 = 0, num2 = 0;
69786+ unsigned long ulong1 = 0, ulong2 = 0;
69787+ struct dentry *dentry = NULL;
69788+ struct vfsmount *mnt = NULL;
69789+ struct file *file = NULL;
69790+ struct task_struct *task = NULL;
69791+ struct vm_area_struct *vma = NULL;
69792+ const struct cred *cred, *pcred;
69793+ va_list ap;
69794+
69795+ BEGIN_LOCKS(audit);
69796+ logtype = gr_log_start(audit);
69797+ if (logtype == FLOODING) {
69798+ END_LOCKS(audit);
69799+ return;
69800+ }
69801+ va_start(ap, argtypes);
69802+ switch (argtypes) {
69803+ case GR_TTYSNIFF:
69804+ task = va_arg(ap, struct task_struct *);
69805+ 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));
69806+ break;
69807+ case GR_SYSCTL_HIDDEN:
69808+ str1 = va_arg(ap, char *);
69809+ gr_log_middle_varargs(audit, msg, result, str1);
69810+ break;
69811+ case GR_RBAC:
69812+ dentry = va_arg(ap, struct dentry *);
69813+ mnt = va_arg(ap, struct vfsmount *);
69814+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69815+ break;
69816+ case GR_RBAC_STR:
69817+ dentry = va_arg(ap, struct dentry *);
69818+ mnt = va_arg(ap, struct vfsmount *);
69819+ str1 = va_arg(ap, char *);
69820+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69821+ break;
69822+ case GR_STR_RBAC:
69823+ str1 = va_arg(ap, char *);
69824+ dentry = va_arg(ap, struct dentry *);
69825+ mnt = va_arg(ap, struct vfsmount *);
69826+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69827+ break;
69828+ case GR_RBAC_MODE2:
69829+ dentry = va_arg(ap, struct dentry *);
69830+ mnt = va_arg(ap, struct vfsmount *);
69831+ str1 = va_arg(ap, char *);
69832+ str2 = va_arg(ap, char *);
69833+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69834+ break;
69835+ case GR_RBAC_MODE3:
69836+ dentry = va_arg(ap, struct dentry *);
69837+ mnt = va_arg(ap, struct vfsmount *);
69838+ str1 = va_arg(ap, char *);
69839+ str2 = va_arg(ap, char *);
69840+ str3 = va_arg(ap, char *);
69841+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69842+ break;
69843+ case GR_FILENAME:
69844+ dentry = va_arg(ap, struct dentry *);
69845+ mnt = va_arg(ap, struct vfsmount *);
69846+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69847+ break;
69848+ case GR_STR_FILENAME:
69849+ str1 = va_arg(ap, char *);
69850+ dentry = va_arg(ap, struct dentry *);
69851+ mnt = va_arg(ap, struct vfsmount *);
69852+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69853+ break;
69854+ case GR_FILENAME_STR:
69855+ dentry = va_arg(ap, struct dentry *);
69856+ mnt = va_arg(ap, struct vfsmount *);
69857+ str1 = va_arg(ap, char *);
69858+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69859+ break;
69860+ case GR_FILENAME_TWO_INT:
69861+ dentry = va_arg(ap, struct dentry *);
69862+ mnt = va_arg(ap, struct vfsmount *);
69863+ num1 = va_arg(ap, int);
69864+ num2 = va_arg(ap, int);
69865+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69866+ break;
69867+ case GR_FILENAME_TWO_INT_STR:
69868+ dentry = va_arg(ap, struct dentry *);
69869+ mnt = va_arg(ap, struct vfsmount *);
69870+ num1 = va_arg(ap, int);
69871+ num2 = va_arg(ap, int);
69872+ str1 = va_arg(ap, char *);
69873+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69874+ break;
69875+ case GR_TEXTREL:
69876+ file = va_arg(ap, struct file *);
69877+ ulong1 = va_arg(ap, unsigned long);
69878+ ulong2 = va_arg(ap, unsigned long);
69879+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69880+ break;
69881+ case GR_PTRACE:
69882+ task = va_arg(ap, struct task_struct *);
69883+ 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));
69884+ break;
69885+ case GR_RESOURCE:
69886+ task = va_arg(ap, struct task_struct *);
69887+ cred = __task_cred(task);
69888+ pcred = __task_cred(task->real_parent);
69889+ ulong1 = va_arg(ap, unsigned long);
69890+ str1 = va_arg(ap, char *);
69891+ ulong2 = va_arg(ap, unsigned long);
69892+ 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));
69893+ break;
69894+ case GR_CAP:
69895+ task = va_arg(ap, struct task_struct *);
69896+ cred = __task_cred(task);
69897+ pcred = __task_cred(task->real_parent);
69898+ str1 = va_arg(ap, char *);
69899+ 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));
69900+ break;
69901+ case GR_SIG:
69902+ str1 = va_arg(ap, char *);
69903+ voidptr = va_arg(ap, void *);
69904+ gr_log_middle_varargs(audit, msg, str1, voidptr);
69905+ break;
69906+ case GR_SIG2:
69907+ task = va_arg(ap, struct task_struct *);
69908+ cred = __task_cred(task);
69909+ pcred = __task_cred(task->real_parent);
69910+ num1 = va_arg(ap, int);
69911+ 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));
69912+ break;
69913+ case GR_CRASH1:
69914+ task = va_arg(ap, struct task_struct *);
69915+ cred = __task_cred(task);
69916+ pcred = __task_cred(task->real_parent);
69917+ ulong1 = va_arg(ap, unsigned long);
69918+ 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);
69919+ break;
69920+ case GR_CRASH2:
69921+ task = va_arg(ap, struct task_struct *);
69922+ cred = __task_cred(task);
69923+ pcred = __task_cred(task->real_parent);
69924+ ulong1 = va_arg(ap, unsigned long);
69925+ 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);
69926+ break;
69927+ case GR_RWXMAP:
69928+ file = va_arg(ap, struct file *);
69929+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
69930+ break;
69931+ case GR_RWXMAPVMA:
69932+ vma = va_arg(ap, struct vm_area_struct *);
69933+ if (vma->vm_file)
69934+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
69935+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
69936+ str1 = "<stack>";
69937+ else if (vma->vm_start <= current->mm->brk &&
69938+ vma->vm_end >= current->mm->start_brk)
69939+ str1 = "<heap>";
69940+ else
69941+ str1 = "<anonymous mapping>";
69942+ gr_log_middle_varargs(audit, msg, str1);
69943+ break;
69944+ case GR_PSACCT:
69945+ {
69946+ unsigned int wday, cday;
69947+ __u8 whr, chr;
69948+ __u8 wmin, cmin;
69949+ __u8 wsec, csec;
69950+ char cur_tty[64] = { 0 };
69951+ char parent_tty[64] = { 0 };
69952+
69953+ task = va_arg(ap, struct task_struct *);
69954+ wday = va_arg(ap, unsigned int);
69955+ cday = va_arg(ap, unsigned int);
69956+ whr = va_arg(ap, int);
69957+ chr = va_arg(ap, int);
69958+ wmin = va_arg(ap, int);
69959+ cmin = va_arg(ap, int);
69960+ wsec = va_arg(ap, int);
69961+ csec = va_arg(ap, int);
69962+ ulong1 = va_arg(ap, unsigned long);
69963+ cred = __task_cred(task);
69964+ pcred = __task_cred(task->real_parent);
69965+
69966+ 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));
69967+ }
69968+ break;
69969+ default:
69970+ gr_log_middle(audit, msg, ap);
69971+ }
69972+ va_end(ap);
69973+ // these don't need DEFAULTSECARGS printed on the end
69974+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
69975+ gr_log_end(audit, 0);
69976+ else
69977+ gr_log_end(audit, 1);
69978+ END_LOCKS(audit);
69979+}
69980diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
69981new file mode 100644
69982index 0000000..f536303
69983--- /dev/null
69984+++ b/grsecurity/grsec_mem.c
69985@@ -0,0 +1,40 @@
69986+#include <linux/kernel.h>
69987+#include <linux/sched.h>
69988+#include <linux/mm.h>
69989+#include <linux/mman.h>
69990+#include <linux/grinternal.h>
69991+
69992+void
69993+gr_handle_ioperm(void)
69994+{
69995+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
69996+ return;
69997+}
69998+
69999+void
70000+gr_handle_iopl(void)
70001+{
70002+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70003+ return;
70004+}
70005+
70006+void
70007+gr_handle_mem_readwrite(u64 from, u64 to)
70008+{
70009+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70010+ return;
70011+}
70012+
70013+void
70014+gr_handle_vm86(void)
70015+{
70016+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70017+ return;
70018+}
70019+
70020+void
70021+gr_log_badprocpid(const char *entry)
70022+{
70023+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70024+ return;
70025+}
70026diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70027new file mode 100644
70028index 0000000..2131422
70029--- /dev/null
70030+++ b/grsecurity/grsec_mount.c
70031@@ -0,0 +1,62 @@
70032+#include <linux/kernel.h>
70033+#include <linux/sched.h>
70034+#include <linux/mount.h>
70035+#include <linux/grsecurity.h>
70036+#include <linux/grinternal.h>
70037+
70038+void
70039+gr_log_remount(const char *devname, const int retval)
70040+{
70041+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70042+ if (grsec_enable_mount && (retval >= 0))
70043+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70044+#endif
70045+ return;
70046+}
70047+
70048+void
70049+gr_log_unmount(const char *devname, const int retval)
70050+{
70051+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70052+ if (grsec_enable_mount && (retval >= 0))
70053+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70054+#endif
70055+ return;
70056+}
70057+
70058+void
70059+gr_log_mount(const char *from, const char *to, const int retval)
70060+{
70061+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70062+ if (grsec_enable_mount && (retval >= 0))
70063+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70064+#endif
70065+ return;
70066+}
70067+
70068+int
70069+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70070+{
70071+#ifdef CONFIG_GRKERNSEC_ROFS
70072+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70073+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70074+ return -EPERM;
70075+ } else
70076+ return 0;
70077+#endif
70078+ return 0;
70079+}
70080+
70081+int
70082+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70083+{
70084+#ifdef CONFIG_GRKERNSEC_ROFS
70085+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70086+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70087+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70088+ return -EPERM;
70089+ } else
70090+ return 0;
70091+#endif
70092+ return 0;
70093+}
70094diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70095new file mode 100644
70096index 0000000..6ee9d50
70097--- /dev/null
70098+++ b/grsecurity/grsec_pax.c
70099@@ -0,0 +1,45 @@
70100+#include <linux/kernel.h>
70101+#include <linux/sched.h>
70102+#include <linux/mm.h>
70103+#include <linux/file.h>
70104+#include <linux/grinternal.h>
70105+#include <linux/grsecurity.h>
70106+
70107+void
70108+gr_log_textrel(struct vm_area_struct * vma)
70109+{
70110+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70111+ if (grsec_enable_log_rwxmaps)
70112+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70113+#endif
70114+ return;
70115+}
70116+
70117+void gr_log_ptgnustack(struct file *file)
70118+{
70119+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70120+ if (grsec_enable_log_rwxmaps)
70121+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70122+#endif
70123+ return;
70124+}
70125+
70126+void
70127+gr_log_rwxmmap(struct file *file)
70128+{
70129+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70130+ if (grsec_enable_log_rwxmaps)
70131+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70132+#endif
70133+ return;
70134+}
70135+
70136+void
70137+gr_log_rwxmprotect(struct vm_area_struct *vma)
70138+{
70139+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70140+ if (grsec_enable_log_rwxmaps)
70141+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70142+#endif
70143+ return;
70144+}
70145diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70146new file mode 100644
70147index 0000000..f7f29aa
70148--- /dev/null
70149+++ b/grsecurity/grsec_ptrace.c
70150@@ -0,0 +1,30 @@
70151+#include <linux/kernel.h>
70152+#include <linux/sched.h>
70153+#include <linux/grinternal.h>
70154+#include <linux/security.h>
70155+
70156+void
70157+gr_audit_ptrace(struct task_struct *task)
70158+{
70159+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70160+ if (grsec_enable_audit_ptrace)
70161+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70162+#endif
70163+ return;
70164+}
70165+
70166+int
70167+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70168+{
70169+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70170+ const struct dentry *dentry = file->f_path.dentry;
70171+ const struct vfsmount *mnt = file->f_path.mnt;
70172+
70173+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70174+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70175+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70176+ return -EACCES;
70177+ }
70178+#endif
70179+ return 0;
70180+}
70181diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70182new file mode 100644
70183index 0000000..4e29cc7
70184--- /dev/null
70185+++ b/grsecurity/grsec_sig.c
70186@@ -0,0 +1,246 @@
70187+#include <linux/kernel.h>
70188+#include <linux/sched.h>
70189+#include <linux/fs.h>
70190+#include <linux/delay.h>
70191+#include <linux/grsecurity.h>
70192+#include <linux/grinternal.h>
70193+#include <linux/hardirq.h>
70194+
70195+char *signames[] = {
70196+ [SIGSEGV] = "Segmentation fault",
70197+ [SIGILL] = "Illegal instruction",
70198+ [SIGABRT] = "Abort",
70199+ [SIGBUS] = "Invalid alignment/Bus error"
70200+};
70201+
70202+void
70203+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70204+{
70205+#ifdef CONFIG_GRKERNSEC_SIGNAL
70206+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70207+ (sig == SIGABRT) || (sig == SIGBUS))) {
70208+ if (task_pid_nr(t) == task_pid_nr(current)) {
70209+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70210+ } else {
70211+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70212+ }
70213+ }
70214+#endif
70215+ return;
70216+}
70217+
70218+int
70219+gr_handle_signal(const struct task_struct *p, const int sig)
70220+{
70221+#ifdef CONFIG_GRKERNSEC
70222+ /* ignore the 0 signal for protected task checks */
70223+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70224+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70225+ return -EPERM;
70226+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70227+ return -EPERM;
70228+ }
70229+#endif
70230+ return 0;
70231+}
70232+
70233+#ifdef CONFIG_GRKERNSEC
70234+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70235+
70236+int gr_fake_force_sig(int sig, struct task_struct *t)
70237+{
70238+ unsigned long int flags;
70239+ int ret, blocked, ignored;
70240+ struct k_sigaction *action;
70241+
70242+ spin_lock_irqsave(&t->sighand->siglock, flags);
70243+ action = &t->sighand->action[sig-1];
70244+ ignored = action->sa.sa_handler == SIG_IGN;
70245+ blocked = sigismember(&t->blocked, sig);
70246+ if (blocked || ignored) {
70247+ action->sa.sa_handler = SIG_DFL;
70248+ if (blocked) {
70249+ sigdelset(&t->blocked, sig);
70250+ recalc_sigpending_and_wake(t);
70251+ }
70252+ }
70253+ if (action->sa.sa_handler == SIG_DFL)
70254+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70255+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70256+
70257+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70258+
70259+ return ret;
70260+}
70261+#endif
70262+
70263+#ifdef CONFIG_GRKERNSEC_BRUTE
70264+#define GR_USER_BAN_TIME (15 * 60)
70265+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70266+
70267+static int __get_dumpable(unsigned long mm_flags)
70268+{
70269+ int ret;
70270+
70271+ ret = mm_flags & MMF_DUMPABLE_MASK;
70272+ return (ret >= 2) ? 2 : ret;
70273+}
70274+#endif
70275+
70276+void gr_handle_brute_attach(unsigned long mm_flags)
70277+{
70278+#ifdef CONFIG_GRKERNSEC_BRUTE
70279+ struct task_struct *p = current;
70280+ kuid_t uid = GLOBAL_ROOT_UID;
70281+ int daemon = 0;
70282+
70283+ if (!grsec_enable_brute)
70284+ return;
70285+
70286+ rcu_read_lock();
70287+ read_lock(&tasklist_lock);
70288+ read_lock(&grsec_exec_file_lock);
70289+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70290+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70291+ p->real_parent->brute = 1;
70292+ daemon = 1;
70293+ } else {
70294+ const struct cred *cred = __task_cred(p), *cred2;
70295+ struct task_struct *tsk, *tsk2;
70296+
70297+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70298+ struct user_struct *user;
70299+
70300+ uid = cred->uid;
70301+
70302+ /* this is put upon execution past expiration */
70303+ user = find_user(uid);
70304+ if (user == NULL)
70305+ goto unlock;
70306+ user->suid_banned = 1;
70307+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70308+ if (user->suid_ban_expires == ~0UL)
70309+ user->suid_ban_expires--;
70310+
70311+ /* only kill other threads of the same binary, from the same user */
70312+ do_each_thread(tsk2, tsk) {
70313+ cred2 = __task_cred(tsk);
70314+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70315+ gr_fake_force_sig(SIGKILL, tsk);
70316+ } while_each_thread(tsk2, tsk);
70317+ }
70318+ }
70319+unlock:
70320+ read_unlock(&grsec_exec_file_lock);
70321+ read_unlock(&tasklist_lock);
70322+ rcu_read_unlock();
70323+
70324+ if (gr_is_global_nonroot(uid))
70325+ 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);
70326+ else if (daemon)
70327+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70328+
70329+#endif
70330+ return;
70331+}
70332+
70333+void gr_handle_brute_check(void)
70334+{
70335+#ifdef CONFIG_GRKERNSEC_BRUTE
70336+ struct task_struct *p = current;
70337+
70338+ if (unlikely(p->brute)) {
70339+ if (!grsec_enable_brute)
70340+ p->brute = 0;
70341+ else if (time_before(get_seconds(), p->brute_expires))
70342+ msleep(30 * 1000);
70343+ }
70344+#endif
70345+ return;
70346+}
70347+
70348+void gr_handle_kernel_exploit(void)
70349+{
70350+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70351+ const struct cred *cred;
70352+ struct task_struct *tsk, *tsk2;
70353+ struct user_struct *user;
70354+ kuid_t uid;
70355+
70356+ if (in_irq() || in_serving_softirq() || in_nmi())
70357+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70358+
70359+ uid = current_uid();
70360+
70361+ if (gr_is_global_root(uid))
70362+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70363+ else {
70364+ /* kill all the processes of this user, hold a reference
70365+ to their creds struct, and prevent them from creating
70366+ another process until system reset
70367+ */
70368+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70369+ GR_GLOBAL_UID(uid));
70370+ /* we intentionally leak this ref */
70371+ user = get_uid(current->cred->user);
70372+ if (user)
70373+ user->kernel_banned = 1;
70374+
70375+ /* kill all processes of this user */
70376+ read_lock(&tasklist_lock);
70377+ do_each_thread(tsk2, tsk) {
70378+ cred = __task_cred(tsk);
70379+ if (uid_eq(cred->uid, uid))
70380+ gr_fake_force_sig(SIGKILL, tsk);
70381+ } while_each_thread(tsk2, tsk);
70382+ read_unlock(&tasklist_lock);
70383+ }
70384+#endif
70385+}
70386+
70387+#ifdef CONFIG_GRKERNSEC_BRUTE
70388+static bool suid_ban_expired(struct user_struct *user)
70389+{
70390+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70391+ user->suid_banned = 0;
70392+ user->suid_ban_expires = 0;
70393+ free_uid(user);
70394+ return true;
70395+ }
70396+
70397+ return false;
70398+}
70399+#endif
70400+
70401+int gr_process_kernel_exec_ban(void)
70402+{
70403+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70404+ if (unlikely(current->cred->user->kernel_banned))
70405+ return -EPERM;
70406+#endif
70407+ return 0;
70408+}
70409+
70410+int gr_process_kernel_setuid_ban(struct user_struct *user)
70411+{
70412+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70413+ if (unlikely(user->kernel_banned))
70414+ gr_fake_force_sig(SIGKILL, current);
70415+#endif
70416+ return 0;
70417+}
70418+
70419+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70420+{
70421+#ifdef CONFIG_GRKERNSEC_BRUTE
70422+ struct user_struct *user = current->cred->user;
70423+ if (unlikely(user->suid_banned)) {
70424+ if (suid_ban_expired(user))
70425+ return 0;
70426+ /* disallow execution of suid binaries only */
70427+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70428+ return -EPERM;
70429+ }
70430+#endif
70431+ return 0;
70432+}
70433diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70434new file mode 100644
70435index 0000000..4030d57
70436--- /dev/null
70437+++ b/grsecurity/grsec_sock.c
70438@@ -0,0 +1,244 @@
70439+#include <linux/kernel.h>
70440+#include <linux/module.h>
70441+#include <linux/sched.h>
70442+#include <linux/file.h>
70443+#include <linux/net.h>
70444+#include <linux/in.h>
70445+#include <linux/ip.h>
70446+#include <net/sock.h>
70447+#include <net/inet_sock.h>
70448+#include <linux/grsecurity.h>
70449+#include <linux/grinternal.h>
70450+#include <linux/gracl.h>
70451+
70452+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70453+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70454+
70455+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70456+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70457+
70458+#ifdef CONFIG_UNIX_MODULE
70459+EXPORT_SYMBOL(gr_acl_handle_unix);
70460+EXPORT_SYMBOL(gr_acl_handle_mknod);
70461+EXPORT_SYMBOL(gr_handle_chroot_unix);
70462+EXPORT_SYMBOL(gr_handle_create);
70463+#endif
70464+
70465+#ifdef CONFIG_GRKERNSEC
70466+#define gr_conn_table_size 32749
70467+struct conn_table_entry {
70468+ struct conn_table_entry *next;
70469+ struct signal_struct *sig;
70470+};
70471+
70472+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70473+DEFINE_SPINLOCK(gr_conn_table_lock);
70474+
70475+extern const char * gr_socktype_to_name(unsigned char type);
70476+extern const char * gr_proto_to_name(unsigned char proto);
70477+extern const char * gr_sockfamily_to_name(unsigned char family);
70478+
70479+static __inline__ int
70480+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70481+{
70482+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70483+}
70484+
70485+static __inline__ int
70486+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70487+ __u16 sport, __u16 dport)
70488+{
70489+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70490+ sig->gr_sport == sport && sig->gr_dport == dport))
70491+ return 1;
70492+ else
70493+ return 0;
70494+}
70495+
70496+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70497+{
70498+ struct conn_table_entry **match;
70499+ unsigned int index;
70500+
70501+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70502+ sig->gr_sport, sig->gr_dport,
70503+ gr_conn_table_size);
70504+
70505+ newent->sig = sig;
70506+
70507+ match = &gr_conn_table[index];
70508+ newent->next = *match;
70509+ *match = newent;
70510+
70511+ return;
70512+}
70513+
70514+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70515+{
70516+ struct conn_table_entry *match, *last = NULL;
70517+ unsigned int index;
70518+
70519+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70520+ sig->gr_sport, sig->gr_dport,
70521+ gr_conn_table_size);
70522+
70523+ match = gr_conn_table[index];
70524+ while (match && !conn_match(match->sig,
70525+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70526+ sig->gr_dport)) {
70527+ last = match;
70528+ match = match->next;
70529+ }
70530+
70531+ if (match) {
70532+ if (last)
70533+ last->next = match->next;
70534+ else
70535+ gr_conn_table[index] = NULL;
70536+ kfree(match);
70537+ }
70538+
70539+ return;
70540+}
70541+
70542+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70543+ __u16 sport, __u16 dport)
70544+{
70545+ struct conn_table_entry *match;
70546+ unsigned int index;
70547+
70548+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70549+
70550+ match = gr_conn_table[index];
70551+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70552+ match = match->next;
70553+
70554+ if (match)
70555+ return match->sig;
70556+ else
70557+ return NULL;
70558+}
70559+
70560+#endif
70561+
70562+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70563+{
70564+#ifdef CONFIG_GRKERNSEC
70565+ struct signal_struct *sig = task->signal;
70566+ struct conn_table_entry *newent;
70567+
70568+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70569+ if (newent == NULL)
70570+ return;
70571+ /* no bh lock needed since we are called with bh disabled */
70572+ spin_lock(&gr_conn_table_lock);
70573+ gr_del_task_from_ip_table_nolock(sig);
70574+ sig->gr_saddr = inet->inet_rcv_saddr;
70575+ sig->gr_daddr = inet->inet_daddr;
70576+ sig->gr_sport = inet->inet_sport;
70577+ sig->gr_dport = inet->inet_dport;
70578+ gr_add_to_task_ip_table_nolock(sig, newent);
70579+ spin_unlock(&gr_conn_table_lock);
70580+#endif
70581+ return;
70582+}
70583+
70584+void gr_del_task_from_ip_table(struct task_struct *task)
70585+{
70586+#ifdef CONFIG_GRKERNSEC
70587+ spin_lock_bh(&gr_conn_table_lock);
70588+ gr_del_task_from_ip_table_nolock(task->signal);
70589+ spin_unlock_bh(&gr_conn_table_lock);
70590+#endif
70591+ return;
70592+}
70593+
70594+void
70595+gr_attach_curr_ip(const struct sock *sk)
70596+{
70597+#ifdef CONFIG_GRKERNSEC
70598+ struct signal_struct *p, *set;
70599+ const struct inet_sock *inet = inet_sk(sk);
70600+
70601+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70602+ return;
70603+
70604+ set = current->signal;
70605+
70606+ spin_lock_bh(&gr_conn_table_lock);
70607+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70608+ inet->inet_dport, inet->inet_sport);
70609+ if (unlikely(p != NULL)) {
70610+ set->curr_ip = p->curr_ip;
70611+ set->used_accept = 1;
70612+ gr_del_task_from_ip_table_nolock(p);
70613+ spin_unlock_bh(&gr_conn_table_lock);
70614+ return;
70615+ }
70616+ spin_unlock_bh(&gr_conn_table_lock);
70617+
70618+ set->curr_ip = inet->inet_daddr;
70619+ set->used_accept = 1;
70620+#endif
70621+ return;
70622+}
70623+
70624+int
70625+gr_handle_sock_all(const int family, const int type, const int protocol)
70626+{
70627+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70628+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70629+ (family != AF_UNIX)) {
70630+ if (family == AF_INET)
70631+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70632+ else
70633+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70634+ return -EACCES;
70635+ }
70636+#endif
70637+ return 0;
70638+}
70639+
70640+int
70641+gr_handle_sock_server(const struct sockaddr *sck)
70642+{
70643+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70644+ if (grsec_enable_socket_server &&
70645+ in_group_p(grsec_socket_server_gid) &&
70646+ sck && (sck->sa_family != AF_UNIX) &&
70647+ (sck->sa_family != AF_LOCAL)) {
70648+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70649+ return -EACCES;
70650+ }
70651+#endif
70652+ return 0;
70653+}
70654+
70655+int
70656+gr_handle_sock_server_other(const struct sock *sck)
70657+{
70658+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70659+ if (grsec_enable_socket_server &&
70660+ in_group_p(grsec_socket_server_gid) &&
70661+ sck && (sck->sk_family != AF_UNIX) &&
70662+ (sck->sk_family != AF_LOCAL)) {
70663+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70664+ return -EACCES;
70665+ }
70666+#endif
70667+ return 0;
70668+}
70669+
70670+int
70671+gr_handle_sock_client(const struct sockaddr *sck)
70672+{
70673+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70674+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70675+ sck && (sck->sa_family != AF_UNIX) &&
70676+ (sck->sa_family != AF_LOCAL)) {
70677+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70678+ return -EACCES;
70679+ }
70680+#endif
70681+ return 0;
70682+}
70683diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70684new file mode 100644
70685index 0000000..a147ae7
70686--- /dev/null
70687+++ b/grsecurity/grsec_sysctl.c
70688@@ -0,0 +1,470 @@
70689+#include <linux/kernel.h>
70690+#include <linux/sched.h>
70691+#include <linux/sysctl.h>
70692+#include <linux/grsecurity.h>
70693+#include <linux/grinternal.h>
70694+
70695+int
70696+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70697+{
70698+#ifdef CONFIG_GRKERNSEC_SYSCTL
70699+ if (dirname == NULL || name == NULL)
70700+ return 0;
70701+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70702+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70703+ return -EACCES;
70704+ }
70705+#endif
70706+ return 0;
70707+}
70708+
70709+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70710+static int __maybe_unused __read_only one = 1;
70711+#endif
70712+
70713+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70714+ defined(CONFIG_GRKERNSEC_DENYUSB)
70715+struct ctl_table grsecurity_table[] = {
70716+#ifdef CONFIG_GRKERNSEC_SYSCTL
70717+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70718+#ifdef CONFIG_GRKERNSEC_IO
70719+ {
70720+ .procname = "disable_priv_io",
70721+ .data = &grsec_disable_privio,
70722+ .maxlen = sizeof(int),
70723+ .mode = 0600,
70724+ .proc_handler = &proc_dointvec,
70725+ },
70726+#endif
70727+#endif
70728+#ifdef CONFIG_GRKERNSEC_LINK
70729+ {
70730+ .procname = "linking_restrictions",
70731+ .data = &grsec_enable_link,
70732+ .maxlen = sizeof(int),
70733+ .mode = 0600,
70734+ .proc_handler = &proc_dointvec,
70735+ },
70736+#endif
70737+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70738+ {
70739+ .procname = "enforce_symlinksifowner",
70740+ .data = &grsec_enable_symlinkown,
70741+ .maxlen = sizeof(int),
70742+ .mode = 0600,
70743+ .proc_handler = &proc_dointvec,
70744+ },
70745+ {
70746+ .procname = "symlinkown_gid",
70747+ .data = &grsec_symlinkown_gid,
70748+ .maxlen = sizeof(int),
70749+ .mode = 0600,
70750+ .proc_handler = &proc_dointvec,
70751+ },
70752+#endif
70753+#ifdef CONFIG_GRKERNSEC_BRUTE
70754+ {
70755+ .procname = "deter_bruteforce",
70756+ .data = &grsec_enable_brute,
70757+ .maxlen = sizeof(int),
70758+ .mode = 0600,
70759+ .proc_handler = &proc_dointvec,
70760+ },
70761+#endif
70762+#ifdef CONFIG_GRKERNSEC_FIFO
70763+ {
70764+ .procname = "fifo_restrictions",
70765+ .data = &grsec_enable_fifo,
70766+ .maxlen = sizeof(int),
70767+ .mode = 0600,
70768+ .proc_handler = &proc_dointvec,
70769+ },
70770+#endif
70771+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70772+ {
70773+ .procname = "ptrace_readexec",
70774+ .data = &grsec_enable_ptrace_readexec,
70775+ .maxlen = sizeof(int),
70776+ .mode = 0600,
70777+ .proc_handler = &proc_dointvec,
70778+ },
70779+#endif
70780+#ifdef CONFIG_GRKERNSEC_SETXID
70781+ {
70782+ .procname = "consistent_setxid",
70783+ .data = &grsec_enable_setxid,
70784+ .maxlen = sizeof(int),
70785+ .mode = 0600,
70786+ .proc_handler = &proc_dointvec,
70787+ },
70788+#endif
70789+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70790+ {
70791+ .procname = "ip_blackhole",
70792+ .data = &grsec_enable_blackhole,
70793+ .maxlen = sizeof(int),
70794+ .mode = 0600,
70795+ .proc_handler = &proc_dointvec,
70796+ },
70797+ {
70798+ .procname = "lastack_retries",
70799+ .data = &grsec_lastack_retries,
70800+ .maxlen = sizeof(int),
70801+ .mode = 0600,
70802+ .proc_handler = &proc_dointvec,
70803+ },
70804+#endif
70805+#ifdef CONFIG_GRKERNSEC_EXECLOG
70806+ {
70807+ .procname = "exec_logging",
70808+ .data = &grsec_enable_execlog,
70809+ .maxlen = sizeof(int),
70810+ .mode = 0600,
70811+ .proc_handler = &proc_dointvec,
70812+ },
70813+#endif
70814+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70815+ {
70816+ .procname = "rwxmap_logging",
70817+ .data = &grsec_enable_log_rwxmaps,
70818+ .maxlen = sizeof(int),
70819+ .mode = 0600,
70820+ .proc_handler = &proc_dointvec,
70821+ },
70822+#endif
70823+#ifdef CONFIG_GRKERNSEC_SIGNAL
70824+ {
70825+ .procname = "signal_logging",
70826+ .data = &grsec_enable_signal,
70827+ .maxlen = sizeof(int),
70828+ .mode = 0600,
70829+ .proc_handler = &proc_dointvec,
70830+ },
70831+#endif
70832+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70833+ {
70834+ .procname = "forkfail_logging",
70835+ .data = &grsec_enable_forkfail,
70836+ .maxlen = sizeof(int),
70837+ .mode = 0600,
70838+ .proc_handler = &proc_dointvec,
70839+ },
70840+#endif
70841+#ifdef CONFIG_GRKERNSEC_TIME
70842+ {
70843+ .procname = "timechange_logging",
70844+ .data = &grsec_enable_time,
70845+ .maxlen = sizeof(int),
70846+ .mode = 0600,
70847+ .proc_handler = &proc_dointvec,
70848+ },
70849+#endif
70850+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70851+ {
70852+ .procname = "chroot_deny_shmat",
70853+ .data = &grsec_enable_chroot_shmat,
70854+ .maxlen = sizeof(int),
70855+ .mode = 0600,
70856+ .proc_handler = &proc_dointvec,
70857+ },
70858+#endif
70859+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70860+ {
70861+ .procname = "chroot_deny_unix",
70862+ .data = &grsec_enable_chroot_unix,
70863+ .maxlen = sizeof(int),
70864+ .mode = 0600,
70865+ .proc_handler = &proc_dointvec,
70866+ },
70867+#endif
70868+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70869+ {
70870+ .procname = "chroot_deny_mount",
70871+ .data = &grsec_enable_chroot_mount,
70872+ .maxlen = sizeof(int),
70873+ .mode = 0600,
70874+ .proc_handler = &proc_dointvec,
70875+ },
70876+#endif
70877+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70878+ {
70879+ .procname = "chroot_deny_fchdir",
70880+ .data = &grsec_enable_chroot_fchdir,
70881+ .maxlen = sizeof(int),
70882+ .mode = 0600,
70883+ .proc_handler = &proc_dointvec,
70884+ },
70885+#endif
70886+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70887+ {
70888+ .procname = "chroot_deny_chroot",
70889+ .data = &grsec_enable_chroot_double,
70890+ .maxlen = sizeof(int),
70891+ .mode = 0600,
70892+ .proc_handler = &proc_dointvec,
70893+ },
70894+#endif
70895+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70896+ {
70897+ .procname = "chroot_deny_pivot",
70898+ .data = &grsec_enable_chroot_pivot,
70899+ .maxlen = sizeof(int),
70900+ .mode = 0600,
70901+ .proc_handler = &proc_dointvec,
70902+ },
70903+#endif
70904+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70905+ {
70906+ .procname = "chroot_enforce_chdir",
70907+ .data = &grsec_enable_chroot_chdir,
70908+ .maxlen = sizeof(int),
70909+ .mode = 0600,
70910+ .proc_handler = &proc_dointvec,
70911+ },
70912+#endif
70913+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70914+ {
70915+ .procname = "chroot_deny_chmod",
70916+ .data = &grsec_enable_chroot_chmod,
70917+ .maxlen = sizeof(int),
70918+ .mode = 0600,
70919+ .proc_handler = &proc_dointvec,
70920+ },
70921+#endif
70922+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70923+ {
70924+ .procname = "chroot_deny_mknod",
70925+ .data = &grsec_enable_chroot_mknod,
70926+ .maxlen = sizeof(int),
70927+ .mode = 0600,
70928+ .proc_handler = &proc_dointvec,
70929+ },
70930+#endif
70931+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70932+ {
70933+ .procname = "chroot_restrict_nice",
70934+ .data = &grsec_enable_chroot_nice,
70935+ .maxlen = sizeof(int),
70936+ .mode = 0600,
70937+ .proc_handler = &proc_dointvec,
70938+ },
70939+#endif
70940+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70941+ {
70942+ .procname = "chroot_execlog",
70943+ .data = &grsec_enable_chroot_execlog,
70944+ .maxlen = sizeof(int),
70945+ .mode = 0600,
70946+ .proc_handler = &proc_dointvec,
70947+ },
70948+#endif
70949+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70950+ {
70951+ .procname = "chroot_caps",
70952+ .data = &grsec_enable_chroot_caps,
70953+ .maxlen = sizeof(int),
70954+ .mode = 0600,
70955+ .proc_handler = &proc_dointvec,
70956+ },
70957+#endif
70958+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70959+ {
70960+ .procname = "chroot_deny_sysctl",
70961+ .data = &grsec_enable_chroot_sysctl,
70962+ .maxlen = sizeof(int),
70963+ .mode = 0600,
70964+ .proc_handler = &proc_dointvec,
70965+ },
70966+#endif
70967+#ifdef CONFIG_GRKERNSEC_TPE
70968+ {
70969+ .procname = "tpe",
70970+ .data = &grsec_enable_tpe,
70971+ .maxlen = sizeof(int),
70972+ .mode = 0600,
70973+ .proc_handler = &proc_dointvec,
70974+ },
70975+ {
70976+ .procname = "tpe_gid",
70977+ .data = &grsec_tpe_gid,
70978+ .maxlen = sizeof(int),
70979+ .mode = 0600,
70980+ .proc_handler = &proc_dointvec,
70981+ },
70982+#endif
70983+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70984+ {
70985+ .procname = "tpe_invert",
70986+ .data = &grsec_enable_tpe_invert,
70987+ .maxlen = sizeof(int),
70988+ .mode = 0600,
70989+ .proc_handler = &proc_dointvec,
70990+ },
70991+#endif
70992+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70993+ {
70994+ .procname = "tpe_restrict_all",
70995+ .data = &grsec_enable_tpe_all,
70996+ .maxlen = sizeof(int),
70997+ .mode = 0600,
70998+ .proc_handler = &proc_dointvec,
70999+ },
71000+#endif
71001+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71002+ {
71003+ .procname = "socket_all",
71004+ .data = &grsec_enable_socket_all,
71005+ .maxlen = sizeof(int),
71006+ .mode = 0600,
71007+ .proc_handler = &proc_dointvec,
71008+ },
71009+ {
71010+ .procname = "socket_all_gid",
71011+ .data = &grsec_socket_all_gid,
71012+ .maxlen = sizeof(int),
71013+ .mode = 0600,
71014+ .proc_handler = &proc_dointvec,
71015+ },
71016+#endif
71017+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71018+ {
71019+ .procname = "socket_client",
71020+ .data = &grsec_enable_socket_client,
71021+ .maxlen = sizeof(int),
71022+ .mode = 0600,
71023+ .proc_handler = &proc_dointvec,
71024+ },
71025+ {
71026+ .procname = "socket_client_gid",
71027+ .data = &grsec_socket_client_gid,
71028+ .maxlen = sizeof(int),
71029+ .mode = 0600,
71030+ .proc_handler = &proc_dointvec,
71031+ },
71032+#endif
71033+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71034+ {
71035+ .procname = "socket_server",
71036+ .data = &grsec_enable_socket_server,
71037+ .maxlen = sizeof(int),
71038+ .mode = 0600,
71039+ .proc_handler = &proc_dointvec,
71040+ },
71041+ {
71042+ .procname = "socket_server_gid",
71043+ .data = &grsec_socket_server_gid,
71044+ .maxlen = sizeof(int),
71045+ .mode = 0600,
71046+ .proc_handler = &proc_dointvec,
71047+ },
71048+#endif
71049+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71050+ {
71051+ .procname = "audit_group",
71052+ .data = &grsec_enable_group,
71053+ .maxlen = sizeof(int),
71054+ .mode = 0600,
71055+ .proc_handler = &proc_dointvec,
71056+ },
71057+ {
71058+ .procname = "audit_gid",
71059+ .data = &grsec_audit_gid,
71060+ .maxlen = sizeof(int),
71061+ .mode = 0600,
71062+ .proc_handler = &proc_dointvec,
71063+ },
71064+#endif
71065+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71066+ {
71067+ .procname = "audit_chdir",
71068+ .data = &grsec_enable_chdir,
71069+ .maxlen = sizeof(int),
71070+ .mode = 0600,
71071+ .proc_handler = &proc_dointvec,
71072+ },
71073+#endif
71074+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71075+ {
71076+ .procname = "audit_mount",
71077+ .data = &grsec_enable_mount,
71078+ .maxlen = sizeof(int),
71079+ .mode = 0600,
71080+ .proc_handler = &proc_dointvec,
71081+ },
71082+#endif
71083+#ifdef CONFIG_GRKERNSEC_DMESG
71084+ {
71085+ .procname = "dmesg",
71086+ .data = &grsec_enable_dmesg,
71087+ .maxlen = sizeof(int),
71088+ .mode = 0600,
71089+ .proc_handler = &proc_dointvec,
71090+ },
71091+#endif
71092+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71093+ {
71094+ .procname = "chroot_findtask",
71095+ .data = &grsec_enable_chroot_findtask,
71096+ .maxlen = sizeof(int),
71097+ .mode = 0600,
71098+ .proc_handler = &proc_dointvec,
71099+ },
71100+#endif
71101+#ifdef CONFIG_GRKERNSEC_RESLOG
71102+ {
71103+ .procname = "resource_logging",
71104+ .data = &grsec_resource_logging,
71105+ .maxlen = sizeof(int),
71106+ .mode = 0600,
71107+ .proc_handler = &proc_dointvec,
71108+ },
71109+#endif
71110+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71111+ {
71112+ .procname = "audit_ptrace",
71113+ .data = &grsec_enable_audit_ptrace,
71114+ .maxlen = sizeof(int),
71115+ .mode = 0600,
71116+ .proc_handler = &proc_dointvec,
71117+ },
71118+#endif
71119+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71120+ {
71121+ .procname = "harden_ptrace",
71122+ .data = &grsec_enable_harden_ptrace,
71123+ .maxlen = sizeof(int),
71124+ .mode = 0600,
71125+ .proc_handler = &proc_dointvec,
71126+ },
71127+#endif
71128+ {
71129+ .procname = "grsec_lock",
71130+ .data = &grsec_lock,
71131+ .maxlen = sizeof(int),
71132+ .mode = 0600,
71133+ .proc_handler = &proc_dointvec,
71134+ },
71135+#endif
71136+#ifdef CONFIG_GRKERNSEC_ROFS
71137+ {
71138+ .procname = "romount_protect",
71139+ .data = &grsec_enable_rofs,
71140+ .maxlen = sizeof(int),
71141+ .mode = 0600,
71142+ .proc_handler = &proc_dointvec_minmax,
71143+ .extra1 = &one,
71144+ .extra2 = &one,
71145+ },
71146+#endif
71147+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71148+ {
71149+ .procname = "deny_new_usb",
71150+ .data = &grsec_deny_new_usb,
71151+ .maxlen = sizeof(int),
71152+ .mode = 0600,
71153+ .proc_handler = &proc_dointvec,
71154+ },
71155+#endif
71156+ { }
71157+};
71158+#endif
71159diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71160new file mode 100644
71161index 0000000..0dc13c3
71162--- /dev/null
71163+++ b/grsecurity/grsec_time.c
71164@@ -0,0 +1,16 @@
71165+#include <linux/kernel.h>
71166+#include <linux/sched.h>
71167+#include <linux/grinternal.h>
71168+#include <linux/module.h>
71169+
71170+void
71171+gr_log_timechange(void)
71172+{
71173+#ifdef CONFIG_GRKERNSEC_TIME
71174+ if (grsec_enable_time)
71175+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71176+#endif
71177+ return;
71178+}
71179+
71180+EXPORT_SYMBOL(gr_log_timechange);
71181diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71182new file mode 100644
71183index 0000000..ee57dcf
71184--- /dev/null
71185+++ b/grsecurity/grsec_tpe.c
71186@@ -0,0 +1,73 @@
71187+#include <linux/kernel.h>
71188+#include <linux/sched.h>
71189+#include <linux/file.h>
71190+#include <linux/fs.h>
71191+#include <linux/grinternal.h>
71192+
71193+extern int gr_acl_tpe_check(void);
71194+
71195+int
71196+gr_tpe_allow(const struct file *file)
71197+{
71198+#ifdef CONFIG_GRKERNSEC
71199+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71200+ const struct cred *cred = current_cred();
71201+ char *msg = NULL;
71202+ char *msg2 = NULL;
71203+
71204+ // never restrict root
71205+ if (gr_is_global_root(cred->uid))
71206+ return 1;
71207+
71208+ if (grsec_enable_tpe) {
71209+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71210+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71211+ msg = "not being in trusted group";
71212+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71213+ msg = "being in untrusted group";
71214+#else
71215+ if (in_group_p(grsec_tpe_gid))
71216+ msg = "being in untrusted group";
71217+#endif
71218+ }
71219+ if (!msg && gr_acl_tpe_check())
71220+ msg = "being in untrusted role";
71221+
71222+ // not in any affected group/role
71223+ if (!msg)
71224+ goto next_check;
71225+
71226+ if (gr_is_global_nonroot(inode->i_uid))
71227+ msg2 = "file in non-root-owned directory";
71228+ else if (inode->i_mode & S_IWOTH)
71229+ msg2 = "file in world-writable directory";
71230+ else if (inode->i_mode & S_IWGRP)
71231+ msg2 = "file in group-writable directory";
71232+
71233+ if (msg && msg2) {
71234+ char fullmsg[70] = {0};
71235+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71236+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71237+ return 0;
71238+ }
71239+ msg = NULL;
71240+next_check:
71241+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71242+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71243+ return 1;
71244+
71245+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71246+ msg = "directory not owned by user";
71247+ else if (inode->i_mode & S_IWOTH)
71248+ msg = "file in world-writable directory";
71249+ else if (inode->i_mode & S_IWGRP)
71250+ msg = "file in group-writable directory";
71251+
71252+ if (msg) {
71253+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71254+ return 0;
71255+ }
71256+#endif
71257+#endif
71258+ return 1;
71259+}
71260diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71261new file mode 100644
71262index 0000000..ae02d8e
71263--- /dev/null
71264+++ b/grsecurity/grsec_usb.c
71265@@ -0,0 +1,15 @@
71266+#include <linux/kernel.h>
71267+#include <linux/grinternal.h>
71268+#include <linux/module.h>
71269+
71270+int gr_handle_new_usb(void)
71271+{
71272+#ifdef CONFIG_GRKERNSEC_DENYUSB
71273+ if (grsec_deny_new_usb) {
71274+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71275+ return 1;
71276+ }
71277+#endif
71278+ return 0;
71279+}
71280+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71281diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71282new file mode 100644
71283index 0000000..9f7b1ac
71284--- /dev/null
71285+++ b/grsecurity/grsum.c
71286@@ -0,0 +1,61 @@
71287+#include <linux/err.h>
71288+#include <linux/kernel.h>
71289+#include <linux/sched.h>
71290+#include <linux/mm.h>
71291+#include <linux/scatterlist.h>
71292+#include <linux/crypto.h>
71293+#include <linux/gracl.h>
71294+
71295+
71296+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71297+#error "crypto and sha256 must be built into the kernel"
71298+#endif
71299+
71300+int
71301+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71302+{
71303+ char *p;
71304+ struct crypto_hash *tfm;
71305+ struct hash_desc desc;
71306+ struct scatterlist sg;
71307+ unsigned char temp_sum[GR_SHA_LEN];
71308+ volatile int retval = 0;
71309+ volatile int dummy = 0;
71310+ unsigned int i;
71311+
71312+ sg_init_table(&sg, 1);
71313+
71314+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71315+ if (IS_ERR(tfm)) {
71316+ /* should never happen, since sha256 should be built in */
71317+ return 1;
71318+ }
71319+
71320+ desc.tfm = tfm;
71321+ desc.flags = 0;
71322+
71323+ crypto_hash_init(&desc);
71324+
71325+ p = salt;
71326+ sg_set_buf(&sg, p, GR_SALT_LEN);
71327+ crypto_hash_update(&desc, &sg, sg.length);
71328+
71329+ p = entry->pw;
71330+ sg_set_buf(&sg, p, strlen(p));
71331+
71332+ crypto_hash_update(&desc, &sg, sg.length);
71333+
71334+ crypto_hash_final(&desc, temp_sum);
71335+
71336+ memset(entry->pw, 0, GR_PW_LEN);
71337+
71338+ for (i = 0; i < GR_SHA_LEN; i++)
71339+ if (sum[i] != temp_sum[i])
71340+ retval = 1;
71341+ else
71342+ dummy = 1; // waste a cycle
71343+
71344+ crypto_free_hash(tfm);
71345+
71346+ return retval;
71347+}
71348diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71349index 77ff547..181834f 100644
71350--- a/include/asm-generic/4level-fixup.h
71351+++ b/include/asm-generic/4level-fixup.h
71352@@ -13,8 +13,10 @@
71353 #define pmd_alloc(mm, pud, address) \
71354 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71355 NULL: pmd_offset(pud, address))
71356+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71357
71358 #define pud_alloc(mm, pgd, address) (pgd)
71359+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71360 #define pud_offset(pgd, start) (pgd)
71361 #define pud_none(pud) 0
71362 #define pud_bad(pud) 0
71363diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71364index b7babf0..04ad282 100644
71365--- a/include/asm-generic/atomic-long.h
71366+++ b/include/asm-generic/atomic-long.h
71367@@ -22,6 +22,12 @@
71368
71369 typedef atomic64_t atomic_long_t;
71370
71371+#ifdef CONFIG_PAX_REFCOUNT
71372+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71373+#else
71374+typedef atomic64_t atomic_long_unchecked_t;
71375+#endif
71376+
71377 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71378
71379 static inline long atomic_long_read(atomic_long_t *l)
71380@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71381 return (long)atomic64_read(v);
71382 }
71383
71384+#ifdef CONFIG_PAX_REFCOUNT
71385+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71386+{
71387+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71388+
71389+ return (long)atomic64_read_unchecked(v);
71390+}
71391+#endif
71392+
71393 static inline void atomic_long_set(atomic_long_t *l, long i)
71394 {
71395 atomic64_t *v = (atomic64_t *)l;
71396@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71397 atomic64_set(v, i);
71398 }
71399
71400+#ifdef CONFIG_PAX_REFCOUNT
71401+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71402+{
71403+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71404+
71405+ atomic64_set_unchecked(v, i);
71406+}
71407+#endif
71408+
71409 static inline void atomic_long_inc(atomic_long_t *l)
71410 {
71411 atomic64_t *v = (atomic64_t *)l;
71412@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71413 atomic64_inc(v);
71414 }
71415
71416+#ifdef CONFIG_PAX_REFCOUNT
71417+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71418+{
71419+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71420+
71421+ atomic64_inc_unchecked(v);
71422+}
71423+#endif
71424+
71425 static inline void atomic_long_dec(atomic_long_t *l)
71426 {
71427 atomic64_t *v = (atomic64_t *)l;
71428@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71429 atomic64_dec(v);
71430 }
71431
71432+#ifdef CONFIG_PAX_REFCOUNT
71433+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71434+{
71435+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71436+
71437+ atomic64_dec_unchecked(v);
71438+}
71439+#endif
71440+
71441 static inline void atomic_long_add(long i, atomic_long_t *l)
71442 {
71443 atomic64_t *v = (atomic64_t *)l;
71444@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71445 atomic64_add(i, v);
71446 }
71447
71448+#ifdef CONFIG_PAX_REFCOUNT
71449+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71450+{
71451+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71452+
71453+ atomic64_add_unchecked(i, v);
71454+}
71455+#endif
71456+
71457 static inline void atomic_long_sub(long i, atomic_long_t *l)
71458 {
71459 atomic64_t *v = (atomic64_t *)l;
71460@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71461 atomic64_sub(i, v);
71462 }
71463
71464+#ifdef CONFIG_PAX_REFCOUNT
71465+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71466+{
71467+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71468+
71469+ atomic64_sub_unchecked(i, v);
71470+}
71471+#endif
71472+
71473 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71474 {
71475 atomic64_t *v = (atomic64_t *)l;
71476@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71477 return (long)atomic64_add_return(i, v);
71478 }
71479
71480+#ifdef CONFIG_PAX_REFCOUNT
71481+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71482+{
71483+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71484+
71485+ return (long)atomic64_add_return_unchecked(i, v);
71486+}
71487+#endif
71488+
71489 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71490 {
71491 atomic64_t *v = (atomic64_t *)l;
71492@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71493 return (long)atomic64_inc_return(v);
71494 }
71495
71496+#ifdef CONFIG_PAX_REFCOUNT
71497+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71498+{
71499+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71500+
71501+ return (long)atomic64_inc_return_unchecked(v);
71502+}
71503+#endif
71504+
71505 static inline long atomic_long_dec_return(atomic_long_t *l)
71506 {
71507 atomic64_t *v = (atomic64_t *)l;
71508@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71509
71510 typedef atomic_t atomic_long_t;
71511
71512+#ifdef CONFIG_PAX_REFCOUNT
71513+typedef atomic_unchecked_t atomic_long_unchecked_t;
71514+#else
71515+typedef atomic_t atomic_long_unchecked_t;
71516+#endif
71517+
71518 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71519 static inline long atomic_long_read(atomic_long_t *l)
71520 {
71521@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71522 return (long)atomic_read(v);
71523 }
71524
71525+#ifdef CONFIG_PAX_REFCOUNT
71526+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71527+{
71528+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71529+
71530+ return (long)atomic_read_unchecked(v);
71531+}
71532+#endif
71533+
71534 static inline void atomic_long_set(atomic_long_t *l, long i)
71535 {
71536 atomic_t *v = (atomic_t *)l;
71537@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71538 atomic_set(v, i);
71539 }
71540
71541+#ifdef CONFIG_PAX_REFCOUNT
71542+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71543+{
71544+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71545+
71546+ atomic_set_unchecked(v, i);
71547+}
71548+#endif
71549+
71550 static inline void atomic_long_inc(atomic_long_t *l)
71551 {
71552 atomic_t *v = (atomic_t *)l;
71553@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71554 atomic_inc(v);
71555 }
71556
71557+#ifdef CONFIG_PAX_REFCOUNT
71558+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71559+{
71560+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71561+
71562+ atomic_inc_unchecked(v);
71563+}
71564+#endif
71565+
71566 static inline void atomic_long_dec(atomic_long_t *l)
71567 {
71568 atomic_t *v = (atomic_t *)l;
71569@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71570 atomic_dec(v);
71571 }
71572
71573+#ifdef CONFIG_PAX_REFCOUNT
71574+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71575+{
71576+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71577+
71578+ atomic_dec_unchecked(v);
71579+}
71580+#endif
71581+
71582 static inline void atomic_long_add(long i, atomic_long_t *l)
71583 {
71584 atomic_t *v = (atomic_t *)l;
71585@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71586 atomic_add(i, v);
71587 }
71588
71589+#ifdef CONFIG_PAX_REFCOUNT
71590+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71591+{
71592+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71593+
71594+ atomic_add_unchecked(i, v);
71595+}
71596+#endif
71597+
71598 static inline void atomic_long_sub(long i, atomic_long_t *l)
71599 {
71600 atomic_t *v = (atomic_t *)l;
71601@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71602 atomic_sub(i, v);
71603 }
71604
71605+#ifdef CONFIG_PAX_REFCOUNT
71606+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71607+{
71608+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71609+
71610+ atomic_sub_unchecked(i, v);
71611+}
71612+#endif
71613+
71614 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71615 {
71616 atomic_t *v = (atomic_t *)l;
71617@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71618 return (long)atomic_add_return(i, v);
71619 }
71620
71621+#ifdef CONFIG_PAX_REFCOUNT
71622+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71623+{
71624+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71625+
71626+ return (long)atomic_add_return_unchecked(i, v);
71627+}
71628+
71629+#endif
71630+
71631 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71632 {
71633 atomic_t *v = (atomic_t *)l;
71634@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71635 return (long)atomic_inc_return(v);
71636 }
71637
71638+#ifdef CONFIG_PAX_REFCOUNT
71639+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71640+{
71641+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71642+
71643+ return (long)atomic_inc_return_unchecked(v);
71644+}
71645+#endif
71646+
71647 static inline long atomic_long_dec_return(atomic_long_t *l)
71648 {
71649 atomic_t *v = (atomic_t *)l;
71650@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71651
71652 #endif /* BITS_PER_LONG == 64 */
71653
71654+#ifdef CONFIG_PAX_REFCOUNT
71655+static inline void pax_refcount_needs_these_functions(void)
71656+{
71657+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71658+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71659+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71660+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71661+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71662+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71663+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71664+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71665+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71666+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71667+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71668+#ifdef CONFIG_X86
71669+ atomic_clear_mask_unchecked(0, NULL);
71670+ atomic_set_mask_unchecked(0, NULL);
71671+#endif
71672+
71673+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71674+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71675+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71676+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71677+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71678+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71679+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71680+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71681+}
71682+#else
71683+#define atomic_read_unchecked(v) atomic_read(v)
71684+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71685+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71686+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71687+#define atomic_inc_unchecked(v) atomic_inc(v)
71688+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71689+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71690+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71691+#define atomic_dec_unchecked(v) atomic_dec(v)
71692+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71693+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71694+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71695+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71696+
71697+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71698+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71699+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71700+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71701+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71702+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71703+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71704+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71705+#endif
71706+
71707 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71708diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71709index 33bd2de..f31bff97 100644
71710--- a/include/asm-generic/atomic.h
71711+++ b/include/asm-generic/atomic.h
71712@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71713 * Atomically clears the bits set in @mask from @v
71714 */
71715 #ifndef atomic_clear_mask
71716-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71717+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71718 {
71719 unsigned long flags;
71720
71721diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71722index b18ce4f..2ee2843 100644
71723--- a/include/asm-generic/atomic64.h
71724+++ b/include/asm-generic/atomic64.h
71725@@ -16,6 +16,8 @@ typedef struct {
71726 long long counter;
71727 } atomic64_t;
71728
71729+typedef atomic64_t atomic64_unchecked_t;
71730+
71731 #define ATOMIC64_INIT(i) { (i) }
71732
71733 extern long long atomic64_read(const atomic64_t *v);
71734@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71735 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71736 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71737
71738+#define atomic64_read_unchecked(v) atomic64_read(v)
71739+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71740+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71741+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71742+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71743+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71744+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71745+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71746+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71747+
71748 #endif /* _ASM_GENERIC_ATOMIC64_H */
71749diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71750index 1bfcfe5..e04c5c9 100644
71751--- a/include/asm-generic/cache.h
71752+++ b/include/asm-generic/cache.h
71753@@ -6,7 +6,7 @@
71754 * cache lines need to provide their own cache.h.
71755 */
71756
71757-#define L1_CACHE_SHIFT 5
71758-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71759+#define L1_CACHE_SHIFT 5UL
71760+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71761
71762 #endif /* __ASM_GENERIC_CACHE_H */
71763diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71764index 0d68a1e..b74a761 100644
71765--- a/include/asm-generic/emergency-restart.h
71766+++ b/include/asm-generic/emergency-restart.h
71767@@ -1,7 +1,7 @@
71768 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71769 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71770
71771-static inline void machine_emergency_restart(void)
71772+static inline __noreturn void machine_emergency_restart(void)
71773 {
71774 machine_restart(NULL);
71775 }
71776diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71777index 90f99c7..00ce236 100644
71778--- a/include/asm-generic/kmap_types.h
71779+++ b/include/asm-generic/kmap_types.h
71780@@ -2,9 +2,9 @@
71781 #define _ASM_GENERIC_KMAP_TYPES_H
71782
71783 #ifdef __WITH_KM_FENCE
71784-# define KM_TYPE_NR 41
71785+# define KM_TYPE_NR 42
71786 #else
71787-# define KM_TYPE_NR 20
71788+# define KM_TYPE_NR 21
71789 #endif
71790
71791 #endif
71792diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71793index 9ceb03b..62b0b8f 100644
71794--- a/include/asm-generic/local.h
71795+++ b/include/asm-generic/local.h
71796@@ -23,24 +23,37 @@ typedef struct
71797 atomic_long_t a;
71798 } local_t;
71799
71800+typedef struct {
71801+ atomic_long_unchecked_t a;
71802+} local_unchecked_t;
71803+
71804 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71805
71806 #define local_read(l) atomic_long_read(&(l)->a)
71807+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71808 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71809+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71810 #define local_inc(l) atomic_long_inc(&(l)->a)
71811+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71812 #define local_dec(l) atomic_long_dec(&(l)->a)
71813+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71814 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71815+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71816 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71817+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71818
71819 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71820 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71821 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71822 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71823 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71824+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71825 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71826 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71827+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71828
71829 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71830+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71831 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71832 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71833 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71834diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71835index 725612b..9cc513a 100644
71836--- a/include/asm-generic/pgtable-nopmd.h
71837+++ b/include/asm-generic/pgtable-nopmd.h
71838@@ -1,14 +1,19 @@
71839 #ifndef _PGTABLE_NOPMD_H
71840 #define _PGTABLE_NOPMD_H
71841
71842-#ifndef __ASSEMBLY__
71843-
71844 #include <asm-generic/pgtable-nopud.h>
71845
71846-struct mm_struct;
71847-
71848 #define __PAGETABLE_PMD_FOLDED
71849
71850+#define PMD_SHIFT PUD_SHIFT
71851+#define PTRS_PER_PMD 1
71852+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71853+#define PMD_MASK (~(PMD_SIZE-1))
71854+
71855+#ifndef __ASSEMBLY__
71856+
71857+struct mm_struct;
71858+
71859 /*
71860 * Having the pmd type consist of a pud gets the size right, and allows
71861 * us to conceptually access the pud entry that this pmd is folded into
71862@@ -16,11 +21,6 @@ struct mm_struct;
71863 */
71864 typedef struct { pud_t pud; } pmd_t;
71865
71866-#define PMD_SHIFT PUD_SHIFT
71867-#define PTRS_PER_PMD 1
71868-#define PMD_SIZE (1UL << PMD_SHIFT)
71869-#define PMD_MASK (~(PMD_SIZE-1))
71870-
71871 /*
71872 * The "pud_xxx()" functions here are trivial for a folded two-level
71873 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71874diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71875index 810431d..0ec4804f 100644
71876--- a/include/asm-generic/pgtable-nopud.h
71877+++ b/include/asm-generic/pgtable-nopud.h
71878@@ -1,10 +1,15 @@
71879 #ifndef _PGTABLE_NOPUD_H
71880 #define _PGTABLE_NOPUD_H
71881
71882-#ifndef __ASSEMBLY__
71883-
71884 #define __PAGETABLE_PUD_FOLDED
71885
71886+#define PUD_SHIFT PGDIR_SHIFT
71887+#define PTRS_PER_PUD 1
71888+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71889+#define PUD_MASK (~(PUD_SIZE-1))
71890+
71891+#ifndef __ASSEMBLY__
71892+
71893 /*
71894 * Having the pud type consist of a pgd gets the size right, and allows
71895 * us to conceptually access the pgd entry that this pud is folded into
71896@@ -12,11 +17,6 @@
71897 */
71898 typedef struct { pgd_t pgd; } pud_t;
71899
71900-#define PUD_SHIFT PGDIR_SHIFT
71901-#define PTRS_PER_PUD 1
71902-#define PUD_SIZE (1UL << PUD_SHIFT)
71903-#define PUD_MASK (~(PUD_SIZE-1))
71904-
71905 /*
71906 * The "pgd_xxx()" functions here are trivial for a folded two-level
71907 * setup: the pud is never bad, and a pud always exists (as it's folded
71908@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
71909 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
71910
71911 #define pgd_populate(mm, pgd, pud) do { } while (0)
71912+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
71913 /*
71914 * (puds are folded into pgds so this doesn't get actually called,
71915 * but the define is needed for a generic inline function.)
71916diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
71917index 0807ddf..cd67747 100644
71918--- a/include/asm-generic/pgtable.h
71919+++ b/include/asm-generic/pgtable.h
71920@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
71921 }
71922 #endif /* CONFIG_NUMA_BALANCING */
71923
71924+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
71925+#ifdef CONFIG_PAX_KERNEXEC
71926+#error KERNEXEC requires pax_open_kernel
71927+#else
71928+static inline unsigned long pax_open_kernel(void) { return 0; }
71929+#endif
71930+#endif
71931+
71932+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
71933+#ifdef CONFIG_PAX_KERNEXEC
71934+#error KERNEXEC requires pax_close_kernel
71935+#else
71936+static inline unsigned long pax_close_kernel(void) { return 0; }
71937+#endif
71938+#endif
71939+
71940 #endif /* CONFIG_MMU */
71941
71942 #endif /* !__ASSEMBLY__ */
71943diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
71944index dc1269c..48a4f51 100644
71945--- a/include/asm-generic/uaccess.h
71946+++ b/include/asm-generic/uaccess.h
71947@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
71948 return __clear_user(to, n);
71949 }
71950
71951+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
71952+#ifdef CONFIG_PAX_MEMORY_UDEREF
71953+#error UDEREF requires pax_open_userland
71954+#else
71955+static inline unsigned long pax_open_userland(void) { return 0; }
71956+#endif
71957+#endif
71958+
71959+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
71960+#ifdef CONFIG_PAX_MEMORY_UDEREF
71961+#error UDEREF requires pax_close_userland
71962+#else
71963+static inline unsigned long pax_close_userland(void) { return 0; }
71964+#endif
71965+#endif
71966+
71967 #endif /* __ASM_GENERIC_UACCESS_H */
71968diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
71969index 69732d2..cbe16d9 100644
71970--- a/include/asm-generic/vmlinux.lds.h
71971+++ b/include/asm-generic/vmlinux.lds.h
71972@@ -227,6 +227,7 @@
71973 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
71974 VMLINUX_SYMBOL(__start_rodata) = .; \
71975 *(.rodata) *(.rodata.*) \
71976+ *(.data..read_only) \
71977 *(__vermagic) /* Kernel version magic */ \
71978 . = ALIGN(8); \
71979 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
71980@@ -710,17 +711,18 @@
71981 * section in the linker script will go there too. @phdr should have
71982 * a leading colon.
71983 *
71984- * Note that this macros defines __per_cpu_load as an absolute symbol.
71985+ * Note that this macros defines per_cpu_load as an absolute symbol.
71986 * If there is no need to put the percpu section at a predetermined
71987 * address, use PERCPU_SECTION.
71988 */
71989 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
71990- VMLINUX_SYMBOL(__per_cpu_load) = .; \
71991- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
71992+ per_cpu_load = .; \
71993+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
71994 - LOAD_OFFSET) { \
71995+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
71996 PERCPU_INPUT(cacheline) \
71997 } phdr \
71998- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
71999+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72000
72001 /**
72002 * PERCPU_SECTION - define output section for percpu area, simple version
72003diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72004index 418d270..bfd2794 100644
72005--- a/include/crypto/algapi.h
72006+++ b/include/crypto/algapi.h
72007@@ -34,7 +34,7 @@ struct crypto_type {
72008 unsigned int maskclear;
72009 unsigned int maskset;
72010 unsigned int tfmsize;
72011-};
72012+} __do_const;
72013
72014 struct crypto_instance {
72015 struct crypto_alg alg;
72016diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72017index 12083dc..39740ec 100644
72018--- a/include/drm/drmP.h
72019+++ b/include/drm/drmP.h
72020@@ -69,6 +69,7 @@
72021 #include <linux/workqueue.h>
72022 #include <linux/poll.h>
72023 #include <asm/pgalloc.h>
72024+#include <asm/local.h>
72025 #include <drm/drm.h>
72026 #include <drm/drm_sarea.h>
72027
72028@@ -293,10 +294,12 @@ do { \
72029 * \param cmd command.
72030 * \param arg argument.
72031 */
72032-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72033+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72034+ struct drm_file *file_priv);
72035+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72036 struct drm_file *file_priv);
72037
72038-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72039+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72040 unsigned long arg);
72041
72042 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72043@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72044 struct drm_ioctl_desc {
72045 unsigned int cmd;
72046 int flags;
72047- drm_ioctl_t *func;
72048+ drm_ioctl_t func;
72049 unsigned int cmd_drv;
72050 const char *name;
72051-};
72052+} __do_const;
72053
72054 /**
72055 * Creates a driver or general drm_ioctl_desc array entry for the given
72056@@ -1015,7 +1018,7 @@ struct drm_info_list {
72057 int (*show)(struct seq_file*, void*); /** show callback */
72058 u32 driver_features; /**< Required driver features for this entry */
72059 void *data;
72060-};
72061+} __do_const;
72062
72063 /**
72064 * debugfs node structure. This structure represents a debugfs file.
72065@@ -1088,7 +1091,7 @@ struct drm_device {
72066
72067 /** \name Usage Counters */
72068 /*@{ */
72069- int open_count; /**< Outstanding files open */
72070+ local_t open_count; /**< Outstanding files open */
72071 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72072 atomic_t vma_count; /**< Outstanding vma areas open */
72073 int buf_use; /**< Buffers in use -- cannot alloc */
72074@@ -1099,7 +1102,7 @@ struct drm_device {
72075 /*@{ */
72076 unsigned long counters;
72077 enum drm_stat_type types[15];
72078- atomic_t counts[15];
72079+ atomic_unchecked_t counts[15];
72080 /*@} */
72081
72082 struct list_head filelist;
72083diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72084index f43d556..94d9343 100644
72085--- a/include/drm/drm_crtc_helper.h
72086+++ b/include/drm/drm_crtc_helper.h
72087@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72088 struct drm_connector *connector);
72089 /* disable encoder when not in use - more explicit than dpms off */
72090 void (*disable)(struct drm_encoder *encoder);
72091-};
72092+} __no_const;
72093
72094 /**
72095 * drm_connector_helper_funcs - helper operations for connectors
72096diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72097index 72dcbe8..8db58d7 100644
72098--- a/include/drm/ttm/ttm_memory.h
72099+++ b/include/drm/ttm/ttm_memory.h
72100@@ -48,7 +48,7 @@
72101
72102 struct ttm_mem_shrink {
72103 int (*do_shrink) (struct ttm_mem_shrink *);
72104-};
72105+} __no_const;
72106
72107 /**
72108 * struct ttm_mem_global - Global memory accounting structure.
72109diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72110index 4b840e8..155d235 100644
72111--- a/include/keys/asymmetric-subtype.h
72112+++ b/include/keys/asymmetric-subtype.h
72113@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72114 /* Verify the signature on a key of this subtype (optional) */
72115 int (*verify_signature)(const struct key *key,
72116 const struct public_key_signature *sig);
72117-};
72118+} __do_const;
72119
72120 /**
72121 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72122diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72123index c1da539..1dcec55 100644
72124--- a/include/linux/atmdev.h
72125+++ b/include/linux/atmdev.h
72126@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72127 #endif
72128
72129 struct k_atm_aal_stats {
72130-#define __HANDLE_ITEM(i) atomic_t i
72131+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72132 __AAL_STAT_ITEMS
72133 #undef __HANDLE_ITEM
72134 };
72135@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72136 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72137 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72138 struct module *owner;
72139-};
72140+} __do_const ;
72141
72142 struct atmphy_ops {
72143 int (*start)(struct atm_dev *dev);
72144diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72145index 70cf138..0418ee2 100644
72146--- a/include/linux/binfmts.h
72147+++ b/include/linux/binfmts.h
72148@@ -73,8 +73,10 @@ struct linux_binfmt {
72149 int (*load_binary)(struct linux_binprm *);
72150 int (*load_shlib)(struct file *);
72151 int (*core_dump)(struct coredump_params *cprm);
72152+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72153+ void (*handle_mmap)(struct file *);
72154 unsigned long min_coredump; /* minimal dump size */
72155-};
72156+} __do_const;
72157
72158 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72159
72160diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72161index 2fdb4a4..54aad7e 100644
72162--- a/include/linux/blkdev.h
72163+++ b/include/linux/blkdev.h
72164@@ -1526,7 +1526,7 @@ struct block_device_operations {
72165 /* this callback is with swap_lock and sometimes page table lock held */
72166 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72167 struct module *owner;
72168-};
72169+} __do_const;
72170
72171 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72172 unsigned long);
72173diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72174index 7c2e030..b72475d 100644
72175--- a/include/linux/blktrace_api.h
72176+++ b/include/linux/blktrace_api.h
72177@@ -23,7 +23,7 @@ struct blk_trace {
72178 struct dentry *dir;
72179 struct dentry *dropped_file;
72180 struct dentry *msg_file;
72181- atomic_t dropped;
72182+ atomic_unchecked_t dropped;
72183 };
72184
72185 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72186diff --git a/include/linux/cache.h b/include/linux/cache.h
72187index 4c57065..40346da 100644
72188--- a/include/linux/cache.h
72189+++ b/include/linux/cache.h
72190@@ -16,6 +16,14 @@
72191 #define __read_mostly
72192 #endif
72193
72194+#ifndef __read_only
72195+#ifdef CONFIG_PAX_KERNEXEC
72196+#error KERNEXEC requires __read_only
72197+#else
72198+#define __read_only __read_mostly
72199+#endif
72200+#endif
72201+
72202 #ifndef ____cacheline_aligned
72203 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72204 #endif
72205diff --git a/include/linux/capability.h b/include/linux/capability.h
72206index d9a4f7f4..19f77d6 100644
72207--- a/include/linux/capability.h
72208+++ b/include/linux/capability.h
72209@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72210 extern bool nsown_capable(int cap);
72211 extern bool inode_capable(const struct inode *inode, int cap);
72212 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72213+extern bool capable_nolog(int cap);
72214+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72215+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72216
72217 /* audit system wants to get cap info from files as well */
72218 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72219
72220+extern int is_privileged_binary(const struct dentry *dentry);
72221+
72222 #endif /* !_LINUX_CAPABILITY_H */
72223diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72224index 8609d57..86e4d79 100644
72225--- a/include/linux/cdrom.h
72226+++ b/include/linux/cdrom.h
72227@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72228
72229 /* driver specifications */
72230 const int capability; /* capability flags */
72231- int n_minors; /* number of active minor devices */
72232 /* handle uniform packets for scsi type devices (scsi,atapi) */
72233 int (*generic_packet) (struct cdrom_device_info *,
72234 struct packet_command *);
72235diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72236index 4ce9056..86caac6 100644
72237--- a/include/linux/cleancache.h
72238+++ b/include/linux/cleancache.h
72239@@ -31,7 +31,7 @@ struct cleancache_ops {
72240 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72241 void (*invalidate_inode)(int, struct cleancache_filekey);
72242 void (*invalidate_fs)(int);
72243-};
72244+} __no_const;
72245
72246 extern struct cleancache_ops *
72247 cleancache_register_ops(struct cleancache_ops *ops);
72248diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72249index 1ec14a7..d0654a2 100644
72250--- a/include/linux/clk-provider.h
72251+++ b/include/linux/clk-provider.h
72252@@ -132,6 +132,7 @@ struct clk_ops {
72253 unsigned long);
72254 void (*init)(struct clk_hw *hw);
72255 };
72256+typedef struct clk_ops __no_const clk_ops_no_const;
72257
72258 /**
72259 * struct clk_init_data - holds init data that's common to all clocks and is
72260diff --git a/include/linux/compat.h b/include/linux/compat.h
72261index ec1aee4..1077986 100644
72262--- a/include/linux/compat.h
72263+++ b/include/linux/compat.h
72264@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72265 compat_size_t __user *len_ptr);
72266
72267 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72268-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72269+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72270 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72271 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72272 compat_ssize_t msgsz, int msgflg);
72273@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72274 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72275 compat_ulong_t addr, compat_ulong_t data);
72276 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72277- compat_long_t addr, compat_long_t data);
72278+ compat_ulong_t addr, compat_ulong_t data);
72279
72280 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72281 /*
72282diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72283index 842de22..7f3a41f 100644
72284--- a/include/linux/compiler-gcc4.h
72285+++ b/include/linux/compiler-gcc4.h
72286@@ -39,9 +39,29 @@
72287 # define __compiletime_warning(message) __attribute__((warning(message)))
72288 # define __compiletime_error(message) __attribute__((error(message)))
72289 #endif /* __CHECKER__ */
72290+
72291+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72292+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72293+#define __bos0(ptr) __bos((ptr), 0)
72294+#define __bos1(ptr) __bos((ptr), 1)
72295 #endif /* GCC_VERSION >= 40300 */
72296
72297 #if GCC_VERSION >= 40500
72298+
72299+#ifdef CONSTIFY_PLUGIN
72300+#define __no_const __attribute__((no_const))
72301+#define __do_const __attribute__((do_const))
72302+#endif
72303+
72304+#ifdef SIZE_OVERFLOW_PLUGIN
72305+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72306+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72307+#endif
72308+
72309+#ifdef LATENT_ENTROPY_PLUGIN
72310+#define __latent_entropy __attribute__((latent_entropy))
72311+#endif
72312+
72313 /*
72314 * Mark a position in code as unreachable. This can be used to
72315 * suppress control flow warnings after asm blocks that transfer
72316diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72317index 92669cd..1771a15 100644
72318--- a/include/linux/compiler.h
72319+++ b/include/linux/compiler.h
72320@@ -5,11 +5,14 @@
72321
72322 #ifdef __CHECKER__
72323 # define __user __attribute__((noderef, address_space(1)))
72324+# define __force_user __force __user
72325 # define __kernel __attribute__((address_space(0)))
72326+# define __force_kernel __force __kernel
72327 # define __safe __attribute__((safe))
72328 # define __force __attribute__((force))
72329 # define __nocast __attribute__((nocast))
72330 # define __iomem __attribute__((noderef, address_space(2)))
72331+# define __force_iomem __force __iomem
72332 # define __must_hold(x) __attribute__((context(x,1,1)))
72333 # define __acquires(x) __attribute__((context(x,0,1)))
72334 # define __releases(x) __attribute__((context(x,1,0)))
72335@@ -17,20 +20,37 @@
72336 # define __release(x) __context__(x,-1)
72337 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72338 # define __percpu __attribute__((noderef, address_space(3)))
72339+# define __force_percpu __force __percpu
72340 #ifdef CONFIG_SPARSE_RCU_POINTER
72341 # define __rcu __attribute__((noderef, address_space(4)))
72342+# define __force_rcu __force __rcu
72343 #else
72344 # define __rcu
72345+# define __force_rcu
72346 #endif
72347 extern void __chk_user_ptr(const volatile void __user *);
72348 extern void __chk_io_ptr(const volatile void __iomem *);
72349 #else
72350-# define __user
72351-# define __kernel
72352+# ifdef CHECKER_PLUGIN
72353+//# define __user
72354+//# define __force_user
72355+//# define __kernel
72356+//# define __force_kernel
72357+# else
72358+# ifdef STRUCTLEAK_PLUGIN
72359+# define __user __attribute__((user))
72360+# else
72361+# define __user
72362+# endif
72363+# define __force_user
72364+# define __kernel
72365+# define __force_kernel
72366+# endif
72367 # define __safe
72368 # define __force
72369 # define __nocast
72370 # define __iomem
72371+# define __force_iomem
72372 # define __chk_user_ptr(x) (void)0
72373 # define __chk_io_ptr(x) (void)0
72374 # define __builtin_warning(x, y...) (1)
72375@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72376 # define __release(x) (void)0
72377 # define __cond_lock(x,c) (c)
72378 # define __percpu
72379+# define __force_percpu
72380 # define __rcu
72381+# define __force_rcu
72382 #endif
72383
72384 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72385@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72386 # define __attribute_const__ /* unimplemented */
72387 #endif
72388
72389+#ifndef __no_const
72390+# define __no_const
72391+#endif
72392+
72393+#ifndef __do_const
72394+# define __do_const
72395+#endif
72396+
72397+#ifndef __size_overflow
72398+# define __size_overflow(...)
72399+#endif
72400+
72401+#ifndef __intentional_overflow
72402+# define __intentional_overflow(...)
72403+#endif
72404+
72405+#ifndef __latent_entropy
72406+# define __latent_entropy
72407+#endif
72408+
72409 /*
72410 * Tell gcc if a function is cold. The compiler will assume any path
72411 * directly leading to the call is unlikely.
72412@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72413 #define __cold
72414 #endif
72415
72416+#ifndef __alloc_size
72417+#define __alloc_size(...)
72418+#endif
72419+
72420+#ifndef __bos
72421+#define __bos(ptr, arg)
72422+#endif
72423+
72424+#ifndef __bos0
72425+#define __bos0(ptr)
72426+#endif
72427+
72428+#ifndef __bos1
72429+#define __bos1(ptr)
72430+#endif
72431+
72432 /* Simple shorthand for a section definition */
72433 #ifndef __section
72434 # define __section(S) __attribute__ ((__section__(#S)))
72435@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72436 * use is to mediate communication between process-level code and irq/NMI
72437 * handlers, all running on the same CPU.
72438 */
72439-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72440+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72441+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72442
72443 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72444 #ifdef CONFIG_KPROBES
72445diff --git a/include/linux/completion.h b/include/linux/completion.h
72446index 3cd574d..adce5fa 100644
72447--- a/include/linux/completion.h
72448+++ b/include/linux/completion.h
72449@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72450 extern void wait_for_completion(struct completion *);
72451 extern void wait_for_completion_io(struct completion *);
72452 extern int wait_for_completion_interruptible(struct completion *x);
72453-extern int wait_for_completion_killable(struct completion *x);
72454+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72455 extern unsigned long wait_for_completion_timeout(struct completion *x,
72456 unsigned long timeout);
72457 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72458 unsigned long timeout);
72459 extern long wait_for_completion_interruptible_timeout(
72460- struct completion *x, unsigned long timeout);
72461+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72462 extern long wait_for_completion_killable_timeout(
72463- struct completion *x, unsigned long timeout);
72464+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72465 extern bool try_wait_for_completion(struct completion *x);
72466 extern bool completion_done(struct completion *x);
72467
72468diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72469index 34025df..d94bbbc 100644
72470--- a/include/linux/configfs.h
72471+++ b/include/linux/configfs.h
72472@@ -125,7 +125,7 @@ struct configfs_attribute {
72473 const char *ca_name;
72474 struct module *ca_owner;
72475 umode_t ca_mode;
72476-};
72477+} __do_const;
72478
72479 /*
72480 * Users often need to create attribute structures for their configurable
72481diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72482index 90d5a15..950cb80 100644
72483--- a/include/linux/cpufreq.h
72484+++ b/include/linux/cpufreq.h
72485@@ -266,7 +266,7 @@ struct cpufreq_driver {
72486 int (*suspend) (struct cpufreq_policy *policy);
72487 int (*resume) (struct cpufreq_policy *policy);
72488 struct freq_attr **attr;
72489-};
72490+} __do_const;
72491
72492 /* flags */
72493
72494@@ -325,6 +325,7 @@ struct global_attr {
72495 ssize_t (*store)(struct kobject *a, struct attribute *b,
72496 const char *c, size_t count);
72497 };
72498+typedef struct global_attr __no_const global_attr_no_const;
72499
72500 #define define_one_global_ro(_name) \
72501 static struct global_attr _name = \
72502diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72503index 0bc4b74..973b368 100644
72504--- a/include/linux/cpuidle.h
72505+++ b/include/linux/cpuidle.h
72506@@ -52,7 +52,8 @@ struct cpuidle_state {
72507 int index);
72508
72509 int (*enter_dead) (struct cpuidle_device *dev, int index);
72510-};
72511+} __do_const;
72512+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72513
72514 /* Idle State Flags */
72515 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72516@@ -191,7 +192,7 @@ struct cpuidle_governor {
72517 void (*reflect) (struct cpuidle_device *dev, int index);
72518
72519 struct module *owner;
72520-};
72521+} __do_const;
72522
72523 #ifdef CONFIG_CPU_IDLE
72524
72525diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72526index d08e4d2..95fad61 100644
72527--- a/include/linux/cpumask.h
72528+++ b/include/linux/cpumask.h
72529@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72530 }
72531
72532 /* Valid inputs for n are -1 and 0. */
72533-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72534+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72535 {
72536 return n+1;
72537 }
72538
72539-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72540+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72541 {
72542 return n+1;
72543 }
72544
72545-static inline unsigned int cpumask_next_and(int n,
72546+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72547 const struct cpumask *srcp,
72548 const struct cpumask *andp)
72549 {
72550@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72551 *
72552 * Returns >= nr_cpu_ids if no further cpus set.
72553 */
72554-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72555+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72556 {
72557 /* -1 is a legal arg here. */
72558 if (n != -1)
72559@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72560 *
72561 * Returns >= nr_cpu_ids if no further cpus unset.
72562 */
72563-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72564+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72565 {
72566 /* -1 is a legal arg here. */
72567 if (n != -1)
72568@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72569 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72570 }
72571
72572-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72573+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72574 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72575
72576 /**
72577diff --git a/include/linux/cred.h b/include/linux/cred.h
72578index 04421e8..6bce4ef 100644
72579--- a/include/linux/cred.h
72580+++ b/include/linux/cred.h
72581@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72582 static inline void validate_process_creds(void)
72583 {
72584 }
72585+static inline void validate_task_creds(struct task_struct *task)
72586+{
72587+}
72588 #endif
72589
72590 /**
72591diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72592index b92eadf..b4ecdc1 100644
72593--- a/include/linux/crypto.h
72594+++ b/include/linux/crypto.h
72595@@ -373,7 +373,7 @@ struct cipher_tfm {
72596 const u8 *key, unsigned int keylen);
72597 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72598 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72599-};
72600+} __no_const;
72601
72602 struct hash_tfm {
72603 int (*init)(struct hash_desc *desc);
72604@@ -394,13 +394,13 @@ struct compress_tfm {
72605 int (*cot_decompress)(struct crypto_tfm *tfm,
72606 const u8 *src, unsigned int slen,
72607 u8 *dst, unsigned int *dlen);
72608-};
72609+} __no_const;
72610
72611 struct rng_tfm {
72612 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72613 unsigned int dlen);
72614 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72615-};
72616+} __no_const;
72617
72618 #define crt_ablkcipher crt_u.ablkcipher
72619 #define crt_aead crt_u.aead
72620diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72621index 653589e..4ef254a 100644
72622--- a/include/linux/ctype.h
72623+++ b/include/linux/ctype.h
72624@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72625 * Fast implementation of tolower() for internal usage. Do not use in your
72626 * code.
72627 */
72628-static inline char _tolower(const char c)
72629+static inline unsigned char _tolower(const unsigned char c)
72630 {
72631 return c | 0x20;
72632 }
72633diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72634index 7925bf0..d5143d2 100644
72635--- a/include/linux/decompress/mm.h
72636+++ b/include/linux/decompress/mm.h
72637@@ -77,7 +77,7 @@ static void free(void *where)
72638 * warnings when not needed (indeed large_malloc / large_free are not
72639 * needed by inflate */
72640
72641-#define malloc(a) kmalloc(a, GFP_KERNEL)
72642+#define malloc(a) kmalloc((a), GFP_KERNEL)
72643 #define free(a) kfree(a)
72644
72645 #define large_malloc(a) vmalloc(a)
72646diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72647index 5f1ab92..39c35ae 100644
72648--- a/include/linux/devfreq.h
72649+++ b/include/linux/devfreq.h
72650@@ -114,7 +114,7 @@ struct devfreq_governor {
72651 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72652 int (*event_handler)(struct devfreq *devfreq,
72653 unsigned int event, void *data);
72654-};
72655+} __do_const;
72656
72657 /**
72658 * struct devfreq - Device devfreq structure
72659diff --git a/include/linux/device.h b/include/linux/device.h
72660index 22b546a..a573dc9 100644
72661--- a/include/linux/device.h
72662+++ b/include/linux/device.h
72663@@ -305,7 +305,7 @@ struct subsys_interface {
72664 struct list_head node;
72665 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72666 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72667-};
72668+} __do_const;
72669
72670 int subsys_interface_register(struct subsys_interface *sif);
72671 void subsys_interface_unregister(struct subsys_interface *sif);
72672@@ -493,7 +493,7 @@ struct device_type {
72673 void (*release)(struct device *dev);
72674
72675 const struct dev_pm_ops *pm;
72676-};
72677+} __do_const;
72678
72679 /* interface for exporting device attributes */
72680 struct device_attribute {
72681@@ -503,11 +503,12 @@ struct device_attribute {
72682 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72683 const char *buf, size_t count);
72684 };
72685+typedef struct device_attribute __no_const device_attribute_no_const;
72686
72687 struct dev_ext_attribute {
72688 struct device_attribute attr;
72689 void *var;
72690-};
72691+} __do_const;
72692
72693 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72694 char *buf);
72695diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72696index 94af418..b1ca7a2 100644
72697--- a/include/linux/dma-mapping.h
72698+++ b/include/linux/dma-mapping.h
72699@@ -54,7 +54,7 @@ struct dma_map_ops {
72700 u64 (*get_required_mask)(struct device *dev);
72701 #endif
72702 int is_phys;
72703-};
72704+} __do_const;
72705
72706 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72707
72708diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72709index cb286b1..923d066 100644
72710--- a/include/linux/dmaengine.h
72711+++ b/include/linux/dmaengine.h
72712@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72713 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72714 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72715
72716-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72717+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72718 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72719-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72720+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72721 struct dma_pinned_list *pinned_list, struct page *page,
72722 unsigned int offset, size_t len);
72723
72724diff --git a/include/linux/efi.h b/include/linux/efi.h
72725index 5f8f176..62a0556 100644
72726--- a/include/linux/efi.h
72727+++ b/include/linux/efi.h
72728@@ -745,6 +745,7 @@ struct efivar_operations {
72729 efi_set_variable_t *set_variable;
72730 efi_query_variable_store_t *query_variable_store;
72731 };
72732+typedef struct efivar_operations __no_const efivar_operations_no_const;
72733
72734 struct efivars {
72735 /*
72736diff --git a/include/linux/elf.h b/include/linux/elf.h
72737index 40a3c0e..4c45a38 100644
72738--- a/include/linux/elf.h
72739+++ b/include/linux/elf.h
72740@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72741 #define elf_note elf32_note
72742 #define elf_addr_t Elf32_Off
72743 #define Elf_Half Elf32_Half
72744+#define elf_dyn Elf32_Dyn
72745
72746 #else
72747
72748@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72749 #define elf_note elf64_note
72750 #define elf_addr_t Elf64_Off
72751 #define Elf_Half Elf64_Half
72752+#define elf_dyn Elf64_Dyn
72753
72754 #endif
72755
72756diff --git a/include/linux/err.h b/include/linux/err.h
72757index 221fcfb..f29e5e2 100644
72758--- a/include/linux/err.h
72759+++ b/include/linux/err.h
72760@@ -19,12 +19,12 @@
72761
72762 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72763
72764-static inline void * __must_check ERR_PTR(long error)
72765+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72766 {
72767 return (void *) error;
72768 }
72769
72770-static inline long __must_check PTR_ERR(__force const void *ptr)
72771+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72772 {
72773 return (long) ptr;
72774 }
72775diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72776index fcb51c8..bdafcf6 100644
72777--- a/include/linux/extcon.h
72778+++ b/include/linux/extcon.h
72779@@ -134,7 +134,7 @@ struct extcon_dev {
72780 /* /sys/class/extcon/.../mutually_exclusive/... */
72781 struct attribute_group attr_g_muex;
72782 struct attribute **attrs_muex;
72783- struct device_attribute *d_attrs_muex;
72784+ device_attribute_no_const *d_attrs_muex;
72785 };
72786
72787 /**
72788diff --git a/include/linux/fb.h b/include/linux/fb.h
72789index ffac70a..ca3e711 100644
72790--- a/include/linux/fb.h
72791+++ b/include/linux/fb.h
72792@@ -304,7 +304,7 @@ struct fb_ops {
72793 /* called at KDB enter and leave time to prepare the console */
72794 int (*fb_debug_enter)(struct fb_info *info);
72795 int (*fb_debug_leave)(struct fb_info *info);
72796-};
72797+} __do_const;
72798
72799 #ifdef CONFIG_FB_TILEBLITTING
72800 #define FB_TILE_CURSOR_NONE 0
72801diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72802index 085197b..0fa6f0b 100644
72803--- a/include/linux/fdtable.h
72804+++ b/include/linux/fdtable.h
72805@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72806 void put_files_struct(struct files_struct *fs);
72807 void reset_files_struct(struct files_struct *);
72808 int unshare_files(struct files_struct **);
72809-struct files_struct *dup_fd(struct files_struct *, int *);
72810+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72811 void do_close_on_exec(struct files_struct *);
72812 int iterate_fd(struct files_struct *, unsigned,
72813 int (*)(const void *, struct file *, unsigned),
72814diff --git a/include/linux/filter.h b/include/linux/filter.h
72815index a6ac848..a104a76 100644
72816--- a/include/linux/filter.h
72817+++ b/include/linux/filter.h
72818@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72819
72820 struct sk_buff;
72821 struct sock;
72822+struct bpf_jit_work;
72823
72824 struct sk_filter
72825 {
72826@@ -27,6 +28,9 @@ struct sk_filter
72827 unsigned int len; /* Number of filter blocks */
72828 unsigned int (*bpf_func)(const struct sk_buff *skb,
72829 const struct sock_filter *filter);
72830+#ifdef CONFIG_BPF_JIT
72831+ struct bpf_jit_work *work;
72832+#endif
72833 struct rcu_head rcu;
72834 struct sock_filter insns[0];
72835 };
72836diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72837index 8293262..2b3b8bd 100644
72838--- a/include/linux/frontswap.h
72839+++ b/include/linux/frontswap.h
72840@@ -11,7 +11,7 @@ struct frontswap_ops {
72841 int (*load)(unsigned, pgoff_t, struct page *);
72842 void (*invalidate_page)(unsigned, pgoff_t);
72843 void (*invalidate_area)(unsigned);
72844-};
72845+} __no_const;
72846
72847 extern bool frontswap_enabled;
72848 extern struct frontswap_ops *
72849diff --git a/include/linux/fs.h b/include/linux/fs.h
72850index 9818747..788bfbd 100644
72851--- a/include/linux/fs.h
72852+++ b/include/linux/fs.h
72853@@ -1554,7 +1554,8 @@ struct file_operations {
72854 long (*fallocate)(struct file *file, int mode, loff_t offset,
72855 loff_t len);
72856 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72857-};
72858+} __do_const;
72859+typedef struct file_operations __no_const file_operations_no_const;
72860
72861 struct inode_operations {
72862 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72863@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72864 return !IS_DEADDIR(inode);
72865 }
72866
72867+static inline bool is_sidechannel_device(const struct inode *inode)
72868+{
72869+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72870+ umode_t mode = inode->i_mode;
72871+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72872+#else
72873+ return false;
72874+#endif
72875+}
72876+
72877 #endif /* _LINUX_FS_H */
72878diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72879index 2b93a9a..855d94a 100644
72880--- a/include/linux/fs_struct.h
72881+++ b/include/linux/fs_struct.h
72882@@ -6,7 +6,7 @@
72883 #include <linux/seqlock.h>
72884
72885 struct fs_struct {
72886- int users;
72887+ atomic_t users;
72888 spinlock_t lock;
72889 seqcount_t seq;
72890 int umask;
72891diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72892index a9ff9a3..1ba1788 100644
72893--- a/include/linux/fscache-cache.h
72894+++ b/include/linux/fscache-cache.h
72895@@ -113,7 +113,7 @@ struct fscache_operation {
72896 fscache_operation_release_t release;
72897 };
72898
72899-extern atomic_t fscache_op_debug_id;
72900+extern atomic_unchecked_t fscache_op_debug_id;
72901 extern void fscache_op_work_func(struct work_struct *work);
72902
72903 extern void fscache_enqueue_operation(struct fscache_operation *);
72904@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
72905 INIT_WORK(&op->work, fscache_op_work_func);
72906 atomic_set(&op->usage, 1);
72907 op->state = FSCACHE_OP_ST_INITIALISED;
72908- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
72909+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
72910 op->processor = processor;
72911 op->release = release;
72912 INIT_LIST_HEAD(&op->pend_link);
72913diff --git a/include/linux/fscache.h b/include/linux/fscache.h
72914index 7a08623..4c07b0f 100644
72915--- a/include/linux/fscache.h
72916+++ b/include/linux/fscache.h
72917@@ -152,7 +152,7 @@ struct fscache_cookie_def {
72918 * - this is mandatory for any object that may have data
72919 */
72920 void (*now_uncached)(void *cookie_netfs_data);
72921-};
72922+} __do_const;
72923
72924 /*
72925 * fscache cached network filesystem type
72926diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
72927index 1c804b0..1432c2b 100644
72928--- a/include/linux/fsnotify.h
72929+++ b/include/linux/fsnotify.h
72930@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
72931 struct inode *inode = file_inode(file);
72932 __u32 mask = FS_ACCESS;
72933
72934+ if (is_sidechannel_device(inode))
72935+ return;
72936+
72937 if (S_ISDIR(inode->i_mode))
72938 mask |= FS_ISDIR;
72939
72940@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
72941 struct inode *inode = file_inode(file);
72942 __u32 mask = FS_MODIFY;
72943
72944+ if (is_sidechannel_device(inode))
72945+ return;
72946+
72947 if (S_ISDIR(inode->i_mode))
72948 mask |= FS_ISDIR;
72949
72950@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
72951 */
72952 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
72953 {
72954- return kstrdup(name, GFP_KERNEL);
72955+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
72956 }
72957
72958 /*
72959diff --git a/include/linux/genhd.h b/include/linux/genhd.h
72960index 9f3c275..8bdff5d 100644
72961--- a/include/linux/genhd.h
72962+++ b/include/linux/genhd.h
72963@@ -194,7 +194,7 @@ struct gendisk {
72964 struct kobject *slave_dir;
72965
72966 struct timer_rand_state *random;
72967- atomic_t sync_io; /* RAID */
72968+ atomic_unchecked_t sync_io; /* RAID */
72969 struct disk_events *ev;
72970 #ifdef CONFIG_BLK_DEV_INTEGRITY
72971 struct blk_integrity *integrity;
72972@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
72973 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
72974
72975 /* drivers/char/random.c */
72976-extern void add_disk_randomness(struct gendisk *disk);
72977+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
72978 extern void rand_initialize_disk(struct gendisk *disk);
72979
72980 static inline sector_t get_start_sect(struct block_device *bdev)
72981diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
72982index 023bc34..b02b46a 100644
72983--- a/include/linux/genl_magic_func.h
72984+++ b/include/linux/genl_magic_func.h
72985@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
72986 },
72987
72988 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
72989-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
72990+static struct genl_ops ZZZ_genl_ops[] = {
72991 #include GENL_MAGIC_INCLUDE_FILE
72992 };
72993
72994diff --git a/include/linux/gfp.h b/include/linux/gfp.h
72995index 9b4dd49..61fd41d 100644
72996--- a/include/linux/gfp.h
72997+++ b/include/linux/gfp.h
72998@@ -35,6 +35,13 @@ struct vm_area_struct;
72999 #define ___GFP_NO_KSWAPD 0x400000u
73000 #define ___GFP_OTHER_NODE 0x800000u
73001 #define ___GFP_WRITE 0x1000000u
73002+
73003+#ifdef CONFIG_PAX_USERCOPY_SLABS
73004+#define ___GFP_USERCOPY 0x2000000u
73005+#else
73006+#define ___GFP_USERCOPY 0
73007+#endif
73008+
73009 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73010
73011 /*
73012@@ -92,6 +99,7 @@ struct vm_area_struct;
73013 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73014 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73015 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73016+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73017
73018 /*
73019 * This may seem redundant, but it's a way of annotating false positives vs.
73020@@ -99,7 +107,7 @@ struct vm_area_struct;
73021 */
73022 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73023
73024-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73025+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73026 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73027
73028 /* This equals 0, but use constants in case they ever change */
73029@@ -153,6 +161,8 @@ struct vm_area_struct;
73030 /* 4GB DMA on some platforms */
73031 #define GFP_DMA32 __GFP_DMA32
73032
73033+#define GFP_USERCOPY __GFP_USERCOPY
73034+
73035 /* Convert GFP flags to their corresponding migrate type */
73036 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73037 {
73038diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73039new file mode 100644
73040index 0000000..ebe6d72
73041--- /dev/null
73042+++ b/include/linux/gracl.h
73043@@ -0,0 +1,319 @@
73044+#ifndef GR_ACL_H
73045+#define GR_ACL_H
73046+
73047+#include <linux/grdefs.h>
73048+#include <linux/resource.h>
73049+#include <linux/capability.h>
73050+#include <linux/dcache.h>
73051+#include <asm/resource.h>
73052+
73053+/* Major status information */
73054+
73055+#define GR_VERSION "grsecurity 2.9.1"
73056+#define GRSECURITY_VERSION 0x2901
73057+
73058+enum {
73059+ GR_SHUTDOWN = 0,
73060+ GR_ENABLE = 1,
73061+ GR_SPROLE = 2,
73062+ GR_RELOAD = 3,
73063+ GR_SEGVMOD = 4,
73064+ GR_STATUS = 5,
73065+ GR_UNSPROLE = 6,
73066+ GR_PASSSET = 7,
73067+ GR_SPROLEPAM = 8,
73068+};
73069+
73070+/* Password setup definitions
73071+ * kernel/grhash.c */
73072+enum {
73073+ GR_PW_LEN = 128,
73074+ GR_SALT_LEN = 16,
73075+ GR_SHA_LEN = 32,
73076+};
73077+
73078+enum {
73079+ GR_SPROLE_LEN = 64,
73080+};
73081+
73082+enum {
73083+ GR_NO_GLOB = 0,
73084+ GR_REG_GLOB,
73085+ GR_CREATE_GLOB
73086+};
73087+
73088+#define GR_NLIMITS 32
73089+
73090+/* Begin Data Structures */
73091+
73092+struct sprole_pw {
73093+ unsigned char *rolename;
73094+ unsigned char salt[GR_SALT_LEN];
73095+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73096+};
73097+
73098+struct name_entry {
73099+ __u32 key;
73100+ ino_t inode;
73101+ dev_t device;
73102+ char *name;
73103+ __u16 len;
73104+ __u8 deleted;
73105+ struct name_entry *prev;
73106+ struct name_entry *next;
73107+};
73108+
73109+struct inodev_entry {
73110+ struct name_entry *nentry;
73111+ struct inodev_entry *prev;
73112+ struct inodev_entry *next;
73113+};
73114+
73115+struct acl_role_db {
73116+ struct acl_role_label **r_hash;
73117+ __u32 r_size;
73118+};
73119+
73120+struct inodev_db {
73121+ struct inodev_entry **i_hash;
73122+ __u32 i_size;
73123+};
73124+
73125+struct name_db {
73126+ struct name_entry **n_hash;
73127+ __u32 n_size;
73128+};
73129+
73130+struct crash_uid {
73131+ uid_t uid;
73132+ unsigned long expires;
73133+};
73134+
73135+struct gr_hash_struct {
73136+ void **table;
73137+ void **nametable;
73138+ void *first;
73139+ __u32 table_size;
73140+ __u32 used_size;
73141+ int type;
73142+};
73143+
73144+/* Userspace Grsecurity ACL data structures */
73145+
73146+struct acl_subject_label {
73147+ char *filename;
73148+ ino_t inode;
73149+ dev_t device;
73150+ __u32 mode;
73151+ kernel_cap_t cap_mask;
73152+ kernel_cap_t cap_lower;
73153+ kernel_cap_t cap_invert_audit;
73154+
73155+ struct rlimit res[GR_NLIMITS];
73156+ __u32 resmask;
73157+
73158+ __u8 user_trans_type;
73159+ __u8 group_trans_type;
73160+ uid_t *user_transitions;
73161+ gid_t *group_transitions;
73162+ __u16 user_trans_num;
73163+ __u16 group_trans_num;
73164+
73165+ __u32 sock_families[2];
73166+ __u32 ip_proto[8];
73167+ __u32 ip_type;
73168+ struct acl_ip_label **ips;
73169+ __u32 ip_num;
73170+ __u32 inaddr_any_override;
73171+
73172+ __u32 crashes;
73173+ unsigned long expires;
73174+
73175+ struct acl_subject_label *parent_subject;
73176+ struct gr_hash_struct *hash;
73177+ struct acl_subject_label *prev;
73178+ struct acl_subject_label *next;
73179+
73180+ struct acl_object_label **obj_hash;
73181+ __u32 obj_hash_size;
73182+ __u16 pax_flags;
73183+};
73184+
73185+struct role_allowed_ip {
73186+ __u32 addr;
73187+ __u32 netmask;
73188+
73189+ struct role_allowed_ip *prev;
73190+ struct role_allowed_ip *next;
73191+};
73192+
73193+struct role_transition {
73194+ char *rolename;
73195+
73196+ struct role_transition *prev;
73197+ struct role_transition *next;
73198+};
73199+
73200+struct acl_role_label {
73201+ char *rolename;
73202+ uid_t uidgid;
73203+ __u16 roletype;
73204+
73205+ __u16 auth_attempts;
73206+ unsigned long expires;
73207+
73208+ struct acl_subject_label *root_label;
73209+ struct gr_hash_struct *hash;
73210+
73211+ struct acl_role_label *prev;
73212+ struct acl_role_label *next;
73213+
73214+ struct role_transition *transitions;
73215+ struct role_allowed_ip *allowed_ips;
73216+ uid_t *domain_children;
73217+ __u16 domain_child_num;
73218+
73219+ umode_t umask;
73220+
73221+ struct acl_subject_label **subj_hash;
73222+ __u32 subj_hash_size;
73223+};
73224+
73225+struct user_acl_role_db {
73226+ struct acl_role_label **r_table;
73227+ __u32 num_pointers; /* Number of allocations to track */
73228+ __u32 num_roles; /* Number of roles */
73229+ __u32 num_domain_children; /* Number of domain children */
73230+ __u32 num_subjects; /* Number of subjects */
73231+ __u32 num_objects; /* Number of objects */
73232+};
73233+
73234+struct acl_object_label {
73235+ char *filename;
73236+ ino_t inode;
73237+ dev_t device;
73238+ __u32 mode;
73239+
73240+ struct acl_subject_label *nested;
73241+ struct acl_object_label *globbed;
73242+
73243+ /* next two structures not used */
73244+
73245+ struct acl_object_label *prev;
73246+ struct acl_object_label *next;
73247+};
73248+
73249+struct acl_ip_label {
73250+ char *iface;
73251+ __u32 addr;
73252+ __u32 netmask;
73253+ __u16 low, high;
73254+ __u8 mode;
73255+ __u32 type;
73256+ __u32 proto[8];
73257+
73258+ /* next two structures not used */
73259+
73260+ struct acl_ip_label *prev;
73261+ struct acl_ip_label *next;
73262+};
73263+
73264+struct gr_arg {
73265+ struct user_acl_role_db role_db;
73266+ unsigned char pw[GR_PW_LEN];
73267+ unsigned char salt[GR_SALT_LEN];
73268+ unsigned char sum[GR_SHA_LEN];
73269+ unsigned char sp_role[GR_SPROLE_LEN];
73270+ struct sprole_pw *sprole_pws;
73271+ dev_t segv_device;
73272+ ino_t segv_inode;
73273+ uid_t segv_uid;
73274+ __u16 num_sprole_pws;
73275+ __u16 mode;
73276+};
73277+
73278+struct gr_arg_wrapper {
73279+ struct gr_arg *arg;
73280+ __u32 version;
73281+ __u32 size;
73282+};
73283+
73284+struct subject_map {
73285+ struct acl_subject_label *user;
73286+ struct acl_subject_label *kernel;
73287+ struct subject_map *prev;
73288+ struct subject_map *next;
73289+};
73290+
73291+struct acl_subj_map_db {
73292+ struct subject_map **s_hash;
73293+ __u32 s_size;
73294+};
73295+
73296+/* End Data Structures Section */
73297+
73298+/* Hash functions generated by empirical testing by Brad Spengler
73299+ Makes good use of the low bits of the inode. Generally 0-1 times
73300+ in loop for successful match. 0-3 for unsuccessful match.
73301+ Shift/add algorithm with modulus of table size and an XOR*/
73302+
73303+static __inline__ unsigned int
73304+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73305+{
73306+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73307+}
73308+
73309+ static __inline__ unsigned int
73310+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73311+{
73312+ return ((const unsigned long)userp % sz);
73313+}
73314+
73315+static __inline__ unsigned int
73316+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73317+{
73318+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73319+}
73320+
73321+static __inline__ unsigned int
73322+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73323+{
73324+ return full_name_hash((const unsigned char *)name, len) % sz;
73325+}
73326+
73327+#define FOR_EACH_ROLE_START(role) \
73328+ role = role_list; \
73329+ while (role) {
73330+
73331+#define FOR_EACH_ROLE_END(role) \
73332+ role = role->prev; \
73333+ }
73334+
73335+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73336+ subj = NULL; \
73337+ iter = 0; \
73338+ while (iter < role->subj_hash_size) { \
73339+ if (subj == NULL) \
73340+ subj = role->subj_hash[iter]; \
73341+ if (subj == NULL) { \
73342+ iter++; \
73343+ continue; \
73344+ }
73345+
73346+#define FOR_EACH_SUBJECT_END(subj,iter) \
73347+ subj = subj->next; \
73348+ if (subj == NULL) \
73349+ iter++; \
73350+ }
73351+
73352+
73353+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73354+ subj = role->hash->first; \
73355+ while (subj != NULL) {
73356+
73357+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73358+ subj = subj->next; \
73359+ }
73360+
73361+#endif
73362+
73363diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73364new file mode 100644
73365index 0000000..33ebd1f
73366--- /dev/null
73367+++ b/include/linux/gracl_compat.h
73368@@ -0,0 +1,156 @@
73369+#ifndef GR_ACL_COMPAT_H
73370+#define GR_ACL_COMPAT_H
73371+
73372+#include <linux/resource.h>
73373+#include <asm/resource.h>
73374+
73375+struct sprole_pw_compat {
73376+ compat_uptr_t rolename;
73377+ unsigned char salt[GR_SALT_LEN];
73378+ unsigned char sum[GR_SHA_LEN];
73379+};
73380+
73381+struct gr_hash_struct_compat {
73382+ compat_uptr_t table;
73383+ compat_uptr_t nametable;
73384+ compat_uptr_t first;
73385+ __u32 table_size;
73386+ __u32 used_size;
73387+ int type;
73388+};
73389+
73390+struct acl_subject_label_compat {
73391+ compat_uptr_t filename;
73392+ compat_ino_t inode;
73393+ __u32 device;
73394+ __u32 mode;
73395+ kernel_cap_t cap_mask;
73396+ kernel_cap_t cap_lower;
73397+ kernel_cap_t cap_invert_audit;
73398+
73399+ struct compat_rlimit res[GR_NLIMITS];
73400+ __u32 resmask;
73401+
73402+ __u8 user_trans_type;
73403+ __u8 group_trans_type;
73404+ compat_uptr_t user_transitions;
73405+ compat_uptr_t group_transitions;
73406+ __u16 user_trans_num;
73407+ __u16 group_trans_num;
73408+
73409+ __u32 sock_families[2];
73410+ __u32 ip_proto[8];
73411+ __u32 ip_type;
73412+ compat_uptr_t ips;
73413+ __u32 ip_num;
73414+ __u32 inaddr_any_override;
73415+
73416+ __u32 crashes;
73417+ compat_ulong_t expires;
73418+
73419+ compat_uptr_t parent_subject;
73420+ compat_uptr_t hash;
73421+ compat_uptr_t prev;
73422+ compat_uptr_t next;
73423+
73424+ compat_uptr_t obj_hash;
73425+ __u32 obj_hash_size;
73426+ __u16 pax_flags;
73427+};
73428+
73429+struct role_allowed_ip_compat {
73430+ __u32 addr;
73431+ __u32 netmask;
73432+
73433+ compat_uptr_t prev;
73434+ compat_uptr_t next;
73435+};
73436+
73437+struct role_transition_compat {
73438+ compat_uptr_t rolename;
73439+
73440+ compat_uptr_t prev;
73441+ compat_uptr_t next;
73442+};
73443+
73444+struct acl_role_label_compat {
73445+ compat_uptr_t rolename;
73446+ uid_t uidgid;
73447+ __u16 roletype;
73448+
73449+ __u16 auth_attempts;
73450+ compat_ulong_t expires;
73451+
73452+ compat_uptr_t root_label;
73453+ compat_uptr_t hash;
73454+
73455+ compat_uptr_t prev;
73456+ compat_uptr_t next;
73457+
73458+ compat_uptr_t transitions;
73459+ compat_uptr_t allowed_ips;
73460+ compat_uptr_t domain_children;
73461+ __u16 domain_child_num;
73462+
73463+ umode_t umask;
73464+
73465+ compat_uptr_t subj_hash;
73466+ __u32 subj_hash_size;
73467+};
73468+
73469+struct user_acl_role_db_compat {
73470+ compat_uptr_t r_table;
73471+ __u32 num_pointers;
73472+ __u32 num_roles;
73473+ __u32 num_domain_children;
73474+ __u32 num_subjects;
73475+ __u32 num_objects;
73476+};
73477+
73478+struct acl_object_label_compat {
73479+ compat_uptr_t filename;
73480+ compat_ino_t inode;
73481+ __u32 device;
73482+ __u32 mode;
73483+
73484+ compat_uptr_t nested;
73485+ compat_uptr_t globbed;
73486+
73487+ compat_uptr_t prev;
73488+ compat_uptr_t next;
73489+};
73490+
73491+struct acl_ip_label_compat {
73492+ compat_uptr_t iface;
73493+ __u32 addr;
73494+ __u32 netmask;
73495+ __u16 low, high;
73496+ __u8 mode;
73497+ __u32 type;
73498+ __u32 proto[8];
73499+
73500+ compat_uptr_t prev;
73501+ compat_uptr_t next;
73502+};
73503+
73504+struct gr_arg_compat {
73505+ struct user_acl_role_db_compat role_db;
73506+ unsigned char pw[GR_PW_LEN];
73507+ unsigned char salt[GR_SALT_LEN];
73508+ unsigned char sum[GR_SHA_LEN];
73509+ unsigned char sp_role[GR_SPROLE_LEN];
73510+ compat_uptr_t sprole_pws;
73511+ __u32 segv_device;
73512+ compat_ino_t segv_inode;
73513+ uid_t segv_uid;
73514+ __u16 num_sprole_pws;
73515+ __u16 mode;
73516+};
73517+
73518+struct gr_arg_wrapper_compat {
73519+ compat_uptr_t arg;
73520+ __u32 version;
73521+ __u32 size;
73522+};
73523+
73524+#endif
73525diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73526new file mode 100644
73527index 0000000..323ecf2
73528--- /dev/null
73529+++ b/include/linux/gralloc.h
73530@@ -0,0 +1,9 @@
73531+#ifndef __GRALLOC_H
73532+#define __GRALLOC_H
73533+
73534+void acl_free_all(void);
73535+int acl_alloc_stack_init(unsigned long size);
73536+void *acl_alloc(unsigned long len);
73537+void *acl_alloc_num(unsigned long num, unsigned long len);
73538+
73539+#endif
73540diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73541new file mode 100644
73542index 0000000..be66033
73543--- /dev/null
73544+++ b/include/linux/grdefs.h
73545@@ -0,0 +1,140 @@
73546+#ifndef GRDEFS_H
73547+#define GRDEFS_H
73548+
73549+/* Begin grsecurity status declarations */
73550+
73551+enum {
73552+ GR_READY = 0x01,
73553+ GR_STATUS_INIT = 0x00 // disabled state
73554+};
73555+
73556+/* Begin ACL declarations */
73557+
73558+/* Role flags */
73559+
73560+enum {
73561+ GR_ROLE_USER = 0x0001,
73562+ GR_ROLE_GROUP = 0x0002,
73563+ GR_ROLE_DEFAULT = 0x0004,
73564+ GR_ROLE_SPECIAL = 0x0008,
73565+ GR_ROLE_AUTH = 0x0010,
73566+ GR_ROLE_NOPW = 0x0020,
73567+ GR_ROLE_GOD = 0x0040,
73568+ GR_ROLE_LEARN = 0x0080,
73569+ GR_ROLE_TPE = 0x0100,
73570+ GR_ROLE_DOMAIN = 0x0200,
73571+ GR_ROLE_PAM = 0x0400,
73572+ GR_ROLE_PERSIST = 0x0800
73573+};
73574+
73575+/* ACL Subject and Object mode flags */
73576+enum {
73577+ GR_DELETED = 0x80000000
73578+};
73579+
73580+/* ACL Object-only mode flags */
73581+enum {
73582+ GR_READ = 0x00000001,
73583+ GR_APPEND = 0x00000002,
73584+ GR_WRITE = 0x00000004,
73585+ GR_EXEC = 0x00000008,
73586+ GR_FIND = 0x00000010,
73587+ GR_INHERIT = 0x00000020,
73588+ GR_SETID = 0x00000040,
73589+ GR_CREATE = 0x00000080,
73590+ GR_DELETE = 0x00000100,
73591+ GR_LINK = 0x00000200,
73592+ GR_AUDIT_READ = 0x00000400,
73593+ GR_AUDIT_APPEND = 0x00000800,
73594+ GR_AUDIT_WRITE = 0x00001000,
73595+ GR_AUDIT_EXEC = 0x00002000,
73596+ GR_AUDIT_FIND = 0x00004000,
73597+ GR_AUDIT_INHERIT= 0x00008000,
73598+ GR_AUDIT_SETID = 0x00010000,
73599+ GR_AUDIT_CREATE = 0x00020000,
73600+ GR_AUDIT_DELETE = 0x00040000,
73601+ GR_AUDIT_LINK = 0x00080000,
73602+ GR_PTRACERD = 0x00100000,
73603+ GR_NOPTRACE = 0x00200000,
73604+ GR_SUPPRESS = 0x00400000,
73605+ GR_NOLEARN = 0x00800000,
73606+ GR_INIT_TRANSFER= 0x01000000
73607+};
73608+
73609+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73610+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73611+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73612+
73613+/* ACL subject-only mode flags */
73614+enum {
73615+ GR_KILL = 0x00000001,
73616+ GR_VIEW = 0x00000002,
73617+ GR_PROTECTED = 0x00000004,
73618+ GR_LEARN = 0x00000008,
73619+ GR_OVERRIDE = 0x00000010,
73620+ /* just a placeholder, this mode is only used in userspace */
73621+ GR_DUMMY = 0x00000020,
73622+ GR_PROTSHM = 0x00000040,
73623+ GR_KILLPROC = 0x00000080,
73624+ GR_KILLIPPROC = 0x00000100,
73625+ /* just a placeholder, this mode is only used in userspace */
73626+ GR_NOTROJAN = 0x00000200,
73627+ GR_PROTPROCFD = 0x00000400,
73628+ GR_PROCACCT = 0x00000800,
73629+ GR_RELAXPTRACE = 0x00001000,
73630+ //GR_NESTED = 0x00002000,
73631+ GR_INHERITLEARN = 0x00004000,
73632+ GR_PROCFIND = 0x00008000,
73633+ GR_POVERRIDE = 0x00010000,
73634+ GR_KERNELAUTH = 0x00020000,
73635+ GR_ATSECURE = 0x00040000,
73636+ GR_SHMEXEC = 0x00080000
73637+};
73638+
73639+enum {
73640+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73641+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73642+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73643+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73644+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73645+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73646+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73647+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73648+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73649+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73650+};
73651+
73652+enum {
73653+ GR_ID_USER = 0x01,
73654+ GR_ID_GROUP = 0x02,
73655+};
73656+
73657+enum {
73658+ GR_ID_ALLOW = 0x01,
73659+ GR_ID_DENY = 0x02,
73660+};
73661+
73662+#define GR_CRASH_RES 31
73663+#define GR_UIDTABLE_MAX 500
73664+
73665+/* begin resource learning section */
73666+enum {
73667+ GR_RLIM_CPU_BUMP = 60,
73668+ GR_RLIM_FSIZE_BUMP = 50000,
73669+ GR_RLIM_DATA_BUMP = 10000,
73670+ GR_RLIM_STACK_BUMP = 1000,
73671+ GR_RLIM_CORE_BUMP = 10000,
73672+ GR_RLIM_RSS_BUMP = 500000,
73673+ GR_RLIM_NPROC_BUMP = 1,
73674+ GR_RLIM_NOFILE_BUMP = 5,
73675+ GR_RLIM_MEMLOCK_BUMP = 50000,
73676+ GR_RLIM_AS_BUMP = 500000,
73677+ GR_RLIM_LOCKS_BUMP = 2,
73678+ GR_RLIM_SIGPENDING_BUMP = 5,
73679+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73680+ GR_RLIM_NICE_BUMP = 1,
73681+ GR_RLIM_RTPRIO_BUMP = 1,
73682+ GR_RLIM_RTTIME_BUMP = 1000000
73683+};
73684+
73685+#endif
73686diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73687new file mode 100644
73688index 0000000..e337683
73689--- /dev/null
73690+++ b/include/linux/grinternal.h
73691@@ -0,0 +1,229 @@
73692+#ifndef __GRINTERNAL_H
73693+#define __GRINTERNAL_H
73694+
73695+#ifdef CONFIG_GRKERNSEC
73696+
73697+#include <linux/fs.h>
73698+#include <linux/mnt_namespace.h>
73699+#include <linux/nsproxy.h>
73700+#include <linux/gracl.h>
73701+#include <linux/grdefs.h>
73702+#include <linux/grmsg.h>
73703+
73704+void gr_add_learn_entry(const char *fmt, ...)
73705+ __attribute__ ((format (printf, 1, 2)));
73706+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73707+ const struct vfsmount *mnt);
73708+__u32 gr_check_create(const struct dentry *new_dentry,
73709+ const struct dentry *parent,
73710+ const struct vfsmount *mnt, const __u32 mode);
73711+int gr_check_protected_task(const struct task_struct *task);
73712+__u32 to_gr_audit(const __u32 reqmode);
73713+int gr_set_acls(const int type);
73714+int gr_apply_subject_to_task(struct task_struct *task);
73715+int gr_acl_is_enabled(void);
73716+char gr_roletype_to_char(void);
73717+
73718+void gr_handle_alertkill(struct task_struct *task);
73719+char *gr_to_filename(const struct dentry *dentry,
73720+ const struct vfsmount *mnt);
73721+char *gr_to_filename1(const struct dentry *dentry,
73722+ const struct vfsmount *mnt);
73723+char *gr_to_filename2(const struct dentry *dentry,
73724+ const struct vfsmount *mnt);
73725+char *gr_to_filename3(const struct dentry *dentry,
73726+ const struct vfsmount *mnt);
73727+
73728+extern int grsec_enable_ptrace_readexec;
73729+extern int grsec_enable_harden_ptrace;
73730+extern int grsec_enable_link;
73731+extern int grsec_enable_fifo;
73732+extern int grsec_enable_execve;
73733+extern int grsec_enable_shm;
73734+extern int grsec_enable_execlog;
73735+extern int grsec_enable_signal;
73736+extern int grsec_enable_audit_ptrace;
73737+extern int grsec_enable_forkfail;
73738+extern int grsec_enable_time;
73739+extern int grsec_enable_rofs;
73740+extern int grsec_deny_new_usb;
73741+extern int grsec_enable_chroot_shmat;
73742+extern int grsec_enable_chroot_mount;
73743+extern int grsec_enable_chroot_double;
73744+extern int grsec_enable_chroot_pivot;
73745+extern int grsec_enable_chroot_chdir;
73746+extern int grsec_enable_chroot_chmod;
73747+extern int grsec_enable_chroot_mknod;
73748+extern int grsec_enable_chroot_fchdir;
73749+extern int grsec_enable_chroot_nice;
73750+extern int grsec_enable_chroot_execlog;
73751+extern int grsec_enable_chroot_caps;
73752+extern int grsec_enable_chroot_sysctl;
73753+extern int grsec_enable_chroot_unix;
73754+extern int grsec_enable_symlinkown;
73755+extern kgid_t grsec_symlinkown_gid;
73756+extern int grsec_enable_tpe;
73757+extern kgid_t grsec_tpe_gid;
73758+extern int grsec_enable_tpe_all;
73759+extern int grsec_enable_tpe_invert;
73760+extern int grsec_enable_socket_all;
73761+extern kgid_t grsec_socket_all_gid;
73762+extern int grsec_enable_socket_client;
73763+extern kgid_t grsec_socket_client_gid;
73764+extern int grsec_enable_socket_server;
73765+extern kgid_t grsec_socket_server_gid;
73766+extern kgid_t grsec_audit_gid;
73767+extern int grsec_enable_group;
73768+extern int grsec_enable_log_rwxmaps;
73769+extern int grsec_enable_mount;
73770+extern int grsec_enable_chdir;
73771+extern int grsec_resource_logging;
73772+extern int grsec_enable_blackhole;
73773+extern int grsec_lastack_retries;
73774+extern int grsec_enable_brute;
73775+extern int grsec_lock;
73776+
73777+extern spinlock_t grsec_alert_lock;
73778+extern unsigned long grsec_alert_wtime;
73779+extern unsigned long grsec_alert_fyet;
73780+
73781+extern spinlock_t grsec_audit_lock;
73782+
73783+extern rwlock_t grsec_exec_file_lock;
73784+
73785+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73786+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73787+ (tsk)->exec_file->f_path.mnt) : "/")
73788+
73789+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73790+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73791+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73792+
73793+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73794+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73795+ (tsk)->exec_file->f_path.mnt) : "/")
73796+
73797+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73798+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73799+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73800+
73801+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73802+
73803+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73804+
73805+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73806+{
73807+ if (file1 && file2) {
73808+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73809+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73810+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73811+ return true;
73812+ }
73813+
73814+ return false;
73815+}
73816+
73817+#define GR_CHROOT_CAPS {{ \
73818+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73819+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73820+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73821+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73822+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73823+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73824+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73825+
73826+#define security_learn(normal_msg,args...) \
73827+({ \
73828+ read_lock(&grsec_exec_file_lock); \
73829+ gr_add_learn_entry(normal_msg "\n", ## args); \
73830+ read_unlock(&grsec_exec_file_lock); \
73831+})
73832+
73833+enum {
73834+ GR_DO_AUDIT,
73835+ GR_DONT_AUDIT,
73836+ /* used for non-audit messages that we shouldn't kill the task on */
73837+ GR_DONT_AUDIT_GOOD
73838+};
73839+
73840+enum {
73841+ GR_TTYSNIFF,
73842+ GR_RBAC,
73843+ GR_RBAC_STR,
73844+ GR_STR_RBAC,
73845+ GR_RBAC_MODE2,
73846+ GR_RBAC_MODE3,
73847+ GR_FILENAME,
73848+ GR_SYSCTL_HIDDEN,
73849+ GR_NOARGS,
73850+ GR_ONE_INT,
73851+ GR_ONE_INT_TWO_STR,
73852+ GR_ONE_STR,
73853+ GR_STR_INT,
73854+ GR_TWO_STR_INT,
73855+ GR_TWO_INT,
73856+ GR_TWO_U64,
73857+ GR_THREE_INT,
73858+ GR_FIVE_INT_TWO_STR,
73859+ GR_TWO_STR,
73860+ GR_THREE_STR,
73861+ GR_FOUR_STR,
73862+ GR_STR_FILENAME,
73863+ GR_FILENAME_STR,
73864+ GR_FILENAME_TWO_INT,
73865+ GR_FILENAME_TWO_INT_STR,
73866+ GR_TEXTREL,
73867+ GR_PTRACE,
73868+ GR_RESOURCE,
73869+ GR_CAP,
73870+ GR_SIG,
73871+ GR_SIG2,
73872+ GR_CRASH1,
73873+ GR_CRASH2,
73874+ GR_PSACCT,
73875+ GR_RWXMAP,
73876+ GR_RWXMAPVMA
73877+};
73878+
73879+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73880+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73881+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73882+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73883+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73884+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73885+#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)
73886+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73887+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73888+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73889+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73890+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73891+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73892+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73893+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73894+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73895+#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)
73896+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
73897+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
73898+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
73899+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
73900+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
73901+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
73902+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
73903+#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)
73904+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
73905+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
73906+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
73907+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
73908+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
73909+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
73910+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
73911+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
73912+#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)
73913+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
73914+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
73915+
73916+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
73917+
73918+#endif
73919+
73920+#endif
73921diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
73922new file mode 100644
73923index 0000000..a4396b5
73924--- /dev/null
73925+++ b/include/linux/grmsg.h
73926@@ -0,0 +1,113 @@
73927+#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"
73928+#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"
73929+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
73930+#define GR_STOPMOD_MSG "denied modification of module state by "
73931+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
73932+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
73933+#define GR_IOPERM_MSG "denied use of ioperm() by "
73934+#define GR_IOPL_MSG "denied use of iopl() by "
73935+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
73936+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
73937+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
73938+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
73939+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
73940+#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"
73941+#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"
73942+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
73943+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
73944+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
73945+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
73946+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
73947+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
73948+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
73949+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
73950+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
73951+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
73952+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
73953+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
73954+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
73955+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
73956+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
73957+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
73958+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
73959+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
73960+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
73961+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
73962+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
73963+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
73964+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
73965+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
73966+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
73967+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
73968+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
73969+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
73970+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
73971+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
73972+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
73973+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
73974+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
73975+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
73976+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
73977+#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"
73978+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
73979+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
73980+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
73981+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
73982+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
73983+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
73984+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
73985+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
73986+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
73987+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
73988+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
73989+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
73990+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
73991+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
73992+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
73993+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
73994+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
73995+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
73996+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
73997+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
73998+#define GR_FAILFORK_MSG "failed fork with errno %s by "
73999+#define GR_NICE_CHROOT_MSG "denied priority change by "
74000+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74001+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74002+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74003+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74004+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74005+#define GR_TIME_MSG "time set by "
74006+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74007+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74008+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74009+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74010+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74011+#define GR_BIND_MSG "denied bind() by "
74012+#define GR_CONNECT_MSG "denied connect() by "
74013+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74014+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74015+#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"
74016+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74017+#define GR_CAP_ACL_MSG "use of %s denied for "
74018+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74019+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74020+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74021+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74022+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74023+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74024+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74025+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74026+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74027+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74028+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74029+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74030+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74031+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74032+#define GR_VM86_MSG "denied use of vm86 by "
74033+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74034+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74035+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74036+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74037+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74038+#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 "
74039+#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 "
74040diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74041new file mode 100644
74042index 0000000..d6f5a21
74043--- /dev/null
74044+++ b/include/linux/grsecurity.h
74045@@ -0,0 +1,244 @@
74046+#ifndef GR_SECURITY_H
74047+#define GR_SECURITY_H
74048+#include <linux/fs.h>
74049+#include <linux/fs_struct.h>
74050+#include <linux/binfmts.h>
74051+#include <linux/gracl.h>
74052+
74053+/* notify of brain-dead configs */
74054+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74055+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74056+#endif
74057+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74058+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74059+#endif
74060+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74061+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74062+#endif
74063+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74064+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74065+#endif
74066+
74067+int gr_handle_new_usb(void);
74068+
74069+void gr_handle_brute_attach(unsigned long mm_flags);
74070+void gr_handle_brute_check(void);
74071+void gr_handle_kernel_exploit(void);
74072+
74073+char gr_roletype_to_char(void);
74074+
74075+int gr_acl_enable_at_secure(void);
74076+
74077+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74078+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74079+
74080+void gr_del_task_from_ip_table(struct task_struct *p);
74081+
74082+int gr_pid_is_chrooted(struct task_struct *p);
74083+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74084+int gr_handle_chroot_nice(void);
74085+int gr_handle_chroot_sysctl(const int op);
74086+int gr_handle_chroot_setpriority(struct task_struct *p,
74087+ const int niceval);
74088+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74089+int gr_handle_chroot_chroot(const struct dentry *dentry,
74090+ const struct vfsmount *mnt);
74091+void gr_handle_chroot_chdir(const struct path *path);
74092+int gr_handle_chroot_chmod(const struct dentry *dentry,
74093+ const struct vfsmount *mnt, const int mode);
74094+int gr_handle_chroot_mknod(const struct dentry *dentry,
74095+ const struct vfsmount *mnt, const int mode);
74096+int gr_handle_chroot_mount(const struct dentry *dentry,
74097+ const struct vfsmount *mnt,
74098+ const char *dev_name);
74099+int gr_handle_chroot_pivot(void);
74100+int gr_handle_chroot_unix(const pid_t pid);
74101+
74102+int gr_handle_rawio(const struct inode *inode);
74103+
74104+void gr_handle_ioperm(void);
74105+void gr_handle_iopl(void);
74106+
74107+umode_t gr_acl_umask(void);
74108+
74109+int gr_tpe_allow(const struct file *file);
74110+
74111+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74112+void gr_clear_chroot_entries(struct task_struct *task);
74113+
74114+void gr_log_forkfail(const int retval);
74115+void gr_log_timechange(void);
74116+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74117+void gr_log_chdir(const struct dentry *dentry,
74118+ const struct vfsmount *mnt);
74119+void gr_log_chroot_exec(const struct dentry *dentry,
74120+ const struct vfsmount *mnt);
74121+void gr_log_remount(const char *devname, const int retval);
74122+void gr_log_unmount(const char *devname, const int retval);
74123+void gr_log_mount(const char *from, const char *to, const int retval);
74124+void gr_log_textrel(struct vm_area_struct *vma);
74125+void gr_log_ptgnustack(struct file *file);
74126+void gr_log_rwxmmap(struct file *file);
74127+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74128+
74129+int gr_handle_follow_link(const struct inode *parent,
74130+ const struct inode *inode,
74131+ const struct dentry *dentry,
74132+ const struct vfsmount *mnt);
74133+int gr_handle_fifo(const struct dentry *dentry,
74134+ const struct vfsmount *mnt,
74135+ const struct dentry *dir, const int flag,
74136+ const int acc_mode);
74137+int gr_handle_hardlink(const struct dentry *dentry,
74138+ const struct vfsmount *mnt,
74139+ struct inode *inode,
74140+ const int mode, const struct filename *to);
74141+
74142+int gr_is_capable(const int cap);
74143+int gr_is_capable_nolog(const int cap);
74144+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74145+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74146+
74147+void gr_copy_label(struct task_struct *tsk);
74148+void gr_handle_crash(struct task_struct *task, const int sig);
74149+int gr_handle_signal(const struct task_struct *p, const int sig);
74150+int gr_check_crash_uid(const kuid_t uid);
74151+int gr_check_protected_task(const struct task_struct *task);
74152+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74153+int gr_acl_handle_mmap(const struct file *file,
74154+ const unsigned long prot);
74155+int gr_acl_handle_mprotect(const struct file *file,
74156+ const unsigned long prot);
74157+int gr_check_hidden_task(const struct task_struct *tsk);
74158+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74159+ const struct vfsmount *mnt);
74160+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74161+ const struct vfsmount *mnt);
74162+__u32 gr_acl_handle_access(const struct dentry *dentry,
74163+ const struct vfsmount *mnt, const int fmode);
74164+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74165+ const struct vfsmount *mnt, umode_t *mode);
74166+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74167+ const struct vfsmount *mnt);
74168+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74169+ const struct vfsmount *mnt);
74170+int gr_handle_ptrace(struct task_struct *task, const long request);
74171+int gr_handle_proc_ptrace(struct task_struct *task);
74172+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74173+ const struct vfsmount *mnt);
74174+int gr_check_crash_exec(const struct file *filp);
74175+int gr_acl_is_enabled(void);
74176+void gr_set_kernel_label(struct task_struct *task);
74177+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74178+ const kgid_t gid);
74179+int gr_set_proc_label(const struct dentry *dentry,
74180+ const struct vfsmount *mnt,
74181+ const int unsafe_flags);
74182+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74183+ const struct vfsmount *mnt);
74184+__u32 gr_acl_handle_open(const struct dentry *dentry,
74185+ const struct vfsmount *mnt, int acc_mode);
74186+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74187+ const struct dentry *p_dentry,
74188+ const struct vfsmount *p_mnt,
74189+ int open_flags, int acc_mode, const int imode);
74190+void gr_handle_create(const struct dentry *dentry,
74191+ const struct vfsmount *mnt);
74192+void gr_handle_proc_create(const struct dentry *dentry,
74193+ const struct inode *inode);
74194+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74195+ const struct dentry *parent_dentry,
74196+ const struct vfsmount *parent_mnt,
74197+ const int mode);
74198+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74199+ const struct dentry *parent_dentry,
74200+ const struct vfsmount *parent_mnt);
74201+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74202+ const struct vfsmount *mnt);
74203+void gr_handle_delete(const ino_t ino, const dev_t dev);
74204+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74205+ const struct vfsmount *mnt);
74206+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74207+ const struct dentry *parent_dentry,
74208+ const struct vfsmount *parent_mnt,
74209+ const struct filename *from);
74210+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74211+ const struct dentry *parent_dentry,
74212+ const struct vfsmount *parent_mnt,
74213+ const struct dentry *old_dentry,
74214+ const struct vfsmount *old_mnt, const struct filename *to);
74215+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74216+int gr_acl_handle_rename(struct dentry *new_dentry,
74217+ struct dentry *parent_dentry,
74218+ const struct vfsmount *parent_mnt,
74219+ struct dentry *old_dentry,
74220+ struct inode *old_parent_inode,
74221+ struct vfsmount *old_mnt, const struct filename *newname);
74222+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74223+ struct dentry *old_dentry,
74224+ struct dentry *new_dentry,
74225+ struct vfsmount *mnt, const __u8 replace);
74226+__u32 gr_check_link(const struct dentry *new_dentry,
74227+ const struct dentry *parent_dentry,
74228+ const struct vfsmount *parent_mnt,
74229+ const struct dentry *old_dentry,
74230+ const struct vfsmount *old_mnt);
74231+int gr_acl_handle_filldir(const struct file *file, const char *name,
74232+ const unsigned int namelen, const ino_t ino);
74233+
74234+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74235+ const struct vfsmount *mnt);
74236+void gr_acl_handle_exit(void);
74237+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74238+int gr_acl_handle_procpidmem(const struct task_struct *task);
74239+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74240+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74241+void gr_audit_ptrace(struct task_struct *task);
74242+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74243+void gr_put_exec_file(struct task_struct *task);
74244+
74245+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74246+
74247+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74248+extern void gr_learn_resource(const struct task_struct *task, const int res,
74249+ const unsigned long wanted, const int gt);
74250+#else
74251+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74252+ const unsigned long wanted, const int gt)
74253+{
74254+}
74255+#endif
74256+
74257+#ifdef CONFIG_GRKERNSEC_RESLOG
74258+extern void gr_log_resource(const struct task_struct *task, const int res,
74259+ const unsigned long wanted, const int gt);
74260+#else
74261+static inline void gr_log_resource(const struct task_struct *task, const int res,
74262+ const unsigned long wanted, const int gt)
74263+{
74264+}
74265+#endif
74266+
74267+#ifdef CONFIG_GRKERNSEC
74268+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74269+void gr_handle_vm86(void);
74270+void gr_handle_mem_readwrite(u64 from, u64 to);
74271+
74272+void gr_log_badprocpid(const char *entry);
74273+
74274+extern int grsec_enable_dmesg;
74275+extern int grsec_disable_privio;
74276+
74277+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74278+extern kgid_t grsec_proc_gid;
74279+#endif
74280+
74281+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74282+extern int grsec_enable_chroot_findtask;
74283+#endif
74284+#ifdef CONFIG_GRKERNSEC_SETXID
74285+extern int grsec_enable_setxid;
74286+#endif
74287+#endif
74288+
74289+#endif
74290diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74291new file mode 100644
74292index 0000000..e7ffaaf
74293--- /dev/null
74294+++ b/include/linux/grsock.h
74295@@ -0,0 +1,19 @@
74296+#ifndef __GRSOCK_H
74297+#define __GRSOCK_H
74298+
74299+extern void gr_attach_curr_ip(const struct sock *sk);
74300+extern int gr_handle_sock_all(const int family, const int type,
74301+ const int protocol);
74302+extern int gr_handle_sock_server(const struct sockaddr *sck);
74303+extern int gr_handle_sock_server_other(const struct sock *sck);
74304+extern int gr_handle_sock_client(const struct sockaddr *sck);
74305+extern int gr_search_connect(struct socket * sock,
74306+ struct sockaddr_in * addr);
74307+extern int gr_search_bind(struct socket * sock,
74308+ struct sockaddr_in * addr);
74309+extern int gr_search_listen(struct socket * sock);
74310+extern int gr_search_accept(struct socket * sock);
74311+extern int gr_search_socket(const int domain, const int type,
74312+ const int protocol);
74313+
74314+#endif
74315diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74316index 7fb31da..08b5114 100644
74317--- a/include/linux/highmem.h
74318+++ b/include/linux/highmem.h
74319@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74320 kunmap_atomic(kaddr);
74321 }
74322
74323+static inline void sanitize_highpage(struct page *page)
74324+{
74325+ void *kaddr;
74326+ unsigned long flags;
74327+
74328+ local_irq_save(flags);
74329+ kaddr = kmap_atomic(page);
74330+ clear_page(kaddr);
74331+ kunmap_atomic(kaddr);
74332+ local_irq_restore(flags);
74333+}
74334+
74335 static inline void zero_user_segments(struct page *page,
74336 unsigned start1, unsigned end1,
74337 unsigned start2, unsigned end2)
74338diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74339index 1c7b89a..7f52502 100644
74340--- a/include/linux/hwmon-sysfs.h
74341+++ b/include/linux/hwmon-sysfs.h
74342@@ -25,7 +25,8 @@
74343 struct sensor_device_attribute{
74344 struct device_attribute dev_attr;
74345 int index;
74346-};
74347+} __do_const;
74348+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74349 #define to_sensor_dev_attr(_dev_attr) \
74350 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74351
74352@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74353 struct device_attribute dev_attr;
74354 u8 index;
74355 u8 nr;
74356-};
74357+} __do_const;
74358 #define to_sensor_dev_attr_2(_dev_attr) \
74359 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74360
74361diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74362index e988fa9..ff9f17e 100644
74363--- a/include/linux/i2c.h
74364+++ b/include/linux/i2c.h
74365@@ -366,6 +366,7 @@ struct i2c_algorithm {
74366 /* To determine what the adapter supports */
74367 u32 (*functionality) (struct i2c_adapter *);
74368 };
74369+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74370
74371 /**
74372 * struct i2c_bus_recovery_info - I2C bus recovery information
74373diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74374index d23c3c2..eb63c81 100644
74375--- a/include/linux/i2o.h
74376+++ b/include/linux/i2o.h
74377@@ -565,7 +565,7 @@ struct i2o_controller {
74378 struct i2o_device *exec; /* Executive */
74379 #if BITS_PER_LONG == 64
74380 spinlock_t context_list_lock; /* lock for context_list */
74381- atomic_t context_list_counter; /* needed for unique contexts */
74382+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74383 struct list_head context_list; /* list of context id's
74384 and pointers */
74385 #endif
74386diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74387index aff7ad8..3942bbd 100644
74388--- a/include/linux/if_pppox.h
74389+++ b/include/linux/if_pppox.h
74390@@ -76,7 +76,7 @@ struct pppox_proto {
74391 int (*ioctl)(struct socket *sock, unsigned int cmd,
74392 unsigned long arg);
74393 struct module *owner;
74394-};
74395+} __do_const;
74396
74397 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74398 extern void unregister_pppox_proto(int proto_num);
74399diff --git a/include/linux/init.h b/include/linux/init.h
74400index e73f2b7..cc996e0 100644
74401--- a/include/linux/init.h
74402+++ b/include/linux/init.h
74403@@ -39,9 +39,17 @@
74404 * Also note, that this data cannot be "const".
74405 */
74406
74407+#define add_init_latent_entropy __latent_entropy
74408+
74409+#ifdef CONFIG_MEMORY_HOTPLUG
74410+#define add_meminit_latent_entropy
74411+#else
74412+#define add_meminit_latent_entropy __latent_entropy
74413+#endif
74414+
74415 /* These are for everybody (although not all archs will actually
74416 discard it in modules) */
74417-#define __init __section(.init.text) __cold notrace
74418+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74419 #define __initdata __section(.init.data)
74420 #define __initconst __constsection(.init.rodata)
74421 #define __exitdata __section(.exit.data)
74422@@ -102,7 +110,7 @@
74423 #define __cpuexitconst
74424
74425 /* Used for MEMORY_HOTPLUG */
74426-#define __meminit __section(.meminit.text) __cold notrace
74427+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74428 #define __meminitdata __section(.meminit.data)
74429 #define __meminitconst __constsection(.meminit.rodata)
74430 #define __memexit __section(.memexit.text) __exitused __cold notrace
74431diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74432index 5cd0f09..c9f67cc 100644
74433--- a/include/linux/init_task.h
74434+++ b/include/linux/init_task.h
74435@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74436
74437 #define INIT_TASK_COMM "swapper"
74438
74439+#ifdef CONFIG_X86
74440+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74441+#else
74442+#define INIT_TASK_THREAD_INFO
74443+#endif
74444+
74445 /*
74446 * INIT_TASK is used to set up the first task table, touch at
74447 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74448@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74449 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74450 .comm = INIT_TASK_COMM, \
74451 .thread = INIT_THREAD, \
74452+ INIT_TASK_THREAD_INFO \
74453 .fs = &init_fs, \
74454 .files = &init_files, \
74455 .signal = &init_signals, \
74456diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74457index 5fa5afe..ac55b25 100644
74458--- a/include/linux/interrupt.h
74459+++ b/include/linux/interrupt.h
74460@@ -430,7 +430,7 @@ enum
74461 /* map softirq index to softirq name. update 'softirq_to_name' in
74462 * kernel/softirq.c when adding a new softirq.
74463 */
74464-extern char *softirq_to_name[NR_SOFTIRQS];
74465+extern const char * const softirq_to_name[NR_SOFTIRQS];
74466
74467 /* softirq mask and active fields moved to irq_cpustat_t in
74468 * asm/hardirq.h to get better cache usage. KAO
74469@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74470
74471 struct softirq_action
74472 {
74473- void (*action)(struct softirq_action *);
74474-};
74475+ void (*action)(void);
74476+} __no_const;
74477
74478 asmlinkage void do_softirq(void);
74479 asmlinkage void __do_softirq(void);
74480-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74481+extern void open_softirq(int nr, void (*action)(void));
74482 extern void softirq_init(void);
74483 extern void __raise_softirq_irqoff(unsigned int nr);
74484
74485diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74486index 3aeb730..2177f39 100644
74487--- a/include/linux/iommu.h
74488+++ b/include/linux/iommu.h
74489@@ -113,7 +113,7 @@ struct iommu_ops {
74490 u32 (*domain_get_windows)(struct iommu_domain *domain);
74491
74492 unsigned long pgsize_bitmap;
74493-};
74494+} __do_const;
74495
74496 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74497 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74498diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74499index 89b7c24..382af74 100644
74500--- a/include/linux/ioport.h
74501+++ b/include/linux/ioport.h
74502@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74503 int adjust_resource(struct resource *res, resource_size_t start,
74504 resource_size_t size);
74505 resource_size_t resource_alignment(struct resource *res);
74506-static inline resource_size_t resource_size(const struct resource *res)
74507+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74508 {
74509 return res->end - res->start + 1;
74510 }
74511diff --git a/include/linux/irq.h b/include/linux/irq.h
74512index f04d3ba..bcf2cfb 100644
74513--- a/include/linux/irq.h
74514+++ b/include/linux/irq.h
74515@@ -333,7 +333,8 @@ struct irq_chip {
74516 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74517
74518 unsigned long flags;
74519-};
74520+} __do_const;
74521+typedef struct irq_chip __no_const irq_chip_no_const;
74522
74523 /*
74524 * irq_chip specific flags
74525diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74526index 3e203eb..3fe68d0 100644
74527--- a/include/linux/irqchip/arm-gic.h
74528+++ b/include/linux/irqchip/arm-gic.h
74529@@ -59,9 +59,11 @@
74530
74531 #ifndef __ASSEMBLY__
74532
74533+#include <linux/irq.h>
74534+
74535 struct device_node;
74536
74537-extern struct irq_chip gic_arch_extn;
74538+extern irq_chip_no_const gic_arch_extn;
74539
74540 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74541 u32 offset, struct device_node *);
74542diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74543index 6883e19..e854fcb 100644
74544--- a/include/linux/kallsyms.h
74545+++ b/include/linux/kallsyms.h
74546@@ -15,7 +15,8 @@
74547
74548 struct module;
74549
74550-#ifdef CONFIG_KALLSYMS
74551+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74552+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74553 /* Lookup the address for a symbol. Returns 0 if not found. */
74554 unsigned long kallsyms_lookup_name(const char *name);
74555
74556@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74557 /* Stupid that this does nothing, but I didn't create this mess. */
74558 #define __print_symbol(fmt, addr)
74559 #endif /*CONFIG_KALLSYMS*/
74560+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74561+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74562+extern unsigned long kallsyms_lookup_name(const char *name);
74563+extern void __print_symbol(const char *fmt, unsigned long address);
74564+extern int sprint_backtrace(char *buffer, unsigned long address);
74565+extern int sprint_symbol(char *buffer, unsigned long address);
74566+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74567+const char *kallsyms_lookup(unsigned long addr,
74568+ unsigned long *symbolsize,
74569+ unsigned long *offset,
74570+ char **modname, char *namebuf);
74571+extern int kallsyms_lookup_size_offset(unsigned long addr,
74572+ unsigned long *symbolsize,
74573+ unsigned long *offset);
74574+#endif
74575
74576 /* This macro allows us to keep printk typechecking */
74577 static __printf(1, 2)
74578diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74579index 518a53a..5e28358 100644
74580--- a/include/linux/key-type.h
74581+++ b/include/linux/key-type.h
74582@@ -125,7 +125,7 @@ struct key_type {
74583 /* internal fields */
74584 struct list_head link; /* link in types list */
74585 struct lock_class_key lock_class; /* key->sem lock class */
74586-};
74587+} __do_const;
74588
74589 extern struct key_type key_type_keyring;
74590
74591diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74592index c6e091b..a940adf 100644
74593--- a/include/linux/kgdb.h
74594+++ b/include/linux/kgdb.h
74595@@ -52,7 +52,7 @@ extern int kgdb_connected;
74596 extern int kgdb_io_module_registered;
74597
74598 extern atomic_t kgdb_setting_breakpoint;
74599-extern atomic_t kgdb_cpu_doing_single_step;
74600+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74601
74602 extern struct task_struct *kgdb_usethread;
74603 extern struct task_struct *kgdb_contthread;
74604@@ -254,7 +254,7 @@ struct kgdb_arch {
74605 void (*correct_hw_break)(void);
74606
74607 void (*enable_nmi)(bool on);
74608-};
74609+} __do_const;
74610
74611 /**
74612 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74613@@ -279,7 +279,7 @@ struct kgdb_io {
74614 void (*pre_exception) (void);
74615 void (*post_exception) (void);
74616 int is_console;
74617-};
74618+} __do_const;
74619
74620 extern struct kgdb_arch arch_kgdb_ops;
74621
74622diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74623index 0555cc6..b16a7a4 100644
74624--- a/include/linux/kmod.h
74625+++ b/include/linux/kmod.h
74626@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74627 * usually useless though. */
74628 extern __printf(2, 3)
74629 int __request_module(bool wait, const char *name, ...);
74630+extern __printf(3, 4)
74631+int ___request_module(bool wait, char *param_name, const char *name, ...);
74632 #define request_module(mod...) __request_module(true, mod)
74633 #define request_module_nowait(mod...) __request_module(false, mod)
74634 #define try_then_request_module(x, mod...) \
74635diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74636index 939b112..ed6ed51 100644
74637--- a/include/linux/kobject.h
74638+++ b/include/linux/kobject.h
74639@@ -111,7 +111,7 @@ struct kobj_type {
74640 struct attribute **default_attrs;
74641 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74642 const void *(*namespace)(struct kobject *kobj);
74643-};
74644+} __do_const;
74645
74646 struct kobj_uevent_env {
74647 char *envp[UEVENT_NUM_ENVP];
74648@@ -134,6 +134,7 @@ struct kobj_attribute {
74649 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74650 const char *buf, size_t count);
74651 };
74652+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74653
74654 extern const struct sysfs_ops kobj_sysfs_ops;
74655
74656diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74657index f66b065..c2c29b4 100644
74658--- a/include/linux/kobject_ns.h
74659+++ b/include/linux/kobject_ns.h
74660@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74661 const void *(*netlink_ns)(struct sock *sk);
74662 const void *(*initial_ns)(void);
74663 void (*drop_ns)(void *);
74664-};
74665+} __do_const;
74666
74667 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74668 int kobj_ns_type_registered(enum kobj_ns_type type);
74669diff --git a/include/linux/kref.h b/include/linux/kref.h
74670index 484604d..0f6c5b6 100644
74671--- a/include/linux/kref.h
74672+++ b/include/linux/kref.h
74673@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74674 static inline int kref_sub(struct kref *kref, unsigned int count,
74675 void (*release)(struct kref *kref))
74676 {
74677- WARN_ON(release == NULL);
74678+ BUG_ON(release == NULL);
74679
74680 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74681 release(kref);
74682diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74683index a63d83e..77fd685 100644
74684--- a/include/linux/kvm_host.h
74685+++ b/include/linux/kvm_host.h
74686@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74687 {
74688 }
74689 #endif
74690-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74691+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74692 struct module *module);
74693 void kvm_exit(void);
74694
74695@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74696 struct kvm_guest_debug *dbg);
74697 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74698
74699-int kvm_arch_init(void *opaque);
74700+int kvm_arch_init(const void *opaque);
74701 void kvm_arch_exit(void);
74702
74703 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74704diff --git a/include/linux/libata.h b/include/linux/libata.h
74705index 4ea55bb..dcd2601 100644
74706--- a/include/linux/libata.h
74707+++ b/include/linux/libata.h
74708@@ -924,7 +924,7 @@ struct ata_port_operations {
74709 * fields must be pointers.
74710 */
74711 const struct ata_port_operations *inherits;
74712-};
74713+} __do_const;
74714
74715 struct ata_port_info {
74716 unsigned long flags;
74717diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74718index d3e8ad2..a949f68 100644
74719--- a/include/linux/linkage.h
74720+++ b/include/linux/linkage.h
74721@@ -31,6 +31,7 @@
74722 #endif
74723
74724 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74725+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74726 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74727
74728 /*
74729diff --git a/include/linux/list.h b/include/linux/list.h
74730index f4d8a2f..38e6e46 100644
74731--- a/include/linux/list.h
74732+++ b/include/linux/list.h
74733@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74734 extern void list_del(struct list_head *entry);
74735 #endif
74736
74737+extern void __pax_list_add(struct list_head *new,
74738+ struct list_head *prev,
74739+ struct list_head *next);
74740+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74741+{
74742+ __pax_list_add(new, head, head->next);
74743+}
74744+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74745+{
74746+ __pax_list_add(new, head->prev, head);
74747+}
74748+extern void pax_list_del(struct list_head *entry);
74749+
74750 /**
74751 * list_replace - replace old entry by new one
74752 * @old : the element to be replaced
74753@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74754 INIT_LIST_HEAD(entry);
74755 }
74756
74757+extern void pax_list_del_init(struct list_head *entry);
74758+
74759 /**
74760 * list_move - delete from one list and add as another's head
74761 * @list: the entry to move
74762diff --git a/include/linux/math64.h b/include/linux/math64.h
74763index 2913b86..8dcbb1e 100644
74764--- a/include/linux/math64.h
74765+++ b/include/linux/math64.h
74766@@ -15,7 +15,7 @@
74767 * This is commonly provided by 32bit archs to provide an optimized 64bit
74768 * divide.
74769 */
74770-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74771+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74772 {
74773 *remainder = dividend % divisor;
74774 return dividend / divisor;
74775@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74776 /**
74777 * div64_u64 - unsigned 64bit divide with 64bit divisor
74778 */
74779-static inline u64 div64_u64(u64 dividend, u64 divisor)
74780+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74781 {
74782 return dividend / divisor;
74783 }
74784@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74785 #define div64_ul(x, y) div_u64((x), (y))
74786
74787 #ifndef div_u64_rem
74788-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74789+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74790 {
74791 *remainder = do_div(dividend, divisor);
74792 return dividend;
74793@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74794 * divide.
74795 */
74796 #ifndef div_u64
74797-static inline u64 div_u64(u64 dividend, u32 divisor)
74798+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74799 {
74800 u32 remainder;
74801 return div_u64_rem(dividend, divisor, &remainder);
74802diff --git a/include/linux/mm.h b/include/linux/mm.h
74803index f022460..6ecf4f9 100644
74804--- a/include/linux/mm.h
74805+++ b/include/linux/mm.h
74806@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74807 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74808 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74809 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74810+
74811+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74812+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74813+#endif
74814+
74815 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74816
74817 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74818@@ -208,8 +213,8 @@ struct vm_operations_struct {
74819 /* called by access_process_vm when get_user_pages() fails, typically
74820 * for use by special VMAs that can switch between memory and hardware
74821 */
74822- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74823- void *buf, int len, int write);
74824+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74825+ void *buf, size_t len, int write);
74826 #ifdef CONFIG_NUMA
74827 /*
74828 * set_policy() op must add a reference to any non-NULL @new mempolicy
74829@@ -239,6 +244,7 @@ struct vm_operations_struct {
74830 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74831 unsigned long size, pgoff_t pgoff);
74832 };
74833+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74834
74835 struct mmu_gather;
74836 struct inode;
74837@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74838 unsigned long *pfn);
74839 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74840 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74841-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74842- void *buf, int len, int write);
74843+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74844+ void *buf, size_t len, int write);
74845
74846 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74847 loff_t const holebegin, loff_t const holelen)
74848@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74849 }
74850 #endif
74851
74852-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74853-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74854- void *buf, int len, int write);
74855+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74856+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74857+ void *buf, size_t len, int write);
74858
74859 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74860 unsigned long start, unsigned long nr_pages,
74861@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74862 int set_page_dirty_lock(struct page *page);
74863 int clear_page_dirty_for_io(struct page *page);
74864
74865-/* Is the vma a continuation of the stack vma above it? */
74866-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74867-{
74868- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74869-}
74870-
74871-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74872- unsigned long addr)
74873-{
74874- return (vma->vm_flags & VM_GROWSDOWN) &&
74875- (vma->vm_start == addr) &&
74876- !vma_growsdown(vma->vm_prev, addr);
74877-}
74878-
74879-/* Is the vma a continuation of the stack vma below it? */
74880-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74881-{
74882- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74883-}
74884-
74885-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74886- unsigned long addr)
74887-{
74888- return (vma->vm_flags & VM_GROWSUP) &&
74889- (vma->vm_end == addr) &&
74890- !vma_growsup(vma->vm_next, addr);
74891-}
74892-
74893 extern pid_t
74894 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74895
74896@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
74897 }
74898 #endif
74899
74900+#ifdef CONFIG_MMU
74901+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
74902+#else
74903+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74904+{
74905+ return __pgprot(0);
74906+}
74907+#endif
74908+
74909 int vma_wants_writenotify(struct vm_area_struct *vma);
74910
74911 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
74912@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
74913 {
74914 return 0;
74915 }
74916+
74917+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
74918+ unsigned long address)
74919+{
74920+ return 0;
74921+}
74922 #else
74923 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74924+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74925 #endif
74926
74927 #ifdef __PAGETABLE_PMD_FOLDED
74928@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
74929 {
74930 return 0;
74931 }
74932+
74933+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
74934+ unsigned long address)
74935+{
74936+ return 0;
74937+}
74938 #else
74939 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
74940+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
74941 #endif
74942
74943 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
74944@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
74945 NULL: pud_offset(pgd, address);
74946 }
74947
74948+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74949+{
74950+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
74951+ NULL: pud_offset(pgd, address);
74952+}
74953+
74954 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74955 {
74956 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
74957 NULL: pmd_offset(pud, address);
74958 }
74959+
74960+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74961+{
74962+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
74963+ NULL: pmd_offset(pud, address);
74964+}
74965 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
74966
74967 #if USE_SPLIT_PTLOCKS
74968@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74969 unsigned long len, unsigned long prot, unsigned long flags,
74970 unsigned long pgoff, unsigned long *populate);
74971 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
74972+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
74973
74974 #ifdef CONFIG_MMU
74975 extern int __mm_populate(unsigned long addr, unsigned long len,
74976@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
74977 unsigned long high_limit;
74978 unsigned long align_mask;
74979 unsigned long align_offset;
74980+ unsigned long threadstack_offset;
74981 };
74982
74983-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
74984-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
74985+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
74986+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
74987
74988 /*
74989 * Search for an unmapped address range.
74990@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
74991 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
74992 */
74993 static inline unsigned long
74994-vm_unmapped_area(struct vm_unmapped_area_info *info)
74995+vm_unmapped_area(const struct vm_unmapped_area_info *info)
74996 {
74997 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
74998 return unmapped_area(info);
74999@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75000 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75001 struct vm_area_struct **pprev);
75002
75003+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75004+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75005+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75006+
75007 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75008 NULL if none. Assume start_addr < end_addr. */
75009 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75010@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75011 return vma;
75012 }
75013
75014-#ifdef CONFIG_MMU
75015-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75016-#else
75017-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75018-{
75019- return __pgprot(0);
75020-}
75021-#endif
75022-
75023 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75024 unsigned long change_prot_numa(struct vm_area_struct *vma,
75025 unsigned long start, unsigned long end);
75026@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75027 static inline void vm_stat_account(struct mm_struct *mm,
75028 unsigned long flags, struct file *file, long pages)
75029 {
75030+
75031+#ifdef CONFIG_PAX_RANDMMAP
75032+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75033+#endif
75034+
75035 mm->total_vm += pages;
75036 }
75037 #endif /* CONFIG_PROC_FS */
75038@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75039 extern int sysctl_memory_failure_early_kill;
75040 extern int sysctl_memory_failure_recovery;
75041 extern void shake_page(struct page *p, int access);
75042-extern atomic_long_t num_poisoned_pages;
75043+extern atomic_long_unchecked_t num_poisoned_pages;
75044 extern int soft_offline_page(struct page *page, int flags);
75045
75046 extern void dump_page(struct page *page);
75047@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75048 static inline void setup_nr_node_ids(void) {}
75049 #endif
75050
75051+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75052+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75053+#else
75054+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75055+#endif
75056+
75057 #endif /* __KERNEL__ */
75058 #endif /* _LINUX_MM_H */
75059diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75060index faf4b7c..1e70c6e 100644
75061--- a/include/linux/mm_types.h
75062+++ b/include/linux/mm_types.h
75063@@ -289,6 +289,8 @@ struct vm_area_struct {
75064 #ifdef CONFIG_NUMA
75065 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75066 #endif
75067+
75068+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75069 };
75070
75071 struct core_thread {
75072@@ -435,6 +437,24 @@ struct mm_struct {
75073 int first_nid;
75074 #endif
75075 struct uprobes_state uprobes_state;
75076+
75077+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75078+ unsigned long pax_flags;
75079+#endif
75080+
75081+#ifdef CONFIG_PAX_DLRESOLVE
75082+ unsigned long call_dl_resolve;
75083+#endif
75084+
75085+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75086+ unsigned long call_syscall;
75087+#endif
75088+
75089+#ifdef CONFIG_PAX_ASLR
75090+ unsigned long delta_mmap; /* randomized offset */
75091+ unsigned long delta_stack; /* randomized offset */
75092+#endif
75093+
75094 };
75095
75096 /* first nid will either be a valid NID or one of these values */
75097diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75098index c5d5278..f0b68c8 100644
75099--- a/include/linux/mmiotrace.h
75100+++ b/include/linux/mmiotrace.h
75101@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75102 /* Called from ioremap.c */
75103 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75104 void __iomem *addr);
75105-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75106+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75107
75108 /* For anyone to insert markers. Remember trailing newline. */
75109 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75110@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75111 {
75112 }
75113
75114-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75115+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75116 {
75117 }
75118
75119diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75120index af4a3b7..9ad8889 100644
75121--- a/include/linux/mmzone.h
75122+++ b/include/linux/mmzone.h
75123@@ -396,7 +396,7 @@ struct zone {
75124 unsigned long flags; /* zone flags, see below */
75125
75126 /* Zone statistics */
75127- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75128+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75129
75130 /*
75131 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75132diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75133index 45e9214..a7227d6 100644
75134--- a/include/linux/mod_devicetable.h
75135+++ b/include/linux/mod_devicetable.h
75136@@ -13,7 +13,7 @@
75137 typedef unsigned long kernel_ulong_t;
75138 #endif
75139
75140-#define PCI_ANY_ID (~0)
75141+#define PCI_ANY_ID ((__u16)~0)
75142
75143 struct pci_device_id {
75144 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75145@@ -139,7 +139,7 @@ struct usb_device_id {
75146 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75147 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75148
75149-#define HID_ANY_ID (~0)
75150+#define HID_ANY_ID (~0U)
75151 #define HID_BUS_ANY 0xffff
75152 #define HID_GROUP_ANY 0x0000
75153
75154@@ -467,7 +467,7 @@ struct dmi_system_id {
75155 const char *ident;
75156 struct dmi_strmatch matches[4];
75157 void *driver_data;
75158-};
75159+} __do_const;
75160 /*
75161 * struct dmi_device_id appears during expansion of
75162 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75163diff --git a/include/linux/module.h b/include/linux/module.h
75164index 46f1ea0..a34ca37 100644
75165--- a/include/linux/module.h
75166+++ b/include/linux/module.h
75167@@ -17,9 +17,11 @@
75168 #include <linux/moduleparam.h>
75169 #include <linux/tracepoint.h>
75170 #include <linux/export.h>
75171+#include <linux/fs.h>
75172
75173 #include <linux/percpu.h>
75174 #include <asm/module.h>
75175+#include <asm/pgtable.h>
75176
75177 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75178 #define MODULE_SIG_STRING "~Module signature appended~\n"
75179@@ -54,12 +56,13 @@ struct module_attribute {
75180 int (*test)(struct module *);
75181 void (*free)(struct module *);
75182 };
75183+typedef struct module_attribute __no_const module_attribute_no_const;
75184
75185 struct module_version_attribute {
75186 struct module_attribute mattr;
75187 const char *module_name;
75188 const char *version;
75189-} __attribute__ ((__aligned__(sizeof(void *))));
75190+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75191
75192 extern ssize_t __modver_version_show(struct module_attribute *,
75193 struct module_kobject *, char *);
75194@@ -232,7 +235,7 @@ struct module
75195
75196 /* Sysfs stuff. */
75197 struct module_kobject mkobj;
75198- struct module_attribute *modinfo_attrs;
75199+ module_attribute_no_const *modinfo_attrs;
75200 const char *version;
75201 const char *srcversion;
75202 struct kobject *holders_dir;
75203@@ -281,19 +284,16 @@ struct module
75204 int (*init)(void);
75205
75206 /* If this is non-NULL, vfree after init() returns */
75207- void *module_init;
75208+ void *module_init_rx, *module_init_rw;
75209
75210 /* Here is the actual code + data, vfree'd on unload. */
75211- void *module_core;
75212+ void *module_core_rx, *module_core_rw;
75213
75214 /* Here are the sizes of the init and core sections */
75215- unsigned int init_size, core_size;
75216+ unsigned int init_size_rw, core_size_rw;
75217
75218 /* The size of the executable code in each section. */
75219- unsigned int init_text_size, core_text_size;
75220-
75221- /* Size of RO sections of the module (text+rodata) */
75222- unsigned int init_ro_size, core_ro_size;
75223+ unsigned int init_size_rx, core_size_rx;
75224
75225 /* Arch-specific module values */
75226 struct mod_arch_specific arch;
75227@@ -349,6 +349,10 @@ struct module
75228 #ifdef CONFIG_EVENT_TRACING
75229 struct ftrace_event_call **trace_events;
75230 unsigned int num_trace_events;
75231+ struct file_operations trace_id;
75232+ struct file_operations trace_enable;
75233+ struct file_operations trace_format;
75234+ struct file_operations trace_filter;
75235 #endif
75236 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75237 unsigned int num_ftrace_callsites;
75238@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75239 bool is_module_percpu_address(unsigned long addr);
75240 bool is_module_text_address(unsigned long addr);
75241
75242+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75243+{
75244+
75245+#ifdef CONFIG_PAX_KERNEXEC
75246+ if (ktla_ktva(addr) >= (unsigned long)start &&
75247+ ktla_ktva(addr) < (unsigned long)start + size)
75248+ return 1;
75249+#endif
75250+
75251+ return ((void *)addr >= start && (void *)addr < start + size);
75252+}
75253+
75254+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75255+{
75256+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75257+}
75258+
75259+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75260+{
75261+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75262+}
75263+
75264+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75265+{
75266+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75267+}
75268+
75269+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75270+{
75271+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75272+}
75273+
75274 static inline int within_module_core(unsigned long addr, const struct module *mod)
75275 {
75276- return (unsigned long)mod->module_core <= addr &&
75277- addr < (unsigned long)mod->module_core + mod->core_size;
75278+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75279 }
75280
75281 static inline int within_module_init(unsigned long addr, const struct module *mod)
75282 {
75283- return (unsigned long)mod->module_init <= addr &&
75284- addr < (unsigned long)mod->module_init + mod->init_size;
75285+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75286 }
75287
75288 /* Search for module by name: must hold module_mutex. */
75289diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75290index 560ca53..ef621ef 100644
75291--- a/include/linux/moduleloader.h
75292+++ b/include/linux/moduleloader.h
75293@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75294 sections. Returns NULL on failure. */
75295 void *module_alloc(unsigned long size);
75296
75297+#ifdef CONFIG_PAX_KERNEXEC
75298+void *module_alloc_exec(unsigned long size);
75299+#else
75300+#define module_alloc_exec(x) module_alloc(x)
75301+#endif
75302+
75303 /* Free memory returned from module_alloc. */
75304 void module_free(struct module *mod, void *module_region);
75305
75306+#ifdef CONFIG_PAX_KERNEXEC
75307+void module_free_exec(struct module *mod, void *module_region);
75308+#else
75309+#define module_free_exec(x, y) module_free((x), (y))
75310+#endif
75311+
75312 /*
75313 * Apply the given relocation to the (simplified) ELF. Return -error
75314 * or 0.
75315@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75316 unsigned int relsec,
75317 struct module *me)
75318 {
75319+#ifdef CONFIG_MODULES
75320 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75321+#endif
75322 return -ENOEXEC;
75323 }
75324 #endif
75325@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75326 unsigned int relsec,
75327 struct module *me)
75328 {
75329+#ifdef CONFIG_MODULES
75330 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75331+#endif
75332 return -ENOEXEC;
75333 }
75334 #endif
75335diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75336index 27d9da3..5d94aa3 100644
75337--- a/include/linux/moduleparam.h
75338+++ b/include/linux/moduleparam.h
75339@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75340 * @len is usually just sizeof(string).
75341 */
75342 #define module_param_string(name, string, len, perm) \
75343- static const struct kparam_string __param_string_##name \
75344+ static const struct kparam_string __param_string_##name __used \
75345 = { len, string }; \
75346 __module_param_call(MODULE_PARAM_PREFIX, name, \
75347 &param_ops_string, \
75348@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75349 */
75350 #define module_param_array_named(name, array, type, nump, perm) \
75351 param_check_##type(name, &(array)[0]); \
75352- static const struct kparam_array __param_arr_##name \
75353+ static const struct kparam_array __param_arr_##name __used \
75354 = { .max = ARRAY_SIZE(array), .num = nump, \
75355 .ops = &param_ops_##type, \
75356 .elemsize = sizeof(array[0]), .elem = array }; \
75357diff --git a/include/linux/namei.h b/include/linux/namei.h
75358index 5a5ff57..5ae5070 100644
75359--- a/include/linux/namei.h
75360+++ b/include/linux/namei.h
75361@@ -19,7 +19,7 @@ struct nameidata {
75362 unsigned seq;
75363 int last_type;
75364 unsigned depth;
75365- char *saved_names[MAX_NESTED_LINKS + 1];
75366+ const char *saved_names[MAX_NESTED_LINKS + 1];
75367 };
75368
75369 /*
75370@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75371
75372 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75373
75374-static inline void nd_set_link(struct nameidata *nd, char *path)
75375+static inline void nd_set_link(struct nameidata *nd, const char *path)
75376 {
75377 nd->saved_names[nd->depth] = path;
75378 }
75379
75380-static inline char *nd_get_link(struct nameidata *nd)
75381+static inline const char *nd_get_link(const struct nameidata *nd)
75382 {
75383 return nd->saved_names[nd->depth];
75384 }
75385diff --git a/include/linux/net.h b/include/linux/net.h
75386index 4f27575..fc8a65f 100644
75387--- a/include/linux/net.h
75388+++ b/include/linux/net.h
75389@@ -183,7 +183,7 @@ struct net_proto_family {
75390 int (*create)(struct net *net, struct socket *sock,
75391 int protocol, int kern);
75392 struct module *owner;
75393-};
75394+} __do_const;
75395
75396 struct iovec;
75397 struct kvec;
75398diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75399index 9a41568..203d903 100644
75400--- a/include/linux/netdevice.h
75401+++ b/include/linux/netdevice.h
75402@@ -1061,6 +1061,7 @@ struct net_device_ops {
75403 int (*ndo_change_carrier)(struct net_device *dev,
75404 bool new_carrier);
75405 };
75406+typedef struct net_device_ops __no_const net_device_ops_no_const;
75407
75408 /*
75409 * The DEVICE structure.
75410@@ -1131,7 +1132,7 @@ struct net_device {
75411 int iflink;
75412
75413 struct net_device_stats stats;
75414- atomic_long_t rx_dropped; /* dropped packets by core network
75415+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75416 * Do not use this in drivers.
75417 */
75418
75419diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75420index de70f7b..2675e91 100644
75421--- a/include/linux/netfilter.h
75422+++ b/include/linux/netfilter.h
75423@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75424 #endif
75425 /* Use the module struct to lock set/get code in place */
75426 struct module *owner;
75427-};
75428+} __do_const;
75429
75430 /* Function to register/unregister hook points. */
75431 int nf_register_hook(struct nf_hook_ops *reg);
75432diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75433index d80e275..c3510b8 100644
75434--- a/include/linux/netfilter/ipset/ip_set.h
75435+++ b/include/linux/netfilter/ipset/ip_set.h
75436@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75437 /* Return true if "b" set is the same as "a"
75438 * according to the create set parameters */
75439 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75440-};
75441+} __do_const;
75442
75443 /* The core set type structure */
75444 struct ip_set_type {
75445diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75446index cadb740..d7c37c0 100644
75447--- a/include/linux/netfilter/nfnetlink.h
75448+++ b/include/linux/netfilter/nfnetlink.h
75449@@ -16,7 +16,7 @@ struct nfnl_callback {
75450 const struct nlattr * const cda[]);
75451 const struct nla_policy *policy; /* netlink attribute policy */
75452 const u_int16_t attr_count; /* number of nlattr's */
75453-};
75454+} __do_const;
75455
75456 struct nfnetlink_subsystem {
75457 const char *name;
75458diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75459new file mode 100644
75460index 0000000..33f4af8
75461--- /dev/null
75462+++ b/include/linux/netfilter/xt_gradm.h
75463@@ -0,0 +1,9 @@
75464+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75465+#define _LINUX_NETFILTER_XT_GRADM_H 1
75466+
75467+struct xt_gradm_mtinfo {
75468+ __u16 flags;
75469+ __u16 invflags;
75470+};
75471+
75472+#endif
75473diff --git a/include/linux/nls.h b/include/linux/nls.h
75474index 5dc635f..35f5e11 100644
75475--- a/include/linux/nls.h
75476+++ b/include/linux/nls.h
75477@@ -31,7 +31,7 @@ struct nls_table {
75478 const unsigned char *charset2upper;
75479 struct module *owner;
75480 struct nls_table *next;
75481-};
75482+} __do_const;
75483
75484 /* this value hold the maximum octet of charset */
75485 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75486diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75487index d14a4c3..a078786 100644
75488--- a/include/linux/notifier.h
75489+++ b/include/linux/notifier.h
75490@@ -54,7 +54,8 @@ struct notifier_block {
75491 notifier_fn_t notifier_call;
75492 struct notifier_block __rcu *next;
75493 int priority;
75494-};
75495+} __do_const;
75496+typedef struct notifier_block __no_const notifier_block_no_const;
75497
75498 struct atomic_notifier_head {
75499 spinlock_t lock;
75500diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75501index a4c5624..79d6d88 100644
75502--- a/include/linux/oprofile.h
75503+++ b/include/linux/oprofile.h
75504@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75505 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75506 char const * name, ulong * val);
75507
75508-/** Create a file for read-only access to an atomic_t. */
75509+/** Create a file for read-only access to an atomic_unchecked_t. */
75510 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75511- char const * name, atomic_t * val);
75512+ char const * name, atomic_unchecked_t * val);
75513
75514 /** create a directory */
75515 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75516diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75517index 8db71dc..a76bf2c 100644
75518--- a/include/linux/pci_hotplug.h
75519+++ b/include/linux/pci_hotplug.h
75520@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75521 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75522 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75523 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75524-};
75525+} __do_const;
75526+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75527
75528 /**
75529 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75530diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75531index c43f6ea..2d4416f 100644
75532--- a/include/linux/perf_event.h
75533+++ b/include/linux/perf_event.h
75534@@ -328,8 +328,8 @@ struct perf_event {
75535
75536 enum perf_event_active_state state;
75537 unsigned int attach_state;
75538- local64_t count;
75539- atomic64_t child_count;
75540+ local64_t count; /* PaX: fix it one day */
75541+ atomic64_unchecked_t child_count;
75542
75543 /*
75544 * These are the total time in nanoseconds that the event
75545@@ -380,8 +380,8 @@ struct perf_event {
75546 * These accumulate total time (in nanoseconds) that children
75547 * events have been enabled and running, respectively.
75548 */
75549- atomic64_t child_total_time_enabled;
75550- atomic64_t child_total_time_running;
75551+ atomic64_unchecked_t child_total_time_enabled;
75552+ atomic64_unchecked_t child_total_time_running;
75553
75554 /*
75555 * Protect attach/detach and child_list:
75556@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75557 entry->ip[entry->nr++] = ip;
75558 }
75559
75560-extern int sysctl_perf_event_paranoid;
75561+extern int sysctl_perf_event_legitimately_concerned;
75562 extern int sysctl_perf_event_mlock;
75563 extern int sysctl_perf_event_sample_rate;
75564 extern int sysctl_perf_cpu_time_max_percent;
75565@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75566 loff_t *ppos);
75567
75568
75569+static inline bool perf_paranoid_any(void)
75570+{
75571+ return sysctl_perf_event_legitimately_concerned > 2;
75572+}
75573+
75574 static inline bool perf_paranoid_tracepoint_raw(void)
75575 {
75576- return sysctl_perf_event_paranoid > -1;
75577+ return sysctl_perf_event_legitimately_concerned > -1;
75578 }
75579
75580 static inline bool perf_paranoid_cpu(void)
75581 {
75582- return sysctl_perf_event_paranoid > 0;
75583+ return sysctl_perf_event_legitimately_concerned > 0;
75584 }
75585
75586 static inline bool perf_paranoid_kernel(void)
75587 {
75588- return sysctl_perf_event_paranoid > 1;
75589+ return sysctl_perf_event_legitimately_concerned > 1;
75590 }
75591
75592 extern void perf_event_init(void);
75593@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75594 struct device_attribute attr;
75595 u64 id;
75596 const char *event_str;
75597-};
75598+} __do_const;
75599
75600 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75601 static struct perf_pmu_events_attr _var = { \
75602diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75603index b8809fe..ae4ccd0 100644
75604--- a/include/linux/pipe_fs_i.h
75605+++ b/include/linux/pipe_fs_i.h
75606@@ -47,10 +47,10 @@ struct pipe_inode_info {
75607 struct mutex mutex;
75608 wait_queue_head_t wait;
75609 unsigned int nrbufs, curbuf, buffers;
75610- unsigned int readers;
75611- unsigned int writers;
75612- unsigned int files;
75613- unsigned int waiting_writers;
75614+ atomic_t readers;
75615+ atomic_t writers;
75616+ atomic_t files;
75617+ atomic_t waiting_writers;
75618 unsigned int r_counter;
75619 unsigned int w_counter;
75620 struct page *tmp_page;
75621diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75622index 5f28cae..3d23723 100644
75623--- a/include/linux/platform_data/usb-ehci-s5p.h
75624+++ b/include/linux/platform_data/usb-ehci-s5p.h
75625@@ -14,7 +14,7 @@
75626 struct s5p_ehci_platdata {
75627 int (*phy_init)(struct platform_device *pdev, int type);
75628 int (*phy_exit)(struct platform_device *pdev, int type);
75629-};
75630+} __no_const;
75631
75632 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75633
75634diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75635index c256c59..8ea94c7 100644
75636--- a/include/linux/platform_data/usb-ohci-exynos.h
75637+++ b/include/linux/platform_data/usb-ohci-exynos.h
75638@@ -14,7 +14,7 @@
75639 struct exynos4_ohci_platdata {
75640 int (*phy_init)(struct platform_device *pdev, int type);
75641 int (*phy_exit)(struct platform_device *pdev, int type);
75642-};
75643+} __no_const;
75644
75645 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75646
75647diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75648index 7c1d252..c5c773e 100644
75649--- a/include/linux/pm_domain.h
75650+++ b/include/linux/pm_domain.h
75651@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75652
75653 struct gpd_cpu_data {
75654 unsigned int saved_exit_latency;
75655- struct cpuidle_state *idle_state;
75656+ cpuidle_state_no_const *idle_state;
75657 };
75658
75659 struct generic_pm_domain {
75660diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75661index 6fa7cea..7bf6415 100644
75662--- a/include/linux/pm_runtime.h
75663+++ b/include/linux/pm_runtime.h
75664@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75665
75666 static inline void pm_runtime_mark_last_busy(struct device *dev)
75667 {
75668- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75669+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75670 }
75671
75672 #else /* !CONFIG_PM_RUNTIME */
75673diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75674index 195aafc..49a7bc2 100644
75675--- a/include/linux/pnp.h
75676+++ b/include/linux/pnp.h
75677@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75678 struct pnp_fixup {
75679 char id[7];
75680 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75681-};
75682+} __do_const;
75683
75684 /* config parameters */
75685 #define PNP_CONFIG_NORMAL 0x0001
75686diff --git a/include/linux/poison.h b/include/linux/poison.h
75687index 2110a81..13a11bb 100644
75688--- a/include/linux/poison.h
75689+++ b/include/linux/poison.h
75690@@ -19,8 +19,8 @@
75691 * under normal circumstances, used to verify that nobody uses
75692 * non-initialized list entries.
75693 */
75694-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75695-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75696+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75697+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75698
75699 /********** include/linux/timer.h **********/
75700 /*
75701diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75702index d8b187c3..9a9257a 100644
75703--- a/include/linux/power/smartreflex.h
75704+++ b/include/linux/power/smartreflex.h
75705@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75706 int (*notify)(struct omap_sr *sr, u32 status);
75707 u8 notify_flags;
75708 u8 class_type;
75709-};
75710+} __do_const;
75711
75712 /**
75713 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75714diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75715index 4ea1d37..80f4b33 100644
75716--- a/include/linux/ppp-comp.h
75717+++ b/include/linux/ppp-comp.h
75718@@ -84,7 +84,7 @@ struct compressor {
75719 struct module *owner;
75720 /* Extra skb space needed by the compressor algorithm */
75721 unsigned int comp_extra;
75722-};
75723+} __do_const;
75724
75725 /*
75726 * The return value from decompress routine is the length of the
75727diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75728index f5d4723..a6ea2fa 100644
75729--- a/include/linux/preempt.h
75730+++ b/include/linux/preempt.h
75731@@ -18,8 +18,13 @@
75732 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75733 #endif
75734
75735+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75736+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75737+
75738 #define inc_preempt_count() add_preempt_count(1)
75739+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75740 #define dec_preempt_count() sub_preempt_count(1)
75741+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75742
75743 #define preempt_count() (current_thread_info()->preempt_count)
75744
75745@@ -64,6 +69,12 @@ do { \
75746 barrier(); \
75747 } while (0)
75748
75749+#define raw_preempt_disable() \
75750+do { \
75751+ raw_inc_preempt_count(); \
75752+ barrier(); \
75753+} while (0)
75754+
75755 #define sched_preempt_enable_no_resched() \
75756 do { \
75757 barrier(); \
75758@@ -72,6 +83,12 @@ do { \
75759
75760 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75761
75762+#define raw_preempt_enable_no_resched() \
75763+do { \
75764+ barrier(); \
75765+ raw_dec_preempt_count(); \
75766+} while (0)
75767+
75768 #define preempt_enable() \
75769 do { \
75770 preempt_enable_no_resched(); \
75771@@ -116,8 +133,10 @@ do { \
75772 * region.
75773 */
75774 #define preempt_disable() barrier()
75775+#define raw_preempt_disable() barrier()
75776 #define sched_preempt_enable_no_resched() barrier()
75777 #define preempt_enable_no_resched() barrier()
75778+#define raw_preempt_enable_no_resched() barrier()
75779 #define preempt_enable() barrier()
75780
75781 #define preempt_disable_notrace() barrier()
75782diff --git a/include/linux/printk.h b/include/linux/printk.h
75783index 22c7052..ad3fa0a 100644
75784--- a/include/linux/printk.h
75785+++ b/include/linux/printk.h
75786@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75787 void early_printk(const char *s, ...) { }
75788 #endif
75789
75790+extern int kptr_restrict;
75791+
75792 #ifdef CONFIG_PRINTK
75793 asmlinkage __printf(5, 0)
75794 int vprintk_emit(int facility, int level,
75795@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75796
75797 extern int printk_delay_msec;
75798 extern int dmesg_restrict;
75799-extern int kptr_restrict;
75800
75801 extern void wake_up_klogd(void);
75802
75803diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75804index 608e60a..c26f864 100644
75805--- a/include/linux/proc_fs.h
75806+++ b/include/linux/proc_fs.h
75807@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75808 return proc_create_data(name, mode, parent, proc_fops, NULL);
75809 }
75810
75811+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75812+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75813+{
75814+#ifdef CONFIG_GRKERNSEC_PROC_USER
75815+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75816+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75817+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75818+#else
75819+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75820+#endif
75821+}
75822+
75823+
75824 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75825 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75826 extern void *PDE_DATA(const struct inode *);
75827diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75828index 34a1e10..03a6d03 100644
75829--- a/include/linux/proc_ns.h
75830+++ b/include/linux/proc_ns.h
75831@@ -14,7 +14,7 @@ struct proc_ns_operations {
75832 void (*put)(void *ns);
75833 int (*install)(struct nsproxy *nsproxy, void *ns);
75834 unsigned int (*inum)(void *ns);
75835-};
75836+} __do_const;
75837
75838 struct proc_ns {
75839 void *ns;
75840diff --git a/include/linux/random.h b/include/linux/random.h
75841index 3b9377d..e418336 100644
75842--- a/include/linux/random.h
75843+++ b/include/linux/random.h
75844@@ -10,9 +10,19 @@
75845
75846
75847 extern void add_device_randomness(const void *, unsigned int);
75848+
75849+static inline void add_latent_entropy(void)
75850+{
75851+
75852+#ifdef LATENT_ENTROPY_PLUGIN
75853+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75854+#endif
75855+
75856+}
75857+
75858 extern void add_input_randomness(unsigned int type, unsigned int code,
75859- unsigned int value);
75860-extern void add_interrupt_randomness(int irq, int irq_flags);
75861+ unsigned int value) __latent_entropy;
75862+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75863
75864 extern void get_random_bytes(void *buf, int nbytes);
75865 extern void get_random_bytes_arch(void *buf, int nbytes);
75866@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
75867 u32 prandom_u32_state(struct rnd_state *);
75868 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75869
75870+static inline unsigned long pax_get_random_long(void)
75871+{
75872+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75873+}
75874+
75875 /*
75876 * Handle minimum values for seeds
75877 */
75878diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75879index 4106721..132d42c 100644
75880--- a/include/linux/rculist.h
75881+++ b/include/linux/rculist.h
75882@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75883 struct list_head *prev, struct list_head *next);
75884 #endif
75885
75886+extern void __pax_list_add_rcu(struct list_head *new,
75887+ struct list_head *prev, struct list_head *next);
75888+
75889 /**
75890 * list_add_rcu - add a new entry to rcu-protected list
75891 * @new: new entry to be added
75892@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75893 __list_add_rcu(new, head, head->next);
75894 }
75895
75896+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
75897+{
75898+ __pax_list_add_rcu(new, head, head->next);
75899+}
75900+
75901 /**
75902 * list_add_tail_rcu - add a new entry to rcu-protected list
75903 * @new: new entry to be added
75904@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
75905 __list_add_rcu(new, head->prev, head);
75906 }
75907
75908+static inline void pax_list_add_tail_rcu(struct list_head *new,
75909+ struct list_head *head)
75910+{
75911+ __pax_list_add_rcu(new, head->prev, head);
75912+}
75913+
75914 /**
75915 * list_del_rcu - deletes entry from list without re-initialization
75916 * @entry: the element to delete from the list.
75917@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
75918 entry->prev = LIST_POISON2;
75919 }
75920
75921+extern void pax_list_del_rcu(struct list_head *entry);
75922+
75923 /**
75924 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
75925 * @n: the element to delete from the hash list.
75926diff --git a/include/linux/reboot.h b/include/linux/reboot.h
75927index 8e00f9f..9449b55 100644
75928--- a/include/linux/reboot.h
75929+++ b/include/linux/reboot.h
75930@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
75931 * Architecture-specific implementations of sys_reboot commands.
75932 */
75933
75934-extern void machine_restart(char *cmd);
75935-extern void machine_halt(void);
75936-extern void machine_power_off(void);
75937+extern void machine_restart(char *cmd) __noreturn;
75938+extern void machine_halt(void) __noreturn;
75939+extern void machine_power_off(void) __noreturn;
75940
75941 extern void machine_shutdown(void);
75942 struct pt_regs;
75943@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
75944 */
75945
75946 extern void kernel_restart_prepare(char *cmd);
75947-extern void kernel_restart(char *cmd);
75948-extern void kernel_halt(void);
75949-extern void kernel_power_off(void);
75950+extern void kernel_restart(char *cmd) __noreturn;
75951+extern void kernel_halt(void) __noreturn;
75952+extern void kernel_power_off(void) __noreturn;
75953
75954 extern int C_A_D; /* for sysctl */
75955 void ctrl_alt_del(void);
75956@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
75957 * Emergency restart, callable from an interrupt handler.
75958 */
75959
75960-extern void emergency_restart(void);
75961+extern void emergency_restart(void) __noreturn;
75962 #include <asm/emergency-restart.h>
75963
75964 #endif /* _LINUX_REBOOT_H */
75965diff --git a/include/linux/regset.h b/include/linux/regset.h
75966index 8e0c9fe..ac4d221 100644
75967--- a/include/linux/regset.h
75968+++ b/include/linux/regset.h
75969@@ -161,7 +161,8 @@ struct user_regset {
75970 unsigned int align;
75971 unsigned int bias;
75972 unsigned int core_note_type;
75973-};
75974+} __do_const;
75975+typedef struct user_regset __no_const user_regset_no_const;
75976
75977 /**
75978 * struct user_regset_view - available regsets
75979diff --git a/include/linux/relay.h b/include/linux/relay.h
75980index d7c8359..818daf5 100644
75981--- a/include/linux/relay.h
75982+++ b/include/linux/relay.h
75983@@ -157,7 +157,7 @@ struct rchan_callbacks
75984 * The callback should return 0 if successful, negative if not.
75985 */
75986 int (*remove_buf_file)(struct dentry *dentry);
75987-};
75988+} __no_const;
75989
75990 /*
75991 * CONFIG_RELAY kernel API, kernel/relay.c
75992diff --git a/include/linux/rio.h b/include/linux/rio.h
75993index b71d573..2f940bd 100644
75994--- a/include/linux/rio.h
75995+++ b/include/linux/rio.h
75996@@ -355,7 +355,7 @@ struct rio_ops {
75997 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
75998 u64 rstart, u32 size, u32 flags);
75999 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76000-};
76001+} __no_const;
76002
76003 #define RIO_RESOURCE_MEM 0x00000100
76004 #define RIO_RESOURCE_DOORBELL 0x00000200
76005diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76006index 6dacb93..6174423 100644
76007--- a/include/linux/rmap.h
76008+++ b/include/linux/rmap.h
76009@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76010 void anon_vma_init(void); /* create anon_vma_cachep */
76011 int anon_vma_prepare(struct vm_area_struct *);
76012 void unlink_anon_vmas(struct vm_area_struct *);
76013-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76014-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76015+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76016+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76017
76018 static inline void anon_vma_merge(struct vm_area_struct *vma,
76019 struct vm_area_struct *next)
76020diff --git a/include/linux/sched.h b/include/linux/sched.h
76021index 078066d..4090b3b 100644
76022--- a/include/linux/sched.h
76023+++ b/include/linux/sched.h
76024@@ -62,6 +62,7 @@ struct bio_list;
76025 struct fs_struct;
76026 struct perf_event_context;
76027 struct blk_plug;
76028+struct linux_binprm;
76029
76030 /*
76031 * List of flags we want to share for kernel threads,
76032@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76033 extern int in_sched_functions(unsigned long addr);
76034
76035 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76036-extern signed long schedule_timeout(signed long timeout);
76037+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76038 extern signed long schedule_timeout_interruptible(signed long timeout);
76039 extern signed long schedule_timeout_killable(signed long timeout);
76040 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76041@@ -314,6 +315,19 @@ struct nsproxy;
76042 struct user_namespace;
76043
76044 #ifdef CONFIG_MMU
76045+
76046+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76047+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76048+#else
76049+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76050+{
76051+ return 0;
76052+}
76053+#endif
76054+
76055+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76056+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76057+
76058 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76059 extern unsigned long
76060 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76061@@ -589,6 +603,17 @@ struct signal_struct {
76062 #ifdef CONFIG_TASKSTATS
76063 struct taskstats *stats;
76064 #endif
76065+
76066+#ifdef CONFIG_GRKERNSEC
76067+ u32 curr_ip;
76068+ u32 saved_ip;
76069+ u32 gr_saddr;
76070+ u32 gr_daddr;
76071+ u16 gr_sport;
76072+ u16 gr_dport;
76073+ u8 used_accept:1;
76074+#endif
76075+
76076 #ifdef CONFIG_AUDIT
76077 unsigned audit_tty;
76078 unsigned audit_tty_log_passwd;
76079@@ -669,6 +694,14 @@ struct user_struct {
76080 struct key *session_keyring; /* UID's default session keyring */
76081 #endif
76082
76083+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76084+ unsigned char kernel_banned;
76085+#endif
76086+#ifdef CONFIG_GRKERNSEC_BRUTE
76087+ unsigned char suid_banned;
76088+ unsigned long suid_ban_expires;
76089+#endif
76090+
76091 /* Hash table maintenance information */
76092 struct hlist_node uidhash_node;
76093 kuid_t uid;
76094@@ -1151,8 +1184,8 @@ struct task_struct {
76095 struct list_head thread_group;
76096
76097 struct completion *vfork_done; /* for vfork() */
76098- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76099- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76100+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76101+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76102
76103 cputime_t utime, stime, utimescaled, stimescaled;
76104 cputime_t gtime;
76105@@ -1177,11 +1210,6 @@ struct task_struct {
76106 struct task_cputime cputime_expires;
76107 struct list_head cpu_timers[3];
76108
76109-/* process credentials */
76110- const struct cred __rcu *real_cred; /* objective and real subjective task
76111- * credentials (COW) */
76112- const struct cred __rcu *cred; /* effective (overridable) subjective task
76113- * credentials (COW) */
76114 char comm[TASK_COMM_LEN]; /* executable name excluding path
76115 - access with [gs]et_task_comm (which lock
76116 it with task_lock())
76117@@ -1198,6 +1226,10 @@ struct task_struct {
76118 #endif
76119 /* CPU-specific state of this task */
76120 struct thread_struct thread;
76121+/* thread_info moved to task_struct */
76122+#ifdef CONFIG_X86
76123+ struct thread_info tinfo;
76124+#endif
76125 /* filesystem information */
76126 struct fs_struct *fs;
76127 /* open file information */
76128@@ -1271,6 +1303,10 @@ struct task_struct {
76129 gfp_t lockdep_reclaim_gfp;
76130 #endif
76131
76132+/* process credentials */
76133+ const struct cred __rcu *real_cred; /* objective and real subjective task
76134+ * credentials (COW) */
76135+
76136 /* journalling filesystem info */
76137 void *journal_info;
76138
76139@@ -1309,6 +1345,10 @@ struct task_struct {
76140 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76141 struct list_head cg_list;
76142 #endif
76143+
76144+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76145+ * credentials (COW) */
76146+
76147 #ifdef CONFIG_FUTEX
76148 struct robust_list_head __user *robust_list;
76149 #ifdef CONFIG_COMPAT
76150@@ -1406,8 +1446,76 @@ struct task_struct {
76151 unsigned int sequential_io;
76152 unsigned int sequential_io_avg;
76153 #endif
76154+
76155+#ifdef CONFIG_GRKERNSEC
76156+ /* grsecurity */
76157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76158+ u64 exec_id;
76159+#endif
76160+#ifdef CONFIG_GRKERNSEC_SETXID
76161+ const struct cred *delayed_cred;
76162+#endif
76163+ struct dentry *gr_chroot_dentry;
76164+ struct acl_subject_label *acl;
76165+ struct acl_role_label *role;
76166+ struct file *exec_file;
76167+ unsigned long brute_expires;
76168+ u16 acl_role_id;
76169+ /* is this the task that authenticated to the special role */
76170+ u8 acl_sp_role;
76171+ u8 is_writable;
76172+ u8 brute;
76173+ u8 gr_is_chrooted;
76174+#endif
76175+
76176 };
76177
76178+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76179+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76180+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76181+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76182+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76183+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76184+
76185+#ifdef CONFIG_PAX_SOFTMODE
76186+extern int pax_softmode;
76187+#endif
76188+
76189+extern int pax_check_flags(unsigned long *);
76190+
76191+/* if tsk != current then task_lock must be held on it */
76192+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76193+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76194+{
76195+ if (likely(tsk->mm))
76196+ return tsk->mm->pax_flags;
76197+ else
76198+ return 0UL;
76199+}
76200+
76201+/* if tsk != current then task_lock must be held on it */
76202+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76203+{
76204+ if (likely(tsk->mm)) {
76205+ tsk->mm->pax_flags = flags;
76206+ return 0;
76207+ }
76208+ return -EINVAL;
76209+}
76210+#endif
76211+
76212+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76213+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76214+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76215+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76216+#endif
76217+
76218+struct path;
76219+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76220+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76221+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76222+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76223+
76224 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76225 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76226
76227@@ -1466,7 +1574,7 @@ struct pid_namespace;
76228 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76229 struct pid_namespace *ns);
76230
76231-static inline pid_t task_pid_nr(struct task_struct *tsk)
76232+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76233 {
76234 return tsk->pid;
76235 }
76236@@ -1916,7 +2024,9 @@ void yield(void);
76237 extern struct exec_domain default_exec_domain;
76238
76239 union thread_union {
76240+#ifndef CONFIG_X86
76241 struct thread_info thread_info;
76242+#endif
76243 unsigned long stack[THREAD_SIZE/sizeof(long)];
76244 };
76245
76246@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76247 */
76248
76249 extern struct task_struct *find_task_by_vpid(pid_t nr);
76250+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76251 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76252 struct pid_namespace *ns);
76253
76254@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76255 extern void exit_itimers(struct signal_struct *);
76256 extern void flush_itimer_signals(void);
76257
76258-extern void do_group_exit(int);
76259+extern __noreturn void do_group_exit(int);
76260
76261 extern int allow_signal(int);
76262 extern int disallow_signal(int);
76263@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76264
76265 #endif
76266
76267-static inline int object_is_on_stack(void *obj)
76268+static inline int object_starts_on_stack(void *obj)
76269 {
76270- void *stack = task_stack_page(current);
76271+ const void *stack = task_stack_page(current);
76272
76273 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76274 }
76275diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76276index bf8086b..962b035 100644
76277--- a/include/linux/sched/sysctl.h
76278+++ b/include/linux/sched/sysctl.h
76279@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76280 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76281
76282 extern int sysctl_max_map_count;
76283+extern unsigned long sysctl_heap_stack_gap;
76284
76285 extern unsigned int sysctl_sched_latency;
76286 extern unsigned int sysctl_sched_min_granularity;
76287diff --git a/include/linux/security.h b/include/linux/security.h
76288index 7ce53ae..8ee24a5 100644
76289--- a/include/linux/security.h
76290+++ b/include/linux/security.h
76291@@ -27,6 +27,7 @@
76292 #include <linux/slab.h>
76293 #include <linux/err.h>
76294 #include <linux/string.h>
76295+#include <linux/grsecurity.h>
76296
76297 struct linux_binprm;
76298 struct cred;
76299@@ -116,8 +117,6 @@ struct seq_file;
76300
76301 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76302
76303-void reset_security_ops(void);
76304-
76305 #ifdef CONFIG_MMU
76306 extern unsigned long mmap_min_addr;
76307 extern unsigned long dac_mmap_min_addr;
76308diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76309index 4e32edc..f8f2d18 100644
76310--- a/include/linux/seq_file.h
76311+++ b/include/linux/seq_file.h
76312@@ -26,6 +26,9 @@ struct seq_file {
76313 struct mutex lock;
76314 const struct seq_operations *op;
76315 int poll_event;
76316+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76317+ u64 exec_id;
76318+#endif
76319 #ifdef CONFIG_USER_NS
76320 struct user_namespace *user_ns;
76321 #endif
76322@@ -38,6 +41,7 @@ struct seq_operations {
76323 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76324 int (*show) (struct seq_file *m, void *v);
76325 };
76326+typedef struct seq_operations __no_const seq_operations_no_const;
76327
76328 #define SEQ_SKIP 1
76329
76330diff --git a/include/linux/shm.h b/include/linux/shm.h
76331index 429c199..4d42e38 100644
76332--- a/include/linux/shm.h
76333+++ b/include/linux/shm.h
76334@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76335
76336 /* The task created the shm object. NULL if the task is dead. */
76337 struct task_struct *shm_creator;
76338+#ifdef CONFIG_GRKERNSEC
76339+ time_t shm_createtime;
76340+ pid_t shm_lapid;
76341+#endif
76342 };
76343
76344 /* shm_mode upper byte flags */
76345diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76346index 3b71a4e..5c9f309 100644
76347--- a/include/linux/skbuff.h
76348+++ b/include/linux/skbuff.h
76349@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76350 extern struct sk_buff *__alloc_skb(unsigned int size,
76351 gfp_t priority, int flags, int node);
76352 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76353-static inline struct sk_buff *alloc_skb(unsigned int size,
76354+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76355 gfp_t priority)
76356 {
76357 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76358@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76359 */
76360 static inline int skb_queue_empty(const struct sk_buff_head *list)
76361 {
76362- return list->next == (struct sk_buff *)list;
76363+ return list->next == (const struct sk_buff *)list;
76364 }
76365
76366 /**
76367@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76368 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76369 const struct sk_buff *skb)
76370 {
76371- return skb->next == (struct sk_buff *)list;
76372+ return skb->next == (const struct sk_buff *)list;
76373 }
76374
76375 /**
76376@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76377 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76378 const struct sk_buff *skb)
76379 {
76380- return skb->prev == (struct sk_buff *)list;
76381+ return skb->prev == (const struct sk_buff *)list;
76382 }
76383
76384 /**
76385@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76386 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76387 */
76388 #ifndef NET_SKB_PAD
76389-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76390+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76391 #endif
76392
76393 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76394@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76395 int noblock, int *err);
76396 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76397 struct poll_table_struct *wait);
76398-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76399+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76400 int offset, struct iovec *to,
76401 int size);
76402 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76403@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76404 nf_bridge_put(skb->nf_bridge);
76405 skb->nf_bridge = NULL;
76406 #endif
76407+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76408+ skb->nf_trace = 0;
76409+#endif
76410 }
76411
76412 static inline void nf_reset_trace(struct sk_buff *skb)
76413diff --git a/include/linux/slab.h b/include/linux/slab.h
76414index 6c5cc0e..9ca0fd6 100644
76415--- a/include/linux/slab.h
76416+++ b/include/linux/slab.h
76417@@ -12,15 +12,29 @@
76418 #include <linux/gfp.h>
76419 #include <linux/types.h>
76420 #include <linux/workqueue.h>
76421-
76422+#include <linux/err.h>
76423
76424 /*
76425 * Flags to pass to kmem_cache_create().
76426 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76427 */
76428 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76429+
76430+#ifdef CONFIG_PAX_USERCOPY_SLABS
76431+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76432+#else
76433+#define SLAB_USERCOPY 0x00000000UL
76434+#endif
76435+
76436 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76437 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76438+
76439+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76440+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76441+#else
76442+#define SLAB_NO_SANITIZE 0x00000000UL
76443+#endif
76444+
76445 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76446 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76447 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76448@@ -89,10 +103,13 @@
76449 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76450 * Both make kfree a no-op.
76451 */
76452-#define ZERO_SIZE_PTR ((void *)16)
76453+#define ZERO_SIZE_PTR \
76454+({ \
76455+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76456+ (void *)(-MAX_ERRNO-1L); \
76457+})
76458
76459-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76460- (unsigned long)ZERO_SIZE_PTR)
76461+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76462
76463
76464 struct mem_cgroup;
76465@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76466 void kfree(const void *);
76467 void kzfree(const void *);
76468 size_t ksize(const void *);
76469+const char *check_heap_object(const void *ptr, unsigned long n);
76470+bool is_usercopy_object(const void *ptr);
76471
76472 /*
76473 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76474@@ -164,7 +183,7 @@ struct kmem_cache {
76475 unsigned int align; /* Alignment as calculated */
76476 unsigned long flags; /* Active flags on the slab */
76477 const char *name; /* Slab name for sysfs */
76478- int refcount; /* Use counter */
76479+ atomic_t refcount; /* Use counter */
76480 void (*ctor)(void *); /* Called on object slot creation */
76481 struct list_head list; /* List of all slab caches on the system */
76482 };
76483@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76484 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76485 #endif
76486
76487+#ifdef CONFIG_PAX_USERCOPY_SLABS
76488+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76489+#endif
76490+
76491 /*
76492 * Figure out which kmalloc slab an allocation of a certain size
76493 * belongs to.
76494@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76495 * 2 = 120 .. 192 bytes
76496 * n = 2^(n-1) .. 2^n -1
76497 */
76498-static __always_inline int kmalloc_index(size_t size)
76499+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76500 {
76501 if (!size)
76502 return 0;
76503@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76504 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76505 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76506 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76507-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76508+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76509 #define kmalloc_track_caller(size, flags) \
76510 __kmalloc_track_caller(size, flags, _RET_IP_)
76511 #else
76512@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76513 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76514 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76515 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76516-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76517+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76518 #define kmalloc_node_track_caller(size, flags, node) \
76519 __kmalloc_node_track_caller(size, flags, node, \
76520 _RET_IP_)
76521diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76522index cd40158..4e2f7af 100644
76523--- a/include/linux/slab_def.h
76524+++ b/include/linux/slab_def.h
76525@@ -50,7 +50,7 @@ struct kmem_cache {
76526 /* 4) cache creation/removal */
76527 const char *name;
76528 struct list_head list;
76529- int refcount;
76530+ atomic_t refcount;
76531 int object_size;
76532 int align;
76533
76534@@ -66,10 +66,14 @@ struct kmem_cache {
76535 unsigned long node_allocs;
76536 unsigned long node_frees;
76537 unsigned long node_overflow;
76538- atomic_t allochit;
76539- atomic_t allocmiss;
76540- atomic_t freehit;
76541- atomic_t freemiss;
76542+ atomic_unchecked_t allochit;
76543+ atomic_unchecked_t allocmiss;
76544+ atomic_unchecked_t freehit;
76545+ atomic_unchecked_t freemiss;
76546+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76547+ atomic_unchecked_t sanitized;
76548+ atomic_unchecked_t not_sanitized;
76549+#endif
76550
76551 /*
76552 * If debugging is enabled, then the allocator can add additional
76553@@ -103,7 +107,7 @@ struct kmem_cache {
76554 };
76555
76556 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76557-void *__kmalloc(size_t size, gfp_t flags);
76558+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76559
76560 #ifdef CONFIG_TRACING
76561 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76562@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76563 cachep = kmalloc_dma_caches[i];
76564 else
76565 #endif
76566+
76567+#ifdef CONFIG_PAX_USERCOPY_SLABS
76568+ if (flags & GFP_USERCOPY)
76569+ cachep = kmalloc_usercopy_caches[i];
76570+ else
76571+#endif
76572+
76573 cachep = kmalloc_caches[i];
76574
76575 ret = kmem_cache_alloc_trace(cachep, flags, size);
76576@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76577 }
76578
76579 #ifdef CONFIG_NUMA
76580-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76581+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76582 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76583
76584 #ifdef CONFIG_TRACING
76585@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76586 cachep = kmalloc_dma_caches[i];
76587 else
76588 #endif
76589+
76590+#ifdef CONFIG_PAX_USERCOPY_SLABS
76591+ if (flags & GFP_USERCOPY)
76592+ cachep = kmalloc_usercopy_caches[i];
76593+ else
76594+#endif
76595+
76596 cachep = kmalloc_caches[i];
76597
76598 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76599diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76600index 095a5a4..4b82027 100644
76601--- a/include/linux/slob_def.h
76602+++ b/include/linux/slob_def.h
76603@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76604 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76605 }
76606
76607-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76608+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76609
76610 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76611 {
76612@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76613 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76614 }
76615
76616-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76617+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76618 {
76619 return kmalloc(size, flags);
76620 }
76621diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76622index 027276f..092bfe8 100644
76623--- a/include/linux/slub_def.h
76624+++ b/include/linux/slub_def.h
76625@@ -80,7 +80,7 @@ struct kmem_cache {
76626 struct kmem_cache_order_objects max;
76627 struct kmem_cache_order_objects min;
76628 gfp_t allocflags; /* gfp flags to use on each alloc */
76629- int refcount; /* Refcount for slab cache destroy */
76630+ atomic_t refcount; /* Refcount for slab cache destroy */
76631 void (*ctor)(void *);
76632 int inuse; /* Offset to metadata */
76633 int align; /* Alignment */
76634@@ -105,7 +105,7 @@ struct kmem_cache {
76635 };
76636
76637 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76638-void *__kmalloc(size_t size, gfp_t flags);
76639+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76640
76641 static __always_inline void *
76642 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76643@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76644 }
76645 #endif
76646
76647-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76648+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76649 {
76650 unsigned int order = get_order(size);
76651 return kmalloc_order_trace(size, flags, order);
76652@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76653 }
76654
76655 #ifdef CONFIG_NUMA
76656-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76657+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76658 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76659
76660 #ifdef CONFIG_TRACING
76661diff --git a/include/linux/smp.h b/include/linux/smp.h
76662index c181399..09d7b92 100644
76663--- a/include/linux/smp.h
76664+++ b/include/linux/smp.h
76665@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76666 #endif
76667
76668 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76669+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76670 #define put_cpu() preempt_enable()
76671+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76672
76673 /*
76674 * Callback to arch code if there's nosmp or maxcpus=0 on the
76675diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76676index 54f91d3..be2c379 100644
76677--- a/include/linux/sock_diag.h
76678+++ b/include/linux/sock_diag.h
76679@@ -11,7 +11,7 @@ struct sock;
76680 struct sock_diag_handler {
76681 __u8 family;
76682 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76683-};
76684+} __do_const;
76685
76686 int sock_diag_register(const struct sock_diag_handler *h);
76687 void sock_diag_unregister(const struct sock_diag_handler *h);
76688diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76689index 680f9a3..f13aeb0 100644
76690--- a/include/linux/sonet.h
76691+++ b/include/linux/sonet.h
76692@@ -7,7 +7,7 @@
76693 #include <uapi/linux/sonet.h>
76694
76695 struct k_sonet_stats {
76696-#define __HANDLE_ITEM(i) atomic_t i
76697+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76698 __SONET_ITEMS
76699 #undef __HANDLE_ITEM
76700 };
76701diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76702index 07d8e53..dc934c9 100644
76703--- a/include/linux/sunrpc/addr.h
76704+++ b/include/linux/sunrpc/addr.h
76705@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76706 {
76707 switch (sap->sa_family) {
76708 case AF_INET:
76709- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76710+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76711 case AF_INET6:
76712- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76713+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76714 }
76715 return 0;
76716 }
76717@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76718 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76719 const struct sockaddr *src)
76720 {
76721- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76722+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76723 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76724
76725 dsin->sin_family = ssin->sin_family;
76726@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76727 if (sa->sa_family != AF_INET6)
76728 return 0;
76729
76730- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76731+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76732 }
76733
76734 #endif /* _LINUX_SUNRPC_ADDR_H */
76735diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76736index bfe11be..12bc8c4 100644
76737--- a/include/linux/sunrpc/clnt.h
76738+++ b/include/linux/sunrpc/clnt.h
76739@@ -96,7 +96,7 @@ struct rpc_procinfo {
76740 unsigned int p_timer; /* Which RTT timer to use */
76741 u32 p_statidx; /* Which procedure to account */
76742 const char * p_name; /* name of procedure */
76743-};
76744+} __do_const;
76745
76746 #ifdef __KERNEL__
76747
76748diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76749index 1f0216b..6a4fa50 100644
76750--- a/include/linux/sunrpc/svc.h
76751+++ b/include/linux/sunrpc/svc.h
76752@@ -411,7 +411,7 @@ struct svc_procedure {
76753 unsigned int pc_count; /* call count */
76754 unsigned int pc_cachetype; /* cache info (NFS) */
76755 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76756-};
76757+} __do_const;
76758
76759 /*
76760 * Function prototypes.
76761diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76762index 0b8e3e6..33e0a01 100644
76763--- a/include/linux/sunrpc/svc_rdma.h
76764+++ b/include/linux/sunrpc/svc_rdma.h
76765@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76766 extern unsigned int svcrdma_max_requests;
76767 extern unsigned int svcrdma_max_req_size;
76768
76769-extern atomic_t rdma_stat_recv;
76770-extern atomic_t rdma_stat_read;
76771-extern atomic_t rdma_stat_write;
76772-extern atomic_t rdma_stat_sq_starve;
76773-extern atomic_t rdma_stat_rq_starve;
76774-extern atomic_t rdma_stat_rq_poll;
76775-extern atomic_t rdma_stat_rq_prod;
76776-extern atomic_t rdma_stat_sq_poll;
76777-extern atomic_t rdma_stat_sq_prod;
76778+extern atomic_unchecked_t rdma_stat_recv;
76779+extern atomic_unchecked_t rdma_stat_read;
76780+extern atomic_unchecked_t rdma_stat_write;
76781+extern atomic_unchecked_t rdma_stat_sq_starve;
76782+extern atomic_unchecked_t rdma_stat_rq_starve;
76783+extern atomic_unchecked_t rdma_stat_rq_poll;
76784+extern atomic_unchecked_t rdma_stat_rq_prod;
76785+extern atomic_unchecked_t rdma_stat_sq_poll;
76786+extern atomic_unchecked_t rdma_stat_sq_prod;
76787
76788 #define RPCRDMA_VERSION 1
76789
76790diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76791index 8d71d65..f79586e 100644
76792--- a/include/linux/sunrpc/svcauth.h
76793+++ b/include/linux/sunrpc/svcauth.h
76794@@ -120,7 +120,7 @@ struct auth_ops {
76795 int (*release)(struct svc_rqst *rq);
76796 void (*domain_release)(struct auth_domain *);
76797 int (*set_client)(struct svc_rqst *rq);
76798-};
76799+} __do_const;
76800
76801 #define SVC_GARBAGE 1
76802 #define SVC_SYSERR 2
76803diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76804index a5ffd32..0935dea 100644
76805--- a/include/linux/swiotlb.h
76806+++ b/include/linux/swiotlb.h
76807@@ -60,7 +60,8 @@ extern void
76808
76809 extern void
76810 swiotlb_free_coherent(struct device *hwdev, size_t size,
76811- void *vaddr, dma_addr_t dma_handle);
76812+ void *vaddr, dma_addr_t dma_handle,
76813+ struct dma_attrs *attrs);
76814
76815 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76816 unsigned long offset, size_t size,
76817diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76818index 84662ec..5271947 100644
76819--- a/include/linux/syscalls.h
76820+++ b/include/linux/syscalls.h
76821@@ -97,8 +97,14 @@ struct sigaltstack;
76822 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76823
76824 #define __SC_DECL(t, a) t a
76825+#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
76826 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76827-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76828+#define __SC_LONG(t, a) __typeof( \
76829+ __builtin_choose_expr( \
76830+ sizeof(t) > sizeof(int), \
76831+ (t) 0, \
76832+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76833+ )) a
76834 #define __SC_CAST(t, a) (t) a
76835 #define __SC_ARGS(t, a) a
76836 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76837@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76838 asmlinkage long sys_fsync(unsigned int fd);
76839 asmlinkage long sys_fdatasync(unsigned int fd);
76840 asmlinkage long sys_bdflush(int func, long data);
76841-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76842- char __user *type, unsigned long flags,
76843+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76844+ const char __user *type, unsigned long flags,
76845 void __user *data);
76846-asmlinkage long sys_umount(char __user *name, int flags);
76847-asmlinkage long sys_oldumount(char __user *name);
76848+asmlinkage long sys_umount(const char __user *name, int flags);
76849+asmlinkage long sys_oldumount(const char __user *name);
76850 asmlinkage long sys_truncate(const char __user *path, long length);
76851 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76852 asmlinkage long sys_stat(const char __user *filename,
76853@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76854 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76855 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76856 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76857- struct sockaddr __user *, int);
76858+ struct sockaddr __user *, int) __intentional_overflow(0);
76859 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76860 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76861 unsigned int vlen, unsigned flags);
76862diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76863index 27b3b0b..e093dd9 100644
76864--- a/include/linux/syscore_ops.h
76865+++ b/include/linux/syscore_ops.h
76866@@ -16,7 +16,7 @@ struct syscore_ops {
76867 int (*suspend)(void);
76868 void (*resume)(void);
76869 void (*shutdown)(void);
76870-};
76871+} __do_const;
76872
76873 extern void register_syscore_ops(struct syscore_ops *ops);
76874 extern void unregister_syscore_ops(struct syscore_ops *ops);
76875diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76876index 14a8ff2..af52bad 100644
76877--- a/include/linux/sysctl.h
76878+++ b/include/linux/sysctl.h
76879@@ -34,13 +34,13 @@ struct ctl_table_root;
76880 struct ctl_table_header;
76881 struct ctl_dir;
76882
76883-typedef struct ctl_table ctl_table;
76884-
76885 typedef int proc_handler (struct ctl_table *ctl, int write,
76886 void __user *buffer, size_t *lenp, loff_t *ppos);
76887
76888 extern int proc_dostring(struct ctl_table *, int,
76889 void __user *, size_t *, loff_t *);
76890+extern int proc_dostring_modpriv(struct ctl_table *, int,
76891+ void __user *, size_t *, loff_t *);
76892 extern int proc_dointvec(struct ctl_table *, int,
76893 void __user *, size_t *, loff_t *);
76894 extern int proc_dointvec_minmax(struct ctl_table *, int,
76895@@ -115,7 +115,9 @@ struct ctl_table
76896 struct ctl_table_poll *poll;
76897 void *extra1;
76898 void *extra2;
76899-};
76900+} __do_const;
76901+typedef struct ctl_table __no_const ctl_table_no_const;
76902+typedef struct ctl_table ctl_table;
76903
76904 struct ctl_node {
76905 struct rb_node node;
76906diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
76907index 9e8a9b5..753de68 100644
76908--- a/include/linux/sysfs.h
76909+++ b/include/linux/sysfs.h
76910@@ -33,7 +33,8 @@ struct attribute {
76911 struct lock_class_key *key;
76912 struct lock_class_key skey;
76913 #endif
76914-};
76915+} __do_const;
76916+typedef struct attribute __no_const attribute_no_const;
76917
76918 /**
76919 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
76920@@ -62,7 +63,8 @@ struct attribute_group {
76921 struct attribute *, int);
76922 struct attribute **attrs;
76923 struct bin_attribute **bin_attrs;
76924-};
76925+} __do_const;
76926+typedef struct attribute_group __no_const attribute_group_no_const;
76927
76928 /**
76929 * Use these macros to make defining attributes easier. See include/linux/device.h
76930@@ -123,7 +125,8 @@ struct bin_attribute {
76931 char *, loff_t, size_t);
76932 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
76933 struct vm_area_struct *vma);
76934-};
76935+} __do_const;
76936+typedef struct bin_attribute __no_const bin_attribute_no_const;
76937
76938 /**
76939 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
76940diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
76941index 7faf933..9b85a0c 100644
76942--- a/include/linux/sysrq.h
76943+++ b/include/linux/sysrq.h
76944@@ -16,6 +16,7 @@
76945
76946 #include <linux/errno.h>
76947 #include <linux/types.h>
76948+#include <linux/compiler.h>
76949
76950 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
76951 #define SYSRQ_DEFAULT_ENABLE 1
76952@@ -36,7 +37,7 @@ struct sysrq_key_op {
76953 char *help_msg;
76954 char *action_msg;
76955 int enable_mask;
76956-};
76957+} __do_const;
76958
76959 #ifdef CONFIG_MAGIC_SYSRQ
76960
76961diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
76962index e7e0473..7989295 100644
76963--- a/include/linux/thread_info.h
76964+++ b/include/linux/thread_info.h
76965@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
76966 #error "no set_restore_sigmask() provided and default one won't work"
76967 #endif
76968
76969+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
76970+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
76971+{
76972+#ifndef CONFIG_PAX_USERCOPY_DEBUG
76973+ if (!__builtin_constant_p(n))
76974+#endif
76975+ __check_object_size(ptr, n, to_user);
76976+}
76977+
76978 #endif /* __KERNEL__ */
76979
76980 #endif /* _LINUX_THREAD_INFO_H */
76981diff --git a/include/linux/tty.h b/include/linux/tty.h
76982index 01ac30e..bf18a71 100644
76983--- a/include/linux/tty.h
76984+++ b/include/linux/tty.h
76985@@ -194,7 +194,7 @@ struct tty_port {
76986 const struct tty_port_operations *ops; /* Port operations */
76987 spinlock_t lock; /* Lock protecting tty field */
76988 int blocked_open; /* Waiting to open */
76989- int count; /* Usage count */
76990+ atomic_t count; /* Usage count */
76991 wait_queue_head_t open_wait; /* Open waiters */
76992 wait_queue_head_t close_wait; /* Close waiters */
76993 wait_queue_head_t delta_msr_wait; /* Modem status change */
76994@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
76995 struct tty_struct *tty, struct file *filp);
76996 static inline int tty_port_users(struct tty_port *port)
76997 {
76998- return port->count + port->blocked_open;
76999+ return atomic_read(&port->count) + port->blocked_open;
77000 }
77001
77002 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77003diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77004index 756a609..b302dd6 100644
77005--- a/include/linux/tty_driver.h
77006+++ b/include/linux/tty_driver.h
77007@@ -285,7 +285,7 @@ struct tty_operations {
77008 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77009 #endif
77010 const struct file_operations *proc_fops;
77011-};
77012+} __do_const;
77013
77014 struct tty_driver {
77015 int magic; /* magic number for this structure */
77016diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77017index a1b0489..f02e17c 100644
77018--- a/include/linux/tty_ldisc.h
77019+++ b/include/linux/tty_ldisc.h
77020@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77021
77022 struct module *owner;
77023
77024- int refcount;
77025+ atomic_t refcount;
77026 };
77027
77028 struct tty_ldisc {
77029diff --git a/include/linux/types.h b/include/linux/types.h
77030index 4d118ba..c3ee9bf 100644
77031--- a/include/linux/types.h
77032+++ b/include/linux/types.h
77033@@ -176,10 +176,26 @@ typedef struct {
77034 int counter;
77035 } atomic_t;
77036
77037+#ifdef CONFIG_PAX_REFCOUNT
77038+typedef struct {
77039+ int counter;
77040+} atomic_unchecked_t;
77041+#else
77042+typedef atomic_t atomic_unchecked_t;
77043+#endif
77044+
77045 #ifdef CONFIG_64BIT
77046 typedef struct {
77047 long counter;
77048 } atomic64_t;
77049+
77050+#ifdef CONFIG_PAX_REFCOUNT
77051+typedef struct {
77052+ long counter;
77053+} atomic64_unchecked_t;
77054+#else
77055+typedef atomic64_t atomic64_unchecked_t;
77056+#endif
77057 #endif
77058
77059 struct list_head {
77060diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77061index 5ca0951..ab496a5 100644
77062--- a/include/linux/uaccess.h
77063+++ b/include/linux/uaccess.h
77064@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77065 long ret; \
77066 mm_segment_t old_fs = get_fs(); \
77067 \
77068- set_fs(KERNEL_DS); \
77069 pagefault_disable(); \
77070- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77071- pagefault_enable(); \
77072+ set_fs(KERNEL_DS); \
77073+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77074 set_fs(old_fs); \
77075+ pagefault_enable(); \
77076 ret; \
77077 })
77078
77079diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77080index 8e522cbc..aa8572d 100644
77081--- a/include/linux/uidgid.h
77082+++ b/include/linux/uidgid.h
77083@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77084
77085 #endif /* CONFIG_USER_NS */
77086
77087+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77088+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77089+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77090+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77091+
77092 #endif /* _LINUX_UIDGID_H */
77093diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77094index 99c1b4d..562e6f3 100644
77095--- a/include/linux/unaligned/access_ok.h
77096+++ b/include/linux/unaligned/access_ok.h
77097@@ -4,34 +4,34 @@
77098 #include <linux/kernel.h>
77099 #include <asm/byteorder.h>
77100
77101-static inline u16 get_unaligned_le16(const void *p)
77102+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77103 {
77104- return le16_to_cpup((__le16 *)p);
77105+ return le16_to_cpup((const __le16 *)p);
77106 }
77107
77108-static inline u32 get_unaligned_le32(const void *p)
77109+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77110 {
77111- return le32_to_cpup((__le32 *)p);
77112+ return le32_to_cpup((const __le32 *)p);
77113 }
77114
77115-static inline u64 get_unaligned_le64(const void *p)
77116+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77117 {
77118- return le64_to_cpup((__le64 *)p);
77119+ return le64_to_cpup((const __le64 *)p);
77120 }
77121
77122-static inline u16 get_unaligned_be16(const void *p)
77123+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77124 {
77125- return be16_to_cpup((__be16 *)p);
77126+ return be16_to_cpup((const __be16 *)p);
77127 }
77128
77129-static inline u32 get_unaligned_be32(const void *p)
77130+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77131 {
77132- return be32_to_cpup((__be32 *)p);
77133+ return be32_to_cpup((const __be32 *)p);
77134 }
77135
77136-static inline u64 get_unaligned_be64(const void *p)
77137+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77138 {
77139- return be64_to_cpup((__be64 *)p);
77140+ return be64_to_cpup((const __be64 *)p);
77141 }
77142
77143 static inline void put_unaligned_le16(u16 val, void *p)
77144diff --git a/include/linux/usb.h b/include/linux/usb.h
77145index 0eec268..4496526 100644
77146--- a/include/linux/usb.h
77147+++ b/include/linux/usb.h
77148@@ -560,7 +560,7 @@ struct usb_device {
77149 int maxchild;
77150
77151 u32 quirks;
77152- atomic_t urbnum;
77153+ atomic_unchecked_t urbnum;
77154
77155 unsigned long active_duration;
77156
77157@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77158
77159 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77160 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77161- void *data, __u16 size, int timeout);
77162+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77163 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77164 void *data, int len, int *actual_length, int timeout);
77165 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77166diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77167index e452ba6..78f8e80 100644
77168--- a/include/linux/usb/renesas_usbhs.h
77169+++ b/include/linux/usb/renesas_usbhs.h
77170@@ -39,7 +39,7 @@ enum {
77171 */
77172 struct renesas_usbhs_driver_callback {
77173 int (*notify_hotplug)(struct platform_device *pdev);
77174-};
77175+} __no_const;
77176
77177 /*
77178 * callback functions for platform
77179diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77180index 6f8fbcf..8259001 100644
77181--- a/include/linux/vermagic.h
77182+++ b/include/linux/vermagic.h
77183@@ -25,9 +25,35 @@
77184 #define MODULE_ARCH_VERMAGIC ""
77185 #endif
77186
77187+#ifdef CONFIG_PAX_REFCOUNT
77188+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77189+#else
77190+#define MODULE_PAX_REFCOUNT ""
77191+#endif
77192+
77193+#ifdef CONSTIFY_PLUGIN
77194+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77195+#else
77196+#define MODULE_CONSTIFY_PLUGIN ""
77197+#endif
77198+
77199+#ifdef STACKLEAK_PLUGIN
77200+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77201+#else
77202+#define MODULE_STACKLEAK_PLUGIN ""
77203+#endif
77204+
77205+#ifdef CONFIG_GRKERNSEC
77206+#define MODULE_GRSEC "GRSEC "
77207+#else
77208+#define MODULE_GRSEC ""
77209+#endif
77210+
77211 #define VERMAGIC_STRING \
77212 UTS_RELEASE " " \
77213 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77214 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77215- MODULE_ARCH_VERMAGIC
77216+ MODULE_ARCH_VERMAGIC \
77217+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77218+ MODULE_GRSEC
77219
77220diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77221index 4b8a891..c20e936 100644
77222--- a/include/linux/vmalloc.h
77223+++ b/include/linux/vmalloc.h
77224@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77225 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77226 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77227 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77228+
77229+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77230+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77231+#endif
77232+
77233 /* bits [20..32] reserved for arch specific ioremap internals */
77234
77235 /*
77236@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77237 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77238 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77239 unsigned long start, unsigned long end, gfp_t gfp_mask,
77240- pgprot_t prot, int node, const void *caller);
77241+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77242 extern void vfree(const void *addr);
77243
77244 extern void *vmap(struct page **pages, unsigned int count,
77245@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77246 extern void free_vm_area(struct vm_struct *area);
77247
77248 /* for /dev/kmem */
77249-extern long vread(char *buf, char *addr, unsigned long count);
77250-extern long vwrite(char *buf, char *addr, unsigned long count);
77251+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77252+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77253
77254 /*
77255 * Internals. Dont't use..
77256diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77257index c586679..f06b389 100644
77258--- a/include/linux/vmstat.h
77259+++ b/include/linux/vmstat.h
77260@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77261 /*
77262 * Zone based page accounting with per cpu differentials.
77263 */
77264-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77265+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77266
77267 static inline void zone_page_state_add(long x, struct zone *zone,
77268 enum zone_stat_item item)
77269 {
77270- atomic_long_add(x, &zone->vm_stat[item]);
77271- atomic_long_add(x, &vm_stat[item]);
77272+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77273+ atomic_long_add_unchecked(x, &vm_stat[item]);
77274 }
77275
77276 static inline unsigned long global_page_state(enum zone_stat_item item)
77277 {
77278- long x = atomic_long_read(&vm_stat[item]);
77279+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77280 #ifdef CONFIG_SMP
77281 if (x < 0)
77282 x = 0;
77283@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77284 static inline unsigned long zone_page_state(struct zone *zone,
77285 enum zone_stat_item item)
77286 {
77287- long x = atomic_long_read(&zone->vm_stat[item]);
77288+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77289 #ifdef CONFIG_SMP
77290 if (x < 0)
77291 x = 0;
77292@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77293 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77294 enum zone_stat_item item)
77295 {
77296- long x = atomic_long_read(&zone->vm_stat[item]);
77297+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77298
77299 #ifdef CONFIG_SMP
77300 int cpu;
77301@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77302
77303 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77304 {
77305- atomic_long_inc(&zone->vm_stat[item]);
77306- atomic_long_inc(&vm_stat[item]);
77307+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77308+ atomic_long_inc_unchecked(&vm_stat[item]);
77309 }
77310
77311 static inline void __inc_zone_page_state(struct page *page,
77312@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77313
77314 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77315 {
77316- atomic_long_dec(&zone->vm_stat[item]);
77317- atomic_long_dec(&vm_stat[item]);
77318+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77319+ atomic_long_dec_unchecked(&vm_stat[item]);
77320 }
77321
77322 static inline void __dec_zone_page_state(struct page *page,
77323diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77324index fdbafc6..49dfe4f 100644
77325--- a/include/linux/xattr.h
77326+++ b/include/linux/xattr.h
77327@@ -28,7 +28,7 @@ struct xattr_handler {
77328 size_t size, int handler_flags);
77329 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77330 size_t size, int flags, int handler_flags);
77331-};
77332+} __do_const;
77333
77334 struct xattr {
77335 char *name;
77336@@ -37,6 +37,9 @@ struct xattr {
77337 };
77338
77339 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77340+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77341+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77342+#endif
77343 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77344 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77345 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77346diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77347index 9c5a6b4..09c9438 100644
77348--- a/include/linux/zlib.h
77349+++ b/include/linux/zlib.h
77350@@ -31,6 +31,7 @@
77351 #define _ZLIB_H
77352
77353 #include <linux/zconf.h>
77354+#include <linux/compiler.h>
77355
77356 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77357 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77358@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77359
77360 /* basic functions */
77361
77362-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77363+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77364 /*
77365 Returns the number of bytes that needs to be allocated for a per-
77366 stream workspace with the specified parameters. A pointer to this
77367diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77368index c768c9f..bdcaa5a 100644
77369--- a/include/media/v4l2-dev.h
77370+++ b/include/media/v4l2-dev.h
77371@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77372 int (*mmap) (struct file *, struct vm_area_struct *);
77373 int (*open) (struct file *);
77374 int (*release) (struct file *);
77375-};
77376+} __do_const;
77377
77378 /*
77379 * Newer version of video_device, handled by videodev2.c
77380diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77381index c9b1593..a572459 100644
77382--- a/include/media/v4l2-device.h
77383+++ b/include/media/v4l2-device.h
77384@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77385 this function returns 0. If the name ends with a digit (e.g. cx18),
77386 then the name will be set to cx18-0 since cx180 looks really odd. */
77387 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77388- atomic_t *instance);
77389+ atomic_unchecked_t *instance);
77390
77391 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77392 Since the parent disappears this ensures that v4l2_dev doesn't have an
77393diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77394index d9fa68f..45c88d1 100644
77395--- a/include/net/9p/transport.h
77396+++ b/include/net/9p/transport.h
77397@@ -63,7 +63,7 @@ struct p9_trans_module {
77398 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77399 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77400 char *, char *, int , int, int, int);
77401-};
77402+} __do_const;
77403
77404 void v9fs_register_trans(struct p9_trans_module *m);
77405 void v9fs_unregister_trans(struct p9_trans_module *m);
77406diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77407index 1a966af..2767cf6 100644
77408--- a/include/net/bluetooth/l2cap.h
77409+++ b/include/net/bluetooth/l2cap.h
77410@@ -551,7 +551,7 @@ struct l2cap_ops {
77411 void (*defer) (struct l2cap_chan *chan);
77412 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77413 unsigned long len, int nb);
77414-};
77415+} __do_const;
77416
77417 struct l2cap_conn {
77418 struct hci_conn *hcon;
77419diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77420index f2ae33d..c457cf0 100644
77421--- a/include/net/caif/cfctrl.h
77422+++ b/include/net/caif/cfctrl.h
77423@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77424 void (*radioset_rsp)(void);
77425 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77426 struct cflayer *client_layer);
77427-};
77428+} __no_const;
77429
77430 /* Link Setup Parameters for CAIF-Links. */
77431 struct cfctrl_link_param {
77432@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77433 struct cfctrl {
77434 struct cfsrvl serv;
77435 struct cfctrl_rsp res;
77436- atomic_t req_seq_no;
77437- atomic_t rsp_seq_no;
77438+ atomic_unchecked_t req_seq_no;
77439+ atomic_unchecked_t rsp_seq_no;
77440 struct list_head list;
77441 /* Protects from simultaneous access to first_req list */
77442 spinlock_t info_list_lock;
77443diff --git a/include/net/flow.h b/include/net/flow.h
77444index 628e11b..4c475df 100644
77445--- a/include/net/flow.h
77446+++ b/include/net/flow.h
77447@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77448
77449 extern void flow_cache_flush(void);
77450 extern void flow_cache_flush_deferred(void);
77451-extern atomic_t flow_cache_genid;
77452+extern atomic_unchecked_t flow_cache_genid;
77453
77454 #endif
77455diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77456index 8e0b6c8..73cf605 100644
77457--- a/include/net/genetlink.h
77458+++ b/include/net/genetlink.h
77459@@ -120,7 +120,7 @@ struct genl_ops {
77460 struct netlink_callback *cb);
77461 int (*done)(struct netlink_callback *cb);
77462 struct list_head ops_list;
77463-};
77464+} __do_const;
77465
77466 extern int __genl_register_family(struct genl_family *family);
77467
77468diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77469index 734d9b5..48a9a4b 100644
77470--- a/include/net/gro_cells.h
77471+++ b/include/net/gro_cells.h
77472@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77473 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77474
77475 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77476- atomic_long_inc(&dev->rx_dropped);
77477+ atomic_long_inc_unchecked(&dev->rx_dropped);
77478 kfree_skb(skb);
77479 return;
77480 }
77481diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77482index de2c785..0588a6b 100644
77483--- a/include/net/inet_connection_sock.h
77484+++ b/include/net/inet_connection_sock.h
77485@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77486 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77487 int (*bind_conflict)(const struct sock *sk,
77488 const struct inet_bind_bucket *tb, bool relax);
77489-};
77490+} __do_const;
77491
77492 /** inet_connection_sock - INET connection oriented sock
77493 *
77494diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77495index 53f464d..0bd0b49 100644
77496--- a/include/net/inetpeer.h
77497+++ b/include/net/inetpeer.h
77498@@ -47,8 +47,8 @@ struct inet_peer {
77499 */
77500 union {
77501 struct {
77502- atomic_t rid; /* Frag reception counter */
77503- atomic_t ip_id_count; /* IP ID for the next packet */
77504+ atomic_unchecked_t rid; /* Frag reception counter */
77505+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77506 };
77507 struct rcu_head rcu;
77508 struct inet_peer *gc_next;
77509@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77510 /* can be called with or without local BH being disabled */
77511 static inline int inet_getid(struct inet_peer *p, int more)
77512 {
77513- int old, new;
77514+ int id;
77515 more++;
77516 inet_peer_refcheck(p);
77517- do {
77518- old = atomic_read(&p->ip_id_count);
77519- new = old + more;
77520- if (!new)
77521- new = 1;
77522- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77523- return new;
77524+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77525+ if (!id)
77526+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77527+ return id;
77528 }
77529
77530 #endif /* _NET_INETPEER_H */
77531diff --git a/include/net/ip.h b/include/net/ip.h
77532index edfa591..a643b82 100644
77533--- a/include/net/ip.h
77534+++ b/include/net/ip.h
77535@@ -202,7 +202,7 @@ extern struct local_ports {
77536 } sysctl_local_ports;
77537 extern void inet_get_local_port_range(int *low, int *high);
77538
77539-extern unsigned long *sysctl_local_reserved_ports;
77540+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77541 static inline int inet_is_reserved_local_port(int port)
77542 {
77543 return test_bit(port, sysctl_local_reserved_ports);
77544diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77545index cbf2be3..3683f6d 100644
77546--- a/include/net/ip_fib.h
77547+++ b/include/net/ip_fib.h
77548@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77549
77550 #define FIB_RES_SADDR(net, res) \
77551 ((FIB_RES_NH(res).nh_saddr_genid == \
77552- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77553+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77554 FIB_RES_NH(res).nh_saddr : \
77555 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77556 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77557diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77558index f0d70f0..185f15b 100644
77559--- a/include/net/ip_vs.h
77560+++ b/include/net/ip_vs.h
77561@@ -588,7 +588,7 @@ struct ip_vs_conn {
77562 struct ip_vs_conn *control; /* Master control connection */
77563 atomic_t n_control; /* Number of controlled ones */
77564 struct ip_vs_dest *dest; /* real server */
77565- atomic_t in_pkts; /* incoming packet counter */
77566+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77567
77568 /* packet transmitter for different forwarding methods. If it
77569 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77570@@ -737,7 +737,7 @@ struct ip_vs_dest {
77571 __be16 port; /* port number of the server */
77572 union nf_inet_addr addr; /* IP address of the server */
77573 volatile unsigned int flags; /* dest status flags */
77574- atomic_t conn_flags; /* flags to copy to conn */
77575+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77576 atomic_t weight; /* server weight */
77577
77578 atomic_t refcnt; /* reference counter */
77579@@ -993,11 +993,11 @@ struct netns_ipvs {
77580 /* ip_vs_lblc */
77581 int sysctl_lblc_expiration;
77582 struct ctl_table_header *lblc_ctl_header;
77583- struct ctl_table *lblc_ctl_table;
77584+ ctl_table_no_const *lblc_ctl_table;
77585 /* ip_vs_lblcr */
77586 int sysctl_lblcr_expiration;
77587 struct ctl_table_header *lblcr_ctl_header;
77588- struct ctl_table *lblcr_ctl_table;
77589+ ctl_table_no_const *lblcr_ctl_table;
77590 /* ip_vs_est */
77591 struct list_head est_list; /* estimator list */
77592 spinlock_t est_lock;
77593diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77594index 80ffde3..968b0f4 100644
77595--- a/include/net/irda/ircomm_tty.h
77596+++ b/include/net/irda/ircomm_tty.h
77597@@ -35,6 +35,7 @@
77598 #include <linux/termios.h>
77599 #include <linux/timer.h>
77600 #include <linux/tty.h> /* struct tty_struct */
77601+#include <asm/local.h>
77602
77603 #include <net/irda/irias_object.h>
77604 #include <net/irda/ircomm_core.h>
77605diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77606index 714cc9a..ea05f3e 100644
77607--- a/include/net/iucv/af_iucv.h
77608+++ b/include/net/iucv/af_iucv.h
77609@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77610 struct iucv_sock_list {
77611 struct hlist_head head;
77612 rwlock_t lock;
77613- atomic_t autobind_name;
77614+ atomic_unchecked_t autobind_name;
77615 };
77616
77617 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77618diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77619index df83f69..9b640b8 100644
77620--- a/include/net/llc_c_ac.h
77621+++ b/include/net/llc_c_ac.h
77622@@ -87,7 +87,7 @@
77623 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77624 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77625
77626-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77627+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77628
77629 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77630 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77631diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77632index 6ca3113..f8026dd 100644
77633--- a/include/net/llc_c_ev.h
77634+++ b/include/net/llc_c_ev.h
77635@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77636 return (struct llc_conn_state_ev *)skb->cb;
77637 }
77638
77639-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77640-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77641+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77642+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77643
77644 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77645 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77646diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77647index 0e79cfb..f46db31 100644
77648--- a/include/net/llc_c_st.h
77649+++ b/include/net/llc_c_st.h
77650@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77651 u8 next_state;
77652 llc_conn_ev_qfyr_t *ev_qualifiers;
77653 llc_conn_action_t *ev_actions;
77654-};
77655+} __do_const;
77656
77657 struct llc_conn_state {
77658 u8 current_state;
77659diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77660index 37a3bbd..55a4241 100644
77661--- a/include/net/llc_s_ac.h
77662+++ b/include/net/llc_s_ac.h
77663@@ -23,7 +23,7 @@
77664 #define SAP_ACT_TEST_IND 9
77665
77666 /* All action functions must look like this */
77667-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77668+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77669
77670 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77671 struct sk_buff *skb);
77672diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77673index 567c681..cd73ac0 100644
77674--- a/include/net/llc_s_st.h
77675+++ b/include/net/llc_s_st.h
77676@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77677 llc_sap_ev_t ev;
77678 u8 next_state;
77679 llc_sap_action_t *ev_actions;
77680-};
77681+} __do_const;
77682
77683 struct llc_sap_state {
77684 u8 curr_state;
77685diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77686index 551ba6a..11c99c1 100644
77687--- a/include/net/mac80211.h
77688+++ b/include/net/mac80211.h
77689@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77690 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77691 struct dentry *dir);
77692 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77693-};
77694+} __do_const;
77695
77696 static inline int rate_supported(struct ieee80211_sta *sta,
77697 enum ieee80211_band band,
77698diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77699index 7e748ad..5c6229b 100644
77700--- a/include/net/neighbour.h
77701+++ b/include/net/neighbour.h
77702@@ -123,7 +123,7 @@ struct neigh_ops {
77703 void (*error_report)(struct neighbour *, struct sk_buff *);
77704 int (*output)(struct neighbour *, struct sk_buff *);
77705 int (*connected_output)(struct neighbour *, struct sk_buff *);
77706-};
77707+} __do_const;
77708
77709 struct pneigh_entry {
77710 struct pneigh_entry *next;
77711diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77712index 84e37b1..8eba19a 100644
77713--- a/include/net/net_namespace.h
77714+++ b/include/net/net_namespace.h
77715@@ -119,8 +119,8 @@ struct net {
77716 struct netns_ipvs *ipvs;
77717 #endif
77718 struct sock *diag_nlsk;
77719- atomic_t rt_genid;
77720- atomic_t fnhe_genid;
77721+ atomic_unchecked_t rt_genid;
77722+ atomic_unchecked_t fnhe_genid;
77723 };
77724
77725 /*
77726@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77727 #define __net_init __init
77728 #define __net_exit __exit_refok
77729 #define __net_initdata __initdata
77730+#ifdef CONSTIFY_PLUGIN
77731 #define __net_initconst __initconst
77732+#else
77733+#define __net_initconst __initdata
77734+#endif
77735 #endif
77736
77737 struct pernet_operations {
77738@@ -287,7 +291,7 @@ struct pernet_operations {
77739 void (*exit_batch)(struct list_head *net_exit_list);
77740 int *id;
77741 size_t size;
77742-};
77743+} __do_const;
77744
77745 /*
77746 * Use these carefully. If you implement a network device and it
77747@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77748
77749 static inline int rt_genid(struct net *net)
77750 {
77751- return atomic_read(&net->rt_genid);
77752+ return atomic_read_unchecked(&net->rt_genid);
77753 }
77754
77755 static inline void rt_genid_bump(struct net *net)
77756 {
77757- atomic_inc(&net->rt_genid);
77758+ atomic_inc_unchecked(&net->rt_genid);
77759 }
77760
77761 static inline int fnhe_genid(struct net *net)
77762 {
77763- return atomic_read(&net->fnhe_genid);
77764+ return atomic_read_unchecked(&net->fnhe_genid);
77765 }
77766
77767 static inline void fnhe_genid_bump(struct net *net)
77768 {
77769- atomic_inc(&net->fnhe_genid);
77770+ atomic_inc_unchecked(&net->fnhe_genid);
77771 }
77772
77773 #endif /* __NET_NET_NAMESPACE_H */
77774diff --git a/include/net/netdma.h b/include/net/netdma.h
77775index 8ba8ce2..99b7fff 100644
77776--- a/include/net/netdma.h
77777+++ b/include/net/netdma.h
77778@@ -24,7 +24,7 @@
77779 #include <linux/dmaengine.h>
77780 #include <linux/skbuff.h>
77781
77782-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77783+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77784 struct sk_buff *skb, int offset, struct iovec *to,
77785 size_t len, struct dma_pinned_list *pinned_list);
77786
77787diff --git a/include/net/netlink.h b/include/net/netlink.h
77788index 9690b0f..87aded7 100644
77789--- a/include/net/netlink.h
77790+++ b/include/net/netlink.h
77791@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77792 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77793 {
77794 if (mark)
77795- skb_trim(skb, (unsigned char *) mark - skb->data);
77796+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77797 }
77798
77799 /**
77800diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77801index c9c0c53..53f24c3 100644
77802--- a/include/net/netns/conntrack.h
77803+++ b/include/net/netns/conntrack.h
77804@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77805 struct nf_proto_net {
77806 #ifdef CONFIG_SYSCTL
77807 struct ctl_table_header *ctl_table_header;
77808- struct ctl_table *ctl_table;
77809+ ctl_table_no_const *ctl_table;
77810 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77811 struct ctl_table_header *ctl_compat_header;
77812- struct ctl_table *ctl_compat_table;
77813+ ctl_table_no_const *ctl_compat_table;
77814 #endif
77815 #endif
77816 unsigned int users;
77817@@ -58,7 +58,7 @@ struct nf_ip_net {
77818 struct nf_icmp_net icmpv6;
77819 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77820 struct ctl_table_header *ctl_table_header;
77821- struct ctl_table *ctl_table;
77822+ ctl_table_no_const *ctl_table;
77823 #endif
77824 };
77825
77826diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77827index 2ba9de8..47bd6c7 100644
77828--- a/include/net/netns/ipv4.h
77829+++ b/include/net/netns/ipv4.h
77830@@ -67,7 +67,7 @@ struct netns_ipv4 {
77831 kgid_t sysctl_ping_group_range[2];
77832 long sysctl_tcp_mem[3];
77833
77834- atomic_t dev_addr_genid;
77835+ atomic_unchecked_t dev_addr_genid;
77836
77837 #ifdef CONFIG_IP_MROUTE
77838 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77839diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77840index 005e2c2..023d340 100644
77841--- a/include/net/netns/ipv6.h
77842+++ b/include/net/netns/ipv6.h
77843@@ -71,7 +71,7 @@ struct netns_ipv6 {
77844 struct fib_rules_ops *mr6_rules_ops;
77845 #endif
77846 #endif
77847- atomic_t dev_addr_genid;
77848+ atomic_unchecked_t dev_addr_genid;
77849 };
77850
77851 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77852diff --git a/include/net/ping.h b/include/net/ping.h
77853index 5db0224..0d65365 100644
77854--- a/include/net/ping.h
77855+++ b/include/net/ping.h
77856@@ -55,7 +55,7 @@ struct ping_iter_state {
77857 extern struct proto ping_prot;
77858 extern struct ping_table ping_table;
77859 #if IS_ENABLED(CONFIG_IPV6)
77860-extern struct pingv6_ops pingv6_ops;
77861+extern struct pingv6_ops *pingv6_ops;
77862 #endif
77863
77864 struct pingfakehdr {
77865diff --git a/include/net/protocol.h b/include/net/protocol.h
77866index 047c047..b9dad15 100644
77867--- a/include/net/protocol.h
77868+++ b/include/net/protocol.h
77869@@ -44,7 +44,7 @@ struct net_protocol {
77870 void (*err_handler)(struct sk_buff *skb, u32 info);
77871 unsigned int no_policy:1,
77872 netns_ok:1;
77873-};
77874+} __do_const;
77875
77876 #if IS_ENABLED(CONFIG_IPV6)
77877 struct inet6_protocol {
77878@@ -57,7 +57,7 @@ struct inet6_protocol {
77879 u8 type, u8 code, int offset,
77880 __be32 info);
77881 unsigned int flags; /* INET6_PROTO_xxx */
77882-};
77883+} __do_const;
77884
77885 #define INET6_PROTO_NOPOLICY 0x1
77886 #define INET6_PROTO_FINAL 0x2
77887diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
77888index 7026648..584cc8c 100644
77889--- a/include/net/rtnetlink.h
77890+++ b/include/net/rtnetlink.h
77891@@ -81,7 +81,7 @@ struct rtnl_link_ops {
77892 const struct net_device *dev);
77893 unsigned int (*get_num_tx_queues)(void);
77894 unsigned int (*get_num_rx_queues)(void);
77895-};
77896+} __do_const;
77897
77898 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
77899 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
77900diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
77901index 2a82d13..62a31c2 100644
77902--- a/include/net/sctp/sm.h
77903+++ b/include/net/sctp/sm.h
77904@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
77905 typedef struct {
77906 sctp_state_fn_t *fn;
77907 const char *name;
77908-} sctp_sm_table_entry_t;
77909+} __do_const sctp_sm_table_entry_t;
77910
77911 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
77912 * currently in use.
77913@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
77914 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
77915
77916 /* Extern declarations for major data structures. */
77917-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77918+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77919
77920
77921 /* Get the size of a DATA chunk payload. */
77922diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
77923index e745c92..3641448 100644
77924--- a/include/net/sctp/structs.h
77925+++ b/include/net/sctp/structs.h
77926@@ -516,7 +516,7 @@ struct sctp_pf {
77927 struct sctp_association *asoc);
77928 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
77929 struct sctp_af *af;
77930-};
77931+} __do_const;
77932
77933
77934 /* Structure to track chunk fragments that have been acked, but peer
77935diff --git a/include/net/sock.h b/include/net/sock.h
77936index 31d5cfb..9ee0602 100644
77937--- a/include/net/sock.h
77938+++ b/include/net/sock.h
77939@@ -331,7 +331,7 @@ struct sock {
77940 unsigned int sk_napi_id;
77941 unsigned int sk_ll_usec;
77942 #endif
77943- atomic_t sk_drops;
77944+ atomic_unchecked_t sk_drops;
77945 int sk_rcvbuf;
77946
77947 struct sk_filter __rcu *sk_filter;
77948@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
77949 }
77950
77951 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
77952- char __user *from, char *to,
77953+ char __user *from, unsigned char *to,
77954 int copy, int offset)
77955 {
77956 if (skb->ip_summed == CHECKSUM_NONE) {
77957@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
77958 }
77959 }
77960
77961-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
77962+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
77963
77964 /**
77965 * sk_page_frag - return an appropriate page_frag
77966diff --git a/include/net/tcp.h b/include/net/tcp.h
77967index d198005..c974a393 100644
77968--- a/include/net/tcp.h
77969+++ b/include/net/tcp.h
77970@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
77971 extern void tcp_xmit_retransmit_queue(struct sock *);
77972 extern void tcp_simple_retransmit(struct sock *);
77973 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
77974-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
77975+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
77976
77977 extern void tcp_send_probe0(struct sock *);
77978 extern void tcp_send_partial(struct sock *);
77979@@ -694,8 +694,8 @@ struct tcp_skb_cb {
77980 struct inet6_skb_parm h6;
77981 #endif
77982 } header; /* For incoming frames */
77983- __u32 seq; /* Starting sequence number */
77984- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
77985+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
77986+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
77987 __u32 when; /* used to compute rtt's */
77988 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
77989
77990@@ -709,7 +709,7 @@ struct tcp_skb_cb {
77991
77992 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
77993 /* 1 byte hole */
77994- __u32 ack_seq; /* Sequence number ACK'd */
77995+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
77996 };
77997
77998 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
77999diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78000index e823786..53b0608 100644
78001--- a/include/net/xfrm.h
78002+++ b/include/net/xfrm.h
78003@@ -287,7 +287,6 @@ struct xfrm_dst;
78004 struct xfrm_policy_afinfo {
78005 unsigned short family;
78006 struct dst_ops *dst_ops;
78007- void (*garbage_collect)(struct net *net);
78008 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78009 const xfrm_address_t *saddr,
78010 const xfrm_address_t *daddr);
78011@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78012 struct net_device *dev,
78013 const struct flowi *fl);
78014 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78015-};
78016+} __do_const;
78017
78018 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78019 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78020@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78021 int (*transport_finish)(struct sk_buff *skb,
78022 int async);
78023 void (*local_error)(struct sk_buff *skb, u32 mtu);
78024-};
78025+} __do_const;
78026
78027 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78028 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78029@@ -427,7 +426,7 @@ struct xfrm_mode {
78030 struct module *owner;
78031 unsigned int encap;
78032 int flags;
78033-};
78034+} __do_const;
78035
78036 /* Flags for xfrm_mode. */
78037 enum {
78038@@ -524,7 +523,7 @@ struct xfrm_policy {
78039 struct timer_list timer;
78040
78041 struct flow_cache_object flo;
78042- atomic_t genid;
78043+ atomic_unchecked_t genid;
78044 u32 priority;
78045 u32 index;
78046 struct xfrm_mark mark;
78047@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78048 }
78049
78050 extern void xfrm_garbage_collect(struct net *net);
78051+extern void xfrm_garbage_collect_deferred(struct net *net);
78052
78053 #else
78054
78055@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78056 static inline void xfrm_garbage_collect(struct net *net)
78057 {
78058 }
78059+static inline void xfrm_garbage_collect_deferred(struct net *net)
78060+{
78061+}
78062 #endif
78063
78064 static __inline__
78065diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78066index 1a046b1..ee0bef0 100644
78067--- a/include/rdma/iw_cm.h
78068+++ b/include/rdma/iw_cm.h
78069@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78070 int backlog);
78071
78072 int (*destroy_listen)(struct iw_cm_id *cm_id);
78073-};
78074+} __no_const;
78075
78076 /**
78077 * iw_create_cm_id - Create an IW CM identifier.
78078diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78079index e1379b4..67eafbe 100644
78080--- a/include/scsi/libfc.h
78081+++ b/include/scsi/libfc.h
78082@@ -762,6 +762,7 @@ struct libfc_function_template {
78083 */
78084 void (*disc_stop_final) (struct fc_lport *);
78085 };
78086+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78087
78088 /**
78089 * struct fc_disc - Discovery context
78090@@ -866,7 +867,7 @@ struct fc_lport {
78091 struct fc_vport *vport;
78092
78093 /* Operational Information */
78094- struct libfc_function_template tt;
78095+ libfc_function_template_no_const tt;
78096 u8 link_up;
78097 u8 qfull;
78098 enum fc_lport_state state;
78099diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78100index a44954c..5da04b2 100644
78101--- a/include/scsi/scsi_device.h
78102+++ b/include/scsi/scsi_device.h
78103@@ -172,9 +172,9 @@ struct scsi_device {
78104 unsigned int max_device_blocked; /* what device_blocked counts down from */
78105 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78106
78107- atomic_t iorequest_cnt;
78108- atomic_t iodone_cnt;
78109- atomic_t ioerr_cnt;
78110+ atomic_unchecked_t iorequest_cnt;
78111+ atomic_unchecked_t iodone_cnt;
78112+ atomic_unchecked_t ioerr_cnt;
78113
78114 struct device sdev_gendev,
78115 sdev_dev;
78116diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78117index b797e8f..8e2c3aa 100644
78118--- a/include/scsi/scsi_transport_fc.h
78119+++ b/include/scsi/scsi_transport_fc.h
78120@@ -751,7 +751,8 @@ struct fc_function_template {
78121 unsigned long show_host_system_hostname:1;
78122
78123 unsigned long disable_target_scan:1;
78124-};
78125+} __do_const;
78126+typedef struct fc_function_template __no_const fc_function_template_no_const;
78127
78128
78129 /**
78130diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78131index 9031a26..750d592 100644
78132--- a/include/sound/compress_driver.h
78133+++ b/include/sound/compress_driver.h
78134@@ -128,7 +128,7 @@ struct snd_compr_ops {
78135 struct snd_compr_caps *caps);
78136 int (*get_codec_caps) (struct snd_compr_stream *stream,
78137 struct snd_compr_codec_caps *codec);
78138-};
78139+} __no_const;
78140
78141 /**
78142 * struct snd_compr: Compressed device
78143diff --git a/include/sound/soc.h b/include/sound/soc.h
78144index 6eabee7..58afb50 100644
78145--- a/include/sound/soc.h
78146+++ b/include/sound/soc.h
78147@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78148 /* probe ordering - for components with runtime dependencies */
78149 int probe_order;
78150 int remove_order;
78151-};
78152+} __do_const;
78153
78154 /* SoC platform interface */
78155 struct snd_soc_platform_driver {
78156@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78157 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78158 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78159 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78160-};
78161+} __do_const;
78162
78163 struct snd_soc_platform {
78164 const char *name;
78165diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78166index e34fc90..ecefa2c 100644
78167--- a/include/target/target_core_base.h
78168+++ b/include/target/target_core_base.h
78169@@ -643,7 +643,7 @@ struct se_device {
78170 spinlock_t stats_lock;
78171 /* Active commands on this virtual SE device */
78172 atomic_t simple_cmds;
78173- atomic_t dev_ordered_id;
78174+ atomic_unchecked_t dev_ordered_id;
78175 atomic_t dev_ordered_sync;
78176 atomic_t dev_qf_count;
78177 int export_count;
78178diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78179new file mode 100644
78180index 0000000..fb634b7
78181--- /dev/null
78182+++ b/include/trace/events/fs.h
78183@@ -0,0 +1,53 @@
78184+#undef TRACE_SYSTEM
78185+#define TRACE_SYSTEM fs
78186+
78187+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78188+#define _TRACE_FS_H
78189+
78190+#include <linux/fs.h>
78191+#include <linux/tracepoint.h>
78192+
78193+TRACE_EVENT(do_sys_open,
78194+
78195+ TP_PROTO(const char *filename, int flags, int mode),
78196+
78197+ TP_ARGS(filename, flags, mode),
78198+
78199+ TP_STRUCT__entry(
78200+ __string( filename, filename )
78201+ __field( int, flags )
78202+ __field( int, mode )
78203+ ),
78204+
78205+ TP_fast_assign(
78206+ __assign_str(filename, filename);
78207+ __entry->flags = flags;
78208+ __entry->mode = mode;
78209+ ),
78210+
78211+ TP_printk("\"%s\" %x %o",
78212+ __get_str(filename), __entry->flags, __entry->mode)
78213+);
78214+
78215+TRACE_EVENT(open_exec,
78216+
78217+ TP_PROTO(const char *filename),
78218+
78219+ TP_ARGS(filename),
78220+
78221+ TP_STRUCT__entry(
78222+ __string( filename, filename )
78223+ ),
78224+
78225+ TP_fast_assign(
78226+ __assign_str(filename, filename);
78227+ ),
78228+
78229+ TP_printk("\"%s\"",
78230+ __get_str(filename))
78231+);
78232+
78233+#endif /* _TRACE_FS_H */
78234+
78235+/* This part must be outside protection */
78236+#include <trace/define_trace.h>
78237diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78238index 1c09820..7f5ec79 100644
78239--- a/include/trace/events/irq.h
78240+++ b/include/trace/events/irq.h
78241@@ -36,7 +36,7 @@ struct softirq_action;
78242 */
78243 TRACE_EVENT(irq_handler_entry,
78244
78245- TP_PROTO(int irq, struct irqaction *action),
78246+ TP_PROTO(int irq, const struct irqaction *action),
78247
78248 TP_ARGS(irq, action),
78249
78250@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78251 */
78252 TRACE_EVENT(irq_handler_exit,
78253
78254- TP_PROTO(int irq, struct irqaction *action, int ret),
78255+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78256
78257 TP_ARGS(irq, action, ret),
78258
78259diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78260index 7caf44c..23c6f27 100644
78261--- a/include/uapi/linux/a.out.h
78262+++ b/include/uapi/linux/a.out.h
78263@@ -39,6 +39,14 @@ enum machine_type {
78264 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78265 };
78266
78267+/* Constants for the N_FLAGS field */
78268+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78269+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78270+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78271+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78272+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78273+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78274+
78275 #if !defined (N_MAGIC)
78276 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78277 #endif
78278diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78279index d876736..ccce5c0 100644
78280--- a/include/uapi/linux/byteorder/little_endian.h
78281+++ b/include/uapi/linux/byteorder/little_endian.h
78282@@ -42,51 +42,51 @@
78283
78284 static inline __le64 __cpu_to_le64p(const __u64 *p)
78285 {
78286- return (__force __le64)*p;
78287+ return (__force const __le64)*p;
78288 }
78289-static inline __u64 __le64_to_cpup(const __le64 *p)
78290+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78291 {
78292- return (__force __u64)*p;
78293+ return (__force const __u64)*p;
78294 }
78295 static inline __le32 __cpu_to_le32p(const __u32 *p)
78296 {
78297- return (__force __le32)*p;
78298+ return (__force const __le32)*p;
78299 }
78300 static inline __u32 __le32_to_cpup(const __le32 *p)
78301 {
78302- return (__force __u32)*p;
78303+ return (__force const __u32)*p;
78304 }
78305 static inline __le16 __cpu_to_le16p(const __u16 *p)
78306 {
78307- return (__force __le16)*p;
78308+ return (__force const __le16)*p;
78309 }
78310 static inline __u16 __le16_to_cpup(const __le16 *p)
78311 {
78312- return (__force __u16)*p;
78313+ return (__force const __u16)*p;
78314 }
78315 static inline __be64 __cpu_to_be64p(const __u64 *p)
78316 {
78317- return (__force __be64)__swab64p(p);
78318+ return (__force const __be64)__swab64p(p);
78319 }
78320 static inline __u64 __be64_to_cpup(const __be64 *p)
78321 {
78322- return __swab64p((__u64 *)p);
78323+ return __swab64p((const __u64 *)p);
78324 }
78325 static inline __be32 __cpu_to_be32p(const __u32 *p)
78326 {
78327- return (__force __be32)__swab32p(p);
78328+ return (__force const __be32)__swab32p(p);
78329 }
78330-static inline __u32 __be32_to_cpup(const __be32 *p)
78331+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78332 {
78333- return __swab32p((__u32 *)p);
78334+ return __swab32p((const __u32 *)p);
78335 }
78336 static inline __be16 __cpu_to_be16p(const __u16 *p)
78337 {
78338- return (__force __be16)__swab16p(p);
78339+ return (__force const __be16)__swab16p(p);
78340 }
78341 static inline __u16 __be16_to_cpup(const __be16 *p)
78342 {
78343- return __swab16p((__u16 *)p);
78344+ return __swab16p((const __u16 *)p);
78345 }
78346 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78347 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78348diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78349index ef6103b..d4e65dd 100644
78350--- a/include/uapi/linux/elf.h
78351+++ b/include/uapi/linux/elf.h
78352@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78353 #define PT_GNU_EH_FRAME 0x6474e550
78354
78355 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78356+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78357+
78358+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78359+
78360+/* Constants for the e_flags field */
78361+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78362+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78363+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78364+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78365+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78366+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78367
78368 /*
78369 * Extended Numbering
78370@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78371 #define DT_DEBUG 21
78372 #define DT_TEXTREL 22
78373 #define DT_JMPREL 23
78374+#define DT_FLAGS 30
78375+ #define DF_TEXTREL 0x00000004
78376 #define DT_ENCODING 32
78377 #define OLD_DT_LOOS 0x60000000
78378 #define DT_LOOS 0x6000000d
78379@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78380 #define PF_W 0x2
78381 #define PF_X 0x1
78382
78383+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78384+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78385+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78386+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78387+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78388+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78389+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78390+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78391+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78392+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78393+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78394+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78395+
78396 typedef struct elf32_phdr{
78397 Elf32_Word p_type;
78398 Elf32_Off p_offset;
78399@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78400 #define EI_OSABI 7
78401 #define EI_PAD 8
78402
78403+#define EI_PAX 14
78404+
78405 #define ELFMAG0 0x7f /* EI_MAG */
78406 #define ELFMAG1 'E'
78407 #define ELFMAG2 'L'
78408diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78409index aa169c4..6a2771d 100644
78410--- a/include/uapi/linux/personality.h
78411+++ b/include/uapi/linux/personality.h
78412@@ -30,6 +30,7 @@ enum {
78413 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78414 ADDR_NO_RANDOMIZE | \
78415 ADDR_COMPAT_LAYOUT | \
78416+ ADDR_LIMIT_3GB | \
78417 MMAP_PAGE_ZERO)
78418
78419 /*
78420diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78421index 7530e74..e714828 100644
78422--- a/include/uapi/linux/screen_info.h
78423+++ b/include/uapi/linux/screen_info.h
78424@@ -43,7 +43,8 @@ struct screen_info {
78425 __u16 pages; /* 0x32 */
78426 __u16 vesa_attributes; /* 0x34 */
78427 __u32 capabilities; /* 0x36 */
78428- __u8 _reserved[6]; /* 0x3a */
78429+ __u16 vesapm_size; /* 0x3a */
78430+ __u8 _reserved[4]; /* 0x3c */
78431 } __attribute__((packed));
78432
78433 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78434diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78435index 0e011eb..82681b1 100644
78436--- a/include/uapi/linux/swab.h
78437+++ b/include/uapi/linux/swab.h
78438@@ -43,7 +43,7 @@
78439 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78440 */
78441
78442-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78443+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78444 {
78445 #ifdef __HAVE_BUILTIN_BSWAP16__
78446 return __builtin_bswap16(val);
78447@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78448 #endif
78449 }
78450
78451-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78452+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78453 {
78454 #ifdef __HAVE_BUILTIN_BSWAP32__
78455 return __builtin_bswap32(val);
78456@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78457 #endif
78458 }
78459
78460-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78461+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78462 {
78463 #ifdef __HAVE_BUILTIN_BSWAP64__
78464 return __builtin_bswap64(val);
78465diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78466index 6d67213..8dab561 100644
78467--- a/include/uapi/linux/sysctl.h
78468+++ b/include/uapi/linux/sysctl.h
78469@@ -155,7 +155,11 @@ enum
78470 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78471 };
78472
78473-
78474+#ifdef CONFIG_PAX_SOFTMODE
78475+enum {
78476+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78477+};
78478+#endif
78479
78480 /* CTL_VM names: */
78481 enum
78482diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78483index e4629b9..6958086 100644
78484--- a/include/uapi/linux/xattr.h
78485+++ b/include/uapi/linux/xattr.h
78486@@ -63,5 +63,9 @@
78487 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78488 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78489
78490+/* User namespace */
78491+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78492+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78493+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78494
78495 #endif /* _UAPI_LINUX_XATTR_H */
78496diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78497index f9466fa..f4e2b81 100644
78498--- a/include/video/udlfb.h
78499+++ b/include/video/udlfb.h
78500@@ -53,10 +53,10 @@ struct dlfb_data {
78501 u32 pseudo_palette[256];
78502 int blank_mode; /*one of FB_BLANK_ */
78503 /* blit-only rendering path metrics, exposed through sysfs */
78504- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78505- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78506- atomic_t bytes_sent; /* to usb, after compression including overhead */
78507- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78508+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78509+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78510+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78511+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78512 };
78513
78514 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78515diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78516index 30f5362..8ed8ac9 100644
78517--- a/include/video/uvesafb.h
78518+++ b/include/video/uvesafb.h
78519@@ -122,6 +122,7 @@ struct uvesafb_par {
78520 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78521 u8 pmi_setpal; /* PMI for palette changes */
78522 u16 *pmi_base; /* protected mode interface location */
78523+ u8 *pmi_code; /* protected mode code location */
78524 void *pmi_start;
78525 void *pmi_pal;
78526 u8 *vbe_state_orig; /*
78527diff --git a/init/Kconfig b/init/Kconfig
78528index fed81b5..0d3b964 100644
78529--- a/init/Kconfig
78530+++ b/init/Kconfig
78531@@ -1069,6 +1069,7 @@ endif # CGROUPS
78532
78533 config CHECKPOINT_RESTORE
78534 bool "Checkpoint/restore support" if EXPERT
78535+ depends on !GRKERNSEC
78536 default n
78537 help
78538 Enables additional kernel features in a sake of checkpoint/restore.
78539@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78540
78541 config COMPAT_BRK
78542 bool "Disable heap randomization"
78543- default y
78544+ default n
78545 help
78546 Randomizing heap placement makes heap exploits harder, but it
78547 also breaks ancient binaries (including anything libc5 based).
78548@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78549 config STOP_MACHINE
78550 bool
78551 default y
78552- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78553+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78554 help
78555 Need stop_machine() primitive.
78556
78557diff --git a/init/Makefile b/init/Makefile
78558index 7bc47ee..6da2dc7 100644
78559--- a/init/Makefile
78560+++ b/init/Makefile
78561@@ -2,6 +2,9 @@
78562 # Makefile for the linux kernel.
78563 #
78564
78565+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78566+asflags-y := $(GCC_PLUGINS_AFLAGS)
78567+
78568 obj-y := main.o version.o mounts.o
78569 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78570 obj-y += noinitramfs.o
78571diff --git a/init/do_mounts.c b/init/do_mounts.c
78572index 816014c..c2054db 100644
78573--- a/init/do_mounts.c
78574+++ b/init/do_mounts.c
78575@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78576 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78577 {
78578 struct super_block *s;
78579- int err = sys_mount(name, "/root", fs, flags, data);
78580+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78581 if (err)
78582 return err;
78583
78584- sys_chdir("/root");
78585+ sys_chdir((const char __force_user *)"/root");
78586 s = current->fs->pwd.dentry->d_sb;
78587 ROOT_DEV = s->s_dev;
78588 printk(KERN_INFO
78589@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78590 va_start(args, fmt);
78591 vsprintf(buf, fmt, args);
78592 va_end(args);
78593- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78594+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78595 if (fd >= 0) {
78596 sys_ioctl(fd, FDEJECT, 0);
78597 sys_close(fd);
78598 }
78599 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78600- fd = sys_open("/dev/console", O_RDWR, 0);
78601+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78602 if (fd >= 0) {
78603 sys_ioctl(fd, TCGETS, (long)&termios);
78604 termios.c_lflag &= ~ICANON;
78605 sys_ioctl(fd, TCSETSF, (long)&termios);
78606- sys_read(fd, &c, 1);
78607+ sys_read(fd, (char __user *)&c, 1);
78608 termios.c_lflag |= ICANON;
78609 sys_ioctl(fd, TCSETSF, (long)&termios);
78610 sys_close(fd);
78611@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78612 mount_root();
78613 out:
78614 devtmpfs_mount("dev");
78615- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78616- sys_chroot(".");
78617+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78618+ sys_chroot((const char __force_user *)".");
78619 }
78620diff --git a/init/do_mounts.h b/init/do_mounts.h
78621index f5b978a..69dbfe8 100644
78622--- a/init/do_mounts.h
78623+++ b/init/do_mounts.h
78624@@ -15,15 +15,15 @@ extern int root_mountflags;
78625
78626 static inline int create_dev(char *name, dev_t dev)
78627 {
78628- sys_unlink(name);
78629- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78630+ sys_unlink((char __force_user *)name);
78631+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78632 }
78633
78634 #if BITS_PER_LONG == 32
78635 static inline u32 bstat(char *name)
78636 {
78637 struct stat64 stat;
78638- if (sys_stat64(name, &stat) != 0)
78639+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78640 return 0;
78641 if (!S_ISBLK(stat.st_mode))
78642 return 0;
78643@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78644 static inline u32 bstat(char *name)
78645 {
78646 struct stat stat;
78647- if (sys_newstat(name, &stat) != 0)
78648+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78649 return 0;
78650 if (!S_ISBLK(stat.st_mode))
78651 return 0;
78652diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78653index 3e0878e..8a9d7a0 100644
78654--- a/init/do_mounts_initrd.c
78655+++ b/init/do_mounts_initrd.c
78656@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78657 {
78658 sys_unshare(CLONE_FS | CLONE_FILES);
78659 /* stdin/stdout/stderr for /linuxrc */
78660- sys_open("/dev/console", O_RDWR, 0);
78661+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78662 sys_dup(0);
78663 sys_dup(0);
78664 /* move initrd over / and chdir/chroot in initrd root */
78665- sys_chdir("/root");
78666- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78667- sys_chroot(".");
78668+ sys_chdir((const char __force_user *)"/root");
78669+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78670+ sys_chroot((const char __force_user *)".");
78671 sys_setsid();
78672 return 0;
78673 }
78674@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78675 create_dev("/dev/root.old", Root_RAM0);
78676 /* mount initrd on rootfs' /root */
78677 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78678- sys_mkdir("/old", 0700);
78679- sys_chdir("/old");
78680+ sys_mkdir((const char __force_user *)"/old", 0700);
78681+ sys_chdir((const char __force_user *)"/old");
78682
78683 /* try loading default modules from initrd */
78684 load_default_modules();
78685@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78686 current->flags &= ~PF_FREEZER_SKIP;
78687
78688 /* move initrd to rootfs' /old */
78689- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78690+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78691 /* switch root and cwd back to / of rootfs */
78692- sys_chroot("..");
78693+ sys_chroot((const char __force_user *)"..");
78694
78695 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78696- sys_chdir("/old");
78697+ sys_chdir((const char __force_user *)"/old");
78698 return;
78699 }
78700
78701- sys_chdir("/");
78702+ sys_chdir((const char __force_user *)"/");
78703 ROOT_DEV = new_decode_dev(real_root_dev);
78704 mount_root();
78705
78706 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78707- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78708+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78709 if (!error)
78710 printk("okay\n");
78711 else {
78712- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78713+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78714 if (error == -ENOENT)
78715 printk("/initrd does not exist. Ignored.\n");
78716 else
78717 printk("failed\n");
78718 printk(KERN_NOTICE "Unmounting old root\n");
78719- sys_umount("/old", MNT_DETACH);
78720+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78721 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78722 if (fd < 0) {
78723 error = fd;
78724@@ -127,11 +127,11 @@ int __init initrd_load(void)
78725 * mounted in the normal path.
78726 */
78727 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78728- sys_unlink("/initrd.image");
78729+ sys_unlink((const char __force_user *)"/initrd.image");
78730 handle_initrd();
78731 return 1;
78732 }
78733 }
78734- sys_unlink("/initrd.image");
78735+ sys_unlink((const char __force_user *)"/initrd.image");
78736 return 0;
78737 }
78738diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78739index 8cb6db5..d729f50 100644
78740--- a/init/do_mounts_md.c
78741+++ b/init/do_mounts_md.c
78742@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78743 partitioned ? "_d" : "", minor,
78744 md_setup_args[ent].device_names);
78745
78746- fd = sys_open(name, 0, 0);
78747+ fd = sys_open((char __force_user *)name, 0, 0);
78748 if (fd < 0) {
78749 printk(KERN_ERR "md: open failed - cannot start "
78750 "array %s\n", name);
78751@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78752 * array without it
78753 */
78754 sys_close(fd);
78755- fd = sys_open(name, 0, 0);
78756+ fd = sys_open((char __force_user *)name, 0, 0);
78757 sys_ioctl(fd, BLKRRPART, 0);
78758 }
78759 sys_close(fd);
78760@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78761
78762 wait_for_device_probe();
78763
78764- fd = sys_open("/dev/md0", 0, 0);
78765+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78766 if (fd >= 0) {
78767 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78768 sys_close(fd);
78769diff --git a/init/init_task.c b/init/init_task.c
78770index ba0a7f36..2bcf1d5 100644
78771--- a/init/init_task.c
78772+++ b/init/init_task.c
78773@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78774 * Initial thread structure. Alignment of this is handled by a special
78775 * linker map entry.
78776 */
78777+#ifdef CONFIG_X86
78778+union thread_union init_thread_union __init_task_data;
78779+#else
78780 union thread_union init_thread_union __init_task_data =
78781 { INIT_THREAD_INFO(init_task) };
78782+#endif
78783diff --git a/init/initramfs.c b/init/initramfs.c
78784index a67ef9d..2d17ed9 100644
78785--- a/init/initramfs.c
78786+++ b/init/initramfs.c
78787@@ -84,7 +84,7 @@ static void __init free_hash(void)
78788 }
78789 }
78790
78791-static long __init do_utime(char *filename, time_t mtime)
78792+static long __init do_utime(char __force_user *filename, time_t mtime)
78793 {
78794 struct timespec t[2];
78795
78796@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78797 struct dir_entry *de, *tmp;
78798 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78799 list_del(&de->list);
78800- do_utime(de->name, de->mtime);
78801+ do_utime((char __force_user *)de->name, de->mtime);
78802 kfree(de->name);
78803 kfree(de);
78804 }
78805@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78806 if (nlink >= 2) {
78807 char *old = find_link(major, minor, ino, mode, collected);
78808 if (old)
78809- return (sys_link(old, collected) < 0) ? -1 : 1;
78810+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78811 }
78812 return 0;
78813 }
78814@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78815 {
78816 struct stat st;
78817
78818- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78819+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78820 if (S_ISDIR(st.st_mode))
78821- sys_rmdir(path);
78822+ sys_rmdir((char __force_user *)path);
78823 else
78824- sys_unlink(path);
78825+ sys_unlink((char __force_user *)path);
78826 }
78827 }
78828
78829@@ -315,7 +315,7 @@ static int __init do_name(void)
78830 int openflags = O_WRONLY|O_CREAT;
78831 if (ml != 1)
78832 openflags |= O_TRUNC;
78833- wfd = sys_open(collected, openflags, mode);
78834+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78835
78836 if (wfd >= 0) {
78837 sys_fchown(wfd, uid, gid);
78838@@ -327,17 +327,17 @@ static int __init do_name(void)
78839 }
78840 }
78841 } else if (S_ISDIR(mode)) {
78842- sys_mkdir(collected, mode);
78843- sys_chown(collected, uid, gid);
78844- sys_chmod(collected, mode);
78845+ sys_mkdir((char __force_user *)collected, mode);
78846+ sys_chown((char __force_user *)collected, uid, gid);
78847+ sys_chmod((char __force_user *)collected, mode);
78848 dir_add(collected, mtime);
78849 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78850 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78851 if (maybe_link() == 0) {
78852- sys_mknod(collected, mode, rdev);
78853- sys_chown(collected, uid, gid);
78854- sys_chmod(collected, mode);
78855- do_utime(collected, mtime);
78856+ sys_mknod((char __force_user *)collected, mode, rdev);
78857+ sys_chown((char __force_user *)collected, uid, gid);
78858+ sys_chmod((char __force_user *)collected, mode);
78859+ do_utime((char __force_user *)collected, mtime);
78860 }
78861 }
78862 return 0;
78863@@ -346,15 +346,15 @@ static int __init do_name(void)
78864 static int __init do_copy(void)
78865 {
78866 if (count >= body_len) {
78867- sys_write(wfd, victim, body_len);
78868+ sys_write(wfd, (char __force_user *)victim, body_len);
78869 sys_close(wfd);
78870- do_utime(vcollected, mtime);
78871+ do_utime((char __force_user *)vcollected, mtime);
78872 kfree(vcollected);
78873 eat(body_len);
78874 state = SkipIt;
78875 return 0;
78876 } else {
78877- sys_write(wfd, victim, count);
78878+ sys_write(wfd, (char __force_user *)victim, count);
78879 body_len -= count;
78880 eat(count);
78881 return 1;
78882@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78883 {
78884 collected[N_ALIGN(name_len) + body_len] = '\0';
78885 clean_path(collected, 0);
78886- sys_symlink(collected + N_ALIGN(name_len), collected);
78887- sys_lchown(collected, uid, gid);
78888- do_utime(collected, mtime);
78889+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
78890+ sys_lchown((char __force_user *)collected, uid, gid);
78891+ do_utime((char __force_user *)collected, mtime);
78892 state = SkipIt;
78893 next_state = Reset;
78894 return 0;
78895@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
78896 {
78897 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
78898 if (err)
78899- panic(err); /* Failed to decompress INTERNAL initramfs */
78900+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
78901 if (initrd_start) {
78902 #ifdef CONFIG_BLK_DEV_RAM
78903 int fd;
78904diff --git a/init/main.c b/init/main.c
78905index d03d2ec..9fc4737 100644
78906--- a/init/main.c
78907+++ b/init/main.c
78908@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
78909 extern void tc_init(void);
78910 #endif
78911
78912+extern void grsecurity_init(void);
78913+
78914 /*
78915 * Debug helper: via this flag we know that we are in 'early bootup code'
78916 * where only the boot processor is running with IRQ disabled. This means
78917@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
78918
78919 __setup("reset_devices", set_reset_devices);
78920
78921+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78922+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
78923+static int __init setup_grsec_proc_gid(char *str)
78924+{
78925+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
78926+ return 1;
78927+}
78928+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
78929+#endif
78930+
78931+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
78932+unsigned long pax_user_shadow_base __read_only;
78933+EXPORT_SYMBOL(pax_user_shadow_base);
78934+extern char pax_enter_kernel_user[];
78935+extern char pax_exit_kernel_user[];
78936+#endif
78937+
78938+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
78939+static int __init setup_pax_nouderef(char *str)
78940+{
78941+#ifdef CONFIG_X86_32
78942+ unsigned int cpu;
78943+ struct desc_struct *gdt;
78944+
78945+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
78946+ gdt = get_cpu_gdt_table(cpu);
78947+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
78948+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
78949+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
78950+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
78951+ }
78952+ loadsegment(ds, __KERNEL_DS);
78953+ loadsegment(es, __KERNEL_DS);
78954+ loadsegment(ss, __KERNEL_DS);
78955+#else
78956+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
78957+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
78958+ clone_pgd_mask = ~(pgdval_t)0UL;
78959+ pax_user_shadow_base = 0UL;
78960+ setup_clear_cpu_cap(X86_FEATURE_PCID);
78961+#endif
78962+
78963+ return 0;
78964+}
78965+early_param("pax_nouderef", setup_pax_nouderef);
78966+
78967+#ifdef CONFIG_X86_64
78968+static int __init setup_pax_weakuderef(char *str)
78969+{
78970+ if (clone_pgd_mask != ~(pgdval_t)0UL)
78971+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
78972+ return 1;
78973+}
78974+__setup("pax_weakuderef", setup_pax_weakuderef);
78975+#endif
78976+#endif
78977+
78978+#ifdef CONFIG_PAX_SOFTMODE
78979+int pax_softmode;
78980+
78981+static int __init setup_pax_softmode(char *str)
78982+{
78983+ get_option(&str, &pax_softmode);
78984+ return 1;
78985+}
78986+__setup("pax_softmode=", setup_pax_softmode);
78987+#endif
78988+
78989 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
78990 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
78991 static const char *panic_later, *panic_param;
78992@@ -679,25 +749,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
78993 {
78994 int count = preempt_count();
78995 int ret;
78996- char msgbuf[64];
78997+ const char *msg1 = "", *msg2 = "";
78998
78999 if (initcall_debug)
79000 ret = do_one_initcall_debug(fn);
79001 else
79002 ret = fn();
79003
79004- msgbuf[0] = 0;
79005-
79006 if (preempt_count() != count) {
79007- sprintf(msgbuf, "preemption imbalance ");
79008+ msg1 = " preemption imbalance";
79009 preempt_count() = count;
79010 }
79011 if (irqs_disabled()) {
79012- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79013+ msg2 = " disabled interrupts";
79014 local_irq_enable();
79015 }
79016- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79017+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79018
79019+ add_latent_entropy();
79020 return ret;
79021 }
79022
79023@@ -803,8 +872,8 @@ static int run_init_process(const char *init_filename)
79024 {
79025 argv_init[0] = init_filename;
79026 return do_execve(init_filename,
79027- (const char __user *const __user *)argv_init,
79028- (const char __user *const __user *)envp_init);
79029+ (const char __user *const __force_user *)argv_init,
79030+ (const char __user *const __force_user *)envp_init);
79031 }
79032
79033 static noinline void __init kernel_init_freeable(void);
79034@@ -881,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
79035 do_basic_setup();
79036
79037 /* Open the /dev/console on the rootfs, this should never fail */
79038- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79039+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79040 pr_err("Warning: unable to open an initial console.\n");
79041
79042 (void) sys_dup(0);
79043@@ -894,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
79044 if (!ramdisk_execute_command)
79045 ramdisk_execute_command = "/init";
79046
79047- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79048+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79049 ramdisk_execute_command = NULL;
79050 prepare_namespace();
79051 }
79052
79053+ grsecurity_init();
79054+
79055 /*
79056 * Ok, we have completed the initial bootup, and
79057 * we're essentially up and running. Get rid of the
79058diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79059index 130dfec..cc88451 100644
79060--- a/ipc/ipc_sysctl.c
79061+++ b/ipc/ipc_sysctl.c
79062@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79063 static int proc_ipc_dointvec(ctl_table *table, int write,
79064 void __user *buffer, size_t *lenp, loff_t *ppos)
79065 {
79066- struct ctl_table ipc_table;
79067+ ctl_table_no_const ipc_table;
79068
79069 memcpy(&ipc_table, table, sizeof(ipc_table));
79070 ipc_table.data = get_ipc(table);
79071@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79072 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79073 void __user *buffer, size_t *lenp, loff_t *ppos)
79074 {
79075- struct ctl_table ipc_table;
79076+ ctl_table_no_const ipc_table;
79077
79078 memcpy(&ipc_table, table, sizeof(ipc_table));
79079 ipc_table.data = get_ipc(table);
79080@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79081 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79082 void __user *buffer, size_t *lenp, loff_t *ppos)
79083 {
79084- struct ctl_table ipc_table;
79085+ ctl_table_no_const ipc_table;
79086 size_t lenp_bef = *lenp;
79087 int rc;
79088
79089@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79090 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79091 void __user *buffer, size_t *lenp, loff_t *ppos)
79092 {
79093- struct ctl_table ipc_table;
79094+ ctl_table_no_const ipc_table;
79095 memcpy(&ipc_table, table, sizeof(ipc_table));
79096 ipc_table.data = get_ipc(table);
79097
79098@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79099 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79100 void __user *buffer, size_t *lenp, loff_t *ppos)
79101 {
79102- struct ctl_table ipc_table;
79103+ ctl_table_no_const ipc_table;
79104 size_t lenp_bef = *lenp;
79105 int oldval;
79106 int rc;
79107diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79108index 383d638..943fdbb 100644
79109--- a/ipc/mq_sysctl.c
79110+++ b/ipc/mq_sysctl.c
79111@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79112 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79113 void __user *buffer, size_t *lenp, loff_t *ppos)
79114 {
79115- struct ctl_table mq_table;
79116+ ctl_table_no_const mq_table;
79117 memcpy(&mq_table, table, sizeof(mq_table));
79118 mq_table.data = get_mq(table);
79119
79120diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79121index ae1996d..a35f2cc 100644
79122--- a/ipc/mqueue.c
79123+++ b/ipc/mqueue.c
79124@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79125 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79126 info->attr.mq_msgsize);
79127
79128+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79129 spin_lock(&mq_lock);
79130 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79131 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79132diff --git a/ipc/msg.c b/ipc/msg.c
79133index a877c16..b632025 100644
79134--- a/ipc/msg.c
79135+++ b/ipc/msg.c
79136@@ -298,18 +298,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79137 return security_msg_queue_associate(msq, msgflg);
79138 }
79139
79140+static struct ipc_ops msg_ops = {
79141+ .getnew = newque,
79142+ .associate = msg_security,
79143+ .more_checks = NULL
79144+};
79145+
79146 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79147 {
79148 struct ipc_namespace *ns;
79149- struct ipc_ops msg_ops;
79150 struct ipc_params msg_params;
79151
79152 ns = current->nsproxy->ipc_ns;
79153
79154- msg_ops.getnew = newque;
79155- msg_ops.associate = msg_security;
79156- msg_ops.more_checks = NULL;
79157-
79158 msg_params.key = key;
79159 msg_params.flg = msgflg;
79160
79161diff --git a/ipc/sem.c b/ipc/sem.c
79162index 87614511..c715d03 100644
79163--- a/ipc/sem.c
79164+++ b/ipc/sem.c
79165@@ -554,10 +554,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79166 return 0;
79167 }
79168
79169+static struct ipc_ops sem_ops = {
79170+ .getnew = newary,
79171+ .associate = sem_security,
79172+ .more_checks = sem_more_checks
79173+};
79174+
79175 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79176 {
79177 struct ipc_namespace *ns;
79178- struct ipc_ops sem_ops;
79179 struct ipc_params sem_params;
79180
79181 ns = current->nsproxy->ipc_ns;
79182@@ -565,10 +570,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79183 if (nsems < 0 || nsems > ns->sc_semmsl)
79184 return -EINVAL;
79185
79186- sem_ops.getnew = newary;
79187- sem_ops.associate = sem_security;
79188- sem_ops.more_checks = sem_more_checks;
79189-
79190 sem_params.key = key;
79191 sem_params.flg = semflg;
79192 sem_params.u.nsems = nsems;
79193diff --git a/ipc/shm.c b/ipc/shm.c
79194index 2d6833d..855bf81 100644
79195--- a/ipc/shm.c
79196+++ b/ipc/shm.c
79197@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79198 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79199 #endif
79200
79201+#ifdef CONFIG_GRKERNSEC
79202+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79203+ const time_t shm_createtime, const kuid_t cuid,
79204+ const int shmid);
79205+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79206+ const time_t shm_createtime);
79207+#endif
79208+
79209 void shm_init_ns(struct ipc_namespace *ns)
79210 {
79211 ns->shm_ctlmax = SHMMAX;
79212@@ -539,6 +547,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79213 shp->shm_lprid = 0;
79214 shp->shm_atim = shp->shm_dtim = 0;
79215 shp->shm_ctim = get_seconds();
79216+#ifdef CONFIG_GRKERNSEC
79217+ {
79218+ struct timespec timeval;
79219+ do_posix_clock_monotonic_gettime(&timeval);
79220+
79221+ shp->shm_createtime = timeval.tv_sec;
79222+ }
79223+#endif
79224 shp->shm_segsz = size;
79225 shp->shm_nattch = 0;
79226 shp->shm_file = file;
79227@@ -592,18 +608,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79228 return 0;
79229 }
79230
79231+static struct ipc_ops shm_ops = {
79232+ .getnew = newseg,
79233+ .associate = shm_security,
79234+ .more_checks = shm_more_checks
79235+};
79236+
79237 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79238 {
79239 struct ipc_namespace *ns;
79240- struct ipc_ops shm_ops;
79241 struct ipc_params shm_params;
79242
79243 ns = current->nsproxy->ipc_ns;
79244
79245- shm_ops.getnew = newseg;
79246- shm_ops.associate = shm_security;
79247- shm_ops.more_checks = shm_more_checks;
79248-
79249 shm_params.key = key;
79250 shm_params.flg = shmflg;
79251 shm_params.u.size = size;
79252@@ -1035,6 +1052,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79253 f_mode = FMODE_READ | FMODE_WRITE;
79254 }
79255 if (shmflg & SHM_EXEC) {
79256+
79257+#ifdef CONFIG_PAX_MPROTECT
79258+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79259+ goto out;
79260+#endif
79261+
79262 prot |= PROT_EXEC;
79263 acc_mode |= S_IXUGO;
79264 }
79265@@ -1058,9 +1081,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79266 if (err)
79267 goto out_unlock;
79268
79269+#ifdef CONFIG_GRKERNSEC
79270+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79271+ shp->shm_perm.cuid, shmid) ||
79272+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79273+ err = -EACCES;
79274+ goto out_unlock;
79275+ }
79276+#endif
79277+
79278 path = shp->shm_file->f_path;
79279 path_get(&path);
79280 shp->shm_nattch++;
79281+#ifdef CONFIG_GRKERNSEC
79282+ shp->shm_lapid = current->pid;
79283+#endif
79284 size = i_size_read(path.dentry->d_inode);
79285 shm_unlock(shp);
79286
79287diff --git a/kernel/acct.c b/kernel/acct.c
79288index 8d6e145..33e0b1e 100644
79289--- a/kernel/acct.c
79290+++ b/kernel/acct.c
79291@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79292 */
79293 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79294 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79295- file->f_op->write(file, (char *)&ac,
79296+ file->f_op->write(file, (char __force_user *)&ac,
79297 sizeof(acct_t), &file->f_pos);
79298 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79299 set_fs(fs);
79300diff --git a/kernel/audit.c b/kernel/audit.c
79301index 7b0e23a..5b27ab9 100644
79302--- a/kernel/audit.c
79303+++ b/kernel/audit.c
79304@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79305 3) suppressed due to audit_rate_limit
79306 4) suppressed due to audit_backlog_limit
79307 */
79308-static atomic_t audit_lost = ATOMIC_INIT(0);
79309+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79310
79311 /* The netlink socket. */
79312 static struct sock *audit_sock;
79313@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79314 unsigned long now;
79315 int print;
79316
79317- atomic_inc(&audit_lost);
79318+ atomic_inc_unchecked(&audit_lost);
79319
79320 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79321
79322@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79323 printk(KERN_WARNING
79324 "audit: audit_lost=%d audit_rate_limit=%d "
79325 "audit_backlog_limit=%d\n",
79326- atomic_read(&audit_lost),
79327+ atomic_read_unchecked(&audit_lost),
79328 audit_rate_limit,
79329 audit_backlog_limit);
79330 audit_panic(message);
79331@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79332
79333 switch (msg_type) {
79334 case AUDIT_GET:
79335+ status_set.mask = 0;
79336 status_set.enabled = audit_enabled;
79337 status_set.failure = audit_failure;
79338 status_set.pid = audit_pid;
79339 status_set.rate_limit = audit_rate_limit;
79340 status_set.backlog_limit = audit_backlog_limit;
79341- status_set.lost = atomic_read(&audit_lost);
79342+ status_set.lost = atomic_read_unchecked(&audit_lost);
79343 status_set.backlog = skb_queue_len(&audit_skb_queue);
79344 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79345 &status_set, sizeof(status_set));
79346 break;
79347 case AUDIT_SET:
79348- if (nlh->nlmsg_len < sizeof(struct audit_status))
79349+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79350 return -EINVAL;
79351 status_get = (struct audit_status *)data;
79352 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79353@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79354
79355 memset(&s, 0, sizeof(s));
79356 /* guard against past and future API changes */
79357- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79358+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79359 if ((s.enabled != 0 && s.enabled != 1) ||
79360 (s.log_passwd != 0 && s.log_passwd != 1))
79361 return -EINVAL;
79362diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79363index 9845cb3..3ec9369 100644
79364--- a/kernel/auditsc.c
79365+++ b/kernel/auditsc.c
79366@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79367 }
79368
79369 /* global counter which is incremented every time something logs in */
79370-static atomic_t session_id = ATOMIC_INIT(0);
79371+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79372
79373 /**
79374 * audit_set_loginuid - set current task's audit_context loginuid
79375@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79376 return -EPERM;
79377 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79378
79379- sessionid = atomic_inc_return(&session_id);
79380+ sessionid = atomic_inc_return_unchecked(&session_id);
79381 if (context && context->in_syscall) {
79382 struct audit_buffer *ab;
79383
79384diff --git a/kernel/capability.c b/kernel/capability.c
79385index f6c2ce5..982c0f9 100644
79386--- a/kernel/capability.c
79387+++ b/kernel/capability.c
79388@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79389 * before modification is attempted and the application
79390 * fails.
79391 */
79392+ if (tocopy > ARRAY_SIZE(kdata))
79393+ return -EFAULT;
79394+
79395 if (copy_to_user(dataptr, kdata, tocopy
79396 * sizeof(struct __user_cap_data_struct))) {
79397 return -EFAULT;
79398@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79399 int ret;
79400
79401 rcu_read_lock();
79402- ret = security_capable(__task_cred(t), ns, cap);
79403+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79404+ gr_task_is_capable(t, __task_cred(t), cap);
79405 rcu_read_unlock();
79406
79407- return (ret == 0);
79408+ return ret;
79409 }
79410
79411 /**
79412@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79413 int ret;
79414
79415 rcu_read_lock();
79416- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79417+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79418 rcu_read_unlock();
79419
79420- return (ret == 0);
79421+ return ret;
79422 }
79423
79424 /**
79425@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79426 BUG();
79427 }
79428
79429- if (security_capable(current_cred(), ns, cap) == 0) {
79430+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79431 current->flags |= PF_SUPERPRIV;
79432 return true;
79433 }
79434@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79435 }
79436 EXPORT_SYMBOL(ns_capable);
79437
79438+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79439+{
79440+ if (unlikely(!cap_valid(cap))) {
79441+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79442+ BUG();
79443+ }
79444+
79445+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79446+ current->flags |= PF_SUPERPRIV;
79447+ return true;
79448+ }
79449+ return false;
79450+}
79451+EXPORT_SYMBOL(ns_capable_nolog);
79452+
79453 /**
79454 * file_ns_capable - Determine if the file's opener had a capability in effect
79455 * @file: The file we want to check
79456@@ -432,6 +451,12 @@ bool capable(int cap)
79457 }
79458 EXPORT_SYMBOL(capable);
79459
79460+bool capable_nolog(int cap)
79461+{
79462+ return ns_capable_nolog(&init_user_ns, cap);
79463+}
79464+EXPORT_SYMBOL(capable_nolog);
79465+
79466 /**
79467 * nsown_capable - Check superior capability to one's own user_ns
79468 * @cap: The capability in question
79469@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79470
79471 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79472 }
79473+
79474+bool inode_capable_nolog(const struct inode *inode, int cap)
79475+{
79476+ struct user_namespace *ns = current_user_ns();
79477+
79478+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79479+}
79480diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79481index e919633..f46b08f 100644
79482--- a/kernel/cgroup.c
79483+++ b/kernel/cgroup.c
79484@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79485 struct css_set *cset = link->cset;
79486 struct task_struct *task;
79487 int count = 0;
79488- seq_printf(seq, "css_set %p\n", cset);
79489+ seq_printf(seq, "css_set %pK\n", cset);
79490 list_for_each_entry(task, &cset->tasks, cg_list) {
79491 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79492 seq_puts(seq, " ...\n");
79493diff --git a/kernel/compat.c b/kernel/compat.c
79494index 0a09e48..f44f3f0 100644
79495--- a/kernel/compat.c
79496+++ b/kernel/compat.c
79497@@ -13,6 +13,7 @@
79498
79499 #include <linux/linkage.h>
79500 #include <linux/compat.h>
79501+#include <linux/module.h>
79502 #include <linux/errno.h>
79503 #include <linux/time.h>
79504 #include <linux/signal.h>
79505@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79506 mm_segment_t oldfs;
79507 long ret;
79508
79509- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79510+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79511 oldfs = get_fs();
79512 set_fs(KERNEL_DS);
79513 ret = hrtimer_nanosleep_restart(restart);
79514@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79515 oldfs = get_fs();
79516 set_fs(KERNEL_DS);
79517 ret = hrtimer_nanosleep(&tu,
79518- rmtp ? (struct timespec __user *)&rmt : NULL,
79519+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79520 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79521 set_fs(oldfs);
79522
79523@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79524 mm_segment_t old_fs = get_fs();
79525
79526 set_fs(KERNEL_DS);
79527- ret = sys_sigpending((old_sigset_t __user *) &s);
79528+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79529 set_fs(old_fs);
79530 if (ret == 0)
79531 ret = put_user(s, set);
79532@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79533 mm_segment_t old_fs = get_fs();
79534
79535 set_fs(KERNEL_DS);
79536- ret = sys_old_getrlimit(resource, &r);
79537+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79538 set_fs(old_fs);
79539
79540 if (!ret) {
79541@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79542 set_fs (KERNEL_DS);
79543 ret = sys_wait4(pid,
79544 (stat_addr ?
79545- (unsigned int __user *) &status : NULL),
79546- options, (struct rusage __user *) &r);
79547+ (unsigned int __force_user *) &status : NULL),
79548+ options, (struct rusage __force_user *) &r);
79549 set_fs (old_fs);
79550
79551 if (ret > 0) {
79552@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79553 memset(&info, 0, sizeof(info));
79554
79555 set_fs(KERNEL_DS);
79556- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79557- uru ? (struct rusage __user *)&ru : NULL);
79558+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79559+ uru ? (struct rusage __force_user *)&ru : NULL);
79560 set_fs(old_fs);
79561
79562 if ((ret < 0) || (info.si_signo == 0))
79563@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79564 oldfs = get_fs();
79565 set_fs(KERNEL_DS);
79566 err = sys_timer_settime(timer_id, flags,
79567- (struct itimerspec __user *) &newts,
79568- (struct itimerspec __user *) &oldts);
79569+ (struct itimerspec __force_user *) &newts,
79570+ (struct itimerspec __force_user *) &oldts);
79571 set_fs(oldfs);
79572 if (!err && old && put_compat_itimerspec(old, &oldts))
79573 return -EFAULT;
79574@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79575 oldfs = get_fs();
79576 set_fs(KERNEL_DS);
79577 err = sys_timer_gettime(timer_id,
79578- (struct itimerspec __user *) &ts);
79579+ (struct itimerspec __force_user *) &ts);
79580 set_fs(oldfs);
79581 if (!err && put_compat_itimerspec(setting, &ts))
79582 return -EFAULT;
79583@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79584 oldfs = get_fs();
79585 set_fs(KERNEL_DS);
79586 err = sys_clock_settime(which_clock,
79587- (struct timespec __user *) &ts);
79588+ (struct timespec __force_user *) &ts);
79589 set_fs(oldfs);
79590 return err;
79591 }
79592@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79593 oldfs = get_fs();
79594 set_fs(KERNEL_DS);
79595 err = sys_clock_gettime(which_clock,
79596- (struct timespec __user *) &ts);
79597+ (struct timespec __force_user *) &ts);
79598 set_fs(oldfs);
79599 if (!err && put_compat_timespec(&ts, tp))
79600 return -EFAULT;
79601@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79602
79603 oldfs = get_fs();
79604 set_fs(KERNEL_DS);
79605- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79606+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79607 set_fs(oldfs);
79608
79609 err = compat_put_timex(utp, &txc);
79610@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79611 oldfs = get_fs();
79612 set_fs(KERNEL_DS);
79613 err = sys_clock_getres(which_clock,
79614- (struct timespec __user *) &ts);
79615+ (struct timespec __force_user *) &ts);
79616 set_fs(oldfs);
79617 if (!err && tp && put_compat_timespec(&ts, tp))
79618 return -EFAULT;
79619@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79620 long err;
79621 mm_segment_t oldfs;
79622 struct timespec tu;
79623- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79624+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79625
79626- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79627+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79628 oldfs = get_fs();
79629 set_fs(KERNEL_DS);
79630 err = clock_nanosleep_restart(restart);
79631@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79632 oldfs = get_fs();
79633 set_fs(KERNEL_DS);
79634 err = sys_clock_nanosleep(which_clock, flags,
79635- (struct timespec __user *) &in,
79636- (struct timespec __user *) &out);
79637+ (struct timespec __force_user *) &in,
79638+ (struct timespec __force_user *) &out);
79639 set_fs(oldfs);
79640
79641 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79642diff --git a/kernel/configs.c b/kernel/configs.c
79643index c18b1f1..b9a0132 100644
79644--- a/kernel/configs.c
79645+++ b/kernel/configs.c
79646@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79647 struct proc_dir_entry *entry;
79648
79649 /* create the current config file */
79650+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79651+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79652+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79653+ &ikconfig_file_ops);
79654+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79655+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79656+ &ikconfig_file_ops);
79657+#endif
79658+#else
79659 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79660 &ikconfig_file_ops);
79661+#endif
79662+
79663 if (!entry)
79664 return -ENOMEM;
79665
79666diff --git a/kernel/cred.c b/kernel/cred.c
79667index e0573a4..3874e41 100644
79668--- a/kernel/cred.c
79669+++ b/kernel/cred.c
79670@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79671 validate_creds(cred);
79672 alter_cred_subscribers(cred, -1);
79673 put_cred(cred);
79674+
79675+#ifdef CONFIG_GRKERNSEC_SETXID
79676+ cred = (struct cred *) tsk->delayed_cred;
79677+ if (cred != NULL) {
79678+ tsk->delayed_cred = NULL;
79679+ validate_creds(cred);
79680+ alter_cred_subscribers(cred, -1);
79681+ put_cred(cred);
79682+ }
79683+#endif
79684 }
79685
79686 /**
79687@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79688 * Always returns 0 thus allowing this function to be tail-called at the end
79689 * of, say, sys_setgid().
79690 */
79691-int commit_creds(struct cred *new)
79692+static int __commit_creds(struct cred *new)
79693 {
79694 struct task_struct *task = current;
79695 const struct cred *old = task->real_cred;
79696@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79697
79698 get_cred(new); /* we will require a ref for the subj creds too */
79699
79700+ gr_set_role_label(task, new->uid, new->gid);
79701+
79702 /* dumpability changes */
79703 if (!uid_eq(old->euid, new->euid) ||
79704 !gid_eq(old->egid, new->egid) ||
79705@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79706 put_cred(old);
79707 return 0;
79708 }
79709+#ifdef CONFIG_GRKERNSEC_SETXID
79710+extern int set_user(struct cred *new);
79711+
79712+void gr_delayed_cred_worker(void)
79713+{
79714+ const struct cred *new = current->delayed_cred;
79715+ struct cred *ncred;
79716+
79717+ current->delayed_cred = NULL;
79718+
79719+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79720+ // from doing get_cred on it when queueing this
79721+ put_cred(new);
79722+ return;
79723+ } else if (new == NULL)
79724+ return;
79725+
79726+ ncred = prepare_creds();
79727+ if (!ncred)
79728+ goto die;
79729+ // uids
79730+ ncred->uid = new->uid;
79731+ ncred->euid = new->euid;
79732+ ncred->suid = new->suid;
79733+ ncred->fsuid = new->fsuid;
79734+ // gids
79735+ ncred->gid = new->gid;
79736+ ncred->egid = new->egid;
79737+ ncred->sgid = new->sgid;
79738+ ncred->fsgid = new->fsgid;
79739+ // groups
79740+ if (set_groups(ncred, new->group_info) < 0) {
79741+ abort_creds(ncred);
79742+ goto die;
79743+ }
79744+ // caps
79745+ ncred->securebits = new->securebits;
79746+ ncred->cap_inheritable = new->cap_inheritable;
79747+ ncred->cap_permitted = new->cap_permitted;
79748+ ncred->cap_effective = new->cap_effective;
79749+ ncred->cap_bset = new->cap_bset;
79750+
79751+ if (set_user(ncred)) {
79752+ abort_creds(ncred);
79753+ goto die;
79754+ }
79755+
79756+ // from doing get_cred on it when queueing this
79757+ put_cred(new);
79758+
79759+ __commit_creds(ncred);
79760+ return;
79761+die:
79762+ // from doing get_cred on it when queueing this
79763+ put_cred(new);
79764+ do_group_exit(SIGKILL);
79765+}
79766+#endif
79767+
79768+int commit_creds(struct cred *new)
79769+{
79770+#ifdef CONFIG_GRKERNSEC_SETXID
79771+ int ret;
79772+ int schedule_it = 0;
79773+ struct task_struct *t;
79774+
79775+ /* we won't get called with tasklist_lock held for writing
79776+ and interrupts disabled as the cred struct in that case is
79777+ init_cred
79778+ */
79779+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79780+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79781+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79782+ schedule_it = 1;
79783+ }
79784+ ret = __commit_creds(new);
79785+ if (schedule_it) {
79786+ rcu_read_lock();
79787+ read_lock(&tasklist_lock);
79788+ for (t = next_thread(current); t != current;
79789+ t = next_thread(t)) {
79790+ if (t->delayed_cred == NULL) {
79791+ t->delayed_cred = get_cred(new);
79792+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79793+ set_tsk_need_resched(t);
79794+ }
79795+ }
79796+ read_unlock(&tasklist_lock);
79797+ rcu_read_unlock();
79798+ }
79799+ return ret;
79800+#else
79801+ return __commit_creds(new);
79802+#endif
79803+}
79804+
79805 EXPORT_SYMBOL(commit_creds);
79806
79807 /**
79808diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79809index 0506d44..2c20034 100644
79810--- a/kernel/debug/debug_core.c
79811+++ b/kernel/debug/debug_core.c
79812@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79813 */
79814 static atomic_t masters_in_kgdb;
79815 static atomic_t slaves_in_kgdb;
79816-static atomic_t kgdb_break_tasklet_var;
79817+static atomic_unchecked_t kgdb_break_tasklet_var;
79818 atomic_t kgdb_setting_breakpoint;
79819
79820 struct task_struct *kgdb_usethread;
79821@@ -133,7 +133,7 @@ int kgdb_single_step;
79822 static pid_t kgdb_sstep_pid;
79823
79824 /* to keep track of the CPU which is doing the single stepping*/
79825-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79826+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79827
79828 /*
79829 * If you are debugging a problem where roundup (the collection of
79830@@ -541,7 +541,7 @@ return_normal:
79831 * kernel will only try for the value of sstep_tries before
79832 * giving up and continuing on.
79833 */
79834- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79835+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79836 (kgdb_info[cpu].task &&
79837 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79838 atomic_set(&kgdb_active, -1);
79839@@ -635,8 +635,8 @@ cpu_master_loop:
79840 }
79841
79842 kgdb_restore:
79843- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79844- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79845+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79846+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79847 if (kgdb_info[sstep_cpu].task)
79848 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79849 else
79850@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79851 static void kgdb_tasklet_bpt(unsigned long ing)
79852 {
79853 kgdb_breakpoint();
79854- atomic_set(&kgdb_break_tasklet_var, 0);
79855+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79856 }
79857
79858 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79859
79860 void kgdb_schedule_breakpoint(void)
79861 {
79862- if (atomic_read(&kgdb_break_tasklet_var) ||
79863+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79864 atomic_read(&kgdb_active) != -1 ||
79865 atomic_read(&kgdb_setting_breakpoint))
79866 return;
79867- atomic_inc(&kgdb_break_tasklet_var);
79868+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79869 tasklet_schedule(&kgdb_tasklet_breakpoint);
79870 }
79871 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79872diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79873index 00eb8f7..d7e3244 100644
79874--- a/kernel/debug/kdb/kdb_main.c
79875+++ b/kernel/debug/kdb/kdb_main.c
79876@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79877 continue;
79878
79879 kdb_printf("%-20s%8u 0x%p ", mod->name,
79880- mod->core_size, (void *)mod);
79881+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79882 #ifdef CONFIG_MODULE_UNLOAD
79883 kdb_printf("%4ld ", module_refcount(mod));
79884 #endif
79885@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
79886 kdb_printf(" (Loading)");
79887 else
79888 kdb_printf(" (Live)");
79889- kdb_printf(" 0x%p", mod->module_core);
79890+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
79891
79892 #ifdef CONFIG_MODULE_UNLOAD
79893 {
79894diff --git a/kernel/events/core.c b/kernel/events/core.c
79895index f86599e..b18b180 100644
79896--- a/kernel/events/core.c
79897+++ b/kernel/events/core.c
79898@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
79899 * 0 - disallow raw tracepoint access for unpriv
79900 * 1 - disallow cpu events for unpriv
79901 * 2 - disallow kernel profiling for unpriv
79902+ * 3 - disallow all unpriv perf event use
79903 */
79904-int sysctl_perf_event_paranoid __read_mostly = 1;
79905+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79906+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
79907+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
79908+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
79909+#else
79910+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
79911+#endif
79912
79913 /* Minimum for 512 kiB + 1 user control page */
79914 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
79915@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
79916 update_perf_cpu_limits();
79917 }
79918
79919-static atomic64_t perf_event_id;
79920+static atomic64_unchecked_t perf_event_id;
79921
79922 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
79923 enum event_type_t event_type);
79924@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
79925
79926 static inline u64 perf_event_count(struct perf_event *event)
79927 {
79928- return local64_read(&event->count) + atomic64_read(&event->child_count);
79929+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
79930 }
79931
79932 static u64 perf_event_read(struct perf_event *event)
79933@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
79934 mutex_lock(&event->child_mutex);
79935 total += perf_event_read(event);
79936 *enabled += event->total_time_enabled +
79937- atomic64_read(&event->child_total_time_enabled);
79938+ atomic64_read_unchecked(&event->child_total_time_enabled);
79939 *running += event->total_time_running +
79940- atomic64_read(&event->child_total_time_running);
79941+ atomic64_read_unchecked(&event->child_total_time_running);
79942
79943 list_for_each_entry(child, &event->child_list, child_list) {
79944 total += perf_event_read(child);
79945@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
79946 userpg->offset -= local64_read(&event->hw.prev_count);
79947
79948 userpg->time_enabled = enabled +
79949- atomic64_read(&event->child_total_time_enabled);
79950+ atomic64_read_unchecked(&event->child_total_time_enabled);
79951
79952 userpg->time_running = running +
79953- atomic64_read(&event->child_total_time_running);
79954+ atomic64_read_unchecked(&event->child_total_time_running);
79955
79956 arch_perf_update_userpage(userpg, now);
79957
79958@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
79959
79960 /* Data. */
79961 sp = perf_user_stack_pointer(regs);
79962- rem = __output_copy_user(handle, (void *) sp, dump_size);
79963+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
79964 dyn_size = dump_size - rem;
79965
79966 perf_output_skip(handle, rem);
79967@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
79968 values[n++] = perf_event_count(event);
79969 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
79970 values[n++] = enabled +
79971- atomic64_read(&event->child_total_time_enabled);
79972+ atomic64_read_unchecked(&event->child_total_time_enabled);
79973 }
79974 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
79975 values[n++] = running +
79976- atomic64_read(&event->child_total_time_running);
79977+ atomic64_read_unchecked(&event->child_total_time_running);
79978 }
79979 if (read_format & PERF_FORMAT_ID)
79980 values[n++] = primary_event_id(event);
79981@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
79982 * need to add enough zero bytes after the string to handle
79983 * the 64bit alignment we do later.
79984 */
79985- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
79986+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
79987 if (!buf) {
79988 name = strncpy(tmp, "//enomem", sizeof(tmp));
79989 goto got_name;
79990 }
79991- name = d_path(&file->f_path, buf, PATH_MAX);
79992+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
79993 if (IS_ERR(name)) {
79994 name = strncpy(tmp, "//toolong", sizeof(tmp));
79995 goto got_name;
79996@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
79997 event->parent = parent_event;
79998
79999 event->ns = get_pid_ns(task_active_pid_ns(current));
80000- event->id = atomic64_inc_return(&perf_event_id);
80001+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80002
80003 event->state = PERF_EVENT_STATE_INACTIVE;
80004
80005@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80006 if (flags & ~PERF_FLAG_ALL)
80007 return -EINVAL;
80008
80009+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80010+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80011+ return -EACCES;
80012+#endif
80013+
80014 err = perf_copy_attr(attr_uptr, &attr);
80015 if (err)
80016 return err;
80017@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80018 /*
80019 * Add back the child's count to the parent's count:
80020 */
80021- atomic64_add(child_val, &parent_event->child_count);
80022- atomic64_add(child_event->total_time_enabled,
80023+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80024+ atomic64_add_unchecked(child_event->total_time_enabled,
80025 &parent_event->child_total_time_enabled);
80026- atomic64_add(child_event->total_time_running,
80027+ atomic64_add_unchecked(child_event->total_time_running,
80028 &parent_event->child_total_time_running);
80029
80030 /*
80031diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80032index ca65997..60df03d 100644
80033--- a/kernel/events/internal.h
80034+++ b/kernel/events/internal.h
80035@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80036 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80037 }
80038
80039-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80040-static inline unsigned int \
80041+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80042+static inline unsigned long \
80043 func_name(struct perf_output_handle *handle, \
80044- const void *buf, unsigned int len) \
80045+ const void user *buf, unsigned long len) \
80046 { \
80047 unsigned long size, written; \
80048 \
80049@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80050 return n;
80051 }
80052
80053-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80054+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80055
80056 #define MEMCPY_SKIP(dst, src, n) (n)
80057
80058-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80059+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80060
80061 #ifndef arch_perf_out_copy_user
80062 #define arch_perf_out_copy_user __copy_from_user_inatomic
80063 #endif
80064
80065-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80066+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80067
80068 /* Callchain handling */
80069 extern struct perf_callchain_entry *
80070diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80071index ad8e1bd..fed7ba9 100644
80072--- a/kernel/events/uprobes.c
80073+++ b/kernel/events/uprobes.c
80074@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80075 {
80076 struct page *page;
80077 uprobe_opcode_t opcode;
80078- int result;
80079+ long result;
80080
80081 pagefault_disable();
80082 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80083diff --git a/kernel/exit.c b/kernel/exit.c
80084index a949819..a5f127d 100644
80085--- a/kernel/exit.c
80086+++ b/kernel/exit.c
80087@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80088 struct task_struct *leader;
80089 int zap_leader;
80090 repeat:
80091+#ifdef CONFIG_NET
80092+ gr_del_task_from_ip_table(p);
80093+#endif
80094+
80095 /* don't need to get the RCU readlock here - the process is dead and
80096 * can't be modifying its own credentials. But shut RCU-lockdep up */
80097 rcu_read_lock();
80098@@ -329,7 +333,7 @@ int allow_signal(int sig)
80099 * know it'll be handled, so that they don't get converted to
80100 * SIGKILL or just silently dropped.
80101 */
80102- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80103+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80104 recalc_sigpending();
80105 spin_unlock_irq(&current->sighand->siglock);
80106 return 0;
80107@@ -698,6 +702,8 @@ void do_exit(long code)
80108 struct task_struct *tsk = current;
80109 int group_dead;
80110
80111+ set_fs(USER_DS);
80112+
80113 profile_task_exit(tsk);
80114
80115 WARN_ON(blk_needs_flush_plug(tsk));
80116@@ -714,7 +720,6 @@ void do_exit(long code)
80117 * mm_release()->clear_child_tid() from writing to a user-controlled
80118 * kernel address.
80119 */
80120- set_fs(USER_DS);
80121
80122 ptrace_event(PTRACE_EVENT_EXIT, code);
80123
80124@@ -773,6 +778,9 @@ void do_exit(long code)
80125 tsk->exit_code = code;
80126 taskstats_exit(tsk, group_dead);
80127
80128+ gr_acl_handle_psacct(tsk, code);
80129+ gr_acl_handle_exit();
80130+
80131 exit_mm(tsk);
80132
80133 if (group_dead)
80134@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80135 * Take down every thread in the group. This is called by fatal signals
80136 * as well as by sys_exit_group (below).
80137 */
80138-void
80139+__noreturn void
80140 do_group_exit(int exit_code)
80141 {
80142 struct signal_struct *sig = current->signal;
80143diff --git a/kernel/fork.c b/kernel/fork.c
80144index 200a7a2..43e52da 100644
80145--- a/kernel/fork.c
80146+++ b/kernel/fork.c
80147@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80148 *stackend = STACK_END_MAGIC; /* for overflow detection */
80149
80150 #ifdef CONFIG_CC_STACKPROTECTOR
80151- tsk->stack_canary = get_random_int();
80152+ tsk->stack_canary = pax_get_random_long();
80153 #endif
80154
80155 /*
80156@@ -345,13 +345,81 @@ free_tsk:
80157 }
80158
80159 #ifdef CONFIG_MMU
80160-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80161+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80162 {
80163- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80164- struct rb_node **rb_link, *rb_parent;
80165- int retval;
80166+ struct vm_area_struct *tmp;
80167 unsigned long charge;
80168 struct mempolicy *pol;
80169+ struct file *file;
80170+
80171+ charge = 0;
80172+ if (mpnt->vm_flags & VM_ACCOUNT) {
80173+ unsigned long len = vma_pages(mpnt);
80174+
80175+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80176+ goto fail_nomem;
80177+ charge = len;
80178+ }
80179+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80180+ if (!tmp)
80181+ goto fail_nomem;
80182+ *tmp = *mpnt;
80183+ tmp->vm_mm = mm;
80184+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80185+ pol = mpol_dup(vma_policy(mpnt));
80186+ if (IS_ERR(pol))
80187+ goto fail_nomem_policy;
80188+ vma_set_policy(tmp, pol);
80189+ if (anon_vma_fork(tmp, mpnt))
80190+ goto fail_nomem_anon_vma_fork;
80191+ tmp->vm_flags &= ~VM_LOCKED;
80192+ tmp->vm_next = tmp->vm_prev = NULL;
80193+ tmp->vm_mirror = NULL;
80194+ file = tmp->vm_file;
80195+ if (file) {
80196+ struct inode *inode = file_inode(file);
80197+ struct address_space *mapping = file->f_mapping;
80198+
80199+ get_file(file);
80200+ if (tmp->vm_flags & VM_DENYWRITE)
80201+ atomic_dec(&inode->i_writecount);
80202+ mutex_lock(&mapping->i_mmap_mutex);
80203+ if (tmp->vm_flags & VM_SHARED)
80204+ mapping->i_mmap_writable++;
80205+ flush_dcache_mmap_lock(mapping);
80206+ /* insert tmp into the share list, just after mpnt */
80207+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80208+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80209+ else
80210+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80211+ flush_dcache_mmap_unlock(mapping);
80212+ mutex_unlock(&mapping->i_mmap_mutex);
80213+ }
80214+
80215+ /*
80216+ * Clear hugetlb-related page reserves for children. This only
80217+ * affects MAP_PRIVATE mappings. Faults generated by the child
80218+ * are not guaranteed to succeed, even if read-only
80219+ */
80220+ if (is_vm_hugetlb_page(tmp))
80221+ reset_vma_resv_huge_pages(tmp);
80222+
80223+ return tmp;
80224+
80225+fail_nomem_anon_vma_fork:
80226+ mpol_put(pol);
80227+fail_nomem_policy:
80228+ kmem_cache_free(vm_area_cachep, tmp);
80229+fail_nomem:
80230+ vm_unacct_memory(charge);
80231+ return NULL;
80232+}
80233+
80234+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80235+{
80236+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80237+ struct rb_node **rb_link, *rb_parent;
80238+ int retval;
80239
80240 uprobe_start_dup_mmap();
80241 down_write(&oldmm->mmap_sem);
80242@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80243
80244 prev = NULL;
80245 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80246- struct file *file;
80247-
80248 if (mpnt->vm_flags & VM_DONTCOPY) {
80249 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80250 -vma_pages(mpnt));
80251 continue;
80252 }
80253- charge = 0;
80254- if (mpnt->vm_flags & VM_ACCOUNT) {
80255- unsigned long len = vma_pages(mpnt);
80256-
80257- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80258- goto fail_nomem;
80259- charge = len;
80260- }
80261- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80262- if (!tmp)
80263- goto fail_nomem;
80264- *tmp = *mpnt;
80265- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80266- pol = mpol_dup(vma_policy(mpnt));
80267- retval = PTR_ERR(pol);
80268- if (IS_ERR(pol))
80269- goto fail_nomem_policy;
80270- vma_set_policy(tmp, pol);
80271- tmp->vm_mm = mm;
80272- if (anon_vma_fork(tmp, mpnt))
80273- goto fail_nomem_anon_vma_fork;
80274- tmp->vm_flags &= ~VM_LOCKED;
80275- tmp->vm_next = tmp->vm_prev = NULL;
80276- file = tmp->vm_file;
80277- if (file) {
80278- struct inode *inode = file_inode(file);
80279- struct address_space *mapping = file->f_mapping;
80280-
80281- get_file(file);
80282- if (tmp->vm_flags & VM_DENYWRITE)
80283- atomic_dec(&inode->i_writecount);
80284- mutex_lock(&mapping->i_mmap_mutex);
80285- if (tmp->vm_flags & VM_SHARED)
80286- mapping->i_mmap_writable++;
80287- flush_dcache_mmap_lock(mapping);
80288- /* insert tmp into the share list, just after mpnt */
80289- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80290- vma_nonlinear_insert(tmp,
80291- &mapping->i_mmap_nonlinear);
80292- else
80293- vma_interval_tree_insert_after(tmp, mpnt,
80294- &mapping->i_mmap);
80295- flush_dcache_mmap_unlock(mapping);
80296- mutex_unlock(&mapping->i_mmap_mutex);
80297+ tmp = dup_vma(mm, oldmm, mpnt);
80298+ if (!tmp) {
80299+ retval = -ENOMEM;
80300+ goto out;
80301 }
80302
80303 /*
80304@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80305 if (retval)
80306 goto out;
80307 }
80308+
80309+#ifdef CONFIG_PAX_SEGMEXEC
80310+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80311+ struct vm_area_struct *mpnt_m;
80312+
80313+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80314+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80315+
80316+ if (!mpnt->vm_mirror)
80317+ continue;
80318+
80319+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80320+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80321+ mpnt->vm_mirror = mpnt_m;
80322+ } else {
80323+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80324+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80325+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80326+ mpnt->vm_mirror->vm_mirror = mpnt;
80327+ }
80328+ }
80329+ BUG_ON(mpnt_m);
80330+ }
80331+#endif
80332+
80333 /* a new mm has just been created */
80334 arch_dup_mmap(oldmm, mm);
80335 retval = 0;
80336@@ -471,14 +522,6 @@ out:
80337 up_write(&oldmm->mmap_sem);
80338 uprobe_end_dup_mmap();
80339 return retval;
80340-fail_nomem_anon_vma_fork:
80341- mpol_put(pol);
80342-fail_nomem_policy:
80343- kmem_cache_free(vm_area_cachep, tmp);
80344-fail_nomem:
80345- retval = -ENOMEM;
80346- vm_unacct_memory(charge);
80347- goto out;
80348 }
80349
80350 static inline int mm_alloc_pgd(struct mm_struct *mm)
80351@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80352 return ERR_PTR(err);
80353
80354 mm = get_task_mm(task);
80355- if (mm && mm != current->mm &&
80356- !ptrace_may_access(task, mode)) {
80357+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80358+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80359 mmput(mm);
80360 mm = ERR_PTR(-EACCES);
80361 }
80362@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80363 spin_unlock(&fs->lock);
80364 return -EAGAIN;
80365 }
80366- fs->users++;
80367+ atomic_inc(&fs->users);
80368 spin_unlock(&fs->lock);
80369 return 0;
80370 }
80371 tsk->fs = copy_fs_struct(fs);
80372 if (!tsk->fs)
80373 return -ENOMEM;
80374+ /* Carry through gr_chroot_dentry and is_chrooted instead
80375+ of recomputing it here. Already copied when the task struct
80376+ is duplicated. This allows pivot_root to not be treated as
80377+ a chroot
80378+ */
80379+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80380+
80381 return 0;
80382 }
80383
80384@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80385 * parts of the process environment (as per the clone
80386 * flags). The actual kick-off is left to the caller.
80387 */
80388-static struct task_struct *copy_process(unsigned long clone_flags,
80389+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80390 unsigned long stack_start,
80391 unsigned long stack_size,
80392 int __user *child_tidptr,
80393@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80394 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80395 #endif
80396 retval = -EAGAIN;
80397+
80398+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80399+
80400 if (atomic_read(&p->real_cred->user->processes) >=
80401 task_rlimit(p, RLIMIT_NPROC)) {
80402 if (p->real_cred->user != INIT_USER &&
80403@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80404 goto bad_fork_free_pid;
80405 }
80406
80407+ /* synchronizes with gr_set_acls()
80408+ we need to call this past the point of no return for fork()
80409+ */
80410+ gr_copy_label(p);
80411+
80412 if (likely(p->pid)) {
80413 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80414
80415@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80416 bad_fork_free:
80417 free_task(p);
80418 fork_out:
80419+ gr_log_forkfail(retval);
80420+
80421 return ERR_PTR(retval);
80422 }
80423
80424@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80425
80426 p = copy_process(clone_flags, stack_start, stack_size,
80427 child_tidptr, NULL, trace);
80428+ add_latent_entropy();
80429 /*
80430 * Do this prior waking up the new thread - the thread pointer
80431 * might get invalid after that point, if the thread exits quickly.
80432@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80433 if (clone_flags & CLONE_PARENT_SETTID)
80434 put_user(nr, parent_tidptr);
80435
80436+ gr_handle_brute_check();
80437+
80438 if (clone_flags & CLONE_VFORK) {
80439 p->vfork_done = &vfork;
80440 init_completion(&vfork);
80441@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80442 mm_cachep = kmem_cache_create("mm_struct",
80443 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80444 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80445- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80446+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80447 mmap_init();
80448 nsproxy_cache_init();
80449 }
80450@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80451 return 0;
80452
80453 /* don't need lock here; in the worst case we'll do useless copy */
80454- if (fs->users == 1)
80455+ if (atomic_read(&fs->users) == 1)
80456 return 0;
80457
80458 *new_fsp = copy_fs_struct(fs);
80459@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80460 fs = current->fs;
80461 spin_lock(&fs->lock);
80462 current->fs = new_fs;
80463- if (--fs->users)
80464+ gr_set_chroot_entries(current, &current->fs->root);
80465+ if (atomic_dec_return(&fs->users))
80466 new_fs = NULL;
80467 else
80468 new_fs = fs;
80469diff --git a/kernel/futex.c b/kernel/futex.c
80470index c3a1a55..e32b4a98 100644
80471--- a/kernel/futex.c
80472+++ b/kernel/futex.c
80473@@ -54,6 +54,7 @@
80474 #include <linux/mount.h>
80475 #include <linux/pagemap.h>
80476 #include <linux/syscalls.h>
80477+#include <linux/ptrace.h>
80478 #include <linux/signal.h>
80479 #include <linux/export.h>
80480 #include <linux/magic.h>
80481@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80482 struct page *page, *page_head;
80483 int err, ro = 0;
80484
80485+#ifdef CONFIG_PAX_SEGMEXEC
80486+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80487+ return -EFAULT;
80488+#endif
80489+
80490 /*
80491 * The futex address must be "naturally" aligned.
80492 */
80493@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80494
80495 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80496 {
80497- int ret;
80498+ unsigned long ret;
80499
80500 pagefault_disable();
80501 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80502@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80503 {
80504 u32 curval;
80505 int i;
80506+ mm_segment_t oldfs;
80507
80508 /*
80509 * This will fail and we want it. Some arch implementations do
80510@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80511 * implementation, the non-functional ones will return
80512 * -ENOSYS.
80513 */
80514+ oldfs = get_fs();
80515+ set_fs(USER_DS);
80516 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80517 futex_cmpxchg_enabled = 1;
80518+ set_fs(oldfs);
80519
80520 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80521 plist_head_init(&futex_queues[i].chain);
80522diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80523index f9f44fd..29885e4 100644
80524--- a/kernel/futex_compat.c
80525+++ b/kernel/futex_compat.c
80526@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80527 return 0;
80528 }
80529
80530-static void __user *futex_uaddr(struct robust_list __user *entry,
80531+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80532 compat_long_t futex_offset)
80533 {
80534 compat_uptr_t base = ptr_to_compat(entry);
80535diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80536index 9b22d03..6295b62 100644
80537--- a/kernel/gcov/base.c
80538+++ b/kernel/gcov/base.c
80539@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80540 }
80541
80542 #ifdef CONFIG_MODULES
80543-static inline int within(void *addr, void *start, unsigned long size)
80544-{
80545- return ((addr >= start) && (addr < start + size));
80546-}
80547-
80548 /* Update list and generate events when modules are unloaded. */
80549 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80550 void *data)
80551@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80552 prev = NULL;
80553 /* Remove entries located in module from linked list. */
80554 for (info = gcov_info_head; info; info = info->next) {
80555- if (within(info, mod->module_core, mod->core_size)) {
80556+ if (within_module_core_rw((unsigned long)info, mod)) {
80557 if (prev)
80558 prev->next = info->next;
80559 else
80560diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80561index 383319b..56ebb13 100644
80562--- a/kernel/hrtimer.c
80563+++ b/kernel/hrtimer.c
80564@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80565 local_irq_restore(flags);
80566 }
80567
80568-static void run_hrtimer_softirq(struct softirq_action *h)
80569+static __latent_entropy void run_hrtimer_softirq(void)
80570 {
80571 hrtimer_peek_ahead_timers();
80572 }
80573diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80574index 55fcce6..0e4cf34 100644
80575--- a/kernel/irq_work.c
80576+++ b/kernel/irq_work.c
80577@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80578 return NOTIFY_OK;
80579 }
80580
80581-static struct notifier_block cpu_notify;
80582+static struct notifier_block cpu_notify = {
80583+ .notifier_call = irq_work_cpu_notify,
80584+ .priority = 0,
80585+};
80586
80587 static __init int irq_work_init_cpu_notifier(void)
80588 {
80589- cpu_notify.notifier_call = irq_work_cpu_notify;
80590- cpu_notify.priority = 0;
80591 register_cpu_notifier(&cpu_notify);
80592 return 0;
80593 }
80594diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80595index 60f48fa..7f3a770 100644
80596--- a/kernel/jump_label.c
80597+++ b/kernel/jump_label.c
80598@@ -13,6 +13,7 @@
80599 #include <linux/sort.h>
80600 #include <linux/err.h>
80601 #include <linux/static_key.h>
80602+#include <linux/mm.h>
80603
80604 #ifdef HAVE_JUMP_LABEL
80605
80606@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80607
80608 size = (((unsigned long)stop - (unsigned long)start)
80609 / sizeof(struct jump_entry));
80610+ pax_open_kernel();
80611 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80612+ pax_close_kernel();
80613 }
80614
80615 static void jump_label_update(struct static_key *key, int enable);
80616@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80617 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80618 struct jump_entry *iter;
80619
80620+ pax_open_kernel();
80621 for (iter = iter_start; iter < iter_stop; iter++) {
80622 if (within_module_init(iter->code, mod))
80623 iter->code = 0;
80624 }
80625+ pax_close_kernel();
80626 }
80627
80628 static int
80629diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80630index 3127ad5..159d880 100644
80631--- a/kernel/kallsyms.c
80632+++ b/kernel/kallsyms.c
80633@@ -11,6 +11,9 @@
80634 * Changed the compression method from stem compression to "table lookup"
80635 * compression (see scripts/kallsyms.c for a more complete description)
80636 */
80637+#ifdef CONFIG_GRKERNSEC_HIDESYM
80638+#define __INCLUDED_BY_HIDESYM 1
80639+#endif
80640 #include <linux/kallsyms.h>
80641 #include <linux/module.h>
80642 #include <linux/init.h>
80643@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80644
80645 static inline int is_kernel_inittext(unsigned long addr)
80646 {
80647+ if (system_state != SYSTEM_BOOTING)
80648+ return 0;
80649+
80650 if (addr >= (unsigned long)_sinittext
80651 && addr <= (unsigned long)_einittext)
80652 return 1;
80653 return 0;
80654 }
80655
80656+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80657+#ifdef CONFIG_MODULES
80658+static inline int is_module_text(unsigned long addr)
80659+{
80660+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80661+ return 1;
80662+
80663+ addr = ktla_ktva(addr);
80664+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80665+}
80666+#else
80667+static inline int is_module_text(unsigned long addr)
80668+{
80669+ return 0;
80670+}
80671+#endif
80672+#endif
80673+
80674 static inline int is_kernel_text(unsigned long addr)
80675 {
80676 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80677@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80678
80679 static inline int is_kernel(unsigned long addr)
80680 {
80681+
80682+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80683+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80684+ return 1;
80685+
80686+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80687+#else
80688 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80689+#endif
80690+
80691 return 1;
80692 return in_gate_area_no_mm(addr);
80693 }
80694
80695 static int is_ksym_addr(unsigned long addr)
80696 {
80697+
80698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80699+ if (is_module_text(addr))
80700+ return 0;
80701+#endif
80702+
80703 if (all_var)
80704 return is_kernel(addr);
80705
80706@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80707
80708 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80709 {
80710- iter->name[0] = '\0';
80711 iter->nameoff = get_symbol_offset(new_pos);
80712 iter->pos = new_pos;
80713 }
80714@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80715 {
80716 struct kallsym_iter *iter = m->private;
80717
80718+#ifdef CONFIG_GRKERNSEC_HIDESYM
80719+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80720+ return 0;
80721+#endif
80722+
80723 /* Some debugging symbols have no name. Ignore them. */
80724 if (!iter->name[0])
80725 return 0;
80726@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80727 */
80728 type = iter->exported ? toupper(iter->type) :
80729 tolower(iter->type);
80730+
80731 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80732 type, iter->name, iter->module_name);
80733 } else
80734@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80735 struct kallsym_iter *iter;
80736 int ret;
80737
80738- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80739+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80740 if (!iter)
80741 return -ENOMEM;
80742 reset_iter(iter, 0);
80743diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80744index e30ac0f..3528cac 100644
80745--- a/kernel/kcmp.c
80746+++ b/kernel/kcmp.c
80747@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80748 struct task_struct *task1, *task2;
80749 int ret;
80750
80751+#ifdef CONFIG_GRKERNSEC
80752+ return -ENOSYS;
80753+#endif
80754+
80755 rcu_read_lock();
80756
80757 /*
80758diff --git a/kernel/kexec.c b/kernel/kexec.c
80759index 59f7b55..4022f65 100644
80760--- a/kernel/kexec.c
80761+++ b/kernel/kexec.c
80762@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80763 unsigned long flags)
80764 {
80765 struct compat_kexec_segment in;
80766- struct kexec_segment out, __user *ksegments;
80767+ struct kexec_segment out;
80768+ struct kexec_segment __user *ksegments;
80769 unsigned long i, result;
80770
80771 /* Don't allow clients that don't understand the native
80772diff --git a/kernel/kmod.c b/kernel/kmod.c
80773index b086006..a27913b 100644
80774--- a/kernel/kmod.c
80775+++ b/kernel/kmod.c
80776@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80777 kfree(info->argv);
80778 }
80779
80780-static int call_modprobe(char *module_name, int wait)
80781+static int call_modprobe(char *module_name, char *module_param, int wait)
80782 {
80783 struct subprocess_info *info;
80784 static char *envp[] = {
80785@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80786 NULL
80787 };
80788
80789- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80790+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80791 if (!argv)
80792 goto out;
80793
80794@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80795 argv[1] = "-q";
80796 argv[2] = "--";
80797 argv[3] = module_name; /* check free_modprobe_argv() */
80798- argv[4] = NULL;
80799+ argv[4] = module_param;
80800+ argv[5] = NULL;
80801
80802 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80803 NULL, free_modprobe_argv, NULL);
80804@@ -129,9 +130,8 @@ out:
80805 * If module auto-loading support is disabled then this function
80806 * becomes a no-operation.
80807 */
80808-int __request_module(bool wait, const char *fmt, ...)
80809+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80810 {
80811- va_list args;
80812 char module_name[MODULE_NAME_LEN];
80813 unsigned int max_modprobes;
80814 int ret;
80815@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80816 if (!modprobe_path[0])
80817 return 0;
80818
80819- va_start(args, fmt);
80820- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80821- va_end(args);
80822+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80823 if (ret >= MODULE_NAME_LEN)
80824 return -ENAMETOOLONG;
80825
80826@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80827 if (ret)
80828 return ret;
80829
80830+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80831+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80832+ /* hack to workaround consolekit/udisks stupidity */
80833+ read_lock(&tasklist_lock);
80834+ if (!strcmp(current->comm, "mount") &&
80835+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80836+ read_unlock(&tasklist_lock);
80837+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80838+ return -EPERM;
80839+ }
80840+ read_unlock(&tasklist_lock);
80841+ }
80842+#endif
80843+
80844 /* If modprobe needs a service that is in a module, we get a recursive
80845 * loop. Limit the number of running kmod threads to max_threads/2 or
80846 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80847@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80848
80849 trace_module_request(module_name, wait, _RET_IP_);
80850
80851- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80852+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80853
80854 atomic_dec(&kmod_concurrent);
80855 return ret;
80856 }
80857+
80858+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80859+{
80860+ va_list args;
80861+ int ret;
80862+
80863+ va_start(args, fmt);
80864+ ret = ____request_module(wait, module_param, fmt, args);
80865+ va_end(args);
80866+
80867+ return ret;
80868+}
80869+
80870+int __request_module(bool wait, const char *fmt, ...)
80871+{
80872+ va_list args;
80873+ int ret;
80874+
80875+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80876+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80877+ char module_param[MODULE_NAME_LEN];
80878+
80879+ memset(module_param, 0, sizeof(module_param));
80880+
80881+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80882+
80883+ va_start(args, fmt);
80884+ ret = ____request_module(wait, module_param, fmt, args);
80885+ va_end(args);
80886+
80887+ return ret;
80888+ }
80889+#endif
80890+
80891+ va_start(args, fmt);
80892+ ret = ____request_module(wait, NULL, fmt, args);
80893+ va_end(args);
80894+
80895+ return ret;
80896+}
80897+
80898 EXPORT_SYMBOL(__request_module);
80899 #endif /* CONFIG_MODULES */
80900
80901@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
80902 *
80903 * Thus the __user pointer cast is valid here.
80904 */
80905- sys_wait4(pid, (int __user *)&ret, 0, NULL);
80906+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
80907
80908 /*
80909 * If ret is 0, either ____call_usermodehelper failed and the
80910@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
80911 static int proc_cap_handler(struct ctl_table *table, int write,
80912 void __user *buffer, size_t *lenp, loff_t *ppos)
80913 {
80914- struct ctl_table t;
80915+ ctl_table_no_const t;
80916 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
80917 kernel_cap_t new_cap;
80918 int err, i;
80919diff --git a/kernel/kprobes.c b/kernel/kprobes.c
80920index 6e33498..3133bd3 100644
80921--- a/kernel/kprobes.c
80922+++ b/kernel/kprobes.c
80923@@ -31,6 +31,9 @@
80924 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
80925 * <prasanna@in.ibm.com> added function-return probes.
80926 */
80927+#ifdef CONFIG_GRKERNSEC_HIDESYM
80928+#define __INCLUDED_BY_HIDESYM 1
80929+#endif
80930 #include <linux/kprobes.h>
80931 #include <linux/hash.h>
80932 #include <linux/init.h>
80933@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
80934 * kernel image and loaded module images reside. This is required
80935 * so x86_64 can correctly handle the %rip-relative fixups.
80936 */
80937- kip->insns = module_alloc(PAGE_SIZE);
80938+ kip->insns = module_alloc_exec(PAGE_SIZE);
80939 if (!kip->insns) {
80940 kfree(kip);
80941 return NULL;
80942@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
80943 */
80944 if (!list_is_singular(&kip->list)) {
80945 list_del(&kip->list);
80946- module_free(NULL, kip->insns);
80947+ module_free_exec(NULL, kip->insns);
80948 kfree(kip);
80949 }
80950 return 1;
80951@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
80952 {
80953 int i, err = 0;
80954 unsigned long offset = 0, size = 0;
80955- char *modname, namebuf[128];
80956+ char *modname, namebuf[KSYM_NAME_LEN];
80957 const char *symbol_name;
80958 void *addr;
80959 struct kprobe_blackpoint *kb;
80960@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
80961 kprobe_type = "k";
80962
80963 if (sym)
80964- seq_printf(pi, "%p %s %s+0x%x %s ",
80965+ seq_printf(pi, "%pK %s %s+0x%x %s ",
80966 p->addr, kprobe_type, sym, offset,
80967 (modname ? modname : " "));
80968 else
80969- seq_printf(pi, "%p %s %p ",
80970+ seq_printf(pi, "%pK %s %pK ",
80971 p->addr, kprobe_type, p->addr);
80972
80973 if (!pp)
80974@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
80975 const char *sym = NULL;
80976 unsigned int i = *(loff_t *) v;
80977 unsigned long offset = 0;
80978- char *modname, namebuf[128];
80979+ char *modname, namebuf[KSYM_NAME_LEN];
80980
80981 head = &kprobe_table[i];
80982 preempt_disable();
80983diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
80984index 6ada93c..dce7d5d 100644
80985--- a/kernel/ksysfs.c
80986+++ b/kernel/ksysfs.c
80987@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
80988 {
80989 if (count+1 > UEVENT_HELPER_PATH_LEN)
80990 return -ENOENT;
80991+ if (!capable(CAP_SYS_ADMIN))
80992+ return -EPERM;
80993 memcpy(uevent_helper, buf, count);
80994 uevent_helper[count] = '\0';
80995 if (count && uevent_helper[count-1] == '\n')
80996@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
80997 return count;
80998 }
80999
81000-static struct bin_attribute notes_attr = {
81001+static bin_attribute_no_const notes_attr __read_only = {
81002 .attr = {
81003 .name = "notes",
81004 .mode = S_IRUGO,
81005diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81006index e16c45b..6f49c48 100644
81007--- a/kernel/lockdep.c
81008+++ b/kernel/lockdep.c
81009@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81010 end = (unsigned long) &_end,
81011 addr = (unsigned long) obj;
81012
81013+#ifdef CONFIG_PAX_KERNEXEC
81014+ start = ktla_ktva(start);
81015+#endif
81016+
81017 /*
81018 * static variable?
81019 */
81020@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81021 if (!static_obj(lock->key)) {
81022 debug_locks_off();
81023 printk("INFO: trying to register non-static key.\n");
81024+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81025 printk("the code is fine but needs lockdep annotation.\n");
81026 printk("turning off the locking correctness validator.\n");
81027 dump_stack();
81028@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81029 if (!class)
81030 return 0;
81031 }
81032- atomic_inc((atomic_t *)&class->ops);
81033+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81034 if (very_verbose(class)) {
81035 printk("\nacquire class [%p] %s", class->key, class->name);
81036 if (class->name_version > 1)
81037diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81038index b2c71c5..7b88d63 100644
81039--- a/kernel/lockdep_proc.c
81040+++ b/kernel/lockdep_proc.c
81041@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81042 return 0;
81043 }
81044
81045- seq_printf(m, "%p", class->key);
81046+ seq_printf(m, "%pK", class->key);
81047 #ifdef CONFIG_DEBUG_LOCKDEP
81048 seq_printf(m, " OPS:%8ld", class->ops);
81049 #endif
81050@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81051
81052 list_for_each_entry(entry, &class->locks_after, entry) {
81053 if (entry->distance == 1) {
81054- seq_printf(m, " -> [%p] ", entry->class->key);
81055+ seq_printf(m, " -> [%pK] ", entry->class->key);
81056 print_name(m, entry->class);
81057 seq_puts(m, "\n");
81058 }
81059@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81060 if (!class->key)
81061 continue;
81062
81063- seq_printf(m, "[%p] ", class->key);
81064+ seq_printf(m, "[%pK] ", class->key);
81065 print_name(m, class);
81066 seq_puts(m, "\n");
81067 }
81068@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81069 if (!i)
81070 seq_line(m, '-', 40-namelen, namelen);
81071
81072- snprintf(ip, sizeof(ip), "[<%p>]",
81073+ snprintf(ip, sizeof(ip), "[<%pK>]",
81074 (void *)class->contention_point[i]);
81075 seq_printf(m, "%40s %14lu %29s %pS\n",
81076 name, stats->contention_point[i],
81077@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81078 if (!i)
81079 seq_line(m, '-', 40-namelen, namelen);
81080
81081- snprintf(ip, sizeof(ip), "[<%p>]",
81082+ snprintf(ip, sizeof(ip), "[<%pK>]",
81083 (void *)class->contending_point[i]);
81084 seq_printf(m, "%40s %14lu %29s %pS\n",
81085 name, stats->contending_point[i],
81086diff --git a/kernel/module.c b/kernel/module.c
81087index 2069158..71101bb 100644
81088--- a/kernel/module.c
81089+++ b/kernel/module.c
81090@@ -61,6 +61,7 @@
81091 #include <linux/pfn.h>
81092 #include <linux/bsearch.h>
81093 #include <linux/fips.h>
81094+#include <linux/grsecurity.h>
81095 #include <uapi/linux/module.h>
81096 #include "module-internal.h"
81097
81098@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81099
81100 /* Bounds of module allocation, for speeding __module_address.
81101 * Protected by module_mutex. */
81102-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81103+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81104+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81105
81106 int register_module_notifier(struct notifier_block * nb)
81107 {
81108@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81109 return true;
81110
81111 list_for_each_entry_rcu(mod, &modules, list) {
81112- struct symsearch arr[] = {
81113+ struct symsearch modarr[] = {
81114 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81115 NOT_GPL_ONLY, false },
81116 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81117@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81118 if (mod->state == MODULE_STATE_UNFORMED)
81119 continue;
81120
81121- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81122+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81123 return true;
81124 }
81125 return false;
81126@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81127 if (!pcpusec->sh_size)
81128 return 0;
81129
81130- if (align > PAGE_SIZE) {
81131+ if (align-1 >= PAGE_SIZE) {
81132 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81133 mod->name, align, PAGE_SIZE);
81134 align = PAGE_SIZE;
81135@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81136 static ssize_t show_coresize(struct module_attribute *mattr,
81137 struct module_kobject *mk, char *buffer)
81138 {
81139- return sprintf(buffer, "%u\n", mk->mod->core_size);
81140+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81141 }
81142
81143 static struct module_attribute modinfo_coresize =
81144@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81145 static ssize_t show_initsize(struct module_attribute *mattr,
81146 struct module_kobject *mk, char *buffer)
81147 {
81148- return sprintf(buffer, "%u\n", mk->mod->init_size);
81149+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81150 }
81151
81152 static struct module_attribute modinfo_initsize =
81153@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81154 */
81155 #ifdef CONFIG_SYSFS
81156
81157-#ifdef CONFIG_KALLSYMS
81158+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81159 static inline bool sect_empty(const Elf_Shdr *sect)
81160 {
81161 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81162@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81163 {
81164 unsigned int notes, loaded, i;
81165 struct module_notes_attrs *notes_attrs;
81166- struct bin_attribute *nattr;
81167+ bin_attribute_no_const *nattr;
81168
81169 /* failed to create section attributes, so can't create notes */
81170 if (!mod->sect_attrs)
81171@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81172 static int module_add_modinfo_attrs(struct module *mod)
81173 {
81174 struct module_attribute *attr;
81175- struct module_attribute *temp_attr;
81176+ module_attribute_no_const *temp_attr;
81177 int error = 0;
81178 int i;
81179
81180@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81181
81182 static void unset_module_core_ro_nx(struct module *mod)
81183 {
81184- set_page_attributes(mod->module_core + mod->core_text_size,
81185- mod->module_core + mod->core_size,
81186+ set_page_attributes(mod->module_core_rw,
81187+ mod->module_core_rw + mod->core_size_rw,
81188 set_memory_x);
81189- set_page_attributes(mod->module_core,
81190- mod->module_core + mod->core_ro_size,
81191+ set_page_attributes(mod->module_core_rx,
81192+ mod->module_core_rx + mod->core_size_rx,
81193 set_memory_rw);
81194 }
81195
81196 static void unset_module_init_ro_nx(struct module *mod)
81197 {
81198- set_page_attributes(mod->module_init + mod->init_text_size,
81199- mod->module_init + mod->init_size,
81200+ set_page_attributes(mod->module_init_rw,
81201+ mod->module_init_rw + mod->init_size_rw,
81202 set_memory_x);
81203- set_page_attributes(mod->module_init,
81204- mod->module_init + mod->init_ro_size,
81205+ set_page_attributes(mod->module_init_rx,
81206+ mod->module_init_rx + mod->init_size_rx,
81207 set_memory_rw);
81208 }
81209
81210@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81211 list_for_each_entry_rcu(mod, &modules, list) {
81212 if (mod->state == MODULE_STATE_UNFORMED)
81213 continue;
81214- if ((mod->module_core) && (mod->core_text_size)) {
81215- set_page_attributes(mod->module_core,
81216- mod->module_core + mod->core_text_size,
81217+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81218+ set_page_attributes(mod->module_core_rx,
81219+ mod->module_core_rx + mod->core_size_rx,
81220 set_memory_rw);
81221 }
81222- if ((mod->module_init) && (mod->init_text_size)) {
81223- set_page_attributes(mod->module_init,
81224- mod->module_init + mod->init_text_size,
81225+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81226+ set_page_attributes(mod->module_init_rx,
81227+ mod->module_init_rx + mod->init_size_rx,
81228 set_memory_rw);
81229 }
81230 }
81231@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81232 list_for_each_entry_rcu(mod, &modules, list) {
81233 if (mod->state == MODULE_STATE_UNFORMED)
81234 continue;
81235- if ((mod->module_core) && (mod->core_text_size)) {
81236- set_page_attributes(mod->module_core,
81237- mod->module_core + mod->core_text_size,
81238+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81239+ set_page_attributes(mod->module_core_rx,
81240+ mod->module_core_rx + mod->core_size_rx,
81241 set_memory_ro);
81242 }
81243- if ((mod->module_init) && (mod->init_text_size)) {
81244- set_page_attributes(mod->module_init,
81245- mod->module_init + mod->init_text_size,
81246+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81247+ set_page_attributes(mod->module_init_rx,
81248+ mod->module_init_rx + mod->init_size_rx,
81249 set_memory_ro);
81250 }
81251 }
81252@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81253
81254 /* This may be NULL, but that's OK */
81255 unset_module_init_ro_nx(mod);
81256- module_free(mod, mod->module_init);
81257+ module_free(mod, mod->module_init_rw);
81258+ module_free_exec(mod, mod->module_init_rx);
81259 kfree(mod->args);
81260 percpu_modfree(mod);
81261
81262 /* Free lock-classes: */
81263- lockdep_free_key_range(mod->module_core, mod->core_size);
81264+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81265+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81266
81267 /* Finally, free the core (containing the module structure) */
81268 unset_module_core_ro_nx(mod);
81269- module_free(mod, mod->module_core);
81270+ module_free_exec(mod, mod->module_core_rx);
81271+ module_free(mod, mod->module_core_rw);
81272
81273 #ifdef CONFIG_MPU
81274 update_protections(current->mm);
81275@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81276 int ret = 0;
81277 const struct kernel_symbol *ksym;
81278
81279+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81280+ int is_fs_load = 0;
81281+ int register_filesystem_found = 0;
81282+ char *p;
81283+
81284+ p = strstr(mod->args, "grsec_modharden_fs");
81285+ if (p) {
81286+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81287+ /* copy \0 as well */
81288+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81289+ is_fs_load = 1;
81290+ }
81291+#endif
81292+
81293 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81294 const char *name = info->strtab + sym[i].st_name;
81295
81296+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81297+ /* it's a real shame this will never get ripped and copied
81298+ upstream! ;(
81299+ */
81300+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81301+ register_filesystem_found = 1;
81302+#endif
81303+
81304 switch (sym[i].st_shndx) {
81305 case SHN_COMMON:
81306 /* We compiled with -fno-common. These are not
81307@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81308 ksym = resolve_symbol_wait(mod, info, name);
81309 /* Ok if resolved. */
81310 if (ksym && !IS_ERR(ksym)) {
81311+ pax_open_kernel();
81312 sym[i].st_value = ksym->value;
81313+ pax_close_kernel();
81314 break;
81315 }
81316
81317@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81318 secbase = (unsigned long)mod_percpu(mod);
81319 else
81320 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81321+ pax_open_kernel();
81322 sym[i].st_value += secbase;
81323+ pax_close_kernel();
81324 break;
81325 }
81326 }
81327
81328+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81329+ if (is_fs_load && !register_filesystem_found) {
81330+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81331+ ret = -EPERM;
81332+ }
81333+#endif
81334+
81335 return ret;
81336 }
81337
81338@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81339 || s->sh_entsize != ~0UL
81340 || strstarts(sname, ".init"))
81341 continue;
81342- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81343+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81344+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81345+ else
81346+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81347 pr_debug("\t%s\n", sname);
81348 }
81349- switch (m) {
81350- case 0: /* executable */
81351- mod->core_size = debug_align(mod->core_size);
81352- mod->core_text_size = mod->core_size;
81353- break;
81354- case 1: /* RO: text and ro-data */
81355- mod->core_size = debug_align(mod->core_size);
81356- mod->core_ro_size = mod->core_size;
81357- break;
81358- case 3: /* whole core */
81359- mod->core_size = debug_align(mod->core_size);
81360- break;
81361- }
81362 }
81363
81364 pr_debug("Init section allocation order:\n");
81365@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81366 || s->sh_entsize != ~0UL
81367 || !strstarts(sname, ".init"))
81368 continue;
81369- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81370- | INIT_OFFSET_MASK);
81371+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81372+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81373+ else
81374+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81375+ s->sh_entsize |= INIT_OFFSET_MASK;
81376 pr_debug("\t%s\n", sname);
81377 }
81378- switch (m) {
81379- case 0: /* executable */
81380- mod->init_size = debug_align(mod->init_size);
81381- mod->init_text_size = mod->init_size;
81382- break;
81383- case 1: /* RO: text and ro-data */
81384- mod->init_size = debug_align(mod->init_size);
81385- mod->init_ro_size = mod->init_size;
81386- break;
81387- case 3: /* whole init */
81388- mod->init_size = debug_align(mod->init_size);
81389- break;
81390- }
81391 }
81392 }
81393
81394@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81395
81396 /* Put symbol section at end of init part of module. */
81397 symsect->sh_flags |= SHF_ALLOC;
81398- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81399+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81400 info->index.sym) | INIT_OFFSET_MASK;
81401 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81402
81403@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81404 }
81405
81406 /* Append room for core symbols at end of core part. */
81407- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81408- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81409- mod->core_size += strtab_size;
81410+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81411+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81412+ mod->core_size_rx += strtab_size;
81413
81414 /* Put string table section at end of init part of module. */
81415 strsect->sh_flags |= SHF_ALLOC;
81416- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81417+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81418 info->index.str) | INIT_OFFSET_MASK;
81419 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81420 }
81421@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81422 /* Make sure we get permanent strtab: don't use info->strtab. */
81423 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81424
81425+ pax_open_kernel();
81426+
81427 /* Set types up while we still have access to sections. */
81428 for (i = 0; i < mod->num_symtab; i++)
81429 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81430
81431- mod->core_symtab = dst = mod->module_core + info->symoffs;
81432- mod->core_strtab = s = mod->module_core + info->stroffs;
81433+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81434+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81435 src = mod->symtab;
81436 for (ndst = i = 0; i < mod->num_symtab; i++) {
81437 if (i == 0 ||
81438@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81439 }
81440 }
81441 mod->core_num_syms = ndst;
81442+
81443+ pax_close_kernel();
81444 }
81445 #else
81446 static inline void layout_symtab(struct module *mod, struct load_info *info)
81447@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81448 return vmalloc_exec(size);
81449 }
81450
81451-static void *module_alloc_update_bounds(unsigned long size)
81452+static void *module_alloc_update_bounds_rw(unsigned long size)
81453 {
81454 void *ret = module_alloc(size);
81455
81456 if (ret) {
81457 mutex_lock(&module_mutex);
81458 /* Update module bounds. */
81459- if ((unsigned long)ret < module_addr_min)
81460- module_addr_min = (unsigned long)ret;
81461- if ((unsigned long)ret + size > module_addr_max)
81462- module_addr_max = (unsigned long)ret + size;
81463+ if ((unsigned long)ret < module_addr_min_rw)
81464+ module_addr_min_rw = (unsigned long)ret;
81465+ if ((unsigned long)ret + size > module_addr_max_rw)
81466+ module_addr_max_rw = (unsigned long)ret + size;
81467+ mutex_unlock(&module_mutex);
81468+ }
81469+ return ret;
81470+}
81471+
81472+static void *module_alloc_update_bounds_rx(unsigned long size)
81473+{
81474+ void *ret = module_alloc_exec(size);
81475+
81476+ if (ret) {
81477+ mutex_lock(&module_mutex);
81478+ /* Update module bounds. */
81479+ if ((unsigned long)ret < module_addr_min_rx)
81480+ module_addr_min_rx = (unsigned long)ret;
81481+ if ((unsigned long)ret + size > module_addr_max_rx)
81482+ module_addr_max_rx = (unsigned long)ret + size;
81483 mutex_unlock(&module_mutex);
81484 }
81485 return ret;
81486@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81487 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81488 {
81489 const char *modmagic = get_modinfo(info, "vermagic");
81490+ const char *license = get_modinfo(info, "license");
81491 int err;
81492
81493+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81494+ if (!license || !license_is_gpl_compatible(license))
81495+ return -ENOEXEC;
81496+#endif
81497+
81498 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81499 modmagic = NULL;
81500
81501@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81502 }
81503
81504 /* Set up license info based on the info section */
81505- set_license(mod, get_modinfo(info, "license"));
81506+ set_license(mod, license);
81507
81508 return 0;
81509 }
81510@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81511 void *ptr;
81512
81513 /* Do the allocs. */
81514- ptr = module_alloc_update_bounds(mod->core_size);
81515+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81516 /*
81517 * The pointer to this block is stored in the module structure
81518 * which is inside the block. Just mark it as not being a
81519@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81520 if (!ptr)
81521 return -ENOMEM;
81522
81523- memset(ptr, 0, mod->core_size);
81524- mod->module_core = ptr;
81525+ memset(ptr, 0, mod->core_size_rw);
81526+ mod->module_core_rw = ptr;
81527
81528- if (mod->init_size) {
81529- ptr = module_alloc_update_bounds(mod->init_size);
81530+ if (mod->init_size_rw) {
81531+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81532 /*
81533 * The pointer to this block is stored in the module structure
81534 * which is inside the block. This block doesn't need to be
81535@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81536 */
81537 kmemleak_ignore(ptr);
81538 if (!ptr) {
81539- module_free(mod, mod->module_core);
81540+ module_free(mod, mod->module_core_rw);
81541 return -ENOMEM;
81542 }
81543- memset(ptr, 0, mod->init_size);
81544- mod->module_init = ptr;
81545+ memset(ptr, 0, mod->init_size_rw);
81546+ mod->module_init_rw = ptr;
81547 } else
81548- mod->module_init = NULL;
81549+ mod->module_init_rw = NULL;
81550+
81551+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81552+ kmemleak_not_leak(ptr);
81553+ if (!ptr) {
81554+ if (mod->module_init_rw)
81555+ module_free(mod, mod->module_init_rw);
81556+ module_free(mod, mod->module_core_rw);
81557+ return -ENOMEM;
81558+ }
81559+
81560+ pax_open_kernel();
81561+ memset(ptr, 0, mod->core_size_rx);
81562+ pax_close_kernel();
81563+ mod->module_core_rx = ptr;
81564+
81565+ if (mod->init_size_rx) {
81566+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81567+ kmemleak_ignore(ptr);
81568+ if (!ptr && mod->init_size_rx) {
81569+ module_free_exec(mod, mod->module_core_rx);
81570+ if (mod->module_init_rw)
81571+ module_free(mod, mod->module_init_rw);
81572+ module_free(mod, mod->module_core_rw);
81573+ return -ENOMEM;
81574+ }
81575+
81576+ pax_open_kernel();
81577+ memset(ptr, 0, mod->init_size_rx);
81578+ pax_close_kernel();
81579+ mod->module_init_rx = ptr;
81580+ } else
81581+ mod->module_init_rx = NULL;
81582
81583 /* Transfer each section which specifies SHF_ALLOC */
81584 pr_debug("final section addresses:\n");
81585@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81586 if (!(shdr->sh_flags & SHF_ALLOC))
81587 continue;
81588
81589- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81590- dest = mod->module_init
81591- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81592- else
81593- dest = mod->module_core + shdr->sh_entsize;
81594+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81595+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81596+ dest = mod->module_init_rw
81597+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81598+ else
81599+ dest = mod->module_init_rx
81600+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81601+ } else {
81602+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81603+ dest = mod->module_core_rw + shdr->sh_entsize;
81604+ else
81605+ dest = mod->module_core_rx + shdr->sh_entsize;
81606+ }
81607+
81608+ if (shdr->sh_type != SHT_NOBITS) {
81609+
81610+#ifdef CONFIG_PAX_KERNEXEC
81611+#ifdef CONFIG_X86_64
81612+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81613+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81614+#endif
81615+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81616+ pax_open_kernel();
81617+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81618+ pax_close_kernel();
81619+ } else
81620+#endif
81621
81622- if (shdr->sh_type != SHT_NOBITS)
81623 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81624+ }
81625 /* Update sh_addr to point to copy in image. */
81626- shdr->sh_addr = (unsigned long)dest;
81627+
81628+#ifdef CONFIG_PAX_KERNEXEC
81629+ if (shdr->sh_flags & SHF_EXECINSTR)
81630+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81631+ else
81632+#endif
81633+
81634+ shdr->sh_addr = (unsigned long)dest;
81635 pr_debug("\t0x%lx %s\n",
81636 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81637 }
81638@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81639 * Do it before processing of module parameters, so the module
81640 * can provide parameter accessor functions of its own.
81641 */
81642- if (mod->module_init)
81643- flush_icache_range((unsigned long)mod->module_init,
81644- (unsigned long)mod->module_init
81645- + mod->init_size);
81646- flush_icache_range((unsigned long)mod->module_core,
81647- (unsigned long)mod->module_core + mod->core_size);
81648+ if (mod->module_init_rx)
81649+ flush_icache_range((unsigned long)mod->module_init_rx,
81650+ (unsigned long)mod->module_init_rx
81651+ + mod->init_size_rx);
81652+ flush_icache_range((unsigned long)mod->module_core_rx,
81653+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81654
81655 set_fs(old_fs);
81656 }
81657@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81658 static void module_deallocate(struct module *mod, struct load_info *info)
81659 {
81660 percpu_modfree(mod);
81661- module_free(mod, mod->module_init);
81662- module_free(mod, mod->module_core);
81663+ module_free_exec(mod, mod->module_init_rx);
81664+ module_free_exec(mod, mod->module_core_rx);
81665+ module_free(mod, mod->module_init_rw);
81666+ module_free(mod, mod->module_core_rw);
81667 }
81668
81669 int __weak module_finalize(const Elf_Ehdr *hdr,
81670@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81671 static int post_relocation(struct module *mod, const struct load_info *info)
81672 {
81673 /* Sort exception table now relocations are done. */
81674+ pax_open_kernel();
81675 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81676+ pax_close_kernel();
81677
81678 /* Copy relocated percpu area over. */
81679 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81680@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81681 MODULE_STATE_COMING, mod);
81682
81683 /* Set RO and NX regions for core */
81684- set_section_ro_nx(mod->module_core,
81685- mod->core_text_size,
81686- mod->core_ro_size,
81687- mod->core_size);
81688+ set_section_ro_nx(mod->module_core_rx,
81689+ mod->core_size_rx,
81690+ mod->core_size_rx,
81691+ mod->core_size_rx);
81692
81693 /* Set RO and NX regions for init */
81694- set_section_ro_nx(mod->module_init,
81695- mod->init_text_size,
81696- mod->init_ro_size,
81697- mod->init_size);
81698+ set_section_ro_nx(mod->module_init_rx,
81699+ mod->init_size_rx,
81700+ mod->init_size_rx,
81701+ mod->init_size_rx);
81702
81703 do_mod_ctors(mod);
81704 /* Start the module */
81705@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81706 mod->strtab = mod->core_strtab;
81707 #endif
81708 unset_module_init_ro_nx(mod);
81709- module_free(mod, mod->module_init);
81710- mod->module_init = NULL;
81711- mod->init_size = 0;
81712- mod->init_ro_size = 0;
81713- mod->init_text_size = 0;
81714+ module_free(mod, mod->module_init_rw);
81715+ module_free_exec(mod, mod->module_init_rx);
81716+ mod->module_init_rw = NULL;
81717+ mod->module_init_rx = NULL;
81718+ mod->init_size_rw = 0;
81719+ mod->init_size_rx = 0;
81720 mutex_unlock(&module_mutex);
81721 wake_up_all(&module_wq);
81722
81723@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81724 if (err)
81725 goto free_unload;
81726
81727+ /* Now copy in args */
81728+ mod->args = strndup_user(uargs, ~0UL >> 1);
81729+ if (IS_ERR(mod->args)) {
81730+ err = PTR_ERR(mod->args);
81731+ goto free_unload;
81732+ }
81733+
81734 /* Set up MODINFO_ATTR fields */
81735 setup_modinfo(mod, info);
81736
81737+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81738+ {
81739+ char *p, *p2;
81740+
81741+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81742+ 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);
81743+ err = -EPERM;
81744+ goto free_modinfo;
81745+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81746+ p += sizeof("grsec_modharden_normal") - 1;
81747+ p2 = strstr(p, "_");
81748+ if (p2) {
81749+ *p2 = '\0';
81750+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81751+ *p2 = '_';
81752+ }
81753+ err = -EPERM;
81754+ goto free_modinfo;
81755+ }
81756+ }
81757+#endif
81758+
81759 /* Fix up syms, so that st_value is a pointer to location. */
81760 err = simplify_symbols(mod, info);
81761 if (err < 0)
81762@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81763
81764 flush_module_icache(mod);
81765
81766- /* Now copy in args */
81767- mod->args = strndup_user(uargs, ~0UL >> 1);
81768- if (IS_ERR(mod->args)) {
81769- err = PTR_ERR(mod->args);
81770- goto free_arch_cleanup;
81771- }
81772-
81773 dynamic_debug_setup(info->debug, info->num_debug);
81774
81775 /* Finally it's fully formed, ready to start executing. */
81776@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81777 ddebug_cleanup:
81778 dynamic_debug_remove(info->debug);
81779 synchronize_sched();
81780- kfree(mod->args);
81781- free_arch_cleanup:
81782 module_arch_cleanup(mod);
81783 free_modinfo:
81784 free_modinfo(mod);
81785+ kfree(mod->args);
81786 free_unload:
81787 module_unload_free(mod);
81788 unlink_mod:
81789@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81790 unsigned long nextval;
81791
81792 /* At worse, next value is at end of module */
81793- if (within_module_init(addr, mod))
81794- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81795+ if (within_module_init_rx(addr, mod))
81796+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81797+ else if (within_module_init_rw(addr, mod))
81798+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81799+ else if (within_module_core_rx(addr, mod))
81800+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81801+ else if (within_module_core_rw(addr, mod))
81802+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81803 else
81804- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81805+ return NULL;
81806
81807 /* Scan for closest preceding symbol, and next symbol. (ELF
81808 starts real symbols at 1). */
81809@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81810 return 0;
81811
81812 seq_printf(m, "%s %u",
81813- mod->name, mod->init_size + mod->core_size);
81814+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81815 print_unload_info(m, mod);
81816
81817 /* Informative for users. */
81818@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81819 mod->state == MODULE_STATE_COMING ? "Loading":
81820 "Live");
81821 /* Used by oprofile and other similar tools. */
81822- seq_printf(m, " 0x%pK", mod->module_core);
81823+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81824
81825 /* Taints info */
81826 if (mod->taints)
81827@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81828
81829 static int __init proc_modules_init(void)
81830 {
81831+#ifndef CONFIG_GRKERNSEC_HIDESYM
81832+#ifdef CONFIG_GRKERNSEC_PROC_USER
81833+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81834+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81835+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81836+#else
81837 proc_create("modules", 0, NULL, &proc_modules_operations);
81838+#endif
81839+#else
81840+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81841+#endif
81842 return 0;
81843 }
81844 module_init(proc_modules_init);
81845@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81846 {
81847 struct module *mod;
81848
81849- if (addr < module_addr_min || addr > module_addr_max)
81850+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81851+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81852 return NULL;
81853
81854 list_for_each_entry_rcu(mod, &modules, list) {
81855 if (mod->state == MODULE_STATE_UNFORMED)
81856 continue;
81857- if (within_module_core(addr, mod)
81858- || within_module_init(addr, mod))
81859+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81860 return mod;
81861 }
81862 return NULL;
81863@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81864 */
81865 struct module *__module_text_address(unsigned long addr)
81866 {
81867- struct module *mod = __module_address(addr);
81868+ struct module *mod;
81869+
81870+#ifdef CONFIG_X86_32
81871+ addr = ktla_ktva(addr);
81872+#endif
81873+
81874+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81875+ return NULL;
81876+
81877+ mod = __module_address(addr);
81878+
81879 if (mod) {
81880 /* Make sure it's within the text section. */
81881- if (!within(addr, mod->module_init, mod->init_text_size)
81882- && !within(addr, mod->module_core, mod->core_text_size))
81883+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
81884 mod = NULL;
81885 }
81886 return mod;
81887diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
81888index 7e3443f..b2a1e6b 100644
81889--- a/kernel/mutex-debug.c
81890+++ b/kernel/mutex-debug.c
81891@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
81892 }
81893
81894 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81895- struct thread_info *ti)
81896+ struct task_struct *task)
81897 {
81898 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
81899
81900 /* Mark the current thread as blocked on the lock: */
81901- ti->task->blocked_on = waiter;
81902+ task->blocked_on = waiter;
81903 }
81904
81905 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81906- struct thread_info *ti)
81907+ struct task_struct *task)
81908 {
81909 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
81910- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
81911- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
81912- ti->task->blocked_on = NULL;
81913+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
81914+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
81915+ task->blocked_on = NULL;
81916
81917 list_del_init(&waiter->list);
81918 waiter->task = NULL;
81919diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
81920index 0799fd3..d06ae3b 100644
81921--- a/kernel/mutex-debug.h
81922+++ b/kernel/mutex-debug.h
81923@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
81924 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
81925 extern void debug_mutex_add_waiter(struct mutex *lock,
81926 struct mutex_waiter *waiter,
81927- struct thread_info *ti);
81928+ struct task_struct *task);
81929 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81930- struct thread_info *ti);
81931+ struct task_struct *task);
81932 extern void debug_mutex_unlock(struct mutex *lock);
81933 extern void debug_mutex_init(struct mutex *lock, const char *name,
81934 struct lock_class_key *key);
81935diff --git a/kernel/mutex.c b/kernel/mutex.c
81936index a52ee7bb..f361f16 100644
81937--- a/kernel/mutex.c
81938+++ b/kernel/mutex.c
81939@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
81940 node->locked = 1;
81941 return;
81942 }
81943- ACCESS_ONCE(prev->next) = node;
81944+ ACCESS_ONCE_RW(prev->next) = node;
81945 smp_wmb();
81946 /* Wait until the lock holder passes the lock down */
81947 while (!ACCESS_ONCE(node->locked))
81948@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
81949 while (!(next = ACCESS_ONCE(node->next)))
81950 arch_mutex_cpu_relax();
81951 }
81952- ACCESS_ONCE(next->locked) = 1;
81953+ ACCESS_ONCE_RW(next->locked) = 1;
81954 smp_wmb();
81955 }
81956
81957@@ -514,7 +514,7 @@ slowpath:
81958 spin_lock_mutex(&lock->wait_lock, flags);
81959
81960 debug_mutex_lock_common(lock, &waiter);
81961- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
81962+ debug_mutex_add_waiter(lock, &waiter, task);
81963
81964 /* add waiting tasks to the end of the waitqueue (FIFO): */
81965 list_add_tail(&waiter.list, &lock->wait_list);
81966@@ -565,7 +565,7 @@ slowpath:
81967 done:
81968 lock_acquired(&lock->dep_map, ip);
81969 /* got the lock - rejoice! */
81970- mutex_remove_waiter(lock, &waiter, current_thread_info());
81971+ mutex_remove_waiter(lock, &waiter, task);
81972 mutex_set_owner(lock);
81973
81974 if (!__builtin_constant_p(ww_ctx == NULL)) {
81975@@ -604,7 +604,7 @@ done:
81976 return 0;
81977
81978 err:
81979- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
81980+ mutex_remove_waiter(lock, &waiter, task);
81981 spin_unlock_mutex(&lock->wait_lock, flags);
81982 debug_mutex_free_waiter(&waiter);
81983 mutex_release(&lock->dep_map, 1, ip);
81984diff --git a/kernel/notifier.c b/kernel/notifier.c
81985index 2d5cc4c..d9ea600 100644
81986--- a/kernel/notifier.c
81987+++ b/kernel/notifier.c
81988@@ -5,6 +5,7 @@
81989 #include <linux/rcupdate.h>
81990 #include <linux/vmalloc.h>
81991 #include <linux/reboot.h>
81992+#include <linux/mm.h>
81993
81994 /*
81995 * Notifier list for kernel code which wants to be called
81996@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
81997 while ((*nl) != NULL) {
81998 if (n->priority > (*nl)->priority)
81999 break;
82000- nl = &((*nl)->next);
82001+ nl = (struct notifier_block **)&((*nl)->next);
82002 }
82003- n->next = *nl;
82004+ pax_open_kernel();
82005+ *(const void **)&n->next = *nl;
82006 rcu_assign_pointer(*nl, n);
82007+ pax_close_kernel();
82008 return 0;
82009 }
82010
82011@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82012 return 0;
82013 if (n->priority > (*nl)->priority)
82014 break;
82015- nl = &((*nl)->next);
82016+ nl = (struct notifier_block **)&((*nl)->next);
82017 }
82018- n->next = *nl;
82019+ pax_open_kernel();
82020+ *(const void **)&n->next = *nl;
82021 rcu_assign_pointer(*nl, n);
82022+ pax_close_kernel();
82023 return 0;
82024 }
82025
82026@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82027 {
82028 while ((*nl) != NULL) {
82029 if ((*nl) == n) {
82030+ pax_open_kernel();
82031 rcu_assign_pointer(*nl, n->next);
82032+ pax_close_kernel();
82033 return 0;
82034 }
82035- nl = &((*nl)->next);
82036+ nl = (struct notifier_block **)&((*nl)->next);
82037 }
82038 return -ENOENT;
82039 }
82040diff --git a/kernel/panic.c b/kernel/panic.c
82041index 8018646..b6a5b4f 100644
82042--- a/kernel/panic.c
82043+++ b/kernel/panic.c
82044@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82045 disable_trace_on_warning();
82046
82047 pr_warn("------------[ cut here ]------------\n");
82048- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82049+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82050 raw_smp_processor_id(), current->pid, file, line, caller);
82051
82052 if (args)
82053@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82054 */
82055 void __stack_chk_fail(void)
82056 {
82057- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82058+ dump_stack();
82059+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82060 __builtin_return_address(0));
82061 }
82062 EXPORT_SYMBOL(__stack_chk_fail);
82063diff --git a/kernel/pid.c b/kernel/pid.c
82064index ebe5e80..5d6d634 100644
82065--- a/kernel/pid.c
82066+++ b/kernel/pid.c
82067@@ -33,6 +33,7 @@
82068 #include <linux/rculist.h>
82069 #include <linux/bootmem.h>
82070 #include <linux/hash.h>
82071+#include <linux/security.h>
82072 #include <linux/pid_namespace.h>
82073 #include <linux/init_task.h>
82074 #include <linux/syscalls.h>
82075@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82076
82077 int pid_max = PID_MAX_DEFAULT;
82078
82079-#define RESERVED_PIDS 300
82080+#define RESERVED_PIDS 500
82081
82082 int pid_max_min = RESERVED_PIDS + 1;
82083 int pid_max_max = PID_MAX_LIMIT;
82084@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82085 */
82086 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82087 {
82088+ struct task_struct *task;
82089+
82090 rcu_lockdep_assert(rcu_read_lock_held(),
82091 "find_task_by_pid_ns() needs rcu_read_lock()"
82092 " protection");
82093- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82094+
82095+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82096+
82097+ if (gr_pid_is_chrooted(task))
82098+ return NULL;
82099+
82100+ return task;
82101 }
82102
82103 struct task_struct *find_task_by_vpid(pid_t vnr)
82104@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82105 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82106 }
82107
82108+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82109+{
82110+ rcu_lockdep_assert(rcu_read_lock_held(),
82111+ "find_task_by_pid_ns() needs rcu_read_lock()"
82112+ " protection");
82113+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82114+}
82115+
82116 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82117 {
82118 struct pid *pid;
82119diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82120index 601bb36..f7e6f34 100644
82121--- a/kernel/pid_namespace.c
82122+++ b/kernel/pid_namespace.c
82123@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82124 void __user *buffer, size_t *lenp, loff_t *ppos)
82125 {
82126 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82127- struct ctl_table tmp = *table;
82128+ ctl_table_no_const tmp = *table;
82129
82130 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82131 return -EPERM;
82132diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82133index c7f31aa..2b44977 100644
82134--- a/kernel/posix-cpu-timers.c
82135+++ b/kernel/posix-cpu-timers.c
82136@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82137
82138 static __init int init_posix_cpu_timers(void)
82139 {
82140- struct k_clock process = {
82141+ static struct k_clock process = {
82142 .clock_getres = process_cpu_clock_getres,
82143 .clock_get = process_cpu_clock_get,
82144 .timer_create = process_cpu_timer_create,
82145 .nsleep = process_cpu_nsleep,
82146 .nsleep_restart = process_cpu_nsleep_restart,
82147 };
82148- struct k_clock thread = {
82149+ static struct k_clock thread = {
82150 .clock_getres = thread_cpu_clock_getres,
82151 .clock_get = thread_cpu_clock_get,
82152 .timer_create = thread_cpu_timer_create,
82153diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82154index 424c2d4..679242f 100644
82155--- a/kernel/posix-timers.c
82156+++ b/kernel/posix-timers.c
82157@@ -43,6 +43,7 @@
82158 #include <linux/hash.h>
82159 #include <linux/posix-clock.h>
82160 #include <linux/posix-timers.h>
82161+#include <linux/grsecurity.h>
82162 #include <linux/syscalls.h>
82163 #include <linux/wait.h>
82164 #include <linux/workqueue.h>
82165@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82166 * which we beg off on and pass to do_sys_settimeofday().
82167 */
82168
82169-static struct k_clock posix_clocks[MAX_CLOCKS];
82170+static struct k_clock *posix_clocks[MAX_CLOCKS];
82171
82172 /*
82173 * These ones are defined below.
82174@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82175 */
82176 static __init int init_posix_timers(void)
82177 {
82178- struct k_clock clock_realtime = {
82179+ static struct k_clock clock_realtime = {
82180 .clock_getres = hrtimer_get_res,
82181 .clock_get = posix_clock_realtime_get,
82182 .clock_set = posix_clock_realtime_set,
82183@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82184 .timer_get = common_timer_get,
82185 .timer_del = common_timer_del,
82186 };
82187- struct k_clock clock_monotonic = {
82188+ static struct k_clock clock_monotonic = {
82189 .clock_getres = hrtimer_get_res,
82190 .clock_get = posix_ktime_get_ts,
82191 .nsleep = common_nsleep,
82192@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82193 .timer_get = common_timer_get,
82194 .timer_del = common_timer_del,
82195 };
82196- struct k_clock clock_monotonic_raw = {
82197+ static struct k_clock clock_monotonic_raw = {
82198 .clock_getres = hrtimer_get_res,
82199 .clock_get = posix_get_monotonic_raw,
82200 };
82201- struct k_clock clock_realtime_coarse = {
82202+ static struct k_clock clock_realtime_coarse = {
82203 .clock_getres = posix_get_coarse_res,
82204 .clock_get = posix_get_realtime_coarse,
82205 };
82206- struct k_clock clock_monotonic_coarse = {
82207+ static struct k_clock clock_monotonic_coarse = {
82208 .clock_getres = posix_get_coarse_res,
82209 .clock_get = posix_get_monotonic_coarse,
82210 };
82211- struct k_clock clock_tai = {
82212+ static struct k_clock clock_tai = {
82213 .clock_getres = hrtimer_get_res,
82214 .clock_get = posix_get_tai,
82215 .nsleep = common_nsleep,
82216@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82217 .timer_get = common_timer_get,
82218 .timer_del = common_timer_del,
82219 };
82220- struct k_clock clock_boottime = {
82221+ static struct k_clock clock_boottime = {
82222 .clock_getres = hrtimer_get_res,
82223 .clock_get = posix_get_boottime,
82224 .nsleep = common_nsleep,
82225@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82226 return;
82227 }
82228
82229- posix_clocks[clock_id] = *new_clock;
82230+ posix_clocks[clock_id] = new_clock;
82231 }
82232 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82233
82234@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82235 return (id & CLOCKFD_MASK) == CLOCKFD ?
82236 &clock_posix_dynamic : &clock_posix_cpu;
82237
82238- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82239+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82240 return NULL;
82241- return &posix_clocks[id];
82242+ return posix_clocks[id];
82243 }
82244
82245 static int common_timer_create(struct k_itimer *new_timer)
82246@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82247 struct k_clock *kc = clockid_to_kclock(which_clock);
82248 struct k_itimer *new_timer;
82249 int error, new_timer_id;
82250- sigevent_t event;
82251+ sigevent_t event = { };
82252 int it_id_set = IT_ID_NOT_SET;
82253
82254 if (!kc)
82255@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82256 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82257 return -EFAULT;
82258
82259+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82260+ have their clock_set fptr set to a nosettime dummy function
82261+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82262+ call common_clock_set, which calls do_sys_settimeofday, which
82263+ we hook
82264+ */
82265+
82266 return kc->clock_set(which_clock, &new_tp);
82267 }
82268
82269diff --git a/kernel/power/process.c b/kernel/power/process.c
82270index 06ec886..9dba35e 100644
82271--- a/kernel/power/process.c
82272+++ b/kernel/power/process.c
82273@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82274 unsigned int elapsed_msecs;
82275 bool wakeup = false;
82276 int sleep_usecs = USEC_PER_MSEC;
82277+ bool timedout = false;
82278
82279 do_gettimeofday(&start);
82280
82281@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82282
82283 while (true) {
82284 todo = 0;
82285+ if (time_after(jiffies, end_time))
82286+ timedout = true;
82287 read_lock(&tasklist_lock);
82288 do_each_thread(g, p) {
82289 if (p == current || !freeze_task(p))
82290 continue;
82291
82292- if (!freezer_should_skip(p))
82293+ if (!freezer_should_skip(p)) {
82294 todo++;
82295+ if (timedout) {
82296+ printk(KERN_ERR "Task refusing to freeze:\n");
82297+ sched_show_task(p);
82298+ }
82299+ }
82300 } while_each_thread(g, p);
82301 read_unlock(&tasklist_lock);
82302
82303@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82304 todo += wq_busy;
82305 }
82306
82307- if (!todo || time_after(jiffies, end_time))
82308+ if (!todo || timedout)
82309 break;
82310
82311 if (pm_wakeup_pending()) {
82312diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82313index 5b5a708..ec7637e 100644
82314--- a/kernel/printk/printk.c
82315+++ b/kernel/printk/printk.c
82316@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82317 if (from_file && type != SYSLOG_ACTION_OPEN)
82318 return 0;
82319
82320+#ifdef CONFIG_GRKERNSEC_DMESG
82321+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82322+ return -EPERM;
82323+#endif
82324+
82325 if (syslog_action_restricted(type)) {
82326 if (capable(CAP_SYSLOG))
82327 return 0;
82328diff --git a/kernel/profile.c b/kernel/profile.c
82329index 6631e1e..310c266 100644
82330--- a/kernel/profile.c
82331+++ b/kernel/profile.c
82332@@ -37,7 +37,7 @@ struct profile_hit {
82333 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82334 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82335
82336-static atomic_t *prof_buffer;
82337+static atomic_unchecked_t *prof_buffer;
82338 static unsigned long prof_len, prof_shift;
82339
82340 int prof_on __read_mostly;
82341@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82342 hits[i].pc = 0;
82343 continue;
82344 }
82345- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82346+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82347 hits[i].hits = hits[i].pc = 0;
82348 }
82349 }
82350@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82351 * Add the current hit(s) and flush the write-queue out
82352 * to the global buffer:
82353 */
82354- atomic_add(nr_hits, &prof_buffer[pc]);
82355+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82356 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82357- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82358+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82359 hits[i].pc = hits[i].hits = 0;
82360 }
82361 out:
82362@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82363 {
82364 unsigned long pc;
82365 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82366- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82367+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82368 }
82369 #endif /* !CONFIG_SMP */
82370
82371@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82372 return -EFAULT;
82373 buf++; p++; count--; read++;
82374 }
82375- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82376+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82377 if (copy_to_user(buf, (void *)pnt, count))
82378 return -EFAULT;
82379 read += count;
82380@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82381 }
82382 #endif
82383 profile_discard_flip_buffers();
82384- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82385+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82386 return count;
82387 }
82388
82389diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82390index a146ee3..ffed4c3 100644
82391--- a/kernel/ptrace.c
82392+++ b/kernel/ptrace.c
82393@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82394 if (seize)
82395 flags |= PT_SEIZED;
82396 rcu_read_lock();
82397- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82398+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82399 flags |= PT_PTRACE_CAP;
82400 rcu_read_unlock();
82401 task->ptrace = flags;
82402@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82403 break;
82404 return -EIO;
82405 }
82406- if (copy_to_user(dst, buf, retval))
82407+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82408 return -EFAULT;
82409 copied += retval;
82410 src += retval;
82411@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82412 bool seized = child->ptrace & PT_SEIZED;
82413 int ret = -EIO;
82414 siginfo_t siginfo, *si;
82415- void __user *datavp = (void __user *) data;
82416+ void __user *datavp = (__force void __user *) data;
82417 unsigned long __user *datalp = datavp;
82418 unsigned long flags;
82419
82420@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82421 goto out;
82422 }
82423
82424+ if (gr_handle_ptrace(child, request)) {
82425+ ret = -EPERM;
82426+ goto out_put_task_struct;
82427+ }
82428+
82429 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82430 ret = ptrace_attach(child, request, addr, data);
82431 /*
82432 * Some architectures need to do book-keeping after
82433 * a ptrace attach.
82434 */
82435- if (!ret)
82436+ if (!ret) {
82437 arch_ptrace_attach(child);
82438+ gr_audit_ptrace(child);
82439+ }
82440 goto out_put_task_struct;
82441 }
82442
82443@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82444 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82445 if (copied != sizeof(tmp))
82446 return -EIO;
82447- return put_user(tmp, (unsigned long __user *)data);
82448+ return put_user(tmp, (__force unsigned long __user *)data);
82449 }
82450
82451 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82452@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82453 }
82454
82455 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82456- compat_long_t addr, compat_long_t data)
82457+ compat_ulong_t addr, compat_ulong_t data)
82458 {
82459 struct task_struct *child;
82460 long ret;
82461@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82462 goto out;
82463 }
82464
82465+ if (gr_handle_ptrace(child, request)) {
82466+ ret = -EPERM;
82467+ goto out_put_task_struct;
82468+ }
82469+
82470 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82471 ret = ptrace_attach(child, request, addr, data);
82472 /*
82473 * Some architectures need to do book-keeping after
82474 * a ptrace attach.
82475 */
82476- if (!ret)
82477+ if (!ret) {
82478 arch_ptrace_attach(child);
82479+ gr_audit_ptrace(child);
82480+ }
82481 goto out_put_task_struct;
82482 }
82483
82484diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82485index cce6ba8..7c758b1f 100644
82486--- a/kernel/rcupdate.c
82487+++ b/kernel/rcupdate.c
82488@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82489 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82490 */
82491 if (till_stall_check < 3) {
82492- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82493+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82494 till_stall_check = 3;
82495 } else if (till_stall_check > 300) {
82496- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82497+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82498 till_stall_check = 300;
82499 }
82500 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82501diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82502index aa34411..4832cd4 100644
82503--- a/kernel/rcutiny.c
82504+++ b/kernel/rcutiny.c
82505@@ -45,7 +45,7 @@
82506 /* Forward declarations for rcutiny_plugin.h. */
82507 struct rcu_ctrlblk;
82508 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82509-static void rcu_process_callbacks(struct softirq_action *unused);
82510+static void rcu_process_callbacks(void);
82511 static void __call_rcu(struct rcu_head *head,
82512 void (*func)(struct rcu_head *rcu),
82513 struct rcu_ctrlblk *rcp);
82514@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82515 false));
82516 }
82517
82518-static void rcu_process_callbacks(struct softirq_action *unused)
82519+static __latent_entropy void rcu_process_callbacks(void)
82520 {
82521 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82522 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82523diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82524index f4871e5..8ef5741 100644
82525--- a/kernel/rcutorture.c
82526+++ b/kernel/rcutorture.c
82527@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82528 { 0 };
82529 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82530 { 0 };
82531-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82532-static atomic_t n_rcu_torture_alloc;
82533-static atomic_t n_rcu_torture_alloc_fail;
82534-static atomic_t n_rcu_torture_free;
82535-static atomic_t n_rcu_torture_mberror;
82536-static atomic_t n_rcu_torture_error;
82537+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82538+static atomic_unchecked_t n_rcu_torture_alloc;
82539+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82540+static atomic_unchecked_t n_rcu_torture_free;
82541+static atomic_unchecked_t n_rcu_torture_mberror;
82542+static atomic_unchecked_t n_rcu_torture_error;
82543 static long n_rcu_torture_barrier_error;
82544 static long n_rcu_torture_boost_ktrerror;
82545 static long n_rcu_torture_boost_rterror;
82546@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82547
82548 spin_lock_bh(&rcu_torture_lock);
82549 if (list_empty(&rcu_torture_freelist)) {
82550- atomic_inc(&n_rcu_torture_alloc_fail);
82551+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82552 spin_unlock_bh(&rcu_torture_lock);
82553 return NULL;
82554 }
82555- atomic_inc(&n_rcu_torture_alloc);
82556+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82557 p = rcu_torture_freelist.next;
82558 list_del_init(p);
82559 spin_unlock_bh(&rcu_torture_lock);
82560@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82561 static void
82562 rcu_torture_free(struct rcu_torture *p)
82563 {
82564- atomic_inc(&n_rcu_torture_free);
82565+ atomic_inc_unchecked(&n_rcu_torture_free);
82566 spin_lock_bh(&rcu_torture_lock);
82567 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82568 spin_unlock_bh(&rcu_torture_lock);
82569@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82570 i = rp->rtort_pipe_count;
82571 if (i > RCU_TORTURE_PIPE_LEN)
82572 i = RCU_TORTURE_PIPE_LEN;
82573- atomic_inc(&rcu_torture_wcount[i]);
82574+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82575 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82576 rp->rtort_mbtest = 0;
82577 rcu_torture_free(rp);
82578@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82579 i = rp->rtort_pipe_count;
82580 if (i > RCU_TORTURE_PIPE_LEN)
82581 i = RCU_TORTURE_PIPE_LEN;
82582- atomic_inc(&rcu_torture_wcount[i]);
82583+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82584 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82585 rp->rtort_mbtest = 0;
82586 list_del(&rp->rtort_free);
82587@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82588 i = old_rp->rtort_pipe_count;
82589 if (i > RCU_TORTURE_PIPE_LEN)
82590 i = RCU_TORTURE_PIPE_LEN;
82591- atomic_inc(&rcu_torture_wcount[i]);
82592+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82593 old_rp->rtort_pipe_count++;
82594 cur_ops->deferred_free(old_rp);
82595 }
82596@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82597 return;
82598 }
82599 if (p->rtort_mbtest == 0)
82600- atomic_inc(&n_rcu_torture_mberror);
82601+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82602 spin_lock(&rand_lock);
82603 cur_ops->read_delay(&rand);
82604 n_rcu_torture_timers++;
82605@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82606 continue;
82607 }
82608 if (p->rtort_mbtest == 0)
82609- atomic_inc(&n_rcu_torture_mberror);
82610+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82611 cur_ops->read_delay(&rand);
82612 preempt_disable();
82613 pipe_count = p->rtort_pipe_count;
82614@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82615 rcu_torture_current,
82616 rcu_torture_current_version,
82617 list_empty(&rcu_torture_freelist),
82618- atomic_read(&n_rcu_torture_alloc),
82619- atomic_read(&n_rcu_torture_alloc_fail),
82620- atomic_read(&n_rcu_torture_free));
82621+ atomic_read_unchecked(&n_rcu_torture_alloc),
82622+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82623+ atomic_read_unchecked(&n_rcu_torture_free));
82624 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82625- atomic_read(&n_rcu_torture_mberror),
82626+ atomic_read_unchecked(&n_rcu_torture_mberror),
82627 n_rcu_torture_boost_ktrerror,
82628 n_rcu_torture_boost_rterror);
82629 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82630@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82631 n_barrier_attempts,
82632 n_rcu_torture_barrier_error);
82633 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82634- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82635+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82636 n_rcu_torture_barrier_error != 0 ||
82637 n_rcu_torture_boost_ktrerror != 0 ||
82638 n_rcu_torture_boost_rterror != 0 ||
82639 n_rcu_torture_boost_failure != 0 ||
82640 i > 1) {
82641 cnt += sprintf(&page[cnt], "!!! ");
82642- atomic_inc(&n_rcu_torture_error);
82643+ atomic_inc_unchecked(&n_rcu_torture_error);
82644 WARN_ON_ONCE(1);
82645 }
82646 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82647@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82648 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82649 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82650 cnt += sprintf(&page[cnt], " %d",
82651- atomic_read(&rcu_torture_wcount[i]));
82652+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82653 }
82654 cnt += sprintf(&page[cnt], "\n");
82655 if (cur_ops->stats)
82656@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82657
82658 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82659
82660- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82661+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82662 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82663 else if (n_online_successes != n_online_attempts ||
82664 n_offline_successes != n_offline_attempts)
82665@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82666
82667 rcu_torture_current = NULL;
82668 rcu_torture_current_version = 0;
82669- atomic_set(&n_rcu_torture_alloc, 0);
82670- atomic_set(&n_rcu_torture_alloc_fail, 0);
82671- atomic_set(&n_rcu_torture_free, 0);
82672- atomic_set(&n_rcu_torture_mberror, 0);
82673- atomic_set(&n_rcu_torture_error, 0);
82674+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82675+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82676+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82677+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82678+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82679 n_rcu_torture_barrier_error = 0;
82680 n_rcu_torture_boost_ktrerror = 0;
82681 n_rcu_torture_boost_rterror = 0;
82682 n_rcu_torture_boost_failure = 0;
82683 n_rcu_torture_boosts = 0;
82684 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82685- atomic_set(&rcu_torture_wcount[i], 0);
82686+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82687 for_each_possible_cpu(cpu) {
82688 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82689 per_cpu(rcu_torture_count, cpu)[i] = 0;
82690diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82691index 068de3a..5e7db2f 100644
82692--- a/kernel/rcutree.c
82693+++ b/kernel/rcutree.c
82694@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82695 rcu_prepare_for_idle(smp_processor_id());
82696 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82697 smp_mb__before_atomic_inc(); /* See above. */
82698- atomic_inc(&rdtp->dynticks);
82699+ atomic_inc_unchecked(&rdtp->dynticks);
82700 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82701- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82702+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82703
82704 /*
82705 * It is illegal to enter an extended quiescent state while
82706@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82707 int user)
82708 {
82709 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82710- atomic_inc(&rdtp->dynticks);
82711+ atomic_inc_unchecked(&rdtp->dynticks);
82712 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82713 smp_mb__after_atomic_inc(); /* See above. */
82714- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82715+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82716 rcu_cleanup_after_idle(smp_processor_id());
82717 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82718 if (!user && !is_idle_task(current)) {
82719@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82720 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82721
82722 if (rdtp->dynticks_nmi_nesting == 0 &&
82723- (atomic_read(&rdtp->dynticks) & 0x1))
82724+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82725 return;
82726 rdtp->dynticks_nmi_nesting++;
82727 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82728- atomic_inc(&rdtp->dynticks);
82729+ atomic_inc_unchecked(&rdtp->dynticks);
82730 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82731 smp_mb__after_atomic_inc(); /* See above. */
82732- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82733+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82734 }
82735
82736 /**
82737@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82738 return;
82739 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82740 smp_mb__before_atomic_inc(); /* See above. */
82741- atomic_inc(&rdtp->dynticks);
82742+ atomic_inc_unchecked(&rdtp->dynticks);
82743 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82744- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82745+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82746 }
82747
82748 /**
82749@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82750 int ret;
82751
82752 preempt_disable();
82753- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82754+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82755 preempt_enable();
82756 return ret;
82757 }
82758@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82759 */
82760 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82761 {
82762- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82763+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82764 return (rdp->dynticks_snap & 0x1) == 0;
82765 }
82766
82767@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82768 unsigned int curr;
82769 unsigned int snap;
82770
82771- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82772+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82773 snap = (unsigned int)rdp->dynticks_snap;
82774
82775 /*
82776@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82777 rdp = this_cpu_ptr(rsp->rda);
82778 rcu_preempt_check_blocked_tasks(rnp);
82779 rnp->qsmask = rnp->qsmaskinit;
82780- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82781+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82782 WARN_ON_ONCE(rnp->completed != rsp->completed);
82783- ACCESS_ONCE(rnp->completed) = rsp->completed;
82784+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82785 if (rnp == rdp->mynode)
82786 __note_gp_changes(rsp, rnp, rdp);
82787 rcu_preempt_boost_start_gp(rnp);
82788@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82789 */
82790 rcu_for_each_node_breadth_first(rsp, rnp) {
82791 raw_spin_lock_irq(&rnp->lock);
82792- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82793+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82794 rdp = this_cpu_ptr(rsp->rda);
82795 if (rnp == rdp->mynode)
82796 __note_gp_changes(rsp, rnp, rdp);
82797@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82798 rsp->qlen += rdp->qlen;
82799 rdp->n_cbs_orphaned += rdp->qlen;
82800 rdp->qlen_lazy = 0;
82801- ACCESS_ONCE(rdp->qlen) = 0;
82802+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82803 }
82804
82805 /*
82806@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82807 }
82808 smp_mb(); /* List handling before counting for rcu_barrier(). */
82809 rdp->qlen_lazy -= count_lazy;
82810- ACCESS_ONCE(rdp->qlen) -= count;
82811+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82812 rdp->n_cbs_invoked += count;
82813
82814 /* Reinstate batch limit if we have worked down the excess. */
82815@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82816 /*
82817 * Do RCU core processing for the current CPU.
82818 */
82819-static void rcu_process_callbacks(struct softirq_action *unused)
82820+static __latent_entropy void rcu_process_callbacks(void)
82821 {
82822 struct rcu_state *rsp;
82823
82824@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82825 local_irq_restore(flags);
82826 return;
82827 }
82828- ACCESS_ONCE(rdp->qlen)++;
82829+ ACCESS_ONCE_RW(rdp->qlen)++;
82830 if (lazy)
82831 rdp->qlen_lazy++;
82832 else
82833@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82834 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82835 * course be required on a 64-bit system.
82836 */
82837- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82838+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82839 (ulong)atomic_long_read(&rsp->expedited_done) +
82840 ULONG_MAX / 8)) {
82841 synchronize_sched();
82842- atomic_long_inc(&rsp->expedited_wrap);
82843+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82844 return;
82845 }
82846
82847@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82848 * Take a ticket. Note that atomic_inc_return() implies a
82849 * full memory barrier.
82850 */
82851- snap = atomic_long_inc_return(&rsp->expedited_start);
82852+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82853 firstsnap = snap;
82854 get_online_cpus();
82855 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82856@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82857 synchronize_sched_expedited_cpu_stop,
82858 NULL) == -EAGAIN) {
82859 put_online_cpus();
82860- atomic_long_inc(&rsp->expedited_tryfail);
82861+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82862
82863 /* Check to see if someone else did our work for us. */
82864 s = atomic_long_read(&rsp->expedited_done);
82865 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82866 /* ensure test happens before caller kfree */
82867 smp_mb__before_atomic_inc(); /* ^^^ */
82868- atomic_long_inc(&rsp->expedited_workdone1);
82869+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82870 return;
82871 }
82872
82873@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82874 udelay(trycount * num_online_cpus());
82875 } else {
82876 wait_rcu_gp(call_rcu_sched);
82877- atomic_long_inc(&rsp->expedited_normal);
82878+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82879 return;
82880 }
82881
82882@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82883 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82884 /* ensure test happens before caller kfree */
82885 smp_mb__before_atomic_inc(); /* ^^^ */
82886- atomic_long_inc(&rsp->expedited_workdone2);
82887+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
82888 return;
82889 }
82890
82891@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
82892 * period works for us.
82893 */
82894 get_online_cpus();
82895- snap = atomic_long_read(&rsp->expedited_start);
82896+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
82897 smp_mb(); /* ensure read is before try_stop_cpus(). */
82898 }
82899- atomic_long_inc(&rsp->expedited_stoppedcpus);
82900+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
82901
82902 /*
82903 * Everyone up to our most recent fetch is covered by our grace
82904@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
82905 * than we did already did their update.
82906 */
82907 do {
82908- atomic_long_inc(&rsp->expedited_done_tries);
82909+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
82910 s = atomic_long_read(&rsp->expedited_done);
82911 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
82912 /* ensure test happens before caller kfree */
82913 smp_mb__before_atomic_inc(); /* ^^^ */
82914- atomic_long_inc(&rsp->expedited_done_lost);
82915+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
82916 break;
82917 }
82918 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
82919- atomic_long_inc(&rsp->expedited_done_exit);
82920+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
82921
82922 put_online_cpus();
82923 }
82924@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
82925 * ACCESS_ONCE() to prevent the compiler from speculating
82926 * the increment to precede the early-exit check.
82927 */
82928- ACCESS_ONCE(rsp->n_barrier_done)++;
82929+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
82930 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
82931 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
82932 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
82933@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
82934
82935 /* Increment ->n_barrier_done to prevent duplicate work. */
82936 smp_mb(); /* Keep increment after above mechanism. */
82937- ACCESS_ONCE(rsp->n_barrier_done)++;
82938+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
82939 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
82940 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
82941 smp_mb(); /* Keep increment before caller's subsequent code. */
82942@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
82943 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
82944 init_callback_list(rdp);
82945 rdp->qlen_lazy = 0;
82946- ACCESS_ONCE(rdp->qlen) = 0;
82947+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82948 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
82949 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
82950- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
82951+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
82952 rdp->cpu = cpu;
82953 rdp->rsp = rsp;
82954 rcu_boot_init_nocb_percpu_data(rdp);
82955@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
82956 rdp->blimit = blimit;
82957 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
82958 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
82959- atomic_set(&rdp->dynticks->dynticks,
82960- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
82961+ atomic_set_unchecked(&rdp->dynticks->dynticks,
82962+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
82963 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
82964
82965 /* Add CPU to rcu_node bitmasks. */
82966diff --git a/kernel/rcutree.h b/kernel/rcutree.h
82967index b383258..2440c1e 100644
82968--- a/kernel/rcutree.h
82969+++ b/kernel/rcutree.h
82970@@ -87,7 +87,7 @@ struct rcu_dynticks {
82971 long long dynticks_nesting; /* Track irq/process nesting level. */
82972 /* Process level is worth LLONG_MAX/2. */
82973 int dynticks_nmi_nesting; /* Track NMI nesting level. */
82974- atomic_t dynticks; /* Even value for idle, else odd. */
82975+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
82976 #ifdef CONFIG_RCU_FAST_NO_HZ
82977 bool all_lazy; /* Are all CPU's CBs lazy? */
82978 unsigned long nonlazy_posted;
82979@@ -419,17 +419,17 @@ struct rcu_state {
82980 /* _rcu_barrier(). */
82981 /* End of fields guarded by barrier_mutex. */
82982
82983- atomic_long_t expedited_start; /* Starting ticket. */
82984- atomic_long_t expedited_done; /* Done ticket. */
82985- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
82986- atomic_long_t expedited_tryfail; /* # acquisition failures. */
82987- atomic_long_t expedited_workdone1; /* # done by others #1. */
82988- atomic_long_t expedited_workdone2; /* # done by others #2. */
82989- atomic_long_t expedited_normal; /* # fallbacks to normal. */
82990- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
82991- atomic_long_t expedited_done_tries; /* # tries to update _done. */
82992- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
82993- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
82994+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
82995+ atomic_long_t expedited_done; /* Done ticket. */
82996+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
82997+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
82998+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
82999+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83000+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83001+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83002+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83003+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83004+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83005
83006 unsigned long jiffies_force_qs; /* Time at which to invoke */
83007 /* force_quiescent_state(). */
83008diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83009index 769e12e..7b2139b 100644
83010--- a/kernel/rcutree_plugin.h
83011+++ b/kernel/rcutree_plugin.h
83012@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83013
83014 /* Clean up and exit. */
83015 smp_mb(); /* ensure expedited GP seen before counter increment. */
83016- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83017+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83018 unlock_mb_ret:
83019 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83020 mb_ret:
83021@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83022 free_cpumask_var(cm);
83023 }
83024
83025-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83026+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83027 .store = &rcu_cpu_kthread_task,
83028 .thread_should_run = rcu_cpu_kthread_should_run,
83029 .thread_fn = rcu_cpu_kthread,
83030@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83031 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83032 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83033 cpu, ticks_value, ticks_title,
83034- atomic_read(&rdtp->dynticks) & 0xfff,
83035+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83036 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83037 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83038 fast_no_hz);
83039@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83040
83041 /* Enqueue the callback on the nocb list and update counts. */
83042 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83043- ACCESS_ONCE(*old_rhpp) = rhp;
83044+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83045 atomic_long_add(rhcount, &rdp->nocb_q_count);
83046 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83047
83048@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83049 * Extract queued callbacks, update counts, and wait
83050 * for a grace period to elapse.
83051 */
83052- ACCESS_ONCE(rdp->nocb_head) = NULL;
83053+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83054 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83055 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83056 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83057- ACCESS_ONCE(rdp->nocb_p_count) += c;
83058- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83059+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83060+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83061 rcu_nocb_wait_gp(rdp);
83062
83063 /* Each pass through the following loop invokes a callback. */
83064@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83065 list = next;
83066 }
83067 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83068- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83069- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83070+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83071+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83072 rdp->n_nocbs_invoked += c;
83073 }
83074 return 0;
83075@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83076 t = kthread_run(rcu_nocb_kthread, rdp,
83077 "rcuo%c/%d", rsp->abbr, cpu);
83078 BUG_ON(IS_ERR(t));
83079- ACCESS_ONCE(rdp->nocb_kthread) = t;
83080+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83081 }
83082 }
83083
83084diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83085index cf6c174..a8f4b50 100644
83086--- a/kernel/rcutree_trace.c
83087+++ b/kernel/rcutree_trace.c
83088@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83089 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83090 rdp->passed_quiesce, rdp->qs_pending);
83091 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83092- atomic_read(&rdp->dynticks->dynticks),
83093+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83094 rdp->dynticks->dynticks_nesting,
83095 rdp->dynticks->dynticks_nmi_nesting,
83096 rdp->dynticks_fqs);
83097@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83098 struct rcu_state *rsp = (struct rcu_state *)m->private;
83099
83100 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",
83101- atomic_long_read(&rsp->expedited_start),
83102+ atomic_long_read_unchecked(&rsp->expedited_start),
83103 atomic_long_read(&rsp->expedited_done),
83104- atomic_long_read(&rsp->expedited_wrap),
83105- atomic_long_read(&rsp->expedited_tryfail),
83106- atomic_long_read(&rsp->expedited_workdone1),
83107- atomic_long_read(&rsp->expedited_workdone2),
83108- atomic_long_read(&rsp->expedited_normal),
83109- atomic_long_read(&rsp->expedited_stoppedcpus),
83110- atomic_long_read(&rsp->expedited_done_tries),
83111- atomic_long_read(&rsp->expedited_done_lost),
83112- atomic_long_read(&rsp->expedited_done_exit));
83113+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83114+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83115+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83116+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83117+ atomic_long_read_unchecked(&rsp->expedited_normal),
83118+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83119+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83120+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83121+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83122 return 0;
83123 }
83124
83125diff --git a/kernel/resource.c b/kernel/resource.c
83126index 3f285dc..5755f62 100644
83127--- a/kernel/resource.c
83128+++ b/kernel/resource.c
83129@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83130
83131 static int __init ioresources_init(void)
83132 {
83133+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83134+#ifdef CONFIG_GRKERNSEC_PROC_USER
83135+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83136+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83137+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83138+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83139+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83140+#endif
83141+#else
83142 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83143 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83144+#endif
83145 return 0;
83146 }
83147 __initcall(ioresources_init);
83148diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83149index 1d96dd0..994ff19 100644
83150--- a/kernel/rtmutex-tester.c
83151+++ b/kernel/rtmutex-tester.c
83152@@ -22,7 +22,7 @@
83153 #define MAX_RT_TEST_MUTEXES 8
83154
83155 static spinlock_t rttest_lock;
83156-static atomic_t rttest_event;
83157+static atomic_unchecked_t rttest_event;
83158
83159 struct test_thread_data {
83160 int opcode;
83161@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83162
83163 case RTTEST_LOCKCONT:
83164 td->mutexes[td->opdata] = 1;
83165- td->event = atomic_add_return(1, &rttest_event);
83166+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83167 return 0;
83168
83169 case RTTEST_RESET:
83170@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83171 return 0;
83172
83173 case RTTEST_RESETEVENT:
83174- atomic_set(&rttest_event, 0);
83175+ atomic_set_unchecked(&rttest_event, 0);
83176 return 0;
83177
83178 default:
83179@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83180 return ret;
83181
83182 td->mutexes[id] = 1;
83183- td->event = atomic_add_return(1, &rttest_event);
83184+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83185 rt_mutex_lock(&mutexes[id]);
83186- td->event = atomic_add_return(1, &rttest_event);
83187+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83188 td->mutexes[id] = 4;
83189 return 0;
83190
83191@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83192 return ret;
83193
83194 td->mutexes[id] = 1;
83195- td->event = atomic_add_return(1, &rttest_event);
83196+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83197 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83198- td->event = atomic_add_return(1, &rttest_event);
83199+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83200 td->mutexes[id] = ret ? 0 : 4;
83201 return ret ? -EINTR : 0;
83202
83203@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83204 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83205 return ret;
83206
83207- td->event = atomic_add_return(1, &rttest_event);
83208+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83209 rt_mutex_unlock(&mutexes[id]);
83210- td->event = atomic_add_return(1, &rttest_event);
83211+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83212 td->mutexes[id] = 0;
83213 return 0;
83214
83215@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83216 break;
83217
83218 td->mutexes[dat] = 2;
83219- td->event = atomic_add_return(1, &rttest_event);
83220+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83221 break;
83222
83223 default:
83224@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83225 return;
83226
83227 td->mutexes[dat] = 3;
83228- td->event = atomic_add_return(1, &rttest_event);
83229+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83230 break;
83231
83232 case RTTEST_LOCKNOWAIT:
83233@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83234 return;
83235
83236 td->mutexes[dat] = 1;
83237- td->event = atomic_add_return(1, &rttest_event);
83238+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83239 return;
83240
83241 default:
83242diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83243index 4a07353..66b5291 100644
83244--- a/kernel/sched/auto_group.c
83245+++ b/kernel/sched/auto_group.c
83246@@ -11,7 +11,7 @@
83247
83248 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83249 static struct autogroup autogroup_default;
83250-static atomic_t autogroup_seq_nr;
83251+static atomic_unchecked_t autogroup_seq_nr;
83252
83253 void __init autogroup_init(struct task_struct *init_task)
83254 {
83255@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83256
83257 kref_init(&ag->kref);
83258 init_rwsem(&ag->lock);
83259- ag->id = atomic_inc_return(&autogroup_seq_nr);
83260+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83261 ag->tg = tg;
83262 #ifdef CONFIG_RT_GROUP_SCHED
83263 /*
83264diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83265index 05c39f0..442e6fe 100644
83266--- a/kernel/sched/core.c
83267+++ b/kernel/sched/core.c
83268@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83269 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83270 * or number of jiffies left till timeout) if completed.
83271 */
83272-long __sched
83273+long __sched __intentional_overflow(-1)
83274 wait_for_completion_interruptible_timeout(struct completion *x,
83275 unsigned long timeout)
83276 {
83277@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83278 *
83279 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83280 */
83281-int __sched wait_for_completion_killable(struct completion *x)
83282+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83283 {
83284 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83285 if (t == -ERESTARTSYS)
83286@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83287 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83288 * or number of jiffies left till timeout) if completed.
83289 */
83290-long __sched
83291+long __sched __intentional_overflow(-1)
83292 wait_for_completion_killable_timeout(struct completion *x,
83293 unsigned long timeout)
83294 {
83295@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83296 /* convert nice value [19,-20] to rlimit style value [1,40] */
83297 int nice_rlim = 20 - nice;
83298
83299+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83300+
83301 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83302 capable(CAP_SYS_NICE));
83303 }
83304@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83305 if (nice > 19)
83306 nice = 19;
83307
83308- if (increment < 0 && !can_nice(current, nice))
83309+ if (increment < 0 && (!can_nice(current, nice) ||
83310+ gr_handle_chroot_nice()))
83311 return -EPERM;
83312
83313 retval = security_task_setnice(current, nice);
83314@@ -3344,6 +3347,7 @@ recheck:
83315 unsigned long rlim_rtprio =
83316 task_rlimit(p, RLIMIT_RTPRIO);
83317
83318+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83319 /* can't set/change the rt policy */
83320 if (policy != p->policy && !rlim_rtprio)
83321 return -EPERM;
83322@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83323
83324 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83325
83326-static struct ctl_table sd_ctl_dir[] = {
83327+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83328 {
83329 .procname = "sched_domain",
83330 .mode = 0555,
83331@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83332 {}
83333 };
83334
83335-static struct ctl_table *sd_alloc_ctl_entry(int n)
83336+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83337 {
83338- struct ctl_table *entry =
83339+ ctl_table_no_const *entry =
83340 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83341
83342 return entry;
83343 }
83344
83345-static void sd_free_ctl_entry(struct ctl_table **tablep)
83346+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83347 {
83348- struct ctl_table *entry;
83349+ ctl_table_no_const *entry;
83350
83351 /*
83352 * In the intermediate directories, both the child directory and
83353@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83354 * will always be set. In the lowest directory the names are
83355 * static strings and all have proc handlers.
83356 */
83357- for (entry = *tablep; entry->mode; entry++) {
83358- if (entry->child)
83359- sd_free_ctl_entry(&entry->child);
83360+ for (entry = tablep; entry->mode; entry++) {
83361+ if (entry->child) {
83362+ sd_free_ctl_entry(entry->child);
83363+ pax_open_kernel();
83364+ entry->child = NULL;
83365+ pax_close_kernel();
83366+ }
83367 if (entry->proc_handler == NULL)
83368 kfree(entry->procname);
83369 }
83370
83371- kfree(*tablep);
83372- *tablep = NULL;
83373+ kfree(tablep);
83374 }
83375
83376 static int min_load_idx = 0;
83377 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83378
83379 static void
83380-set_table_entry(struct ctl_table *entry,
83381+set_table_entry(ctl_table_no_const *entry,
83382 const char *procname, void *data, int maxlen,
83383 umode_t mode, proc_handler *proc_handler,
83384 bool load_idx)
83385@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83386 static struct ctl_table *
83387 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83388 {
83389- struct ctl_table *table = sd_alloc_ctl_entry(13);
83390+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83391
83392 if (table == NULL)
83393 return NULL;
83394@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83395 return table;
83396 }
83397
83398-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83399+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83400 {
83401- struct ctl_table *entry, *table;
83402+ ctl_table_no_const *entry, *table;
83403 struct sched_domain *sd;
83404 int domain_num = 0, i;
83405 char buf[32];
83406@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83407 static void register_sched_domain_sysctl(void)
83408 {
83409 int i, cpu_num = num_possible_cpus();
83410- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83411+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83412 char buf[32];
83413
83414 WARN_ON(sd_ctl_dir[0].child);
83415+ pax_open_kernel();
83416 sd_ctl_dir[0].child = entry;
83417+ pax_close_kernel();
83418
83419 if (entry == NULL)
83420 return;
83421@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83422 if (sd_sysctl_header)
83423 unregister_sysctl_table(sd_sysctl_header);
83424 sd_sysctl_header = NULL;
83425- if (sd_ctl_dir[0].child)
83426- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83427+ if (sd_ctl_dir[0].child) {
83428+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83429+ pax_open_kernel();
83430+ sd_ctl_dir[0].child = NULL;
83431+ pax_close_kernel();
83432+ }
83433 }
83434 #else
83435 static void register_sched_domain_sysctl(void)
83436diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83437index 31cbc15..ba68c15 100644
83438--- a/kernel/sched/fair.c
83439+++ b/kernel/sched/fair.c
83440@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83441
83442 static void reset_ptenuma_scan(struct task_struct *p)
83443 {
83444- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83445+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83446 p->mm->numa_scan_offset = 0;
83447 }
83448
83449@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83450 * run_rebalance_domains is triggered when needed from the scheduler tick.
83451 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83452 */
83453-static void run_rebalance_domains(struct softirq_action *h)
83454+static __latent_entropy void run_rebalance_domains(void)
83455 {
83456 int this_cpu = smp_processor_id();
83457 struct rq *this_rq = cpu_rq(this_cpu);
83458diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83459index ef0a7b2..1b728c1 100644
83460--- a/kernel/sched/sched.h
83461+++ b/kernel/sched/sched.h
83462@@ -1004,7 +1004,7 @@ struct sched_class {
83463 #ifdef CONFIG_FAIR_GROUP_SCHED
83464 void (*task_move_group) (struct task_struct *p, int on_rq);
83465 #endif
83466-};
83467+} __do_const;
83468
83469 #define sched_class_highest (&stop_sched_class)
83470 #define for_each_class(class) \
83471diff --git a/kernel/signal.c b/kernel/signal.c
83472index 50e4107..9409983 100644
83473--- a/kernel/signal.c
83474+++ b/kernel/signal.c
83475@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83476
83477 int print_fatal_signals __read_mostly;
83478
83479-static void __user *sig_handler(struct task_struct *t, int sig)
83480+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83481 {
83482 return t->sighand->action[sig - 1].sa.sa_handler;
83483 }
83484
83485-static int sig_handler_ignored(void __user *handler, int sig)
83486+static int sig_handler_ignored(__sighandler_t handler, int sig)
83487 {
83488 /* Is it explicitly or implicitly ignored? */
83489 return handler == SIG_IGN ||
83490@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83491
83492 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83493 {
83494- void __user *handler;
83495+ __sighandler_t handler;
83496
83497 handler = sig_handler(t, sig);
83498
83499@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83500 atomic_inc(&user->sigpending);
83501 rcu_read_unlock();
83502
83503+ if (!override_rlimit)
83504+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83505+
83506 if (override_rlimit ||
83507 atomic_read(&user->sigpending) <=
83508 task_rlimit(t, RLIMIT_SIGPENDING)) {
83509@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83510
83511 int unhandled_signal(struct task_struct *tsk, int sig)
83512 {
83513- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83514+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83515 if (is_global_init(tsk))
83516 return 1;
83517 if (handler != SIG_IGN && handler != SIG_DFL)
83518@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83519 }
83520 }
83521
83522+ /* allow glibc communication via tgkill to other threads in our
83523+ thread group */
83524+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83525+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83526+ && gr_handle_signal(t, sig))
83527+ return -EPERM;
83528+
83529 return security_task_kill(t, info, sig, 0);
83530 }
83531
83532@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83533 return send_signal(sig, info, p, 1);
83534 }
83535
83536-static int
83537+int
83538 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83539 {
83540 return send_signal(sig, info, t, 0);
83541@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83542 unsigned long int flags;
83543 int ret, blocked, ignored;
83544 struct k_sigaction *action;
83545+ int is_unhandled = 0;
83546
83547 spin_lock_irqsave(&t->sighand->siglock, flags);
83548 action = &t->sighand->action[sig-1];
83549@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83550 }
83551 if (action->sa.sa_handler == SIG_DFL)
83552 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83553+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83554+ is_unhandled = 1;
83555 ret = specific_send_sig_info(sig, info, t);
83556 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83557
83558+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83559+ normal operation */
83560+ if (is_unhandled) {
83561+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83562+ gr_handle_crash(t, sig);
83563+ }
83564+
83565 return ret;
83566 }
83567
83568@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83569 ret = check_kill_permission(sig, info, p);
83570 rcu_read_unlock();
83571
83572- if (!ret && sig)
83573+ if (!ret && sig) {
83574 ret = do_send_sig_info(sig, info, p, true);
83575+ if (!ret)
83576+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83577+ }
83578
83579 return ret;
83580 }
83581@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83582 int error = -ESRCH;
83583
83584 rcu_read_lock();
83585- p = find_task_by_vpid(pid);
83586+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83587+ /* allow glibc communication via tgkill to other threads in our
83588+ thread group */
83589+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83590+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83591+ p = find_task_by_vpid_unrestricted(pid);
83592+ else
83593+#endif
83594+ p = find_task_by_vpid(pid);
83595 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83596 error = check_kill_permission(sig, info, p);
83597 /*
83598@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83599 }
83600 seg = get_fs();
83601 set_fs(KERNEL_DS);
83602- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83603- (stack_t __force __user *) &uoss,
83604+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83605+ (stack_t __force_user *) &uoss,
83606 compat_user_stack_pointer());
83607 set_fs(seg);
83608 if (ret >= 0 && uoss_ptr) {
83609diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83610index eb89e18..a4e6792 100644
83611--- a/kernel/smpboot.c
83612+++ b/kernel/smpboot.c
83613@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83614 }
83615 smpboot_unpark_thread(plug_thread, cpu);
83616 }
83617- list_add(&plug_thread->list, &hotplug_threads);
83618+ pax_list_add(&plug_thread->list, &hotplug_threads);
83619 out:
83620 mutex_unlock(&smpboot_threads_lock);
83621 return ret;
83622@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83623 {
83624 get_online_cpus();
83625 mutex_lock(&smpboot_threads_lock);
83626- list_del(&plug_thread->list);
83627+ pax_list_del(&plug_thread->list);
83628 smpboot_destroy_threads(plug_thread);
83629 mutex_unlock(&smpboot_threads_lock);
83630 put_online_cpus();
83631diff --git a/kernel/softirq.c b/kernel/softirq.c
83632index adf6c00..5d89b73 100644
83633--- a/kernel/softirq.c
83634+++ b/kernel/softirq.c
83635@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83636 EXPORT_SYMBOL(irq_stat);
83637 #endif
83638
83639-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83640+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83641
83642 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83643
83644-char *softirq_to_name[NR_SOFTIRQS] = {
83645+const char * const softirq_to_name[NR_SOFTIRQS] = {
83646 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83647 "TASKLET", "SCHED", "HRTIMER", "RCU"
83648 };
83649@@ -248,7 +248,7 @@ restart:
83650 kstat_incr_softirqs_this_cpu(vec_nr);
83651
83652 trace_softirq_entry(vec_nr);
83653- h->action(h);
83654+ h->action();
83655 trace_softirq_exit(vec_nr);
83656 if (unlikely(prev_count != preempt_count())) {
83657 printk(KERN_ERR "huh, entered softirq %u %s %p"
83658@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83659 or_softirq_pending(1UL << nr);
83660 }
83661
83662-void open_softirq(int nr, void (*action)(struct softirq_action *))
83663+void __init open_softirq(int nr, void (*action)(void))
83664 {
83665 softirq_vec[nr].action = action;
83666 }
83667@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83668
83669 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83670
83671-static void tasklet_action(struct softirq_action *a)
83672+static __latent_entropy void tasklet_action(void)
83673 {
83674 struct tasklet_struct *list;
83675
83676@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83677 }
83678 }
83679
83680-static void tasklet_hi_action(struct softirq_action *a)
83681+static __latent_entropy void tasklet_hi_action(void)
83682 {
83683 struct tasklet_struct *list;
83684
83685@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83686 .notifier_call = cpu_callback
83687 };
83688
83689-static struct smp_hotplug_thread softirq_threads = {
83690+static struct smp_hotplug_thread softirq_threads __read_only = {
83691 .store = &ksoftirqd,
83692 .thread_should_run = ksoftirqd_should_run,
83693 .thread_fn = run_ksoftirqd,
83694diff --git a/kernel/srcu.c b/kernel/srcu.c
83695index 01d5ccb..cdcbee6 100644
83696--- a/kernel/srcu.c
83697+++ b/kernel/srcu.c
83698@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83699
83700 idx = ACCESS_ONCE(sp->completed) & 0x1;
83701 preempt_disable();
83702- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83703+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83704 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83705- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83706+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83707 preempt_enable();
83708 return idx;
83709 }
83710diff --git a/kernel/sys.c b/kernel/sys.c
83711index 771129b..dc0c7e3 100644
83712--- a/kernel/sys.c
83713+++ b/kernel/sys.c
83714@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83715 error = -EACCES;
83716 goto out;
83717 }
83718+
83719+ if (gr_handle_chroot_setpriority(p, niceval)) {
83720+ error = -EACCES;
83721+ goto out;
83722+ }
83723+
83724 no_nice = security_task_setnice(p, niceval);
83725 if (no_nice) {
83726 error = no_nice;
83727@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83728 goto error;
83729 }
83730
83731+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83732+ goto error;
83733+
83734 if (rgid != (gid_t) -1 ||
83735 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83736 new->sgid = new->egid;
83737@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83738 old = current_cred();
83739
83740 retval = -EPERM;
83741+
83742+ if (gr_check_group_change(kgid, kgid, kgid))
83743+ goto error;
83744+
83745 if (nsown_capable(CAP_SETGID))
83746 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83747 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83748@@ -404,7 +417,7 @@ error:
83749 /*
83750 * change the user struct in a credentials set to match the new UID
83751 */
83752-static int set_user(struct cred *new)
83753+int set_user(struct cred *new)
83754 {
83755 struct user_struct *new_user;
83756
83757@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83758 goto error;
83759 }
83760
83761+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83762+ goto error;
83763+
83764 if (!uid_eq(new->uid, old->uid)) {
83765 retval = set_user(new);
83766 if (retval < 0)
83767@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83768 old = current_cred();
83769
83770 retval = -EPERM;
83771+
83772+ if (gr_check_crash_uid(kuid))
83773+ goto error;
83774+ if (gr_check_user_change(kuid, kuid, kuid))
83775+ goto error;
83776+
83777 if (nsown_capable(CAP_SETUID)) {
83778 new->suid = new->uid = kuid;
83779 if (!uid_eq(kuid, old->uid)) {
83780@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83781 goto error;
83782 }
83783
83784+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83785+ goto error;
83786+
83787 if (ruid != (uid_t) -1) {
83788 new->uid = kruid;
83789 if (!uid_eq(kruid, old->uid)) {
83790@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83791 goto error;
83792 }
83793
83794+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83795+ goto error;
83796+
83797 if (rgid != (gid_t) -1)
83798 new->gid = krgid;
83799 if (egid != (gid_t) -1)
83800@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83801 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83802 nsown_capable(CAP_SETUID)) {
83803 if (!uid_eq(kuid, old->fsuid)) {
83804+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83805+ goto error;
83806+
83807 new->fsuid = kuid;
83808 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83809 goto change_okay;
83810 }
83811 }
83812
83813+error:
83814 abort_creds(new);
83815 return old_fsuid;
83816
83817@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83818 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83819 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83820 nsown_capable(CAP_SETGID)) {
83821+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83822+ goto error;
83823+
83824 if (!gid_eq(kgid, old->fsgid)) {
83825 new->fsgid = kgid;
83826 goto change_okay;
83827 }
83828 }
83829
83830+error:
83831 abort_creds(new);
83832 return old_fsgid;
83833
83834@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83835 return -EFAULT;
83836
83837 down_read(&uts_sem);
83838- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83839+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83840 __OLD_UTS_LEN);
83841 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83842- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83843+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83844 __OLD_UTS_LEN);
83845 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83846- error |= __copy_to_user(&name->release, &utsname()->release,
83847+ error |= __copy_to_user(name->release, &utsname()->release,
83848 __OLD_UTS_LEN);
83849 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83850- error |= __copy_to_user(&name->version, &utsname()->version,
83851+ error |= __copy_to_user(name->version, &utsname()->version,
83852 __OLD_UTS_LEN);
83853 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83854- error |= __copy_to_user(&name->machine, &utsname()->machine,
83855+ error |= __copy_to_user(name->machine, &utsname()->machine,
83856 __OLD_UTS_LEN);
83857 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83858 up_read(&uts_sem);
83859@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83860 */
83861 new_rlim->rlim_cur = 1;
83862 }
83863+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83864+ is changed to a lower value. Since tasks can be created by the same
83865+ user in between this limit change and an execve by this task, force
83866+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83867+ */
83868+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83869+ tsk->flags |= PF_NPROC_EXCEEDED;
83870 }
83871 if (!retval) {
83872 if (old_rlim)
83873diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83874index 07f6fc4..65fb3d4 100644
83875--- a/kernel/sysctl.c
83876+++ b/kernel/sysctl.c
83877@@ -93,7 +93,6 @@
83878
83879
83880 #if defined(CONFIG_SYSCTL)
83881-
83882 /* External variables not in a header file. */
83883 extern int sysctl_overcommit_memory;
83884 extern int sysctl_overcommit_ratio;
83885@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
83886
83887 /* Constants used for minimum and maximum */
83888 #ifdef CONFIG_LOCKUP_DETECTOR
83889-static int sixty = 60;
83890+static int sixty __read_only = 60;
83891 #endif
83892
83893-static int zero;
83894-static int __maybe_unused one = 1;
83895-static int __maybe_unused two = 2;
83896-static int __maybe_unused three = 3;
83897-static unsigned long one_ul = 1;
83898-static int one_hundred = 100;
83899+static int neg_one __read_only = -1;
83900+static int zero __read_only = 0;
83901+static int __maybe_unused one __read_only = 1;
83902+static int __maybe_unused two __read_only = 2;
83903+static int __maybe_unused three __read_only = 3;
83904+static unsigned long one_ul __read_only = 1;
83905+static int one_hundred __read_only = 100;
83906 #ifdef CONFIG_PRINTK
83907-static int ten_thousand = 10000;
83908+static int ten_thousand __read_only = 10000;
83909 #endif
83910
83911 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
83912@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
83913 void __user *buffer, size_t *lenp, loff_t *ppos);
83914 #endif
83915
83916-#ifdef CONFIG_PRINTK
83917 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83918 void __user *buffer, size_t *lenp, loff_t *ppos);
83919-#endif
83920
83921 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
83922 void __user *buffer, size_t *lenp, loff_t *ppos);
83923@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
83924
83925 #endif
83926
83927+extern struct ctl_table grsecurity_table[];
83928+
83929 static struct ctl_table kern_table[];
83930 static struct ctl_table vm_table[];
83931 static struct ctl_table fs_table[];
83932@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
83933 int sysctl_legacy_va_layout;
83934 #endif
83935
83936+#ifdef CONFIG_PAX_SOFTMODE
83937+static ctl_table pax_table[] = {
83938+ {
83939+ .procname = "softmode",
83940+ .data = &pax_softmode,
83941+ .maxlen = sizeof(unsigned int),
83942+ .mode = 0600,
83943+ .proc_handler = &proc_dointvec,
83944+ },
83945+
83946+ { }
83947+};
83948+#endif
83949+
83950 /* The default sysctl tables: */
83951
83952 static struct ctl_table sysctl_base_table[] = {
83953@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
83954 #endif
83955
83956 static struct ctl_table kern_table[] = {
83957+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
83958+ {
83959+ .procname = "grsecurity",
83960+ .mode = 0500,
83961+ .child = grsecurity_table,
83962+ },
83963+#endif
83964+
83965+#ifdef CONFIG_PAX_SOFTMODE
83966+ {
83967+ .procname = "pax",
83968+ .mode = 0500,
83969+ .child = pax_table,
83970+ },
83971+#endif
83972+
83973 {
83974 .procname = "sched_child_runs_first",
83975 .data = &sysctl_sched_child_runs_first,
83976@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
83977 .data = &modprobe_path,
83978 .maxlen = KMOD_PATH_LEN,
83979 .mode = 0644,
83980- .proc_handler = proc_dostring,
83981+ .proc_handler = proc_dostring_modpriv,
83982 },
83983 {
83984 .procname = "modules_disabled",
83985@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
83986 .extra1 = &zero,
83987 .extra2 = &one,
83988 },
83989+#endif
83990 {
83991 .procname = "kptr_restrict",
83992 .data = &kptr_restrict,
83993 .maxlen = sizeof(int),
83994 .mode = 0644,
83995 .proc_handler = proc_dointvec_minmax_sysadmin,
83996+#ifdef CONFIG_GRKERNSEC_HIDESYM
83997+ .extra1 = &two,
83998+#else
83999 .extra1 = &zero,
84000+#endif
84001 .extra2 = &two,
84002 },
84003-#endif
84004 {
84005 .procname = "ngroups_max",
84006 .data = &ngroups_max,
84007@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84008 */
84009 {
84010 .procname = "perf_event_paranoid",
84011- .data = &sysctl_perf_event_paranoid,
84012- .maxlen = sizeof(sysctl_perf_event_paranoid),
84013+ .data = &sysctl_perf_event_legitimately_concerned,
84014+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84015 .mode = 0644,
84016- .proc_handler = proc_dointvec,
84017+ /* go ahead, be a hero */
84018+ .proc_handler = proc_dointvec_minmax_sysadmin,
84019+ .extra1 = &neg_one,
84020+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84021+ .extra2 = &three,
84022+#else
84023+ .extra2 = &two,
84024+#endif
84025 },
84026 {
84027 .procname = "perf_event_mlock_kb",
84028@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84029 .proc_handler = proc_dointvec_minmax,
84030 .extra1 = &zero,
84031 },
84032+ {
84033+ .procname = "heap_stack_gap",
84034+ .data = &sysctl_heap_stack_gap,
84035+ .maxlen = sizeof(sysctl_heap_stack_gap),
84036+ .mode = 0644,
84037+ .proc_handler = proc_doulongvec_minmax,
84038+ },
84039 #else
84040 {
84041 .procname = "nr_trim_pages",
84042@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84043 buffer, lenp, ppos);
84044 }
84045
84046+int proc_dostring_modpriv(struct ctl_table *table, int write,
84047+ void __user *buffer, size_t *lenp, loff_t *ppos)
84048+{
84049+ if (write && !capable(CAP_SYS_MODULE))
84050+ return -EPERM;
84051+
84052+ return _proc_do_string(table->data, table->maxlen, write,
84053+ buffer, lenp, ppos);
84054+}
84055+
84056 static size_t proc_skip_spaces(char **buf)
84057 {
84058 size_t ret;
84059@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84060 len = strlen(tmp);
84061 if (len > *size)
84062 len = *size;
84063+ if (len > sizeof(tmp))
84064+ len = sizeof(tmp);
84065 if (copy_to_user(*buf, tmp, len))
84066 return -EFAULT;
84067 *size -= len;
84068@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84069 static int proc_taint(struct ctl_table *table, int write,
84070 void __user *buffer, size_t *lenp, loff_t *ppos)
84071 {
84072- struct ctl_table t;
84073+ ctl_table_no_const t;
84074 unsigned long tmptaint = get_taint();
84075 int err;
84076
84077@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84078 return err;
84079 }
84080
84081-#ifdef CONFIG_PRINTK
84082 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84083 void __user *buffer, size_t *lenp, loff_t *ppos)
84084 {
84085@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84086
84087 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84088 }
84089-#endif
84090
84091 struct do_proc_dointvec_minmax_conv_param {
84092 int *min;
84093@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84094 *i = val;
84095 } else {
84096 val = convdiv * (*i) / convmul;
84097- if (!first)
84098+ if (!first) {
84099 err = proc_put_char(&buffer, &left, '\t');
84100+ if (err)
84101+ break;
84102+ }
84103 err = proc_put_long(&buffer, &left, val, false);
84104 if (err)
84105 break;
84106@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84107 return -ENOSYS;
84108 }
84109
84110+int proc_dostring_modpriv(struct ctl_table *table, int write,
84111+ void __user *buffer, size_t *lenp, loff_t *ppos)
84112+{
84113+ return -ENOSYS;
84114+}
84115+
84116 int proc_dointvec(struct ctl_table *table, int write,
84117 void __user *buffer, size_t *lenp, loff_t *ppos)
84118 {
84119@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84120 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84121 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84122 EXPORT_SYMBOL(proc_dostring);
84123+EXPORT_SYMBOL(proc_dostring_modpriv);
84124 EXPORT_SYMBOL(proc_doulongvec_minmax);
84125 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84126diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84127index 145bb4d..b2aa969 100644
84128--- a/kernel/taskstats.c
84129+++ b/kernel/taskstats.c
84130@@ -28,9 +28,12 @@
84131 #include <linux/fs.h>
84132 #include <linux/file.h>
84133 #include <linux/pid_namespace.h>
84134+#include <linux/grsecurity.h>
84135 #include <net/genetlink.h>
84136 #include <linux/atomic.h>
84137
84138+extern int gr_is_taskstats_denied(int pid);
84139+
84140 /*
84141 * Maximum length of a cpumask that can be specified in
84142 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84143@@ -570,6 +573,9 @@ err:
84144
84145 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84146 {
84147+ if (gr_is_taskstats_denied(current->pid))
84148+ return -EACCES;
84149+
84150 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84151 return cmd_attr_register_cpumask(info);
84152 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84153diff --git a/kernel/time.c b/kernel/time.c
84154index 7c7964c..784a599 100644
84155--- a/kernel/time.c
84156+++ b/kernel/time.c
84157@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84158 return error;
84159
84160 if (tz) {
84161+ /* we log in do_settimeofday called below, so don't log twice
84162+ */
84163+ if (!tv)
84164+ gr_log_timechange();
84165+
84166 sys_tz = *tz;
84167 update_vsyscall_tz();
84168 if (firsttime) {
84169@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84170 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84171 * value to a scaled second value.
84172 */
84173-unsigned long
84174+unsigned long __intentional_overflow(-1)
84175 timespec_to_jiffies(const struct timespec *value)
84176 {
84177 unsigned long sec = value->tv_sec;
84178diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84179index eec50fc..65e5df6 100644
84180--- a/kernel/time/alarmtimer.c
84181+++ b/kernel/time/alarmtimer.c
84182@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84183 struct platform_device *pdev;
84184 int error = 0;
84185 int i;
84186- struct k_clock alarm_clock = {
84187+ static struct k_clock alarm_clock = {
84188 .clock_getres = alarm_clock_getres,
84189 .clock_get = alarm_clock_get,
84190 .timer_create = alarm_timer_create,
84191diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84192index 947ba25..20cbade 100644
84193--- a/kernel/time/timekeeping.c
84194+++ b/kernel/time/timekeeping.c
84195@@ -15,6 +15,7 @@
84196 #include <linux/init.h>
84197 #include <linux/mm.h>
84198 #include <linux/sched.h>
84199+#include <linux/grsecurity.h>
84200 #include <linux/syscore_ops.h>
84201 #include <linux/clocksource.h>
84202 #include <linux/jiffies.h>
84203@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84204 if (!timespec_valid_strict(tv))
84205 return -EINVAL;
84206
84207+ gr_log_timechange();
84208+
84209 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84210 write_seqcount_begin(&timekeeper_seq);
84211
84212diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84213index 61ed862..3b52c65 100644
84214--- a/kernel/time/timer_list.c
84215+++ b/kernel/time/timer_list.c
84216@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84217
84218 static void print_name_offset(struct seq_file *m, void *sym)
84219 {
84220+#ifdef CONFIG_GRKERNSEC_HIDESYM
84221+ SEQ_printf(m, "<%p>", NULL);
84222+#else
84223 char symname[KSYM_NAME_LEN];
84224
84225 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84226 SEQ_printf(m, "<%pK>", sym);
84227 else
84228 SEQ_printf(m, "%s", symname);
84229+#endif
84230 }
84231
84232 static void
84233@@ -119,7 +123,11 @@ next_one:
84234 static void
84235 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84236 {
84237+#ifdef CONFIG_GRKERNSEC_HIDESYM
84238+ SEQ_printf(m, " .base: %p\n", NULL);
84239+#else
84240 SEQ_printf(m, " .base: %pK\n", base);
84241+#endif
84242 SEQ_printf(m, " .index: %d\n",
84243 base->index);
84244 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84245@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84246 {
84247 struct proc_dir_entry *pe;
84248
84249+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84250+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84251+#else
84252 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84253+#endif
84254 if (!pe)
84255 return -ENOMEM;
84256 return 0;
84257diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84258index 0b537f2..40d6c20 100644
84259--- a/kernel/time/timer_stats.c
84260+++ b/kernel/time/timer_stats.c
84261@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84262 static unsigned long nr_entries;
84263 static struct entry entries[MAX_ENTRIES];
84264
84265-static atomic_t overflow_count;
84266+static atomic_unchecked_t overflow_count;
84267
84268 /*
84269 * The entries are in a hash-table, for fast lookup:
84270@@ -140,7 +140,7 @@ static void reset_entries(void)
84271 nr_entries = 0;
84272 memset(entries, 0, sizeof(entries));
84273 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84274- atomic_set(&overflow_count, 0);
84275+ atomic_set_unchecked(&overflow_count, 0);
84276 }
84277
84278 static struct entry *alloc_entry(void)
84279@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84280 if (likely(entry))
84281 entry->count++;
84282 else
84283- atomic_inc(&overflow_count);
84284+ atomic_inc_unchecked(&overflow_count);
84285
84286 out_unlock:
84287 raw_spin_unlock_irqrestore(lock, flags);
84288@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84289
84290 static void print_name_offset(struct seq_file *m, unsigned long addr)
84291 {
84292+#ifdef CONFIG_GRKERNSEC_HIDESYM
84293+ seq_printf(m, "<%p>", NULL);
84294+#else
84295 char symname[KSYM_NAME_LEN];
84296
84297 if (lookup_symbol_name(addr, symname) < 0)
84298- seq_printf(m, "<%p>", (void *)addr);
84299+ seq_printf(m, "<%pK>", (void *)addr);
84300 else
84301 seq_printf(m, "%s", symname);
84302+#endif
84303 }
84304
84305 static int tstats_show(struct seq_file *m, void *v)
84306@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84307
84308 seq_puts(m, "Timer Stats Version: v0.2\n");
84309 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84310- if (atomic_read(&overflow_count))
84311+ if (atomic_read_unchecked(&overflow_count))
84312 seq_printf(m, "Overflow: %d entries\n",
84313- atomic_read(&overflow_count));
84314+ atomic_read_unchecked(&overflow_count));
84315
84316 for (i = 0; i < nr_entries; i++) {
84317 entry = entries + i;
84318@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84319 {
84320 struct proc_dir_entry *pe;
84321
84322+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84323+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84324+#else
84325 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84326+#endif
84327 if (!pe)
84328 return -ENOMEM;
84329 return 0;
84330diff --git a/kernel/timer.c b/kernel/timer.c
84331index 4296d13..0164b04 100644
84332--- a/kernel/timer.c
84333+++ b/kernel/timer.c
84334@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84335 /*
84336 * This function runs timers and the timer-tq in bottom half context.
84337 */
84338-static void run_timer_softirq(struct softirq_action *h)
84339+static __latent_entropy void run_timer_softirq(void)
84340 {
84341 struct tvec_base *base = __this_cpu_read(tvec_bases);
84342
84343@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84344 *
84345 * In all cases the return value is guaranteed to be non-negative.
84346 */
84347-signed long __sched schedule_timeout(signed long timeout)
84348+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84349 {
84350 struct timer_list timer;
84351 unsigned long expire;
84352diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84353index b8b8560..75b1a09 100644
84354--- a/kernel/trace/blktrace.c
84355+++ b/kernel/trace/blktrace.c
84356@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84357 struct blk_trace *bt = filp->private_data;
84358 char buf[16];
84359
84360- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84361+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84362
84363 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84364 }
84365@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84366 return 1;
84367
84368 bt = buf->chan->private_data;
84369- atomic_inc(&bt->dropped);
84370+ atomic_inc_unchecked(&bt->dropped);
84371 return 0;
84372 }
84373
84374@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84375
84376 bt->dir = dir;
84377 bt->dev = dev;
84378- atomic_set(&bt->dropped, 0);
84379+ atomic_set_unchecked(&bt->dropped, 0);
84380
84381 ret = -EIO;
84382 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84383diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84384index a6d098c..bb8cf65 100644
84385--- a/kernel/trace/ftrace.c
84386+++ b/kernel/trace/ftrace.c
84387@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84388 if (unlikely(ftrace_disabled))
84389 return 0;
84390
84391+ ret = ftrace_arch_code_modify_prepare();
84392+ FTRACE_WARN_ON(ret);
84393+ if (ret)
84394+ return 0;
84395+
84396 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84397+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84398 if (ret) {
84399 ftrace_bug(ret, ip);
84400- return 0;
84401 }
84402- return 1;
84403+ return ret ? 0 : 1;
84404 }
84405
84406 /*
84407@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84408 if (!count)
84409 return 0;
84410
84411+ pax_open_kernel();
84412 sort(start, count, sizeof(*start),
84413 ftrace_cmp_ips, ftrace_swap_ips);
84414+ pax_close_kernel();
84415
84416 start_pg = ftrace_allocate_pages(count);
84417 if (!start_pg)
84418@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84419 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84420
84421 static int ftrace_graph_active;
84422-static struct notifier_block ftrace_suspend_notifier;
84423-
84424 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84425 {
84426 return 0;
84427@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84428 return NOTIFY_DONE;
84429 }
84430
84431+static struct notifier_block ftrace_suspend_notifier = {
84432+ .notifier_call = ftrace_suspend_notifier_call
84433+};
84434+
84435 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84436 trace_func_graph_ent_t entryfunc)
84437 {
84438@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84439 goto out;
84440 }
84441
84442- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84443 register_pm_notifier(&ftrace_suspend_notifier);
84444
84445 ftrace_graph_active++;
84446diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84447index cc2f66f..05edd54 100644
84448--- a/kernel/trace/ring_buffer.c
84449+++ b/kernel/trace/ring_buffer.c
84450@@ -352,9 +352,9 @@ struct buffer_data_page {
84451 */
84452 struct buffer_page {
84453 struct list_head list; /* list of buffer pages */
84454- local_t write; /* index for next write */
84455+ local_unchecked_t write; /* index for next write */
84456 unsigned read; /* index for next read */
84457- local_t entries; /* entries on this page */
84458+ local_unchecked_t entries; /* entries on this page */
84459 unsigned long real_end; /* real end of data */
84460 struct buffer_data_page *page; /* Actual data page */
84461 };
84462@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84463 unsigned long last_overrun;
84464 local_t entries_bytes;
84465 local_t entries;
84466- local_t overrun;
84467- local_t commit_overrun;
84468+ local_unchecked_t overrun;
84469+ local_unchecked_t commit_overrun;
84470 local_t dropped_events;
84471 local_t committing;
84472 local_t commits;
84473@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84474 *
84475 * We add a counter to the write field to denote this.
84476 */
84477- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84478- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84479+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84480+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84481
84482 /*
84483 * Just make sure we have seen our old_write and synchronize
84484@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84485 * cmpxchg to only update if an interrupt did not already
84486 * do it for us. If the cmpxchg fails, we don't care.
84487 */
84488- (void)local_cmpxchg(&next_page->write, old_write, val);
84489- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84490+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84491+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84492
84493 /*
84494 * No need to worry about races with clearing out the commit.
84495@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84496
84497 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84498 {
84499- return local_read(&bpage->entries) & RB_WRITE_MASK;
84500+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84501 }
84502
84503 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84504 {
84505- return local_read(&bpage->write) & RB_WRITE_MASK;
84506+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84507 }
84508
84509 static int
84510@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84511 * bytes consumed in ring buffer from here.
84512 * Increment overrun to account for the lost events.
84513 */
84514- local_add(page_entries, &cpu_buffer->overrun);
84515+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84516 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84517 }
84518
84519@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84520 * it is our responsibility to update
84521 * the counters.
84522 */
84523- local_add(entries, &cpu_buffer->overrun);
84524+ local_add_unchecked(entries, &cpu_buffer->overrun);
84525 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84526
84527 /*
84528@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84529 if (tail == BUF_PAGE_SIZE)
84530 tail_page->real_end = 0;
84531
84532- local_sub(length, &tail_page->write);
84533+ local_sub_unchecked(length, &tail_page->write);
84534 return;
84535 }
84536
84537@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84538 rb_event_set_padding(event);
84539
84540 /* Set the write back to the previous setting */
84541- local_sub(length, &tail_page->write);
84542+ local_sub_unchecked(length, &tail_page->write);
84543 return;
84544 }
84545
84546@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84547
84548 /* Set write to end of buffer */
84549 length = (tail + length) - BUF_PAGE_SIZE;
84550- local_sub(length, &tail_page->write);
84551+ local_sub_unchecked(length, &tail_page->write);
84552 }
84553
84554 /*
84555@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84556 * about it.
84557 */
84558 if (unlikely(next_page == commit_page)) {
84559- local_inc(&cpu_buffer->commit_overrun);
84560+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84561 goto out_reset;
84562 }
84563
84564@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84565 cpu_buffer->tail_page) &&
84566 (cpu_buffer->commit_page ==
84567 cpu_buffer->reader_page))) {
84568- local_inc(&cpu_buffer->commit_overrun);
84569+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84570 goto out_reset;
84571 }
84572 }
84573@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84574 length += RB_LEN_TIME_EXTEND;
84575
84576 tail_page = cpu_buffer->tail_page;
84577- write = local_add_return(length, &tail_page->write);
84578+ write = local_add_return_unchecked(length, &tail_page->write);
84579
84580 /* set write to only the index of the write */
84581 write &= RB_WRITE_MASK;
84582@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84583 kmemcheck_annotate_bitfield(event, bitfield);
84584 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84585
84586- local_inc(&tail_page->entries);
84587+ local_inc_unchecked(&tail_page->entries);
84588
84589 /*
84590 * If this is the first commit on the page, then update
84591@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84592
84593 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84594 unsigned long write_mask =
84595- local_read(&bpage->write) & ~RB_WRITE_MASK;
84596+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84597 unsigned long event_length = rb_event_length(event);
84598 /*
84599 * This is on the tail page. It is possible that
84600@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84601 */
84602 old_index += write_mask;
84603 new_index += write_mask;
84604- index = local_cmpxchg(&bpage->write, old_index, new_index);
84605+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84606 if (index == old_index) {
84607 /* update counters */
84608 local_sub(event_length, &cpu_buffer->entries_bytes);
84609@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84610
84611 /* Do the likely case first */
84612 if (likely(bpage->page == (void *)addr)) {
84613- local_dec(&bpage->entries);
84614+ local_dec_unchecked(&bpage->entries);
84615 return;
84616 }
84617
84618@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84619 start = bpage;
84620 do {
84621 if (bpage->page == (void *)addr) {
84622- local_dec(&bpage->entries);
84623+ local_dec_unchecked(&bpage->entries);
84624 return;
84625 }
84626 rb_inc_page(cpu_buffer, &bpage);
84627@@ -3139,7 +3139,7 @@ static inline unsigned long
84628 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84629 {
84630 return local_read(&cpu_buffer->entries) -
84631- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84632+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84633 }
84634
84635 /**
84636@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84637 return 0;
84638
84639 cpu_buffer = buffer->buffers[cpu];
84640- ret = local_read(&cpu_buffer->overrun);
84641+ ret = local_read_unchecked(&cpu_buffer->overrun);
84642
84643 return ret;
84644 }
84645@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84646 return 0;
84647
84648 cpu_buffer = buffer->buffers[cpu];
84649- ret = local_read(&cpu_buffer->commit_overrun);
84650+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84651
84652 return ret;
84653 }
84654@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84655 /* if you care about this being correct, lock the buffer */
84656 for_each_buffer_cpu(buffer, cpu) {
84657 cpu_buffer = buffer->buffers[cpu];
84658- overruns += local_read(&cpu_buffer->overrun);
84659+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84660 }
84661
84662 return overruns;
84663@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84664 /*
84665 * Reset the reader page to size zero.
84666 */
84667- local_set(&cpu_buffer->reader_page->write, 0);
84668- local_set(&cpu_buffer->reader_page->entries, 0);
84669+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84670+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84671 local_set(&cpu_buffer->reader_page->page->commit, 0);
84672 cpu_buffer->reader_page->real_end = 0;
84673
84674@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84675 * want to compare with the last_overrun.
84676 */
84677 smp_mb();
84678- overwrite = local_read(&(cpu_buffer->overrun));
84679+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84680
84681 /*
84682 * Here's the tricky part.
84683@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84684
84685 cpu_buffer->head_page
84686 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84687- local_set(&cpu_buffer->head_page->write, 0);
84688- local_set(&cpu_buffer->head_page->entries, 0);
84689+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84690+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84691 local_set(&cpu_buffer->head_page->page->commit, 0);
84692
84693 cpu_buffer->head_page->read = 0;
84694@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84695
84696 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84697 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84698- local_set(&cpu_buffer->reader_page->write, 0);
84699- local_set(&cpu_buffer->reader_page->entries, 0);
84700+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84701+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84702 local_set(&cpu_buffer->reader_page->page->commit, 0);
84703 cpu_buffer->reader_page->read = 0;
84704
84705 local_set(&cpu_buffer->entries_bytes, 0);
84706- local_set(&cpu_buffer->overrun, 0);
84707- local_set(&cpu_buffer->commit_overrun, 0);
84708+ local_set_unchecked(&cpu_buffer->overrun, 0);
84709+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84710 local_set(&cpu_buffer->dropped_events, 0);
84711 local_set(&cpu_buffer->entries, 0);
84712 local_set(&cpu_buffer->committing, 0);
84713@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84714 rb_init_page(bpage);
84715 bpage = reader->page;
84716 reader->page = *data_page;
84717- local_set(&reader->write, 0);
84718- local_set(&reader->entries, 0);
84719+ local_set_unchecked(&reader->write, 0);
84720+ local_set_unchecked(&reader->entries, 0);
84721 reader->read = 0;
84722 *data_page = bpage;
84723
84724diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84725index 496f94d..754aeea 100644
84726--- a/kernel/trace/trace.c
84727+++ b/kernel/trace/trace.c
84728@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84729 return 0;
84730 }
84731
84732-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84733+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84734 {
84735 /* do nothing if flag is already set */
84736 if (!!(trace_flags & mask) == !!enabled)
84737diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84738index afaae41..64871f8 100644
84739--- a/kernel/trace/trace.h
84740+++ b/kernel/trace/trace.h
84741@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84742 void trace_printk_init_buffers(void);
84743 void trace_printk_start_comm(void);
84744 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84745-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84746+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84747
84748 /*
84749 * Normal trace_printk() and friends allocates special buffers
84750diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84751index 26dc348..8708ca7 100644
84752--- a/kernel/trace/trace_clock.c
84753+++ b/kernel/trace/trace_clock.c
84754@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84755 return now;
84756 }
84757
84758-static atomic64_t trace_counter;
84759+static atomic64_unchecked_t trace_counter;
84760
84761 /*
84762 * trace_clock_counter(): simply an atomic counter.
84763@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84764 */
84765 u64 notrace trace_clock_counter(void)
84766 {
84767- return atomic64_add_return(1, &trace_counter);
84768+ return atomic64_inc_return_unchecked(&trace_counter);
84769 }
84770diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84771index 29a7ebc..eb473cf 100644
84772--- a/kernel/trace/trace_events.c
84773+++ b/kernel/trace/trace_events.c
84774@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84775 struct ftrace_module_file_ops {
84776 struct list_head list;
84777 struct module *mod;
84778- struct file_operations id;
84779- struct file_operations enable;
84780- struct file_operations format;
84781- struct file_operations filter;
84782 };
84783
84784 static struct ftrace_module_file_ops *
84785@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84786
84787 file_ops->mod = mod;
84788
84789- file_ops->id = ftrace_event_id_fops;
84790- file_ops->id.owner = mod;
84791-
84792- file_ops->enable = ftrace_enable_fops;
84793- file_ops->enable.owner = mod;
84794-
84795- file_ops->filter = ftrace_event_filter_fops;
84796- file_ops->filter.owner = mod;
84797-
84798- file_ops->format = ftrace_event_format_fops;
84799- file_ops->format.owner = mod;
84800+ pax_open_kernel();
84801+ mod->trace_id.owner = mod;
84802+ mod->trace_enable.owner = mod;
84803+ mod->trace_filter.owner = mod;
84804+ mod->trace_format.owner = mod;
84805+ pax_close_kernel();
84806
84807 list_add(&file_ops->list, &ftrace_module_file_list);
84808
84809@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84810 struct ftrace_module_file_ops *file_ops)
84811 {
84812 return __trace_add_new_event(call, tr,
84813- &file_ops->id, &file_ops->enable,
84814- &file_ops->filter, &file_ops->format);
84815+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84816+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84817 }
84818
84819 #else
84820diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84821index b3dcfb2..ebee344 100644
84822--- a/kernel/trace/trace_mmiotrace.c
84823+++ b/kernel/trace/trace_mmiotrace.c
84824@@ -24,7 +24,7 @@ struct header_iter {
84825 static struct trace_array *mmio_trace_array;
84826 static bool overrun_detected;
84827 static unsigned long prev_overruns;
84828-static atomic_t dropped_count;
84829+static atomic_unchecked_t dropped_count;
84830
84831 static void mmio_reset_data(struct trace_array *tr)
84832 {
84833@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84834
84835 static unsigned long count_overruns(struct trace_iterator *iter)
84836 {
84837- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84838+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84839 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84840
84841 if (over > prev_overruns)
84842@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84843 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84844 sizeof(*entry), 0, pc);
84845 if (!event) {
84846- atomic_inc(&dropped_count);
84847+ atomic_inc_unchecked(&dropped_count);
84848 return;
84849 }
84850 entry = ring_buffer_event_data(event);
84851@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84852 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84853 sizeof(*entry), 0, pc);
84854 if (!event) {
84855- atomic_inc(&dropped_count);
84856+ atomic_inc_unchecked(&dropped_count);
84857 return;
84858 }
84859 entry = ring_buffer_event_data(event);
84860diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84861index 34e7cba..6f9a729 100644
84862--- a/kernel/trace/trace_output.c
84863+++ b/kernel/trace/trace_output.c
84864@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84865
84866 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84867 if (!IS_ERR(p)) {
84868- p = mangle_path(s->buffer + s->len, p, "\n");
84869+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84870 if (p) {
84871 s->len = p - s->buffer;
84872 return 1;
84873@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84874 goto out;
84875 }
84876
84877+ pax_open_kernel();
84878 if (event->funcs->trace == NULL)
84879- event->funcs->trace = trace_nop_print;
84880+ *(void **)&event->funcs->trace = trace_nop_print;
84881 if (event->funcs->raw == NULL)
84882- event->funcs->raw = trace_nop_print;
84883+ *(void **)&event->funcs->raw = trace_nop_print;
84884 if (event->funcs->hex == NULL)
84885- event->funcs->hex = trace_nop_print;
84886+ *(void **)&event->funcs->hex = trace_nop_print;
84887 if (event->funcs->binary == NULL)
84888- event->funcs->binary = trace_nop_print;
84889+ *(void **)&event->funcs->binary = trace_nop_print;
84890+ pax_close_kernel();
84891
84892 key = event->type & (EVENT_HASHSIZE - 1);
84893
84894diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
84895index b20428c..4845a10 100644
84896--- a/kernel/trace/trace_stack.c
84897+++ b/kernel/trace/trace_stack.c
84898@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
84899 return;
84900
84901 /* we do not handle interrupt stacks yet */
84902- if (!object_is_on_stack(stack))
84903+ if (!object_starts_on_stack(stack))
84904 return;
84905
84906 local_irq_save(flags);
84907diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
84908index 9064b91..1f5d2f8 100644
84909--- a/kernel/user_namespace.c
84910+++ b/kernel/user_namespace.c
84911@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
84912 !kgid_has_mapping(parent_ns, group))
84913 return -EPERM;
84914
84915+#ifdef CONFIG_GRKERNSEC
84916+ /*
84917+ * This doesn't really inspire confidence:
84918+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
84919+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
84920+ * Increases kernel attack surface in areas developers
84921+ * previously cared little about ("low importance due
84922+ * to requiring "root" capability")
84923+ * To be removed when this code receives *proper* review
84924+ */
84925+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
84926+ !capable(CAP_SETGID))
84927+ return -EPERM;
84928+#endif
84929+
84930 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
84931 if (!ns)
84932 return -ENOMEM;
84933@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
84934 if (atomic_read(&current->mm->mm_users) > 1)
84935 return -EINVAL;
84936
84937- if (current->fs->users != 1)
84938+ if (atomic_read(&current->fs->users) != 1)
84939 return -EINVAL;
84940
84941 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
84942diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
84943index 4f69f9a..7c6f8f8 100644
84944--- a/kernel/utsname_sysctl.c
84945+++ b/kernel/utsname_sysctl.c
84946@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
84947 static int proc_do_uts_string(ctl_table *table, int write,
84948 void __user *buffer, size_t *lenp, loff_t *ppos)
84949 {
84950- struct ctl_table uts_table;
84951+ ctl_table_no_const uts_table;
84952 int r;
84953 memcpy(&uts_table, table, sizeof(uts_table));
84954 uts_table.data = get_uts(table, write);
84955diff --git a/kernel/watchdog.c b/kernel/watchdog.c
84956index 1241d8c..d5cfc28 100644
84957--- a/kernel/watchdog.c
84958+++ b/kernel/watchdog.c
84959@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
84960 static void watchdog_nmi_disable(unsigned int cpu) { return; }
84961 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
84962
84963-static struct smp_hotplug_thread watchdog_threads = {
84964+static struct smp_hotplug_thread watchdog_threads __read_only = {
84965 .store = &softlockup_watchdog,
84966 .thread_should_run = watchdog_should_run,
84967 .thread_fn = watchdog,
84968diff --git a/kernel/workqueue.c b/kernel/workqueue.c
84969index e93f7b9..989fcd7 100644
84970--- a/kernel/workqueue.c
84971+++ b/kernel/workqueue.c
84972@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
84973 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
84974 worker_flags |= WORKER_REBOUND;
84975 worker_flags &= ~WORKER_UNBOUND;
84976- ACCESS_ONCE(worker->flags) = worker_flags;
84977+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
84978 }
84979
84980 spin_unlock_irq(&pool->lock);
84981diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
84982index 1501aa5..e771896 100644
84983--- a/lib/Kconfig.debug
84984+++ b/lib/Kconfig.debug
84985@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
84986
84987 config DEBUG_WW_MUTEX_SLOWPATH
84988 bool "Wait/wound mutex debugging: Slowpath testing"
84989- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84990+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
84991 select DEBUG_LOCK_ALLOC
84992 select DEBUG_SPINLOCK
84993 select DEBUG_MUTEXES
84994@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
84995
84996 config DEBUG_LOCK_ALLOC
84997 bool "Lock debugging: detect incorrect freeing of live locks"
84998- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84999+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85000 select DEBUG_SPINLOCK
85001 select DEBUG_MUTEXES
85002 select LOCKDEP
85003@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85004
85005 config PROVE_LOCKING
85006 bool "Lock debugging: prove locking correctness"
85007- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85008+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85009 select LOCKDEP
85010 select DEBUG_SPINLOCK
85011 select DEBUG_MUTEXES
85012@@ -914,7 +914,7 @@ config LOCKDEP
85013
85014 config LOCK_STAT
85015 bool "Lock usage statistics"
85016- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85017+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85018 select LOCKDEP
85019 select DEBUG_SPINLOCK
85020 select DEBUG_MUTEXES
85021@@ -1357,6 +1357,7 @@ config LATENCYTOP
85022 depends on DEBUG_KERNEL
85023 depends on STACKTRACE_SUPPORT
85024 depends on PROC_FS
85025+ depends on !GRKERNSEC_HIDESYM
85026 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85027 select KALLSYMS
85028 select KALLSYMS_ALL
85029@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85030 config DEBUG_STRICT_USER_COPY_CHECKS
85031 bool "Strict user copy size checks"
85032 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85033- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85034+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85035 help
85036 Enabling this option turns a certain set of sanity checks for user
85037 copy operations into compile time failures.
85038@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85039
85040 config PROVIDE_OHCI1394_DMA_INIT
85041 bool "Remote debugging over FireWire early on boot"
85042- depends on PCI && X86
85043+ depends on PCI && X86 && !GRKERNSEC
85044 help
85045 If you want to debug problems which hang or crash the kernel early
85046 on boot and the crashing machine has a FireWire port, you can use
85047@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85048
85049 config FIREWIRE_OHCI_REMOTE_DMA
85050 bool "Remote debugging over FireWire with firewire-ohci"
85051- depends on FIREWIRE_OHCI
85052+ depends on FIREWIRE_OHCI && !GRKERNSEC
85053 help
85054 This option lets you use the FireWire bus for remote debugging
85055 with help of the firewire-ohci driver. It enables unfiltered
85056diff --git a/lib/Makefile b/lib/Makefile
85057index 7baccfd..3ceb95f 100644
85058--- a/lib/Makefile
85059+++ b/lib/Makefile
85060@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85061
85062 obj-$(CONFIG_BTREE) += btree.o
85063 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85064-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85065+obj-y += list_debug.o
85066 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85067
85068 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85069diff --git a/lib/bitmap.c b/lib/bitmap.c
85070index 06f7e4f..f3cf2b0 100644
85071--- a/lib/bitmap.c
85072+++ b/lib/bitmap.c
85073@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85074 {
85075 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85076 u32 chunk;
85077- const char __user __force *ubuf = (const char __user __force *)buf;
85078+ const char __user *ubuf = (const char __force_user *)buf;
85079
85080 bitmap_zero(maskp, nmaskbits);
85081
85082@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85083 {
85084 if (!access_ok(VERIFY_READ, ubuf, ulen))
85085 return -EFAULT;
85086- return __bitmap_parse((const char __force *)ubuf,
85087+ return __bitmap_parse((const char __force_kernel *)ubuf,
85088 ulen, 1, maskp, nmaskbits);
85089
85090 }
85091@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85092 {
85093 unsigned a, b;
85094 int c, old_c, totaldigits;
85095- const char __user __force *ubuf = (const char __user __force *)buf;
85096+ const char __user *ubuf = (const char __force_user *)buf;
85097 int exp_digit, in_range;
85098
85099 totaldigits = c = 0;
85100@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85101 {
85102 if (!access_ok(VERIFY_READ, ubuf, ulen))
85103 return -EFAULT;
85104- return __bitmap_parselist((const char __force *)ubuf,
85105+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85106 ulen, 1, maskp, nmaskbits);
85107 }
85108 EXPORT_SYMBOL(bitmap_parselist_user);
85109diff --git a/lib/bug.c b/lib/bug.c
85110index 1686034..a9c00c8 100644
85111--- a/lib/bug.c
85112+++ b/lib/bug.c
85113@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85114 return BUG_TRAP_TYPE_NONE;
85115
85116 bug = find_bug(bugaddr);
85117+ if (!bug)
85118+ return BUG_TRAP_TYPE_NONE;
85119
85120 file = NULL;
85121 line = 0;
85122diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85123index 37061ed..da83f48 100644
85124--- a/lib/debugobjects.c
85125+++ b/lib/debugobjects.c
85126@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85127 if (limit > 4)
85128 return;
85129
85130- is_on_stack = object_is_on_stack(addr);
85131+ is_on_stack = object_starts_on_stack(addr);
85132 if (is_on_stack == onstack)
85133 return;
85134
85135diff --git a/lib/devres.c b/lib/devres.c
85136index 8235331..5881053 100644
85137--- a/lib/devres.c
85138+++ b/lib/devres.c
85139@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85140 void devm_iounmap(struct device *dev, void __iomem *addr)
85141 {
85142 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85143- (void *)addr));
85144+ (void __force *)addr));
85145 iounmap(addr);
85146 }
85147 EXPORT_SYMBOL(devm_iounmap);
85148@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85149 {
85150 ioport_unmap(addr);
85151 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85152- devm_ioport_map_match, (void *)addr));
85153+ devm_ioport_map_match, (void __force *)addr));
85154 }
85155 EXPORT_SYMBOL(devm_ioport_unmap);
85156 #endif /* CONFIG_HAS_IOPORT */
85157diff --git a/lib/div64.c b/lib/div64.c
85158index a163b6c..9618fa5 100644
85159--- a/lib/div64.c
85160+++ b/lib/div64.c
85161@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85162 EXPORT_SYMBOL(__div64_32);
85163
85164 #ifndef div_s64_rem
85165-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85166+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85167 {
85168 u64 quotient;
85169
85170@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85171 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85172 */
85173 #ifndef div64_u64
85174-u64 div64_u64(u64 dividend, u64 divisor)
85175+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85176 {
85177 u32 high = divisor >> 32;
85178 u64 quot;
85179diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85180index d87a17a..ac0d79a 100644
85181--- a/lib/dma-debug.c
85182+++ b/lib/dma-debug.c
85183@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85184
85185 void dma_debug_add_bus(struct bus_type *bus)
85186 {
85187- struct notifier_block *nb;
85188+ notifier_block_no_const *nb;
85189
85190 if (global_disable)
85191 return;
85192@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85193
85194 static void check_for_stack(struct device *dev, void *addr)
85195 {
85196- if (object_is_on_stack(addr))
85197+ if (object_starts_on_stack(addr))
85198 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85199 "stack [addr=%p]\n", addr);
85200 }
85201diff --git a/lib/inflate.c b/lib/inflate.c
85202index 013a761..c28f3fc 100644
85203--- a/lib/inflate.c
85204+++ b/lib/inflate.c
85205@@ -269,7 +269,7 @@ static void free(void *where)
85206 malloc_ptr = free_mem_ptr;
85207 }
85208 #else
85209-#define malloc(a) kmalloc(a, GFP_KERNEL)
85210+#define malloc(a) kmalloc((a), GFP_KERNEL)
85211 #define free(a) kfree(a)
85212 #endif
85213
85214diff --git a/lib/ioremap.c b/lib/ioremap.c
85215index 0c9216c..863bd89 100644
85216--- a/lib/ioremap.c
85217+++ b/lib/ioremap.c
85218@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85219 unsigned long next;
85220
85221 phys_addr -= addr;
85222- pmd = pmd_alloc(&init_mm, pud, addr);
85223+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85224 if (!pmd)
85225 return -ENOMEM;
85226 do {
85227@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85228 unsigned long next;
85229
85230 phys_addr -= addr;
85231- pud = pud_alloc(&init_mm, pgd, addr);
85232+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85233 if (!pud)
85234 return -ENOMEM;
85235 do {
85236diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85237index bd2bea9..6b3c95e 100644
85238--- a/lib/is_single_threaded.c
85239+++ b/lib/is_single_threaded.c
85240@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85241 struct task_struct *p, *t;
85242 bool ret;
85243
85244+ if (!mm)
85245+ return true;
85246+
85247 if (atomic_read(&task->signal->live) != 1)
85248 return false;
85249
85250diff --git a/lib/kobject.c b/lib/kobject.c
85251index 4a1f33d..2f3ca75 100644
85252--- a/lib/kobject.c
85253+++ b/lib/kobject.c
85254@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85255
85256
85257 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85258-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85259+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85260
85261-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85262+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85263 {
85264 enum kobj_ns_type type = ops->type;
85265 int error;
85266diff --git a/lib/list_debug.c b/lib/list_debug.c
85267index c24c2f7..06e070b 100644
85268--- a/lib/list_debug.c
85269+++ b/lib/list_debug.c
85270@@ -11,7 +11,9 @@
85271 #include <linux/bug.h>
85272 #include <linux/kernel.h>
85273 #include <linux/rculist.h>
85274+#include <linux/mm.h>
85275
85276+#ifdef CONFIG_DEBUG_LIST
85277 /*
85278 * Insert a new entry between two known consecutive entries.
85279 *
85280@@ -19,21 +21,32 @@
85281 * the prev/next entries already!
85282 */
85283
85284-void __list_add(struct list_head *new,
85285- struct list_head *prev,
85286- struct list_head *next)
85287+static bool __list_add_debug(struct list_head *new,
85288+ struct list_head *prev,
85289+ struct list_head *next)
85290 {
85291- WARN(next->prev != prev,
85292+ if (WARN(next->prev != prev,
85293 "list_add corruption. next->prev should be "
85294 "prev (%p), but was %p. (next=%p).\n",
85295- prev, next->prev, next);
85296- WARN(prev->next != next,
85297+ prev, next->prev, next) ||
85298+ WARN(prev->next != next,
85299 "list_add corruption. prev->next should be "
85300 "next (%p), but was %p. (prev=%p).\n",
85301- next, prev->next, prev);
85302- WARN(new == prev || new == next,
85303- "list_add double add: new=%p, prev=%p, next=%p.\n",
85304- new, prev, next);
85305+ next, prev->next, prev) ||
85306+ WARN(new == prev || new == next,
85307+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85308+ new, prev, next))
85309+ return false;
85310+ return true;
85311+}
85312+
85313+void __list_add(struct list_head *new,
85314+ struct list_head *prev,
85315+ struct list_head *next)
85316+{
85317+ if (!__list_add_debug(new, prev, next))
85318+ return;
85319+
85320 next->prev = new;
85321 new->next = next;
85322 new->prev = prev;
85323@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85324 }
85325 EXPORT_SYMBOL(__list_add);
85326
85327-void __list_del_entry(struct list_head *entry)
85328+static bool __list_del_entry_debug(struct list_head *entry)
85329 {
85330 struct list_head *prev, *next;
85331
85332@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85333 WARN(next->prev != entry,
85334 "list_del corruption. next->prev should be %p, "
85335 "but was %p\n", entry, next->prev))
85336+ return false;
85337+ return true;
85338+}
85339+
85340+void __list_del_entry(struct list_head *entry)
85341+{
85342+ if (!__list_del_entry_debug(entry))
85343 return;
85344
85345- __list_del(prev, next);
85346+ __list_del(entry->prev, entry->next);
85347 }
85348 EXPORT_SYMBOL(__list_del_entry);
85349
85350@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85351 void __list_add_rcu(struct list_head *new,
85352 struct list_head *prev, struct list_head *next)
85353 {
85354- WARN(next->prev != prev,
85355- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85356- prev, next->prev, next);
85357- WARN(prev->next != next,
85358- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85359- next, prev->next, prev);
85360+ if (!__list_add_debug(new, prev, next))
85361+ return;
85362+
85363 new->next = next;
85364 new->prev = prev;
85365 rcu_assign_pointer(list_next_rcu(prev), new);
85366 next->prev = new;
85367 }
85368 EXPORT_SYMBOL(__list_add_rcu);
85369+#endif
85370+
85371+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85372+{
85373+#ifdef CONFIG_DEBUG_LIST
85374+ if (!__list_add_debug(new, prev, next))
85375+ return;
85376+#endif
85377+
85378+ pax_open_kernel();
85379+ next->prev = new;
85380+ new->next = next;
85381+ new->prev = prev;
85382+ prev->next = new;
85383+ pax_close_kernel();
85384+}
85385+EXPORT_SYMBOL(__pax_list_add);
85386+
85387+void pax_list_del(struct list_head *entry)
85388+{
85389+#ifdef CONFIG_DEBUG_LIST
85390+ if (!__list_del_entry_debug(entry))
85391+ return;
85392+#endif
85393+
85394+ pax_open_kernel();
85395+ __list_del(entry->prev, entry->next);
85396+ entry->next = LIST_POISON1;
85397+ entry->prev = LIST_POISON2;
85398+ pax_close_kernel();
85399+}
85400+EXPORT_SYMBOL(pax_list_del);
85401+
85402+void pax_list_del_init(struct list_head *entry)
85403+{
85404+ pax_open_kernel();
85405+ __list_del(entry->prev, entry->next);
85406+ INIT_LIST_HEAD(entry);
85407+ pax_close_kernel();
85408+}
85409+EXPORT_SYMBOL(pax_list_del_init);
85410+
85411+void __pax_list_add_rcu(struct list_head *new,
85412+ struct list_head *prev, struct list_head *next)
85413+{
85414+#ifdef CONFIG_DEBUG_LIST
85415+ if (!__list_add_debug(new, prev, next))
85416+ return;
85417+#endif
85418+
85419+ pax_open_kernel();
85420+ new->next = next;
85421+ new->prev = prev;
85422+ rcu_assign_pointer(list_next_rcu(prev), new);
85423+ next->prev = new;
85424+ pax_close_kernel();
85425+}
85426+EXPORT_SYMBOL(__pax_list_add_rcu);
85427+
85428+void pax_list_del_rcu(struct list_head *entry)
85429+{
85430+#ifdef CONFIG_DEBUG_LIST
85431+ if (!__list_del_entry_debug(entry))
85432+ return;
85433+#endif
85434+
85435+ pax_open_kernel();
85436+ __list_del(entry->prev, entry->next);
85437+ entry->next = LIST_POISON1;
85438+ entry->prev = LIST_POISON2;
85439+ pax_close_kernel();
85440+}
85441+EXPORT_SYMBOL(pax_list_del_rcu);
85442diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85443index 7deeb62..144eb47 100644
85444--- a/lib/percpu-refcount.c
85445+++ b/lib/percpu-refcount.c
85446@@ -29,7 +29,7 @@
85447 * can't hit 0 before we've added up all the percpu refs.
85448 */
85449
85450-#define PCPU_COUNT_BIAS (1U << 31)
85451+#define PCPU_COUNT_BIAS (1U << 30)
85452
85453 /**
85454 * percpu_ref_init - initialize a percpu refcount
85455diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85456index e796429..6e38f9f 100644
85457--- a/lib/radix-tree.c
85458+++ b/lib/radix-tree.c
85459@@ -92,7 +92,7 @@ struct radix_tree_preload {
85460 int nr;
85461 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85462 };
85463-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85464+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85465
85466 static inline void *ptr_to_indirect(void *ptr)
85467 {
85468diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85469index bb2b201..46abaf9 100644
85470--- a/lib/strncpy_from_user.c
85471+++ b/lib/strncpy_from_user.c
85472@@ -21,7 +21,7 @@
85473 */
85474 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85475 {
85476- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85477+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85478 long res = 0;
85479
85480 /*
85481diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85482index a28df52..3d55877 100644
85483--- a/lib/strnlen_user.c
85484+++ b/lib/strnlen_user.c
85485@@ -26,7 +26,7 @@
85486 */
85487 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85488 {
85489- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85490+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85491 long align, res = 0;
85492 unsigned long c;
85493
85494diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85495index d23762e..e21eab2 100644
85496--- a/lib/swiotlb.c
85497+++ b/lib/swiotlb.c
85498@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85499
85500 void
85501 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85502- dma_addr_t dev_addr)
85503+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85504 {
85505 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85506
85507diff --git a/lib/usercopy.c b/lib/usercopy.c
85508index 4f5b1dd..7cab418 100644
85509--- a/lib/usercopy.c
85510+++ b/lib/usercopy.c
85511@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85512 WARN(1, "Buffer overflow detected!\n");
85513 }
85514 EXPORT_SYMBOL(copy_from_user_overflow);
85515+
85516+void copy_to_user_overflow(void)
85517+{
85518+ WARN(1, "Buffer overflow detected!\n");
85519+}
85520+EXPORT_SYMBOL(copy_to_user_overflow);
85521diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85522index 739a363..aa668d7 100644
85523--- a/lib/vsprintf.c
85524+++ b/lib/vsprintf.c
85525@@ -16,6 +16,9 @@
85526 * - scnprintf and vscnprintf
85527 */
85528
85529+#ifdef CONFIG_GRKERNSEC_HIDESYM
85530+#define __INCLUDED_BY_HIDESYM 1
85531+#endif
85532 #include <stdarg.h>
85533 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85534 #include <linux/types.h>
85535@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85536 return number(buf, end, *(const netdev_features_t *)addr, spec);
85537 }
85538
85539+#ifdef CONFIG_GRKERNSEC_HIDESYM
85540+int kptr_restrict __read_mostly = 2;
85541+#else
85542 int kptr_restrict __read_mostly;
85543+#endif
85544
85545 /*
85546 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85547@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85548 * - 'f' For simple symbolic function names without offset
85549 * - 'S' For symbolic direct pointers with offset
85550 * - 's' For symbolic direct pointers without offset
85551+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85552 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85553 * - 'B' For backtraced symbolic direct pointers with offset
85554 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85555@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85556
85557 if (!ptr && *fmt != 'K') {
85558 /*
85559- * Print (null) with the same width as a pointer so it makes
85560+ * Print (nil) with the same width as a pointer so it makes
85561 * tabular output look nice.
85562 */
85563 if (spec.field_width == -1)
85564 spec.field_width = default_width;
85565- return string(buf, end, "(null)", spec);
85566+ return string(buf, end, "(nil)", spec);
85567 }
85568
85569 switch (*fmt) {
85570@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85571 /* Fallthrough */
85572 case 'S':
85573 case 's':
85574+#ifdef CONFIG_GRKERNSEC_HIDESYM
85575+ break;
85576+#else
85577+ return symbol_string(buf, end, ptr, spec, fmt);
85578+#endif
85579+ case 'A':
85580 case 'B':
85581 return symbol_string(buf, end, ptr, spec, fmt);
85582 case 'R':
85583@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85584 va_end(va);
85585 return buf;
85586 }
85587+ case 'P':
85588+ break;
85589 case 'K':
85590 /*
85591 * %pK cannot be used in IRQ context because its test
85592@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85593 return number(buf, end,
85594 (unsigned long long) *((phys_addr_t *)ptr), spec);
85595 }
85596+
85597+#ifdef CONFIG_GRKERNSEC_HIDESYM
85598+ /* 'P' = approved pointers to copy to userland,
85599+ as in the /proc/kallsyms case, as we make it display nothing
85600+ for non-root users, and the real contents for root users
85601+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85602+ above
85603+ */
85604+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85605+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85606+ dump_stack();
85607+ ptr = NULL;
85608+ }
85609+#endif
85610+
85611 spec.flags |= SMALL;
85612 if (spec.field_width == -1) {
85613 spec.field_width = default_width;
85614@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85615 typeof(type) value; \
85616 if (sizeof(type) == 8) { \
85617 args = PTR_ALIGN(args, sizeof(u32)); \
85618- *(u32 *)&value = *(u32 *)args; \
85619- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85620+ *(u32 *)&value = *(const u32 *)args; \
85621+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85622 } else { \
85623 args = PTR_ALIGN(args, sizeof(type)); \
85624- value = *(typeof(type) *)args; \
85625+ value = *(const typeof(type) *)args; \
85626 } \
85627 args += sizeof(type); \
85628 value; \
85629@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85630 case FORMAT_TYPE_STR: {
85631 const char *str_arg = args;
85632 args += strlen(str_arg) + 1;
85633- str = string(str, end, (char *)str_arg, spec);
85634+ str = string(str, end, str_arg, spec);
85635 break;
85636 }
85637
85638diff --git a/localversion-grsec b/localversion-grsec
85639new file mode 100644
85640index 0000000..7cd6065
85641--- /dev/null
85642+++ b/localversion-grsec
85643@@ -0,0 +1 @@
85644+-grsec
85645diff --git a/mm/Kconfig b/mm/Kconfig
85646index 6509d27..dbec5b8 100644
85647--- a/mm/Kconfig
85648+++ b/mm/Kconfig
85649@@ -317,10 +317,10 @@ config KSM
85650 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85651
85652 config DEFAULT_MMAP_MIN_ADDR
85653- int "Low address space to protect from user allocation"
85654+ int "Low address space to protect from user allocation"
85655 depends on MMU
85656- default 4096
85657- help
85658+ default 65536
85659+ help
85660 This is the portion of low virtual memory which should be protected
85661 from userspace allocation. Keeping a user from writing to low pages
85662 can help reduce the impact of kernel NULL pointer bugs.
85663@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85664
85665 config HWPOISON_INJECT
85666 tristate "HWPoison pages injector"
85667- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85668+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85669 select PROC_PAGE_MONITOR
85670
85671 config NOMMU_INITIAL_TRIM_EXCESS
85672diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85673index e04454c..ca5be3e 100644
85674--- a/mm/backing-dev.c
85675+++ b/mm/backing-dev.c
85676@@ -12,7 +12,7 @@
85677 #include <linux/device.h>
85678 #include <trace/events/writeback.h>
85679
85680-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85681+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85682
85683 struct backing_dev_info default_backing_dev_info = {
85684 .name = "default",
85685@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85686 return err;
85687
85688 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85689- atomic_long_inc_return(&bdi_seq));
85690+ atomic_long_inc_return_unchecked(&bdi_seq));
85691 if (err) {
85692 bdi_destroy(bdi);
85693 return err;
85694diff --git a/mm/filemap.c b/mm/filemap.c
85695index 4b51ac1..5aa90ff 100644
85696--- a/mm/filemap.c
85697+++ b/mm/filemap.c
85698@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85699 struct address_space *mapping = file->f_mapping;
85700
85701 if (!mapping->a_ops->readpage)
85702- return -ENOEXEC;
85703+ return -ENODEV;
85704 file_accessed(file);
85705 vma->vm_ops = &generic_file_vm_ops;
85706 return 0;
85707@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85708
85709 while (bytes) {
85710 char __user *buf = iov->iov_base + base;
85711- int copy = min(bytes, iov->iov_len - base);
85712+ size_t copy = min(bytes, iov->iov_len - base);
85713
85714 base = 0;
85715 left = __copy_from_user_inatomic(vaddr, buf, copy);
85716@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85717 BUG_ON(!in_atomic());
85718 kaddr = kmap_atomic(page);
85719 if (likely(i->nr_segs == 1)) {
85720- int left;
85721+ size_t left;
85722 char __user *buf = i->iov->iov_base + i->iov_offset;
85723 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85724 copied = bytes - left;
85725@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85726
85727 kaddr = kmap(page);
85728 if (likely(i->nr_segs == 1)) {
85729- int left;
85730+ size_t left;
85731 char __user *buf = i->iov->iov_base + i->iov_offset;
85732 left = __copy_from_user(kaddr + offset, buf, bytes);
85733 copied = bytes - left;
85734@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85735 * zero-length segments (without overruning the iovec).
85736 */
85737 while (bytes || unlikely(i->count && !iov->iov_len)) {
85738- int copy;
85739+ size_t copy;
85740
85741 copy = min(bytes, iov->iov_len - base);
85742 BUG_ON(!i->count || i->count < copy);
85743@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85744 *pos = i_size_read(inode);
85745
85746 if (limit != RLIM_INFINITY) {
85747+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85748 if (*pos >= limit) {
85749 send_sig(SIGXFSZ, current, 0);
85750 return -EFBIG;
85751diff --git a/mm/fremap.c b/mm/fremap.c
85752index 5bff081..d8189a9 100644
85753--- a/mm/fremap.c
85754+++ b/mm/fremap.c
85755@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85756 retry:
85757 vma = find_vma(mm, start);
85758
85759+#ifdef CONFIG_PAX_SEGMEXEC
85760+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85761+ goto out;
85762+#endif
85763+
85764 /*
85765 * Make sure the vma is shared, that it supports prefaulting,
85766 * and that the remapped range is valid and fully within
85767diff --git a/mm/highmem.c b/mm/highmem.c
85768index b32b70c..e512eb0 100644
85769--- a/mm/highmem.c
85770+++ b/mm/highmem.c
85771@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85772 * So no dangers, even with speculative execution.
85773 */
85774 page = pte_page(pkmap_page_table[i]);
85775+ pax_open_kernel();
85776 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85777-
85778+ pax_close_kernel();
85779 set_page_address(page, NULL);
85780 need_flush = 1;
85781 }
85782@@ -198,9 +199,11 @@ start:
85783 }
85784 }
85785 vaddr = PKMAP_ADDR(last_pkmap_nr);
85786+
85787+ pax_open_kernel();
85788 set_pte_at(&init_mm, vaddr,
85789 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85790-
85791+ pax_close_kernel();
85792 pkmap_count[last_pkmap_nr] = 1;
85793 set_page_address(page, (void *)vaddr);
85794
85795diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85796index b60f330..ee7de7e 100644
85797--- a/mm/hugetlb.c
85798+++ b/mm/hugetlb.c
85799@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85800 struct hstate *h = &default_hstate;
85801 unsigned long tmp;
85802 int ret;
85803+ ctl_table_no_const hugetlb_table;
85804
85805 tmp = h->max_huge_pages;
85806
85807 if (write && h->order >= MAX_ORDER)
85808 return -EINVAL;
85809
85810- table->data = &tmp;
85811- table->maxlen = sizeof(unsigned long);
85812- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85813+ hugetlb_table = *table;
85814+ hugetlb_table.data = &tmp;
85815+ hugetlb_table.maxlen = sizeof(unsigned long);
85816+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85817 if (ret)
85818 goto out;
85819
85820@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85821 struct hstate *h = &default_hstate;
85822 unsigned long tmp;
85823 int ret;
85824+ ctl_table_no_const hugetlb_table;
85825
85826 tmp = h->nr_overcommit_huge_pages;
85827
85828 if (write && h->order >= MAX_ORDER)
85829 return -EINVAL;
85830
85831- table->data = &tmp;
85832- table->maxlen = sizeof(unsigned long);
85833- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85834+ hugetlb_table = *table;
85835+ hugetlb_table.data = &tmp;
85836+ hugetlb_table.maxlen = sizeof(unsigned long);
85837+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85838 if (ret)
85839 goto out;
85840
85841@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85842 return 1;
85843 }
85844
85845+#ifdef CONFIG_PAX_SEGMEXEC
85846+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
85847+{
85848+ struct mm_struct *mm = vma->vm_mm;
85849+ struct vm_area_struct *vma_m;
85850+ unsigned long address_m;
85851+ pte_t *ptep_m;
85852+
85853+ vma_m = pax_find_mirror_vma(vma);
85854+ if (!vma_m)
85855+ return;
85856+
85857+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85858+ address_m = address + SEGMEXEC_TASK_SIZE;
85859+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
85860+ get_page(page_m);
85861+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
85862+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
85863+}
85864+#endif
85865+
85866 /*
85867 * Hugetlb_cow() should be called with page lock of the original hugepage held.
85868 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
85869@@ -2663,6 +2688,11 @@ retry_avoidcopy:
85870 make_huge_pte(vma, new_page, 1));
85871 page_remove_rmap(old_page);
85872 hugepage_add_new_anon_rmap(new_page, vma, address);
85873+
85874+#ifdef CONFIG_PAX_SEGMEXEC
85875+ pax_mirror_huge_pte(vma, address, new_page);
85876+#endif
85877+
85878 /* Make the old page be freed below */
85879 new_page = old_page;
85880 }
85881@@ -2821,6 +2851,10 @@ retry:
85882 && (vma->vm_flags & VM_SHARED)));
85883 set_huge_pte_at(mm, address, ptep, new_pte);
85884
85885+#ifdef CONFIG_PAX_SEGMEXEC
85886+ pax_mirror_huge_pte(vma, address, page);
85887+#endif
85888+
85889 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
85890 /* Optimization, do the COW without a second fault */
85891 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
85892@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85893 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
85894 struct hstate *h = hstate_vma(vma);
85895
85896+#ifdef CONFIG_PAX_SEGMEXEC
85897+ struct vm_area_struct *vma_m;
85898+#endif
85899+
85900 address &= huge_page_mask(h);
85901
85902 ptep = huge_pte_offset(mm, address);
85903@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85904 VM_FAULT_SET_HINDEX(hstate_index(h));
85905 }
85906
85907+#ifdef CONFIG_PAX_SEGMEXEC
85908+ vma_m = pax_find_mirror_vma(vma);
85909+ if (vma_m) {
85910+ unsigned long address_m;
85911+
85912+ if (vma->vm_start > vma_m->vm_start) {
85913+ address_m = address;
85914+ address -= SEGMEXEC_TASK_SIZE;
85915+ vma = vma_m;
85916+ h = hstate_vma(vma);
85917+ } else
85918+ address_m = address + SEGMEXEC_TASK_SIZE;
85919+
85920+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
85921+ return VM_FAULT_OOM;
85922+ address_m &= HPAGE_MASK;
85923+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
85924+ }
85925+#endif
85926+
85927 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
85928 if (!ptep)
85929 return VM_FAULT_OOM;
85930diff --git a/mm/internal.h b/mm/internal.h
85931index 4390ac6..fc60373c 100644
85932--- a/mm/internal.h
85933+++ b/mm/internal.h
85934@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
85935 * in mm/page_alloc.c
85936 */
85937 extern void __free_pages_bootmem(struct page *page, unsigned int order);
85938+extern void free_compound_page(struct page *page);
85939 extern void prep_compound_page(struct page *page, unsigned long order);
85940 #ifdef CONFIG_MEMORY_FAILURE
85941 extern bool is_free_buddy_page(struct page *page);
85942@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
85943
85944 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
85945 unsigned long, unsigned long,
85946- unsigned long, unsigned long);
85947+ unsigned long, unsigned long) __intentional_overflow(-1);
85948
85949 extern void set_pageblock_order(void);
85950 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
85951diff --git a/mm/kmemleak.c b/mm/kmemleak.c
85952index c8d7f31..2dbeffd 100644
85953--- a/mm/kmemleak.c
85954+++ b/mm/kmemleak.c
85955@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
85956
85957 for (i = 0; i < object->trace_len; i++) {
85958 void *ptr = (void *)object->trace[i];
85959- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
85960+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
85961 }
85962 }
85963
85964@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
85965 return -ENOMEM;
85966 }
85967
85968- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
85969+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
85970 &kmemleak_fops);
85971 if (!dentry)
85972 pr_warning("Failed to create the debugfs kmemleak file\n");
85973diff --git a/mm/maccess.c b/mm/maccess.c
85974index d53adf9..03a24bf 100644
85975--- a/mm/maccess.c
85976+++ b/mm/maccess.c
85977@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
85978 set_fs(KERNEL_DS);
85979 pagefault_disable();
85980 ret = __copy_from_user_inatomic(dst,
85981- (__force const void __user *)src, size);
85982+ (const void __force_user *)src, size);
85983 pagefault_enable();
85984 set_fs(old_fs);
85985
85986@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
85987
85988 set_fs(KERNEL_DS);
85989 pagefault_disable();
85990- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
85991+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
85992 pagefault_enable();
85993 set_fs(old_fs);
85994
85995diff --git a/mm/madvise.c b/mm/madvise.c
85996index 7055883..aafb1ed 100644
85997--- a/mm/madvise.c
85998+++ b/mm/madvise.c
85999@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86000 pgoff_t pgoff;
86001 unsigned long new_flags = vma->vm_flags;
86002
86003+#ifdef CONFIG_PAX_SEGMEXEC
86004+ struct vm_area_struct *vma_m;
86005+#endif
86006+
86007 switch (behavior) {
86008 case MADV_NORMAL:
86009 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86010@@ -126,6 +130,13 @@ success:
86011 /*
86012 * vm_flags is protected by the mmap_sem held in write mode.
86013 */
86014+
86015+#ifdef CONFIG_PAX_SEGMEXEC
86016+ vma_m = pax_find_mirror_vma(vma);
86017+ if (vma_m)
86018+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86019+#endif
86020+
86021 vma->vm_flags = new_flags;
86022
86023 out:
86024@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86025 struct vm_area_struct ** prev,
86026 unsigned long start, unsigned long end)
86027 {
86028+
86029+#ifdef CONFIG_PAX_SEGMEXEC
86030+ struct vm_area_struct *vma_m;
86031+#endif
86032+
86033 *prev = vma;
86034 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86035 return -EINVAL;
86036@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86037 zap_page_range(vma, start, end - start, &details);
86038 } else
86039 zap_page_range(vma, start, end - start, NULL);
86040+
86041+#ifdef CONFIG_PAX_SEGMEXEC
86042+ vma_m = pax_find_mirror_vma(vma);
86043+ if (vma_m) {
86044+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86045+ struct zap_details details = {
86046+ .nonlinear_vma = vma_m,
86047+ .last_index = ULONG_MAX,
86048+ };
86049+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86050+ } else
86051+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86052+ }
86053+#endif
86054+
86055 return 0;
86056 }
86057
86058@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86059 if (end < start)
86060 return error;
86061
86062+#ifdef CONFIG_PAX_SEGMEXEC
86063+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86064+ if (end > SEGMEXEC_TASK_SIZE)
86065+ return error;
86066+ } else
86067+#endif
86068+
86069+ if (end > TASK_SIZE)
86070+ return error;
86071+
86072 error = 0;
86073 if (end == start)
86074 return error;
86075diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86076index 2c13aa7..64cbc3f 100644
86077--- a/mm/memory-failure.c
86078+++ b/mm/memory-failure.c
86079@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86080
86081 int sysctl_memory_failure_recovery __read_mostly = 1;
86082
86083-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86084+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86085
86086 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86087
86088@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86089 pfn, t->comm, t->pid);
86090 si.si_signo = SIGBUS;
86091 si.si_errno = 0;
86092- si.si_addr = (void *)addr;
86093+ si.si_addr = (void __user *)addr;
86094 #ifdef __ARCH_SI_TRAPNO
86095 si.si_trapno = trapno;
86096 #endif
86097@@ -760,7 +760,7 @@ static struct page_state {
86098 unsigned long res;
86099 char *msg;
86100 int (*action)(struct page *p, unsigned long pfn);
86101-} error_states[] = {
86102+} __do_const error_states[] = {
86103 { reserved, reserved, "reserved kernel", me_kernel },
86104 /*
86105 * free pages are specially detected outside this table:
86106@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86107 nr_pages = 1 << compound_order(hpage);
86108 else /* normal page or thp */
86109 nr_pages = 1;
86110- atomic_long_add(nr_pages, &num_poisoned_pages);
86111+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86112
86113 /*
86114 * We need/can do nothing about count=0 pages.
86115@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86116 if (!PageHWPoison(hpage)
86117 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86118 || (p != hpage && TestSetPageHWPoison(hpage))) {
86119- atomic_long_sub(nr_pages, &num_poisoned_pages);
86120+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86121 return 0;
86122 }
86123 set_page_hwpoison_huge_page(hpage);
86124@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86125 }
86126 if (hwpoison_filter(p)) {
86127 if (TestClearPageHWPoison(p))
86128- atomic_long_sub(nr_pages, &num_poisoned_pages);
86129+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86130 unlock_page(hpage);
86131 put_page(hpage);
86132 return 0;
86133@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86134 return 0;
86135 }
86136 if (TestClearPageHWPoison(p))
86137- atomic_long_sub(nr_pages, &num_poisoned_pages);
86138+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86139 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86140 return 0;
86141 }
86142@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86143 */
86144 if (TestClearPageHWPoison(page)) {
86145 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86146- atomic_long_sub(nr_pages, &num_poisoned_pages);
86147+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86148 freeit = 1;
86149 if (PageHuge(page))
86150 clear_page_hwpoison_huge_page(page);
86151@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86152 } else {
86153 set_page_hwpoison_huge_page(hpage);
86154 dequeue_hwpoisoned_huge_page(hpage);
86155- atomic_long_add(1 << compound_trans_order(hpage),
86156+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86157 &num_poisoned_pages);
86158 }
86159 return ret;
86160@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86161 if (PageHuge(page)) {
86162 set_page_hwpoison_huge_page(hpage);
86163 dequeue_hwpoisoned_huge_page(hpage);
86164- atomic_long_add(1 << compound_trans_order(hpage),
86165+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86166 &num_poisoned_pages);
86167 } else {
86168 SetPageHWPoison(page);
86169- atomic_long_inc(&num_poisoned_pages);
86170+ atomic_long_inc_unchecked(&num_poisoned_pages);
86171 }
86172 }
86173 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86174@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86175 put_page(page);
86176 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86177 SetPageHWPoison(page);
86178- atomic_long_inc(&num_poisoned_pages);
86179+ atomic_long_inc_unchecked(&num_poisoned_pages);
86180 return 0;
86181 }
86182
86183@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86184 if (!is_free_buddy_page(page))
86185 pr_info("soft offline: %#lx: page leaked\n",
86186 pfn);
86187- atomic_long_inc(&num_poisoned_pages);
86188+ atomic_long_inc_unchecked(&num_poisoned_pages);
86189 }
86190 } else {
86191 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86192diff --git a/mm/memory.c b/mm/memory.c
86193index af84bc0..2ed0816 100644
86194--- a/mm/memory.c
86195+++ b/mm/memory.c
86196@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86197 free_pte_range(tlb, pmd, addr);
86198 } while (pmd++, addr = next, addr != end);
86199
86200+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86201 start &= PUD_MASK;
86202 if (start < floor)
86203 return;
86204@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86205 pmd = pmd_offset(pud, start);
86206 pud_clear(pud);
86207 pmd_free_tlb(tlb, pmd, start);
86208+#endif
86209+
86210 }
86211
86212 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86213@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86214 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86215 } while (pud++, addr = next, addr != end);
86216
86217+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86218 start &= PGDIR_MASK;
86219 if (start < floor)
86220 return;
86221@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86222 pud = pud_offset(pgd, start);
86223 pgd_clear(pgd);
86224 pud_free_tlb(tlb, pud, start);
86225+#endif
86226+
86227 }
86228
86229 /*
86230@@ -1645,12 +1651,6 @@ no_page_table:
86231 return page;
86232 }
86233
86234-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86235-{
86236- return stack_guard_page_start(vma, addr) ||
86237- stack_guard_page_end(vma, addr+PAGE_SIZE);
86238-}
86239-
86240 /**
86241 * __get_user_pages() - pin user pages in memory
86242 * @tsk: task_struct of target task
86243@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86244
86245 i = 0;
86246
86247- do {
86248+ while (nr_pages) {
86249 struct vm_area_struct *vma;
86250
86251- vma = find_extend_vma(mm, start);
86252+ vma = find_vma(mm, start);
86253 if (!vma && in_gate_area(mm, start)) {
86254 unsigned long pg = start & PAGE_MASK;
86255 pgd_t *pgd;
86256@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86257 goto next_page;
86258 }
86259
86260- if (!vma ||
86261+ if (!vma || start < vma->vm_start ||
86262 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86263 !(vm_flags & vma->vm_flags))
86264 return i ? : -EFAULT;
86265@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86266 int ret;
86267 unsigned int fault_flags = 0;
86268
86269- /* For mlock, just skip the stack guard page. */
86270- if (foll_flags & FOLL_MLOCK) {
86271- if (stack_guard_page(vma, start))
86272- goto next_page;
86273- }
86274 if (foll_flags & FOLL_WRITE)
86275 fault_flags |= FAULT_FLAG_WRITE;
86276 if (nonblocking)
86277@@ -1902,7 +1897,7 @@ next_page:
86278 start += page_increm * PAGE_SIZE;
86279 nr_pages -= page_increm;
86280 } while (nr_pages && start < vma->vm_end);
86281- } while (nr_pages);
86282+ }
86283 return i;
86284 }
86285 EXPORT_SYMBOL(__get_user_pages);
86286@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86287 page_add_file_rmap(page);
86288 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86289
86290+#ifdef CONFIG_PAX_SEGMEXEC
86291+ pax_mirror_file_pte(vma, addr, page, ptl);
86292+#endif
86293+
86294 retval = 0;
86295 pte_unmap_unlock(pte, ptl);
86296 return retval;
86297@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86298 if (!page_count(page))
86299 return -EINVAL;
86300 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86301+
86302+#ifdef CONFIG_PAX_SEGMEXEC
86303+ struct vm_area_struct *vma_m;
86304+#endif
86305+
86306 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86307 BUG_ON(vma->vm_flags & VM_PFNMAP);
86308 vma->vm_flags |= VM_MIXEDMAP;
86309+
86310+#ifdef CONFIG_PAX_SEGMEXEC
86311+ vma_m = pax_find_mirror_vma(vma);
86312+ if (vma_m)
86313+ vma_m->vm_flags |= VM_MIXEDMAP;
86314+#endif
86315+
86316 }
86317 return insert_page(vma, addr, page, vma->vm_page_prot);
86318 }
86319@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86320 unsigned long pfn)
86321 {
86322 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86323+ BUG_ON(vma->vm_mirror);
86324
86325 if (addr < vma->vm_start || addr >= vma->vm_end)
86326 return -EFAULT;
86327@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86328
86329 BUG_ON(pud_huge(*pud));
86330
86331- pmd = pmd_alloc(mm, pud, addr);
86332+ pmd = (mm == &init_mm) ?
86333+ pmd_alloc_kernel(mm, pud, addr) :
86334+ pmd_alloc(mm, pud, addr);
86335 if (!pmd)
86336 return -ENOMEM;
86337 do {
86338@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86339 unsigned long next;
86340 int err;
86341
86342- pud = pud_alloc(mm, pgd, addr);
86343+ pud = (mm == &init_mm) ?
86344+ pud_alloc_kernel(mm, pgd, addr) :
86345+ pud_alloc(mm, pgd, addr);
86346 if (!pud)
86347 return -ENOMEM;
86348 do {
86349@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86350 copy_user_highpage(dst, src, va, vma);
86351 }
86352
86353+#ifdef CONFIG_PAX_SEGMEXEC
86354+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86355+{
86356+ struct mm_struct *mm = vma->vm_mm;
86357+ spinlock_t *ptl;
86358+ pte_t *pte, entry;
86359+
86360+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86361+ entry = *pte;
86362+ if (!pte_present(entry)) {
86363+ if (!pte_none(entry)) {
86364+ BUG_ON(pte_file(entry));
86365+ free_swap_and_cache(pte_to_swp_entry(entry));
86366+ pte_clear_not_present_full(mm, address, pte, 0);
86367+ }
86368+ } else {
86369+ struct page *page;
86370+
86371+ flush_cache_page(vma, address, pte_pfn(entry));
86372+ entry = ptep_clear_flush(vma, address, pte);
86373+ BUG_ON(pte_dirty(entry));
86374+ page = vm_normal_page(vma, address, entry);
86375+ if (page) {
86376+ update_hiwater_rss(mm);
86377+ if (PageAnon(page))
86378+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86379+ else
86380+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86381+ page_remove_rmap(page);
86382+ page_cache_release(page);
86383+ }
86384+ }
86385+ pte_unmap_unlock(pte, ptl);
86386+}
86387+
86388+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86389+ *
86390+ * the ptl of the lower mapped page is held on entry and is not released on exit
86391+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86392+ */
86393+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86394+{
86395+ struct mm_struct *mm = vma->vm_mm;
86396+ unsigned long address_m;
86397+ spinlock_t *ptl_m;
86398+ struct vm_area_struct *vma_m;
86399+ pmd_t *pmd_m;
86400+ pte_t *pte_m, entry_m;
86401+
86402+ BUG_ON(!page_m || !PageAnon(page_m));
86403+
86404+ vma_m = pax_find_mirror_vma(vma);
86405+ if (!vma_m)
86406+ return;
86407+
86408+ BUG_ON(!PageLocked(page_m));
86409+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86410+ address_m = address + SEGMEXEC_TASK_SIZE;
86411+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86412+ pte_m = pte_offset_map(pmd_m, address_m);
86413+ ptl_m = pte_lockptr(mm, pmd_m);
86414+ if (ptl != ptl_m) {
86415+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86416+ if (!pte_none(*pte_m))
86417+ goto out;
86418+ }
86419+
86420+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86421+ page_cache_get(page_m);
86422+ page_add_anon_rmap(page_m, vma_m, address_m);
86423+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86424+ set_pte_at(mm, address_m, pte_m, entry_m);
86425+ update_mmu_cache(vma_m, address_m, pte_m);
86426+out:
86427+ if (ptl != ptl_m)
86428+ spin_unlock(ptl_m);
86429+ pte_unmap(pte_m);
86430+ unlock_page(page_m);
86431+}
86432+
86433+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86434+{
86435+ struct mm_struct *mm = vma->vm_mm;
86436+ unsigned long address_m;
86437+ spinlock_t *ptl_m;
86438+ struct vm_area_struct *vma_m;
86439+ pmd_t *pmd_m;
86440+ pte_t *pte_m, entry_m;
86441+
86442+ BUG_ON(!page_m || PageAnon(page_m));
86443+
86444+ vma_m = pax_find_mirror_vma(vma);
86445+ if (!vma_m)
86446+ return;
86447+
86448+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86449+ address_m = address + SEGMEXEC_TASK_SIZE;
86450+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86451+ pte_m = pte_offset_map(pmd_m, address_m);
86452+ ptl_m = pte_lockptr(mm, pmd_m);
86453+ if (ptl != ptl_m) {
86454+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86455+ if (!pte_none(*pte_m))
86456+ goto out;
86457+ }
86458+
86459+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86460+ page_cache_get(page_m);
86461+ page_add_file_rmap(page_m);
86462+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86463+ set_pte_at(mm, address_m, pte_m, entry_m);
86464+ update_mmu_cache(vma_m, address_m, pte_m);
86465+out:
86466+ if (ptl != ptl_m)
86467+ spin_unlock(ptl_m);
86468+ pte_unmap(pte_m);
86469+}
86470+
86471+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86472+{
86473+ struct mm_struct *mm = vma->vm_mm;
86474+ unsigned long address_m;
86475+ spinlock_t *ptl_m;
86476+ struct vm_area_struct *vma_m;
86477+ pmd_t *pmd_m;
86478+ pte_t *pte_m, entry_m;
86479+
86480+ vma_m = pax_find_mirror_vma(vma);
86481+ if (!vma_m)
86482+ return;
86483+
86484+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86485+ address_m = address + SEGMEXEC_TASK_SIZE;
86486+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86487+ pte_m = pte_offset_map(pmd_m, address_m);
86488+ ptl_m = pte_lockptr(mm, pmd_m);
86489+ if (ptl != ptl_m) {
86490+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86491+ if (!pte_none(*pte_m))
86492+ goto out;
86493+ }
86494+
86495+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86496+ set_pte_at(mm, address_m, pte_m, entry_m);
86497+out:
86498+ if (ptl != ptl_m)
86499+ spin_unlock(ptl_m);
86500+ pte_unmap(pte_m);
86501+}
86502+
86503+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86504+{
86505+ struct page *page_m;
86506+ pte_t entry;
86507+
86508+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86509+ goto out;
86510+
86511+ entry = *pte;
86512+ page_m = vm_normal_page(vma, address, entry);
86513+ if (!page_m)
86514+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86515+ else if (PageAnon(page_m)) {
86516+ if (pax_find_mirror_vma(vma)) {
86517+ pte_unmap_unlock(pte, ptl);
86518+ lock_page(page_m);
86519+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86520+ if (pte_same(entry, *pte))
86521+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86522+ else
86523+ unlock_page(page_m);
86524+ }
86525+ } else
86526+ pax_mirror_file_pte(vma, address, page_m, ptl);
86527+
86528+out:
86529+ pte_unmap_unlock(pte, ptl);
86530+}
86531+#endif
86532+
86533 /*
86534 * This routine handles present pages, when users try to write
86535 * to a shared page. It is done by copying the page to a new address
86536@@ -2809,6 +3005,12 @@ gotten:
86537 */
86538 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86539 if (likely(pte_same(*page_table, orig_pte))) {
86540+
86541+#ifdef CONFIG_PAX_SEGMEXEC
86542+ if (pax_find_mirror_vma(vma))
86543+ BUG_ON(!trylock_page(new_page));
86544+#endif
86545+
86546 if (old_page) {
86547 if (!PageAnon(old_page)) {
86548 dec_mm_counter_fast(mm, MM_FILEPAGES);
86549@@ -2860,6 +3062,10 @@ gotten:
86550 page_remove_rmap(old_page);
86551 }
86552
86553+#ifdef CONFIG_PAX_SEGMEXEC
86554+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86555+#endif
86556+
86557 /* Free the old page.. */
86558 new_page = old_page;
86559 ret |= VM_FAULT_WRITE;
86560@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86561 swap_free(entry);
86562 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86563 try_to_free_swap(page);
86564+
86565+#ifdef CONFIG_PAX_SEGMEXEC
86566+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86567+#endif
86568+
86569 unlock_page(page);
86570 if (page != swapcache) {
86571 /*
86572@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86573
86574 /* No need to invalidate - it was non-present before */
86575 update_mmu_cache(vma, address, page_table);
86576+
86577+#ifdef CONFIG_PAX_SEGMEXEC
86578+ pax_mirror_anon_pte(vma, address, page, ptl);
86579+#endif
86580+
86581 unlock:
86582 pte_unmap_unlock(page_table, ptl);
86583 out:
86584@@ -3179,40 +3395,6 @@ out_release:
86585 }
86586
86587 /*
86588- * This is like a special single-page "expand_{down|up}wards()",
86589- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86590- * doesn't hit another vma.
86591- */
86592-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86593-{
86594- address &= PAGE_MASK;
86595- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86596- struct vm_area_struct *prev = vma->vm_prev;
86597-
86598- /*
86599- * Is there a mapping abutting this one below?
86600- *
86601- * That's only ok if it's the same stack mapping
86602- * that has gotten split..
86603- */
86604- if (prev && prev->vm_end == address)
86605- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86606-
86607- expand_downwards(vma, address - PAGE_SIZE);
86608- }
86609- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86610- struct vm_area_struct *next = vma->vm_next;
86611-
86612- /* As VM_GROWSDOWN but s/below/above/ */
86613- if (next && next->vm_start == address + PAGE_SIZE)
86614- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86615-
86616- expand_upwards(vma, address + PAGE_SIZE);
86617- }
86618- return 0;
86619-}
86620-
86621-/*
86622 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86623 * but allow concurrent faults), and pte mapped but not yet locked.
86624 * We return with mmap_sem still held, but pte unmapped and unlocked.
86625@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86626 unsigned long address, pte_t *page_table, pmd_t *pmd,
86627 unsigned int flags)
86628 {
86629- struct page *page;
86630+ struct page *page = NULL;
86631 spinlock_t *ptl;
86632 pte_t entry;
86633
86634- pte_unmap(page_table);
86635-
86636- /* Check if we need to add a guard page to the stack */
86637- if (check_stack_guard_page(vma, address) < 0)
86638- return VM_FAULT_SIGBUS;
86639-
86640- /* Use the zero-page for reads */
86641 if (!(flags & FAULT_FLAG_WRITE)) {
86642 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86643 vma->vm_page_prot));
86644- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86645+ ptl = pte_lockptr(mm, pmd);
86646+ spin_lock(ptl);
86647 if (!pte_none(*page_table))
86648 goto unlock;
86649 goto setpte;
86650 }
86651
86652 /* Allocate our own private page. */
86653+ pte_unmap(page_table);
86654+
86655 if (unlikely(anon_vma_prepare(vma)))
86656 goto oom;
86657 page = alloc_zeroed_user_highpage_movable(vma, address);
86658@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86659 if (!pte_none(*page_table))
86660 goto release;
86661
86662+#ifdef CONFIG_PAX_SEGMEXEC
86663+ if (pax_find_mirror_vma(vma))
86664+ BUG_ON(!trylock_page(page));
86665+#endif
86666+
86667 inc_mm_counter_fast(mm, MM_ANONPAGES);
86668 page_add_new_anon_rmap(page, vma, address);
86669 setpte:
86670@@ -3272,6 +3455,12 @@ setpte:
86671
86672 /* No need to invalidate - it was non-present before */
86673 update_mmu_cache(vma, address, page_table);
86674+
86675+#ifdef CONFIG_PAX_SEGMEXEC
86676+ if (page)
86677+ pax_mirror_anon_pte(vma, address, page, ptl);
86678+#endif
86679+
86680 unlock:
86681 pte_unmap_unlock(page_table, ptl);
86682 return 0;
86683@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86684 */
86685 /* Only go through if we didn't race with anybody else... */
86686 if (likely(pte_same(*page_table, orig_pte))) {
86687+
86688+#ifdef CONFIG_PAX_SEGMEXEC
86689+ if (anon && pax_find_mirror_vma(vma))
86690+ BUG_ON(!trylock_page(page));
86691+#endif
86692+
86693 flush_icache_page(vma, page);
86694 entry = mk_pte(page, vma->vm_page_prot);
86695 if (flags & FAULT_FLAG_WRITE)
86696@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86697
86698 /* no need to invalidate: a not-present page won't be cached */
86699 update_mmu_cache(vma, address, page_table);
86700+
86701+#ifdef CONFIG_PAX_SEGMEXEC
86702+ if (anon)
86703+ pax_mirror_anon_pte(vma, address, page, ptl);
86704+ else
86705+ pax_mirror_file_pte(vma, address, page, ptl);
86706+#endif
86707+
86708 } else {
86709 if (cow_page)
86710 mem_cgroup_uncharge_page(cow_page);
86711@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86712 if (flags & FAULT_FLAG_WRITE)
86713 flush_tlb_fix_spurious_fault(vma, address);
86714 }
86715+
86716+#ifdef CONFIG_PAX_SEGMEXEC
86717+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86718+ return 0;
86719+#endif
86720+
86721 unlock:
86722 pte_unmap_unlock(pte, ptl);
86723 return 0;
86724@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86725 pmd_t *pmd;
86726 pte_t *pte;
86727
86728+#ifdef CONFIG_PAX_SEGMEXEC
86729+ struct vm_area_struct *vma_m;
86730+#endif
86731+
86732 __set_current_state(TASK_RUNNING);
86733
86734 count_vm_event(PGFAULT);
86735@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86736 if (unlikely(is_vm_hugetlb_page(vma)))
86737 return hugetlb_fault(mm, vma, address, flags);
86738
86739+#ifdef CONFIG_PAX_SEGMEXEC
86740+ vma_m = pax_find_mirror_vma(vma);
86741+ if (vma_m) {
86742+ unsigned long address_m;
86743+ pgd_t *pgd_m;
86744+ pud_t *pud_m;
86745+ pmd_t *pmd_m;
86746+
86747+ if (vma->vm_start > vma_m->vm_start) {
86748+ address_m = address;
86749+ address -= SEGMEXEC_TASK_SIZE;
86750+ vma = vma_m;
86751+ } else
86752+ address_m = address + SEGMEXEC_TASK_SIZE;
86753+
86754+ pgd_m = pgd_offset(mm, address_m);
86755+ pud_m = pud_alloc(mm, pgd_m, address_m);
86756+ if (!pud_m)
86757+ return VM_FAULT_OOM;
86758+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86759+ if (!pmd_m)
86760+ return VM_FAULT_OOM;
86761+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86762+ return VM_FAULT_OOM;
86763+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86764+ }
86765+#endif
86766+
86767 retry:
86768 pgd = pgd_offset(mm, address);
86769 pud = pud_alloc(mm, pgd, address);
86770@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86771 spin_unlock(&mm->page_table_lock);
86772 return 0;
86773 }
86774+
86775+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86776+{
86777+ pud_t *new = pud_alloc_one(mm, address);
86778+ if (!new)
86779+ return -ENOMEM;
86780+
86781+ smp_wmb(); /* See comment in __pte_alloc */
86782+
86783+ spin_lock(&mm->page_table_lock);
86784+ if (pgd_present(*pgd)) /* Another has populated it */
86785+ pud_free(mm, new);
86786+ else
86787+ pgd_populate_kernel(mm, pgd, new);
86788+ spin_unlock(&mm->page_table_lock);
86789+ return 0;
86790+}
86791 #endif /* __PAGETABLE_PUD_FOLDED */
86792
86793 #ifndef __PAGETABLE_PMD_FOLDED
86794@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86795 spin_unlock(&mm->page_table_lock);
86796 return 0;
86797 }
86798+
86799+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86800+{
86801+ pmd_t *new = pmd_alloc_one(mm, address);
86802+ if (!new)
86803+ return -ENOMEM;
86804+
86805+ smp_wmb(); /* See comment in __pte_alloc */
86806+
86807+ spin_lock(&mm->page_table_lock);
86808+#ifndef __ARCH_HAS_4LEVEL_HACK
86809+ if (pud_present(*pud)) /* Another has populated it */
86810+ pmd_free(mm, new);
86811+ else
86812+ pud_populate_kernel(mm, pud, new);
86813+#else
86814+ if (pgd_present(*pud)) /* Another has populated it */
86815+ pmd_free(mm, new);
86816+ else
86817+ pgd_populate_kernel(mm, pud, new);
86818+#endif /* __ARCH_HAS_4LEVEL_HACK */
86819+ spin_unlock(&mm->page_table_lock);
86820+ return 0;
86821+}
86822 #endif /* __PAGETABLE_PMD_FOLDED */
86823
86824 #if !defined(__HAVE_ARCH_GATE_AREA)
86825@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
86826 gate_vma.vm_start = FIXADDR_USER_START;
86827 gate_vma.vm_end = FIXADDR_USER_END;
86828 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86829- gate_vma.vm_page_prot = __P101;
86830+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86831
86832 return 0;
86833 }
86834@@ -4059,8 +4341,8 @@ out:
86835 return ret;
86836 }
86837
86838-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86839- void *buf, int len, int write)
86840+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86841+ void *buf, size_t len, int write)
86842 {
86843 resource_size_t phys_addr;
86844 unsigned long prot = 0;
86845@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86846 * Access another process' address space as given in mm. If non-NULL, use the
86847 * given task for page fault accounting.
86848 */
86849-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86850- unsigned long addr, void *buf, int len, int write)
86851+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86852+ unsigned long addr, void *buf, size_t len, int write)
86853 {
86854 struct vm_area_struct *vma;
86855 void *old_buf = buf;
86856@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86857 down_read(&mm->mmap_sem);
86858 /* ignore errors, just check how much was successfully transferred */
86859 while (len) {
86860- int bytes, ret, offset;
86861+ ssize_t bytes, ret, offset;
86862 void *maddr;
86863 struct page *page = NULL;
86864
86865@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86866 *
86867 * The caller must hold a reference on @mm.
86868 */
86869-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86870- void *buf, int len, int write)
86871+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
86872+ void *buf, size_t len, int write)
86873 {
86874 return __access_remote_vm(NULL, mm, addr, buf, len, write);
86875 }
86876@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86877 * Source/target buffer must be kernel space,
86878 * Do not walk the page table directly, use get_user_pages
86879 */
86880-int access_process_vm(struct task_struct *tsk, unsigned long addr,
86881- void *buf, int len, int write)
86882+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
86883+ void *buf, size_t len, int write)
86884 {
86885 struct mm_struct *mm;
86886- int ret;
86887+ ssize_t ret;
86888
86889 mm = get_task_mm(tsk);
86890 if (!mm)
86891diff --git a/mm/mempolicy.c b/mm/mempolicy.c
86892index 4baf12e..5497066 100644
86893--- a/mm/mempolicy.c
86894+++ b/mm/mempolicy.c
86895@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86896 unsigned long vmstart;
86897 unsigned long vmend;
86898
86899+#ifdef CONFIG_PAX_SEGMEXEC
86900+ struct vm_area_struct *vma_m;
86901+#endif
86902+
86903 vma = find_vma(mm, start);
86904 if (!vma || vma->vm_start > start)
86905 return -EFAULT;
86906@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86907 err = vma_replace_policy(vma, new_pol);
86908 if (err)
86909 goto out;
86910+
86911+#ifdef CONFIG_PAX_SEGMEXEC
86912+ vma_m = pax_find_mirror_vma(vma);
86913+ if (vma_m) {
86914+ err = vma_replace_policy(vma_m, new_pol);
86915+ if (err)
86916+ goto out;
86917+ }
86918+#endif
86919+
86920 }
86921
86922 out:
86923@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
86924
86925 if (end < start)
86926 return -EINVAL;
86927+
86928+#ifdef CONFIG_PAX_SEGMEXEC
86929+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
86930+ if (end > SEGMEXEC_TASK_SIZE)
86931+ return -EINVAL;
86932+ } else
86933+#endif
86934+
86935+ if (end > TASK_SIZE)
86936+ return -EINVAL;
86937+
86938 if (end == start)
86939 return 0;
86940
86941@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
86942 */
86943 tcred = __task_cred(task);
86944 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
86945- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
86946- !capable(CAP_SYS_NICE)) {
86947+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
86948 rcu_read_unlock();
86949 err = -EPERM;
86950 goto out_put;
86951@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
86952 goto out;
86953 }
86954
86955+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86956+ if (mm != current->mm &&
86957+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
86958+ mmput(mm);
86959+ err = -EPERM;
86960+ goto out;
86961+ }
86962+#endif
86963+
86964 err = do_migrate_pages(mm, old, new,
86965 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
86966
86967diff --git a/mm/migrate.c b/mm/migrate.c
86968index 25ca7ca..abe1836 100644
86969--- a/mm/migrate.c
86970+++ b/mm/migrate.c
86971@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
86972 */
86973 tcred = __task_cred(task);
86974 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
86975- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
86976- !capable(CAP_SYS_NICE)) {
86977+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
86978 rcu_read_unlock();
86979 err = -EPERM;
86980 goto out;
86981diff --git a/mm/mlock.c b/mm/mlock.c
86982index 79b7cf7..37472bf 100644
86983--- a/mm/mlock.c
86984+++ b/mm/mlock.c
86985@@ -13,6 +13,7 @@
86986 #include <linux/pagemap.h>
86987 #include <linux/mempolicy.h>
86988 #include <linux/syscalls.h>
86989+#include <linux/security.h>
86990 #include <linux/sched.h>
86991 #include <linux/export.h>
86992 #include <linux/rmap.h>
86993@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
86994 {
86995 unsigned long nstart, end, tmp;
86996 struct vm_area_struct * vma, * prev;
86997- int error;
86998+ int error = 0;
86999
87000 VM_BUG_ON(start & ~PAGE_MASK);
87001 VM_BUG_ON(len != PAGE_ALIGN(len));
87002@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87003 return -EINVAL;
87004 if (end == start)
87005 return 0;
87006+ if (end > TASK_SIZE)
87007+ return -EINVAL;
87008+
87009 vma = find_vma(current->mm, start);
87010 if (!vma || vma->vm_start > start)
87011 return -ENOMEM;
87012@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87013 for (nstart = start ; ; ) {
87014 vm_flags_t newflags;
87015
87016+#ifdef CONFIG_PAX_SEGMEXEC
87017+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87018+ break;
87019+#endif
87020+
87021 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87022
87023 newflags = vma->vm_flags & ~VM_LOCKED;
87024@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87025 lock_limit >>= PAGE_SHIFT;
87026
87027 /* check against resource limits */
87028+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87029 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87030 error = do_mlock(start, len, 1);
87031 up_write(&current->mm->mmap_sem);
87032@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87033 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87034 vm_flags_t newflags;
87035
87036+#ifdef CONFIG_PAX_SEGMEXEC
87037+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87038+ break;
87039+#endif
87040+
87041 newflags = vma->vm_flags & ~VM_LOCKED;
87042 if (flags & MCL_CURRENT)
87043 newflags |= VM_LOCKED;
87044
87045 /* Ignore errors */
87046 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87047+ cond_resched();
87048 }
87049 out:
87050 return 0;
87051@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87052 lock_limit >>= PAGE_SHIFT;
87053
87054 ret = -ENOMEM;
87055+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87056 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87057 capable(CAP_IPC_LOCK))
87058 ret = do_mlockall(flags);
87059diff --git a/mm/mmap.c b/mm/mmap.c
87060index f9c97d1..3468d3b 100644
87061--- a/mm/mmap.c
87062+++ b/mm/mmap.c
87063@@ -36,6 +36,7 @@
87064 #include <linux/sched/sysctl.h>
87065 #include <linux/notifier.h>
87066 #include <linux/memory.h>
87067+#include <linux/random.h>
87068
87069 #include <asm/uaccess.h>
87070 #include <asm/cacheflush.h>
87071@@ -52,6 +53,16 @@
87072 #define arch_rebalance_pgtables(addr, len) (addr)
87073 #endif
87074
87075+static inline void verify_mm_writelocked(struct mm_struct *mm)
87076+{
87077+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87078+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87079+ up_read(&mm->mmap_sem);
87080+ BUG();
87081+ }
87082+#endif
87083+}
87084+
87085 static void unmap_region(struct mm_struct *mm,
87086 struct vm_area_struct *vma, struct vm_area_struct *prev,
87087 unsigned long start, unsigned long end);
87088@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87089 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87090 *
87091 */
87092-pgprot_t protection_map[16] = {
87093+pgprot_t protection_map[16] __read_only = {
87094 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87095 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87096 };
87097
87098-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87099+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87100 {
87101- return __pgprot(pgprot_val(protection_map[vm_flags &
87102+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87103 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87104 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87105+
87106+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87107+ if (!(__supported_pte_mask & _PAGE_NX) &&
87108+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87109+ (vm_flags & (VM_READ | VM_WRITE)))
87110+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87111+#endif
87112+
87113+ return prot;
87114 }
87115 EXPORT_SYMBOL(vm_get_page_prot);
87116
87117@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87118 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87119 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87120 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87121+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87122 /*
87123 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87124 * other variables. It can be updated by several CPUs frequently.
87125@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87126 struct vm_area_struct *next = vma->vm_next;
87127
87128 might_sleep();
87129+ BUG_ON(vma->vm_mirror);
87130 if (vma->vm_ops && vma->vm_ops->close)
87131 vma->vm_ops->close(vma);
87132 if (vma->vm_file)
87133@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87134 * not page aligned -Ram Gupta
87135 */
87136 rlim = rlimit(RLIMIT_DATA);
87137+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87138 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87139 (mm->end_data - mm->start_data) > rlim)
87140 goto out;
87141@@ -933,6 +956,12 @@ static int
87142 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87143 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87144 {
87145+
87146+#ifdef CONFIG_PAX_SEGMEXEC
87147+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87148+ return 0;
87149+#endif
87150+
87151 if (is_mergeable_vma(vma, file, vm_flags) &&
87152 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87153 if (vma->vm_pgoff == vm_pgoff)
87154@@ -952,6 +981,12 @@ static int
87155 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87156 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87157 {
87158+
87159+#ifdef CONFIG_PAX_SEGMEXEC
87160+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87161+ return 0;
87162+#endif
87163+
87164 if (is_mergeable_vma(vma, file, vm_flags) &&
87165 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87166 pgoff_t vm_pglen;
87167@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87168 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87169 struct vm_area_struct *prev, unsigned long addr,
87170 unsigned long end, unsigned long vm_flags,
87171- struct anon_vma *anon_vma, struct file *file,
87172+ struct anon_vma *anon_vma, struct file *file,
87173 pgoff_t pgoff, struct mempolicy *policy)
87174 {
87175 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87176 struct vm_area_struct *area, *next;
87177 int err;
87178
87179+#ifdef CONFIG_PAX_SEGMEXEC
87180+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87181+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87182+
87183+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87184+#endif
87185+
87186 /*
87187 * We later require that vma->vm_flags == vm_flags,
87188 * so this tests vma->vm_flags & VM_SPECIAL, too.
87189@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87190 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87191 next = next->vm_next;
87192
87193+#ifdef CONFIG_PAX_SEGMEXEC
87194+ if (prev)
87195+ prev_m = pax_find_mirror_vma(prev);
87196+ if (area)
87197+ area_m = pax_find_mirror_vma(area);
87198+ if (next)
87199+ next_m = pax_find_mirror_vma(next);
87200+#endif
87201+
87202 /*
87203 * Can it merge with the predecessor?
87204 */
87205@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87206 /* cases 1, 6 */
87207 err = vma_adjust(prev, prev->vm_start,
87208 next->vm_end, prev->vm_pgoff, NULL);
87209- } else /* cases 2, 5, 7 */
87210+
87211+#ifdef CONFIG_PAX_SEGMEXEC
87212+ if (!err && prev_m)
87213+ err = vma_adjust(prev_m, prev_m->vm_start,
87214+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87215+#endif
87216+
87217+ } else { /* cases 2, 5, 7 */
87218 err = vma_adjust(prev, prev->vm_start,
87219 end, prev->vm_pgoff, NULL);
87220+
87221+#ifdef CONFIG_PAX_SEGMEXEC
87222+ if (!err && prev_m)
87223+ err = vma_adjust(prev_m, prev_m->vm_start,
87224+ end_m, prev_m->vm_pgoff, NULL);
87225+#endif
87226+
87227+ }
87228 if (err)
87229 return NULL;
87230 khugepaged_enter_vma_merge(prev);
87231@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87232 mpol_equal(policy, vma_policy(next)) &&
87233 can_vma_merge_before(next, vm_flags,
87234 anon_vma, file, pgoff+pglen)) {
87235- if (prev && addr < prev->vm_end) /* case 4 */
87236+ if (prev && addr < prev->vm_end) { /* case 4 */
87237 err = vma_adjust(prev, prev->vm_start,
87238 addr, prev->vm_pgoff, NULL);
87239- else /* cases 3, 8 */
87240+
87241+#ifdef CONFIG_PAX_SEGMEXEC
87242+ if (!err && prev_m)
87243+ err = vma_adjust(prev_m, prev_m->vm_start,
87244+ addr_m, prev_m->vm_pgoff, NULL);
87245+#endif
87246+
87247+ } else { /* cases 3, 8 */
87248 err = vma_adjust(area, addr, next->vm_end,
87249 next->vm_pgoff - pglen, NULL);
87250+
87251+#ifdef CONFIG_PAX_SEGMEXEC
87252+ if (!err && area_m)
87253+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87254+ next_m->vm_pgoff - pglen, NULL);
87255+#endif
87256+
87257+ }
87258 if (err)
87259 return NULL;
87260 khugepaged_enter_vma_merge(area);
87261@@ -1165,8 +1246,10 @@ none:
87262 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87263 struct file *file, long pages)
87264 {
87265- const unsigned long stack_flags
87266- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87267+
87268+#ifdef CONFIG_PAX_RANDMMAP
87269+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87270+#endif
87271
87272 mm->total_vm += pages;
87273
87274@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87275 mm->shared_vm += pages;
87276 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87277 mm->exec_vm += pages;
87278- } else if (flags & stack_flags)
87279+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87280 mm->stack_vm += pages;
87281 }
87282 #endif /* CONFIG_PROC_FS */
87283@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87284 * (the exception is when the underlying filesystem is noexec
87285 * mounted, in which case we dont add PROT_EXEC.)
87286 */
87287- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87288+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87289 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87290 prot |= PROT_EXEC;
87291
87292@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87293 /* Obtain the address to map to. we verify (or select) it and ensure
87294 * that it represents a valid section of the address space.
87295 */
87296- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87297+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87298 if (addr & ~PAGE_MASK)
87299 return addr;
87300
87301@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87302 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87303 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87304
87305+#ifdef CONFIG_PAX_MPROTECT
87306+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87307+
87308+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87309+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87310+ mm->binfmt->handle_mmap)
87311+ mm->binfmt->handle_mmap(file);
87312+#endif
87313+
87314+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87315+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87316+ gr_log_rwxmmap(file);
87317+
87318+#ifdef CONFIG_PAX_EMUPLT
87319+ vm_flags &= ~VM_EXEC;
87320+#else
87321+ return -EPERM;
87322+#endif
87323+
87324+ }
87325+
87326+ if (!(vm_flags & VM_EXEC))
87327+ vm_flags &= ~VM_MAYEXEC;
87328+#else
87329+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87330+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87331+#endif
87332+ else
87333+ vm_flags &= ~VM_MAYWRITE;
87334+ }
87335+#endif
87336+
87337+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87338+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87339+ vm_flags &= ~VM_PAGEEXEC;
87340+#endif
87341+
87342 if (flags & MAP_LOCKED)
87343 if (!can_do_mlock())
87344 return -EPERM;
87345@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87346 locked += mm->locked_vm;
87347 lock_limit = rlimit(RLIMIT_MEMLOCK);
87348 lock_limit >>= PAGE_SHIFT;
87349+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87350 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87351 return -EAGAIN;
87352 }
87353@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87354 vm_flags |= VM_NORESERVE;
87355 }
87356
87357+ if (!gr_acl_handle_mmap(file, prot))
87358+ return -EACCES;
87359+
87360 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87361 if (!IS_ERR_VALUE(addr) &&
87362 ((vm_flags & VM_LOCKED) ||
87363@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87364 vm_flags_t vm_flags = vma->vm_flags;
87365
87366 /* If it was private or non-writable, the write bit is already clear */
87367- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87368+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87369 return 0;
87370
87371 /* The backer wishes to know when pages are first written to? */
87372@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87373 unsigned long charged = 0;
87374 struct inode *inode = file ? file_inode(file) : NULL;
87375
87376+#ifdef CONFIG_PAX_SEGMEXEC
87377+ struct vm_area_struct *vma_m = NULL;
87378+#endif
87379+
87380+ /*
87381+ * mm->mmap_sem is required to protect against another thread
87382+ * changing the mappings in case we sleep.
87383+ */
87384+ verify_mm_writelocked(mm);
87385+
87386 /* Check against address space limit. */
87387+
87388+#ifdef CONFIG_PAX_RANDMMAP
87389+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87390+#endif
87391+
87392 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87393 unsigned long nr_pages;
87394
87395@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87396
87397 /* Clear old maps */
87398 error = -ENOMEM;
87399-munmap_back:
87400 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87401 if (do_munmap(mm, addr, len))
87402 return -ENOMEM;
87403- goto munmap_back;
87404+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87405 }
87406
87407 /*
87408@@ -1536,6 +1674,16 @@ munmap_back:
87409 goto unacct_error;
87410 }
87411
87412+#ifdef CONFIG_PAX_SEGMEXEC
87413+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87414+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87415+ if (!vma_m) {
87416+ error = -ENOMEM;
87417+ goto free_vma;
87418+ }
87419+ }
87420+#endif
87421+
87422 vma->vm_mm = mm;
87423 vma->vm_start = addr;
87424 vma->vm_end = addr + len;
87425@@ -1560,6 +1708,13 @@ munmap_back:
87426 if (error)
87427 goto unmap_and_free_vma;
87428
87429+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87430+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87431+ vma->vm_flags |= VM_PAGEEXEC;
87432+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87433+ }
87434+#endif
87435+
87436 /* Can addr have changed??
87437 *
87438 * Answer: Yes, several device drivers can do it in their
87439@@ -1598,6 +1753,11 @@ munmap_back:
87440 vma_link(mm, vma, prev, rb_link, rb_parent);
87441 file = vma->vm_file;
87442
87443+#ifdef CONFIG_PAX_SEGMEXEC
87444+ if (vma_m)
87445+ BUG_ON(pax_mirror_vma(vma_m, vma));
87446+#endif
87447+
87448 /* Once vma denies write, undo our temporary denial count */
87449 if (correct_wcount)
87450 atomic_inc(&inode->i_writecount);
87451@@ -1605,6 +1765,7 @@ out:
87452 perf_event_mmap(vma);
87453
87454 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87455+ track_exec_limit(mm, addr, addr + len, vm_flags);
87456 if (vm_flags & VM_LOCKED) {
87457 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87458 vma == get_gate_vma(current->mm)))
87459@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87460 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87461 charged = 0;
87462 free_vma:
87463+
87464+#ifdef CONFIG_PAX_SEGMEXEC
87465+ if (vma_m)
87466+ kmem_cache_free(vm_area_cachep, vma_m);
87467+#endif
87468+
87469 kmem_cache_free(vm_area_cachep, vma);
87470 unacct_error:
87471 if (charged)
87472@@ -1635,7 +1802,63 @@ unacct_error:
87473 return error;
87474 }
87475
87476-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87477+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87478+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87479+{
87480+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87481+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87482+
87483+ return 0;
87484+}
87485+#endif
87486+
87487+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87488+{
87489+ if (!vma) {
87490+#ifdef CONFIG_STACK_GROWSUP
87491+ if (addr > sysctl_heap_stack_gap)
87492+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87493+ else
87494+ vma = find_vma(current->mm, 0);
87495+ if (vma && (vma->vm_flags & VM_GROWSUP))
87496+ return false;
87497+#endif
87498+ return true;
87499+ }
87500+
87501+ if (addr + len > vma->vm_start)
87502+ return false;
87503+
87504+ if (vma->vm_flags & VM_GROWSDOWN)
87505+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87506+#ifdef CONFIG_STACK_GROWSUP
87507+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87508+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87509+#endif
87510+ else if (offset)
87511+ return offset <= vma->vm_start - addr - len;
87512+
87513+ return true;
87514+}
87515+
87516+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87517+{
87518+ if (vma->vm_start < len)
87519+ return -ENOMEM;
87520+
87521+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87522+ if (offset <= vma->vm_start - len)
87523+ return vma->vm_start - len - offset;
87524+ else
87525+ return -ENOMEM;
87526+ }
87527+
87528+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87529+ return vma->vm_start - len - sysctl_heap_stack_gap;
87530+ return -ENOMEM;
87531+}
87532+
87533+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87534 {
87535 /*
87536 * We implement the search by looking for an rbtree node that
87537@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87538 }
87539 }
87540
87541- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87542+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87543 check_current:
87544 /* Check if current node has a suitable gap */
87545 if (gap_start > high_limit)
87546 return -ENOMEM;
87547+
87548+ if (gap_end - gap_start > info->threadstack_offset)
87549+ gap_start += info->threadstack_offset;
87550+ else
87551+ gap_start = gap_end;
87552+
87553+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87554+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87555+ gap_start += sysctl_heap_stack_gap;
87556+ else
87557+ gap_start = gap_end;
87558+ }
87559+ if (vma->vm_flags & VM_GROWSDOWN) {
87560+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87561+ gap_end -= sysctl_heap_stack_gap;
87562+ else
87563+ gap_end = gap_start;
87564+ }
87565 if (gap_end >= low_limit && gap_end - gap_start >= length)
87566 goto found;
87567
87568@@ -1737,7 +1978,7 @@ found:
87569 return gap_start;
87570 }
87571
87572-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87573+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87574 {
87575 struct mm_struct *mm = current->mm;
87576 struct vm_area_struct *vma;
87577@@ -1791,6 +2032,24 @@ check_current:
87578 gap_end = vma->vm_start;
87579 if (gap_end < low_limit)
87580 return -ENOMEM;
87581+
87582+ if (gap_end - gap_start > info->threadstack_offset)
87583+ gap_end -= info->threadstack_offset;
87584+ else
87585+ gap_end = gap_start;
87586+
87587+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87588+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87589+ gap_start += sysctl_heap_stack_gap;
87590+ else
87591+ gap_start = gap_end;
87592+ }
87593+ if (vma->vm_flags & VM_GROWSDOWN) {
87594+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87595+ gap_end -= sysctl_heap_stack_gap;
87596+ else
87597+ gap_end = gap_start;
87598+ }
87599 if (gap_start <= high_limit && gap_end - gap_start >= length)
87600 goto found;
87601
87602@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87603 struct mm_struct *mm = current->mm;
87604 struct vm_area_struct *vma;
87605 struct vm_unmapped_area_info info;
87606+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87607
87608 if (len > TASK_SIZE)
87609 return -ENOMEM;
87610@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87611 if (flags & MAP_FIXED)
87612 return addr;
87613
87614+#ifdef CONFIG_PAX_RANDMMAP
87615+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87616+#endif
87617+
87618 if (addr) {
87619 addr = PAGE_ALIGN(addr);
87620 vma = find_vma(mm, addr);
87621- if (TASK_SIZE - len >= addr &&
87622- (!vma || addr + len <= vma->vm_start))
87623+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87624 return addr;
87625 }
87626
87627 info.flags = 0;
87628 info.length = len;
87629 info.low_limit = TASK_UNMAPPED_BASE;
87630+
87631+#ifdef CONFIG_PAX_RANDMMAP
87632+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87633+ info.low_limit += mm->delta_mmap;
87634+#endif
87635+
87636 info.high_limit = TASK_SIZE;
87637 info.align_mask = 0;
87638+ info.threadstack_offset = offset;
87639 return vm_unmapped_area(&info);
87640 }
87641 #endif
87642@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87643 struct mm_struct *mm = current->mm;
87644 unsigned long addr = addr0;
87645 struct vm_unmapped_area_info info;
87646+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87647
87648 /* requested length too big for entire address space */
87649 if (len > TASK_SIZE)
87650@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87651 if (flags & MAP_FIXED)
87652 return addr;
87653
87654+#ifdef CONFIG_PAX_RANDMMAP
87655+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87656+#endif
87657+
87658 /* requesting a specific address */
87659 if (addr) {
87660 addr = PAGE_ALIGN(addr);
87661 vma = find_vma(mm, addr);
87662- if (TASK_SIZE - len >= addr &&
87663- (!vma || addr + len <= vma->vm_start))
87664+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87665 return addr;
87666 }
87667
87668@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87669 info.low_limit = PAGE_SIZE;
87670 info.high_limit = mm->mmap_base;
87671 info.align_mask = 0;
87672+ info.threadstack_offset = offset;
87673 addr = vm_unmapped_area(&info);
87674
87675 /*
87676@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87677 VM_BUG_ON(addr != -ENOMEM);
87678 info.flags = 0;
87679 info.low_limit = TASK_UNMAPPED_BASE;
87680+
87681+#ifdef CONFIG_PAX_RANDMMAP
87682+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87683+ info.low_limit += mm->delta_mmap;
87684+#endif
87685+
87686 info.high_limit = TASK_SIZE;
87687 addr = vm_unmapped_area(&info);
87688 }
87689@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87690 return vma;
87691 }
87692
87693+#ifdef CONFIG_PAX_SEGMEXEC
87694+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87695+{
87696+ struct vm_area_struct *vma_m;
87697+
87698+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87699+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87700+ BUG_ON(vma->vm_mirror);
87701+ return NULL;
87702+ }
87703+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87704+ vma_m = vma->vm_mirror;
87705+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87706+ BUG_ON(vma->vm_file != vma_m->vm_file);
87707+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87708+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87709+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87710+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87711+ return vma_m;
87712+}
87713+#endif
87714+
87715 /*
87716 * Verify that the stack growth is acceptable and
87717 * update accounting. This is shared with both the
87718@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87719 return -ENOMEM;
87720
87721 /* Stack limit test */
87722+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87723 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87724 return -ENOMEM;
87725
87726@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87727 locked = mm->locked_vm + grow;
87728 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87729 limit >>= PAGE_SHIFT;
87730+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87731 if (locked > limit && !capable(CAP_IPC_LOCK))
87732 return -ENOMEM;
87733 }
87734@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87735 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87736 * vma is the last one with address > vma->vm_end. Have to extend vma.
87737 */
87738+#ifndef CONFIG_IA64
87739+static
87740+#endif
87741 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87742 {
87743 int error;
87744+ bool locknext;
87745
87746 if (!(vma->vm_flags & VM_GROWSUP))
87747 return -EFAULT;
87748
87749+ /* Also guard against wrapping around to address 0. */
87750+ if (address < PAGE_ALIGN(address+1))
87751+ address = PAGE_ALIGN(address+1);
87752+ else
87753+ return -ENOMEM;
87754+
87755 /*
87756 * We must make sure the anon_vma is allocated
87757 * so that the anon_vma locking is not a noop.
87758 */
87759 if (unlikely(anon_vma_prepare(vma)))
87760 return -ENOMEM;
87761+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87762+ if (locknext && anon_vma_prepare(vma->vm_next))
87763+ return -ENOMEM;
87764 vma_lock_anon_vma(vma);
87765+ if (locknext)
87766+ vma_lock_anon_vma(vma->vm_next);
87767
87768 /*
87769 * vma->vm_start/vm_end cannot change under us because the caller
87770 * is required to hold the mmap_sem in read mode. We need the
87771- * anon_vma lock to serialize against concurrent expand_stacks.
87772- * Also guard against wrapping around to address 0.
87773+ * anon_vma locks to serialize against concurrent expand_stacks
87774+ * and expand_upwards.
87775 */
87776- if (address < PAGE_ALIGN(address+4))
87777- address = PAGE_ALIGN(address+4);
87778- else {
87779- vma_unlock_anon_vma(vma);
87780- return -ENOMEM;
87781- }
87782 error = 0;
87783
87784 /* Somebody else might have raced and expanded it already */
87785- if (address > vma->vm_end) {
87786+ 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)
87787+ error = -ENOMEM;
87788+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87789 unsigned long size, grow;
87790
87791 size = address - vma->vm_start;
87792@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87793 }
87794 }
87795 }
87796+ if (locknext)
87797+ vma_unlock_anon_vma(vma->vm_next);
87798 vma_unlock_anon_vma(vma);
87799 khugepaged_enter_vma_merge(vma);
87800 validate_mm(vma->vm_mm);
87801@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87802 unsigned long address)
87803 {
87804 int error;
87805+ bool lockprev = false;
87806+ struct vm_area_struct *prev;
87807
87808 /*
87809 * We must make sure the anon_vma is allocated
87810@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87811 if (error)
87812 return error;
87813
87814+ prev = vma->vm_prev;
87815+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87816+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87817+#endif
87818+ if (lockprev && anon_vma_prepare(prev))
87819+ return -ENOMEM;
87820+ if (lockprev)
87821+ vma_lock_anon_vma(prev);
87822+
87823 vma_lock_anon_vma(vma);
87824
87825 /*
87826@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87827 */
87828
87829 /* Somebody else might have raced and expanded it already */
87830- if (address < vma->vm_start) {
87831+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87832+ error = -ENOMEM;
87833+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
87834 unsigned long size, grow;
87835
87836+#ifdef CONFIG_PAX_SEGMEXEC
87837+ struct vm_area_struct *vma_m;
87838+
87839+ vma_m = pax_find_mirror_vma(vma);
87840+#endif
87841+
87842 size = vma->vm_end - address;
87843 grow = (vma->vm_start - address) >> PAGE_SHIFT;
87844
87845@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
87846 vma->vm_pgoff -= grow;
87847 anon_vma_interval_tree_post_update_vma(vma);
87848 vma_gap_update(vma);
87849+
87850+#ifdef CONFIG_PAX_SEGMEXEC
87851+ if (vma_m) {
87852+ anon_vma_interval_tree_pre_update_vma(vma_m);
87853+ vma_m->vm_start -= grow << PAGE_SHIFT;
87854+ vma_m->vm_pgoff -= grow;
87855+ anon_vma_interval_tree_post_update_vma(vma_m);
87856+ vma_gap_update(vma_m);
87857+ }
87858+#endif
87859+
87860 spin_unlock(&vma->vm_mm->page_table_lock);
87861
87862+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
87863 perf_event_mmap(vma);
87864 }
87865 }
87866 }
87867 vma_unlock_anon_vma(vma);
87868+ if (lockprev)
87869+ vma_unlock_anon_vma(prev);
87870 khugepaged_enter_vma_merge(vma);
87871 validate_mm(vma->vm_mm);
87872 return error;
87873@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
87874 do {
87875 long nrpages = vma_pages(vma);
87876
87877+#ifdef CONFIG_PAX_SEGMEXEC
87878+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
87879+ vma = remove_vma(vma);
87880+ continue;
87881+ }
87882+#endif
87883+
87884 if (vma->vm_flags & VM_ACCOUNT)
87885 nr_accounted += nrpages;
87886 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
87887@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
87888 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
87889 vma->vm_prev = NULL;
87890 do {
87891+
87892+#ifdef CONFIG_PAX_SEGMEXEC
87893+ if (vma->vm_mirror) {
87894+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
87895+ vma->vm_mirror->vm_mirror = NULL;
87896+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
87897+ vma->vm_mirror = NULL;
87898+ }
87899+#endif
87900+
87901 vma_rb_erase(vma, &mm->mm_rb);
87902 mm->map_count--;
87903 tail_vma = vma;
87904@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87905 struct vm_area_struct *new;
87906 int err = -ENOMEM;
87907
87908+#ifdef CONFIG_PAX_SEGMEXEC
87909+ struct vm_area_struct *vma_m, *new_m = NULL;
87910+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
87911+#endif
87912+
87913 if (is_vm_hugetlb_page(vma) && (addr &
87914 ~(huge_page_mask(hstate_vma(vma)))))
87915 return -EINVAL;
87916
87917+#ifdef CONFIG_PAX_SEGMEXEC
87918+ vma_m = pax_find_mirror_vma(vma);
87919+#endif
87920+
87921 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87922 if (!new)
87923 goto out_err;
87924
87925+#ifdef CONFIG_PAX_SEGMEXEC
87926+ if (vma_m) {
87927+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87928+ if (!new_m) {
87929+ kmem_cache_free(vm_area_cachep, new);
87930+ goto out_err;
87931+ }
87932+ }
87933+#endif
87934+
87935 /* most fields are the same, copy all, and then fixup */
87936 *new = *vma;
87937
87938@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87939 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
87940 }
87941
87942+#ifdef CONFIG_PAX_SEGMEXEC
87943+ if (vma_m) {
87944+ *new_m = *vma_m;
87945+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
87946+ new_m->vm_mirror = new;
87947+ new->vm_mirror = new_m;
87948+
87949+ if (new_below)
87950+ new_m->vm_end = addr_m;
87951+ else {
87952+ new_m->vm_start = addr_m;
87953+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
87954+ }
87955+ }
87956+#endif
87957+
87958 pol = mpol_dup(vma_policy(vma));
87959 if (IS_ERR(pol)) {
87960 err = PTR_ERR(pol);
87961@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87962 else
87963 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
87964
87965+#ifdef CONFIG_PAX_SEGMEXEC
87966+ if (!err && vma_m) {
87967+ if (anon_vma_clone(new_m, vma_m))
87968+ goto out_free_mpol;
87969+
87970+ mpol_get(pol);
87971+ vma_set_policy(new_m, pol);
87972+
87973+ if (new_m->vm_file)
87974+ get_file(new_m->vm_file);
87975+
87976+ if (new_m->vm_ops && new_m->vm_ops->open)
87977+ new_m->vm_ops->open(new_m);
87978+
87979+ if (new_below)
87980+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
87981+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
87982+ else
87983+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
87984+
87985+ if (err) {
87986+ if (new_m->vm_ops && new_m->vm_ops->close)
87987+ new_m->vm_ops->close(new_m);
87988+ if (new_m->vm_file)
87989+ fput(new_m->vm_file);
87990+ mpol_put(pol);
87991+ }
87992+ }
87993+#endif
87994+
87995 /* Success. */
87996 if (!err)
87997 return 0;
87998@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87999 new->vm_ops->close(new);
88000 if (new->vm_file)
88001 fput(new->vm_file);
88002- unlink_anon_vmas(new);
88003 out_free_mpol:
88004 mpol_put(pol);
88005 out_free_vma:
88006+
88007+#ifdef CONFIG_PAX_SEGMEXEC
88008+ if (new_m) {
88009+ unlink_anon_vmas(new_m);
88010+ kmem_cache_free(vm_area_cachep, new_m);
88011+ }
88012+#endif
88013+
88014+ unlink_anon_vmas(new);
88015 kmem_cache_free(vm_area_cachep, new);
88016 out_err:
88017 return err;
88018@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88019 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88020 unsigned long addr, int new_below)
88021 {
88022+
88023+#ifdef CONFIG_PAX_SEGMEXEC
88024+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88025+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88026+ if (mm->map_count >= sysctl_max_map_count-1)
88027+ return -ENOMEM;
88028+ } else
88029+#endif
88030+
88031 if (mm->map_count >= sysctl_max_map_count)
88032 return -ENOMEM;
88033
88034@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88035 * work. This now handles partial unmappings.
88036 * Jeremy Fitzhardinge <jeremy@goop.org>
88037 */
88038+#ifdef CONFIG_PAX_SEGMEXEC
88039 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88040 {
88041+ int ret = __do_munmap(mm, start, len);
88042+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88043+ return ret;
88044+
88045+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88046+}
88047+
88048+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88049+#else
88050+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88051+#endif
88052+{
88053 unsigned long end;
88054 struct vm_area_struct *vma, *prev, *last;
88055
88056+ /*
88057+ * mm->mmap_sem is required to protect against another thread
88058+ * changing the mappings in case we sleep.
88059+ */
88060+ verify_mm_writelocked(mm);
88061+
88062 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88063 return -EINVAL;
88064
88065@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88066 /* Fix up all other VM information */
88067 remove_vma_list(mm, vma);
88068
88069+ track_exec_limit(mm, start, end, 0UL);
88070+
88071 return 0;
88072 }
88073
88074@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88075 int ret;
88076 struct mm_struct *mm = current->mm;
88077
88078+
88079+#ifdef CONFIG_PAX_SEGMEXEC
88080+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88081+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88082+ return -EINVAL;
88083+#endif
88084+
88085 down_write(&mm->mmap_sem);
88086 ret = do_munmap(mm, start, len);
88087 up_write(&mm->mmap_sem);
88088@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88089 return vm_munmap(addr, len);
88090 }
88091
88092-static inline void verify_mm_writelocked(struct mm_struct *mm)
88093-{
88094-#ifdef CONFIG_DEBUG_VM
88095- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88096- WARN_ON(1);
88097- up_read(&mm->mmap_sem);
88098- }
88099-#endif
88100-}
88101-
88102 /*
88103 * this is really a simplified "do_mmap". it only handles
88104 * anonymous maps. eventually we may be able to do some
88105@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88106 struct rb_node ** rb_link, * rb_parent;
88107 pgoff_t pgoff = addr >> PAGE_SHIFT;
88108 int error;
88109+ unsigned long charged;
88110
88111 len = PAGE_ALIGN(len);
88112 if (!len)
88113@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88114
88115 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88116
88117+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88118+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88119+ flags &= ~VM_EXEC;
88120+
88121+#ifdef CONFIG_PAX_MPROTECT
88122+ if (mm->pax_flags & MF_PAX_MPROTECT)
88123+ flags &= ~VM_MAYEXEC;
88124+#endif
88125+
88126+ }
88127+#endif
88128+
88129 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88130 if (error & ~PAGE_MASK)
88131 return error;
88132
88133+ charged = len >> PAGE_SHIFT;
88134+
88135 /*
88136 * mlock MCL_FUTURE?
88137 */
88138 if (mm->def_flags & VM_LOCKED) {
88139 unsigned long locked, lock_limit;
88140- locked = len >> PAGE_SHIFT;
88141+ locked = charged;
88142 locked += mm->locked_vm;
88143 lock_limit = rlimit(RLIMIT_MEMLOCK);
88144 lock_limit >>= PAGE_SHIFT;
88145@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88146 /*
88147 * Clear old maps. this also does some error checking for us
88148 */
88149- munmap_back:
88150 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88151 if (do_munmap(mm, addr, len))
88152 return -ENOMEM;
88153- goto munmap_back;
88154+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88155 }
88156
88157 /* Check against address space limits *after* clearing old maps... */
88158- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88159+ if (!may_expand_vm(mm, charged))
88160 return -ENOMEM;
88161
88162 if (mm->map_count > sysctl_max_map_count)
88163 return -ENOMEM;
88164
88165- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88166+ if (security_vm_enough_memory_mm(mm, charged))
88167 return -ENOMEM;
88168
88169 /* Can we just expand an old private anonymous mapping? */
88170@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88171 */
88172 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88173 if (!vma) {
88174- vm_unacct_memory(len >> PAGE_SHIFT);
88175+ vm_unacct_memory(charged);
88176 return -ENOMEM;
88177 }
88178
88179@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88180 vma_link(mm, vma, prev, rb_link, rb_parent);
88181 out:
88182 perf_event_mmap(vma);
88183- mm->total_vm += len >> PAGE_SHIFT;
88184+ mm->total_vm += charged;
88185 if (flags & VM_LOCKED)
88186- mm->locked_vm += (len >> PAGE_SHIFT);
88187+ mm->locked_vm += charged;
88188+ track_exec_limit(mm, addr, addr + len, flags);
88189 return addr;
88190 }
88191
88192@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88193 while (vma) {
88194 if (vma->vm_flags & VM_ACCOUNT)
88195 nr_accounted += vma_pages(vma);
88196+ vma->vm_mirror = NULL;
88197 vma = remove_vma(vma);
88198 }
88199 vm_unacct_memory(nr_accounted);
88200@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88201 struct vm_area_struct *prev;
88202 struct rb_node **rb_link, *rb_parent;
88203
88204+#ifdef CONFIG_PAX_SEGMEXEC
88205+ struct vm_area_struct *vma_m = NULL;
88206+#endif
88207+
88208+ if (security_mmap_addr(vma->vm_start))
88209+ return -EPERM;
88210+
88211 /*
88212 * The vm_pgoff of a purely anonymous vma should be irrelevant
88213 * until its first write fault, when page's anon_vma and index
88214@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88215 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88216 return -ENOMEM;
88217
88218+#ifdef CONFIG_PAX_SEGMEXEC
88219+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88220+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88221+ if (!vma_m)
88222+ return -ENOMEM;
88223+ }
88224+#endif
88225+
88226 vma_link(mm, vma, prev, rb_link, rb_parent);
88227+
88228+#ifdef CONFIG_PAX_SEGMEXEC
88229+ if (vma_m)
88230+ BUG_ON(pax_mirror_vma(vma_m, vma));
88231+#endif
88232+
88233 return 0;
88234 }
88235
88236@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88237 struct mempolicy *pol;
88238 bool faulted_in_anon_vma = true;
88239
88240+ BUG_ON(vma->vm_mirror);
88241+
88242 /*
88243 * If anonymous vma has not yet been faulted, update new pgoff
88244 * to match new location, to increase its chance of merging.
88245@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88246 return NULL;
88247 }
88248
88249+#ifdef CONFIG_PAX_SEGMEXEC
88250+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88251+{
88252+ struct vm_area_struct *prev_m;
88253+ struct rb_node **rb_link_m, *rb_parent_m;
88254+ struct mempolicy *pol_m;
88255+
88256+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88257+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88258+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88259+ *vma_m = *vma;
88260+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88261+ if (anon_vma_clone(vma_m, vma))
88262+ return -ENOMEM;
88263+ pol_m = vma_policy(vma_m);
88264+ mpol_get(pol_m);
88265+ vma_set_policy(vma_m, pol_m);
88266+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88267+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88268+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88269+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88270+ if (vma_m->vm_file)
88271+ get_file(vma_m->vm_file);
88272+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88273+ vma_m->vm_ops->open(vma_m);
88274+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88275+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88276+ vma_m->vm_mirror = vma;
88277+ vma->vm_mirror = vma_m;
88278+ return 0;
88279+}
88280+#endif
88281+
88282 /*
88283 * Return true if the calling process may expand its vm space by the passed
88284 * number of pages
88285@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88286
88287 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88288
88289+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88290 if (cur + npages > lim)
88291 return 0;
88292 return 1;
88293@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88294 vma->vm_start = addr;
88295 vma->vm_end = addr + len;
88296
88297+#ifdef CONFIG_PAX_MPROTECT
88298+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88299+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88300+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88301+ return -EPERM;
88302+ if (!(vm_flags & VM_EXEC))
88303+ vm_flags &= ~VM_MAYEXEC;
88304+#else
88305+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88306+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88307+#endif
88308+ else
88309+ vm_flags &= ~VM_MAYWRITE;
88310+ }
88311+#endif
88312+
88313 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88314 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88315
88316diff --git a/mm/mprotect.c b/mm/mprotect.c
88317index 94722a4..e661e29 100644
88318--- a/mm/mprotect.c
88319+++ b/mm/mprotect.c
88320@@ -23,10 +23,18 @@
88321 #include <linux/mmu_notifier.h>
88322 #include <linux/migrate.h>
88323 #include <linux/perf_event.h>
88324+#include <linux/sched/sysctl.h>
88325+
88326+#ifdef CONFIG_PAX_MPROTECT
88327+#include <linux/elf.h>
88328+#include <linux/binfmts.h>
88329+#endif
88330+
88331 #include <asm/uaccess.h>
88332 #include <asm/pgtable.h>
88333 #include <asm/cacheflush.h>
88334 #include <asm/tlbflush.h>
88335+#include <asm/mmu_context.h>
88336
88337 #ifndef pgprot_modify
88338 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88339@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88340 return pages;
88341 }
88342
88343+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88344+/* called while holding the mmap semaphor for writing except stack expansion */
88345+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88346+{
88347+ unsigned long oldlimit, newlimit = 0UL;
88348+
88349+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88350+ return;
88351+
88352+ spin_lock(&mm->page_table_lock);
88353+ oldlimit = mm->context.user_cs_limit;
88354+ if ((prot & VM_EXEC) && oldlimit < end)
88355+ /* USER_CS limit moved up */
88356+ newlimit = end;
88357+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88358+ /* USER_CS limit moved down */
88359+ newlimit = start;
88360+
88361+ if (newlimit) {
88362+ mm->context.user_cs_limit = newlimit;
88363+
88364+#ifdef CONFIG_SMP
88365+ wmb();
88366+ cpus_clear(mm->context.cpu_user_cs_mask);
88367+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88368+#endif
88369+
88370+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88371+ }
88372+ spin_unlock(&mm->page_table_lock);
88373+ if (newlimit == end) {
88374+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88375+
88376+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88377+ if (is_vm_hugetlb_page(vma))
88378+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88379+ else
88380+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88381+ }
88382+}
88383+#endif
88384+
88385 int
88386 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88387 unsigned long start, unsigned long end, unsigned long newflags)
88388@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88389 int error;
88390 int dirty_accountable = 0;
88391
88392+#ifdef CONFIG_PAX_SEGMEXEC
88393+ struct vm_area_struct *vma_m = NULL;
88394+ unsigned long start_m, end_m;
88395+
88396+ start_m = start + SEGMEXEC_TASK_SIZE;
88397+ end_m = end + SEGMEXEC_TASK_SIZE;
88398+#endif
88399+
88400 if (newflags == oldflags) {
88401 *pprev = vma;
88402 return 0;
88403 }
88404
88405+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88406+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88407+
88408+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88409+ return -ENOMEM;
88410+
88411+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88412+ return -ENOMEM;
88413+ }
88414+
88415 /*
88416 * If we make a private mapping writable we increase our commit;
88417 * but (without finer accounting) cannot reduce our commit if we
88418@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88419 }
88420 }
88421
88422+#ifdef CONFIG_PAX_SEGMEXEC
88423+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88424+ if (start != vma->vm_start) {
88425+ error = split_vma(mm, vma, start, 1);
88426+ if (error)
88427+ goto fail;
88428+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88429+ *pprev = (*pprev)->vm_next;
88430+ }
88431+
88432+ if (end != vma->vm_end) {
88433+ error = split_vma(mm, vma, end, 0);
88434+ if (error)
88435+ goto fail;
88436+ }
88437+
88438+ if (pax_find_mirror_vma(vma)) {
88439+ error = __do_munmap(mm, start_m, end_m - start_m);
88440+ if (error)
88441+ goto fail;
88442+ } else {
88443+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88444+ if (!vma_m) {
88445+ error = -ENOMEM;
88446+ goto fail;
88447+ }
88448+ vma->vm_flags = newflags;
88449+ error = pax_mirror_vma(vma_m, vma);
88450+ if (error) {
88451+ vma->vm_flags = oldflags;
88452+ goto fail;
88453+ }
88454+ }
88455+ }
88456+#endif
88457+
88458 /*
88459 * First try to merge with previous and/or next vma.
88460 */
88461@@ -296,9 +400,21 @@ success:
88462 * vm_flags and vm_page_prot are protected by the mmap_sem
88463 * held in write mode.
88464 */
88465+
88466+#ifdef CONFIG_PAX_SEGMEXEC
88467+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88468+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88469+#endif
88470+
88471 vma->vm_flags = newflags;
88472+
88473+#ifdef CONFIG_PAX_MPROTECT
88474+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88475+ mm->binfmt->handle_mprotect(vma, newflags);
88476+#endif
88477+
88478 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88479- vm_get_page_prot(newflags));
88480+ vm_get_page_prot(vma->vm_flags));
88481
88482 if (vma_wants_writenotify(vma)) {
88483 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88484@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88485 end = start + len;
88486 if (end <= start)
88487 return -ENOMEM;
88488+
88489+#ifdef CONFIG_PAX_SEGMEXEC
88490+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88491+ if (end > SEGMEXEC_TASK_SIZE)
88492+ return -EINVAL;
88493+ } else
88494+#endif
88495+
88496+ if (end > TASK_SIZE)
88497+ return -EINVAL;
88498+
88499 if (!arch_validate_prot(prot))
88500 return -EINVAL;
88501
88502@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88503 /*
88504 * Does the application expect PROT_READ to imply PROT_EXEC:
88505 */
88506- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88507+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88508 prot |= PROT_EXEC;
88509
88510 vm_flags = calc_vm_prot_bits(prot);
88511@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88512 if (start > vma->vm_start)
88513 prev = vma;
88514
88515+#ifdef CONFIG_PAX_MPROTECT
88516+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88517+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88518+#endif
88519+
88520 for (nstart = start ; ; ) {
88521 unsigned long newflags;
88522
88523@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88524
88525 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88526 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88527+ if (prot & (PROT_WRITE | PROT_EXEC))
88528+ gr_log_rwxmprotect(vma);
88529+
88530+ error = -EACCES;
88531+ goto out;
88532+ }
88533+
88534+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88535 error = -EACCES;
88536 goto out;
88537 }
88538@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88539 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88540 if (error)
88541 goto out;
88542+
88543+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88544+
88545 nstart = tmp;
88546
88547 if (nstart < prev->vm_end)
88548diff --git a/mm/mremap.c b/mm/mremap.c
88549index 0843feb..5607f47 100644
88550--- a/mm/mremap.c
88551+++ b/mm/mremap.c
88552@@ -25,6 +25,7 @@
88553 #include <asm/uaccess.h>
88554 #include <asm/cacheflush.h>
88555 #include <asm/tlbflush.h>
88556+#include <asm/pgalloc.h>
88557
88558 #include "internal.h"
88559
88560@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88561 return NULL;
88562
88563 pmd = pmd_alloc(mm, pud, addr);
88564- if (!pmd)
88565+ if (!pmd) {
88566+ pud_free(mm, pud);
88567 return NULL;
88568+ }
88569
88570 VM_BUG_ON(pmd_trans_huge(*pmd));
88571
88572@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88573 continue;
88574 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88575 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88576+
88577+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88578+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88579+ pte = pte_exprotect(pte);
88580+#endif
88581+
88582 pte = move_soft_dirty_pte(pte);
88583 set_pte_at(mm, new_addr, new_pte, pte);
88584 }
88585@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88586 if (is_vm_hugetlb_page(vma))
88587 goto Einval;
88588
88589+#ifdef CONFIG_PAX_SEGMEXEC
88590+ if (pax_find_mirror_vma(vma))
88591+ goto Einval;
88592+#endif
88593+
88594 /* We can't remap across vm area boundaries */
88595 if (old_len > vma->vm_end - addr)
88596 goto Efault;
88597@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88598 unsigned long ret = -EINVAL;
88599 unsigned long charged = 0;
88600 unsigned long map_flags;
88601+ unsigned long pax_task_size = TASK_SIZE;
88602
88603 if (new_addr & ~PAGE_MASK)
88604 goto out;
88605
88606- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88607+#ifdef CONFIG_PAX_SEGMEXEC
88608+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88609+ pax_task_size = SEGMEXEC_TASK_SIZE;
88610+#endif
88611+
88612+ pax_task_size -= PAGE_SIZE;
88613+
88614+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88615 goto out;
88616
88617 /* Check if the location we're moving into overlaps the
88618 * old location at all, and fail if it does.
88619 */
88620- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88621- goto out;
88622-
88623- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88624+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88625 goto out;
88626
88627 ret = do_munmap(mm, new_addr, new_len);
88628@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88629 unsigned long ret = -EINVAL;
88630 unsigned long charged = 0;
88631 bool locked = false;
88632+ unsigned long pax_task_size = TASK_SIZE;
88633
88634 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88635 return ret;
88636@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88637 if (!new_len)
88638 return ret;
88639
88640+#ifdef CONFIG_PAX_SEGMEXEC
88641+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88642+ pax_task_size = SEGMEXEC_TASK_SIZE;
88643+#endif
88644+
88645+ pax_task_size -= PAGE_SIZE;
88646+
88647+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88648+ old_len > pax_task_size || addr > pax_task_size-old_len)
88649+ return ret;
88650+
88651 down_write(&current->mm->mmap_sem);
88652
88653 if (flags & MREMAP_FIXED) {
88654@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88655 new_addr = addr;
88656 }
88657 ret = addr;
88658+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88659 goto out;
88660 }
88661 }
88662@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88663 goto out;
88664 }
88665
88666+ map_flags = vma->vm_flags;
88667 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88668+ if (!(ret & ~PAGE_MASK)) {
88669+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88670+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88671+ }
88672 }
88673 out:
88674 if (ret & ~PAGE_MASK)
88675diff --git a/mm/nommu.c b/mm/nommu.c
88676index ecd1f15..77039bd 100644
88677--- a/mm/nommu.c
88678+++ b/mm/nommu.c
88679@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88680 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88681 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88682 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88683-int heap_stack_gap = 0;
88684
88685 atomic_long_t mmap_pages_allocated;
88686
88687@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88688 EXPORT_SYMBOL(find_vma);
88689
88690 /*
88691- * find a VMA
88692- * - we don't extend stack VMAs under NOMMU conditions
88693- */
88694-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88695-{
88696- return find_vma(mm, addr);
88697-}
88698-
88699-/*
88700 * expand a stack to a given address
88701 * - not supported under NOMMU conditions
88702 */
88703@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88704
88705 /* most fields are the same, copy all, and then fixup */
88706 *new = *vma;
88707+ INIT_LIST_HEAD(&new->anon_vma_chain);
88708 *region = *vma->vm_region;
88709 new->vm_region = region;
88710
88711@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88712 }
88713 EXPORT_SYMBOL(generic_file_remap_pages);
88714
88715-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88716- unsigned long addr, void *buf, int len, int write)
88717+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88718+ unsigned long addr, void *buf, size_t len, int write)
88719 {
88720 struct vm_area_struct *vma;
88721
88722@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88723 *
88724 * The caller must hold a reference on @mm.
88725 */
88726-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88727- void *buf, int len, int write)
88728+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88729+ void *buf, size_t len, int write)
88730 {
88731 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88732 }
88733@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88734 * Access another process' address space.
88735 * - source/target buffer must be kernel space
88736 */
88737-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88738+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88739 {
88740 struct mm_struct *mm;
88741
88742diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88743index 3f0c895..60cd104 100644
88744--- a/mm/page-writeback.c
88745+++ b/mm/page-writeback.c
88746@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88747 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88748 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88749 */
88750-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88751+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88752 unsigned long thresh,
88753 unsigned long bg_thresh,
88754 unsigned long dirty,
88755diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88756index b100255..fba1254 100644
88757--- a/mm/page_alloc.c
88758+++ b/mm/page_alloc.c
88759@@ -60,6 +60,7 @@
88760 #include <linux/page-debug-flags.h>
88761 #include <linux/hugetlb.h>
88762 #include <linux/sched/rt.h>
88763+#include <linux/random.h>
88764
88765 #include <asm/sections.h>
88766 #include <asm/tlbflush.h>
88767@@ -353,7 +354,7 @@ out:
88768 * This usage means that zero-order pages may not be compound.
88769 */
88770
88771-static void free_compound_page(struct page *page)
88772+void free_compound_page(struct page *page)
88773 {
88774 __free_pages_ok(page, compound_order(page));
88775 }
88776@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88777 int i;
88778 int bad = 0;
88779
88780+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88781+ unsigned long index = 1UL << order;
88782+#endif
88783+
88784 trace_mm_page_free(page, order);
88785 kmemcheck_free_shadow(page, order);
88786
88787@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88788 debug_check_no_obj_freed(page_address(page),
88789 PAGE_SIZE << order);
88790 }
88791+
88792+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88793+ for (; index; --index)
88794+ sanitize_highpage(page + index - 1);
88795+#endif
88796+
88797 arch_free_page(page, order);
88798 kernel_map_pages(page, 1 << order, 0);
88799
88800@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88801 local_irq_restore(flags);
88802 }
88803
88804+#ifdef CONFIG_PAX_LATENT_ENTROPY
88805+bool __meminitdata extra_latent_entropy;
88806+
88807+static int __init setup_pax_extra_latent_entropy(char *str)
88808+{
88809+ extra_latent_entropy = true;
88810+ return 0;
88811+}
88812+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88813+
88814+volatile u64 latent_entropy;
88815+EXPORT_SYMBOL(latent_entropy);
88816+#endif
88817+
88818 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88819 {
88820 unsigned int nr_pages = 1 << order;
88821@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88822 set_page_count(p, 0);
88823 }
88824
88825+#ifdef CONFIG_PAX_LATENT_ENTROPY
88826+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88827+ u64 hash = 0;
88828+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88829+ const u64 *data = lowmem_page_address(page);
88830+
88831+ for (index = 0; index < end; index++)
88832+ hash ^= hash + data[index];
88833+ latent_entropy ^= hash;
88834+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88835+ }
88836+#endif
88837+
88838 page_zone(page)->managed_pages += 1 << order;
88839 set_page_refcounted(page);
88840 __free_pages(page, order);
88841@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88842 arch_alloc_page(page, order);
88843 kernel_map_pages(page, 1 << order, 1);
88844
88845+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88846 if (gfp_flags & __GFP_ZERO)
88847 prep_zero_page(page, order, gfp_flags);
88848+#endif
88849
88850 if (order && (gfp_flags & __GFP_COMP))
88851 prep_compound_page(page, order);
88852diff --git a/mm/page_io.c b/mm/page_io.c
88853index ba05b64..ef2f314 100644
88854--- a/mm/page_io.c
88855+++ b/mm/page_io.c
88856@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
88857 struct file *swap_file = sis->swap_file;
88858 struct address_space *mapping = swap_file->f_mapping;
88859 struct iovec iov = {
88860- .iov_base = kmap(page),
88861+ .iov_base = (void __force_user *)kmap(page),
88862 .iov_len = PAGE_SIZE,
88863 };
88864
88865diff --git a/mm/percpu.c b/mm/percpu.c
88866index 8c8e08f..73a5cda 100644
88867--- a/mm/percpu.c
88868+++ b/mm/percpu.c
88869@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
88870 static unsigned int pcpu_high_unit_cpu __read_mostly;
88871
88872 /* the address of the first chunk which starts with the kernel static area */
88873-void *pcpu_base_addr __read_mostly;
88874+void *pcpu_base_addr __read_only;
88875 EXPORT_SYMBOL_GPL(pcpu_base_addr);
88876
88877 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
88878diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
88879index fd26d04..0cea1b0 100644
88880--- a/mm/process_vm_access.c
88881+++ b/mm/process_vm_access.c
88882@@ -13,6 +13,7 @@
88883 #include <linux/uio.h>
88884 #include <linux/sched.h>
88885 #include <linux/highmem.h>
88886+#include <linux/security.h>
88887 #include <linux/ptrace.h>
88888 #include <linux/slab.h>
88889 #include <linux/syscalls.h>
88890@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88891 size_t iov_l_curr_offset = 0;
88892 ssize_t iov_len;
88893
88894+ return -ENOSYS; // PaX: until properly audited
88895+
88896 /*
88897 * Work out how many pages of struct pages we're going to need
88898 * when eventually calling get_user_pages
88899 */
88900 for (i = 0; i < riovcnt; i++) {
88901 iov_len = rvec[i].iov_len;
88902- if (iov_len > 0) {
88903- nr_pages_iov = ((unsigned long)rvec[i].iov_base
88904- + iov_len)
88905- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
88906- / PAGE_SIZE + 1;
88907- nr_pages = max(nr_pages, nr_pages_iov);
88908- }
88909+ if (iov_len <= 0)
88910+ continue;
88911+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
88912+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
88913+ nr_pages = max(nr_pages, nr_pages_iov);
88914 }
88915
88916 if (nr_pages == 0)
88917@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88918 goto free_proc_pages;
88919 }
88920
88921+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
88922+ rc = -EPERM;
88923+ goto put_task_struct;
88924+ }
88925+
88926 mm = mm_access(task, PTRACE_MODE_ATTACH);
88927 if (!mm || IS_ERR(mm)) {
88928 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
88929diff --git a/mm/rmap.c b/mm/rmap.c
88930index b2e29ac..4168491 100644
88931--- a/mm/rmap.c
88932+++ b/mm/rmap.c
88933@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88934 struct anon_vma *anon_vma = vma->anon_vma;
88935 struct anon_vma_chain *avc;
88936
88937+#ifdef CONFIG_PAX_SEGMEXEC
88938+ struct anon_vma_chain *avc_m = NULL;
88939+#endif
88940+
88941 might_sleep();
88942 if (unlikely(!anon_vma)) {
88943 struct mm_struct *mm = vma->vm_mm;
88944@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88945 if (!avc)
88946 goto out_enomem;
88947
88948+#ifdef CONFIG_PAX_SEGMEXEC
88949+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
88950+ if (!avc_m)
88951+ goto out_enomem_free_avc;
88952+#endif
88953+
88954 anon_vma = find_mergeable_anon_vma(vma);
88955 allocated = NULL;
88956 if (!anon_vma) {
88957@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88958 /* page_table_lock to protect against threads */
88959 spin_lock(&mm->page_table_lock);
88960 if (likely(!vma->anon_vma)) {
88961+
88962+#ifdef CONFIG_PAX_SEGMEXEC
88963+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
88964+
88965+ if (vma_m) {
88966+ BUG_ON(vma_m->anon_vma);
88967+ vma_m->anon_vma = anon_vma;
88968+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
88969+ avc_m = NULL;
88970+ }
88971+#endif
88972+
88973 vma->anon_vma = anon_vma;
88974 anon_vma_chain_link(vma, avc, anon_vma);
88975 allocated = NULL;
88976@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88977
88978 if (unlikely(allocated))
88979 put_anon_vma(allocated);
88980+
88981+#ifdef CONFIG_PAX_SEGMEXEC
88982+ if (unlikely(avc_m))
88983+ anon_vma_chain_free(avc_m);
88984+#endif
88985+
88986 if (unlikely(avc))
88987 anon_vma_chain_free(avc);
88988 }
88989 return 0;
88990
88991 out_enomem_free_avc:
88992+
88993+#ifdef CONFIG_PAX_SEGMEXEC
88994+ if (avc_m)
88995+ anon_vma_chain_free(avc_m);
88996+#endif
88997+
88998 anon_vma_chain_free(avc);
88999 out_enomem:
89000 return -ENOMEM;
89001@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89002 * Attach the anon_vmas from src to dst.
89003 * Returns 0 on success, -ENOMEM on failure.
89004 */
89005-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89006+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89007 {
89008 struct anon_vma_chain *avc, *pavc;
89009 struct anon_vma *root = NULL;
89010@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89011 * the corresponding VMA in the parent process is attached to.
89012 * Returns 0 on success, non-zero on failure.
89013 */
89014-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89015+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89016 {
89017 struct anon_vma_chain *avc;
89018 struct anon_vma *anon_vma;
89019@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89020 void __init anon_vma_init(void)
89021 {
89022 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89023- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89024- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89025+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89026+ anon_vma_ctor);
89027+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89028+ SLAB_PANIC|SLAB_NO_SANITIZE);
89029 }
89030
89031 /*
89032diff --git a/mm/shmem.c b/mm/shmem.c
89033index e43dc55..930e3a2 100644
89034--- a/mm/shmem.c
89035+++ b/mm/shmem.c
89036@@ -33,7 +33,7 @@
89037 #include <linux/swap.h>
89038 #include <linux/aio.h>
89039
89040-static struct vfsmount *shm_mnt;
89041+struct vfsmount *shm_mnt;
89042
89043 #ifdef CONFIG_SHMEM
89044 /*
89045@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89046 #define BOGO_DIRENT_SIZE 20
89047
89048 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89049-#define SHORT_SYMLINK_LEN 128
89050+#define SHORT_SYMLINK_LEN 64
89051
89052 /*
89053 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89054@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89055 static int shmem_xattr_validate(const char *name)
89056 {
89057 struct { const char *prefix; size_t len; } arr[] = {
89058+
89059+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89060+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89061+#endif
89062+
89063 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89064 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89065 };
89066@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89067 if (err)
89068 return err;
89069
89070+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89071+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89072+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89073+ return -EOPNOTSUPP;
89074+ if (size > 8)
89075+ return -EINVAL;
89076+ }
89077+#endif
89078+
89079 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89080 }
89081
89082@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89083 int err = -ENOMEM;
89084
89085 /* Round up to L1_CACHE_BYTES to resist false sharing */
89086- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89087- L1_CACHE_BYTES), GFP_KERNEL);
89088+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89089 if (!sbinfo)
89090 return -ENOMEM;
89091
89092diff --git a/mm/slab.c b/mm/slab.c
89093index 2580db0..0523956 100644
89094--- a/mm/slab.c
89095+++ b/mm/slab.c
89096@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89097 if ((x)->max_freeable < i) \
89098 (x)->max_freeable = i; \
89099 } while (0)
89100-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89101-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89102-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89103-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89104+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89105+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89106+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89107+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89108+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89109+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89110 #else
89111 #define STATS_INC_ACTIVE(x) do { } while (0)
89112 #define STATS_DEC_ACTIVE(x) do { } while (0)
89113@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89114 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89115 #define STATS_INC_FREEHIT(x) do { } while (0)
89116 #define STATS_INC_FREEMISS(x) do { } while (0)
89117+#define STATS_INC_SANITIZED(x) do { } while (0)
89118+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89119 #endif
89120
89121 #if DEBUG
89122@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89123 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89124 */
89125 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89126- const struct slab *slab, void *obj)
89127+ const struct slab *slab, const void *obj)
89128 {
89129 u32 offset = (obj - slab->s_mem);
89130 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89131@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89132 */
89133
89134 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89135- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89136+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89137
89138 if (INDEX_AC != INDEX_NODE)
89139 kmalloc_caches[INDEX_NODE] =
89140 create_kmalloc_cache("kmalloc-node",
89141- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89142+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89143
89144 slab_early_init = 0;
89145
89146@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89147 struct array_cache *ac = cpu_cache_get(cachep);
89148
89149 check_irq_off();
89150+
89151+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89152+ if (pax_sanitize_slab) {
89153+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89154+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89155+
89156+ if (cachep->ctor)
89157+ cachep->ctor(objp);
89158+
89159+ STATS_INC_SANITIZED(cachep);
89160+ } else
89161+ STATS_INC_NOT_SANITIZED(cachep);
89162+ }
89163+#endif
89164+
89165 kmemleak_free_recursive(objp, cachep->flags);
89166 objp = cache_free_debugcheck(cachep, objp, caller);
89167
89168@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89169
89170 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89171 return;
89172+ VM_BUG_ON(!virt_addr_valid(objp));
89173 local_irq_save(flags);
89174 kfree_debugcheck(objp);
89175 c = virt_to_cache(objp);
89176@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89177 }
89178 /* cpu stats */
89179 {
89180- unsigned long allochit = atomic_read(&cachep->allochit);
89181- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89182- unsigned long freehit = atomic_read(&cachep->freehit);
89183- unsigned long freemiss = atomic_read(&cachep->freemiss);
89184+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89185+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89186+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89187+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89188
89189 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89190 allochit, allocmiss, freehit, freemiss);
89191 }
89192+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89193+ {
89194+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89195+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89196+
89197+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89198+ }
89199+#endif
89200 #endif
89201 }
89202
89203@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89204 static int __init slab_proc_init(void)
89205 {
89206 #ifdef CONFIG_DEBUG_SLAB_LEAK
89207- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89208+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89209 #endif
89210 return 0;
89211 }
89212 module_init(slab_proc_init);
89213 #endif
89214
89215+bool is_usercopy_object(const void *ptr)
89216+{
89217+ struct page *page;
89218+ struct kmem_cache *cachep;
89219+
89220+ if (ZERO_OR_NULL_PTR(ptr))
89221+ return false;
89222+
89223+ if (!slab_is_available())
89224+ return false;
89225+
89226+ if (!virt_addr_valid(ptr))
89227+ return false;
89228+
89229+ page = virt_to_head_page(ptr);
89230+
89231+ if (!PageSlab(page))
89232+ return false;
89233+
89234+ cachep = page->slab_cache;
89235+ return cachep->flags & SLAB_USERCOPY;
89236+}
89237+
89238+#ifdef CONFIG_PAX_USERCOPY
89239+const char *check_heap_object(const void *ptr, unsigned long n)
89240+{
89241+ struct page *page;
89242+ struct kmem_cache *cachep;
89243+ struct slab *slabp;
89244+ unsigned int objnr;
89245+ unsigned long offset;
89246+
89247+ if (ZERO_OR_NULL_PTR(ptr))
89248+ return "<null>";
89249+
89250+ if (!virt_addr_valid(ptr))
89251+ return NULL;
89252+
89253+ page = virt_to_head_page(ptr);
89254+
89255+ if (!PageSlab(page))
89256+ return NULL;
89257+
89258+ cachep = page->slab_cache;
89259+ if (!(cachep->flags & SLAB_USERCOPY))
89260+ return cachep->name;
89261+
89262+ slabp = page->slab_page;
89263+ objnr = obj_to_index(cachep, slabp, ptr);
89264+ BUG_ON(objnr >= cachep->num);
89265+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89266+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89267+ return NULL;
89268+
89269+ return cachep->name;
89270+}
89271+#endif
89272+
89273 /**
89274 * ksize - get the actual amount of memory allocated for a given object
89275 * @objp: Pointer to the object
89276diff --git a/mm/slab.h b/mm/slab.h
89277index a535033..2f98fe5 100644
89278--- a/mm/slab.h
89279+++ b/mm/slab.h
89280@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89281 /* The slab cache that manages slab cache information */
89282 extern struct kmem_cache *kmem_cache;
89283
89284+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89285+#ifdef CONFIG_X86_64
89286+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89287+#else
89288+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89289+#endif
89290+extern bool pax_sanitize_slab;
89291+#endif
89292+
89293 unsigned long calculate_alignment(unsigned long flags,
89294 unsigned long align, unsigned long size);
89295
89296@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89297
89298 /* Legal flag mask for kmem_cache_create(), for various configurations */
89299 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89300- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89301+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89302+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89303
89304 #if defined(CONFIG_DEBUG_SLAB)
89305 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89306@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89307 return s;
89308
89309 page = virt_to_head_page(x);
89310+
89311+ BUG_ON(!PageSlab(page));
89312+
89313 cachep = page->slab_cache;
89314 if (slab_equal_or_root(cachep, s))
89315 return cachep;
89316diff --git a/mm/slab_common.c b/mm/slab_common.c
89317index 538bade..36fed99 100644
89318--- a/mm/slab_common.c
89319+++ b/mm/slab_common.c
89320@@ -22,11 +22,22 @@
89321
89322 #include "slab.h"
89323
89324-enum slab_state slab_state;
89325+enum slab_state slab_state __read_only;
89326 LIST_HEAD(slab_caches);
89327 DEFINE_MUTEX(slab_mutex);
89328 struct kmem_cache *kmem_cache;
89329
89330+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89331+bool pax_sanitize_slab __read_only = true;
89332+static int __init pax_sanitize_slab_setup(char *str)
89333+{
89334+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89335+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89336+ return 1;
89337+}
89338+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89339+#endif
89340+
89341 #ifdef CONFIG_DEBUG_VM
89342 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89343 size_t size)
89344@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89345
89346 err = __kmem_cache_create(s, flags);
89347 if (!err) {
89348- s->refcount = 1;
89349+ atomic_set(&s->refcount, 1);
89350 list_add(&s->list, &slab_caches);
89351 memcg_cache_list_add(memcg, s);
89352 } else {
89353@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89354
89355 get_online_cpus();
89356 mutex_lock(&slab_mutex);
89357- s->refcount--;
89358- if (!s->refcount) {
89359+ if (atomic_dec_and_test(&s->refcount)) {
89360 list_del(&s->list);
89361
89362 if (!__kmem_cache_shutdown(s)) {
89363@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89364 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89365 name, size, err);
89366
89367- s->refcount = -1; /* Exempt from merging for now */
89368+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89369 }
89370
89371 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89372@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89373
89374 create_boot_cache(s, name, size, flags);
89375 list_add(&s->list, &slab_caches);
89376- s->refcount = 1;
89377+ atomic_set(&s->refcount, 1);
89378 return s;
89379 }
89380
89381@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89382 EXPORT_SYMBOL(kmalloc_dma_caches);
89383 #endif
89384
89385+#ifdef CONFIG_PAX_USERCOPY_SLABS
89386+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89387+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89388+#endif
89389+
89390 /*
89391 * Conversion table for small slabs sizes / 8 to the index in the
89392 * kmalloc array. This is necessary for slabs < 192 since we have non power
89393@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89394 return kmalloc_dma_caches[index];
89395
89396 #endif
89397+
89398+#ifdef CONFIG_PAX_USERCOPY_SLABS
89399+ if (unlikely((flags & GFP_USERCOPY)))
89400+ return kmalloc_usercopy_caches[index];
89401+
89402+#endif
89403+
89404 return kmalloc_caches[index];
89405 }
89406
89407@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89408 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89409 if (!kmalloc_caches[i]) {
89410 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89411- 1 << i, flags);
89412+ 1 << i, SLAB_USERCOPY | flags);
89413 }
89414
89415 /*
89416@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89417 * earlier power of two caches
89418 */
89419 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89420- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89421+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89422
89423 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89424- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89425+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89426 }
89427
89428 /* Kmalloc array is now usable */
89429@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89430 }
89431 }
89432 #endif
89433+
89434+#ifdef CONFIG_PAX_USERCOPY_SLABS
89435+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89436+ struct kmem_cache *s = kmalloc_caches[i];
89437+
89438+ if (s) {
89439+ int size = kmalloc_size(i);
89440+ char *n = kasprintf(GFP_NOWAIT,
89441+ "usercopy-kmalloc-%d", size);
89442+
89443+ BUG_ON(!n);
89444+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89445+ size, SLAB_USERCOPY | flags);
89446+ }
89447+ }
89448+#endif
89449+
89450 }
89451 #endif /* !CONFIG_SLOB */
89452
89453@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89454 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89455 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89456 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89457+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89458+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89459+#endif
89460 #endif
89461 seq_putc(m, '\n');
89462 }
89463diff --git a/mm/slob.c b/mm/slob.c
89464index 91bd3f2..e2f549e 100644
89465--- a/mm/slob.c
89466+++ b/mm/slob.c
89467@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89468 /*
89469 * Return the size of a slob block.
89470 */
89471-static slobidx_t slob_units(slob_t *s)
89472+static slobidx_t slob_units(const slob_t *s)
89473 {
89474 if (s->units > 0)
89475 return s->units;
89476@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89477 /*
89478 * Return the next free slob block pointer after this one.
89479 */
89480-static slob_t *slob_next(slob_t *s)
89481+static slob_t *slob_next(const slob_t *s)
89482 {
89483 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89484 slobidx_t next;
89485@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89486 /*
89487 * Returns true if s is the last free block in its page.
89488 */
89489-static int slob_last(slob_t *s)
89490+static int slob_last(const slob_t *s)
89491 {
89492 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89493 }
89494
89495-static void *slob_new_pages(gfp_t gfp, int order, int node)
89496+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89497 {
89498- void *page;
89499+ struct page *page;
89500
89501 #ifdef CONFIG_NUMA
89502 if (node != NUMA_NO_NODE)
89503@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89504 if (!page)
89505 return NULL;
89506
89507- return page_address(page);
89508+ __SetPageSlab(page);
89509+ return page;
89510 }
89511
89512-static void slob_free_pages(void *b, int order)
89513+static void slob_free_pages(struct page *sp, int order)
89514 {
89515 if (current->reclaim_state)
89516 current->reclaim_state->reclaimed_slab += 1 << order;
89517- free_pages((unsigned long)b, order);
89518+ __ClearPageSlab(sp);
89519+ page_mapcount_reset(sp);
89520+ sp->private = 0;
89521+ __free_pages(sp, order);
89522 }
89523
89524 /*
89525@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89526
89527 /* Not enough space: must allocate a new page */
89528 if (!b) {
89529- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89530- if (!b)
89531+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89532+ if (!sp)
89533 return NULL;
89534- sp = virt_to_page(b);
89535- __SetPageSlab(sp);
89536+ b = page_address(sp);
89537
89538 spin_lock_irqsave(&slob_lock, flags);
89539 sp->units = SLOB_UNITS(PAGE_SIZE);
89540 sp->freelist = b;
89541+ sp->private = 0;
89542 INIT_LIST_HEAD(&sp->list);
89543 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89544 set_slob_page_free(sp, slob_list);
89545@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89546 if (slob_page_free(sp))
89547 clear_slob_page_free(sp);
89548 spin_unlock_irqrestore(&slob_lock, flags);
89549- __ClearPageSlab(sp);
89550- page_mapcount_reset(sp);
89551- slob_free_pages(b, 0);
89552+ slob_free_pages(sp, 0);
89553 return;
89554 }
89555
89556+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89557+ if (pax_sanitize_slab)
89558+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89559+#endif
89560+
89561 if (!slob_page_free(sp)) {
89562 /* This slob page is about to become partially free. Easy! */
89563 sp->units = units;
89564@@ -424,11 +431,10 @@ out:
89565 */
89566
89567 static __always_inline void *
89568-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89569+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89570 {
89571- unsigned int *m;
89572- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89573- void *ret;
89574+ slob_t *m;
89575+ void *ret = NULL;
89576
89577 gfp &= gfp_allowed_mask;
89578
89579@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89580
89581 if (!m)
89582 return NULL;
89583- *m = size;
89584+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89585+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89586+ m[0].units = size;
89587+ m[1].units = align;
89588 ret = (void *)m + align;
89589
89590 trace_kmalloc_node(caller, ret,
89591 size, size + align, gfp, node);
89592 } else {
89593 unsigned int order = get_order(size);
89594+ struct page *page;
89595
89596 if (likely(order))
89597 gfp |= __GFP_COMP;
89598- ret = slob_new_pages(gfp, order, node);
89599+ page = slob_new_pages(gfp, order, node);
89600+ if (page) {
89601+ ret = page_address(page);
89602+ page->private = size;
89603+ }
89604
89605 trace_kmalloc_node(caller, ret,
89606 size, PAGE_SIZE << order, gfp, node);
89607 }
89608
89609- kmemleak_alloc(ret, size, 1, gfp);
89610+ return ret;
89611+}
89612+
89613+static __always_inline void *
89614+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89615+{
89616+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89617+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89618+
89619+ if (!ZERO_OR_NULL_PTR(ret))
89620+ kmemleak_alloc(ret, size, 1, gfp);
89621 return ret;
89622 }
89623
89624@@ -493,34 +517,112 @@ void kfree(const void *block)
89625 return;
89626 kmemleak_free(block);
89627
89628+ VM_BUG_ON(!virt_addr_valid(block));
89629 sp = virt_to_page(block);
89630- if (PageSlab(sp)) {
89631+ VM_BUG_ON(!PageSlab(sp));
89632+ if (!sp->private) {
89633 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89634- unsigned int *m = (unsigned int *)(block - align);
89635- slob_free(m, *m + align);
89636- } else
89637+ slob_t *m = (slob_t *)(block - align);
89638+ slob_free(m, m[0].units + align);
89639+ } else {
89640+ __ClearPageSlab(sp);
89641+ page_mapcount_reset(sp);
89642+ sp->private = 0;
89643 __free_pages(sp, compound_order(sp));
89644+ }
89645 }
89646 EXPORT_SYMBOL(kfree);
89647
89648+bool is_usercopy_object(const void *ptr)
89649+{
89650+ if (!slab_is_available())
89651+ return false;
89652+
89653+ // PAX: TODO
89654+
89655+ return false;
89656+}
89657+
89658+#ifdef CONFIG_PAX_USERCOPY
89659+const char *check_heap_object(const void *ptr, unsigned long n)
89660+{
89661+ struct page *page;
89662+ const slob_t *free;
89663+ const void *base;
89664+ unsigned long flags;
89665+
89666+ if (ZERO_OR_NULL_PTR(ptr))
89667+ return "<null>";
89668+
89669+ if (!virt_addr_valid(ptr))
89670+ return NULL;
89671+
89672+ page = virt_to_head_page(ptr);
89673+ if (!PageSlab(page))
89674+ return NULL;
89675+
89676+ if (page->private) {
89677+ base = page;
89678+ if (base <= ptr && n <= page->private - (ptr - base))
89679+ return NULL;
89680+ return "<slob>";
89681+ }
89682+
89683+ /* some tricky double walking to find the chunk */
89684+ spin_lock_irqsave(&slob_lock, flags);
89685+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89686+ free = page->freelist;
89687+
89688+ while (!slob_last(free) && (void *)free <= ptr) {
89689+ base = free + slob_units(free);
89690+ free = slob_next(free);
89691+ }
89692+
89693+ while (base < (void *)free) {
89694+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89695+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89696+ int offset;
89697+
89698+ if (ptr < base + align)
89699+ break;
89700+
89701+ offset = ptr - base - align;
89702+ if (offset >= m) {
89703+ base += size;
89704+ continue;
89705+ }
89706+
89707+ if (n > m - offset)
89708+ break;
89709+
89710+ spin_unlock_irqrestore(&slob_lock, flags);
89711+ return NULL;
89712+ }
89713+
89714+ spin_unlock_irqrestore(&slob_lock, flags);
89715+ return "<slob>";
89716+}
89717+#endif
89718+
89719 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89720 size_t ksize(const void *block)
89721 {
89722 struct page *sp;
89723 int align;
89724- unsigned int *m;
89725+ slob_t *m;
89726
89727 BUG_ON(!block);
89728 if (unlikely(block == ZERO_SIZE_PTR))
89729 return 0;
89730
89731 sp = virt_to_page(block);
89732- if (unlikely(!PageSlab(sp)))
89733- return PAGE_SIZE << compound_order(sp);
89734+ VM_BUG_ON(!PageSlab(sp));
89735+ if (sp->private)
89736+ return sp->private;
89737
89738 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89739- m = (unsigned int *)(block - align);
89740- return SLOB_UNITS(*m) * SLOB_UNIT;
89741+ m = (slob_t *)(block - align);
89742+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89743 }
89744 EXPORT_SYMBOL(ksize);
89745
89746@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89747
89748 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89749 {
89750- void *b;
89751+ void *b = NULL;
89752
89753 flags &= gfp_allowed_mask;
89754
89755 lockdep_trace_alloc(flags);
89756
89757+#ifdef CONFIG_PAX_USERCOPY_SLABS
89758+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89759+#else
89760 if (c->size < PAGE_SIZE) {
89761 b = slob_alloc(c->size, flags, c->align, node);
89762 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89763 SLOB_UNITS(c->size) * SLOB_UNIT,
89764 flags, node);
89765 } else {
89766- b = slob_new_pages(flags, get_order(c->size), node);
89767+ struct page *sp;
89768+
89769+ sp = slob_new_pages(flags, get_order(c->size), node);
89770+ if (sp) {
89771+ b = page_address(sp);
89772+ sp->private = c->size;
89773+ }
89774 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89775 PAGE_SIZE << get_order(c->size),
89776 flags, node);
89777 }
89778+#endif
89779
89780 if (b && c->ctor)
89781 c->ctor(b);
89782@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89783
89784 static void __kmem_cache_free(void *b, int size)
89785 {
89786- if (size < PAGE_SIZE)
89787+ struct page *sp;
89788+
89789+ sp = virt_to_page(b);
89790+ BUG_ON(!PageSlab(sp));
89791+ if (!sp->private)
89792 slob_free(b, size);
89793 else
89794- slob_free_pages(b, get_order(size));
89795+ slob_free_pages(sp, get_order(size));
89796 }
89797
89798 static void kmem_rcu_free(struct rcu_head *head)
89799@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89800
89801 void kmem_cache_free(struct kmem_cache *c, void *b)
89802 {
89803+ int size = c->size;
89804+
89805+#ifdef CONFIG_PAX_USERCOPY_SLABS
89806+ if (size + c->align < PAGE_SIZE) {
89807+ size += c->align;
89808+ b -= c->align;
89809+ }
89810+#endif
89811+
89812 kmemleak_free_recursive(b, c->flags);
89813 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89814 struct slob_rcu *slob_rcu;
89815- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89816- slob_rcu->size = c->size;
89817+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89818+ slob_rcu->size = size;
89819 call_rcu(&slob_rcu->head, kmem_rcu_free);
89820 } else {
89821- __kmem_cache_free(b, c->size);
89822+ __kmem_cache_free(b, size);
89823 }
89824
89825+#ifdef CONFIG_PAX_USERCOPY_SLABS
89826+ trace_kfree(_RET_IP_, b);
89827+#else
89828 trace_kmem_cache_free(_RET_IP_, b);
89829+#endif
89830+
89831 }
89832 EXPORT_SYMBOL(kmem_cache_free);
89833
89834diff --git a/mm/slub.c b/mm/slub.c
89835index e3ba1f2..bd45dac 100644
89836--- a/mm/slub.c
89837+++ b/mm/slub.c
89838@@ -207,7 +207,7 @@ struct track {
89839
89840 enum track_item { TRACK_ALLOC, TRACK_FREE };
89841
89842-#ifdef CONFIG_SYSFS
89843+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89844 static int sysfs_slab_add(struct kmem_cache *);
89845 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89846 static void sysfs_slab_remove(struct kmem_cache *);
89847@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89848 if (!t->addr)
89849 return;
89850
89851- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89852+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89853 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
89854 #ifdef CONFIG_STACKTRACE
89855 {
89856@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
89857
89858 slab_free_hook(s, x);
89859
89860+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89861+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
89862+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
89863+ if (s->ctor)
89864+ s->ctor(x);
89865+ }
89866+#endif
89867+
89868 redo:
89869 /*
89870 * Determine the currently cpus per cpu slab.
89871@@ -2676,7 +2684,7 @@ static int slub_min_objects;
89872 * Merge control. If this is set then no merging of slab caches will occur.
89873 * (Could be removed. This was introduced to pacify the merge skeptics.)
89874 */
89875-static int slub_nomerge;
89876+static int slub_nomerge = 1;
89877
89878 /*
89879 * Calculate the order of allocation given an slab object size.
89880@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
89881 s->inuse = size;
89882
89883 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
89884+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89885+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
89886+#endif
89887 s->ctor)) {
89888 /*
89889 * Relocate free pointer after the object if it is not
89890@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
89891 EXPORT_SYMBOL(__kmalloc_node);
89892 #endif
89893
89894+bool is_usercopy_object(const void *ptr)
89895+{
89896+ struct page *page;
89897+ struct kmem_cache *s;
89898+
89899+ if (ZERO_OR_NULL_PTR(ptr))
89900+ return false;
89901+
89902+ if (!slab_is_available())
89903+ return false;
89904+
89905+ if (!virt_addr_valid(ptr))
89906+ return false;
89907+
89908+ page = virt_to_head_page(ptr);
89909+
89910+ if (!PageSlab(page))
89911+ return false;
89912+
89913+ s = page->slab_cache;
89914+ return s->flags & SLAB_USERCOPY;
89915+}
89916+
89917+#ifdef CONFIG_PAX_USERCOPY
89918+const char *check_heap_object(const void *ptr, unsigned long n)
89919+{
89920+ struct page *page;
89921+ struct kmem_cache *s;
89922+ unsigned long offset;
89923+
89924+ if (ZERO_OR_NULL_PTR(ptr))
89925+ return "<null>";
89926+
89927+ if (!virt_addr_valid(ptr))
89928+ return NULL;
89929+
89930+ page = virt_to_head_page(ptr);
89931+
89932+ if (!PageSlab(page))
89933+ return NULL;
89934+
89935+ s = page->slab_cache;
89936+ if (!(s->flags & SLAB_USERCOPY))
89937+ return s->name;
89938+
89939+ offset = (ptr - page_address(page)) % s->size;
89940+ if (offset <= s->object_size && n <= s->object_size - offset)
89941+ return NULL;
89942+
89943+ return s->name;
89944+}
89945+#endif
89946+
89947 size_t ksize(const void *object)
89948 {
89949 struct page *page;
89950@@ -3362,6 +3426,7 @@ void kfree(const void *x)
89951 if (unlikely(ZERO_OR_NULL_PTR(x)))
89952 return;
89953
89954+ VM_BUG_ON(!virt_addr_valid(x));
89955 page = virt_to_head_page(x);
89956 if (unlikely(!PageSlab(page))) {
89957 BUG_ON(!PageCompound(page));
89958@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
89959 /*
89960 * We may have set a slab to be unmergeable during bootstrap.
89961 */
89962- if (s->refcount < 0)
89963+ if (atomic_read(&s->refcount) < 0)
89964 return 1;
89965
89966 return 0;
89967@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89968
89969 s = find_mergeable(memcg, size, align, flags, name, ctor);
89970 if (s) {
89971- s->refcount++;
89972+ atomic_inc(&s->refcount);
89973 /*
89974 * Adjust the object sizes so that we clear
89975 * the complete object on kzalloc.
89976@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89977 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
89978
89979 if (sysfs_slab_alias(s, name)) {
89980- s->refcount--;
89981+ atomic_dec(&s->refcount);
89982 s = NULL;
89983 }
89984 }
89985@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
89986 }
89987 #endif
89988
89989-#ifdef CONFIG_SYSFS
89990+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89991 static int count_inuse(struct page *page)
89992 {
89993 return page->inuse;
89994@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
89995 validate_slab_cache(kmalloc_caches[9]);
89996 }
89997 #else
89998-#ifdef CONFIG_SYSFS
89999+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90000 static void resiliency_test(void) {};
90001 #endif
90002 #endif
90003
90004-#ifdef CONFIG_SYSFS
90005+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90006 enum slab_stat_type {
90007 SL_ALL, /* All slabs */
90008 SL_PARTIAL, /* Only partially allocated slabs */
90009@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90010
90011 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90012 {
90013- return sprintf(buf, "%d\n", s->refcount - 1);
90014+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90015 }
90016 SLAB_ATTR_RO(aliases);
90017
90018@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90019 SLAB_ATTR_RO(cache_dma);
90020 #endif
90021
90022+#ifdef CONFIG_PAX_USERCOPY_SLABS
90023+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90024+{
90025+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90026+}
90027+SLAB_ATTR_RO(usercopy);
90028+#endif
90029+
90030 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90031 {
90032 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90033@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90034 #ifdef CONFIG_ZONE_DMA
90035 &cache_dma_attr.attr,
90036 #endif
90037+#ifdef CONFIG_PAX_USERCOPY_SLABS
90038+ &usercopy_attr.attr,
90039+#endif
90040 #ifdef CONFIG_NUMA
90041 &remote_node_defrag_ratio_attr.attr,
90042 #endif
90043@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90044 return name;
90045 }
90046
90047+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90048 static int sysfs_slab_add(struct kmem_cache *s)
90049 {
90050 int err;
90051@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90052 }
90053
90054 s->kobj.kset = slab_kset;
90055- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90056+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90057 if (err) {
90058 kobject_put(&s->kobj);
90059 return err;
90060@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90061 kobject_del(&s->kobj);
90062 kobject_put(&s->kobj);
90063 }
90064+#endif
90065
90066 /*
90067 * Need to buffer aliases during bootup until sysfs becomes
90068@@ -5213,6 +5291,7 @@ struct saved_alias {
90069
90070 static struct saved_alias *alias_list;
90071
90072+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90073 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90074 {
90075 struct saved_alias *al;
90076@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90077 alias_list = al;
90078 return 0;
90079 }
90080+#endif
90081
90082 static int __init slab_sysfs_init(void)
90083 {
90084diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90085index 27eeab3..7c3f7f2 100644
90086--- a/mm/sparse-vmemmap.c
90087+++ b/mm/sparse-vmemmap.c
90088@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90089 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90090 if (!p)
90091 return NULL;
90092- pud_populate(&init_mm, pud, p);
90093+ pud_populate_kernel(&init_mm, pud, p);
90094 }
90095 return pud;
90096 }
90097@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90098 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90099 if (!p)
90100 return NULL;
90101- pgd_populate(&init_mm, pgd, p);
90102+ pgd_populate_kernel(&init_mm, pgd, p);
90103 }
90104 return pgd;
90105 }
90106diff --git a/mm/sparse.c b/mm/sparse.c
90107index 308d503..3dbbd04 100644
90108--- a/mm/sparse.c
90109+++ b/mm/sparse.c
90110@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90111
90112 for (i = 0; i < PAGES_PER_SECTION; i++) {
90113 if (PageHWPoison(&memmap[i])) {
90114- atomic_long_sub(1, &num_poisoned_pages);
90115+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90116 ClearPageHWPoison(&memmap[i]);
90117 }
90118 }
90119diff --git a/mm/swap.c b/mm/swap.c
90120index c899502..d4dc2cd 100644
90121--- a/mm/swap.c
90122+++ b/mm/swap.c
90123@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90124
90125 __page_cache_release(page);
90126 dtor = get_compound_page_dtor(page);
90127+ if (!PageHuge(page))
90128+ BUG_ON(dtor != free_compound_page);
90129 (*dtor)(page);
90130 }
90131
90132diff --git a/mm/swapfile.c b/mm/swapfile.c
90133index 6cf2e60..d204b3e 100644
90134--- a/mm/swapfile.c
90135+++ b/mm/swapfile.c
90136@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90137
90138 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90139 /* Activity counter to indicate that a swapon or swapoff has occurred */
90140-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90141+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90142
90143 static inline unsigned char swap_count(unsigned char ent)
90144 {
90145@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90146 }
90147 filp_close(swap_file, NULL);
90148 err = 0;
90149- atomic_inc(&proc_poll_event);
90150+ atomic_inc_unchecked(&proc_poll_event);
90151 wake_up_interruptible(&proc_poll_wait);
90152
90153 out_dput:
90154@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90155
90156 poll_wait(file, &proc_poll_wait, wait);
90157
90158- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90159- seq->poll_event = atomic_read(&proc_poll_event);
90160+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90161+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90162 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90163 }
90164
90165@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90166 return ret;
90167
90168 seq = file->private_data;
90169- seq->poll_event = atomic_read(&proc_poll_event);
90170+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90171 return 0;
90172 }
90173
90174@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90175 (frontswap_map) ? "FS" : "");
90176
90177 mutex_unlock(&swapon_mutex);
90178- atomic_inc(&proc_poll_event);
90179+ atomic_inc_unchecked(&proc_poll_event);
90180 wake_up_interruptible(&proc_poll_wait);
90181
90182 if (S_ISREG(inode->i_mode))
90183diff --git a/mm/util.c b/mm/util.c
90184index 7441c41..c3de793 100644
90185--- a/mm/util.c
90186+++ b/mm/util.c
90187@@ -294,6 +294,12 @@ done:
90188 void arch_pick_mmap_layout(struct mm_struct *mm)
90189 {
90190 mm->mmap_base = TASK_UNMAPPED_BASE;
90191+
90192+#ifdef CONFIG_PAX_RANDMMAP
90193+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90194+ mm->mmap_base += mm->delta_mmap;
90195+#endif
90196+
90197 mm->get_unmapped_area = arch_get_unmapped_area;
90198 }
90199 #endif
90200diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90201index 13a5495..6707d97 100644
90202--- a/mm/vmalloc.c
90203+++ b/mm/vmalloc.c
90204@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90205
90206 pte = pte_offset_kernel(pmd, addr);
90207 do {
90208- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90209- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90210+
90211+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90212+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90213+ BUG_ON(!pte_exec(*pte));
90214+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90215+ continue;
90216+ }
90217+#endif
90218+
90219+ {
90220+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90221+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90222+ }
90223 } while (pte++, addr += PAGE_SIZE, addr != end);
90224 }
90225
90226@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90227 pte = pte_alloc_kernel(pmd, addr);
90228 if (!pte)
90229 return -ENOMEM;
90230+
90231+ pax_open_kernel();
90232 do {
90233 struct page *page = pages[*nr];
90234
90235- if (WARN_ON(!pte_none(*pte)))
90236+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90237+ if (pgprot_val(prot) & _PAGE_NX)
90238+#endif
90239+
90240+ if (!pte_none(*pte)) {
90241+ pax_close_kernel();
90242+ WARN_ON(1);
90243 return -EBUSY;
90244- if (WARN_ON(!page))
90245+ }
90246+ if (!page) {
90247+ pax_close_kernel();
90248+ WARN_ON(1);
90249 return -ENOMEM;
90250+ }
90251 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90252 (*nr)++;
90253 } while (pte++, addr += PAGE_SIZE, addr != end);
90254+ pax_close_kernel();
90255 return 0;
90256 }
90257
90258@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90259 pmd_t *pmd;
90260 unsigned long next;
90261
90262- pmd = pmd_alloc(&init_mm, pud, addr);
90263+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90264 if (!pmd)
90265 return -ENOMEM;
90266 do {
90267@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90268 pud_t *pud;
90269 unsigned long next;
90270
90271- pud = pud_alloc(&init_mm, pgd, addr);
90272+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90273 if (!pud)
90274 return -ENOMEM;
90275 do {
90276@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90277 if (addr >= MODULES_VADDR && addr < MODULES_END)
90278 return 1;
90279 #endif
90280+
90281+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90282+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90283+ return 1;
90284+#endif
90285+
90286 return is_vmalloc_addr(x);
90287 }
90288
90289@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90290
90291 if (!pgd_none(*pgd)) {
90292 pud_t *pud = pud_offset(pgd, addr);
90293+#ifdef CONFIG_X86
90294+ if (!pud_large(*pud))
90295+#endif
90296 if (!pud_none(*pud)) {
90297 pmd_t *pmd = pmd_offset(pud, addr);
90298+#ifdef CONFIG_X86
90299+ if (!pmd_large(*pmd))
90300+#endif
90301 if (!pmd_none(*pmd)) {
90302 pte_t *ptep, pte;
90303
90304@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90305 * Allocate a region of KVA of the specified size and alignment, within the
90306 * vstart and vend.
90307 */
90308-static struct vmap_area *alloc_vmap_area(unsigned long size,
90309+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90310 unsigned long align,
90311 unsigned long vstart, unsigned long vend,
90312 int node, gfp_t gfp_mask)
90313@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90314 struct vm_struct *area;
90315
90316 BUG_ON(in_interrupt());
90317+
90318+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90319+ if (flags & VM_KERNEXEC) {
90320+ if (start != VMALLOC_START || end != VMALLOC_END)
90321+ return NULL;
90322+ start = (unsigned long)MODULES_EXEC_VADDR;
90323+ end = (unsigned long)MODULES_EXEC_END;
90324+ }
90325+#endif
90326+
90327 if (flags & VM_IOREMAP)
90328 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90329
90330@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90331 if (count > totalram_pages)
90332 return NULL;
90333
90334+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90335+ if (!(pgprot_val(prot) & _PAGE_NX))
90336+ flags |= VM_KERNEXEC;
90337+#endif
90338+
90339 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90340 __builtin_return_address(0));
90341 if (!area)
90342@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90343 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90344 goto fail;
90345
90346+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90347+ if (!(pgprot_val(prot) & _PAGE_NX))
90348+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90349+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90350+ else
90351+#endif
90352+
90353 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90354 start, end, node, gfp_mask, caller);
90355 if (!area)
90356@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90357 * For tight control over page level allocator and protection flags
90358 * use __vmalloc() instead.
90359 */
90360-
90361 void *vmalloc_exec(unsigned long size)
90362 {
90363- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90364+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90365 NUMA_NO_NODE, __builtin_return_address(0));
90366 }
90367
90368@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90369 {
90370 struct vm_struct *area;
90371
90372+ BUG_ON(vma->vm_mirror);
90373+
90374 size = PAGE_ALIGN(size);
90375
90376 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90377@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90378 v->addr, v->addr + v->size, v->size);
90379
90380 if (v->caller)
90381+#ifdef CONFIG_GRKERNSEC_HIDESYM
90382+ seq_printf(m, " %pK", v->caller);
90383+#else
90384 seq_printf(m, " %pS", v->caller);
90385+#endif
90386
90387 if (v->nr_pages)
90388 seq_printf(m, " pages=%d", v->nr_pages);
90389diff --git a/mm/vmstat.c b/mm/vmstat.c
90390index 20c2ef4..15e7ab7 100644
90391--- a/mm/vmstat.c
90392+++ b/mm/vmstat.c
90393@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90394 *
90395 * vm_stat contains the global counters
90396 */
90397-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90398+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90399 EXPORT_SYMBOL(vm_stat);
90400
90401 #ifdef CONFIG_SMP
90402@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90403 v = p->vm_stat_diff[i];
90404 p->vm_stat_diff[i] = 0;
90405 local_irq_restore(flags);
90406- atomic_long_add(v, &zone->vm_stat[i]);
90407+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90408 global_diff[i] += v;
90409 #ifdef CONFIG_NUMA
90410 /* 3 seconds idle till flush */
90411@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90412
90413 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90414 if (global_diff[i])
90415- atomic_long_add(global_diff[i], &vm_stat[i]);
90416+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90417 }
90418
90419 /*
90420@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90421 if (pset->vm_stat_diff[i]) {
90422 int v = pset->vm_stat_diff[i];
90423 pset->vm_stat_diff[i] = 0;
90424- atomic_long_add(v, &zone->vm_stat[i]);
90425- atomic_long_add(v, &vm_stat[i]);
90426+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90427+ atomic_long_add_unchecked(v, &vm_stat[i]);
90428 }
90429 }
90430 #endif
90431@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90432 start_cpu_timer(cpu);
90433 #endif
90434 #ifdef CONFIG_PROC_FS
90435- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90436- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90437- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90438- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90439+ {
90440+ mode_t gr_mode = S_IRUGO;
90441+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90442+ gr_mode = S_IRUSR;
90443+#endif
90444+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90445+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90446+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90447+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90448+#else
90449+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90450+#endif
90451+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90452+ }
90453 #endif
90454 return 0;
90455 }
90456diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90457index 2fb2d88..8c06e40 100644
90458--- a/net/8021q/vlan.c
90459+++ b/net/8021q/vlan.c
90460@@ -469,7 +469,7 @@ out:
90461 return NOTIFY_DONE;
90462 }
90463
90464-static struct notifier_block vlan_notifier_block __read_mostly = {
90465+static struct notifier_block vlan_notifier_block = {
90466 .notifier_call = vlan_device_event,
90467 };
90468
90469@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90470 err = -EPERM;
90471 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90472 break;
90473- if ((args.u.name_type >= 0) &&
90474- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90475+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90476 struct vlan_net *vn;
90477
90478 vn = net_generic(net, vlan_net_id);
90479diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
90480index 3091297..c7e634a 100644
90481--- a/net/8021q/vlan_netlink.c
90482+++ b/net/8021q/vlan_netlink.c
90483@@ -171,7 +171,7 @@ static size_t vlan_get_size(const struct net_device *dev)
90484
90485 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
90486 nla_total_size(2) + /* IFLA_VLAN_ID */
90487- sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
90488+ nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
90489 vlan_qos_map_size(vlan->nr_ingress_mappings) +
90490 vlan_qos_map_size(vlan->nr_egress_mappings);
90491 }
90492diff --git a/net/9p/mod.c b/net/9p/mod.c
90493index 6ab36ae..6f1841b 100644
90494--- a/net/9p/mod.c
90495+++ b/net/9p/mod.c
90496@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90497 void v9fs_register_trans(struct p9_trans_module *m)
90498 {
90499 spin_lock(&v9fs_trans_lock);
90500- list_add_tail(&m->list, &v9fs_trans_list);
90501+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90502 spin_unlock(&v9fs_trans_lock);
90503 }
90504 EXPORT_SYMBOL(v9fs_register_trans);
90505@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90506 void v9fs_unregister_trans(struct p9_trans_module *m)
90507 {
90508 spin_lock(&v9fs_trans_lock);
90509- list_del_init(&m->list);
90510+ pax_list_del_init((struct list_head *)&m->list);
90511 spin_unlock(&v9fs_trans_lock);
90512 }
90513 EXPORT_SYMBOL(v9fs_unregister_trans);
90514diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90515index 3ffda1b..fceac96 100644
90516--- a/net/9p/trans_fd.c
90517+++ b/net/9p/trans_fd.c
90518@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90519 oldfs = get_fs();
90520 set_fs(get_ds());
90521 /* The cast to a user pointer is valid due to the set_fs() */
90522- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90523+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90524 set_fs(oldfs);
90525
90526 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90527diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90528index 876fbe8..8bbea9f 100644
90529--- a/net/atm/atm_misc.c
90530+++ b/net/atm/atm_misc.c
90531@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90532 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90533 return 1;
90534 atm_return(vcc, truesize);
90535- atomic_inc(&vcc->stats->rx_drop);
90536+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90537 return 0;
90538 }
90539 EXPORT_SYMBOL(atm_charge);
90540@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90541 }
90542 }
90543 atm_return(vcc, guess);
90544- atomic_inc(&vcc->stats->rx_drop);
90545+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90546 return NULL;
90547 }
90548 EXPORT_SYMBOL(atm_alloc_charge);
90549@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90550
90551 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90552 {
90553-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90554+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90555 __SONET_ITEMS
90556 #undef __HANDLE_ITEM
90557 }
90558@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90559
90560 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90561 {
90562-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90563+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90564 __SONET_ITEMS
90565 #undef __HANDLE_ITEM
90566 }
90567diff --git a/net/atm/lec.h b/net/atm/lec.h
90568index 4149db1..f2ab682 100644
90569--- a/net/atm/lec.h
90570+++ b/net/atm/lec.h
90571@@ -48,7 +48,7 @@ struct lane2_ops {
90572 const u8 *tlvs, u32 sizeoftlvs);
90573 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90574 const u8 *tlvs, u32 sizeoftlvs);
90575-};
90576+} __no_const;
90577
90578 /*
90579 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90580diff --git a/net/atm/proc.c b/net/atm/proc.c
90581index bbb6461..cf04016 100644
90582--- a/net/atm/proc.c
90583+++ b/net/atm/proc.c
90584@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90585 const struct k_atm_aal_stats *stats)
90586 {
90587 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90588- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90589- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90590- atomic_read(&stats->rx_drop));
90591+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90592+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90593+ atomic_read_unchecked(&stats->rx_drop));
90594 }
90595
90596 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90597diff --git a/net/atm/resources.c b/net/atm/resources.c
90598index 0447d5d..3cf4728 100644
90599--- a/net/atm/resources.c
90600+++ b/net/atm/resources.c
90601@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90602 static void copy_aal_stats(struct k_atm_aal_stats *from,
90603 struct atm_aal_stats *to)
90604 {
90605-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90606+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90607 __AAL_STAT_ITEMS
90608 #undef __HANDLE_ITEM
90609 }
90610@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90611 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90612 struct atm_aal_stats *to)
90613 {
90614-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90615+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90616 __AAL_STAT_ITEMS
90617 #undef __HANDLE_ITEM
90618 }
90619diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90620index 919a5ce..cc6b444 100644
90621--- a/net/ax25/sysctl_net_ax25.c
90622+++ b/net/ax25/sysctl_net_ax25.c
90623@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90624 {
90625 char path[sizeof("net/ax25/") + IFNAMSIZ];
90626 int k;
90627- struct ctl_table *table;
90628+ ctl_table_no_const *table;
90629
90630 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90631 if (!table)
90632diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90633index 62da527..aa27535 100644
90634--- a/net/batman-adv/bat_iv_ogm.c
90635+++ b/net/batman-adv/bat_iv_ogm.c
90636@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90637
90638 /* randomize initial seqno to avoid collision */
90639 get_random_bytes(&random_seqno, sizeof(random_seqno));
90640- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90641+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90642
90643 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90644 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90645@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90646 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90647
90648 /* change sequence number to network order */
90649- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90650+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90651 batadv_ogm_packet->seqno = htonl(seqno);
90652- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90653+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90654
90655 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90656 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90657@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90658 return;
90659
90660 /* could be changed by schedule_own_packet() */
90661- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90662+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90663
90664 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90665 has_directlink_flag = 1;
90666diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90667index c478e6b..469fd2f 100644
90668--- a/net/batman-adv/hard-interface.c
90669+++ b/net/batman-adv/hard-interface.c
90670@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90671 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90672 dev_add_pack(&hard_iface->batman_adv_ptype);
90673
90674- atomic_set(&hard_iface->frag_seqno, 1);
90675+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90676 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90677 hard_iface->net_dev->name);
90678
90679diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90680index 33b6144..3212ac5 100644
90681--- a/net/batman-adv/soft-interface.c
90682+++ b/net/batman-adv/soft-interface.c
90683@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90684 primary_if->net_dev->dev_addr, ETH_ALEN);
90685
90686 /* set broadcast sequence number */
90687- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90688+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90689 bcast_packet->seqno = htonl(seqno);
90690
90691 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90692@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90693 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90694
90695 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90696- atomic_set(&bat_priv->bcast_seqno, 1);
90697+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90698 atomic_set(&bat_priv->tt.vn, 0);
90699 atomic_set(&bat_priv->tt.local_changes, 0);
90700 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90701diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90702index b2c94e1..3d47e07 100644
90703--- a/net/batman-adv/types.h
90704+++ b/net/batman-adv/types.h
90705@@ -51,7 +51,7 @@
90706 struct batadv_hard_iface_bat_iv {
90707 unsigned char *ogm_buff;
90708 int ogm_buff_len;
90709- atomic_t ogm_seqno;
90710+ atomic_unchecked_t ogm_seqno;
90711 };
90712
90713 /**
90714@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90715 int16_t if_num;
90716 char if_status;
90717 struct net_device *net_dev;
90718- atomic_t frag_seqno;
90719+ atomic_unchecked_t frag_seqno;
90720 uint8_t num_bcasts;
90721 struct kobject *hardif_obj;
90722 atomic_t refcount;
90723@@ -560,7 +560,7 @@ struct batadv_priv {
90724 #ifdef CONFIG_BATMAN_ADV_DEBUG
90725 atomic_t log_level;
90726 #endif
90727- atomic_t bcast_seqno;
90728+ atomic_unchecked_t bcast_seqno;
90729 atomic_t bcast_queue_left;
90730 atomic_t batman_queue_left;
90731 char num_ifaces;
90732diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90733index 857e1b8..5ad07b2 100644
90734--- a/net/batman-adv/unicast.c
90735+++ b/net/batman-adv/unicast.c
90736@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90737 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90738 frag2->flags = large_tail;
90739
90740- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90741+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90742 frag1->seqno = htons(seqno - 1);
90743 frag2->seqno = htons(seqno);
90744
90745diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90746index 9bd7d95..6c4884f 100644
90747--- a/net/bluetooth/hci_sock.c
90748+++ b/net/bluetooth/hci_sock.c
90749@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90750 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90751 }
90752
90753- len = min_t(unsigned int, len, sizeof(uf));
90754+ len = min((size_t)len, sizeof(uf));
90755 if (copy_from_user(&uf, optval, len)) {
90756 err = -EFAULT;
90757 break;
90758diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90759index 8c3499b..2661c6a 100644
90760--- a/net/bluetooth/l2cap_core.c
90761+++ b/net/bluetooth/l2cap_core.c
90762@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90763 break;
90764
90765 case L2CAP_CONF_RFC:
90766- if (olen == sizeof(rfc))
90767- memcpy(&rfc, (void *)val, olen);
90768+ if (olen != sizeof(rfc))
90769+ break;
90770+
90771+ memcpy(&rfc, (void *)val, olen);
90772
90773 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90774 rfc.mode != chan->mode)
90775diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90776index 0098af8..fb5a31f 100644
90777--- a/net/bluetooth/l2cap_sock.c
90778+++ b/net/bluetooth/l2cap_sock.c
90779@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90780 struct sock *sk = sock->sk;
90781 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90782 struct l2cap_options opts;
90783- int len, err = 0;
90784+ int err = 0;
90785+ size_t len = optlen;
90786 u32 opt;
90787
90788 BT_DBG("sk %p", sk);
90789@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90790 opts.max_tx = chan->max_tx;
90791 opts.txwin_size = chan->tx_win;
90792
90793- len = min_t(unsigned int, sizeof(opts), optlen);
90794+ len = min(sizeof(opts), len);
90795 if (copy_from_user((char *) &opts, optval, len)) {
90796 err = -EFAULT;
90797 break;
90798@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90799 struct bt_security sec;
90800 struct bt_power pwr;
90801 struct l2cap_conn *conn;
90802- int len, err = 0;
90803+ int err = 0;
90804+ size_t len = optlen;
90805 u32 opt;
90806
90807 BT_DBG("sk %p", sk);
90808@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90809
90810 sec.level = BT_SECURITY_LOW;
90811
90812- len = min_t(unsigned int, sizeof(sec), optlen);
90813+ len = min(sizeof(sec), len);
90814 if (copy_from_user((char *) &sec, optval, len)) {
90815 err = -EFAULT;
90816 break;
90817@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90818
90819 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90820
90821- len = min_t(unsigned int, sizeof(pwr), optlen);
90822+ len = min(sizeof(pwr), len);
90823 if (copy_from_user((char *) &pwr, optval, len)) {
90824 err = -EFAULT;
90825 break;
90826diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90827index 30b3721..c1bd0a0 100644
90828--- a/net/bluetooth/rfcomm/sock.c
90829+++ b/net/bluetooth/rfcomm/sock.c
90830@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90831 struct sock *sk = sock->sk;
90832 struct bt_security sec;
90833 int err = 0;
90834- size_t len;
90835+ size_t len = optlen;
90836 u32 opt;
90837
90838 BT_DBG("sk %p", sk);
90839@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90840
90841 sec.level = BT_SECURITY_LOW;
90842
90843- len = min_t(unsigned int, sizeof(sec), optlen);
90844+ len = min(sizeof(sec), len);
90845 if (copy_from_user((char *) &sec, optval, len)) {
90846 err = -EFAULT;
90847 break;
90848diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90849index b6e44ad..5b0d514 100644
90850--- a/net/bluetooth/rfcomm/tty.c
90851+++ b/net/bluetooth/rfcomm/tty.c
90852@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90853 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90854
90855 spin_lock_irqsave(&dev->port.lock, flags);
90856- if (dev->port.count > 0) {
90857+ if (atomic_read(&dev->port.count) > 0) {
90858 spin_unlock_irqrestore(&dev->port.lock, flags);
90859 return;
90860 }
90861@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90862 return -ENODEV;
90863
90864 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
90865- dev->channel, dev->port.count);
90866+ dev->channel, atomic_read(&dev->port.count));
90867
90868 spin_lock_irqsave(&dev->port.lock, flags);
90869- if (++dev->port.count > 1) {
90870+ if (atomic_inc_return(&dev->port.count) > 1) {
90871 spin_unlock_irqrestore(&dev->port.lock, flags);
90872 return 0;
90873 }
90874@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
90875 return;
90876
90877 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
90878- dev->port.count);
90879+ atomic_read(&dev->port.count));
90880
90881 spin_lock_irqsave(&dev->port.lock, flags);
90882- if (!--dev->port.count) {
90883+ if (!atomic_dec_return(&dev->port.count)) {
90884 spin_unlock_irqrestore(&dev->port.lock, flags);
90885 if (dev->tty_dev->parent)
90886 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
90887diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
90888index 5180938..7c470c3 100644
90889--- a/net/bridge/netfilter/ebt_ulog.c
90890+++ b/net/bridge/netfilter/ebt_ulog.c
90891@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90892 ub->qlen++;
90893
90894 pm = nlmsg_data(nlh);
90895+ memset(pm, 0, sizeof(*pm));
90896
90897 /* Fill in the ulog data */
90898 pm->version = EBT_ULOG_VERSION;
90899@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90900 pm->hook = hooknr;
90901 if (uloginfo->prefix != NULL)
90902 strcpy(pm->prefix, uloginfo->prefix);
90903- else
90904- *(pm->prefix) = '\0';
90905
90906 if (in) {
90907 strcpy(pm->physindev, in->name);
90908@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90909 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
90910 else
90911 strcpy(pm->indev, in->name);
90912- } else
90913- pm->indev[0] = pm->physindev[0] = '\0';
90914+ }
90915
90916 if (out) {
90917 /* If out exists, then out is a bridge port */
90918 strcpy(pm->physoutdev, out->name);
90919 /* rcu_read_lock()ed by nf_hook_slow */
90920 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
90921- } else
90922- pm->outdev[0] = pm->physoutdev[0] = '\0';
90923+ }
90924
90925 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
90926 BUG();
90927diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
90928index ac78024..161a80c 100644
90929--- a/net/bridge/netfilter/ebtables.c
90930+++ b/net/bridge/netfilter/ebtables.c
90931@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
90932 tmp.valid_hooks = t->table->valid_hooks;
90933 }
90934 mutex_unlock(&ebt_mutex);
90935- if (copy_to_user(user, &tmp, *len) != 0){
90936+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
90937 BUGPRINT("c2u Didn't work\n");
90938 ret = -EFAULT;
90939 break;
90940@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
90941 goto out;
90942 tmp.valid_hooks = t->valid_hooks;
90943
90944- if (copy_to_user(user, &tmp, *len) != 0) {
90945+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
90946 ret = -EFAULT;
90947 break;
90948 }
90949@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
90950 tmp.entries_size = t->table->entries_size;
90951 tmp.valid_hooks = t->table->valid_hooks;
90952
90953- if (copy_to_user(user, &tmp, *len) != 0) {
90954+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
90955 ret = -EFAULT;
90956 break;
90957 }
90958diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
90959index 0f45522..dab651f 100644
90960--- a/net/caif/cfctrl.c
90961+++ b/net/caif/cfctrl.c
90962@@ -10,6 +10,7 @@
90963 #include <linux/spinlock.h>
90964 #include <linux/slab.h>
90965 #include <linux/pkt_sched.h>
90966+#include <linux/sched.h>
90967 #include <net/caif/caif_layer.h>
90968 #include <net/caif/cfpkt.h>
90969 #include <net/caif/cfctrl.h>
90970@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
90971 memset(&dev_info, 0, sizeof(dev_info));
90972 dev_info.id = 0xff;
90973 cfsrvl_init(&this->serv, 0, &dev_info, false);
90974- atomic_set(&this->req_seq_no, 1);
90975- atomic_set(&this->rsp_seq_no, 1);
90976+ atomic_set_unchecked(&this->req_seq_no, 1);
90977+ atomic_set_unchecked(&this->rsp_seq_no, 1);
90978 this->serv.layer.receive = cfctrl_recv;
90979 sprintf(this->serv.layer.name, "ctrl");
90980 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
90981@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
90982 struct cfctrl_request_info *req)
90983 {
90984 spin_lock_bh(&ctrl->info_list_lock);
90985- atomic_inc(&ctrl->req_seq_no);
90986- req->sequence_no = atomic_read(&ctrl->req_seq_no);
90987+ atomic_inc_unchecked(&ctrl->req_seq_no);
90988+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
90989 list_add_tail(&req->list, &ctrl->list);
90990 spin_unlock_bh(&ctrl->info_list_lock);
90991 }
90992@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
90993 if (p != first)
90994 pr_warn("Requests are not received in order\n");
90995
90996- atomic_set(&ctrl->rsp_seq_no,
90997+ atomic_set_unchecked(&ctrl->rsp_seq_no,
90998 p->sequence_no);
90999 list_del(&p->list);
91000 goto out;
91001diff --git a/net/can/af_can.c b/net/can/af_can.c
91002index 3ab8dd2..b9aef13 100644
91003--- a/net/can/af_can.c
91004+++ b/net/can/af_can.c
91005@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91006 };
91007
91008 /* notifier block for netdevice event */
91009-static struct notifier_block can_netdev_notifier __read_mostly = {
91010+static struct notifier_block can_netdev_notifier = {
91011 .notifier_call = can_notifier,
91012 };
91013
91014diff --git a/net/can/gw.c b/net/can/gw.c
91015index 2f291f9..98c986a 100644
91016--- a/net/can/gw.c
91017+++ b/net/can/gw.c
91018@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91019 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91020
91021 static HLIST_HEAD(cgw_list);
91022-static struct notifier_block notifier;
91023
91024 static struct kmem_cache *cgw_cache __read_mostly;
91025
91026@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91027 return err;
91028 }
91029
91030+static struct notifier_block notifier = {
91031+ .notifier_call = cgw_notifier
91032+};
91033+
91034 static __init int cgw_module_init(void)
91035 {
91036 /* sanitize given module parameter */
91037@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91038 return -ENOMEM;
91039
91040 /* set notifier */
91041- notifier.notifier_call = cgw_notifier;
91042 register_netdevice_notifier(&notifier);
91043
91044 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91045diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91046index eb0a46a..5f3bae8 100644
91047--- a/net/ceph/messenger.c
91048+++ b/net/ceph/messenger.c
91049@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91050 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91051
91052 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91053-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91054+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91055
91056 static struct page *zero_page; /* used in certain error cases */
91057
91058@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91059 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91060 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91061
91062- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91063+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91064 s = addr_str[i];
91065
91066 switch (ss->ss_family) {
91067diff --git a/net/compat.c b/net/compat.c
91068index f0a1ba6..0541331 100644
91069--- a/net/compat.c
91070+++ b/net/compat.c
91071@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91072 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91073 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91074 return -EFAULT;
91075- kmsg->msg_name = compat_ptr(tmp1);
91076- kmsg->msg_iov = compat_ptr(tmp2);
91077- kmsg->msg_control = compat_ptr(tmp3);
91078+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91079+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91080+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91081 return 0;
91082 }
91083
91084@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91085
91086 if (kern_msg->msg_namelen) {
91087 if (mode == VERIFY_READ) {
91088- int err = move_addr_to_kernel(kern_msg->msg_name,
91089+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91090 kern_msg->msg_namelen,
91091 kern_address);
91092 if (err < 0)
91093@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91094 kern_msg->msg_name = NULL;
91095
91096 tot_len = iov_from_user_compat_to_kern(kern_iov,
91097- (struct compat_iovec __user *)kern_msg->msg_iov,
91098+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91099 kern_msg->msg_iovlen);
91100 if (tot_len >= 0)
91101 kern_msg->msg_iov = kern_iov;
91102@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91103
91104 #define CMSG_COMPAT_FIRSTHDR(msg) \
91105 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91106- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91107+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91108 (struct compat_cmsghdr __user *)NULL)
91109
91110 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91111 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91112 (ucmlen) <= (unsigned long) \
91113 ((mhdr)->msg_controllen - \
91114- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91115+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91116
91117 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91118 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91119 {
91120 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91121- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91122+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91123 msg->msg_controllen)
91124 return NULL;
91125 return (struct compat_cmsghdr __user *)ptr;
91126@@ -219,7 +219,7 @@ Efault:
91127
91128 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91129 {
91130- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91131+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91132 struct compat_cmsghdr cmhdr;
91133 struct compat_timeval ctv;
91134 struct compat_timespec cts[3];
91135@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91136
91137 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91138 {
91139- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91140+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91141 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91142 int fdnum = scm->fp->count;
91143 struct file **fp = scm->fp->fp;
91144@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91145 return -EFAULT;
91146 old_fs = get_fs();
91147 set_fs(KERNEL_DS);
91148- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91149+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91150 set_fs(old_fs);
91151
91152 return err;
91153@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91154 len = sizeof(ktime);
91155 old_fs = get_fs();
91156 set_fs(KERNEL_DS);
91157- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91158+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91159 set_fs(old_fs);
91160
91161 if (!err) {
91162@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91163 case MCAST_JOIN_GROUP:
91164 case MCAST_LEAVE_GROUP:
91165 {
91166- struct compat_group_req __user *gr32 = (void *)optval;
91167+ struct compat_group_req __user *gr32 = (void __user *)optval;
91168 struct group_req __user *kgr =
91169 compat_alloc_user_space(sizeof(struct group_req));
91170 u32 interface;
91171@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91172 case MCAST_BLOCK_SOURCE:
91173 case MCAST_UNBLOCK_SOURCE:
91174 {
91175- struct compat_group_source_req __user *gsr32 = (void *)optval;
91176+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91177 struct group_source_req __user *kgsr = compat_alloc_user_space(
91178 sizeof(struct group_source_req));
91179 u32 interface;
91180@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91181 }
91182 case MCAST_MSFILTER:
91183 {
91184- struct compat_group_filter __user *gf32 = (void *)optval;
91185+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91186 struct group_filter __user *kgf;
91187 u32 interface, fmode, numsrc;
91188
91189@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91190 char __user *optval, int __user *optlen,
91191 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91192 {
91193- struct compat_group_filter __user *gf32 = (void *)optval;
91194+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91195 struct group_filter __user *kgf;
91196 int __user *koptlen;
91197 u32 interface, fmode, numsrc;
91198@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91199
91200 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91201 return -EINVAL;
91202- if (copy_from_user(a, args, nas[call]))
91203+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91204 return -EFAULT;
91205 a0 = a[0];
91206 a1 = a[1];
91207diff --git a/net/core/datagram.c b/net/core/datagram.c
91208index 8ab48cd..57b1a80 100644
91209--- a/net/core/datagram.c
91210+++ b/net/core/datagram.c
91211@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91212 }
91213
91214 kfree_skb(skb);
91215- atomic_inc(&sk->sk_drops);
91216+ atomic_inc_unchecked(&sk->sk_drops);
91217 sk_mem_reclaim_partial(sk);
91218
91219 return err;
91220diff --git a/net/core/dev.c b/net/core/dev.c
91221index 26755dd..2a232de 100644
91222--- a/net/core/dev.c
91223+++ b/net/core/dev.c
91224@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91225 {
91226 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91227 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91228- atomic_long_inc(&dev->rx_dropped);
91229+ atomic_long_inc_unchecked(&dev->rx_dropped);
91230 kfree_skb(skb);
91231 return NET_RX_DROP;
91232 }
91233 }
91234
91235 if (unlikely(!is_skb_forwardable(dev, skb))) {
91236- atomic_long_inc(&dev->rx_dropped);
91237+ atomic_long_inc_unchecked(&dev->rx_dropped);
91238 kfree_skb(skb);
91239 return NET_RX_DROP;
91240 }
91241@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91242
91243 struct dev_gso_cb {
91244 void (*destructor)(struct sk_buff *skb);
91245-};
91246+} __no_const;
91247
91248 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91249
91250@@ -3206,7 +3206,7 @@ enqueue:
91251
91252 local_irq_restore(flags);
91253
91254- atomic_long_inc(&skb->dev->rx_dropped);
91255+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91256 kfree_skb(skb);
91257 return NET_RX_DROP;
91258 }
91259@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91260 }
91261 EXPORT_SYMBOL(netif_rx_ni);
91262
91263-static void net_tx_action(struct softirq_action *h)
91264+static __latent_entropy void net_tx_action(void)
91265 {
91266 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91267
91268@@ -3612,7 +3612,7 @@ ncls:
91269 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91270 } else {
91271 drop:
91272- atomic_long_inc(&skb->dev->rx_dropped);
91273+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91274 kfree_skb(skb);
91275 /* Jamal, now you will not able to escape explaining
91276 * me how you were going to use this. :-)
91277@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91278 }
91279 EXPORT_SYMBOL(netif_napi_del);
91280
91281-static void net_rx_action(struct softirq_action *h)
91282+static __latent_entropy void net_rx_action(void)
91283 {
91284 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91285 unsigned long time_limit = jiffies + 2;
91286@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91287 } else {
91288 netdev_stats_to_stats64(storage, &dev->stats);
91289 }
91290- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91291+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91292 return storage;
91293 }
91294 EXPORT_SYMBOL(dev_get_stats);
91295diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91296index 5b7d0e1..cb960fc 100644
91297--- a/net/core/dev_ioctl.c
91298+++ b/net/core/dev_ioctl.c
91299@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91300 if (no_module && capable(CAP_NET_ADMIN))
91301 no_module = request_module("netdev-%s", name);
91302 if (no_module && capable(CAP_SYS_MODULE)) {
91303+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91304+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91305+#else
91306 if (!request_module("%s", name))
91307 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91308 name);
91309+#endif
91310 }
91311 }
91312 EXPORT_SYMBOL(dev_load);
91313diff --git a/net/core/flow.c b/net/core/flow.c
91314index dfa602c..3103d88 100644
91315--- a/net/core/flow.c
91316+++ b/net/core/flow.c
91317@@ -61,7 +61,7 @@ struct flow_cache {
91318 struct timer_list rnd_timer;
91319 };
91320
91321-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91322+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91323 EXPORT_SYMBOL(flow_cache_genid);
91324 static struct flow_cache flow_cache_global;
91325 static struct kmem_cache *flow_cachep __read_mostly;
91326@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91327
91328 static int flow_entry_valid(struct flow_cache_entry *fle)
91329 {
91330- if (atomic_read(&flow_cache_genid) != fle->genid)
91331+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91332 return 0;
91333 if (fle->object && !fle->object->ops->check(fle->object))
91334 return 0;
91335@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91336 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91337 fcp->hash_count++;
91338 }
91339- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91340+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91341 flo = fle->object;
91342 if (!flo)
91343 goto ret_object;
91344@@ -279,7 +279,7 @@ nocache:
91345 }
91346 flo = resolver(net, key, family, dir, flo, ctx);
91347 if (fle) {
91348- fle->genid = atomic_read(&flow_cache_genid);
91349+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91350 if (!IS_ERR(flo))
91351 fle->object = flo;
91352 else
91353diff --git a/net/core/iovec.c b/net/core/iovec.c
91354index de178e4..1dabd8b 100644
91355--- a/net/core/iovec.c
91356+++ b/net/core/iovec.c
91357@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91358 if (m->msg_namelen) {
91359 if (mode == VERIFY_READ) {
91360 void __user *namep;
91361- namep = (void __user __force *) m->msg_name;
91362+ namep = (void __force_user *) m->msg_name;
91363 err = move_addr_to_kernel(namep, m->msg_namelen,
91364 address);
91365 if (err < 0)
91366@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91367 }
91368
91369 size = m->msg_iovlen * sizeof(struct iovec);
91370- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91371+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91372 return -EFAULT;
91373
91374 m->msg_iov = iov;
91375diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91376index 60533db..14842cc 100644
91377--- a/net/core/neighbour.c
91378+++ b/net/core/neighbour.c
91379@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91380 void __user *buffer, size_t *lenp, loff_t *ppos)
91381 {
91382 int size, ret;
91383- struct ctl_table tmp = *ctl;
91384+ ctl_table_no_const tmp = *ctl;
91385
91386 tmp.extra1 = &zero;
91387 tmp.extra2 = &unres_qlen_max;
91388diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91389index 2bf8329..7960607 100644
91390--- a/net/core/net-procfs.c
91391+++ b/net/core/net-procfs.c
91392@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91393 else
91394 seq_printf(seq, "%04x", ntohs(pt->type));
91395
91396+#ifdef CONFIG_GRKERNSEC_HIDESYM
91397+ seq_printf(seq, " %-8s %pf\n",
91398+ pt->dev ? pt->dev->name : "", NULL);
91399+#else
91400 seq_printf(seq, " %-8s %pf\n",
91401 pt->dev ? pt->dev->name : "", pt->func);
91402+#endif
91403 }
91404
91405 return 0;
91406diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91407index 981fed3..536af34 100644
91408--- a/net/core/net-sysfs.c
91409+++ b/net/core/net-sysfs.c
91410@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91411 }
91412 EXPORT_SYMBOL(netdev_class_remove_file);
91413
91414-int netdev_kobject_init(void)
91415+int __init netdev_kobject_init(void)
91416 {
91417 kobj_ns_type_register(&net_ns_type_operations);
91418 return class_register(&net_class);
91419diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91420index f9765203..9feaef8 100644
91421--- a/net/core/net_namespace.c
91422+++ b/net/core/net_namespace.c
91423@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91424 int error;
91425 LIST_HEAD(net_exit_list);
91426
91427- list_add_tail(&ops->list, list);
91428+ pax_list_add_tail((struct list_head *)&ops->list, list);
91429 if (ops->init || (ops->id && ops->size)) {
91430 for_each_net(net) {
91431 error = ops_init(ops, net);
91432@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91433
91434 out_undo:
91435 /* If I have an error cleanup all namespaces I initialized */
91436- list_del(&ops->list);
91437+ pax_list_del((struct list_head *)&ops->list);
91438 ops_exit_list(ops, &net_exit_list);
91439 ops_free_list(ops, &net_exit_list);
91440 return error;
91441@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91442 struct net *net;
91443 LIST_HEAD(net_exit_list);
91444
91445- list_del(&ops->list);
91446+ pax_list_del((struct list_head *)&ops->list);
91447 for_each_net(net)
91448 list_add_tail(&net->exit_list, &net_exit_list);
91449 ops_exit_list(ops, &net_exit_list);
91450@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91451 mutex_lock(&net_mutex);
91452 error = register_pernet_operations(&pernet_list, ops);
91453 if (!error && (first_device == &pernet_list))
91454- first_device = &ops->list;
91455+ first_device = (struct list_head *)&ops->list;
91456 mutex_unlock(&net_mutex);
91457 return error;
91458 }
91459diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91460index fc75c9e..8c8e9be 100644
91461--- a/net/core/netpoll.c
91462+++ b/net/core/netpoll.c
91463@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91464 struct udphdr *udph;
91465 struct iphdr *iph;
91466 struct ethhdr *eth;
91467- static atomic_t ip_ident;
91468+ static atomic_unchecked_t ip_ident;
91469 struct ipv6hdr *ip6h;
91470
91471 udp_len = len + sizeof(*udph);
91472@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91473 put_unaligned(0x45, (unsigned char *)iph);
91474 iph->tos = 0;
91475 put_unaligned(htons(ip_len), &(iph->tot_len));
91476- iph->id = htons(atomic_inc_return(&ip_ident));
91477+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91478 iph->frag_off = 0;
91479 iph->ttl = 64;
91480 iph->protocol = IPPROTO_UDP;
91481diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91482index ca198c1d1..125372f 100644
91483--- a/net/core/rtnetlink.c
91484+++ b/net/core/rtnetlink.c
91485@@ -58,7 +58,7 @@ struct rtnl_link {
91486 rtnl_doit_func doit;
91487 rtnl_dumpit_func dumpit;
91488 rtnl_calcit_func calcit;
91489-};
91490+} __no_const;
91491
91492 static DEFINE_MUTEX(rtnl_mutex);
91493
91494@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91495 if (rtnl_link_ops_get(ops->kind))
91496 return -EEXIST;
91497
91498- if (!ops->dellink)
91499- ops->dellink = unregister_netdevice_queue;
91500+ if (!ops->dellink) {
91501+ pax_open_kernel();
91502+ *(void **)&ops->dellink = unregister_netdevice_queue;
91503+ pax_close_kernel();
91504+ }
91505
91506- list_add_tail(&ops->list, &link_ops);
91507+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91508 return 0;
91509 }
91510 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91511@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91512 for_each_net(net) {
91513 __rtnl_kill_links(net, ops);
91514 }
91515- list_del(&ops->list);
91516+ pax_list_del((struct list_head *)&ops->list);
91517 }
91518 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91519
91520diff --git a/net/core/scm.c b/net/core/scm.c
91521index b4da80b..98d6bdb 100644
91522--- a/net/core/scm.c
91523+++ b/net/core/scm.c
91524@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91525 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91526 {
91527 struct cmsghdr __user *cm
91528- = (__force struct cmsghdr __user *)msg->msg_control;
91529+ = (struct cmsghdr __force_user *)msg->msg_control;
91530 struct cmsghdr cmhdr;
91531 int cmlen = CMSG_LEN(len);
91532 int err;
91533@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91534 err = -EFAULT;
91535 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91536 goto out;
91537- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91538+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91539 goto out;
91540 cmlen = CMSG_SPACE(len);
91541 if (msg->msg_controllen < cmlen)
91542@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91543 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91544 {
91545 struct cmsghdr __user *cm
91546- = (__force struct cmsghdr __user*)msg->msg_control;
91547+ = (struct cmsghdr __force_user *)msg->msg_control;
91548
91549 int fdmax = 0;
91550 int fdnum = scm->fp->count;
91551@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91552 if (fdnum < fdmax)
91553 fdmax = fdnum;
91554
91555- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91556+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91557 i++, cmfptr++)
91558 {
91559 struct socket *sock;
91560diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91561index 2c3d0f5..f5a326f 100644
91562--- a/net/core/skbuff.c
91563+++ b/net/core/skbuff.c
91564@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91565 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91566 sizeof(struct sk_buff),
91567 0,
91568- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91569+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91570+ SLAB_NO_SANITIZE,
91571 NULL);
91572 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91573 (2*sizeof(struct sk_buff)) +
91574 sizeof(atomic_t),
91575 0,
91576- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91577+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91578+ SLAB_NO_SANITIZE,
91579 NULL);
91580 }
91581
91582diff --git a/net/core/sock.c b/net/core/sock.c
91583index 2c097c5..bf72858 100644
91584--- a/net/core/sock.c
91585+++ b/net/core/sock.c
91586@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91587 struct sk_buff_head *list = &sk->sk_receive_queue;
91588
91589 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91590- atomic_inc(&sk->sk_drops);
91591+ atomic_inc_unchecked(&sk->sk_drops);
91592 trace_sock_rcvqueue_full(sk, skb);
91593 return -ENOMEM;
91594 }
91595@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91596 return err;
91597
91598 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91599- atomic_inc(&sk->sk_drops);
91600+ atomic_inc_unchecked(&sk->sk_drops);
91601 return -ENOBUFS;
91602 }
91603
91604@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91605 skb_dst_force(skb);
91606
91607 spin_lock_irqsave(&list->lock, flags);
91608- skb->dropcount = atomic_read(&sk->sk_drops);
91609+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91610 __skb_queue_tail(list, skb);
91611 spin_unlock_irqrestore(&list->lock, flags);
91612
91613@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91614 skb->dev = NULL;
91615
91616 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91617- atomic_inc(&sk->sk_drops);
91618+ atomic_inc_unchecked(&sk->sk_drops);
91619 goto discard_and_relse;
91620 }
91621 if (nested)
91622@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91623 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91624 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91625 bh_unlock_sock(sk);
91626- atomic_inc(&sk->sk_drops);
91627+ atomic_inc_unchecked(&sk->sk_drops);
91628 goto discard_and_relse;
91629 }
91630
91631@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91632 struct timeval tm;
91633 } v;
91634
91635- int lv = sizeof(int);
91636- int len;
91637+ unsigned int lv = sizeof(int);
91638+ unsigned int len;
91639
91640 if (get_user(len, optlen))
91641 return -EFAULT;
91642- if (len < 0)
91643+ if (len > INT_MAX)
91644 return -EINVAL;
91645
91646 memset(&v, 0, sizeof(v));
91647@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91648
91649 case SO_PEERNAME:
91650 {
91651- char address[128];
91652+ char address[_K_SS_MAXSIZE];
91653
91654 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91655 return -ENOTCONN;
91656- if (lv < len)
91657+ if (lv < len || sizeof address < len)
91658 return -EINVAL;
91659 if (copy_to_user(optval, address, len))
91660 return -EFAULT;
91661@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91662
91663 if (len > lv)
91664 len = lv;
91665- if (copy_to_user(optval, &v, len))
91666+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91667 return -EFAULT;
91668 lenout:
91669 if (put_user(len, optlen))
91670@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91671 */
91672 smp_wmb();
91673 atomic_set(&sk->sk_refcnt, 1);
91674- atomic_set(&sk->sk_drops, 0);
91675+ atomic_set_unchecked(&sk->sk_drops, 0);
91676 }
91677 EXPORT_SYMBOL(sock_init_data);
91678
91679diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91680index a0e9cf6..ef7f9ed 100644
91681--- a/net/core/sock_diag.c
91682+++ b/net/core/sock_diag.c
91683@@ -9,26 +9,33 @@
91684 #include <linux/inet_diag.h>
91685 #include <linux/sock_diag.h>
91686
91687-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91688+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91689 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91690 static DEFINE_MUTEX(sock_diag_table_mutex);
91691
91692 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91693 {
91694+#ifndef CONFIG_GRKERNSEC_HIDESYM
91695 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91696 cookie[1] != INET_DIAG_NOCOOKIE) &&
91697 ((u32)(unsigned long)sk != cookie[0] ||
91698 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91699 return -ESTALE;
91700 else
91701+#endif
91702 return 0;
91703 }
91704 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91705
91706 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91707 {
91708+#ifdef CONFIG_GRKERNSEC_HIDESYM
91709+ cookie[0] = 0;
91710+ cookie[1] = 0;
91711+#else
91712 cookie[0] = (u32)(unsigned long)sk;
91713 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91714+#endif
91715 }
91716 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91717
91718@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91719 mutex_lock(&sock_diag_table_mutex);
91720 if (sock_diag_handlers[hndl->family])
91721 err = -EBUSY;
91722- else
91723+ else {
91724+ pax_open_kernel();
91725 sock_diag_handlers[hndl->family] = hndl;
91726+ pax_close_kernel();
91727+ }
91728 mutex_unlock(&sock_diag_table_mutex);
91729
91730 return err;
91731@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91732
91733 mutex_lock(&sock_diag_table_mutex);
91734 BUG_ON(sock_diag_handlers[family] != hnld);
91735+ pax_open_kernel();
91736 sock_diag_handlers[family] = NULL;
91737+ pax_close_kernel();
91738 mutex_unlock(&sock_diag_table_mutex);
91739 }
91740 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91741diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91742index 31107ab..ae03d5a 100644
91743--- a/net/core/sysctl_net_core.c
91744+++ b/net/core/sysctl_net_core.c
91745@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91746 {
91747 unsigned int orig_size, size;
91748 int ret, i;
91749- struct ctl_table tmp = {
91750+ ctl_table_no_const tmp = {
91751 .data = &size,
91752 .maxlen = sizeof(size),
91753 .mode = table->mode
91754@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91755
91756 static __net_init int sysctl_core_net_init(struct net *net)
91757 {
91758- struct ctl_table *tbl;
91759+ ctl_table_no_const *tbl = NULL;
91760
91761 net->core.sysctl_somaxconn = SOMAXCONN;
91762
91763- tbl = netns_core_table;
91764 if (!net_eq(net, &init_net)) {
91765- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91766+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91767 if (tbl == NULL)
91768 goto err_dup;
91769
91770@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91771 if (net->user_ns != &init_user_ns) {
91772 tbl[0].procname = NULL;
91773 }
91774- }
91775-
91776- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91777+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91778+ } else
91779+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91780 if (net->core.sysctl_hdr == NULL)
91781 goto err_reg;
91782
91783 return 0;
91784
91785 err_reg:
91786- if (tbl != netns_core_table)
91787- kfree(tbl);
91788+ kfree(tbl);
91789 err_dup:
91790 return -ENOMEM;
91791 }
91792@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91793 kfree(tbl);
91794 }
91795
91796-static __net_initdata struct pernet_operations sysctl_core_ops = {
91797+static __net_initconst struct pernet_operations sysctl_core_ops = {
91798 .init = sysctl_core_net_init,
91799 .exit = sysctl_core_net_exit,
91800 };
91801diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91802index dd4d506..fb2fb87 100644
91803--- a/net/decnet/af_decnet.c
91804+++ b/net/decnet/af_decnet.c
91805@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91806 .sysctl_rmem = sysctl_decnet_rmem,
91807 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91808 .obj_size = sizeof(struct dn_sock),
91809+ .slab_flags = SLAB_USERCOPY,
91810 };
91811
91812 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91813diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91814index 5325b54..a0d4d69 100644
91815--- a/net/decnet/sysctl_net_decnet.c
91816+++ b/net/decnet/sysctl_net_decnet.c
91817@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91818
91819 if (len > *lenp) len = *lenp;
91820
91821- if (copy_to_user(buffer, addr, len))
91822+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91823 return -EFAULT;
91824
91825 *lenp = len;
91826@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91827
91828 if (len > *lenp) len = *lenp;
91829
91830- if (copy_to_user(buffer, devname, len))
91831+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91832 return -EFAULT;
91833
91834 *lenp = len;
91835diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91836index 3b9d5f2..d7015c6 100644
91837--- a/net/ieee802154/6lowpan.c
91838+++ b/net/ieee802154/6lowpan.c
91839@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91840 hc06_ptr += 3;
91841 } else {
91842 /* compress nothing */
91843- memcpy(hc06_ptr, &hdr, 4);
91844+ memcpy(hc06_ptr, hdr, 4);
91845 /* replace the top byte with new ECN | DSCP format */
91846 *hc06_ptr = tmp;
91847 hc06_ptr += 4;
91848diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91849index dd6b523..dfe558f 100644
91850--- a/net/ipv4/af_inet.c
91851+++ b/net/ipv4/af_inet.c
91852@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
91853
91854 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91855
91856- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91857- if (!sysctl_local_reserved_ports)
91858- goto out;
91859-
91860 rc = proto_register(&tcp_prot, 1);
91861 if (rc)
91862- goto out_free_reserved_ports;
91863+ goto out;
91864
91865 rc = proto_register(&udp_prot, 1);
91866 if (rc)
91867@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
91868 proto_unregister(&udp_prot);
91869 out_unregister_tcp_proto:
91870 proto_unregister(&tcp_prot);
91871-out_free_reserved_ports:
91872- kfree(sysctl_local_reserved_ports);
91873 goto out;
91874 }
91875
91876diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
91877index 34ca6d5..b6421e8 100644
91878--- a/net/ipv4/devinet.c
91879+++ b/net/ipv4/devinet.c
91880@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
91881 idx = 0;
91882 head = &net->dev_index_head[h];
91883 rcu_read_lock();
91884- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91885+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91886 net->dev_base_seq;
91887 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91888 if (idx < s_idx)
91889@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
91890 idx = 0;
91891 head = &net->dev_index_head[h];
91892 rcu_read_lock();
91893- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91894+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91895 net->dev_base_seq;
91896 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91897 if (idx < s_idx)
91898@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
91899 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
91900 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
91901
91902-static struct devinet_sysctl_table {
91903+static const struct devinet_sysctl_table {
91904 struct ctl_table_header *sysctl_header;
91905 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
91906 } devinet_sysctl = {
91907@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
91908 int err;
91909 struct ipv4_devconf *all, *dflt;
91910 #ifdef CONFIG_SYSCTL
91911- struct ctl_table *tbl = ctl_forward_entry;
91912+ ctl_table_no_const *tbl = NULL;
91913 struct ctl_table_header *forw_hdr;
91914 #endif
91915
91916@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
91917 goto err_alloc_dflt;
91918
91919 #ifdef CONFIG_SYSCTL
91920- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
91921+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
91922 if (tbl == NULL)
91923 goto err_alloc_ctl;
91924
91925@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
91926 goto err_reg_dflt;
91927
91928 err = -ENOMEM;
91929- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
91930+ if (!net_eq(net, &init_net))
91931+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
91932+ else
91933+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
91934 if (forw_hdr == NULL)
91935 goto err_reg_ctl;
91936 net->ipv4.forw_hdr = forw_hdr;
91937@@ -2240,8 +2243,7 @@ err_reg_ctl:
91938 err_reg_dflt:
91939 __devinet_sysctl_unregister(all);
91940 err_reg_all:
91941- if (tbl != ctl_forward_entry)
91942- kfree(tbl);
91943+ kfree(tbl);
91944 err_alloc_ctl:
91945 #endif
91946 if (dflt != &ipv4_devconf_dflt)
91947diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
91948index b3f627a..b0f3e99 100644
91949--- a/net/ipv4/fib_frontend.c
91950+++ b/net/ipv4/fib_frontend.c
91951@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
91952 #ifdef CONFIG_IP_ROUTE_MULTIPATH
91953 fib_sync_up(dev);
91954 #endif
91955- atomic_inc(&net->ipv4.dev_addr_genid);
91956+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91957 rt_cache_flush(dev_net(dev));
91958 break;
91959 case NETDEV_DOWN:
91960 fib_del_ifaddr(ifa, NULL);
91961- atomic_inc(&net->ipv4.dev_addr_genid);
91962+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91963 if (ifa->ifa_dev->ifa_list == NULL) {
91964 /* Last address was deleted from this interface.
91965 * Disable IP.
91966@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
91967 #ifdef CONFIG_IP_ROUTE_MULTIPATH
91968 fib_sync_up(dev);
91969 #endif
91970- atomic_inc(&net->ipv4.dev_addr_genid);
91971+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91972 rt_cache_flush(net);
91973 break;
91974 case NETDEV_DOWN:
91975diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
91976index d5dbca5..6251d5f 100644
91977--- a/net/ipv4/fib_semantics.c
91978+++ b/net/ipv4/fib_semantics.c
91979@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
91980 nh->nh_saddr = inet_select_addr(nh->nh_dev,
91981 nh->nh_gw,
91982 nh->nh_parent->fib_scope);
91983- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
91984+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
91985
91986 return nh->nh_saddr;
91987 }
91988diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
91989index 6acb541..9ea617d 100644
91990--- a/net/ipv4/inet_connection_sock.c
91991+++ b/net/ipv4/inet_connection_sock.c
91992@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
91993 .range = { 32768, 61000 },
91994 };
91995
91996-unsigned long *sysctl_local_reserved_ports;
91997+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
91998 EXPORT_SYMBOL(sysctl_local_reserved_ports);
91999
92000 void inet_get_local_port_range(int *low, int *high)
92001diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92002index 7bd8983..3abdcf6 100644
92003--- a/net/ipv4/inet_hashtables.c
92004+++ b/net/ipv4/inet_hashtables.c
92005@@ -18,12 +18,15 @@
92006 #include <linux/sched.h>
92007 #include <linux/slab.h>
92008 #include <linux/wait.h>
92009+#include <linux/security.h>
92010
92011 #include <net/inet_connection_sock.h>
92012 #include <net/inet_hashtables.h>
92013 #include <net/secure_seq.h>
92014 #include <net/ip.h>
92015
92016+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92017+
92018 /*
92019 * Allocate and initialize a new local port bind bucket.
92020 * The bindhash mutex for snum's hash chain must be held here.
92021@@ -554,6 +557,8 @@ ok:
92022 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92023 spin_unlock(&head->lock);
92024
92025+ gr_update_task_in_ip_table(current, inet_sk(sk));
92026+
92027 if (tw) {
92028 inet_twsk_deschedule(tw, death_row);
92029 while (twrefcnt) {
92030diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92031index 33d5537..da337a4 100644
92032--- a/net/ipv4/inetpeer.c
92033+++ b/net/ipv4/inetpeer.c
92034@@ -503,8 +503,8 @@ relookup:
92035 if (p) {
92036 p->daddr = *daddr;
92037 atomic_set(&p->refcnt, 1);
92038- atomic_set(&p->rid, 0);
92039- atomic_set(&p->ip_id_count,
92040+ atomic_set_unchecked(&p->rid, 0);
92041+ atomic_set_unchecked(&p->ip_id_count,
92042 (daddr->family == AF_INET) ?
92043 secure_ip_id(daddr->addr.a4) :
92044 secure_ipv6_id(daddr->addr.a6));
92045diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92046index b66910a..cfe416e 100644
92047--- a/net/ipv4/ip_fragment.c
92048+++ b/net/ipv4/ip_fragment.c
92049@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92050 return 0;
92051
92052 start = qp->rid;
92053- end = atomic_inc_return(&peer->rid);
92054+ end = atomic_inc_return_unchecked(&peer->rid);
92055 qp->rid = end;
92056
92057 rc = qp->q.fragments && (end - start) > max;
92058@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92059
92060 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92061 {
92062- struct ctl_table *table;
92063+ ctl_table_no_const *table = NULL;
92064 struct ctl_table_header *hdr;
92065
92066- table = ip4_frags_ns_ctl_table;
92067 if (!net_eq(net, &init_net)) {
92068- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92069+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92070 if (table == NULL)
92071 goto err_alloc;
92072
92073@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92074 /* Don't export sysctls to unprivileged users */
92075 if (net->user_ns != &init_user_ns)
92076 table[0].procname = NULL;
92077- }
92078+ hdr = register_net_sysctl(net, "net/ipv4", table);
92079+ } else
92080+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92081
92082- hdr = register_net_sysctl(net, "net/ipv4", table);
92083 if (hdr == NULL)
92084 goto err_reg;
92085
92086@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92087 return 0;
92088
92089 err_reg:
92090- if (!net_eq(net, &init_net))
92091- kfree(table);
92092+ kfree(table);
92093 err_alloc:
92094 return -ENOMEM;
92095 }
92096diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92097index 8d6939e..19d0a95 100644
92098--- a/net/ipv4/ip_gre.c
92099+++ b/net/ipv4/ip_gre.c
92100@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92101 module_param(log_ecn_error, bool, 0644);
92102 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92103
92104-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92105+static struct rtnl_link_ops ipgre_link_ops;
92106 static int ipgre_tunnel_init(struct net_device *dev);
92107
92108 static int ipgre_net_id __read_mostly;
92109@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92110 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92111 };
92112
92113-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92114+static struct rtnl_link_ops ipgre_link_ops = {
92115 .kind = "gre",
92116 .maxtype = IFLA_GRE_MAX,
92117 .policy = ipgre_policy,
92118@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92119 .fill_info = ipgre_fill_info,
92120 };
92121
92122-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92123+static struct rtnl_link_ops ipgre_tap_ops = {
92124 .kind = "gretap",
92125 .maxtype = IFLA_GRE_MAX,
92126 .policy = ipgre_policy,
92127diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92128index d9c4f11..02b82dbc 100644
92129--- a/net/ipv4/ip_sockglue.c
92130+++ b/net/ipv4/ip_sockglue.c
92131@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92132 len = min_t(unsigned int, len, opt->optlen);
92133 if (put_user(len, optlen))
92134 return -EFAULT;
92135- if (copy_to_user(optval, opt->__data, len))
92136+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92137+ copy_to_user(optval, opt->__data, len))
92138 return -EFAULT;
92139 return 0;
92140 }
92141@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92142 if (sk->sk_type != SOCK_STREAM)
92143 return -ENOPROTOOPT;
92144
92145- msg.msg_control = optval;
92146+ msg.msg_control = (void __force_kernel *)optval;
92147 msg.msg_controllen = len;
92148 msg.msg_flags = flags;
92149
92150diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92151index 17cc0ff..63856c4 100644
92152--- a/net/ipv4/ip_vti.c
92153+++ b/net/ipv4/ip_vti.c
92154@@ -47,7 +47,7 @@
92155 #define HASH_SIZE 16
92156 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92157
92158-static struct rtnl_link_ops vti_link_ops __read_mostly;
92159+static struct rtnl_link_ops vti_link_ops;
92160
92161 static int vti_net_id __read_mostly;
92162 struct vti_net {
92163@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92164 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92165 };
92166
92167-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92168+static struct rtnl_link_ops vti_link_ops = {
92169 .kind = "vti",
92170 .maxtype = IFLA_VTI_MAX,
92171 .policy = vti_policy,
92172diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92173index efa1138..20dbba0 100644
92174--- a/net/ipv4/ipconfig.c
92175+++ b/net/ipv4/ipconfig.c
92176@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92177
92178 mm_segment_t oldfs = get_fs();
92179 set_fs(get_ds());
92180- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92181+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92182 set_fs(oldfs);
92183 return res;
92184 }
92185@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92186
92187 mm_segment_t oldfs = get_fs();
92188 set_fs(get_ds());
92189- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92190+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92191 set_fs(oldfs);
92192 return res;
92193 }
92194@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92195
92196 mm_segment_t oldfs = get_fs();
92197 set_fs(get_ds());
92198- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92199+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92200 set_fs(oldfs);
92201 return res;
92202 }
92203diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92204index b3ac3c3..ec6bd95 100644
92205--- a/net/ipv4/ipip.c
92206+++ b/net/ipv4/ipip.c
92207@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92208 static int ipip_net_id __read_mostly;
92209
92210 static int ipip_tunnel_init(struct net_device *dev);
92211-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92212+static struct rtnl_link_ops ipip_link_ops;
92213
92214 static int ipip_err(struct sk_buff *skb, u32 info)
92215 {
92216@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92217 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92218 };
92219
92220-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92221+static struct rtnl_link_ops ipip_link_ops = {
92222 .kind = "ipip",
92223 .maxtype = IFLA_IPTUN_MAX,
92224 .policy = ipip_policy,
92225diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92226index 85a4f21..1beb1f5 100644
92227--- a/net/ipv4/netfilter/arp_tables.c
92228+++ b/net/ipv4/netfilter/arp_tables.c
92229@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92230 #endif
92231
92232 static int get_info(struct net *net, void __user *user,
92233- const int *len, int compat)
92234+ int len, int compat)
92235 {
92236 char name[XT_TABLE_MAXNAMELEN];
92237 struct xt_table *t;
92238 int ret;
92239
92240- if (*len != sizeof(struct arpt_getinfo)) {
92241- duprintf("length %u != %Zu\n", *len,
92242+ if (len != sizeof(struct arpt_getinfo)) {
92243+ duprintf("length %u != %Zu\n", len,
92244 sizeof(struct arpt_getinfo));
92245 return -EINVAL;
92246 }
92247@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92248 info.size = private->size;
92249 strcpy(info.name, name);
92250
92251- if (copy_to_user(user, &info, *len) != 0)
92252+ if (copy_to_user(user, &info, len) != 0)
92253 ret = -EFAULT;
92254 else
92255 ret = 0;
92256@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92257
92258 switch (cmd) {
92259 case ARPT_SO_GET_INFO:
92260- ret = get_info(sock_net(sk), user, len, 1);
92261+ ret = get_info(sock_net(sk), user, *len, 1);
92262 break;
92263 case ARPT_SO_GET_ENTRIES:
92264 ret = compat_get_entries(sock_net(sk), user, len);
92265@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92266
92267 switch (cmd) {
92268 case ARPT_SO_GET_INFO:
92269- ret = get_info(sock_net(sk), user, len, 0);
92270+ ret = get_info(sock_net(sk), user, *len, 0);
92271 break;
92272
92273 case ARPT_SO_GET_ENTRIES:
92274diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92275index d23118d..6ad7277 100644
92276--- a/net/ipv4/netfilter/ip_tables.c
92277+++ b/net/ipv4/netfilter/ip_tables.c
92278@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92279 #endif
92280
92281 static int get_info(struct net *net, void __user *user,
92282- const int *len, int compat)
92283+ int len, int compat)
92284 {
92285 char name[XT_TABLE_MAXNAMELEN];
92286 struct xt_table *t;
92287 int ret;
92288
92289- if (*len != sizeof(struct ipt_getinfo)) {
92290- duprintf("length %u != %zu\n", *len,
92291+ if (len != sizeof(struct ipt_getinfo)) {
92292+ duprintf("length %u != %zu\n", len,
92293 sizeof(struct ipt_getinfo));
92294 return -EINVAL;
92295 }
92296@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92297 info.size = private->size;
92298 strcpy(info.name, name);
92299
92300- if (copy_to_user(user, &info, *len) != 0)
92301+ if (copy_to_user(user, &info, len) != 0)
92302 ret = -EFAULT;
92303 else
92304 ret = 0;
92305@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92306
92307 switch (cmd) {
92308 case IPT_SO_GET_INFO:
92309- ret = get_info(sock_net(sk), user, len, 1);
92310+ ret = get_info(sock_net(sk), user, *len, 1);
92311 break;
92312 case IPT_SO_GET_ENTRIES:
92313 ret = compat_get_entries(sock_net(sk), user, len);
92314@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92315
92316 switch (cmd) {
92317 case IPT_SO_GET_INFO:
92318- ret = get_info(sock_net(sk), user, len, 0);
92319+ ret = get_info(sock_net(sk), user, *len, 0);
92320 break;
92321
92322 case IPT_SO_GET_ENTRIES:
92323diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92324index cbc2215..9cb993c 100644
92325--- a/net/ipv4/netfilter/ipt_ULOG.c
92326+++ b/net/ipv4/netfilter/ipt_ULOG.c
92327@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92328 ub->qlen++;
92329
92330 pm = nlmsg_data(nlh);
92331+ memset(pm, 0, sizeof(*pm));
92332
92333 /* We might not have a timestamp, get one */
92334 if (skb->tstamp.tv64 == 0)
92335@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92336 }
92337 else if (loginfo->prefix[0] != '\0')
92338 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92339- else
92340- *(pm->prefix) = '\0';
92341
92342 if (in && in->hard_header_len > 0 &&
92343 skb->mac_header != skb->network_header &&
92344@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92345
92346 if (in)
92347 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92348- else
92349- pm->indev_name[0] = '\0';
92350
92351 if (out)
92352 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92353- else
92354- pm->outdev_name[0] = '\0';
92355
92356 /* copy_len <= skb->len, so can't fail. */
92357 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92358diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92359index 746427c..80eab72 100644
92360--- a/net/ipv4/ping.c
92361+++ b/net/ipv4/ping.c
92362@@ -55,7 +55,7 @@
92363
92364
92365 struct ping_table ping_table;
92366-struct pingv6_ops pingv6_ops;
92367+struct pingv6_ops *pingv6_ops;
92368 EXPORT_SYMBOL_GPL(pingv6_ops);
92369
92370 static u16 ping_port_rover;
92371@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92372 return -ENODEV;
92373 }
92374 }
92375- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92376+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92377 scoped);
92378 rcu_read_unlock();
92379
92380@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92381 }
92382 #if IS_ENABLED(CONFIG_IPV6)
92383 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92384- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92385+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92386 #endif
92387 }
92388
92389@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92390 info, (u8 *)icmph);
92391 #if IS_ENABLED(CONFIG_IPV6)
92392 } else if (family == AF_INET6) {
92393- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92394+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92395 info, (u8 *)icmph);
92396 #endif
92397 }
92398@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92399 return ip_recv_error(sk, msg, len);
92400 #if IS_ENABLED(CONFIG_IPV6)
92401 } else if (family == AF_INET6) {
92402- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92403+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92404 #endif
92405 }
92406 }
92407@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92408 IP6CB(skb)->iif);
92409
92410 if (inet6_sk(sk)->rxopt.all)
92411- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92412+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92413 #endif
92414 } else {
92415 BUG();
92416@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92417 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92418 0, sock_i_ino(sp),
92419 atomic_read(&sp->sk_refcnt), sp,
92420- atomic_read(&sp->sk_drops), len);
92421+ atomic_read_unchecked(&sp->sk_drops), len);
92422 }
92423
92424 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92425diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92426index 6fb2337..9cd6b20 100644
92427--- a/net/ipv4/raw.c
92428+++ b/net/ipv4/raw.c
92429@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92430 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92431 {
92432 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92433- atomic_inc(&sk->sk_drops);
92434+ atomic_inc_unchecked(&sk->sk_drops);
92435 kfree_skb(skb);
92436 return NET_RX_DROP;
92437 }
92438@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92439
92440 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92441 {
92442+ struct icmp_filter filter;
92443+
92444 if (optlen > sizeof(struct icmp_filter))
92445 optlen = sizeof(struct icmp_filter);
92446- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92447+ if (copy_from_user(&filter, optval, optlen))
92448 return -EFAULT;
92449+ raw_sk(sk)->filter = filter;
92450 return 0;
92451 }
92452
92453 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92454 {
92455 int len, ret = -EFAULT;
92456+ struct icmp_filter filter;
92457
92458 if (get_user(len, optlen))
92459 goto out;
92460@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92461 if (len > sizeof(struct icmp_filter))
92462 len = sizeof(struct icmp_filter);
92463 ret = -EFAULT;
92464- if (put_user(len, optlen) ||
92465- copy_to_user(optval, &raw_sk(sk)->filter, len))
92466+ filter = raw_sk(sk)->filter;
92467+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92468 goto out;
92469 ret = 0;
92470 out: return ret;
92471@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92472 0, 0L, 0,
92473 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92474 0, sock_i_ino(sp),
92475- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92476+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92477 }
92478
92479 static int raw_seq_show(struct seq_file *seq, void *v)
92480diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92481index a9a54a2..647316e 100644
92482--- a/net/ipv4/route.c
92483+++ b/net/ipv4/route.c
92484@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92485 .maxlen = sizeof(int),
92486 .mode = 0200,
92487 .proc_handler = ipv4_sysctl_rtcache_flush,
92488+ .extra1 = &init_net,
92489 },
92490 { },
92491 };
92492
92493 static __net_init int sysctl_route_net_init(struct net *net)
92494 {
92495- struct ctl_table *tbl;
92496+ ctl_table_no_const *tbl = NULL;
92497
92498- tbl = ipv4_route_flush_table;
92499 if (!net_eq(net, &init_net)) {
92500- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92501+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92502 if (tbl == NULL)
92503 goto err_dup;
92504
92505 /* Don't export sysctls to unprivileged users */
92506 if (net->user_ns != &init_user_ns)
92507 tbl[0].procname = NULL;
92508- }
92509- tbl[0].extra1 = net;
92510+ tbl[0].extra1 = net;
92511+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92512+ } else
92513+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92514
92515- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92516 if (net->ipv4.route_hdr == NULL)
92517 goto err_reg;
92518 return 0;
92519
92520 err_reg:
92521- if (tbl != ipv4_route_flush_table)
92522- kfree(tbl);
92523+ kfree(tbl);
92524 err_dup:
92525 return -ENOMEM;
92526 }
92527@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92528
92529 static __net_init int rt_genid_init(struct net *net)
92530 {
92531- atomic_set(&net->rt_genid, 0);
92532- atomic_set(&net->fnhe_genid, 0);
92533+ atomic_set_unchecked(&net->rt_genid, 0);
92534+ atomic_set_unchecked(&net->fnhe_genid, 0);
92535 get_random_bytes(&net->ipv4.dev_addr_genid,
92536 sizeof(net->ipv4.dev_addr_genid));
92537 return 0;
92538diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92539index 610e324..fd42e75 100644
92540--- a/net/ipv4/sysctl_net_ipv4.c
92541+++ b/net/ipv4/sysctl_net_ipv4.c
92542@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92543 {
92544 int ret;
92545 int range[2];
92546- struct ctl_table tmp = {
92547+ ctl_table_no_const tmp = {
92548 .data = &range,
92549 .maxlen = sizeof(range),
92550 .mode = table->mode,
92551@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92552 int ret;
92553 gid_t urange[2];
92554 kgid_t low, high;
92555- struct ctl_table tmp = {
92556+ ctl_table_no_const tmp = {
92557 .data = &urange,
92558 .maxlen = sizeof(urange),
92559 .mode = table->mode,
92560@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92561 void __user *buffer, size_t *lenp, loff_t *ppos)
92562 {
92563 char val[TCP_CA_NAME_MAX];
92564- struct ctl_table tbl = {
92565+ ctl_table_no_const tbl = {
92566 .data = val,
92567 .maxlen = TCP_CA_NAME_MAX,
92568 };
92569@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92570 void __user *buffer, size_t *lenp,
92571 loff_t *ppos)
92572 {
92573- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92574+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92575 int ret;
92576
92577 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92578@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92579 void __user *buffer, size_t *lenp,
92580 loff_t *ppos)
92581 {
92582- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92583+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92584 int ret;
92585
92586 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92587@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92588 struct mem_cgroup *memcg;
92589 #endif
92590
92591- struct ctl_table tmp = {
92592+ ctl_table_no_const tmp = {
92593 .data = &vec,
92594 .maxlen = sizeof(vec),
92595 .mode = ctl->mode,
92596 };
92597
92598 if (!write) {
92599- ctl->data = &net->ipv4.sysctl_tcp_mem;
92600- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92601+ ctl_table_no_const tcp_mem = *ctl;
92602+
92603+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92604+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92605 }
92606
92607 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92608@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92609 void __user *buffer, size_t *lenp,
92610 loff_t *ppos)
92611 {
92612- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92613+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92614 struct tcp_fastopen_context *ctxt;
92615 int ret;
92616 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92617@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92618 },
92619 {
92620 .procname = "ip_local_reserved_ports",
92621- .data = NULL, /* initialized in sysctl_ipv4_init */
92622+ .data = sysctl_local_reserved_ports,
92623 .maxlen = 65536,
92624 .mode = 0644,
92625 .proc_handler = proc_do_large_bitmap,
92626@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92627
92628 static __net_init int ipv4_sysctl_init_net(struct net *net)
92629 {
92630- struct ctl_table *table;
92631+ ctl_table_no_const *table = NULL;
92632
92633- table = ipv4_net_table;
92634 if (!net_eq(net, &init_net)) {
92635- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92636+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92637 if (table == NULL)
92638 goto err_alloc;
92639
92640@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92641
92642 tcp_init_mem(net);
92643
92644- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92645+ if (!net_eq(net, &init_net))
92646+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92647+ else
92648+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92649 if (net->ipv4.ipv4_hdr == NULL)
92650 goto err_reg;
92651
92652 return 0;
92653
92654 err_reg:
92655- if (!net_eq(net, &init_net))
92656- kfree(table);
92657+ kfree(table);
92658 err_alloc:
92659 return -ENOMEM;
92660 }
92661@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92662 static __init int sysctl_ipv4_init(void)
92663 {
92664 struct ctl_table_header *hdr;
92665- struct ctl_table *i;
92666-
92667- for (i = ipv4_table; i->procname; i++) {
92668- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92669- i->data = sysctl_local_reserved_ports;
92670- break;
92671- }
92672- }
92673- if (!i->procname)
92674- return -EINVAL;
92675
92676 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92677 if (hdr == NULL)
92678diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92679index 3ca2139..c4cc060 100644
92680--- a/net/ipv4/tcp_input.c
92681+++ b/net/ipv4/tcp_input.c
92682@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92683 * simplifies code)
92684 */
92685 static void
92686-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92687+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92688 struct sk_buff *head, struct sk_buff *tail,
92689 u32 start, u32 end)
92690 {
92691@@ -5465,6 +5465,7 @@ discard:
92692 tcp_paws_reject(&tp->rx_opt, 0))
92693 goto discard_and_undo;
92694
92695+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92696 if (th->syn) {
92697 /* We see SYN without ACK. It is attempt of
92698 * simultaneous connect with crossed SYNs.
92699@@ -5515,6 +5516,7 @@ discard:
92700 goto discard;
92701 #endif
92702 }
92703+#endif
92704 /* "fifth, if neither of the SYN or RST bits is set then
92705 * drop the segment and return."
92706 */
92707@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92708 goto discard;
92709
92710 if (th->syn) {
92711- if (th->fin)
92712+ if (th->fin || th->urg || th->psh)
92713 goto discard;
92714 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92715 return 1;
92716diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92717index b299da5..097db06 100644
92718--- a/net/ipv4/tcp_ipv4.c
92719+++ b/net/ipv4/tcp_ipv4.c
92720@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92721 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92722
92723
92724+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92725+extern int grsec_enable_blackhole;
92726+#endif
92727+
92728 #ifdef CONFIG_TCP_MD5SIG
92729 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92730 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92731@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92732 return 0;
92733
92734 reset:
92735+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92736+ if (!grsec_enable_blackhole)
92737+#endif
92738 tcp_v4_send_reset(rsk, skb);
92739 discard:
92740 kfree_skb(skb);
92741@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92742 TCP_SKB_CB(skb)->sacked = 0;
92743
92744 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92745- if (!sk)
92746+ if (!sk) {
92747+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92748+ ret = 1;
92749+#endif
92750 goto no_tcp_socket;
92751-
92752+ }
92753 process:
92754- if (sk->sk_state == TCP_TIME_WAIT)
92755+ if (sk->sk_state == TCP_TIME_WAIT) {
92756+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92757+ ret = 2;
92758+#endif
92759 goto do_time_wait;
92760+ }
92761
92762 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92763 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92764@@ -2034,6 +2048,10 @@ csum_error:
92765 bad_packet:
92766 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92767 } else {
92768+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92769+ if (!grsec_enable_blackhole || (ret == 1 &&
92770+ (skb->dev->flags & IFF_LOOPBACK)))
92771+#endif
92772 tcp_v4_send_reset(NULL, skb);
92773 }
92774
92775diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92776index ab1c086..2a8d76b 100644
92777--- a/net/ipv4/tcp_minisocks.c
92778+++ b/net/ipv4/tcp_minisocks.c
92779@@ -27,6 +27,10 @@
92780 #include <net/inet_common.h>
92781 #include <net/xfrm.h>
92782
92783+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92784+extern int grsec_enable_blackhole;
92785+#endif
92786+
92787 int sysctl_tcp_syncookies __read_mostly = 1;
92788 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92789
92790@@ -715,7 +719,10 @@ embryonic_reset:
92791 * avoid becoming vulnerable to outside attack aiming at
92792 * resetting legit local connections.
92793 */
92794- req->rsk_ops->send_reset(sk, skb);
92795+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92796+ if (!grsec_enable_blackhole)
92797+#endif
92798+ req->rsk_ops->send_reset(sk, skb);
92799 } else if (fastopen) { /* received a valid RST pkt */
92800 reqsk_fastopen_remove(sk, req, true);
92801 tcp_reset(sk);
92802diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92803index d4943f6..e7a74a5 100644
92804--- a/net/ipv4/tcp_probe.c
92805+++ b/net/ipv4/tcp_probe.c
92806@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92807 if (cnt + width >= len)
92808 break;
92809
92810- if (copy_to_user(buf + cnt, tbuf, width))
92811+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92812 return -EFAULT;
92813 cnt += width;
92814 }
92815diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92816index 4b85e6f..22f9ac9 100644
92817--- a/net/ipv4/tcp_timer.c
92818+++ b/net/ipv4/tcp_timer.c
92819@@ -22,6 +22,10 @@
92820 #include <linux/gfp.h>
92821 #include <net/tcp.h>
92822
92823+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92824+extern int grsec_lastack_retries;
92825+#endif
92826+
92827 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92828 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92829 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92830@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92831 }
92832 }
92833
92834+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92835+ if ((sk->sk_state == TCP_LAST_ACK) &&
92836+ (grsec_lastack_retries > 0) &&
92837+ (grsec_lastack_retries < retry_until))
92838+ retry_until = grsec_lastack_retries;
92839+#endif
92840+
92841 if (retransmits_timed_out(sk, retry_until,
92842 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92843 /* Has it gone just too far? */
92844diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92845index 766e6ba..aff2f8d 100644
92846--- a/net/ipv4/udp.c
92847+++ b/net/ipv4/udp.c
92848@@ -87,6 +87,7 @@
92849 #include <linux/types.h>
92850 #include <linux/fcntl.h>
92851 #include <linux/module.h>
92852+#include <linux/security.h>
92853 #include <linux/socket.h>
92854 #include <linux/sockios.h>
92855 #include <linux/igmp.h>
92856@@ -112,6 +113,10 @@
92857 #include <net/busy_poll.h>
92858 #include "udp_impl.h"
92859
92860+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92861+extern int grsec_enable_blackhole;
92862+#endif
92863+
92864 struct udp_table udp_table __read_mostly;
92865 EXPORT_SYMBOL(udp_table);
92866
92867@@ -595,6 +600,9 @@ found:
92868 return s;
92869 }
92870
92871+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92872+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92873+
92874 /*
92875 * This routine is called by the ICMP module when it gets some
92876 * sort of error condition. If err < 0 then the socket should
92877@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92878 dport = usin->sin_port;
92879 if (dport == 0)
92880 return -EINVAL;
92881+
92882+ err = gr_search_udp_sendmsg(sk, usin);
92883+ if (err)
92884+ return err;
92885 } else {
92886 if (sk->sk_state != TCP_ESTABLISHED)
92887 return -EDESTADDRREQ;
92888+
92889+ err = gr_search_udp_sendmsg(sk, NULL);
92890+ if (err)
92891+ return err;
92892+
92893 daddr = inet->inet_daddr;
92894 dport = inet->inet_dport;
92895 /* Open fast path for connected socket.
92896@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
92897 IS_UDPLITE(sk));
92898 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92899 IS_UDPLITE(sk));
92900- atomic_inc(&sk->sk_drops);
92901+ atomic_inc_unchecked(&sk->sk_drops);
92902 __skb_unlink(skb, rcvq);
92903 __skb_queue_tail(&list_kill, skb);
92904 }
92905@@ -1223,6 +1240,10 @@ try_again:
92906 if (!skb)
92907 goto out;
92908
92909+ err = gr_search_udp_recvmsg(sk, skb);
92910+ if (err)
92911+ goto out_free;
92912+
92913 ulen = skb->len - sizeof(struct udphdr);
92914 copied = len;
92915 if (copied > ulen)
92916@@ -1256,7 +1277,7 @@ try_again:
92917 if (unlikely(err)) {
92918 trace_kfree_skb(skb, udp_recvmsg);
92919 if (!peeked) {
92920- atomic_inc(&sk->sk_drops);
92921+ atomic_inc_unchecked(&sk->sk_drops);
92922 UDP_INC_STATS_USER(sock_net(sk),
92923 UDP_MIB_INERRORS, is_udplite);
92924 }
92925@@ -1543,7 +1564,7 @@ csum_error:
92926 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
92927 drop:
92928 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
92929- atomic_inc(&sk->sk_drops);
92930+ atomic_inc_unchecked(&sk->sk_drops);
92931 kfree_skb(skb);
92932 return -1;
92933 }
92934@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
92935 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
92936
92937 if (!skb1) {
92938- atomic_inc(&sk->sk_drops);
92939+ atomic_inc_unchecked(&sk->sk_drops);
92940 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
92941 IS_UDPLITE(sk));
92942 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92943@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
92944 goto csum_error;
92945
92946 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
92947+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92948+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
92949+#endif
92950 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
92951
92952 /*
92953@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
92954 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92955 0, sock_i_ino(sp),
92956 atomic_read(&sp->sk_refcnt), sp,
92957- atomic_read(&sp->sk_drops), len);
92958+ atomic_read_unchecked(&sp->sk_drops), len);
92959 }
92960
92961 int udp4_seq_show(struct seq_file *seq, void *v)
92962diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
92963index 9a459be..c7bc04c 100644
92964--- a/net/ipv4/xfrm4_policy.c
92965+++ b/net/ipv4/xfrm4_policy.c
92966@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
92967 fl4->flowi4_tos = iph->tos;
92968 }
92969
92970-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
92971+static int xfrm4_garbage_collect(struct dst_ops *ops)
92972 {
92973 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
92974
92975- xfrm4_policy_afinfo.garbage_collect(net);
92976+ xfrm_garbage_collect_deferred(net);
92977 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
92978 }
92979
92980@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
92981
92982 static int __net_init xfrm4_net_init(struct net *net)
92983 {
92984- struct ctl_table *table;
92985+ ctl_table_no_const *table = NULL;
92986 struct ctl_table_header *hdr;
92987
92988- table = xfrm4_policy_table;
92989 if (!net_eq(net, &init_net)) {
92990- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
92991+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
92992 if (!table)
92993 goto err_alloc;
92994
92995 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
92996- }
92997-
92998- hdr = register_net_sysctl(net, "net/ipv4", table);
92999+ hdr = register_net_sysctl(net, "net/ipv4", table);
93000+ } else
93001+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93002 if (!hdr)
93003 goto err_reg;
93004
93005@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93006 return 0;
93007
93008 err_reg:
93009- if (!net_eq(net, &init_net))
93010- kfree(table);
93011+ kfree(table);
93012 err_alloc:
93013 return -ENOMEM;
93014 }
93015diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93016index 0f99f7b..9375cf5 100644
93017--- a/net/ipv6/addrconf.c
93018+++ b/net/ipv6/addrconf.c
93019@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93020 idx = 0;
93021 head = &net->dev_index_head[h];
93022 rcu_read_lock();
93023- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93024+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93025 net->dev_base_seq;
93026 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93027 if (idx < s_idx)
93028@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93029 p.iph.ihl = 5;
93030 p.iph.protocol = IPPROTO_IPV6;
93031 p.iph.ttl = 64;
93032- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93033+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93034
93035 if (ops->ndo_do_ioctl) {
93036 mm_segment_t oldfs = get_fs();
93037@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93038 s_ip_idx = ip_idx = cb->args[2];
93039
93040 rcu_read_lock();
93041- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93042+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93043 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93044 idx = 0;
93045 head = &net->dev_index_head[h];
93046@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93047 dst_free(&ifp->rt->dst);
93048 break;
93049 }
93050- atomic_inc(&net->ipv6.dev_addr_genid);
93051+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93052 }
93053
93054 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93055@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93056 int *valp = ctl->data;
93057 int val = *valp;
93058 loff_t pos = *ppos;
93059- struct ctl_table lctl;
93060+ ctl_table_no_const lctl;
93061 int ret;
93062
93063 /*
93064@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93065 int *valp = ctl->data;
93066 int val = *valp;
93067 loff_t pos = *ppos;
93068- struct ctl_table lctl;
93069+ ctl_table_no_const lctl;
93070 int ret;
93071
93072 /*
93073diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93074index 197e6f4..16d8396 100644
93075--- a/net/ipv6/datagram.c
93076+++ b/net/ipv6/datagram.c
93077@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93078 0,
93079 sock_i_ino(sp),
93080 atomic_read(&sp->sk_refcnt), sp,
93081- atomic_read(&sp->sk_drops));
93082+ atomic_read_unchecked(&sp->sk_drops));
93083 }
93084diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93085index 7cfc8d2..c5394b6 100644
93086--- a/net/ipv6/icmp.c
93087+++ b/net/ipv6/icmp.c
93088@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93089
93090 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93091 {
93092- struct ctl_table *table;
93093+ ctl_table_no_const *table;
93094
93095 table = kmemdup(ipv6_icmp_table_template,
93096 sizeof(ipv6_icmp_table_template),
93097diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93098index 8bc717b..76fbb5d 100644
93099--- a/net/ipv6/ip6_gre.c
93100+++ b/net/ipv6/ip6_gre.c
93101@@ -74,7 +74,7 @@ struct ip6gre_net {
93102 struct net_device *fb_tunnel_dev;
93103 };
93104
93105-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93106+static struct rtnl_link_ops ip6gre_link_ops;
93107 static int ip6gre_tunnel_init(struct net_device *dev);
93108 static void ip6gre_tunnel_setup(struct net_device *dev);
93109 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93110@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93111 }
93112
93113
93114-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93115+static struct inet6_protocol ip6gre_protocol = {
93116 .handler = ip6gre_rcv,
93117 .err_handler = ip6gre_err,
93118 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93119@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93120 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93121 };
93122
93123-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93124+static struct rtnl_link_ops ip6gre_link_ops = {
93125 .kind = "ip6gre",
93126 .maxtype = IFLA_GRE_MAX,
93127 .policy = ip6gre_policy,
93128@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93129 .fill_info = ip6gre_fill_info,
93130 };
93131
93132-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93133+static struct rtnl_link_ops ip6gre_tap_ops = {
93134 .kind = "ip6gretap",
93135 .maxtype = IFLA_GRE_MAX,
93136 .policy = ip6gre_policy,
93137diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93138index cf5d490..30946f0 100644
93139--- a/net/ipv6/ip6_tunnel.c
93140+++ b/net/ipv6/ip6_tunnel.c
93141@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93142
93143 static int ip6_tnl_dev_init(struct net_device *dev);
93144 static void ip6_tnl_dev_setup(struct net_device *dev);
93145-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93146+static struct rtnl_link_ops ip6_link_ops;
93147
93148 static int ip6_tnl_net_id __read_mostly;
93149 struct ip6_tnl_net {
93150@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93151 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93152 };
93153
93154-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93155+static struct rtnl_link_ops ip6_link_ops = {
93156 .kind = "ip6tnl",
93157 .maxtype = IFLA_IPTUN_MAX,
93158 .policy = ip6_tnl_policy,
93159diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93160index d1e2e8e..51c19ae 100644
93161--- a/net/ipv6/ipv6_sockglue.c
93162+++ b/net/ipv6/ipv6_sockglue.c
93163@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93164 if (sk->sk_type != SOCK_STREAM)
93165 return -ENOPROTOOPT;
93166
93167- msg.msg_control = optval;
93168+ msg.msg_control = (void __force_kernel *)optval;
93169 msg.msg_controllen = len;
93170 msg.msg_flags = flags;
93171
93172diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93173index 44400c2..8e11f52 100644
93174--- a/net/ipv6/netfilter/ip6_tables.c
93175+++ b/net/ipv6/netfilter/ip6_tables.c
93176@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93177 #endif
93178
93179 static int get_info(struct net *net, void __user *user,
93180- const int *len, int compat)
93181+ int len, int compat)
93182 {
93183 char name[XT_TABLE_MAXNAMELEN];
93184 struct xt_table *t;
93185 int ret;
93186
93187- if (*len != sizeof(struct ip6t_getinfo)) {
93188- duprintf("length %u != %zu\n", *len,
93189+ if (len != sizeof(struct ip6t_getinfo)) {
93190+ duprintf("length %u != %zu\n", len,
93191 sizeof(struct ip6t_getinfo));
93192 return -EINVAL;
93193 }
93194@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93195 info.size = private->size;
93196 strcpy(info.name, name);
93197
93198- if (copy_to_user(user, &info, *len) != 0)
93199+ if (copy_to_user(user, &info, len) != 0)
93200 ret = -EFAULT;
93201 else
93202 ret = 0;
93203@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93204
93205 switch (cmd) {
93206 case IP6T_SO_GET_INFO:
93207- ret = get_info(sock_net(sk), user, len, 1);
93208+ ret = get_info(sock_net(sk), user, *len, 1);
93209 break;
93210 case IP6T_SO_GET_ENTRIES:
93211 ret = compat_get_entries(sock_net(sk), user, len);
93212@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93213
93214 switch (cmd) {
93215 case IP6T_SO_GET_INFO:
93216- ret = get_info(sock_net(sk), user, len, 0);
93217+ ret = get_info(sock_net(sk), user, *len, 0);
93218 break;
93219
93220 case IP6T_SO_GET_ENTRIES:
93221diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93222index dffdc1a..ccc6678 100644
93223--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93224+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93225@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93226
93227 static int nf_ct_frag6_sysctl_register(struct net *net)
93228 {
93229- struct ctl_table *table;
93230+ ctl_table_no_const *table = NULL;
93231 struct ctl_table_header *hdr;
93232
93233- table = nf_ct_frag6_sysctl_table;
93234 if (!net_eq(net, &init_net)) {
93235- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93236+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93237 GFP_KERNEL);
93238 if (table == NULL)
93239 goto err_alloc;
93240@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93241 table[0].data = &net->nf_frag.frags.timeout;
93242 table[1].data = &net->nf_frag.frags.low_thresh;
93243 table[2].data = &net->nf_frag.frags.high_thresh;
93244- }
93245-
93246- hdr = register_net_sysctl(net, "net/netfilter", table);
93247+ hdr = register_net_sysctl(net, "net/netfilter", table);
93248+ } else
93249+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93250 if (hdr == NULL)
93251 goto err_reg;
93252
93253@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93254 return 0;
93255
93256 err_reg:
93257- if (!net_eq(net, &init_net))
93258- kfree(table);
93259+ kfree(table);
93260 err_alloc:
93261 return -ENOMEM;
93262 }
93263diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93264index ab92a36..bb4a528 100644
93265--- a/net/ipv6/output_core.c
93266+++ b/net/ipv6/output_core.c
93267@@ -8,8 +8,8 @@
93268
93269 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93270 {
93271- static atomic_t ipv6_fragmentation_id;
93272- int old, new;
93273+ static atomic_unchecked_t ipv6_fragmentation_id;
93274+ int id;
93275
93276 #if IS_ENABLED(CONFIG_IPV6)
93277 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93278@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93279 }
93280 }
93281 #endif
93282- do {
93283- old = atomic_read(&ipv6_fragmentation_id);
93284- new = old + 1;
93285- if (!new)
93286- new = 1;
93287- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93288- fhdr->identification = htonl(new);
93289+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93290+ if (!id)
93291+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93292+ fhdr->identification = htonl(id);
93293 }
93294 EXPORT_SYMBOL(ipv6_select_ident);
93295
93296diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93297index 18f19df..b46ada1 100644
93298--- a/net/ipv6/ping.c
93299+++ b/net/ipv6/ping.c
93300@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93301 };
93302 #endif
93303
93304+static struct pingv6_ops real_pingv6_ops = {
93305+ .ipv6_recv_error = ipv6_recv_error,
93306+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93307+ .icmpv6_err_convert = icmpv6_err_convert,
93308+ .ipv6_icmp_error = ipv6_icmp_error,
93309+ .ipv6_chk_addr = ipv6_chk_addr,
93310+};
93311+
93312+static struct pingv6_ops dummy_pingv6_ops = {
93313+ .ipv6_recv_error = dummy_ipv6_recv_error,
93314+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93315+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93316+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93317+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93318+};
93319+
93320 int __init pingv6_init(void)
93321 {
93322 #ifdef CONFIG_PROC_FS
93323@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93324 if (ret)
93325 return ret;
93326 #endif
93327- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93328- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93329- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93330- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93331- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93332+ pingv6_ops = &real_pingv6_ops;
93333 return inet6_register_protosw(&pingv6_protosw);
93334 }
93335
93336@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93337 */
93338 void pingv6_exit(void)
93339 {
93340- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93341- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93342- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93343- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93344- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93345+ pingv6_ops = &dummy_pingv6_ops;
93346 #ifdef CONFIG_PROC_FS
93347 unregister_pernet_subsys(&ping_v6_net_ops);
93348 #endif
93349diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93350index cdaed47..515edde9 100644
93351--- a/net/ipv6/raw.c
93352+++ b/net/ipv6/raw.c
93353@@ -108,7 +108,7 @@ found:
93354 */
93355 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93356 {
93357- struct icmp6hdr *_hdr;
93358+ struct icmp6hdr _hdr;
93359 const struct icmp6hdr *hdr;
93360
93361 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93362@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93363 {
93364 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93365 skb_checksum_complete(skb)) {
93366- atomic_inc(&sk->sk_drops);
93367+ atomic_inc_unchecked(&sk->sk_drops);
93368 kfree_skb(skb);
93369 return NET_RX_DROP;
93370 }
93371@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93372 struct raw6_sock *rp = raw6_sk(sk);
93373
93374 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93375- atomic_inc(&sk->sk_drops);
93376+ atomic_inc_unchecked(&sk->sk_drops);
93377 kfree_skb(skb);
93378 return NET_RX_DROP;
93379 }
93380@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93381
93382 if (inet->hdrincl) {
93383 if (skb_checksum_complete(skb)) {
93384- atomic_inc(&sk->sk_drops);
93385+ atomic_inc_unchecked(&sk->sk_drops);
93386 kfree_skb(skb);
93387 return NET_RX_DROP;
93388 }
93389@@ -602,7 +602,7 @@ out:
93390 return err;
93391 }
93392
93393-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93394+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93395 struct flowi6 *fl6, struct dst_entry **dstp,
93396 unsigned int flags)
93397 {
93398@@ -915,12 +915,15 @@ do_confirm:
93399 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93400 char __user *optval, int optlen)
93401 {
93402+ struct icmp6_filter filter;
93403+
93404 switch (optname) {
93405 case ICMPV6_FILTER:
93406 if (optlen > sizeof(struct icmp6_filter))
93407 optlen = sizeof(struct icmp6_filter);
93408- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93409+ if (copy_from_user(&filter, optval, optlen))
93410 return -EFAULT;
93411+ raw6_sk(sk)->filter = filter;
93412 return 0;
93413 default:
93414 return -ENOPROTOOPT;
93415@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93416 char __user *optval, int __user *optlen)
93417 {
93418 int len;
93419+ struct icmp6_filter filter;
93420
93421 switch (optname) {
93422 case ICMPV6_FILTER:
93423@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93424 len = sizeof(struct icmp6_filter);
93425 if (put_user(len, optlen))
93426 return -EFAULT;
93427- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93428+ filter = raw6_sk(sk)->filter;
93429+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93430 return -EFAULT;
93431 return 0;
93432 default:
93433diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93434index 1aeb473..bea761c 100644
93435--- a/net/ipv6/reassembly.c
93436+++ b/net/ipv6/reassembly.c
93437@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93438
93439 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93440 {
93441- struct ctl_table *table;
93442+ ctl_table_no_const *table = NULL;
93443 struct ctl_table_header *hdr;
93444
93445- table = ip6_frags_ns_ctl_table;
93446 if (!net_eq(net, &init_net)) {
93447- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93448+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93449 if (table == NULL)
93450 goto err_alloc;
93451
93452@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93453 /* Don't export sysctls to unprivileged users */
93454 if (net->user_ns != &init_user_ns)
93455 table[0].procname = NULL;
93456- }
93457+ hdr = register_net_sysctl(net, "net/ipv6", table);
93458+ } else
93459+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93460
93461- hdr = register_net_sysctl(net, "net/ipv6", table);
93462 if (hdr == NULL)
93463 goto err_reg;
93464
93465@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93466 return 0;
93467
93468 err_reg:
93469- if (!net_eq(net, &init_net))
93470- kfree(table);
93471+ kfree(table);
93472 err_alloc:
93473 return -ENOMEM;
93474 }
93475diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93476index 8d9a93ed..cd89616 100644
93477--- a/net/ipv6/route.c
93478+++ b/net/ipv6/route.c
93479@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93480
93481 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93482 {
93483- struct ctl_table *table;
93484+ ctl_table_no_const *table;
93485
93486 table = kmemdup(ipv6_route_table_template,
93487 sizeof(ipv6_route_table_template),
93488diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93489index 86f639b..71e355e 100644
93490--- a/net/ipv6/sit.c
93491+++ b/net/ipv6/sit.c
93492@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93493 static void ipip6_dev_free(struct net_device *dev);
93494 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93495 __be32 *v4dst);
93496-static struct rtnl_link_ops sit_link_ops __read_mostly;
93497+static struct rtnl_link_ops sit_link_ops;
93498
93499 static int sit_net_id __read_mostly;
93500 struct sit_net {
93501@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93502 #endif
93503 };
93504
93505-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93506+static struct rtnl_link_ops sit_link_ops = {
93507 .kind = "sit",
93508 .maxtype = IFLA_IPTUN_MAX,
93509 .policy = ipip6_policy,
93510diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93511index 107b2f1..72741a9 100644
93512--- a/net/ipv6/sysctl_net_ipv6.c
93513+++ b/net/ipv6/sysctl_net_ipv6.c
93514@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93515
93516 static int __net_init ipv6_sysctl_net_init(struct net *net)
93517 {
93518- struct ctl_table *ipv6_table;
93519+ ctl_table_no_const *ipv6_table;
93520 struct ctl_table *ipv6_route_table;
93521 struct ctl_table *ipv6_icmp_table;
93522 int err;
93523diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93524index 6e1649d..75ddb4c 100644
93525--- a/net/ipv6/tcp_ipv6.c
93526+++ b/net/ipv6/tcp_ipv6.c
93527@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93528 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93529 }
93530
93531+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93532+extern int grsec_enable_blackhole;
93533+#endif
93534+
93535 static void tcp_v6_hash(struct sock *sk)
93536 {
93537 if (sk->sk_state != TCP_CLOSE) {
93538@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93539 return 0;
93540
93541 reset:
93542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93543+ if (!grsec_enable_blackhole)
93544+#endif
93545 tcp_v6_send_reset(sk, skb);
93546 discard:
93547 if (opt_skb)
93548@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93549 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93550 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93551 if (np->rxopt.bits.rxtclass)
93552- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93553+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93554 if (ipv6_opt_accepted(sk, opt_skb)) {
93555 skb_set_owner_r(opt_skb, sk);
93556 opt_skb = xchg(&np->pktoptions, opt_skb);
93557@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93558 TCP_SKB_CB(skb)->sacked = 0;
93559
93560 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93561- if (!sk)
93562+ if (!sk) {
93563+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93564+ ret = 1;
93565+#endif
93566 goto no_tcp_socket;
93567+ }
93568
93569 process:
93570- if (sk->sk_state == TCP_TIME_WAIT)
93571+ if (sk->sk_state == TCP_TIME_WAIT) {
93572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93573+ ret = 2;
93574+#endif
93575 goto do_time_wait;
93576+ }
93577
93578 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93579 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93580@@ -1538,6 +1553,10 @@ csum_error:
93581 bad_packet:
93582 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93583 } else {
93584+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93585+ if (!grsec_enable_blackhole || (ret == 1 &&
93586+ (skb->dev->flags & IFF_LOOPBACK)))
93587+#endif
93588 tcp_v6_send_reset(NULL, skb);
93589 }
93590
93591diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93592index f405815..45a68a6 100644
93593--- a/net/ipv6/udp.c
93594+++ b/net/ipv6/udp.c
93595@@ -53,6 +53,10 @@
93596 #include <trace/events/skb.h>
93597 #include "udp_impl.h"
93598
93599+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93600+extern int grsec_enable_blackhole;
93601+#endif
93602+
93603 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93604 {
93605 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93606@@ -420,7 +424,7 @@ try_again:
93607 if (unlikely(err)) {
93608 trace_kfree_skb(skb, udpv6_recvmsg);
93609 if (!peeked) {
93610- atomic_inc(&sk->sk_drops);
93611+ atomic_inc_unchecked(&sk->sk_drops);
93612 if (is_udp4)
93613 UDP_INC_STATS_USER(sock_net(sk),
93614 UDP_MIB_INERRORS,
93615@@ -666,7 +670,7 @@ csum_error:
93616 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93617 drop:
93618 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93619- atomic_inc(&sk->sk_drops);
93620+ atomic_inc_unchecked(&sk->sk_drops);
93621 kfree_skb(skb);
93622 return -1;
93623 }
93624@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93625 if (likely(skb1 == NULL))
93626 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93627 if (!skb1) {
93628- atomic_inc(&sk->sk_drops);
93629+ atomic_inc_unchecked(&sk->sk_drops);
93630 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93631 IS_UDPLITE(sk));
93632 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93633@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93634 goto csum_error;
93635
93636 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93637+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93638+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93639+#endif
93640 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93641
93642 kfree_skb(skb);
93643diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93644index 23ed03d..6532e67 100644
93645--- a/net/ipv6/xfrm6_policy.c
93646+++ b/net/ipv6/xfrm6_policy.c
93647@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93648 }
93649 }
93650
93651-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93652+static int xfrm6_garbage_collect(struct dst_ops *ops)
93653 {
93654 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93655
93656- xfrm6_policy_afinfo.garbage_collect(net);
93657+ xfrm_garbage_collect_deferred(net);
93658 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93659 }
93660
93661@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93662
93663 static int __net_init xfrm6_net_init(struct net *net)
93664 {
93665- struct ctl_table *table;
93666+ ctl_table_no_const *table = NULL;
93667 struct ctl_table_header *hdr;
93668
93669- table = xfrm6_policy_table;
93670 if (!net_eq(net, &init_net)) {
93671- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93672+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93673 if (!table)
93674 goto err_alloc;
93675
93676 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93677- }
93678+ hdr = register_net_sysctl(net, "net/ipv6", table);
93679+ } else
93680+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93681
93682- hdr = register_net_sysctl(net, "net/ipv6", table);
93683 if (!hdr)
93684 goto err_reg;
93685
93686@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93687 return 0;
93688
93689 err_reg:
93690- if (!net_eq(net, &init_net))
93691- kfree(table);
93692+ kfree(table);
93693 err_alloc:
93694 return -ENOMEM;
93695 }
93696diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93697index 41ac7938..75e3bb1 100644
93698--- a/net/irda/ircomm/ircomm_tty.c
93699+++ b/net/irda/ircomm/ircomm_tty.c
93700@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93701 add_wait_queue(&port->open_wait, &wait);
93702
93703 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93704- __FILE__, __LINE__, tty->driver->name, port->count);
93705+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93706
93707 spin_lock_irqsave(&port->lock, flags);
93708 if (!tty_hung_up_p(filp))
93709- port->count--;
93710+ atomic_dec(&port->count);
93711 port->blocked_open++;
93712 spin_unlock_irqrestore(&port->lock, flags);
93713
93714@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93715 }
93716
93717 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93718- __FILE__, __LINE__, tty->driver->name, port->count);
93719+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93720
93721 schedule();
93722 }
93723@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93724
93725 spin_lock_irqsave(&port->lock, flags);
93726 if (!tty_hung_up_p(filp))
93727- port->count++;
93728+ atomic_inc(&port->count);
93729 port->blocked_open--;
93730 spin_unlock_irqrestore(&port->lock, flags);
93731
93732 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93733- __FILE__, __LINE__, tty->driver->name, port->count);
93734+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93735
93736 if (!retval)
93737 port->flags |= ASYNC_NORMAL_ACTIVE;
93738@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93739
93740 /* ++ is not atomic, so this should be protected - Jean II */
93741 spin_lock_irqsave(&self->port.lock, flags);
93742- self->port.count++;
93743+ atomic_inc(&self->port.count);
93744 spin_unlock_irqrestore(&self->port.lock, flags);
93745 tty_port_tty_set(&self->port, tty);
93746
93747 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93748- self->line, self->port.count);
93749+ self->line, atomic_read(&self->port.count));
93750
93751 /* Not really used by us, but lets do it anyway */
93752 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93753@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93754 tty_kref_put(port->tty);
93755 }
93756 port->tty = NULL;
93757- port->count = 0;
93758+ atomic_set(&port->count, 0);
93759 spin_unlock_irqrestore(&port->lock, flags);
93760
93761 wake_up_interruptible(&port->open_wait);
93762@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93763 seq_putc(m, '\n');
93764
93765 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93766- seq_printf(m, "Open count: %d\n", self->port.count);
93767+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93768 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93769 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93770
93771diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93772index 168aff5..9d43132 100644
93773--- a/net/iucv/af_iucv.c
93774+++ b/net/iucv/af_iucv.c
93775@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93776
93777 write_lock_bh(&iucv_sk_list.lock);
93778
93779- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93780+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93781 while (__iucv_get_sock_by_name(name)) {
93782 sprintf(name, "%08x",
93783- atomic_inc_return(&iucv_sk_list.autobind_name));
93784+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93785 }
93786
93787 write_unlock_bh(&iucv_sk_list.lock);
93788diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93789index cd5b8ec..f205e6b 100644
93790--- a/net/iucv/iucv.c
93791+++ b/net/iucv/iucv.c
93792@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93793 return NOTIFY_OK;
93794 }
93795
93796-static struct notifier_block __refdata iucv_cpu_notifier = {
93797+static struct notifier_block iucv_cpu_notifier = {
93798 .notifier_call = iucv_cpu_notify,
93799 };
93800
93801diff --git a/net/key/af_key.c b/net/key/af_key.c
93802index ab8bd2c..3a3eb81 100644
93803--- a/net/key/af_key.c
93804+++ b/net/key/af_key.c
93805@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
93806
93807 x->id.proto = proto;
93808 x->id.spi = sa->sadb_sa_spi;
93809- x->props.replay_window = sa->sadb_sa_replay;
93810+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
93811+ (sizeof(x->replay.bitmap) * 8));
93812 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
93813 x->props.flags |= XFRM_STATE_NOECN;
93814 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
93815@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93816 static u32 get_acqseq(void)
93817 {
93818 u32 res;
93819- static atomic_t acqseq;
93820+ static atomic_unchecked_t acqseq;
93821
93822 do {
93823- res = atomic_inc_return(&acqseq);
93824+ res = atomic_inc_return_unchecked(&acqseq);
93825 } while (!res);
93826 return res;
93827 }
93828diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
93829index feae495..aedaa2c 100644
93830--- a/net/l2tp/l2tp_core.c
93831+++ b/net/l2tp/l2tp_core.c
93832@@ -496,6 +496,7 @@ out:
93833 static inline int l2tp_verify_udp_checksum(struct sock *sk,
93834 struct sk_buff *skb)
93835 {
93836+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
93837 struct udphdr *uh = udp_hdr(skb);
93838 u16 ulen = ntohs(uh->len);
93839 __wsum psum;
93840@@ -504,7 +505,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
93841 return 0;
93842
93843 #if IS_ENABLED(CONFIG_IPV6)
93844- if (sk->sk_family == PF_INET6) {
93845+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
93846 if (!uh->check) {
93847 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
93848 return 1;
93849@@ -1128,7 +1129,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
93850 /* Queue the packet to IP for output */
93851 skb->local_df = 1;
93852 #if IS_ENABLED(CONFIG_IPV6)
93853- if (skb->sk->sk_family == PF_INET6)
93854+ if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93855 error = inet6_csk_xmit(skb, NULL);
93856 else
93857 #endif
93858@@ -1255,7 +1256,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
93859
93860 /* Calculate UDP checksum if configured to do so */
93861 #if IS_ENABLED(CONFIG_IPV6)
93862- if (sk->sk_family == PF_INET6)
93863+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93864 l2tp_xmit_ipv6_csum(sk, skb, udp_len);
93865 else
93866 #endif
93867@@ -1704,6 +1705,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
93868 if (cfg != NULL)
93869 tunnel->debug = cfg->debug;
93870
93871+#if IS_ENABLED(CONFIG_IPV6)
93872+ if (sk->sk_family == PF_INET6) {
93873+ struct ipv6_pinfo *np = inet6_sk(sk);
93874+
93875+ if (ipv6_addr_v4mapped(&np->saddr) &&
93876+ ipv6_addr_v4mapped(&np->daddr)) {
93877+ struct inet_sock *inet = inet_sk(sk);
93878+
93879+ tunnel->v4mapped = true;
93880+ inet->inet_saddr = np->saddr.s6_addr32[3];
93881+ inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
93882+ inet->inet_daddr = np->daddr.s6_addr32[3];
93883+ } else {
93884+ tunnel->v4mapped = false;
93885+ }
93886+ }
93887+#endif
93888+
93889 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
93890 tunnel->encap = encap;
93891 if (encap == L2TP_ENCAPTYPE_UDP) {
93892@@ -1712,7 +1731,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
93893 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
93894 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
93895 #if IS_ENABLED(CONFIG_IPV6)
93896- if (sk->sk_family == PF_INET6)
93897+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93898 udpv6_encap_enable();
93899 else
93900 #endif
93901diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
93902index 66a559b..6f251cb 100644
93903--- a/net/l2tp/l2tp_core.h
93904+++ b/net/l2tp/l2tp_core.h
93905@@ -194,6 +194,9 @@ struct l2tp_tunnel {
93906 struct sock *sock; /* Parent socket */
93907 int fd; /* Parent fd, if tunnel socket
93908 * was created by userspace */
93909+#if IS_ENABLED(CONFIG_IPV6)
93910+ bool v4mapped;
93911+#endif
93912
93913 struct work_struct del_work;
93914
93915diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93916index 43dd752..63a23bc 100644
93917--- a/net/mac80211/cfg.c
93918+++ b/net/mac80211/cfg.c
93919@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93920 ret = ieee80211_vif_use_channel(sdata, chandef,
93921 IEEE80211_CHANCTX_EXCLUSIVE);
93922 }
93923- } else if (local->open_count == local->monitors) {
93924+ } else if (local_read(&local->open_count) == local->monitors) {
93925 local->_oper_chandef = *chandef;
93926 ieee80211_hw_config(local, 0);
93927 }
93928@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
93929 else
93930 local->probe_req_reg--;
93931
93932- if (!local->open_count)
93933+ if (!local_read(&local->open_count))
93934 break;
93935
93936 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
93937@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
93938 if (chanctx_conf) {
93939 *chandef = chanctx_conf->def;
93940 ret = 0;
93941- } else if (local->open_count > 0 &&
93942- local->open_count == local->monitors &&
93943+ } else if (local_read(&local->open_count) > 0 &&
93944+ local_read(&local->open_count) == local->monitors &&
93945 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
93946 if (local->use_chanctx)
93947 *chandef = local->monitor_chandef;
93948diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
93949index 8412a30..6e00181 100644
93950--- a/net/mac80211/ieee80211_i.h
93951+++ b/net/mac80211/ieee80211_i.h
93952@@ -28,6 +28,7 @@
93953 #include <net/ieee80211_radiotap.h>
93954 #include <net/cfg80211.h>
93955 #include <net/mac80211.h>
93956+#include <asm/local.h>
93957 #include "key.h"
93958 #include "sta_info.h"
93959 #include "debug.h"
93960@@ -907,7 +908,7 @@ struct ieee80211_local {
93961 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
93962 spinlock_t queue_stop_reason_lock;
93963
93964- int open_count;
93965+ local_t open_count;
93966 int monitors, cooked_mntrs;
93967 /* number of interfaces with corresponding FIF_ flags */
93968 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
93969diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
93970index cc11759..11d5541 100644
93971--- a/net/mac80211/iface.c
93972+++ b/net/mac80211/iface.c
93973@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93974 break;
93975 }
93976
93977- if (local->open_count == 0) {
93978+ if (local_read(&local->open_count) == 0) {
93979 res = drv_start(local);
93980 if (res)
93981 goto err_del_bss;
93982@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93983 res = drv_add_interface(local, sdata);
93984 if (res)
93985 goto err_stop;
93986- } else if (local->monitors == 0 && local->open_count == 0) {
93987+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
93988 res = ieee80211_add_virtual_monitor(local);
93989 if (res)
93990 goto err_stop;
93991@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93992 atomic_inc(&local->iff_promiscs);
93993
93994 if (coming_up)
93995- local->open_count++;
93996+ local_inc(&local->open_count);
93997
93998 if (hw_reconf_flags)
93999 ieee80211_hw_config(local, hw_reconf_flags);
94000@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94001 err_del_interface:
94002 drv_remove_interface(local, sdata);
94003 err_stop:
94004- if (!local->open_count)
94005+ if (!local_read(&local->open_count))
94006 drv_stop(local);
94007 err_del_bss:
94008 sdata->bss = NULL;
94009@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94010 }
94011
94012 if (going_down)
94013- local->open_count--;
94014+ local_dec(&local->open_count);
94015
94016 switch (sdata->vif.type) {
94017 case NL80211_IFTYPE_AP_VLAN:
94018@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94019 }
94020 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94021
94022- if (local->open_count == 0)
94023+ if (local_read(&local->open_count) == 0)
94024 ieee80211_clear_tx_pending(local);
94025
94026 /*
94027@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94028
94029 ieee80211_recalc_ps(local, -1);
94030
94031- if (local->open_count == 0) {
94032+ if (local_read(&local->open_count) == 0) {
94033 ieee80211_stop_device(local);
94034
94035 /* no reconfiguring after stop! */
94036@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94037 ieee80211_configure_filter(local);
94038 ieee80211_hw_config(local, hw_reconf_flags);
94039
94040- if (local->monitors == local->open_count)
94041+ if (local->monitors == local_read(&local->open_count))
94042 ieee80211_add_virtual_monitor(local);
94043 }
94044
94045diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94046index 091088a..daf43c7 100644
94047--- a/net/mac80211/main.c
94048+++ b/net/mac80211/main.c
94049@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94050 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94051 IEEE80211_CONF_CHANGE_POWER);
94052
94053- if (changed && local->open_count) {
94054+ if (changed && local_read(&local->open_count)) {
94055 ret = drv_config(local, changed);
94056 /*
94057 * Goal:
94058diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94059index 3401262..d5cd68d 100644
94060--- a/net/mac80211/pm.c
94061+++ b/net/mac80211/pm.c
94062@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94063 struct ieee80211_sub_if_data *sdata;
94064 struct sta_info *sta;
94065
94066- if (!local->open_count)
94067+ if (!local_read(&local->open_count))
94068 goto suspend;
94069
94070 ieee80211_scan_cancel(local);
94071@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94072 cancel_work_sync(&local->dynamic_ps_enable_work);
94073 del_timer_sync(&local->dynamic_ps_timer);
94074
94075- local->wowlan = wowlan && local->open_count;
94076+ local->wowlan = wowlan && local_read(&local->open_count);
94077 if (local->wowlan) {
94078 int err = drv_suspend(local, wowlan);
94079 if (err < 0) {
94080@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94081 WARN_ON(!list_empty(&local->chanctx_list));
94082
94083 /* stop hardware - this must stop RX */
94084- if (local->open_count)
94085+ if (local_read(&local->open_count))
94086 ieee80211_stop_device(local);
94087
94088 suspend:
94089diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94090index 30d58d2..449ac8e 100644
94091--- a/net/mac80211/rate.c
94092+++ b/net/mac80211/rate.c
94093@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94094
94095 ASSERT_RTNL();
94096
94097- if (local->open_count)
94098+ if (local_read(&local->open_count))
94099 return -EBUSY;
94100
94101 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94102diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94103index c97a065..ff61928 100644
94104--- a/net/mac80211/rc80211_pid_debugfs.c
94105+++ b/net/mac80211/rc80211_pid_debugfs.c
94106@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94107
94108 spin_unlock_irqrestore(&events->lock, status);
94109
94110- if (copy_to_user(buf, pb, p))
94111+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94112 return -EFAULT;
94113
94114 return p;
94115diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94116index 2265445..ba14971 100644
94117--- a/net/mac80211/util.c
94118+++ b/net/mac80211/util.c
94119@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94120 }
94121 #endif
94122 /* everything else happens only if HW was up & running */
94123- if (!local->open_count)
94124+ if (!local_read(&local->open_count))
94125 goto wake_up;
94126
94127 /*
94128@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94129 local->in_reconfig = false;
94130 barrier();
94131
94132- if (local->monitors == local->open_count && local->monitors > 0)
94133+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94134 ieee80211_add_virtual_monitor(local);
94135
94136 /*
94137diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94138index 56d22ca..87c778f 100644
94139--- a/net/netfilter/Kconfig
94140+++ b/net/netfilter/Kconfig
94141@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94142
94143 To compile it as a module, choose M here. If unsure, say N.
94144
94145+config NETFILTER_XT_MATCH_GRADM
94146+ tristate '"gradm" match support'
94147+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94148+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94149+ ---help---
94150+ The gradm match allows to match on grsecurity RBAC being enabled.
94151+ It is useful when iptables rules are applied early on bootup to
94152+ prevent connections to the machine (except from a trusted host)
94153+ while the RBAC system is disabled.
94154+
94155 config NETFILTER_XT_MATCH_HASHLIMIT
94156 tristate '"hashlimit" match support'
94157 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94158diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94159index a1abf87..dbcb7ee 100644
94160--- a/net/netfilter/Makefile
94161+++ b/net/netfilter/Makefile
94162@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94163 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94164 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94165 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94166+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94167 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94168 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94169 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94170diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94171index f771390..145b765 100644
94172--- a/net/netfilter/ipset/ip_set_core.c
94173+++ b/net/netfilter/ipset/ip_set_core.c
94174@@ -1820,7 +1820,7 @@ done:
94175 return ret;
94176 }
94177
94178-static struct nf_sockopt_ops so_set __read_mostly = {
94179+static struct nf_sockopt_ops so_set = {
94180 .pf = PF_INET,
94181 .get_optmin = SO_IP_SET,
94182 .get_optmax = SO_IP_SET + 1,
94183diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94184index 4c8e5c0..5a79b4d 100644
94185--- a/net/netfilter/ipvs/ip_vs_conn.c
94186+++ b/net/netfilter/ipvs/ip_vs_conn.c
94187@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94188 /* Increase the refcnt counter of the dest */
94189 ip_vs_dest_hold(dest);
94190
94191- conn_flags = atomic_read(&dest->conn_flags);
94192+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94193 if (cp->protocol != IPPROTO_UDP)
94194 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94195 flags = cp->flags;
94196@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94197
94198 cp->control = NULL;
94199 atomic_set(&cp->n_control, 0);
94200- atomic_set(&cp->in_pkts, 0);
94201+ atomic_set_unchecked(&cp->in_pkts, 0);
94202
94203 cp->packet_xmit = NULL;
94204 cp->app = NULL;
94205@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94206
94207 /* Don't drop the entry if its number of incoming packets is not
94208 located in [0, 8] */
94209- i = atomic_read(&cp->in_pkts);
94210+ i = atomic_read_unchecked(&cp->in_pkts);
94211 if (i > 8 || i < 0) return 0;
94212
94213 if (!todrop_rate[i]) return 0;
94214diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94215index 4f69e83..da2d8bf 100644
94216--- a/net/netfilter/ipvs/ip_vs_core.c
94217+++ b/net/netfilter/ipvs/ip_vs_core.c
94218@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94219 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94220 /* do not touch skb anymore */
94221
94222- atomic_inc(&cp->in_pkts);
94223+ atomic_inc_unchecked(&cp->in_pkts);
94224 ip_vs_conn_put(cp);
94225 return ret;
94226 }
94227@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94228 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94229 pkts = sysctl_sync_threshold(ipvs);
94230 else
94231- pkts = atomic_add_return(1, &cp->in_pkts);
94232+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94233
94234 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94235 ip_vs_sync_conn(net, cp, pkts);
94236diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94237index c8148e4..eff604f 100644
94238--- a/net/netfilter/ipvs/ip_vs_ctl.c
94239+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94240@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94241 */
94242 ip_vs_rs_hash(ipvs, dest);
94243 }
94244- atomic_set(&dest->conn_flags, conn_flags);
94245+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94246
94247 /* bind the service */
94248 if (!dest->svc) {
94249@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94250 * align with netns init in ip_vs_control_net_init()
94251 */
94252
94253-static struct ctl_table vs_vars[] = {
94254+static ctl_table_no_const vs_vars[] __read_only = {
94255 {
94256 .procname = "amemthresh",
94257 .maxlen = sizeof(int),
94258@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94259 " %-7s %-6d %-10d %-10d\n",
94260 &dest->addr.in6,
94261 ntohs(dest->port),
94262- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94263+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94264 atomic_read(&dest->weight),
94265 atomic_read(&dest->activeconns),
94266 atomic_read(&dest->inactconns));
94267@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94268 "%-7s %-6d %-10d %-10d\n",
94269 ntohl(dest->addr.ip),
94270 ntohs(dest->port),
94271- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94272+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94273 atomic_read(&dest->weight),
94274 atomic_read(&dest->activeconns),
94275 atomic_read(&dest->inactconns));
94276@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94277
94278 entry.addr = dest->addr.ip;
94279 entry.port = dest->port;
94280- entry.conn_flags = atomic_read(&dest->conn_flags);
94281+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94282 entry.weight = atomic_read(&dest->weight);
94283 entry.u_threshold = dest->u_threshold;
94284 entry.l_threshold = dest->l_threshold;
94285@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94286 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94287 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94288 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94289- (atomic_read(&dest->conn_flags) &
94290+ (atomic_read_unchecked(&dest->conn_flags) &
94291 IP_VS_CONN_F_FWD_MASK)) ||
94292 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94293 atomic_read(&dest->weight)) ||
94294@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94295 {
94296 int idx;
94297 struct netns_ipvs *ipvs = net_ipvs(net);
94298- struct ctl_table *tbl;
94299+ ctl_table_no_const *tbl;
94300
94301 atomic_set(&ipvs->dropentry, 0);
94302 spin_lock_init(&ipvs->dropentry_lock);
94303diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94304index 1383b0e..a486da1 100644
94305--- a/net/netfilter/ipvs/ip_vs_lblc.c
94306+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94307@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94308 * IPVS LBLC sysctl table
94309 */
94310 #ifdef CONFIG_SYSCTL
94311-static struct ctl_table vs_vars_table[] = {
94312+static ctl_table_no_const vs_vars_table[] __read_only = {
94313 {
94314 .procname = "lblc_expiration",
94315 .data = NULL,
94316diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94317index 3cd85b2..dfab2b8 100644
94318--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94319+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94320@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94321 * IPVS LBLCR sysctl table
94322 */
94323
94324-static struct ctl_table vs_vars_table[] = {
94325+static ctl_table_no_const vs_vars_table[] __read_only = {
94326 {
94327 .procname = "lblcr_expiration",
94328 .data = NULL,
94329diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94330index f448471..995f131 100644
94331--- a/net/netfilter/ipvs/ip_vs_sync.c
94332+++ b/net/netfilter/ipvs/ip_vs_sync.c
94333@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94334 cp = cp->control;
94335 if (cp) {
94336 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94337- pkts = atomic_add_return(1, &cp->in_pkts);
94338+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94339 else
94340 pkts = sysctl_sync_threshold(ipvs);
94341 ip_vs_sync_conn(net, cp->control, pkts);
94342@@ -771,7 +771,7 @@ control:
94343 if (!cp)
94344 return;
94345 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94346- pkts = atomic_add_return(1, &cp->in_pkts);
94347+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94348 else
94349 pkts = sysctl_sync_threshold(ipvs);
94350 goto sloop;
94351@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94352
94353 if (opt)
94354 memcpy(&cp->in_seq, opt, sizeof(*opt));
94355- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94356+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94357 cp->state = state;
94358 cp->old_state = cp->state;
94359 /*
94360diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94361index c47444e..b0961c6 100644
94362--- a/net/netfilter/ipvs/ip_vs_xmit.c
94363+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94364@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94365 else
94366 rc = NF_ACCEPT;
94367 /* do not touch skb anymore */
94368- atomic_inc(&cp->in_pkts);
94369+ atomic_inc_unchecked(&cp->in_pkts);
94370 goto out;
94371 }
94372
94373@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94374 else
94375 rc = NF_ACCEPT;
94376 /* do not touch skb anymore */
94377- atomic_inc(&cp->in_pkts);
94378+ atomic_inc_unchecked(&cp->in_pkts);
94379 goto out;
94380 }
94381
94382diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94383index 2d3030a..7ba1c0a 100644
94384--- a/net/netfilter/nf_conntrack_acct.c
94385+++ b/net/netfilter/nf_conntrack_acct.c
94386@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94387 #ifdef CONFIG_SYSCTL
94388 static int nf_conntrack_acct_init_sysctl(struct net *net)
94389 {
94390- struct ctl_table *table;
94391+ ctl_table_no_const *table;
94392
94393 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94394 GFP_KERNEL);
94395diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94396index 0283bae..5febcb0 100644
94397--- a/net/netfilter/nf_conntrack_core.c
94398+++ b/net/netfilter/nf_conntrack_core.c
94399@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94400 #define DYING_NULLS_VAL ((1<<30)+1)
94401 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94402
94403+#ifdef CONFIG_GRKERNSEC_HIDESYM
94404+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94405+#endif
94406+
94407 int nf_conntrack_init_net(struct net *net)
94408 {
94409 int ret;
94410@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94411 goto err_stat;
94412 }
94413
94414+#ifdef CONFIG_GRKERNSEC_HIDESYM
94415+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94416+#else
94417 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94418+#endif
94419 if (!net->ct.slabname) {
94420 ret = -ENOMEM;
94421 goto err_slabname;
94422diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94423index 1df1761..ce8b88a 100644
94424--- a/net/netfilter/nf_conntrack_ecache.c
94425+++ b/net/netfilter/nf_conntrack_ecache.c
94426@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94427 #ifdef CONFIG_SYSCTL
94428 static int nf_conntrack_event_init_sysctl(struct net *net)
94429 {
94430- struct ctl_table *table;
94431+ ctl_table_no_const *table;
94432
94433 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94434 GFP_KERNEL);
94435diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94436index 974a2a4..52cc6ff 100644
94437--- a/net/netfilter/nf_conntrack_helper.c
94438+++ b/net/netfilter/nf_conntrack_helper.c
94439@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94440
94441 static int nf_conntrack_helper_init_sysctl(struct net *net)
94442 {
94443- struct ctl_table *table;
94444+ ctl_table_no_const *table;
94445
94446 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94447 GFP_KERNEL);
94448diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94449index 0ab9636..cea3c6a 100644
94450--- a/net/netfilter/nf_conntrack_proto.c
94451+++ b/net/netfilter/nf_conntrack_proto.c
94452@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94453
94454 static void
94455 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94456- struct ctl_table **table,
94457+ ctl_table_no_const **table,
94458 unsigned int users)
94459 {
94460 if (users > 0)
94461diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94462index a99b6c3..cb372f9 100644
94463--- a/net/netfilter/nf_conntrack_proto_dccp.c
94464+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94465@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94466 const char *msg;
94467 u_int8_t state;
94468
94469- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94470+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94471 BUG_ON(dh == NULL);
94472
94473 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94474@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94475 out_invalid:
94476 if (LOG_INVALID(net, IPPROTO_DCCP))
94477 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94478- NULL, msg);
94479+ NULL, "%s", msg);
94480 return false;
94481 }
94482
94483@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94484 u_int8_t type, old_state, new_state;
94485 enum ct_dccp_roles role;
94486
94487- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94488+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94489 BUG_ON(dh == NULL);
94490 type = dh->dccph_type;
94491
94492@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94493 unsigned int cscov;
94494 const char *msg;
94495
94496- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94497+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94498 if (dh == NULL) {
94499 msg = "nf_ct_dccp: short packet ";
94500 goto out_invalid;
94501@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94502
94503 out_invalid:
94504 if (LOG_INVALID(net, IPPROTO_DCCP))
94505- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94506+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94507 return -NF_ACCEPT;
94508 }
94509
94510diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94511index f641751..d3c5b51 100644
94512--- a/net/netfilter/nf_conntrack_standalone.c
94513+++ b/net/netfilter/nf_conntrack_standalone.c
94514@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94515
94516 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94517 {
94518- struct ctl_table *table;
94519+ ctl_table_no_const *table;
94520
94521 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94522 GFP_KERNEL);
94523diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94524index 902fb0a..87f7fdb 100644
94525--- a/net/netfilter/nf_conntrack_timestamp.c
94526+++ b/net/netfilter/nf_conntrack_timestamp.c
94527@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94528 #ifdef CONFIG_SYSCTL
94529 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94530 {
94531- struct ctl_table *table;
94532+ ctl_table_no_const *table;
94533
94534 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94535 GFP_KERNEL);
94536diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94537index 85296d4..8becdec 100644
94538--- a/net/netfilter/nf_log.c
94539+++ b/net/netfilter/nf_log.c
94540@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94541
94542 #ifdef CONFIG_SYSCTL
94543 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94544-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94545+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94546
94547 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94548 void __user *buffer, size_t *lenp, loff_t *ppos)
94549@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94550 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94551 mutex_unlock(&nf_log_mutex);
94552 } else {
94553+ ctl_table_no_const nf_log_table = *table;
94554+
94555 mutex_lock(&nf_log_mutex);
94556 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94557 lockdep_is_held(&nf_log_mutex));
94558 if (!logger)
94559- table->data = "NONE";
94560+ nf_log_table.data = "NONE";
94561 else
94562- table->data = logger->name;
94563- r = proc_dostring(table, write, buffer, lenp, ppos);
94564+ nf_log_table.data = logger->name;
94565+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94566 mutex_unlock(&nf_log_mutex);
94567 }
94568
94569diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94570index f042ae5..30ea486 100644
94571--- a/net/netfilter/nf_sockopt.c
94572+++ b/net/netfilter/nf_sockopt.c
94573@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94574 }
94575 }
94576
94577- list_add(&reg->list, &nf_sockopts);
94578+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94579 out:
94580 mutex_unlock(&nf_sockopt_mutex);
94581 return ret;
94582@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94583 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94584 {
94585 mutex_lock(&nf_sockopt_mutex);
94586- list_del(&reg->list);
94587+ pax_list_del((struct list_head *)&reg->list);
94588 mutex_unlock(&nf_sockopt_mutex);
94589 }
94590 EXPORT_SYMBOL(nf_unregister_sockopt);
94591diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94592index d92cc31..e46f350 100644
94593--- a/net/netfilter/nfnetlink_log.c
94594+++ b/net/netfilter/nfnetlink_log.c
94595@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94596 struct nfnl_log_net {
94597 spinlock_t instances_lock;
94598 struct hlist_head instance_table[INSTANCE_BUCKETS];
94599- atomic_t global_seq;
94600+ atomic_unchecked_t global_seq;
94601 };
94602
94603 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94604@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94605 /* global sequence number */
94606 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94607 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94608- htonl(atomic_inc_return(&log->global_seq))))
94609+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94610 goto nla_put_failure;
94611
94612 if (data_len) {
94613diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94614new file mode 100644
94615index 0000000..c566332
94616--- /dev/null
94617+++ b/net/netfilter/xt_gradm.c
94618@@ -0,0 +1,51 @@
94619+/*
94620+ * gradm match for netfilter
94621