]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.12.5-201312151212.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.12.5-201312151212.patch
CommitLineData
67b242af
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 fcbb736..5508d8c 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -1031,6 +1031,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@@ -1999,6 +2003,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@@ -2266,6 +2274,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 986f3cd..8691deb 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 define filechk_kernel.release
403@@ -838,6 +900,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@@ -945,6 +1008,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@@ -960,7 +1025,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@@ -1026,7 +1091,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@@ -1066,6 +1131,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@@ -1227,6 +1293,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@@ -1366,17 +1434,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@@ -1386,11 +1458,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 98838a0..b304fb4 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 1ad6fb6..9406b3d 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1832,7 +1832,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
844@@ -2097,6 +2097,7 @@ config XIP_PHYS_ADDR
845 config KEXEC
846 bool "Kexec system call (EXPERIMENTAL)"
847 depends on (!SMP || PM_SLEEP_SMP)
848+ depends on !GRKERNSEC_KMEM
849 help
850 kexec is a system call that implements the ability to shutdown your
851 current kernel, and to start another kernel. It is like a reboot
852diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
853index da1c77d..2ee6056 100644
854--- a/arch/arm/include/asm/atomic.h
855+++ b/arch/arm/include/asm/atomic.h
856@@ -17,17 +17,35 @@
857 #include <asm/barrier.h>
858 #include <asm/cmpxchg.h>
859
860+#ifdef CONFIG_GENERIC_ATOMIC64
861+#include <asm-generic/atomic64.h>
862+#endif
863+
864 #define ATOMIC_INIT(i) { (i) }
865
866 #ifdef __KERNEL__
867
868+#define _ASM_EXTABLE(from, to) \
869+" .pushsection __ex_table,\"a\"\n"\
870+" .align 3\n" \
871+" .long " #from ", " #to"\n" \
872+" .popsection"
873+
874 /*
875 * On ARM, ordinary assignment (str instruction) doesn't clear the local
876 * strex/ldrex monitor on some implementations. The reason we can use it for
877 * atomic_set() is the clrex or dummy strex done on every exception return.
878 */
879 #define atomic_read(v) (*(volatile int *)&(v)->counter)
880+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
881+{
882+ return v->counter;
883+}
884 #define atomic_set(v,i) (((v)->counter) = (i))
885+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
886+{
887+ v->counter = i;
888+}
889
890 #if __LINUX_ARM_ARCH__ >= 6
891
892@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
893 int result;
894
895 __asm__ __volatile__("@ atomic_add\n"
896+"1: ldrex %1, [%3]\n"
897+" adds %0, %1, %4\n"
898+
899+#ifdef CONFIG_PAX_REFCOUNT
900+" bvc 3f\n"
901+"2: bkpt 0xf103\n"
902+"3:\n"
903+#endif
904+
905+" strex %1, %0, [%3]\n"
906+" teq %1, #0\n"
907+" bne 1b"
908+
909+#ifdef CONFIG_PAX_REFCOUNT
910+"\n4:\n"
911+ _ASM_EXTABLE(2b, 4b)
912+#endif
913+
914+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
915+ : "r" (&v->counter), "Ir" (i)
916+ : "cc");
917+}
918+
919+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
920+{
921+ unsigned long tmp;
922+ int result;
923+
924+ __asm__ __volatile__("@ atomic_add_unchecked\n"
925 "1: ldrex %0, [%3]\n"
926 " add %0, %0, %4\n"
927 " strex %1, %0, [%3]\n"
928@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
929 smp_mb();
930
931 __asm__ __volatile__("@ atomic_add_return\n"
932+"1: ldrex %1, [%3]\n"
933+" adds %0, %1, %4\n"
934+
935+#ifdef CONFIG_PAX_REFCOUNT
936+" bvc 3f\n"
937+" mov %0, %1\n"
938+"2: bkpt 0xf103\n"
939+"3:\n"
940+#endif
941+
942+" strex %1, %0, [%3]\n"
943+" teq %1, #0\n"
944+" bne 1b"
945+
946+#ifdef CONFIG_PAX_REFCOUNT
947+"\n4:\n"
948+ _ASM_EXTABLE(2b, 4b)
949+#endif
950+
951+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
952+ : "r" (&v->counter), "Ir" (i)
953+ : "cc");
954+
955+ smp_mb();
956+
957+ return result;
958+}
959+
960+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
961+{
962+ unsigned long tmp;
963+ int result;
964+
965+ smp_mb();
966+
967+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
968 "1: ldrex %0, [%3]\n"
969 " add %0, %0, %4\n"
970 " strex %1, %0, [%3]\n"
971@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
972 int result;
973
974 __asm__ __volatile__("@ atomic_sub\n"
975+"1: ldrex %1, [%3]\n"
976+" subs %0, %1, %4\n"
977+
978+#ifdef CONFIG_PAX_REFCOUNT
979+" bvc 3f\n"
980+"2: bkpt 0xf103\n"
981+"3:\n"
982+#endif
983+
984+" strex %1, %0, [%3]\n"
985+" teq %1, #0\n"
986+" bne 1b"
987+
988+#ifdef CONFIG_PAX_REFCOUNT
989+"\n4:\n"
990+ _ASM_EXTABLE(2b, 4b)
991+#endif
992+
993+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994+ : "r" (&v->counter), "Ir" (i)
995+ : "cc");
996+}
997+
998+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
999+{
1000+ unsigned long tmp;
1001+ int result;
1002+
1003+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1004 "1: ldrex %0, [%3]\n"
1005 " sub %0, %0, %4\n"
1006 " strex %1, %0, [%3]\n"
1007@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1008 smp_mb();
1009
1010 __asm__ __volatile__("@ atomic_sub_return\n"
1011-"1: ldrex %0, [%3]\n"
1012-" sub %0, %0, %4\n"
1013+"1: ldrex %1, [%3]\n"
1014+" subs %0, %1, %4\n"
1015+
1016+#ifdef CONFIG_PAX_REFCOUNT
1017+" bvc 3f\n"
1018+" mov %0, %1\n"
1019+"2: bkpt 0xf103\n"
1020+"3:\n"
1021+#endif
1022+
1023 " strex %1, %0, [%3]\n"
1024 " teq %1, #0\n"
1025 " bne 1b"
1026+
1027+#ifdef CONFIG_PAX_REFCOUNT
1028+"\n4:\n"
1029+ _ASM_EXTABLE(2b, 4b)
1030+#endif
1031+
1032 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1033 : "r" (&v->counter), "Ir" (i)
1034 : "cc");
1035@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1036 return oldval;
1037 }
1038
1039+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1040+{
1041+ unsigned long oldval, res;
1042+
1043+ smp_mb();
1044+
1045+ do {
1046+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1047+ "ldrex %1, [%3]\n"
1048+ "mov %0, #0\n"
1049+ "teq %1, %4\n"
1050+ "strexeq %0, %5, [%3]\n"
1051+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1052+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1053+ : "cc");
1054+ } while (res);
1055+
1056+ smp_mb();
1057+
1058+ return oldval;
1059+}
1060+
1061 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1062 {
1063 unsigned long tmp, tmp2;
1064@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065
1066 return val;
1067 }
1068+
1069+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1070+{
1071+ return atomic_add_return(i, v);
1072+}
1073+
1074 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1075+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1076+{
1077+ (void) atomic_add_return(i, v);
1078+}
1079
1080 static inline int atomic_sub_return(int i, atomic_t *v)
1081 {
1082@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1083 return val;
1084 }
1085 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1086+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1087+{
1088+ (void) atomic_sub_return(i, v);
1089+}
1090
1091 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1092 {
1093@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1094 return ret;
1095 }
1096
1097+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1098+{
1099+ return atomic_cmpxchg(v, old, new);
1100+}
1101+
1102 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1103 {
1104 unsigned long flags;
1105@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1106 #endif /* __LINUX_ARM_ARCH__ */
1107
1108 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1109+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1110+{
1111+ return xchg(&v->counter, new);
1112+}
1113
1114 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1115 {
1116@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1117 }
1118
1119 #define atomic_inc(v) atomic_add(1, v)
1120+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1121+{
1122+ atomic_add_unchecked(1, v);
1123+}
1124 #define atomic_dec(v) atomic_sub(1, v)
1125+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1126+{
1127+ atomic_sub_unchecked(1, v);
1128+}
1129
1130 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1131+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1132+{
1133+ return atomic_add_return_unchecked(1, v) == 0;
1134+}
1135 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1136 #define atomic_inc_return(v) (atomic_add_return(1, v))
1137+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1138+{
1139+ return atomic_add_return_unchecked(1, v);
1140+}
1141 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1142 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1143
1144@@ -241,6 +428,14 @@ typedef struct {
1145 u64 __aligned(8) counter;
1146 } atomic64_t;
1147
1148+#ifdef CONFIG_PAX_REFCOUNT
1149+typedef struct {
1150+ u64 __aligned(8) counter;
1151+} atomic64_unchecked_t;
1152+#else
1153+typedef atomic64_t atomic64_unchecked_t;
1154+#endif
1155+
1156 #define ATOMIC64_INIT(i) { (i) }
1157
1158 #ifdef CONFIG_ARM_LPAE
1159@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1160 return result;
1161 }
1162
1163+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1164+{
1165+ u64 result;
1166+
1167+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1168+" ldrd %0, %H0, [%1]"
1169+ : "=&r" (result)
1170+ : "r" (&v->counter), "Qo" (v->counter)
1171+ );
1172+
1173+ return result;
1174+}
1175+
1176 static inline void atomic64_set(atomic64_t *v, u64 i)
1177 {
1178 __asm__ __volatile__("@ atomic64_set\n"
1179@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1180 : "r" (&v->counter), "r" (i)
1181 );
1182 }
1183+
1184+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1185+{
1186+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1187+" strd %2, %H2, [%1]"
1188+ : "=Qo" (v->counter)
1189+ : "r" (&v->counter), "r" (i)
1190+ );
1191+}
1192 #else
1193 static inline u64 atomic64_read(const atomic64_t *v)
1194 {
1195@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1196 return result;
1197 }
1198
1199+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1200+{
1201+ u64 result;
1202+
1203+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1204+" ldrexd %0, %H0, [%1]"
1205+ : "=&r" (result)
1206+ : "r" (&v->counter), "Qo" (v->counter)
1207+ );
1208+
1209+ return result;
1210+}
1211+
1212 static inline void atomic64_set(atomic64_t *v, u64 i)
1213 {
1214 u64 tmp;
1215@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1216 : "r" (&v->counter), "r" (i)
1217 : "cc");
1218 }
1219+
1220+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1221+{
1222+ u64 tmp;
1223+
1224+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1225+"1: ldrexd %0, %H0, [%2]\n"
1226+" strexd %0, %3, %H3, [%2]\n"
1227+" teq %0, #0\n"
1228+" bne 1b"
1229+ : "=&r" (tmp), "=Qo" (v->counter)
1230+ : "r" (&v->counter), "r" (i)
1231+ : "cc");
1232+}
1233+
1234 #endif
1235
1236 static inline void atomic64_add(u64 i, atomic64_t *v)
1237@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_add\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " adds %0, %0, %4\n"
1241+" adcs %H0, %H0, %H4\n"
1242+
1243+#ifdef CONFIG_PAX_REFCOUNT
1244+" bvc 3f\n"
1245+"2: bkpt 0xf103\n"
1246+"3:\n"
1247+#endif
1248+
1249+" strexd %1, %0, %H0, [%3]\n"
1250+" teq %1, #0\n"
1251+" bne 1b"
1252+
1253+#ifdef CONFIG_PAX_REFCOUNT
1254+"\n4:\n"
1255+ _ASM_EXTABLE(2b, 4b)
1256+#endif
1257+
1258+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259+ : "r" (&v->counter), "r" (i)
1260+ : "cc");
1261+}
1262+
1263+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1264+{
1265+ u64 result;
1266+ unsigned long tmp;
1267+
1268+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1269+"1: ldrexd %0, %H0, [%3]\n"
1270+" adds %0, %0, %4\n"
1271 " adc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1277 {
1278- u64 result;
1279- unsigned long tmp;
1280+ u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_add_return\n"
1285+"1: ldrexd %1, %H1, [%3]\n"
1286+" adds %0, %1, %4\n"
1287+" adcs %H0, %H1, %H4\n"
1288+
1289+#ifdef CONFIG_PAX_REFCOUNT
1290+" bvc 3f\n"
1291+" mov %0, %1\n"
1292+" mov %H0, %H1\n"
1293+"2: bkpt 0xf103\n"
1294+"3:\n"
1295+#endif
1296+
1297+" strexd %1, %0, %H0, [%3]\n"
1298+" teq %1, #0\n"
1299+" bne 1b"
1300+
1301+#ifdef CONFIG_PAX_REFCOUNT
1302+"\n4:\n"
1303+ _ASM_EXTABLE(2b, 4b)
1304+#endif
1305+
1306+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1307+ : "r" (&v->counter), "r" (i)
1308+ : "cc");
1309+
1310+ smp_mb();
1311+
1312+ return result;
1313+}
1314+
1315+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1316+{
1317+ u64 result;
1318+ unsigned long tmp;
1319+
1320+ smp_mb();
1321+
1322+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1323 "1: ldrexd %0, %H0, [%3]\n"
1324 " adds %0, %0, %4\n"
1325 " adc %H0, %H0, %H4\n"
1326@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1327 __asm__ __volatile__("@ atomic64_sub\n"
1328 "1: ldrexd %0, %H0, [%3]\n"
1329 " subs %0, %0, %4\n"
1330+" sbcs %H0, %H0, %H4\n"
1331+
1332+#ifdef CONFIG_PAX_REFCOUNT
1333+" bvc 3f\n"
1334+"2: bkpt 0xf103\n"
1335+"3:\n"
1336+#endif
1337+
1338+" strexd %1, %0, %H0, [%3]\n"
1339+" teq %1, #0\n"
1340+" bne 1b"
1341+
1342+#ifdef CONFIG_PAX_REFCOUNT
1343+"\n4:\n"
1344+ _ASM_EXTABLE(2b, 4b)
1345+#endif
1346+
1347+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1348+ : "r" (&v->counter), "r" (i)
1349+ : "cc");
1350+}
1351+
1352+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1353+{
1354+ u64 result;
1355+ unsigned long tmp;
1356+
1357+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1358+"1: ldrexd %0, %H0, [%3]\n"
1359+" subs %0, %0, %4\n"
1360 " sbc %H0, %H0, %H4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1364
1365 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1366 {
1367- u64 result;
1368- unsigned long tmp;
1369+ u64 result, tmp;
1370
1371 smp_mb();
1372
1373 __asm__ __volatile__("@ atomic64_sub_return\n"
1374-"1: ldrexd %0, %H0, [%3]\n"
1375-" subs %0, %0, %4\n"
1376-" sbc %H0, %H0, %H4\n"
1377+"1: ldrexd %1, %H1, [%3]\n"
1378+" subs %0, %1, %4\n"
1379+" sbcs %H0, %H1, %H4\n"
1380+
1381+#ifdef CONFIG_PAX_REFCOUNT
1382+" bvc 3f\n"
1383+" mov %0, %1\n"
1384+" mov %H0, %H1\n"
1385+"2: bkpt 0xf103\n"
1386+"3:\n"
1387+#endif
1388+
1389 " strexd %1, %0, %H0, [%3]\n"
1390 " teq %1, #0\n"
1391 " bne 1b"
1392+
1393+#ifdef CONFIG_PAX_REFCOUNT
1394+"\n4:\n"
1395+ _ASM_EXTABLE(2b, 4b)
1396+#endif
1397+
1398 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1399 : "r" (&v->counter), "r" (i)
1400 : "cc");
1401@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1402 return oldval;
1403 }
1404
1405+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1406+{
1407+ u64 oldval;
1408+ unsigned long res;
1409+
1410+ smp_mb();
1411+
1412+ do {
1413+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1414+ "ldrexd %1, %H1, [%3]\n"
1415+ "mov %0, #0\n"
1416+ "teq %1, %4\n"
1417+ "teqeq %H1, %H4\n"
1418+ "strexdeq %0, %5, %H5, [%3]"
1419+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1420+ : "r" (&ptr->counter), "r" (old), "r" (new)
1421+ : "cc");
1422+ } while (res);
1423+
1424+ smp_mb();
1425+
1426+ return oldval;
1427+}
1428+
1429 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1430 {
1431 u64 result;
1432@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1433
1434 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1435 {
1436- u64 result;
1437- unsigned long tmp;
1438+ u64 result, tmp;
1439
1440 smp_mb();
1441
1442 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1443-"1: ldrexd %0, %H0, [%3]\n"
1444-" subs %0, %0, #1\n"
1445-" sbc %H0, %H0, #0\n"
1446+"1: ldrexd %1, %H1, [%3]\n"
1447+" subs %0, %1, #1\n"
1448+" sbcs %H0, %H1, #0\n"
1449+
1450+#ifdef CONFIG_PAX_REFCOUNT
1451+" bvc 3f\n"
1452+" mov %0, %1\n"
1453+" mov %H0, %H1\n"
1454+"2: bkpt 0xf103\n"
1455+"3:\n"
1456+#endif
1457+
1458 " teq %H0, #0\n"
1459-" bmi 2f\n"
1460+" bmi 4f\n"
1461 " strexd %1, %0, %H0, [%3]\n"
1462 " teq %1, #0\n"
1463 " bne 1b\n"
1464-"2:"
1465+"4:\n"
1466+
1467+#ifdef CONFIG_PAX_REFCOUNT
1468+ _ASM_EXTABLE(2b, 4b)
1469+#endif
1470+
1471 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1472 : "r" (&v->counter)
1473 : "cc");
1474@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1475 " teq %0, %5\n"
1476 " teqeq %H0, %H5\n"
1477 " moveq %1, #0\n"
1478-" beq 2f\n"
1479+" beq 4f\n"
1480 " adds %0, %0, %6\n"
1481-" adc %H0, %H0, %H6\n"
1482+" adcs %H0, %H0, %H6\n"
1483+
1484+#ifdef CONFIG_PAX_REFCOUNT
1485+" bvc 3f\n"
1486+"2: bkpt 0xf103\n"
1487+"3:\n"
1488+#endif
1489+
1490 " strexd %2, %0, %H0, [%4]\n"
1491 " teq %2, #0\n"
1492 " bne 1b\n"
1493-"2:"
1494+"4:\n"
1495+
1496+#ifdef CONFIG_PAX_REFCOUNT
1497+ _ASM_EXTABLE(2b, 4b)
1498+#endif
1499+
1500 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1501 : "r" (&v->counter), "r" (u), "r" (a)
1502 : "cc");
1503@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1504
1505 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1506 #define atomic64_inc(v) atomic64_add(1LL, (v))
1507+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1508 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1509+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1510 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1511 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1512 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1513+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1514 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1515 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1516 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1517diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1518index 75fe66b..ba3dee4 100644
1519--- a/arch/arm/include/asm/cache.h
1520+++ b/arch/arm/include/asm/cache.h
1521@@ -4,8 +4,10 @@
1522 #ifndef __ASMARM_CACHE_H
1523 #define __ASMARM_CACHE_H
1524
1525+#include <linux/const.h>
1526+
1527 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1528-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1529+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1530
1531 /*
1532 * Memory returned by kmalloc() may be used for DMA, so we must make
1533@@ -24,5 +26,6 @@
1534 #endif
1535
1536 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1537+#define __read_only __attribute__ ((__section__(".data..read_only")))
1538
1539 #endif
1540diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1541index 15f2d5b..43ffa53 100644
1542--- a/arch/arm/include/asm/cacheflush.h
1543+++ b/arch/arm/include/asm/cacheflush.h
1544@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1545 void (*dma_unmap_area)(const void *, size_t, int);
1546
1547 void (*dma_flush_range)(const void *, const void *);
1548-};
1549+} __no_const;
1550
1551 /*
1552 * Select the calling method
1553diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1554index 6dcc164..b14d917 100644
1555--- a/arch/arm/include/asm/checksum.h
1556+++ b/arch/arm/include/asm/checksum.h
1557@@ -37,7 +37,19 @@ __wsum
1558 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1559
1560 __wsum
1561-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1562+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1563+
1564+static inline __wsum
1565+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1566+{
1567+ __wsum ret;
1568+ pax_open_userland();
1569+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1570+ pax_close_userland();
1571+ return ret;
1572+}
1573+
1574+
1575
1576 /*
1577 * Fold a partial checksum without adding pseudo headers
1578diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1579index 4f009c1..466c59b 100644
1580--- a/arch/arm/include/asm/cmpxchg.h
1581+++ b/arch/arm/include/asm/cmpxchg.h
1582@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1583
1584 #define xchg(ptr,x) \
1585 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1586+#define xchg_unchecked(ptr,x) \
1587+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1588
1589 #include <asm-generic/cmpxchg-local.h>
1590
1591diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1592index 6ddbe44..b5e38b1 100644
1593--- a/arch/arm/include/asm/domain.h
1594+++ b/arch/arm/include/asm/domain.h
1595@@ -48,18 +48,37 @@
1596 * Domain types
1597 */
1598 #define DOMAIN_NOACCESS 0
1599-#define DOMAIN_CLIENT 1
1600 #ifdef CONFIG_CPU_USE_DOMAINS
1601+#define DOMAIN_USERCLIENT 1
1602+#define DOMAIN_KERNELCLIENT 1
1603 #define DOMAIN_MANAGER 3
1604+#define DOMAIN_VECTORS DOMAIN_USER
1605 #else
1606+
1607+#ifdef CONFIG_PAX_KERNEXEC
1608 #define DOMAIN_MANAGER 1
1609+#define DOMAIN_KERNEXEC 3
1610+#else
1611+#define DOMAIN_MANAGER 1
1612+#endif
1613+
1614+#ifdef CONFIG_PAX_MEMORY_UDEREF
1615+#define DOMAIN_USERCLIENT 0
1616+#define DOMAIN_UDEREF 1
1617+#define DOMAIN_VECTORS DOMAIN_KERNEL
1618+#else
1619+#define DOMAIN_USERCLIENT 1
1620+#define DOMAIN_VECTORS DOMAIN_USER
1621+#endif
1622+#define DOMAIN_KERNELCLIENT 1
1623+
1624 #endif
1625
1626 #define domain_val(dom,type) ((type) << (2*(dom)))
1627
1628 #ifndef __ASSEMBLY__
1629
1630-#ifdef CONFIG_CPU_USE_DOMAINS
1631+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1632 static inline void set_domain(unsigned val)
1633 {
1634 asm volatile(
1635@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1636 isb();
1637 }
1638
1639-#define modify_domain(dom,type) \
1640- do { \
1641- struct thread_info *thread = current_thread_info(); \
1642- unsigned int domain = thread->cpu_domain; \
1643- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1644- thread->cpu_domain = domain | domain_val(dom, type); \
1645- set_domain(thread->cpu_domain); \
1646- } while (0)
1647-
1648+extern void modify_domain(unsigned int dom, unsigned int type);
1649 #else
1650 static inline void set_domain(unsigned val) { }
1651 static inline void modify_domain(unsigned dom, unsigned type) { }
1652diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1653index f4b46d3..abc9b2b 100644
1654--- a/arch/arm/include/asm/elf.h
1655+++ b/arch/arm/include/asm/elf.h
1656@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1657 the loader. We need to make sure that it is out of the way of the program
1658 that it will "exec", and that there is sufficient room for the brk. */
1659
1660-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1661+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1662+
1663+#ifdef CONFIG_PAX_ASLR
1664+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1665+
1666+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1667+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1668+#endif
1669
1670 /* When the program starts, a1 contains a pointer to a function to be
1671 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1672@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1673 extern void elf_set_personality(const struct elf32_hdr *);
1674 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1675
1676-struct mm_struct;
1677-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1678-#define arch_randomize_brk arch_randomize_brk
1679-
1680 #ifdef CONFIG_MMU
1681 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1682 struct linux_binprm;
1683diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1684index de53547..52b9a28 100644
1685--- a/arch/arm/include/asm/fncpy.h
1686+++ b/arch/arm/include/asm/fncpy.h
1687@@ -81,7 +81,9 @@
1688 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1689 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1690 \
1691+ pax_open_kernel(); \
1692 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1693+ pax_close_kernel(); \
1694 flush_icache_range((unsigned long)(dest_buf), \
1695 (unsigned long)(dest_buf) + (size)); \
1696 \
1697diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1698index e42cf59..7b94b8f 100644
1699--- a/arch/arm/include/asm/futex.h
1700+++ b/arch/arm/include/asm/futex.h
1701@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1702 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1703 return -EFAULT;
1704
1705+ pax_open_userland();
1706+
1707 smp_mb();
1708 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1709 "1: ldrex %1, [%4]\n"
1710@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1711 : "cc", "memory");
1712 smp_mb();
1713
1714+ pax_close_userland();
1715+
1716 *uval = val;
1717 return ret;
1718 }
1719@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1720 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1721 return -EFAULT;
1722
1723+ pax_open_userland();
1724+
1725 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1726 "1: " TUSER(ldr) " %1, [%4]\n"
1727 " teq %1, %2\n"
1728@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1729 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1730 : "cc", "memory");
1731
1732+ pax_close_userland();
1733+
1734 *uval = val;
1735 return ret;
1736 }
1737@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 return -EFAULT;
1739
1740 pagefault_disable(); /* implies preempt_disable() */
1741+ pax_open_userland();
1742
1743 switch (op) {
1744 case FUTEX_OP_SET:
1745@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 ret = -ENOSYS;
1747 }
1748
1749+ pax_close_userland();
1750 pagefault_enable(); /* subsumes preempt_enable() */
1751
1752 if (!ret) {
1753diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1754index 83eb2f7..ed77159 100644
1755--- a/arch/arm/include/asm/kmap_types.h
1756+++ b/arch/arm/include/asm/kmap_types.h
1757@@ -4,6 +4,6 @@
1758 /*
1759 * This is the "bare minimum". AIO seems to require this.
1760 */
1761-#define KM_TYPE_NR 16
1762+#define KM_TYPE_NR 17
1763
1764 #endif
1765diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1766index 9e614a1..3302cca 100644
1767--- a/arch/arm/include/asm/mach/dma.h
1768+++ b/arch/arm/include/asm/mach/dma.h
1769@@ -22,7 +22,7 @@ struct dma_ops {
1770 int (*residue)(unsigned int, dma_t *); /* optional */
1771 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1772 const char *type;
1773-};
1774+} __do_const;
1775
1776 struct dma_struct {
1777 void *addr; /* single DMA address */
1778diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1779index 2fe141f..192dc01 100644
1780--- a/arch/arm/include/asm/mach/map.h
1781+++ b/arch/arm/include/asm/mach/map.h
1782@@ -27,13 +27,16 @@ struct map_desc {
1783 #define MT_MINICLEAN 6
1784 #define MT_LOW_VECTORS 7
1785 #define MT_HIGH_VECTORS 8
1786-#define MT_MEMORY 9
1787+#define MT_MEMORY_RWX 9
1788 #define MT_ROM 10
1789-#define MT_MEMORY_NONCACHED 11
1790+#define MT_MEMORY_NONCACHED_RX 11
1791 #define MT_MEMORY_DTCM 12
1792 #define MT_MEMORY_ITCM 13
1793 #define MT_MEMORY_SO 14
1794 #define MT_MEMORY_DMA_READY 15
1795+#define MT_MEMORY_RW 16
1796+#define MT_MEMORY_RX 17
1797+#define MT_MEMORY_NONCACHED_RW 18
1798
1799 #ifdef CONFIG_MMU
1800 extern void iotable_init(struct map_desc *, int);
1801diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1802index f94784f..9a09a4a 100644
1803--- a/arch/arm/include/asm/outercache.h
1804+++ b/arch/arm/include/asm/outercache.h
1805@@ -35,7 +35,7 @@ struct outer_cache_fns {
1806 #endif
1807 void (*set_debug)(unsigned long);
1808 void (*resume)(void);
1809-};
1810+} __no_const;
1811
1812 extern struct outer_cache_fns outer_cache;
1813
1814diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1815index 4355f0e..c229913 100644
1816--- a/arch/arm/include/asm/page.h
1817+++ b/arch/arm/include/asm/page.h
1818@@ -114,7 +114,7 @@ struct cpu_user_fns {
1819 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1820 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1821 unsigned long vaddr, struct vm_area_struct *vma);
1822-};
1823+} __no_const;
1824
1825 #ifdef MULTI_USER
1826 extern struct cpu_user_fns cpu_user;
1827diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1828index 943504f..c37a730 100644
1829--- a/arch/arm/include/asm/pgalloc.h
1830+++ b/arch/arm/include/asm/pgalloc.h
1831@@ -17,6 +17,7 @@
1832 #include <asm/processor.h>
1833 #include <asm/cacheflush.h>
1834 #include <asm/tlbflush.h>
1835+#include <asm/system_info.h>
1836
1837 #define check_pgt_cache() do { } while (0)
1838
1839@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1840 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1841 }
1842
1843+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844+{
1845+ pud_populate(mm, pud, pmd);
1846+}
1847+
1848 #else /* !CONFIG_ARM_LPAE */
1849
1850 /*
1851@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1852 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1853 #define pmd_free(mm, pmd) do { } while (0)
1854 #define pud_populate(mm,pmd,pte) BUG()
1855+#define pud_populate_kernel(mm,pmd,pte) BUG()
1856
1857 #endif /* CONFIG_ARM_LPAE */
1858
1859@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1860 __free_page(pte);
1861 }
1862
1863+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1864+{
1865+#ifdef CONFIG_ARM_LPAE
1866+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1867+#else
1868+ if (addr & SECTION_SIZE)
1869+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1870+ else
1871+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1872+#endif
1873+ flush_pmd_entry(pmdp);
1874+}
1875+
1876 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1877 pmdval_t prot)
1878 {
1879@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1880 static inline void
1881 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1882 {
1883- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1884+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1885 }
1886 #define pmd_pgtable(pmd) pmd_page(pmd)
1887
1888diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1889index 5cfba15..f415e1a 100644
1890--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1891+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1892@@ -20,12 +20,15 @@
1893 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1894 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1895 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1896+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1897 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1898 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1899 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1900+
1901 /*
1902 * - section
1903 */
1904+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1905 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1906 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1907 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1908@@ -37,6 +40,7 @@
1909 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1910 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1911 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1912+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1913
1914 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1915 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1916@@ -66,6 +70,7 @@
1917 * - extended small page/tiny page
1918 */
1919 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1920+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1921 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1922 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1923 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1924diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1925index f97ee02..cc9fe9e 100644
1926--- a/arch/arm/include/asm/pgtable-2level.h
1927+++ b/arch/arm/include/asm/pgtable-2level.h
1928@@ -126,6 +126,9 @@
1929 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1930 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1931
1932+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1933+#define L_PTE_PXN (_AT(pteval_t, 0))
1934+
1935 /*
1936 * These are the memory types, defined to be compatible with
1937 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1938diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1939index 626989f..9d67a33 100644
1940--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1941+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1942@@ -75,6 +75,7 @@
1943 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1944 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1945 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1946+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1947 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1948
1949 /*
1950diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1951index 5689c18..eea12f9 100644
1952--- a/arch/arm/include/asm/pgtable-3level.h
1953+++ b/arch/arm/include/asm/pgtable-3level.h
1954@@ -82,6 +82,7 @@
1955 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1956 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1958+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1959 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1960 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1961 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1962@@ -95,6 +96,7 @@
1963 /*
1964 * To be used in assembly code with the upper page attributes.
1965 */
1966+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1967 #define L_PTE_XN_HIGH (1 << (54 - 32))
1968 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1969
1970diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1971index 1571d12..b8a9b43 100644
1972--- a/arch/arm/include/asm/pgtable.h
1973+++ b/arch/arm/include/asm/pgtable.h
1974@@ -33,6 +33,9 @@
1975 #include <asm/pgtable-2level.h>
1976 #endif
1977
1978+#define ktla_ktva(addr) (addr)
1979+#define ktva_ktla(addr) (addr)
1980+
1981 /*
1982 * Just any arbitrary offset to the start of the vmalloc VM area: the
1983 * current 8MB value just means that there will be a 8MB "hole" after the
1984@@ -48,6 +51,9 @@
1985 #define LIBRARY_TEXT_START 0x0c000000
1986
1987 #ifndef __ASSEMBLY__
1988+extern pteval_t __supported_pte_mask;
1989+extern pmdval_t __supported_pmd_mask;
1990+
1991 extern void __pte_error(const char *file, int line, pte_t);
1992 extern void __pmd_error(const char *file, int line, pmd_t);
1993 extern void __pgd_error(const char *file, int line, pgd_t);
1994@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1995 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1996 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1997
1998+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1999+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2000+
2001+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2002+#include <asm/domain.h>
2003+#include <linux/thread_info.h>
2004+#include <linux/preempt.h>
2005+
2006+static inline int test_domain(int domain, int domaintype)
2007+{
2008+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2009+}
2010+#endif
2011+
2012+#ifdef CONFIG_PAX_KERNEXEC
2013+static inline unsigned long pax_open_kernel(void) {
2014+#ifdef CONFIG_ARM_LPAE
2015+ /* TODO */
2016+#else
2017+ preempt_disable();
2018+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2019+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2020+#endif
2021+ return 0;
2022+}
2023+
2024+static inline unsigned long pax_close_kernel(void) {
2025+#ifdef CONFIG_ARM_LPAE
2026+ /* TODO */
2027+#else
2028+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2029+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2030+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2031+ preempt_enable_no_resched();
2032+#endif
2033+ return 0;
2034+}
2035+#else
2036+static inline unsigned long pax_open_kernel(void) { return 0; }
2037+static inline unsigned long pax_close_kernel(void) { return 0; }
2038+#endif
2039+
2040 /*
2041 * This is the lowest virtual address we can permit any user space
2042 * mapping to be mapped at. This is particularly important for
2043@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2044 /*
2045 * The pgprot_* and protection_map entries will be fixed up in runtime
2046 * to include the cachable and bufferable bits based on memory policy,
2047- * as well as any architecture dependent bits like global/ASID and SMP
2048- * shared mapping bits.
2049+ * as well as any architecture dependent bits like global/ASID, PXN,
2050+ * and SMP shared mapping bits.
2051 */
2052 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2053
2054@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2055 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2056 {
2057 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2058- L_PTE_NONE | L_PTE_VALID;
2059+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2060 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2061 return pte;
2062 }
2063diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2064index 5324c11..bcae5f0 100644
2065--- a/arch/arm/include/asm/proc-fns.h
2066+++ b/arch/arm/include/asm/proc-fns.h
2067@@ -75,7 +75,7 @@ extern struct processor {
2068 unsigned int suspend_size;
2069 void (*do_suspend)(void *);
2070 void (*do_resume)(void *);
2071-} processor;
2072+} __do_const processor;
2073
2074 #ifndef MULTI_CPU
2075 extern void cpu_proc_init(void);
2076diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2077index c4ae171..ea0c0c2 100644
2078--- a/arch/arm/include/asm/psci.h
2079+++ b/arch/arm/include/asm/psci.h
2080@@ -29,7 +29,7 @@ struct psci_operations {
2081 int (*cpu_off)(struct psci_power_state state);
2082 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2083 int (*migrate)(unsigned long cpuid);
2084-};
2085+} __no_const;
2086
2087 extern struct psci_operations psci_ops;
2088 extern struct smp_operations psci_smp_ops;
2089diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2090index a8cae71c..65dd797 100644
2091--- a/arch/arm/include/asm/smp.h
2092+++ b/arch/arm/include/asm/smp.h
2093@@ -110,7 +110,7 @@ struct smp_operations {
2094 int (*cpu_disable)(unsigned int cpu);
2095 #endif
2096 #endif
2097-};
2098+} __no_const;
2099
2100 /*
2101 * set platform specific SMP operations
2102diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2103index df5e13d..97efb82 100644
2104--- a/arch/arm/include/asm/thread_info.h
2105+++ b/arch/arm/include/asm/thread_info.h
2106@@ -88,9 +88,9 @@ struct thread_info {
2107 .flags = 0, \
2108 .preempt_count = INIT_PREEMPT_COUNT, \
2109 .addr_limit = KERNEL_DS, \
2110- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2111- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2112- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2113+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2114+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2115+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2116 .restart_block = { \
2117 .fn = do_no_restart_syscall, \
2118 }, \
2119@@ -163,7 +163,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2120 #define TIF_SYSCALL_AUDIT 9
2121 #define TIF_SYSCALL_TRACEPOINT 10
2122 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2123-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2124+/* within 8 bits of TIF_SYSCALL_TRACE
2125+ * to meet flexible second operand requirements
2126+ */
2127+#define TIF_GRSEC_SETXID 12
2128+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2129 #define TIF_USING_IWMMXT 17
2130 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2131 #define TIF_RESTORE_SIGMASK 20
2132@@ -176,10 +180,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2134 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2135 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2136+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2137
2138 /* Checks for any syscall work in entry-common.S */
2139 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2140- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2141+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2142
2143 /*
2144 * Change these and you break ASM code in entry-common.S
2145diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2146index 72abdc5..9eba222 100644
2147--- a/arch/arm/include/asm/uaccess.h
2148+++ b/arch/arm/include/asm/uaccess.h
2149@@ -18,6 +18,7 @@
2150 #include <asm/domain.h>
2151 #include <asm/unified.h>
2152 #include <asm/compiler.h>
2153+#include <asm/pgtable.h>
2154
2155 #if __LINUX_ARM_ARCH__ < 6
2156 #include <asm-generic/uaccess-unaligned.h>
2157@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2158 static inline void set_fs(mm_segment_t fs)
2159 {
2160 current_thread_info()->addr_limit = fs;
2161- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2162+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2163 }
2164
2165 #define segment_eq(a,b) ((a) == (b))
2166
2167+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2168+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2169+
2170+static inline void pax_open_userland(void)
2171+{
2172+
2173+#ifdef CONFIG_PAX_MEMORY_UDEREF
2174+ if (segment_eq(get_fs(), USER_DS)) {
2175+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2176+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2177+ }
2178+#endif
2179+
2180+}
2181+
2182+static inline void pax_close_userland(void)
2183+{
2184+
2185+#ifdef CONFIG_PAX_MEMORY_UDEREF
2186+ if (segment_eq(get_fs(), USER_DS)) {
2187+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2188+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2189+ }
2190+#endif
2191+
2192+}
2193+
2194 #define __addr_ok(addr) ({ \
2195 unsigned long flag; \
2196 __asm__("cmp %2, %0; movlo %0, #0" \
2197@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2198
2199 #define get_user(x,p) \
2200 ({ \
2201+ int __e; \
2202 might_fault(); \
2203- __get_user_check(x,p); \
2204+ pax_open_userland(); \
2205+ __e = __get_user_check(x,p); \
2206+ pax_close_userland(); \
2207+ __e; \
2208 })
2209
2210 extern int __put_user_1(void *, unsigned int);
2211@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2212
2213 #define put_user(x,p) \
2214 ({ \
2215+ int __e; \
2216 might_fault(); \
2217- __put_user_check(x,p); \
2218+ pax_open_userland(); \
2219+ __e = __put_user_check(x,p); \
2220+ pax_close_userland(); \
2221+ __e; \
2222 })
2223
2224 #else /* CONFIG_MMU */
2225@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2226 #define __get_user(x,ptr) \
2227 ({ \
2228 long __gu_err = 0; \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),__gu_err); \
2231+ pax_close_userland(); \
2232 __gu_err; \
2233 })
2234
2235 #define __get_user_error(x,ptr,err) \
2236 ({ \
2237+ pax_open_userland(); \
2238 __get_user_err((x),(ptr),err); \
2239+ pax_close_userland(); \
2240 (void) 0; \
2241 })
2242
2243@@ -319,13 +359,17 @@ do { \
2244 #define __put_user(x,ptr) \
2245 ({ \
2246 long __pu_err = 0; \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),__pu_err); \
2249+ pax_close_userland(); \
2250 __pu_err; \
2251 })
2252
2253 #define __put_user_error(x,ptr,err) \
2254 ({ \
2255+ pax_open_userland(); \
2256 __put_user_err((x),(ptr),err); \
2257+ pax_close_userland(); \
2258 (void) 0; \
2259 })
2260
2261@@ -425,11 +469,44 @@ do { \
2262
2263
2264 #ifdef CONFIG_MMU
2265-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2266-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2267+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2268+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2269+
2270+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2271+{
2272+ unsigned long ret;
2273+
2274+ check_object_size(to, n, false);
2275+ pax_open_userland();
2276+ ret = ___copy_from_user(to, from, n);
2277+ pax_close_userland();
2278+ return ret;
2279+}
2280+
2281+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2282+{
2283+ unsigned long ret;
2284+
2285+ check_object_size(from, n, true);
2286+ pax_open_userland();
2287+ ret = ___copy_to_user(to, from, n);
2288+ pax_close_userland();
2289+ return ret;
2290+}
2291+
2292 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2293-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2294+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2295 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2296+
2297+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2298+{
2299+ unsigned long ret;
2300+ pax_open_userland();
2301+ ret = ___clear_user(addr, n);
2302+ pax_close_userland();
2303+ return ret;
2304+}
2305+
2306 #else
2307 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2308 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2309@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2310
2311 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2312 {
2313+ if ((long)n < 0)
2314+ return n;
2315+
2316 if (access_ok(VERIFY_READ, from, n))
2317 n = __copy_from_user(to, from, n);
2318 else /* security hole - plug it */
2319@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2320
2321 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2322 {
2323+ if ((long)n < 0)
2324+ return n;
2325+
2326 if (access_ok(VERIFY_WRITE, to, n))
2327 n = __copy_to_user(to, from, n);
2328 return n;
2329diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2330index 5af0ed1..cea83883 100644
2331--- a/arch/arm/include/uapi/asm/ptrace.h
2332+++ b/arch/arm/include/uapi/asm/ptrace.h
2333@@ -92,7 +92,7 @@
2334 * ARMv7 groups of PSR bits
2335 */
2336 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2337-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2338+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2339 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2340 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2341
2342diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2343index 60d3b73..e5a0f22 100644
2344--- a/arch/arm/kernel/armksyms.c
2345+++ b/arch/arm/kernel/armksyms.c
2346@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2347
2348 /* networking */
2349 EXPORT_SYMBOL(csum_partial);
2350-EXPORT_SYMBOL(csum_partial_copy_from_user);
2351+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2352 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2353 EXPORT_SYMBOL(__csum_ipv6_magic);
2354
2355@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2356 #ifdef CONFIG_MMU
2357 EXPORT_SYMBOL(copy_page);
2358
2359-EXPORT_SYMBOL(__copy_from_user);
2360-EXPORT_SYMBOL(__copy_to_user);
2361-EXPORT_SYMBOL(__clear_user);
2362+EXPORT_SYMBOL(___copy_from_user);
2363+EXPORT_SYMBOL(___copy_to_user);
2364+EXPORT_SYMBOL(___clear_user);
2365
2366 EXPORT_SYMBOL(__get_user_1);
2367 EXPORT_SYMBOL(__get_user_2);
2368diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2369index ec3e5cf..b450ee3 100644
2370--- a/arch/arm/kernel/entry-armv.S
2371+++ b/arch/arm/kernel/entry-armv.S
2372@@ -47,6 +47,87 @@
2373 9997:
2374 .endm
2375
2376+ .macro pax_enter_kernel
2377+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2378+ @ make aligned space for saved DACR
2379+ sub sp, sp, #8
2380+ @ save regs
2381+ stmdb sp!, {r1, r2}
2382+ @ read DACR from cpu_domain into r1
2383+ mov r2, sp
2384+ @ assume 8K pages, since we have to split the immediate in two
2385+ bic r2, r2, #(0x1fc0)
2386+ bic r2, r2, #(0x3f)
2387+ ldr r1, [r2, #TI_CPU_DOMAIN]
2388+ @ store old DACR on stack
2389+ str r1, [sp, #8]
2390+#ifdef CONFIG_PAX_KERNEXEC
2391+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2392+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2393+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2394+#endif
2395+#ifdef CONFIG_PAX_MEMORY_UDEREF
2396+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2397+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2398+#endif
2399+ @ write r1 to current_thread_info()->cpu_domain
2400+ str r1, [r2, #TI_CPU_DOMAIN]
2401+ @ write r1 to DACR
2402+ mcr p15, 0, r1, c3, c0, 0
2403+ @ instruction sync
2404+ instr_sync
2405+ @ restore regs
2406+ ldmia sp!, {r1, r2}
2407+#endif
2408+ .endm
2409+
2410+ .macro pax_open_userland
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ save regs
2413+ stmdb sp!, {r0, r1}
2414+ @ read DACR from cpu_domain into r1
2415+ mov r0, sp
2416+ @ assume 8K pages, since we have to split the immediate in two
2417+ bic r0, r0, #(0x1fc0)
2418+ bic r0, r0, #(0x3f)
2419+ ldr r1, [r0, #TI_CPU_DOMAIN]
2420+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2423+ @ write r1 to current_thread_info()->cpu_domain
2424+ str r1, [r0, #TI_CPU_DOMAIN]
2425+ @ write r1 to DACR
2426+ mcr p15, 0, r1, c3, c0, 0
2427+ @ instruction sync
2428+ instr_sync
2429+ @ restore regs
2430+ ldmia sp!, {r0, r1}
2431+#endif
2432+ .endm
2433+
2434+ .macro pax_close_userland
2435+#ifdef CONFIG_PAX_MEMORY_UDEREF
2436+ @ save regs
2437+ stmdb sp!, {r0, r1}
2438+ @ read DACR from cpu_domain into r1
2439+ mov r0, sp
2440+ @ assume 8K pages, since we have to split the immediate in two
2441+ bic r0, r0, #(0x1fc0)
2442+ bic r0, r0, #(0x3f)
2443+ ldr r1, [r0, #TI_CPU_DOMAIN]
2444+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2445+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2446+ @ write r1 to current_thread_info()->cpu_domain
2447+ str r1, [r0, #TI_CPU_DOMAIN]
2448+ @ write r1 to DACR
2449+ mcr p15, 0, r1, c3, c0, 0
2450+ @ instruction sync
2451+ instr_sync
2452+ @ restore regs
2453+ ldmia sp!, {r0, r1}
2454+#endif
2455+ .endm
2456+
2457 .macro pabt_helper
2458 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2459 #ifdef MULTI_PABORT
2460@@ -89,11 +170,15 @@
2461 * Invalid mode handlers
2462 */
2463 .macro inv_entry, reason
2464+
2465+ pax_enter_kernel
2466+
2467 sub sp, sp, #S_FRAME_SIZE
2468 ARM( stmib sp, {r1 - lr} )
2469 THUMB( stmia sp, {r0 - r12} )
2470 THUMB( str sp, [sp, #S_SP] )
2471 THUMB( str lr, [sp, #S_LR] )
2472+
2473 mov r1, #\reason
2474 .endm
2475
2476@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2477 .macro svc_entry, stack_hole=0
2478 UNWIND(.fnstart )
2479 UNWIND(.save {r0 - pc} )
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2484+
2485 #ifdef CONFIG_THUMB2_KERNEL
2486 SPFIX( str r0, [sp] ) @ temporarily saved
2487 SPFIX( mov r0, sp )
2488@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2489 ldmia r0, {r3 - r5}
2490 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2491 mov r6, #-1 @ "" "" "" ""
2492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2493+ @ offset sp by 8 as done in pax_enter_kernel
2494+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2495+#else
2496 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497+#endif
2498 SPFIX( addeq r2, r2, #4 )
2499 str r3, [sp, #-4]! @ save the "real" r0 copied
2500 @ from the exception stack
2501@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2502 .macro usr_entry
2503 UNWIND(.fnstart )
2504 UNWIND(.cantunwind ) @ don't unwind the user space
2505+
2506+ pax_enter_kernel_user
2507+
2508 sub sp, sp, #S_FRAME_SIZE
2509 ARM( stmib sp, {r1 - r12} )
2510 THUMB( stmia sp, {r0 - r12} )
2511@@ -416,7 +513,9 @@ __und_usr:
2512 tst r3, #PSR_T_BIT @ Thumb mode?
2513 bne __und_usr_thumb
2514 sub r4, r2, #4 @ ARM instr at LR - 4
2515+ pax_open_userland
2516 1: ldrt r0, [r4]
2517+ pax_close_userland
2518 #ifdef CONFIG_CPU_ENDIAN_BE8
2519 rev r0, r0 @ little endian instruction
2520 #endif
2521@@ -451,10 +550,14 @@ __und_usr_thumb:
2522 */
2523 .arch armv6t2
2524 #endif
2525+ pax_open_userland
2526 2: ldrht r5, [r4]
2527+ pax_close_userland
2528 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2529 blo __und_usr_fault_16 @ 16bit undefined instruction
2530+ pax_open_userland
2531 3: ldrht r0, [r2]
2532+ pax_close_userland
2533 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2534 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2535 orr r0, r0, r5, lsl #16
2536@@ -483,7 +586,8 @@ ENDPROC(__und_usr)
2537 */
2538 .pushsection .fixup, "ax"
2539 .align 2
2540-4: mov pc, r9
2541+4: pax_close_userland
2542+ mov pc, r9
2543 .popsection
2544 .pushsection __ex_table,"a"
2545 .long 1b, 4b
2546@@ -693,7 +797,7 @@ ENTRY(__switch_to)
2547 THUMB( str lr, [ip], #4 )
2548 ldr r4, [r2, #TI_TP_VALUE]
2549 ldr r5, [r2, #TI_TP_VALUE + 4]
2550-#ifdef CONFIG_CPU_USE_DOMAINS
2551+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2552 ldr r6, [r2, #TI_CPU_DOMAIN]
2553 #endif
2554 switch_tls r1, r4, r5, r3, r7
2555@@ -702,7 +806,7 @@ ENTRY(__switch_to)
2556 ldr r8, =__stack_chk_guard
2557 ldr r7, [r7, #TSK_STACK_CANARY]
2558 #endif
2559-#ifdef CONFIG_CPU_USE_DOMAINS
2560+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2561 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2562 #endif
2563 mov r5, r0
2564diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2565index bc6bd96..bd026cb 100644
2566--- a/arch/arm/kernel/entry-common.S
2567+++ b/arch/arm/kernel/entry-common.S
2568@@ -10,18 +10,46 @@
2569
2570 #include <asm/unistd.h>
2571 #include <asm/ftrace.h>
2572+#include <asm/domain.h>
2573 #include <asm/unwind.h>
2574
2575+#include "entry-header.S"
2576+
2577 #ifdef CONFIG_NEED_RET_TO_USER
2578 #include <mach/entry-macro.S>
2579 #else
2580 .macro arch_ret_to_user, tmp1, tmp2
2581+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2582+ @ save regs
2583+ stmdb sp!, {r1, r2}
2584+ @ read DACR from cpu_domain into r1
2585+ mov r2, sp
2586+ @ assume 8K pages, since we have to split the immediate in two
2587+ bic r2, r2, #(0x1fc0)
2588+ bic r2, r2, #(0x3f)
2589+ ldr r1, [r2, #TI_CPU_DOMAIN]
2590+#ifdef CONFIG_PAX_KERNEXEC
2591+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2592+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2593+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2594+#endif
2595+#ifdef CONFIG_PAX_MEMORY_UDEREF
2596+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2597+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2598+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2599+#endif
2600+ @ write r1 to current_thread_info()->cpu_domain
2601+ str r1, [r2, #TI_CPU_DOMAIN]
2602+ @ write r1 to DACR
2603+ mcr p15, 0, r1, c3, c0, 0
2604+ @ instruction sync
2605+ instr_sync
2606+ @ restore regs
2607+ ldmia sp!, {r1, r2}
2608+#endif
2609 .endm
2610 #endif
2611
2612-#include "entry-header.S"
2613-
2614-
2615 .align 5
2616 /*
2617 * This is the fast syscall return path. We do as little as
2618@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2619 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2620 #endif
2621
2622+ /*
2623+ * do this here to avoid a performance hit of wrapping the code above
2624+ * that directly dereferences userland to parse the SWI instruction
2625+ */
2626+ pax_enter_kernel_user
2627+
2628 adr tbl, sys_call_table @ load syscall table pointer
2629
2630 #if defined(CONFIG_OABI_COMPAT)
2631diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2632index 39f89fb..d612bd9 100644
2633--- a/arch/arm/kernel/entry-header.S
2634+++ b/arch/arm/kernel/entry-header.S
2635@@ -184,6 +184,60 @@
2636 msr cpsr_c, \rtemp @ switch back to the SVC mode
2637 .endm
2638
2639+ .macro pax_enter_kernel_user
2640+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2641+ @ save regs
2642+ stmdb sp!, {r0, r1}
2643+ @ read DACR from cpu_domain into r1
2644+ mov r0, sp
2645+ @ assume 8K pages, since we have to split the immediate in two
2646+ bic r0, r0, #(0x1fc0)
2647+ bic r0, r0, #(0x3f)
2648+ ldr r1, [r0, #TI_CPU_DOMAIN]
2649+#ifdef CONFIG_PAX_MEMORY_UDEREF
2650+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2651+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2652+#endif
2653+#ifdef CONFIG_PAX_KERNEXEC
2654+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2655+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2656+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2657+#endif
2658+ @ write r1 to current_thread_info()->cpu_domain
2659+ str r1, [r0, #TI_CPU_DOMAIN]
2660+ @ write r1 to DACR
2661+ mcr p15, 0, r1, c3, c0, 0
2662+ @ instruction sync
2663+ instr_sync
2664+ @ restore regs
2665+ ldmia sp!, {r0, r1}
2666+#endif
2667+ .endm
2668+
2669+ .macro pax_exit_kernel
2670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671+ @ save regs
2672+ stmdb sp!, {r0, r1}
2673+ @ read old DACR from stack into r1
2674+ ldr r1, [sp, #(8 + S_SP)]
2675+ sub r1, r1, #8
2676+ ldr r1, [r1]
2677+
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ mov r0, sp
2680+ @ assume 8K pages, since we have to split the immediate in two
2681+ bic r0, r0, #(0x1fc0)
2682+ bic r0, r0, #(0x3f)
2683+ str r1, [r0, #TI_CPU_DOMAIN]
2684+ @ write r1 to DACR
2685+ mcr p15, 0, r1, c3, c0, 0
2686+ @ instruction sync
2687+ instr_sync
2688+ @ restore regs
2689+ ldmia sp!, {r0, r1}
2690+#endif
2691+ .endm
2692+
2693 #ifndef CONFIG_THUMB2_KERNEL
2694 .macro svc_exit, rpsr, irq = 0
2695 .if \irq != 0
2696@@ -203,6 +257,9 @@
2697 blne trace_hardirqs_off
2698 #endif
2699 .endif
2700+
2701+ pax_exit_kernel
2702+
2703 msr spsr_cxsf, \rpsr
2704 #if defined(CONFIG_CPU_V6)
2705 ldr r0, [sp]
2706@@ -266,6 +323,9 @@
2707 blne trace_hardirqs_off
2708 #endif
2709 .endif
2710+
2711+ pax_exit_kernel
2712+
2713 ldr lr, [sp, #S_SP] @ top of the stack
2714 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2715 clrex @ clear the exclusive monitor
2716diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2717index 918875d..cd5fa27 100644
2718--- a/arch/arm/kernel/fiq.c
2719+++ b/arch/arm/kernel/fiq.c
2720@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2721 void *base = vectors_page;
2722 unsigned offset = FIQ_OFFSET;
2723
2724+ pax_open_kernel();
2725 memcpy(base + offset, start, length);
2726+ pax_close_kernel();
2727+
2728 if (!cache_is_vipt_nonaliasing())
2729 flush_icache_range((unsigned long)base + offset, offset +
2730 length);
2731diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2732index 476de57..4857a76 100644
2733--- a/arch/arm/kernel/head.S
2734+++ b/arch/arm/kernel/head.S
2735@@ -52,7 +52,9 @@
2736 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2737
2738 .macro pgtbl, rd, phys
2739- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2740+ mov \rd, #TEXT_OFFSET
2741+ sub \rd, #PG_DIR_SIZE
2742+ add \rd, \rd, \phys
2743 .endm
2744
2745 /*
2746@@ -432,7 +434,7 @@ __enable_mmu:
2747 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2748 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2749 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2750- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2751+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2752 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2753 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2754 #endif
2755diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2756index 084dc88..fce4e68 100644
2757--- a/arch/arm/kernel/module.c
2758+++ b/arch/arm/kernel/module.c
2759@@ -37,12 +37,39 @@
2760 #endif
2761
2762 #ifdef CONFIG_MMU
2763-void *module_alloc(unsigned long size)
2764+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2765 {
2766+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2767+ return NULL;
2768 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2769- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2770+ GFP_KERNEL, prot, -1,
2771 __builtin_return_address(0));
2772 }
2773+
2774+void *module_alloc(unsigned long size)
2775+{
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+ return __module_alloc(size, PAGE_KERNEL);
2779+#else
2780+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2781+#endif
2782+
2783+}
2784+
2785+#ifdef CONFIG_PAX_KERNEXEC
2786+void module_free_exec(struct module *mod, void *module_region)
2787+{
2788+ module_free(mod, module_region);
2789+}
2790+EXPORT_SYMBOL(module_free_exec);
2791+
2792+void *module_alloc_exec(unsigned long size)
2793+{
2794+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2795+}
2796+EXPORT_SYMBOL(module_alloc_exec);
2797+#endif
2798 #endif
2799
2800 int
2801diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2802index 07314af..c46655c 100644
2803--- a/arch/arm/kernel/patch.c
2804+++ b/arch/arm/kernel/patch.c
2805@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2807 int size;
2808
2809+ pax_open_kernel();
2810 if (thumb2 && __opcode_is_thumb16(insn)) {
2811 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2812 size = sizeof(u16);
2813@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2814 *(u32 *)addr = insn;
2815 size = sizeof(u32);
2816 }
2817+ pax_close_kernel();
2818
2819 flush_icache_range((uintptr_t)(addr),
2820 (uintptr_t)(addr) + size);
2821diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2822index 94f6b05..efd7312 100644
2823--- a/arch/arm/kernel/process.c
2824+++ b/arch/arm/kernel/process.c
2825@@ -217,6 +217,7 @@ void machine_power_off(void)
2826
2827 if (pm_power_off)
2828 pm_power_off();
2829+ BUG();
2830 }
2831
2832 /*
2833@@ -230,7 +231,7 @@ void machine_power_off(void)
2834 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2835 * to use. Implementing such co-ordination would be essentially impossible.
2836 */
2837-void machine_restart(char *cmd)
2838+__noreturn void machine_restart(char *cmd)
2839 {
2840 local_irq_disable();
2841 smp_send_stop();
2842@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2843
2844 show_regs_print_info(KERN_DEFAULT);
2845
2846- print_symbol("PC is at %s\n", instruction_pointer(regs));
2847- print_symbol("LR is at %s\n", regs->ARM_lr);
2848+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2849+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2850 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2851 "sp : %08lx ip : %08lx fp : %08lx\n",
2852 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2853@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2854 return 0;
2855 }
2856
2857-unsigned long arch_randomize_brk(struct mm_struct *mm)
2858-{
2859- unsigned long range_end = mm->brk + 0x02000000;
2860- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2861-}
2862-
2863 #ifdef CONFIG_MMU
2864 #ifdef CONFIG_KUSER_HELPERS
2865 /*
2866@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2867
2868 static int __init gate_vma_init(void)
2869 {
2870- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2871+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2872 return 0;
2873 }
2874 arch_initcall(gate_vma_init);
2875@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2876
2877 const char *arch_vma_name(struct vm_area_struct *vma)
2878 {
2879- return is_gate_vma(vma) ? "[vectors]" :
2880- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2881- "[sigpage]" : NULL;
2882+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2883 }
2884
2885-static struct page *signal_page;
2886-extern struct page *get_signal_page(void);
2887-
2888 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2889 {
2890 struct mm_struct *mm = current->mm;
2891- unsigned long addr;
2892- int ret;
2893-
2894- if (!signal_page)
2895- signal_page = get_signal_page();
2896- if (!signal_page)
2897- return -ENOMEM;
2898
2899 down_write(&mm->mmap_sem);
2900- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2901- if (IS_ERR_VALUE(addr)) {
2902- ret = addr;
2903- goto up_fail;
2904- }
2905-
2906- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2907- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2908- &signal_page);
2909-
2910- if (ret == 0)
2911- mm->context.sigpage = addr;
2912-
2913- up_fail:
2914+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2915 up_write(&mm->mmap_sem);
2916- return ret;
2917+ return 0;
2918 }
2919 #endif
2920diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2921index 4693188..4596c5e 100644
2922--- a/arch/arm/kernel/psci.c
2923+++ b/arch/arm/kernel/psci.c
2924@@ -24,7 +24,7 @@
2925 #include <asm/opcodes-virt.h>
2926 #include <asm/psci.h>
2927
2928-struct psci_operations psci_ops;
2929+struct psci_operations psci_ops __read_only;
2930
2931 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2932
2933diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2934index 0dd3b79..e018f64 100644
2935--- a/arch/arm/kernel/ptrace.c
2936+++ b/arch/arm/kernel/ptrace.c
2937@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2938 return current_thread_info()->syscall;
2939 }
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+extern void gr_delayed_cred_worker(void);
2943+#endif
2944+
2945 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2946 {
2947 current_thread_info()->syscall = scno;
2948
2949+#ifdef CONFIG_GRKERNSEC_SETXID
2950+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2951+ gr_delayed_cred_worker();
2952+#endif
2953+
2954 /* Do the secure computing check first; failures should be fast. */
2955 if (secure_computing(scno) == -1)
2956 return -1;
2957diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2958index 0e1e2b3..c0e821d 100644
2959--- a/arch/arm/kernel/setup.c
2960+++ b/arch/arm/kernel/setup.c
2961@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2962 unsigned int elf_hwcap __read_mostly;
2963 EXPORT_SYMBOL(elf_hwcap);
2964
2965+pteval_t __supported_pte_mask __read_only;
2966+pmdval_t __supported_pmd_mask __read_only;
2967
2968 #ifdef MULTI_CPU
2969-struct processor processor __read_mostly;
2970+struct processor processor;
2971 #endif
2972 #ifdef MULTI_TLB
2973-struct cpu_tlb_fns cpu_tlb __read_mostly;
2974+struct cpu_tlb_fns cpu_tlb __read_only;
2975 #endif
2976 #ifdef MULTI_USER
2977-struct cpu_user_fns cpu_user __read_mostly;
2978+struct cpu_user_fns cpu_user __read_only;
2979 #endif
2980 #ifdef MULTI_CACHE
2981-struct cpu_cache_fns cpu_cache __read_mostly;
2982+struct cpu_cache_fns cpu_cache __read_only;
2983 #endif
2984 #ifdef CONFIG_OUTER_CACHE
2985-struct outer_cache_fns outer_cache __read_mostly;
2986+struct outer_cache_fns outer_cache __read_only;
2987 EXPORT_SYMBOL(outer_cache);
2988 #endif
2989
2990@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2991 asm("mrc p15, 0, %0, c0, c1, 4"
2992 : "=r" (mmfr0));
2993 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2994- (mmfr0 & 0x000000f0) >= 0x00000030)
2995+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2996 cpu_arch = CPU_ARCH_ARMv7;
2997- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2998+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2999+ __supported_pte_mask |= L_PTE_PXN;
3000+ __supported_pmd_mask |= PMD_PXNTABLE;
3001+ }
3002+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3003 (mmfr0 & 0x000000f0) == 0x00000020)
3004 cpu_arch = CPU_ARCH_ARMv6;
3005 else
3006@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3007 __cpu_architecture = __get_cpu_architecture();
3008
3009 #ifdef MULTI_CPU
3010- processor = *list->proc;
3011+ memcpy((void *)&processor, list->proc, sizeof processor);
3012 #endif
3013 #ifdef MULTI_TLB
3014 cpu_tlb = *list->tlb;
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index ab33042..11248a8 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3020 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3021 };
3022
3023-static unsigned long signal_return_offset;
3024-
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032- retcode = mm->context.sigpage + signal_return_offset +
3033- (idx << 2) + thumb;
3034+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042-
3043-struct page *get_signal_page(void)
3044-{
3045- unsigned long ptr;
3046- unsigned offset;
3047- struct page *page;
3048- void *addr;
3049-
3050- page = alloc_pages(GFP_KERNEL, 0);
3051-
3052- if (!page)
3053- return NULL;
3054-
3055- addr = page_address(page);
3056-
3057- /* Give the signal return code some randomness */
3058- offset = 0x200 + (get_random_int() & 0x7fc);
3059- signal_return_offset = offset;
3060-
3061- /*
3062- * Copy signal return handlers into the vector page, and
3063- * set sigreturn to be a pointer to these.
3064- */
3065- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066-
3067- ptr = (unsigned long)addr + offset;
3068- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069-
3070- return page;
3071-}
3072diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073index 72024ea..ae302dd 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -70,7 +70,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080-static struct smp_operations smp_ops;
3081+static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3086index 8fcda14..4512b9d 100644
3087--- a/arch/arm/kernel/traps.c
3088+++ b/arch/arm/kernel/traps.c
3089@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3090 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3091 {
3092 #ifdef CONFIG_KALLSYMS
3093- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3094+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3095 #else
3096 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3097 #endif
3098@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3099 static int die_owner = -1;
3100 static unsigned int die_nest_count;
3101
3102+extern void gr_handle_kernel_exploit(void);
3103+
3104 static unsigned long oops_begin(void)
3105 {
3106 int cpu;
3107@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3108 panic("Fatal exception in interrupt");
3109 if (panic_on_oops)
3110 panic("Fatal exception");
3111+
3112+ gr_handle_kernel_exploit();
3113+
3114 if (signr)
3115 do_exit(signr);
3116 }
3117@@ -628,7 +633,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3118 * The user helper at 0xffff0fe0 must be used instead.
3119 * (see entry-armv.S for details)
3120 */
3121+ pax_open_kernel();
3122 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3123+ pax_close_kernel();
3124 }
3125 return 0;
3126
3127@@ -885,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3128 kuser_init(vectors_base);
3129
3130 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3131- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3132+
3133+#ifndef CONFIG_PAX_MEMORY_UDEREF
3134+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3135+#endif
3136+
3137 #else /* ifndef CONFIG_CPU_V7M */
3138 /*
3139 * on V7-M there is no need to copy the vector table to a dedicated
3140diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3141index 7bcee5c..e2f3249 100644
3142--- a/arch/arm/kernel/vmlinux.lds.S
3143+++ b/arch/arm/kernel/vmlinux.lds.S
3144@@ -8,7 +8,11 @@
3145 #include <asm/thread_info.h>
3146 #include <asm/memory.h>
3147 #include <asm/page.h>
3148-
3149+
3150+#ifdef CONFIG_PAX_KERNEXEC
3151+#include <asm/pgtable.h>
3152+#endif
3153+
3154 #define PROC_INFO \
3155 . = ALIGN(4); \
3156 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3157@@ -34,7 +38,7 @@
3158 #endif
3159
3160 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3161- defined(CONFIG_GENERIC_BUG)
3162+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3163 #define ARM_EXIT_KEEP(x) x
3164 #define ARM_EXIT_DISCARD(x)
3165 #else
3166@@ -90,6 +94,11 @@ SECTIONS
3167 _text = .;
3168 HEAD_TEXT
3169 }
3170+
3171+#ifdef CONFIG_PAX_KERNEXEC
3172+ . = ALIGN(1<<SECTION_SHIFT);
3173+#endif
3174+
3175 .text : { /* Real text segment */
3176 _stext = .; /* Text and read-only data */
3177 __exception_text_start = .;
3178@@ -112,6 +121,8 @@ SECTIONS
3179 ARM_CPU_KEEP(PROC_INFO)
3180 }
3181
3182+ _etext = .; /* End of text section */
3183+
3184 RO_DATA(PAGE_SIZE)
3185
3186 . = ALIGN(4);
3187@@ -142,7 +153,9 @@ SECTIONS
3188
3189 NOTES
3190
3191- _etext = .; /* End of text and rodata section */
3192+#ifdef CONFIG_PAX_KERNEXEC
3193+ . = ALIGN(1<<SECTION_SHIFT);
3194+#endif
3195
3196 #ifndef CONFIG_XIP_KERNEL
3197 . = ALIGN(PAGE_SIZE);
3198@@ -220,6 +233,11 @@ SECTIONS
3199 . = PAGE_OFFSET + TEXT_OFFSET;
3200 #else
3201 __init_end = .;
3202+
3203+#ifdef CONFIG_PAX_KERNEXEC
3204+ . = ALIGN(1<<SECTION_SHIFT);
3205+#endif
3206+
3207 . = ALIGN(THREAD_SIZE);
3208 __data_loc = .;
3209 #endif
3210diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3211index 9c697db..115237f 100644
3212--- a/arch/arm/kvm/arm.c
3213+++ b/arch/arm/kvm/arm.c
3214@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3215 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3216
3217 /* The VMID used in the VTTBR */
3218-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3219+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3220 static u8 kvm_next_vmid;
3221 static DEFINE_SPINLOCK(kvm_vmid_lock);
3222
3223@@ -396,7 +396,7 @@ void force_vm_exit(const cpumask_t *mask)
3224 */
3225 static bool need_new_vmid_gen(struct kvm *kvm)
3226 {
3227- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3228+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3229 }
3230
3231 /**
3232@@ -429,7 +429,7 @@ static void update_vttbr(struct kvm *kvm)
3233
3234 /* First user of a new VMID generation? */
3235 if (unlikely(kvm_next_vmid == 0)) {
3236- atomic64_inc(&kvm_vmid_gen);
3237+ atomic64_inc_unchecked(&kvm_vmid_gen);
3238 kvm_next_vmid = 1;
3239
3240 /*
3241@@ -446,7 +446,7 @@ static void update_vttbr(struct kvm *kvm)
3242 kvm_call_hyp(__kvm_flush_vm_context);
3243 }
3244
3245- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3246+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3247 kvm->arch.vmid = kvm_next_vmid;
3248 kvm_next_vmid++;
3249
3250diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3251index 14a0d98..7771a7d 100644
3252--- a/arch/arm/lib/clear_user.S
3253+++ b/arch/arm/lib/clear_user.S
3254@@ -12,14 +12,14 @@
3255
3256 .text
3257
3258-/* Prototype: int __clear_user(void *addr, size_t sz)
3259+/* Prototype: int ___clear_user(void *addr, size_t sz)
3260 * Purpose : clear some user memory
3261 * Params : addr - user memory address to clear
3262 * : sz - number of bytes to clear
3263 * Returns : number of bytes NOT cleared
3264 */
3265 ENTRY(__clear_user_std)
3266-WEAK(__clear_user)
3267+WEAK(___clear_user)
3268 stmfd sp!, {r1, lr}
3269 mov r2, #0
3270 cmp r1, #4
3271@@ -44,7 +44,7 @@ WEAK(__clear_user)
3272 USER( strnebt r2, [r0])
3273 mov r0, #0
3274 ldmfd sp!, {r1, pc}
3275-ENDPROC(__clear_user)
3276+ENDPROC(___clear_user)
3277 ENDPROC(__clear_user_std)
3278
3279 .pushsection .fixup,"ax"
3280diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3281index 66a477a..bee61d3 100644
3282--- a/arch/arm/lib/copy_from_user.S
3283+++ b/arch/arm/lib/copy_from_user.S
3284@@ -16,7 +16,7 @@
3285 /*
3286 * Prototype:
3287 *
3288- * size_t __copy_from_user(void *to, const void *from, size_t n)
3289+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3290 *
3291 * Purpose:
3292 *
3293@@ -84,11 +84,11 @@
3294
3295 .text
3296
3297-ENTRY(__copy_from_user)
3298+ENTRY(___copy_from_user)
3299
3300 #include "copy_template.S"
3301
3302-ENDPROC(__copy_from_user)
3303+ENDPROC(___copy_from_user)
3304
3305 .pushsection .fixup,"ax"
3306 .align 0
3307diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3308index 6ee2f67..d1cce76 100644
3309--- a/arch/arm/lib/copy_page.S
3310+++ b/arch/arm/lib/copy_page.S
3311@@ -10,6 +10,7 @@
3312 * ASM optimised string functions
3313 */
3314 #include <linux/linkage.h>
3315+#include <linux/const.h>
3316 #include <asm/assembler.h>
3317 #include <asm/asm-offsets.h>
3318 #include <asm/cache.h>
3319diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3320index d066df6..df28194 100644
3321--- a/arch/arm/lib/copy_to_user.S
3322+++ b/arch/arm/lib/copy_to_user.S
3323@@ -16,7 +16,7 @@
3324 /*
3325 * Prototype:
3326 *
3327- * size_t __copy_to_user(void *to, const void *from, size_t n)
3328+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3329 *
3330 * Purpose:
3331 *
3332@@ -88,11 +88,11 @@
3333 .text
3334
3335 ENTRY(__copy_to_user_std)
3336-WEAK(__copy_to_user)
3337+WEAK(___copy_to_user)
3338
3339 #include "copy_template.S"
3340
3341-ENDPROC(__copy_to_user)
3342+ENDPROC(___copy_to_user)
3343 ENDPROC(__copy_to_user_std)
3344
3345 .pushsection .fixup,"ax"
3346diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3347index 7d08b43..f7ca7ea 100644
3348--- a/arch/arm/lib/csumpartialcopyuser.S
3349+++ b/arch/arm/lib/csumpartialcopyuser.S
3350@@ -57,8 +57,8 @@
3351 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3352 */
3353
3354-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3355-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3356+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3357+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3358
3359 #include "csumpartialcopygeneric.S"
3360
3361diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3362index 5306de3..aed6d03 100644
3363--- a/arch/arm/lib/delay.c
3364+++ b/arch/arm/lib/delay.c
3365@@ -28,7 +28,7 @@
3366 /*
3367 * Default to the loop-based delay implementation.
3368 */
3369-struct arm_delay_ops arm_delay_ops = {
3370+struct arm_delay_ops arm_delay_ops __read_only = {
3371 .delay = __loop_delay,
3372 .const_udelay = __loop_const_udelay,
3373 .udelay = __loop_udelay,
3374diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3375index 025f742..a9e5b3b 100644
3376--- a/arch/arm/lib/uaccess_with_memcpy.c
3377+++ b/arch/arm/lib/uaccess_with_memcpy.c
3378@@ -104,7 +104,7 @@ out:
3379 }
3380
3381 unsigned long
3382-__copy_to_user(void __user *to, const void *from, unsigned long n)
3383+___copy_to_user(void __user *to, const void *from, unsigned long n)
3384 {
3385 /*
3386 * This test is stubbed out of the main function above to keep
3387@@ -155,7 +155,7 @@ out:
3388 return n;
3389 }
3390
3391-unsigned long __clear_user(void __user *addr, unsigned long n)
3392+unsigned long ___clear_user(void __user *addr, unsigned long n)
3393 {
3394 /* See rational for this in __copy_to_user() above. */
3395 if (n < 64)
3396diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3397index 1767611..d2e7e24 100644
3398--- a/arch/arm/mach-kirkwood/common.c
3399+++ b/arch/arm/mach-kirkwood/common.c
3400@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3401 clk_gate_ops.disable(hw);
3402 }
3403
3404-static struct clk_ops clk_gate_fn_ops;
3405+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3406+{
3407+ return clk_gate_ops.is_enabled(hw);
3408+}
3409+
3410+static struct clk_ops clk_gate_fn_ops = {
3411+ .enable = clk_gate_fn_enable,
3412+ .disable = clk_gate_fn_disable,
3413+ .is_enabled = clk_gate_fn_is_enabled,
3414+};
3415
3416 static struct clk __init *clk_register_gate_fn(struct device *dev,
3417 const char *name,
3418@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3419 gate_fn->fn_en = fn_en;
3420 gate_fn->fn_dis = fn_dis;
3421
3422- /* ops is the gate ops, but with our enable/disable functions */
3423- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3424- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3425- clk_gate_fn_ops = clk_gate_ops;
3426- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3427- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3428- }
3429-
3430 clk = clk_register(dev, &gate_fn->gate.hw);
3431
3432 if (IS_ERR(clk))
3433diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3434index 827d1500..2885dc6 100644
3435--- a/arch/arm/mach-omap2/board-n8x0.c
3436+++ b/arch/arm/mach-omap2/board-n8x0.c
3437@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3438 }
3439 #endif
3440
3441-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3442+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3443 .late_init = n8x0_menelaus_late_init,
3444 };
3445
3446diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3447index 579697a..1d5a3b2 100644
3448--- a/arch/arm/mach-omap2/gpmc.c
3449+++ b/arch/arm/mach-omap2/gpmc.c
3450@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3451 };
3452
3453 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3454-static struct irq_chip gpmc_irq_chip;
3455 static int gpmc_irq_start;
3456
3457 static struct resource gpmc_mem_root;
3458@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3459
3460 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3461
3462+static struct irq_chip gpmc_irq_chip = {
3463+ .name = "gpmc",
3464+ .irq_startup = gpmc_irq_noop_ret,
3465+ .irq_enable = gpmc_irq_enable,
3466+ .irq_disable = gpmc_irq_disable,
3467+ .irq_shutdown = gpmc_irq_noop,
3468+ .irq_ack = gpmc_irq_noop,
3469+ .irq_mask = gpmc_irq_noop,
3470+ .irq_unmask = gpmc_irq_noop,
3471+
3472+};
3473+
3474 static int gpmc_setup_irq(void)
3475 {
3476 int i;
3477@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3478 return gpmc_irq_start;
3479 }
3480
3481- gpmc_irq_chip.name = "gpmc";
3482- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3483- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3484- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3485- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3486- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3487- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3488- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3489-
3490 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3491 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3492
3493diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3494index f991016..145ebeb 100644
3495--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3496+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3497@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3498 int (*finish_suspend)(unsigned long cpu_state);
3499 void (*resume)(void);
3500 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3501-};
3502+} __no_const;
3503
3504 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3505 static struct powerdomain *mpuss_pd;
3506@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3507 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3508 {}
3509
3510-struct cpu_pm_ops omap_pm_ops = {
3511+static struct cpu_pm_ops omap_pm_ops __read_only = {
3512 .finish_suspend = default_finish_suspend,
3513 .resume = dummy_cpu_resume,
3514 .scu_prepare = dummy_scu_prepare,
3515diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3516index 813c615..ce467c6 100644
3517--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3518+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3519@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3520 return NOTIFY_OK;
3521 }
3522
3523-static struct notifier_block __refdata irq_hotplug_notifier = {
3524+static struct notifier_block irq_hotplug_notifier = {
3525 .notifier_call = irq_cpu_hotplug_notify,
3526 };
3527
3528diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3529index 53f0735..5b54eb6 100644
3530--- a/arch/arm/mach-omap2/omap_device.c
3531+++ b/arch/arm/mach-omap2/omap_device.c
3532@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3533 struct platform_device __init *omap_device_build(const char *pdev_name,
3534 int pdev_id,
3535 struct omap_hwmod *oh,
3536- void *pdata, int pdata_len)
3537+ const void *pdata, int pdata_len)
3538 {
3539 struct omap_hwmod *ohs[] = { oh };
3540
3541@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3542 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3543 int pdev_id,
3544 struct omap_hwmod **ohs,
3545- int oh_cnt, void *pdata,
3546+ int oh_cnt, const void *pdata,
3547 int pdata_len)
3548 {
3549 int ret = -ENOMEM;
3550diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3551index 17ca1ae..beba869 100644
3552--- a/arch/arm/mach-omap2/omap_device.h
3553+++ b/arch/arm/mach-omap2/omap_device.h
3554@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3555 /* Core code interface */
3556
3557 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3558- struct omap_hwmod *oh, void *pdata,
3559+ struct omap_hwmod *oh, const void *pdata,
3560 int pdata_len);
3561
3562 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3563 struct omap_hwmod **oh, int oh_cnt,
3564- void *pdata, int pdata_len);
3565+ const void *pdata, int pdata_len);
3566
3567 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3568 struct omap_hwmod **ohs, int oh_cnt);
3569diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3570index 3d5db8c..ddfa144 100644
3571--- a/arch/arm/mach-omap2/omap_hwmod.c
3572+++ b/arch/arm/mach-omap2/omap_hwmod.c
3573@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3574 int (*init_clkdm)(struct omap_hwmod *oh);
3575 void (*update_context_lost)(struct omap_hwmod *oh);
3576 int (*get_context_lost)(struct omap_hwmod *oh);
3577-};
3578+} __no_const;
3579
3580 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3581-static struct omap_hwmod_soc_ops soc_ops;
3582+static struct omap_hwmod_soc_ops soc_ops __read_only;
3583
3584 /* omap_hwmod_list contains all registered struct omap_hwmods */
3585 static LIST_HEAD(omap_hwmod_list);
3586diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3587index d15c7bb..b2d1f0c 100644
3588--- a/arch/arm/mach-omap2/wd_timer.c
3589+++ b/arch/arm/mach-omap2/wd_timer.c
3590@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3591 struct omap_hwmod *oh;
3592 char *oh_name = "wd_timer2";
3593 char *dev_name = "omap_wdt";
3594- struct omap_wd_timer_platform_data pdata;
3595+ static struct omap_wd_timer_platform_data pdata = {
3596+ .read_reset_sources = prm_read_reset_sources
3597+ };
3598
3599 if (!cpu_class_is_omap2() || of_have_populated_dt())
3600 return 0;
3601@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3602 return -EINVAL;
3603 }
3604
3605- pdata.read_reset_sources = prm_read_reset_sources;
3606-
3607 pdev = omap_device_build(dev_name, id, oh, &pdata,
3608 sizeof(struct omap_wd_timer_platform_data));
3609 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3610diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3611index b82dcae..44ee5b6 100644
3612--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3613+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3614@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3615 bool entered_lp2 = false;
3616
3617 if (tegra_pending_sgi())
3618- ACCESS_ONCE(abort_flag) = true;
3619+ ACCESS_ONCE_RW(abort_flag) = true;
3620
3621 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3622
3623diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3624index 656324a..0beba28 100644
3625--- a/arch/arm/mach-ux500/setup.h
3626+++ b/arch/arm/mach-ux500/setup.h
3627@@ -40,13 +40,6 @@ extern void ux500_timer_init(void);
3628 .type = MT_DEVICE, \
3629 }
3630
3631-#define __MEM_DEV_DESC(x, sz) { \
3632- .virtual = IO_ADDRESS(x), \
3633- .pfn = __phys_to_pfn(x), \
3634- .length = sz, \
3635- .type = MT_MEMORY, \
3636-}
3637-
3638 extern struct smp_operations ux500_smp_ops;
3639 extern void ux500_cpu_die(unsigned int cpu);
3640
3641diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3642index cd2c88e..4dd9b67 100644
3643--- a/arch/arm/mm/Kconfig
3644+++ b/arch/arm/mm/Kconfig
3645@@ -446,7 +446,7 @@ config CPU_32v5
3646
3647 config CPU_32v6
3648 bool
3649- select CPU_USE_DOMAINS if CPU_V6 && MMU
3650+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3651 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3652
3653 config CPU_32v6K
3654@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3655
3656 config CPU_USE_DOMAINS
3657 bool
3658+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3659 help
3660 This option enables or disables the use of domain switching
3661 via the set_fs() function.
3662@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3663 config KUSER_HELPERS
3664 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3665 default y
3666+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3667 help
3668 Warning: disabling this option may break user programs.
3669
3670@@ -812,7 +814,7 @@ config KUSER_HELPERS
3671 See Documentation/arm/kernel_user_helpers.txt for details.
3672
3673 However, the fixed address nature of these helpers can be used
3674- by ROP (return orientated programming) authors when creating
3675+ by ROP (Return Oriented Programming) authors when creating
3676 exploits.
3677
3678 If all of the binaries and libraries which run on your platform
3679diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3680index 6f4585b..7b6f52b 100644
3681--- a/arch/arm/mm/alignment.c
3682+++ b/arch/arm/mm/alignment.c
3683@@ -211,10 +211,12 @@ union offset_union {
3684 #define __get16_unaligned_check(ins,val,addr) \
3685 do { \
3686 unsigned int err = 0, v, a = addr; \
3687+ pax_open_userland(); \
3688 __get8_unaligned_check(ins,v,a,err); \
3689 val = v << ((BE) ? 8 : 0); \
3690 __get8_unaligned_check(ins,v,a,err); \
3691 val |= v << ((BE) ? 0 : 8); \
3692+ pax_close_userland(); \
3693 if (err) \
3694 goto fault; \
3695 } while (0)
3696@@ -228,6 +230,7 @@ union offset_union {
3697 #define __get32_unaligned_check(ins,val,addr) \
3698 do { \
3699 unsigned int err = 0, v, a = addr; \
3700+ pax_open_userland(); \
3701 __get8_unaligned_check(ins,v,a,err); \
3702 val = v << ((BE) ? 24 : 0); \
3703 __get8_unaligned_check(ins,v,a,err); \
3704@@ -236,6 +239,7 @@ union offset_union {
3705 val |= v << ((BE) ? 8 : 16); \
3706 __get8_unaligned_check(ins,v,a,err); \
3707 val |= v << ((BE) ? 0 : 24); \
3708+ pax_close_userland(); \
3709 if (err) \
3710 goto fault; \
3711 } while (0)
3712@@ -249,6 +253,7 @@ union offset_union {
3713 #define __put16_unaligned_check(ins,val,addr) \
3714 do { \
3715 unsigned int err = 0, v = val, a = addr; \
3716+ pax_open_userland(); \
3717 __asm__( FIRST_BYTE_16 \
3718 ARM( "1: "ins" %1, [%2], #1\n" ) \
3719 THUMB( "1: "ins" %1, [%2]\n" ) \
3720@@ -268,6 +273,7 @@ union offset_union {
3721 " .popsection\n" \
3722 : "=r" (err), "=&r" (v), "=&r" (a) \
3723 : "0" (err), "1" (v), "2" (a)); \
3724+ pax_close_userland(); \
3725 if (err) \
3726 goto fault; \
3727 } while (0)
3728@@ -281,6 +287,7 @@ union offset_union {
3729 #define __put32_unaligned_check(ins,val,addr) \
3730 do { \
3731 unsigned int err = 0, v = val, a = addr; \
3732+ pax_open_userland(); \
3733 __asm__( FIRST_BYTE_32 \
3734 ARM( "1: "ins" %1, [%2], #1\n" ) \
3735 THUMB( "1: "ins" %1, [%2]\n" ) \
3736@@ -310,6 +317,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)
3744diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3745index 447da6f..77a5057 100644
3746--- a/arch/arm/mm/cache-l2x0.c
3747+++ b/arch/arm/mm/cache-l2x0.c
3748@@ -45,7 +45,7 @@ struct l2x0_of_data {
3749 void (*setup)(const struct device_node *, u32 *, u32 *);
3750 void (*save)(void);
3751 struct outer_cache_fns outer_cache;
3752-};
3753+} __do_const;
3754
3755 static bool of_init = false;
3756
3757diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3758index 84e6f77..0b52f31 100644
3759--- a/arch/arm/mm/context.c
3760+++ b/arch/arm/mm/context.c
3761@@ -43,7 +43,7 @@
3762 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3763
3764 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3765-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3766+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3767 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3768
3769 static DEFINE_PER_CPU(atomic64_t, active_asids);
3770@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3771 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3772 {
3773 u64 asid = atomic64_read(&mm->context.id);
3774- u64 generation = atomic64_read(&asid_generation);
3775+ u64 generation = atomic64_read_unchecked(&asid_generation);
3776
3777 if (asid != 0 && is_reserved_asid(asid)) {
3778 /*
3779@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3780 */
3781 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3782 if (asid == NUM_USER_ASIDS) {
3783- generation = atomic64_add_return(ASID_FIRST_VERSION,
3784+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3785 &asid_generation);
3786 flush_context(cpu);
3787 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3788@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3789 cpu_set_reserved_ttbr0();
3790
3791 asid = atomic64_read(&mm->context.id);
3792- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3793+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3794 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3795 goto switch_mm_fastpath;
3796
3797 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3798 /* Check that our ASID belongs to the current generation. */
3799 asid = atomic64_read(&mm->context.id);
3800- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3801+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3802 asid = new_context(mm, cpu);
3803 atomic64_set(&mm->context.id, asid);
3804 }
3805diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3806index eb8830a..5360ce7 100644
3807--- a/arch/arm/mm/fault.c
3808+++ b/arch/arm/mm/fault.c
3809@@ -25,6 +25,7 @@
3810 #include <asm/system_misc.h>
3811 #include <asm/system_info.h>
3812 #include <asm/tlbflush.h>
3813+#include <asm/sections.h>
3814
3815 #include "fault.h"
3816
3817@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3818 if (fixup_exception(regs))
3819 return;
3820
3821+#ifdef CONFIG_PAX_MEMORY_UDEREF
3822+ if (addr < TASK_SIZE) {
3823+ if (current->signal->curr_ip)
3824+ 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),
3825+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3826+ else
3827+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3828+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3829+ }
3830+#endif
3831+
3832+#ifdef CONFIG_PAX_KERNEXEC
3833+ if ((fsr & FSR_WRITE) &&
3834+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3835+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3836+ {
3837+ if (current->signal->curr_ip)
3838+ 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),
3839+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3840+ else
3841+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3842+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3843+ }
3844+#endif
3845+
3846 /*
3847 * No handler, we'll have to terminate things with extreme prejudice.
3848 */
3849@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3850 }
3851 #endif
3852
3853+#ifdef CONFIG_PAX_PAGEEXEC
3854+ if (fsr & FSR_LNX_PF) {
3855+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3856+ do_group_exit(SIGKILL);
3857+ }
3858+#endif
3859+
3860 tsk->thread.address = addr;
3861 tsk->thread.error_code = fsr;
3862 tsk->thread.trap_no = 14;
3863@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3864 }
3865 #endif /* CONFIG_MMU */
3866
3867+#ifdef CONFIG_PAX_PAGEEXEC
3868+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3869+{
3870+ long i;
3871+
3872+ printk(KERN_ERR "PAX: bytes at PC: ");
3873+ for (i = 0; i < 20; i++) {
3874+ unsigned char c;
3875+ if (get_user(c, (__force unsigned char __user *)pc+i))
3876+ printk(KERN_CONT "?? ");
3877+ else
3878+ printk(KERN_CONT "%02x ", c);
3879+ }
3880+ printk("\n");
3881+
3882+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3883+ for (i = -1; i < 20; i++) {
3884+ unsigned long c;
3885+ if (get_user(c, (__force unsigned long __user *)sp+i))
3886+ printk(KERN_CONT "???????? ");
3887+ else
3888+ printk(KERN_CONT "%08lx ", c);
3889+ }
3890+ printk("\n");
3891+}
3892+#endif
3893+
3894 /*
3895 * First Level Translation Fault Handler
3896 *
3897@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3898 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3899 struct siginfo info;
3900
3901+#ifdef CONFIG_PAX_MEMORY_UDEREF
3902+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3903+ if (current->signal->curr_ip)
3904+ 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),
3905+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3906+ else
3907+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3908+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3909+ goto die;
3910+ }
3911+#endif
3912+
3913 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3914 return;
3915
3916+die:
3917 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3918 inf->name, fsr, addr);
3919
3920@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3921 ifsr_info[nr].name = name;
3922 }
3923
3924+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3925+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3926+
3927 asmlinkage void __exception
3928 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3929 {
3930 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3931 struct siginfo info;
3932+ unsigned long pc = instruction_pointer(regs);
3933+
3934+ if (user_mode(regs)) {
3935+ unsigned long sigpage = current->mm->context.sigpage;
3936+
3937+ if (sigpage <= pc && pc < sigpage + 7*4) {
3938+ if (pc < sigpage + 3*4)
3939+ sys_sigreturn(regs);
3940+ else
3941+ sys_rt_sigreturn(regs);
3942+ return;
3943+ }
3944+ if (pc == 0xffff0f60UL) {
3945+ /*
3946+ * PaX: __kuser_cmpxchg64 emulation
3947+ */
3948+ // TODO
3949+ //regs->ARM_pc = regs->ARM_lr;
3950+ //return;
3951+ }
3952+ if (pc == 0xffff0fa0UL) {
3953+ /*
3954+ * PaX: __kuser_memory_barrier emulation
3955+ */
3956+ // dmb(); implied by the exception
3957+ regs->ARM_pc = regs->ARM_lr;
3958+ return;
3959+ }
3960+ if (pc == 0xffff0fc0UL) {
3961+ /*
3962+ * PaX: __kuser_cmpxchg emulation
3963+ */
3964+ // TODO
3965+ //long new;
3966+ //int op;
3967+
3968+ //op = FUTEX_OP_SET << 28;
3969+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3970+ //regs->ARM_r0 = old != new;
3971+ //regs->ARM_pc = regs->ARM_lr;
3972+ //return;
3973+ }
3974+ if (pc == 0xffff0fe0UL) {
3975+ /*
3976+ * PaX: __kuser_get_tls emulation
3977+ */
3978+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3979+ regs->ARM_pc = regs->ARM_lr;
3980+ return;
3981+ }
3982+ }
3983+
3984+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3985+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3986+ if (current->signal->curr_ip)
3987+ 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),
3988+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3989+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3990+ else
3991+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3992+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3993+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3994+ goto die;
3995+ }
3996+#endif
3997+
3998+#ifdef CONFIG_PAX_REFCOUNT
3999+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4000+ unsigned int bkpt;
4001+
4002+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4003+ current->thread.error_code = ifsr;
4004+ current->thread.trap_no = 0;
4005+ pax_report_refcount_overflow(regs);
4006+ fixup_exception(regs);
4007+ return;
4008+ }
4009+ }
4010+#endif
4011
4012 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4013 return;
4014
4015+die:
4016 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4017 inf->name, ifsr, addr);
4018
4019diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4020index cf08bdf..772656c 100644
4021--- a/arch/arm/mm/fault.h
4022+++ b/arch/arm/mm/fault.h
4023@@ -3,6 +3,7 @@
4024
4025 /*
4026 * Fault status register encodings. We steal bit 31 for our own purposes.
4027+ * Set when the FSR value is from an instruction fault.
4028 */
4029 #define FSR_LNX_PF (1 << 31)
4030 #define FSR_WRITE (1 << 11)
4031@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4032 }
4033 #endif
4034
4035+/* valid for LPAE and !LPAE */
4036+static inline int is_xn_fault(unsigned int fsr)
4037+{
4038+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4039+}
4040+
4041+static inline int is_domain_fault(unsigned int fsr)
4042+{
4043+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4044+}
4045+
4046 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4047 unsigned long search_exception_table(unsigned long addr);
4048
4049diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4050index 18ec4c5..479bb6a 100644
4051--- a/arch/arm/mm/init.c
4052+++ b/arch/arm/mm/init.c
4053@@ -30,6 +30,8 @@
4054 #include <asm/setup.h>
4055 #include <asm/tlb.h>
4056 #include <asm/fixmap.h>
4057+#include <asm/system_info.h>
4058+#include <asm/cp15.h>
4059
4060 #include <asm/mach/arch.h>
4061 #include <asm/mach/map.h>
4062@@ -684,7 +686,46 @@ void free_initmem(void)
4063 {
4064 #ifdef CONFIG_HAVE_TCM
4065 extern char __tcm_start, __tcm_end;
4066+#endif
4067
4068+#ifdef CONFIG_PAX_KERNEXEC
4069+ unsigned long addr;
4070+ pgd_t *pgd;
4071+ pud_t *pud;
4072+ pmd_t *pmd;
4073+ int cpu_arch = cpu_architecture();
4074+ unsigned int cr = get_cr();
4075+
4076+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4077+ /* make pages tables, etc before .text NX */
4078+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4079+ pgd = pgd_offset_k(addr);
4080+ pud = pud_offset(pgd, addr);
4081+ pmd = pmd_offset(pud, addr);
4082+ __section_update(pmd, addr, PMD_SECT_XN);
4083+ }
4084+ /* make init NX */
4085+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4086+ pgd = pgd_offset_k(addr);
4087+ pud = pud_offset(pgd, addr);
4088+ pmd = pmd_offset(pud, addr);
4089+ __section_update(pmd, addr, PMD_SECT_XN);
4090+ }
4091+ /* make kernel code/rodata RX */
4092+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4093+ pgd = pgd_offset_k(addr);
4094+ pud = pud_offset(pgd, addr);
4095+ pmd = pmd_offset(pud, addr);
4096+#ifdef CONFIG_ARM_LPAE
4097+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4098+#else
4099+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4100+#endif
4101+ }
4102+ }
4103+#endif
4104+
4105+#ifdef CONFIG_HAVE_TCM
4106 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4107 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4108 #endif
4109diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4110index f123d6e..04bf569 100644
4111--- a/arch/arm/mm/ioremap.c
4112+++ b/arch/arm/mm/ioremap.c
4113@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4114 unsigned int mtype;
4115
4116 if (cached)
4117- mtype = MT_MEMORY;
4118+ mtype = MT_MEMORY_RX;
4119 else
4120- mtype = MT_MEMORY_NONCACHED;
4121+ mtype = MT_MEMORY_NONCACHED_RX;
4122
4123 return __arm_ioremap_caller(phys_addr, size, mtype,
4124 __builtin_return_address(0));
4125diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4126index 304661d..53a6b19 100644
4127--- a/arch/arm/mm/mmap.c
4128+++ b/arch/arm/mm/mmap.c
4129@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4130 struct vm_area_struct *vma;
4131 int do_align = 0;
4132 int aliasing = cache_is_vipt_aliasing();
4133+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4134 struct vm_unmapped_area_info info;
4135
4136 /*
4137@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4138 if (len > TASK_SIZE)
4139 return -ENOMEM;
4140
4141+#ifdef CONFIG_PAX_RANDMMAP
4142+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4143+#endif
4144+
4145 if (addr) {
4146 if (do_align)
4147 addr = COLOUR_ALIGN(addr, pgoff);
4148@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4149 addr = PAGE_ALIGN(addr);
4150
4151 vma = find_vma(mm, addr);
4152- if (TASK_SIZE - len >= addr &&
4153- (!vma || addr + len <= vma->vm_start))
4154+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4155 return addr;
4156 }
4157
4158@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4159 info.high_limit = TASK_SIZE;
4160 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4161 info.align_offset = pgoff << PAGE_SHIFT;
4162+ info.threadstack_offset = offset;
4163 return vm_unmapped_area(&info);
4164 }
4165
4166@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4167 unsigned long addr = addr0;
4168 int do_align = 0;
4169 int aliasing = cache_is_vipt_aliasing();
4170+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4171 struct vm_unmapped_area_info info;
4172
4173 /*
4174@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4175 return addr;
4176 }
4177
4178+#ifdef CONFIG_PAX_RANDMMAP
4179+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4180+#endif
4181+
4182 /* requesting a specific address */
4183 if (addr) {
4184 if (do_align)
4185@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4186 else
4187 addr = PAGE_ALIGN(addr);
4188 vma = find_vma(mm, addr);
4189- if (TASK_SIZE - len >= addr &&
4190- (!vma || addr + len <= vma->vm_start))
4191+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4192 return addr;
4193 }
4194
4195@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4196 info.high_limit = mm->mmap_base;
4197 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4198 info.align_offset = pgoff << PAGE_SHIFT;
4199+ info.threadstack_offset = offset;
4200 addr = vm_unmapped_area(&info);
4201
4202 /*
4203@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4204 {
4205 unsigned long random_factor = 0UL;
4206
4207+#ifdef CONFIG_PAX_RANDMMAP
4208+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4209+#endif
4210+
4211 /* 8 bits of randomness in 20 address space bits */
4212 if ((current->flags & PF_RANDOMIZE) &&
4213 !(current->personality & ADDR_NO_RANDOMIZE))
4214@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4215
4216 if (mmap_is_legacy()) {
4217 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4218+
4219+#ifdef CONFIG_PAX_RANDMMAP
4220+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4221+ mm->mmap_base += mm->delta_mmap;
4222+#endif
4223+
4224 mm->get_unmapped_area = arch_get_unmapped_area;
4225 } else {
4226 mm->mmap_base = mmap_base(random_factor);
4227+
4228+#ifdef CONFIG_PAX_RANDMMAP
4229+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4230+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4231+#endif
4232+
4233 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4234 }
4235 }
4236diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4237index b1d17ee..7a6f4d3 100644
4238--- a/arch/arm/mm/mmu.c
4239+++ b/arch/arm/mm/mmu.c
4240@@ -36,6 +36,22 @@
4241 #include "mm.h"
4242 #include "tcm.h"
4243
4244+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4245+void modify_domain(unsigned int dom, unsigned int type)
4246+{
4247+ struct thread_info *thread = current_thread_info();
4248+ unsigned int domain = thread->cpu_domain;
4249+ /*
4250+ * DOMAIN_MANAGER might be defined to some other value,
4251+ * use the arch-defined constant
4252+ */
4253+ domain &= ~domain_val(dom, 3);
4254+ thread->cpu_domain = domain | domain_val(dom, type);
4255+ set_domain(thread->cpu_domain);
4256+}
4257+EXPORT_SYMBOL(modify_domain);
4258+#endif
4259+
4260 /*
4261 * empty_zero_page is a special page that is used for
4262 * zero-initialized data and COW.
4263@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4264
4265 #endif /* ifdef CONFIG_CPU_CP15 / else */
4266
4267-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4268+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4269 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4270
4271-static struct mem_type mem_types[] = {
4272+#ifdef CONFIG_PAX_KERNEXEC
4273+#define L_PTE_KERNEXEC L_PTE_RDONLY
4274+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4275+#else
4276+#define L_PTE_KERNEXEC L_PTE_DIRTY
4277+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4278+#endif
4279+
4280+static struct mem_type mem_types[] __read_only = {
4281 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4282 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4283 L_PTE_SHARED,
4284@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4285 [MT_UNCACHED] = {
4286 .prot_pte = PROT_PTE_DEVICE,
4287 .prot_l1 = PMD_TYPE_TABLE,
4288- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4289+ .prot_sect = PROT_SECT_DEVICE,
4290 .domain = DOMAIN_IO,
4291 },
4292 [MT_CACHECLEAN] = {
4293- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4294+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4295 .domain = DOMAIN_KERNEL,
4296 },
4297 #ifndef CONFIG_ARM_LPAE
4298 [MT_MINICLEAN] = {
4299- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4300+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4301 .domain = DOMAIN_KERNEL,
4302 },
4303 #endif
4304@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4305 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4306 L_PTE_RDONLY,
4307 .prot_l1 = PMD_TYPE_TABLE,
4308- .domain = DOMAIN_USER,
4309+ .domain = DOMAIN_VECTORS,
4310 },
4311 [MT_HIGH_VECTORS] = {
4312 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4313 L_PTE_USER | L_PTE_RDONLY,
4314 .prot_l1 = PMD_TYPE_TABLE,
4315- .domain = DOMAIN_USER,
4316+ .domain = DOMAIN_VECTORS,
4317 },
4318- [MT_MEMORY] = {
4319+ [MT_MEMORY_RWX] = {
4320 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4321 .prot_l1 = PMD_TYPE_TABLE,
4322 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4323 .domain = DOMAIN_KERNEL,
4324 },
4325+ [MT_MEMORY_RW] = {
4326+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4327+ .prot_l1 = PMD_TYPE_TABLE,
4328+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4329+ .domain = DOMAIN_KERNEL,
4330+ },
4331+ [MT_MEMORY_RX] = {
4332+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4333+ .prot_l1 = PMD_TYPE_TABLE,
4334+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4335+ .domain = DOMAIN_KERNEL,
4336+ },
4337 [MT_ROM] = {
4338- .prot_sect = PMD_TYPE_SECT,
4339+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4340 .domain = DOMAIN_KERNEL,
4341 },
4342- [MT_MEMORY_NONCACHED] = {
4343+ [MT_MEMORY_NONCACHED_RW] = {
4344 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4345 L_PTE_MT_BUFFERABLE,
4346 .prot_l1 = PMD_TYPE_TABLE,
4347 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4348 .domain = DOMAIN_KERNEL,
4349 },
4350+ [MT_MEMORY_NONCACHED_RX] = {
4351+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4352+ L_PTE_MT_BUFFERABLE,
4353+ .prot_l1 = PMD_TYPE_TABLE,
4354+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4355+ .domain = DOMAIN_KERNEL,
4356+ },
4357 [MT_MEMORY_DTCM] = {
4358- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4359- L_PTE_XN,
4360+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4361 .prot_l1 = PMD_TYPE_TABLE,
4362- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4363+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4364 .domain = DOMAIN_KERNEL,
4365 },
4366 [MT_MEMORY_ITCM] = {
4367@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4368 },
4369 [MT_MEMORY_SO] = {
4370 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4371- L_PTE_MT_UNCACHED | L_PTE_XN,
4372+ L_PTE_MT_UNCACHED,
4373 .prot_l1 = PMD_TYPE_TABLE,
4374 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4375- PMD_SECT_UNCACHED | PMD_SECT_XN,
4376+ PMD_SECT_UNCACHED,
4377 .domain = DOMAIN_KERNEL,
4378 },
4379 [MT_MEMORY_DMA_READY] = {
4380@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4381 * to prevent speculative instruction fetches.
4382 */
4383 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4385 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4386+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4387 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4388+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4389 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4390+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4391+
4392+ /* Mark other regions on ARMv6+ as execute-never */
4393+
4394+#ifdef CONFIG_PAX_KERNEXEC
4395+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4396+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4397+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4398+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4399+#ifndef CONFIG_ARM_LPAE
4400+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4401+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4402+#endif
4403+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4404+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4405+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4406+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4407+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4408+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4409+#endif
4410+
4411+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4412+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4413 }
4414 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4415 /*
4416@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4417 * from SVC mode and no access from userspace.
4418 */
4419 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4420+#ifdef CONFIG_PAX_KERNEXEC
4421+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4422+#endif
4423 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4424 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4425 #endif
4426@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4427 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4428 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4429 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4430- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4431- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4432+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4433+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4434+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4435+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4436+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4437+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4438 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4439- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4440- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4441+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4442+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4443+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4444+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4445 }
4446 }
4447
4448@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4449 if (cpu_arch >= CPU_ARCH_ARMv6) {
4450 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4451 /* Non-cacheable Normal is XCB = 001 */
4452- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4453+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4454+ PMD_SECT_BUFFERED;
4455+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4456 PMD_SECT_BUFFERED;
4457 } else {
4458 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4459- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4460+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4461+ PMD_SECT_TEX(1);
4462+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4463 PMD_SECT_TEX(1);
4464 }
4465 } else {
4466- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4467+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4468+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4469 }
4470
4471 #ifdef CONFIG_ARM_LPAE
4472@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4473 vecs_pgprot |= PTE_EXT_AF;
4474 #endif
4475
4476+ user_pgprot |= __supported_pte_mask;
4477+
4478 for (i = 0; i < 16; i++) {
4479 pteval_t v = pgprot_val(protection_map[i]);
4480 protection_map[i] = __pgprot(v | user_pgprot);
4481@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4482
4483 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4484 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4485- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4486- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4487+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4488+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4489+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4490+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4491+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4492+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4493 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4494- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4495+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4496+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4497 mem_types[MT_ROM].prot_sect |= cp->pmd;
4498
4499 switch (cp->pmd) {
4500@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4501 * called function. This means you can't use any function or debugging
4502 * method which may touch any device, otherwise the kernel _will_ crash.
4503 */
4504+
4505+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4506+
4507 static void __init devicemaps_init(const struct machine_desc *mdesc)
4508 {
4509 struct map_desc map;
4510 unsigned long addr;
4511- void *vectors;
4512
4513- /*
4514- * Allocate the vector page early.
4515- */
4516- vectors = early_alloc(PAGE_SIZE * 2);
4517-
4518- early_trap_init(vectors);
4519+ early_trap_init(&vectors);
4520
4521 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4522 pmd_clear(pmd_off_k(addr));
4523@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4524 * location (0xffff0000). If we aren't using high-vectors, also
4525 * create a mapping at the low-vectors virtual address.
4526 */
4527- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4528+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4529 map.virtual = 0xffff0000;
4530 map.length = PAGE_SIZE;
4531 #ifdef CONFIG_KUSER_HELPERS
4532@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4533 map.pfn = __phys_to_pfn(start);
4534 map.virtual = __phys_to_virt(start);
4535 map.length = end - start;
4536- map.type = MT_MEMORY;
4537
4538+#ifdef CONFIG_PAX_KERNEXEC
4539+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4540+ struct map_desc kernel;
4541+ struct map_desc initmap;
4542+
4543+ /* when freeing initmem we will make this RW */
4544+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4545+ initmap.virtual = (unsigned long)__init_begin;
4546+ initmap.length = _sdata - __init_begin;
4547+ initmap.type = MT_MEMORY_RWX;
4548+ create_mapping(&initmap);
4549+
4550+ /* when freeing initmem we will make this RX */
4551+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4552+ kernel.virtual = (unsigned long)_stext;
4553+ kernel.length = __init_begin - _stext;
4554+ kernel.type = MT_MEMORY_RWX;
4555+ create_mapping(&kernel);
4556+
4557+ if (map.virtual < (unsigned long)_stext) {
4558+ map.length = (unsigned long)_stext - map.virtual;
4559+ map.type = MT_MEMORY_RWX;
4560+ create_mapping(&map);
4561+ }
4562+
4563+ map.pfn = __phys_to_pfn(__pa(_sdata));
4564+ map.virtual = (unsigned long)_sdata;
4565+ map.length = end - __pa(_sdata);
4566+ }
4567+#endif
4568+
4569+ map.type = MT_MEMORY_RW;
4570 create_mapping(&map);
4571 }
4572 }
4573diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4574index a5bc92d..0bb4730 100644
4575--- a/arch/arm/plat-omap/sram.c
4576+++ b/arch/arm/plat-omap/sram.c
4577@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4578 * Looks like we need to preserve some bootloader code at the
4579 * beginning of SRAM for jumping to flash for reboot to work...
4580 */
4581+ pax_open_kernel();
4582 memset_io(omap_sram_base + omap_sram_skip, 0,
4583 omap_sram_size - omap_sram_skip);
4584+ pax_close_kernel();
4585 }
4586diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4587index ce6d763..cfea917 100644
4588--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4589+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4590@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4591 int (*started)(unsigned ch);
4592 int (*flush)(unsigned ch);
4593 int (*stop)(unsigned ch);
4594-};
4595+} __no_const;
4596
4597 extern void *samsung_dmadev_get_ops(void);
4598 extern void *s3c_dma_get_ops(void);
4599diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4600index c3a58a1..78fbf54 100644
4601--- a/arch/avr32/include/asm/cache.h
4602+++ b/arch/avr32/include/asm/cache.h
4603@@ -1,8 +1,10 @@
4604 #ifndef __ASM_AVR32_CACHE_H
4605 #define __ASM_AVR32_CACHE_H
4606
4607+#include <linux/const.h>
4608+
4609 #define L1_CACHE_SHIFT 5
4610-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4611+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4612
4613 /*
4614 * Memory returned by kmalloc() may be used for DMA, so we must make
4615diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4616index d232888..87c8df1 100644
4617--- a/arch/avr32/include/asm/elf.h
4618+++ b/arch/avr32/include/asm/elf.h
4619@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4620 the loader. We need to make sure that it is out of the way of the program
4621 that it will "exec", and that there is sufficient room for the brk. */
4622
4623-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4624+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4625
4626+#ifdef CONFIG_PAX_ASLR
4627+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4628+
4629+#define PAX_DELTA_MMAP_LEN 15
4630+#define PAX_DELTA_STACK_LEN 15
4631+#endif
4632
4633 /* This yields a mask that user programs can use to figure out what
4634 instruction set this CPU supports. This could be done in user space,
4635diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4636index 479330b..53717a8 100644
4637--- a/arch/avr32/include/asm/kmap_types.h
4638+++ b/arch/avr32/include/asm/kmap_types.h
4639@@ -2,9 +2,9 @@
4640 #define __ASM_AVR32_KMAP_TYPES_H
4641
4642 #ifdef CONFIG_DEBUG_HIGHMEM
4643-# define KM_TYPE_NR 29
4644+# define KM_TYPE_NR 30
4645 #else
4646-# define KM_TYPE_NR 14
4647+# define KM_TYPE_NR 15
4648 #endif
4649
4650 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4651diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4652index 0eca933..eb78c7b 100644
4653--- a/arch/avr32/mm/fault.c
4654+++ b/arch/avr32/mm/fault.c
4655@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4656
4657 int exception_trace = 1;
4658
4659+#ifdef CONFIG_PAX_PAGEEXEC
4660+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4661+{
4662+ unsigned long i;
4663+
4664+ printk(KERN_ERR "PAX: bytes at PC: ");
4665+ for (i = 0; i < 20; i++) {
4666+ unsigned char c;
4667+ if (get_user(c, (unsigned char *)pc+i))
4668+ printk(KERN_CONT "???????? ");
4669+ else
4670+ printk(KERN_CONT "%02x ", c);
4671+ }
4672+ printk("\n");
4673+}
4674+#endif
4675+
4676 /*
4677 * This routine handles page faults. It determines the address and the
4678 * problem, and then passes it off to one of the appropriate routines.
4679@@ -176,6 +193,16 @@ bad_area:
4680 up_read(&mm->mmap_sem);
4681
4682 if (user_mode(regs)) {
4683+
4684+#ifdef CONFIG_PAX_PAGEEXEC
4685+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4686+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4687+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4688+ do_group_exit(SIGKILL);
4689+ }
4690+ }
4691+#endif
4692+
4693 if (exception_trace && printk_ratelimit())
4694 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4695 "sp %08lx ecr %lu\n",
4696diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4697index 568885a..f8008df 100644
4698--- a/arch/blackfin/include/asm/cache.h
4699+++ b/arch/blackfin/include/asm/cache.h
4700@@ -7,6 +7,7 @@
4701 #ifndef __ARCH_BLACKFIN_CACHE_H
4702 #define __ARCH_BLACKFIN_CACHE_H
4703
4704+#include <linux/const.h>
4705 #include <linux/linkage.h> /* for asmlinkage */
4706
4707 /*
4708@@ -14,7 +15,7 @@
4709 * Blackfin loads 32 bytes for cache
4710 */
4711 #define L1_CACHE_SHIFT 5
4712-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4713+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4715
4716 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4717diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4718index aea2718..3639a60 100644
4719--- a/arch/cris/include/arch-v10/arch/cache.h
4720+++ b/arch/cris/include/arch-v10/arch/cache.h
4721@@ -1,8 +1,9 @@
4722 #ifndef _ASM_ARCH_CACHE_H
4723 #define _ASM_ARCH_CACHE_H
4724
4725+#include <linux/const.h>
4726 /* Etrax 100LX have 32-byte cache-lines. */
4727-#define L1_CACHE_BYTES 32
4728 #define L1_CACHE_SHIFT 5
4729+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4730
4731 #endif /* _ASM_ARCH_CACHE_H */
4732diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4733index 7caf25d..ee65ac5 100644
4734--- a/arch/cris/include/arch-v32/arch/cache.h
4735+++ b/arch/cris/include/arch-v32/arch/cache.h
4736@@ -1,11 +1,12 @@
4737 #ifndef _ASM_CRIS_ARCH_CACHE_H
4738 #define _ASM_CRIS_ARCH_CACHE_H
4739
4740+#include <linux/const.h>
4741 #include <arch/hwregs/dma.h>
4742
4743 /* A cache-line is 32 bytes. */
4744-#define L1_CACHE_BYTES 32
4745 #define L1_CACHE_SHIFT 5
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4749
4750diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4751index b86329d..6709906 100644
4752--- a/arch/frv/include/asm/atomic.h
4753+++ b/arch/frv/include/asm/atomic.h
4754@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4755 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4756 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4757
4758+#define atomic64_read_unchecked(v) atomic64_read(v)
4759+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4760+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4761+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4762+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4763+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4764+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4765+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4766+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4767+
4768 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4769 {
4770 int c, old;
4771diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4772index 2797163..c2a401d 100644
4773--- a/arch/frv/include/asm/cache.h
4774+++ b/arch/frv/include/asm/cache.h
4775@@ -12,10 +12,11 @@
4776 #ifndef __ASM_CACHE_H
4777 #define __ASM_CACHE_H
4778
4779+#include <linux/const.h>
4780
4781 /* bytes per L1 cache line */
4782 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4783-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4784+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4785
4786 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4787 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4788diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4789index 43901f2..0d8b865 100644
4790--- a/arch/frv/include/asm/kmap_types.h
4791+++ b/arch/frv/include/asm/kmap_types.h
4792@@ -2,6 +2,6 @@
4793 #ifndef _ASM_KMAP_TYPES_H
4794 #define _ASM_KMAP_TYPES_H
4795
4796-#define KM_TYPE_NR 17
4797+#define KM_TYPE_NR 18
4798
4799 #endif
4800diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4801index 836f147..4cf23f5 100644
4802--- a/arch/frv/mm/elf-fdpic.c
4803+++ b/arch/frv/mm/elf-fdpic.c
4804@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4805 {
4806 struct vm_area_struct *vma;
4807 struct vm_unmapped_area_info info;
4808+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4809
4810 if (len > TASK_SIZE)
4811 return -ENOMEM;
4812@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4813 if (addr) {
4814 addr = PAGE_ALIGN(addr);
4815 vma = find_vma(current->mm, addr);
4816- if (TASK_SIZE - len >= addr &&
4817- (!vma || addr + len <= vma->vm_start))
4818+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4819 goto success;
4820 }
4821
4822@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4823 info.high_limit = (current->mm->start_stack - 0x00200000);
4824 info.align_mask = 0;
4825 info.align_offset = 0;
4826+ info.threadstack_offset = offset;
4827 addr = vm_unmapped_area(&info);
4828 if (!(addr & ~PAGE_MASK))
4829 goto success;
4830diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4831index f4ca594..adc72fd6 100644
4832--- a/arch/hexagon/include/asm/cache.h
4833+++ b/arch/hexagon/include/asm/cache.h
4834@@ -21,9 +21,11 @@
4835 #ifndef __ASM_CACHE_H
4836 #define __ASM_CACHE_H
4837
4838+#include <linux/const.h>
4839+
4840 /* Bytes per L1 cache line */
4841-#define L1_CACHE_SHIFT (5)
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_SHIFT 5
4844+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4845
4846 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4847 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4848diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4849index 7740ab1..17fa8c5 100644
4850--- a/arch/ia64/Kconfig
4851+++ b/arch/ia64/Kconfig
4852@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4853 config KEXEC
4854 bool "kexec system call"
4855 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4856+ depends on !GRKERNSEC_KMEM
4857 help
4858 kexec is a system call that implements the ability to shutdown your
4859 current kernel, and to start another kernel. It is like a reboot
4860diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4861index 6e6fe18..a6ae668 100644
4862--- a/arch/ia64/include/asm/atomic.h
4863+++ b/arch/ia64/include/asm/atomic.h
4864@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4865 #define atomic64_inc(v) atomic64_add(1, (v))
4866 #define atomic64_dec(v) atomic64_sub(1, (v))
4867
4868+#define atomic64_read_unchecked(v) atomic64_read(v)
4869+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4870+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4871+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4872+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4873+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4874+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4875+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4876+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4877+
4878 /* Atomic operations are already serializing */
4879 #define smp_mb__before_atomic_dec() barrier()
4880 #define smp_mb__after_atomic_dec() barrier()
4881diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4882index 988254a..e1ee885 100644
4883--- a/arch/ia64/include/asm/cache.h
4884+++ b/arch/ia64/include/asm/cache.h
4885@@ -1,6 +1,7 @@
4886 #ifndef _ASM_IA64_CACHE_H
4887 #define _ASM_IA64_CACHE_H
4888
4889+#include <linux/const.h>
4890
4891 /*
4892 * Copyright (C) 1998-2000 Hewlett-Packard Co
4893@@ -9,7 +10,7 @@
4894
4895 /* Bytes per L1 (data) cache line. */
4896 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4897-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4898+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4899
4900 #ifdef CONFIG_SMP
4901 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4902diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4903index 5a83c5c..4d7f553 100644
4904--- a/arch/ia64/include/asm/elf.h
4905+++ b/arch/ia64/include/asm/elf.h
4906@@ -42,6 +42,13 @@
4907 */
4908 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4909
4910+#ifdef CONFIG_PAX_ASLR
4911+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4912+
4913+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4914+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4915+#endif
4916+
4917 #define PT_IA_64_UNWIND 0x70000001
4918
4919 /* IA-64 relocations: */
4920diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4921index 96a8d92..617a1cf 100644
4922--- a/arch/ia64/include/asm/pgalloc.h
4923+++ b/arch/ia64/include/asm/pgalloc.h
4924@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4925 pgd_val(*pgd_entry) = __pa(pud);
4926 }
4927
4928+static inline void
4929+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4930+{
4931+ pgd_populate(mm, pgd_entry, pud);
4932+}
4933+
4934 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4935 {
4936 return quicklist_alloc(0, GFP_KERNEL, NULL);
4937@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4938 pud_val(*pud_entry) = __pa(pmd);
4939 }
4940
4941+static inline void
4942+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4943+{
4944+ pud_populate(mm, pud_entry, pmd);
4945+}
4946+
4947 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4948 {
4949 return quicklist_alloc(0, GFP_KERNEL, NULL);
4950diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4951index 7935115..c0eca6a 100644
4952--- a/arch/ia64/include/asm/pgtable.h
4953+++ b/arch/ia64/include/asm/pgtable.h
4954@@ -12,7 +12,7 @@
4955 * David Mosberger-Tang <davidm@hpl.hp.com>
4956 */
4957
4958-
4959+#include <linux/const.h>
4960 #include <asm/mman.h>
4961 #include <asm/page.h>
4962 #include <asm/processor.h>
4963@@ -142,6 +142,17 @@
4964 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4965 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4966 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4967+
4968+#ifdef CONFIG_PAX_PAGEEXEC
4969+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4970+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4971+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4972+#else
4973+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4974+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4975+# define PAGE_COPY_NOEXEC PAGE_COPY
4976+#endif
4977+
4978 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4979 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4980 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4981diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4982index 45698cd..e8e2dbc 100644
4983--- a/arch/ia64/include/asm/spinlock.h
4984+++ b/arch/ia64/include/asm/spinlock.h
4985@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4986 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4987
4988 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4989- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4990+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4991 }
4992
4993 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4994diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4995index 449c8c0..18965fb 100644
4996--- a/arch/ia64/include/asm/uaccess.h
4997+++ b/arch/ia64/include/asm/uaccess.h
4998@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4999 static inline unsigned long
5000 __copy_to_user (void __user *to, const void *from, unsigned long count)
5001 {
5002+ if (count > INT_MAX)
5003+ return count;
5004+
5005+ if (!__builtin_constant_p(count))
5006+ check_object_size(from, count, true);
5007+
5008 return __copy_user(to, (__force void __user *) from, count);
5009 }
5010
5011 static inline unsigned long
5012 __copy_from_user (void *to, const void __user *from, unsigned long count)
5013 {
5014+ if (count > INT_MAX)
5015+ return count;
5016+
5017+ if (!__builtin_constant_p(count))
5018+ check_object_size(to, count, false);
5019+
5020 return __copy_user((__force void __user *) to, from, count);
5021 }
5022
5023@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5024 ({ \
5025 void __user *__cu_to = (to); \
5026 const void *__cu_from = (from); \
5027- long __cu_len = (n); \
5028+ unsigned long __cu_len = (n); \
5029 \
5030- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5031+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5032+ if (!__builtin_constant_p(n)) \
5033+ check_object_size(__cu_from, __cu_len, true); \
5034 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5035+ } \
5036 __cu_len; \
5037 })
5038
5039@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5040 ({ \
5041 void *__cu_to = (to); \
5042 const void __user *__cu_from = (from); \
5043- long __cu_len = (n); \
5044+ unsigned long __cu_len = (n); \
5045 \
5046 __chk_user_ptr(__cu_from); \
5047- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5048+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5049+ if (!__builtin_constant_p(n)) \
5050+ check_object_size(__cu_to, __cu_len, false); \
5051 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5052+ } \
5053 __cu_len; \
5054 })
5055
5056diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5057index 24603be..948052d 100644
5058--- a/arch/ia64/kernel/module.c
5059+++ b/arch/ia64/kernel/module.c
5060@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5061 void
5062 module_free (struct module *mod, void *module_region)
5063 {
5064- if (mod && mod->arch.init_unw_table &&
5065- module_region == mod->module_init) {
5066+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5067 unw_remove_unwind_table(mod->arch.init_unw_table);
5068 mod->arch.init_unw_table = NULL;
5069 }
5070@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5071 }
5072
5073 static inline int
5074+in_init_rx (const struct module *mod, uint64_t addr)
5075+{
5076+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5077+}
5078+
5079+static inline int
5080+in_init_rw (const struct module *mod, uint64_t addr)
5081+{
5082+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5083+}
5084+
5085+static inline int
5086 in_init (const struct module *mod, uint64_t addr)
5087 {
5088- return addr - (uint64_t) mod->module_init < mod->init_size;
5089+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5090+}
5091+
5092+static inline int
5093+in_core_rx (const struct module *mod, uint64_t addr)
5094+{
5095+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5096+}
5097+
5098+static inline int
5099+in_core_rw (const struct module *mod, uint64_t addr)
5100+{
5101+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5102 }
5103
5104 static inline int
5105 in_core (const struct module *mod, uint64_t addr)
5106 {
5107- return addr - (uint64_t) mod->module_core < mod->core_size;
5108+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5109 }
5110
5111 static inline int
5112@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5113 break;
5114
5115 case RV_BDREL:
5116- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5117+ if (in_init_rx(mod, val))
5118+ val -= (uint64_t) mod->module_init_rx;
5119+ else if (in_init_rw(mod, val))
5120+ val -= (uint64_t) mod->module_init_rw;
5121+ else if (in_core_rx(mod, val))
5122+ val -= (uint64_t) mod->module_core_rx;
5123+ else if (in_core_rw(mod, val))
5124+ val -= (uint64_t) mod->module_core_rw;
5125 break;
5126
5127 case RV_LTV:
5128@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5129 * addresses have been selected...
5130 */
5131 uint64_t gp;
5132- if (mod->core_size > MAX_LTOFF)
5133+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5134 /*
5135 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5136 * at the end of the module.
5137 */
5138- gp = mod->core_size - MAX_LTOFF / 2;
5139+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5140 else
5141- gp = mod->core_size / 2;
5142- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5143+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5144+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5145 mod->arch.gp = gp;
5146 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5147 }
5148diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5149index ab33328..f39506c 100644
5150--- a/arch/ia64/kernel/palinfo.c
5151+++ b/arch/ia64/kernel/palinfo.c
5152@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5153 return NOTIFY_OK;
5154 }
5155
5156-static struct notifier_block __refdata palinfo_cpu_notifier =
5157+static struct notifier_block palinfo_cpu_notifier =
5158 {
5159 .notifier_call = palinfo_cpu_callback,
5160 .priority = 0,
5161diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5162index 41e33f8..65180b2a 100644
5163--- a/arch/ia64/kernel/sys_ia64.c
5164+++ b/arch/ia64/kernel/sys_ia64.c
5165@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5166 unsigned long align_mask = 0;
5167 struct mm_struct *mm = current->mm;
5168 struct vm_unmapped_area_info info;
5169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5170
5171 if (len > RGN_MAP_LIMIT)
5172 return -ENOMEM;
5173@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5174 if (REGION_NUMBER(addr) == RGN_HPAGE)
5175 addr = 0;
5176 #endif
5177+
5178+#ifdef CONFIG_PAX_RANDMMAP
5179+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5180+ addr = mm->free_area_cache;
5181+ else
5182+#endif
5183+
5184 if (!addr)
5185 addr = TASK_UNMAPPED_BASE;
5186
5187@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5188 info.high_limit = TASK_SIZE;
5189 info.align_mask = align_mask;
5190 info.align_offset = 0;
5191+ info.threadstack_offset = offset;
5192 return vm_unmapped_area(&info);
5193 }
5194
5195diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5196index 0ccb28f..8992469 100644
5197--- a/arch/ia64/kernel/vmlinux.lds.S
5198+++ b/arch/ia64/kernel/vmlinux.lds.S
5199@@ -198,7 +198,7 @@ SECTIONS {
5200 /* Per-cpu data: */
5201 . = ALIGN(PERCPU_PAGE_SIZE);
5202 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5203- __phys_per_cpu_start = __per_cpu_load;
5204+ __phys_per_cpu_start = per_cpu_load;
5205 /*
5206 * ensure percpu data fits
5207 * into percpu page size
5208diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5209index 7225dad..2a7c8256 100644
5210--- a/arch/ia64/mm/fault.c
5211+++ b/arch/ia64/mm/fault.c
5212@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5213 return pte_present(pte);
5214 }
5215
5216+#ifdef CONFIG_PAX_PAGEEXEC
5217+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5218+{
5219+ unsigned long i;
5220+
5221+ printk(KERN_ERR "PAX: bytes at PC: ");
5222+ for (i = 0; i < 8; i++) {
5223+ unsigned int c;
5224+ if (get_user(c, (unsigned int *)pc+i))
5225+ printk(KERN_CONT "???????? ");
5226+ else
5227+ printk(KERN_CONT "%08x ", c);
5228+ }
5229+ printk("\n");
5230+}
5231+#endif
5232+
5233 # define VM_READ_BIT 0
5234 # define VM_WRITE_BIT 1
5235 # define VM_EXEC_BIT 2
5236@@ -151,8 +168,21 @@ retry:
5237 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5238 goto bad_area;
5239
5240- if ((vma->vm_flags & mask) != mask)
5241+ if ((vma->vm_flags & mask) != mask) {
5242+
5243+#ifdef CONFIG_PAX_PAGEEXEC
5244+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5245+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5246+ goto bad_area;
5247+
5248+ up_read(&mm->mmap_sem);
5249+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5250+ do_group_exit(SIGKILL);
5251+ }
5252+#endif
5253+
5254 goto bad_area;
5255+ }
5256
5257 /*
5258 * If for any reason at all we couldn't handle the fault, make
5259diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5260index 68232db..6ca80af 100644
5261--- a/arch/ia64/mm/hugetlbpage.c
5262+++ b/arch/ia64/mm/hugetlbpage.c
5263@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5264 unsigned long pgoff, unsigned long flags)
5265 {
5266 struct vm_unmapped_area_info info;
5267+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5268
5269 if (len > RGN_MAP_LIMIT)
5270 return -ENOMEM;
5271@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5272 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5273 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5274 info.align_offset = 0;
5275+ info.threadstack_offset = offset;
5276 return vm_unmapped_area(&info);
5277 }
5278
5279diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5280index b6f7f43..c04320d 100644
5281--- a/arch/ia64/mm/init.c
5282+++ b/arch/ia64/mm/init.c
5283@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5284 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5285 vma->vm_end = vma->vm_start + PAGE_SIZE;
5286 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5287+
5288+#ifdef CONFIG_PAX_PAGEEXEC
5289+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5290+ vma->vm_flags &= ~VM_EXEC;
5291+
5292+#ifdef CONFIG_PAX_MPROTECT
5293+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5294+ vma->vm_flags &= ~VM_MAYEXEC;
5295+#endif
5296+
5297+ }
5298+#endif
5299+
5300 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5301 down_write(&current->mm->mmap_sem);
5302 if (insert_vm_struct(current->mm, vma)) {
5303diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5304index 40b3ee9..8c2c112 100644
5305--- a/arch/m32r/include/asm/cache.h
5306+++ b/arch/m32r/include/asm/cache.h
5307@@ -1,8 +1,10 @@
5308 #ifndef _ASM_M32R_CACHE_H
5309 #define _ASM_M32R_CACHE_H
5310
5311+#include <linux/const.h>
5312+
5313 /* L1 cache line size */
5314 #define L1_CACHE_SHIFT 4
5315-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5316+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5317
5318 #endif /* _ASM_M32R_CACHE_H */
5319diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5320index 82abd15..d95ae5d 100644
5321--- a/arch/m32r/lib/usercopy.c
5322+++ b/arch/m32r/lib/usercopy.c
5323@@ -14,6 +14,9 @@
5324 unsigned long
5325 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5326 {
5327+ if ((long)n < 0)
5328+ return n;
5329+
5330 prefetch(from);
5331 if (access_ok(VERIFY_WRITE, to, n))
5332 __copy_user(to,from,n);
5333@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5334 unsigned long
5335 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5336 {
5337+ if ((long)n < 0)
5338+ return n;
5339+
5340 prefetchw(to);
5341 if (access_ok(VERIFY_READ, from, n))
5342 __copy_user_zeroing(to,from,n);
5343diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5344index 0395c51..5f26031 100644
5345--- a/arch/m68k/include/asm/cache.h
5346+++ b/arch/m68k/include/asm/cache.h
5347@@ -4,9 +4,11 @@
5348 #ifndef __ARCH_M68K_CACHE_H
5349 #define __ARCH_M68K_CACHE_H
5350
5351+#include <linux/const.h>
5352+
5353 /* bytes per L1 cache line */
5354 #define L1_CACHE_SHIFT 4
5355-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5357
5358 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5359
5360diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5361index 0424315..defcca9 100644
5362--- a/arch/metag/mm/hugetlbpage.c
5363+++ b/arch/metag/mm/hugetlbpage.c
5364@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5365 info.high_limit = TASK_SIZE;
5366 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5367 info.align_offset = 0;
5368+ info.threadstack_offset = 0;
5369 return vm_unmapped_area(&info);
5370 }
5371
5372diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5373index 4efe96a..60e8699 100644
5374--- a/arch/microblaze/include/asm/cache.h
5375+++ b/arch/microblaze/include/asm/cache.h
5376@@ -13,11 +13,12 @@
5377 #ifndef _ASM_MICROBLAZE_CACHE_H
5378 #define _ASM_MICROBLAZE_CACHE_H
5379
5380+#include <linux/const.h>
5381 #include <asm/registers.h>
5382
5383 #define L1_CACHE_SHIFT 5
5384 /* word-granular cache in microblaze */
5385-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5386+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5387
5388 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5389
5390diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5391index f75ab4a..adc6968 100644
5392--- a/arch/mips/Kconfig
5393+++ b/arch/mips/Kconfig
5394@@ -2283,6 +2283,7 @@ source "kernel/Kconfig.preempt"
5395
5396 config KEXEC
5397 bool "Kexec system call"
5398+ depends on !GRKERNSEC_KMEM
5399 help
5400 kexec is a system call that implements the ability to shutdown your
5401 current kernel, and to start another kernel. It is like a reboot
5402diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5403index 08b6079..8b554d2 100644
5404--- a/arch/mips/include/asm/atomic.h
5405+++ b/arch/mips/include/asm/atomic.h
5406@@ -21,15 +21,39 @@
5407 #include <asm/cmpxchg.h>
5408 #include <asm/war.h>
5409
5410+#ifdef CONFIG_GENERIC_ATOMIC64
5411+#include <asm-generic/atomic64.h>
5412+#endif
5413+
5414 #define ATOMIC_INIT(i) { (i) }
5415
5416+#ifdef CONFIG_64BIT
5417+#define _ASM_EXTABLE(from, to) \
5418+" .section __ex_table,\"a\"\n" \
5419+" .dword " #from ", " #to"\n" \
5420+" .previous\n"
5421+#else
5422+#define _ASM_EXTABLE(from, to) \
5423+" .section __ex_table,\"a\"\n" \
5424+" .word " #from ", " #to"\n" \
5425+" .previous\n"
5426+#endif
5427+
5428 /*
5429 * atomic_read - read atomic variable
5430 * @v: pointer of type atomic_t
5431 *
5432 * Atomically reads the value of @v.
5433 */
5434-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5435+static inline int atomic_read(const atomic_t *v)
5436+{
5437+ return (*(volatile const int *) &v->counter);
5438+}
5439+
5440+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5441+{
5442+ return (*(volatile const int *) &v->counter);
5443+}
5444
5445 /*
5446 * atomic_set - set atomic variable
5447@@ -38,7 +62,15 @@
5448 *
5449 * Atomically sets the value of @v to @i.
5450 */
5451-#define atomic_set(v, i) ((v)->counter = (i))
5452+static inline void atomic_set(atomic_t *v, int i)
5453+{
5454+ v->counter = i;
5455+}
5456+
5457+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5458+{
5459+ v->counter = i;
5460+}
5461
5462 /*
5463 * atomic_add - add integer to atomic variable
5464@@ -47,7 +79,67 @@
5465 *
5466 * Atomically adds @i to @v.
5467 */
5468-static __inline__ void atomic_add(int i, atomic_t * v)
5469+static __inline__ void atomic_add(int i, atomic_t *v)
5470+{
5471+ int temp;
5472+
5473+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5474+ __asm__ __volatile__(
5475+ " .set mips3 \n"
5476+ "1: ll %0, %1 # atomic_add \n"
5477+#ifdef CONFIG_PAX_REFCOUNT
5478+ /* Exception on overflow. */
5479+ "2: add %0, %2 \n"
5480+#else
5481+ " addu %0, %2 \n"
5482+#endif
5483+ " sc %0, %1 \n"
5484+ " beqzl %0, 1b \n"
5485+#ifdef CONFIG_PAX_REFCOUNT
5486+ "3: \n"
5487+ _ASM_EXTABLE(2b, 3b)
5488+#endif
5489+ " .set mips0 \n"
5490+ : "=&r" (temp), "+m" (v->counter)
5491+ : "Ir" (i));
5492+ } else if (kernel_uses_llsc) {
5493+ __asm__ __volatile__(
5494+ " .set mips3 \n"
5495+ "1: ll %0, %1 # atomic_add \n"
5496+#ifdef CONFIG_PAX_REFCOUNT
5497+ /* Exception on overflow. */
5498+ "2: add %0, %2 \n"
5499+#else
5500+ " addu %0, %2 \n"
5501+#endif
5502+ " sc %0, %1 \n"
5503+ " beqz %0, 1b \n"
5504+#ifdef CONFIG_PAX_REFCOUNT
5505+ "3: \n"
5506+ _ASM_EXTABLE(2b, 3b)
5507+#endif
5508+ " .set mips0 \n"
5509+ : "=&r" (temp), "+m" (v->counter)
5510+ : "Ir" (i));
5511+ } else {
5512+ unsigned long flags;
5513+
5514+ raw_local_irq_save(flags);
5515+ __asm__ __volatile__(
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ /* Exception on overflow. */
5518+ "1: add %0, %1 \n"
5519+ "2: \n"
5520+ _ASM_EXTABLE(1b, 2b)
5521+#else
5522+ " addu %0, %1 \n"
5523+#endif
5524+ : "+r" (v->counter) : "Ir" (i));
5525+ raw_local_irq_restore(flags);
5526+ }
5527+}
5528+
5529+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5530 {
5531 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5532 int temp;
5533@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5534 *
5535 * Atomically subtracts @i from @v.
5536 */
5537-static __inline__ void atomic_sub(int i, atomic_t * v)
5538+static __inline__ void atomic_sub(int i, atomic_t *v)
5539+{
5540+ int temp;
5541+
5542+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5543+ __asm__ __volatile__(
5544+ " .set mips3 \n"
5545+ "1: ll %0, %1 # atomic64_sub \n"
5546+#ifdef CONFIG_PAX_REFCOUNT
5547+ /* Exception on overflow. */
5548+ "2: sub %0, %2 \n"
5549+#else
5550+ " subu %0, %2 \n"
5551+#endif
5552+ " sc %0, %1 \n"
5553+ " beqzl %0, 1b \n"
5554+#ifdef CONFIG_PAX_REFCOUNT
5555+ "3: \n"
5556+ _ASM_EXTABLE(2b, 3b)
5557+#endif
5558+ " .set mips0 \n"
5559+ : "=&r" (temp), "+m" (v->counter)
5560+ : "Ir" (i));
5561+ } else if (kernel_uses_llsc) {
5562+ __asm__ __volatile__(
5563+ " .set mips3 \n"
5564+ "1: ll %0, %1 # atomic64_sub \n"
5565+#ifdef CONFIG_PAX_REFCOUNT
5566+ /* Exception on overflow. */
5567+ "2: sub %0, %2 \n"
5568+#else
5569+ " subu %0, %2 \n"
5570+#endif
5571+ " sc %0, %1 \n"
5572+ " beqz %0, 1b \n"
5573+#ifdef CONFIG_PAX_REFCOUNT
5574+ "3: \n"
5575+ _ASM_EXTABLE(2b, 3b)
5576+#endif
5577+ " .set mips0 \n"
5578+ : "=&r" (temp), "+m" (v->counter)
5579+ : "Ir" (i));
5580+ } else {
5581+ unsigned long flags;
5582+
5583+ raw_local_irq_save(flags);
5584+ __asm__ __volatile__(
5585+#ifdef CONFIG_PAX_REFCOUNT
5586+ /* Exception on overflow. */
5587+ "1: sub %0, %1 \n"
5588+ "2: \n"
5589+ _ASM_EXTABLE(1b, 2b)
5590+#else
5591+ " subu %0, %1 \n"
5592+#endif
5593+ : "+r" (v->counter) : "Ir" (i));
5594+ raw_local_irq_restore(flags);
5595+ }
5596+}
5597+
5598+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5599 {
5600 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5601 int temp;
5602@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5603 /*
5604 * Same as above, but return the result value
5605 */
5606-static __inline__ int atomic_add_return(int i, atomic_t * v)
5607+static __inline__ int atomic_add_return(int i, atomic_t *v)
5608+{
5609+ int result;
5610+ int temp;
5611+
5612+ smp_mb__before_llsc();
5613+
5614+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5615+ __asm__ __volatile__(
5616+ " .set mips3 \n"
5617+ "1: ll %1, %2 # atomic_add_return \n"
5618+#ifdef CONFIG_PAX_REFCOUNT
5619+ "2: add %0, %1, %3 \n"
5620+#else
5621+ " addu %0, %1, %3 \n"
5622+#endif
5623+ " sc %0, %2 \n"
5624+ " beqzl %0, 1b \n"
5625+#ifdef CONFIG_PAX_REFCOUNT
5626+ " b 4f \n"
5627+ " .set noreorder \n"
5628+ "3: b 5f \n"
5629+ " move %0, %1 \n"
5630+ " .set reorder \n"
5631+ _ASM_EXTABLE(2b, 3b)
5632+#endif
5633+ "4: addu %0, %1, %3 \n"
5634+#ifdef CONFIG_PAX_REFCOUNT
5635+ "5: \n"
5636+#endif
5637+ " .set mips0 \n"
5638+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5639+ : "Ir" (i));
5640+ } else if (kernel_uses_llsc) {
5641+ __asm__ __volatile__(
5642+ " .set mips3 \n"
5643+ "1: ll %1, %2 # atomic_add_return \n"
5644+#ifdef CONFIG_PAX_REFCOUNT
5645+ "2: add %0, %1, %3 \n"
5646+#else
5647+ " addu %0, %1, %3 \n"
5648+#endif
5649+ " sc %0, %2 \n"
5650+ " bnez %0, 4f \n"
5651+ " b 1b \n"
5652+#ifdef CONFIG_PAX_REFCOUNT
5653+ " .set noreorder \n"
5654+ "3: b 5f \n"
5655+ " move %0, %1 \n"
5656+ " .set reorder \n"
5657+ _ASM_EXTABLE(2b, 3b)
5658+#endif
5659+ "4: addu %0, %1, %3 \n"
5660+#ifdef CONFIG_PAX_REFCOUNT
5661+ "5: \n"
5662+#endif
5663+ " .set mips0 \n"
5664+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5665+ : "Ir" (i));
5666+ } else {
5667+ unsigned long flags;
5668+
5669+ raw_local_irq_save(flags);
5670+ __asm__ __volatile__(
5671+ " lw %0, %1 \n"
5672+#ifdef CONFIG_PAX_REFCOUNT
5673+ /* Exception on overflow. */
5674+ "1: add %0, %2 \n"
5675+#else
5676+ " addu %0, %2 \n"
5677+#endif
5678+ " sw %0, %1 \n"
5679+#ifdef CONFIG_PAX_REFCOUNT
5680+ /* Note: Dest reg is not modified on overflow */
5681+ "2: \n"
5682+ _ASM_EXTABLE(1b, 2b)
5683+#endif
5684+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5685+ raw_local_irq_restore(flags);
5686+ }
5687+
5688+ smp_llsc_mb();
5689+
5690+ return result;
5691+}
5692+
5693+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5694 {
5695 int result;
5696
5697@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5698 return result;
5699 }
5700
5701-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5702+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5703+{
5704+ int result;
5705+ int temp;
5706+
5707+ smp_mb__before_llsc();
5708+
5709+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5710+ __asm__ __volatile__(
5711+ " .set mips3 \n"
5712+ "1: ll %1, %2 # atomic_sub_return \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ "2: sub %0, %1, %3 \n"
5715+#else
5716+ " subu %0, %1, %3 \n"
5717+#endif
5718+ " sc %0, %2 \n"
5719+ " beqzl %0, 1b \n"
5720+#ifdef CONFIG_PAX_REFCOUNT
5721+ " b 4f \n"
5722+ " .set noreorder \n"
5723+ "3: b 5f \n"
5724+ " move %0, %1 \n"
5725+ " .set reorder \n"
5726+ _ASM_EXTABLE(2b, 3b)
5727+#endif
5728+ "4: subu %0, %1, %3 \n"
5729+#ifdef CONFIG_PAX_REFCOUNT
5730+ "5: \n"
5731+#endif
5732+ " .set mips0 \n"
5733+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5734+ : "Ir" (i), "m" (v->counter)
5735+ : "memory");
5736+ } else if (kernel_uses_llsc) {
5737+ __asm__ __volatile__(
5738+ " .set mips3 \n"
5739+ "1: ll %1, %2 # atomic_sub_return \n"
5740+#ifdef CONFIG_PAX_REFCOUNT
5741+ "2: sub %0, %1, %3 \n"
5742+#else
5743+ " subu %0, %1, %3 \n"
5744+#endif
5745+ " sc %0, %2 \n"
5746+ " bnez %0, 4f \n"
5747+ " b 1b \n"
5748+#ifdef CONFIG_PAX_REFCOUNT
5749+ " .set noreorder \n"
5750+ "3: b 5f \n"
5751+ " move %0, %1 \n"
5752+ " .set reorder \n"
5753+ _ASM_EXTABLE(2b, 3b)
5754+#endif
5755+ "4: subu %0, %1, %3 \n"
5756+#ifdef CONFIG_PAX_REFCOUNT
5757+ "5: \n"
5758+#endif
5759+ " .set mips0 \n"
5760+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5761+ : "Ir" (i));
5762+ } else {
5763+ unsigned long flags;
5764+
5765+ raw_local_irq_save(flags);
5766+ __asm__ __volatile__(
5767+ " lw %0, %1 \n"
5768+#ifdef CONFIG_PAX_REFCOUNT
5769+ /* Exception on overflow. */
5770+ "1: sub %0, %2 \n"
5771+#else
5772+ " subu %0, %2 \n"
5773+#endif
5774+ " sw %0, %1 \n"
5775+#ifdef CONFIG_PAX_REFCOUNT
5776+ /* Note: Dest reg is not modified on overflow */
5777+ "2: \n"
5778+ _ASM_EXTABLE(1b, 2b)
5779+#endif
5780+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5781+ raw_local_irq_restore(flags);
5782+ }
5783+
5784+ smp_llsc_mb();
5785+
5786+ return result;
5787+}
5788+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5789 {
5790 int result;
5791
5792@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5793 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5794 * The function returns the old value of @v minus @i.
5795 */
5796-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5797+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5798 {
5799 int result;
5800
5801@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5802 return result;
5803 }
5804
5805-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5806-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5807+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5808+{
5809+ return cmpxchg(&v->counter, old, new);
5810+}
5811+
5812+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5813+ int new)
5814+{
5815+ return cmpxchg(&(v->counter), old, new);
5816+}
5817+
5818+static inline int atomic_xchg(atomic_t *v, int new)
5819+{
5820+ return xchg(&v->counter, new);
5821+}
5822+
5823+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5824+{
5825+ return xchg(&(v->counter), new);
5826+}
5827
5828 /**
5829 * __atomic_add_unless - add unless the number is a given value
5830@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5831
5832 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5833 #define atomic_inc_return(v) atomic_add_return(1, (v))
5834+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5835+{
5836+ return atomic_add_return_unchecked(1, v);
5837+}
5838
5839 /*
5840 * atomic_sub_and_test - subtract value from variable and test result
5841@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5842 * other cases.
5843 */
5844 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5845+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5846+{
5847+ return atomic_add_return_unchecked(1, v) == 0;
5848+}
5849
5850 /*
5851 * atomic_dec_and_test - decrement by 1 and test
5852@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5853 * Atomically increments @v by 1.
5854 */
5855 #define atomic_inc(v) atomic_add(1, (v))
5856+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5857+{
5858+ atomic_add_unchecked(1, v);
5859+}
5860
5861 /*
5862 * atomic_dec - decrement and test
5863@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5864 * Atomically decrements @v by 1.
5865 */
5866 #define atomic_dec(v) atomic_sub(1, (v))
5867+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5868+{
5869+ atomic_sub_unchecked(1, v);
5870+}
5871
5872 /*
5873 * atomic_add_negative - add and test if negative
5874@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5875 * @v: pointer of type atomic64_t
5876 *
5877 */
5878-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5879+static inline long atomic64_read(const atomic64_t *v)
5880+{
5881+ return (*(volatile const long *) &v->counter);
5882+}
5883+
5884+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5885+{
5886+ return (*(volatile const long *) &v->counter);
5887+}
5888
5889 /*
5890 * atomic64_set - set atomic variable
5891 * @v: pointer of type atomic64_t
5892 * @i: required value
5893 */
5894-#define atomic64_set(v, i) ((v)->counter = (i))
5895+static inline void atomic64_set(atomic64_t *v, long i)
5896+{
5897+ v->counter = i;
5898+}
5899+
5900+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5901+{
5902+ v->counter = i;
5903+}
5904
5905 /*
5906 * atomic64_add - add integer to atomic variable
5907@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5908 *
5909 * Atomically adds @i to @v.
5910 */
5911-static __inline__ void atomic64_add(long i, atomic64_t * v)
5912+static __inline__ void atomic64_add(long i, atomic64_t *v)
5913+{
5914+ long temp;
5915+
5916+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5917+ __asm__ __volatile__(
5918+ " .set mips3 \n"
5919+ "1: lld %0, %1 # atomic64_add \n"
5920+#ifdef CONFIG_PAX_REFCOUNT
5921+ /* Exception on overflow. */
5922+ "2: dadd %0, %2 \n"
5923+#else
5924+ " daddu %0, %2 \n"
5925+#endif
5926+ " scd %0, %1 \n"
5927+ " beqzl %0, 1b \n"
5928+#ifdef CONFIG_PAX_REFCOUNT
5929+ "3: \n"
5930+ _ASM_EXTABLE(2b, 3b)
5931+#endif
5932+ " .set mips0 \n"
5933+ : "=&r" (temp), "+m" (v->counter)
5934+ : "Ir" (i));
5935+ } else if (kernel_uses_llsc) {
5936+ __asm__ __volatile__(
5937+ " .set mips3 \n"
5938+ "1: lld %0, %1 # atomic64_add \n"
5939+#ifdef CONFIG_PAX_REFCOUNT
5940+ /* Exception on overflow. */
5941+ "2: dadd %0, %2 \n"
5942+#else
5943+ " daddu %0, %2 \n"
5944+#endif
5945+ " scd %0, %1 \n"
5946+ " beqz %0, 1b \n"
5947+#ifdef CONFIG_PAX_REFCOUNT
5948+ "3: \n"
5949+ _ASM_EXTABLE(2b, 3b)
5950+#endif
5951+ " .set mips0 \n"
5952+ : "=&r" (temp), "+m" (v->counter)
5953+ : "Ir" (i));
5954+ } else {
5955+ unsigned long flags;
5956+
5957+ raw_local_irq_save(flags);
5958+ __asm__ __volatile__(
5959+#ifdef CONFIG_PAX_REFCOUNT
5960+ /* Exception on overflow. */
5961+ "1: dadd %0, %1 \n"
5962+ "2: \n"
5963+ _ASM_EXTABLE(1b, 2b)
5964+#else
5965+ " daddu %0, %1 \n"
5966+#endif
5967+ : "+r" (v->counter) : "Ir" (i));
5968+ raw_local_irq_restore(flags);
5969+ }
5970+}
5971+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5972 {
5973 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5974 long temp;
5975@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5976 *
5977 * Atomically subtracts @i from @v.
5978 */
5979-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5980+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5981+{
5982+ long temp;
5983+
5984+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5985+ __asm__ __volatile__(
5986+ " .set mips3 \n"
5987+ "1: lld %0, %1 # atomic64_sub \n"
5988+#ifdef CONFIG_PAX_REFCOUNT
5989+ /* Exception on overflow. */
5990+ "2: dsub %0, %2 \n"
5991+#else
5992+ " dsubu %0, %2 \n"
5993+#endif
5994+ " scd %0, %1 \n"
5995+ " beqzl %0, 1b \n"
5996+#ifdef CONFIG_PAX_REFCOUNT
5997+ "3: \n"
5998+ _ASM_EXTABLE(2b, 3b)
5999+#endif
6000+ " .set mips0 \n"
6001+ : "=&r" (temp), "+m" (v->counter)
6002+ : "Ir" (i));
6003+ } else if (kernel_uses_llsc) {
6004+ __asm__ __volatile__(
6005+ " .set mips3 \n"
6006+ "1: lld %0, %1 # atomic64_sub \n"
6007+#ifdef CONFIG_PAX_REFCOUNT
6008+ /* Exception on overflow. */
6009+ "2: dsub %0, %2 \n"
6010+#else
6011+ " dsubu %0, %2 \n"
6012+#endif
6013+ " scd %0, %1 \n"
6014+ " beqz %0, 1b \n"
6015+#ifdef CONFIG_PAX_REFCOUNT
6016+ "3: \n"
6017+ _ASM_EXTABLE(2b, 3b)
6018+#endif
6019+ " .set mips0 \n"
6020+ : "=&r" (temp), "+m" (v->counter)
6021+ : "Ir" (i));
6022+ } else {
6023+ unsigned long flags;
6024+
6025+ raw_local_irq_save(flags);
6026+ __asm__ __volatile__(
6027+#ifdef CONFIG_PAX_REFCOUNT
6028+ /* Exception on overflow. */
6029+ "1: dsub %0, %1 \n"
6030+ "2: \n"
6031+ _ASM_EXTABLE(1b, 2b)
6032+#else
6033+ " dsubu %0, %1 \n"
6034+#endif
6035+ : "+r" (v->counter) : "Ir" (i));
6036+ raw_local_irq_restore(flags);
6037+ }
6038+}
6039+
6040+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6041 {
6042 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6043 long temp;
6044@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6045 /*
6046 * Same as above, but return the result value
6047 */
6048-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6049+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6050+{
6051+ long result;
6052+ long temp;
6053+
6054+ smp_mb__before_llsc();
6055+
6056+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6057+ __asm__ __volatile__(
6058+ " .set mips3 \n"
6059+ "1: lld %1, %2 # atomic64_add_return \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ "2: dadd %0, %1, %3 \n"
6062+#else
6063+ " daddu %0, %1, %3 \n"
6064+#endif
6065+ " scd %0, %2 \n"
6066+ " beqzl %0, 1b \n"
6067+#ifdef CONFIG_PAX_REFCOUNT
6068+ " b 4f \n"
6069+ " .set noreorder \n"
6070+ "3: b 5f \n"
6071+ " move %0, %1 \n"
6072+ " .set reorder \n"
6073+ _ASM_EXTABLE(2b, 3b)
6074+#endif
6075+ "4: daddu %0, %1, %3 \n"
6076+#ifdef CONFIG_PAX_REFCOUNT
6077+ "5: \n"
6078+#endif
6079+ " .set mips0 \n"
6080+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6081+ : "Ir" (i));
6082+ } else if (kernel_uses_llsc) {
6083+ __asm__ __volatile__(
6084+ " .set mips3 \n"
6085+ "1: lld %1, %2 # atomic64_add_return \n"
6086+#ifdef CONFIG_PAX_REFCOUNT
6087+ "2: dadd %0, %1, %3 \n"
6088+#else
6089+ " daddu %0, %1, %3 \n"
6090+#endif
6091+ " scd %0, %2 \n"
6092+ " bnez %0, 4f \n"
6093+ " b 1b \n"
6094+#ifdef CONFIG_PAX_REFCOUNT
6095+ " .set noreorder \n"
6096+ "3: b 5f \n"
6097+ " move %0, %1 \n"
6098+ " .set reorder \n"
6099+ _ASM_EXTABLE(2b, 3b)
6100+#endif
6101+ "4: daddu %0, %1, %3 \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ "5: \n"
6104+#endif
6105+ " .set mips0 \n"
6106+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6107+ : "Ir" (i), "m" (v->counter)
6108+ : "memory");
6109+ } else {
6110+ unsigned long flags;
6111+
6112+ raw_local_irq_save(flags);
6113+ __asm__ __volatile__(
6114+ " ld %0, %1 \n"
6115+#ifdef CONFIG_PAX_REFCOUNT
6116+ /* Exception on overflow. */
6117+ "1: dadd %0, %2 \n"
6118+#else
6119+ " daddu %0, %2 \n"
6120+#endif
6121+ " sd %0, %1 \n"
6122+#ifdef CONFIG_PAX_REFCOUNT
6123+ /* Note: Dest reg is not modified on overflow */
6124+ "2: \n"
6125+ _ASM_EXTABLE(1b, 2b)
6126+#endif
6127+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6128+ raw_local_irq_restore(flags);
6129+ }
6130+
6131+ smp_llsc_mb();
6132+
6133+ return result;
6134+}
6135+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6136 {
6137 long result;
6138
6139@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6140 return result;
6141 }
6142
6143-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6144+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6145+{
6146+ long result;
6147+ long temp;
6148+
6149+ smp_mb__before_llsc();
6150+
6151+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6152+ long temp;
6153+
6154+ __asm__ __volatile__(
6155+ " .set mips3 \n"
6156+ "1: lld %1, %2 # atomic64_sub_return \n"
6157+#ifdef CONFIG_PAX_REFCOUNT
6158+ "2: dsub %0, %1, %3 \n"
6159+#else
6160+ " dsubu %0, %1, %3 \n"
6161+#endif
6162+ " scd %0, %2 \n"
6163+ " beqzl %0, 1b \n"
6164+#ifdef CONFIG_PAX_REFCOUNT
6165+ " b 4f \n"
6166+ " .set noreorder \n"
6167+ "3: b 5f \n"
6168+ " move %0, %1 \n"
6169+ " .set reorder \n"
6170+ _ASM_EXTABLE(2b, 3b)
6171+#endif
6172+ "4: dsubu %0, %1, %3 \n"
6173+#ifdef CONFIG_PAX_REFCOUNT
6174+ "5: \n"
6175+#endif
6176+ " .set mips0 \n"
6177+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6178+ : "Ir" (i), "m" (v->counter)
6179+ : "memory");
6180+ } else if (kernel_uses_llsc) {
6181+ __asm__ __volatile__(
6182+ " .set mips3 \n"
6183+ "1: lld %1, %2 # atomic64_sub_return \n"
6184+#ifdef CONFIG_PAX_REFCOUNT
6185+ "2: dsub %0, %1, %3 \n"
6186+#else
6187+ " dsubu %0, %1, %3 \n"
6188+#endif
6189+ " scd %0, %2 \n"
6190+ " bnez %0, 4f \n"
6191+ " b 1b \n"
6192+#ifdef CONFIG_PAX_REFCOUNT
6193+ " .set noreorder \n"
6194+ "3: b 5f \n"
6195+ " move %0, %1 \n"
6196+ " .set reorder \n"
6197+ _ASM_EXTABLE(2b, 3b)
6198+#endif
6199+ "4: dsubu %0, %1, %3 \n"
6200+#ifdef CONFIG_PAX_REFCOUNT
6201+ "5: \n"
6202+#endif
6203+ " .set mips0 \n"
6204+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6205+ : "Ir" (i), "m" (v->counter)
6206+ : "memory");
6207+ } else {
6208+ unsigned long flags;
6209+
6210+ raw_local_irq_save(flags);
6211+ __asm__ __volatile__(
6212+ " ld %0, %1 \n"
6213+#ifdef CONFIG_PAX_REFCOUNT
6214+ /* Exception on overflow. */
6215+ "1: dsub %0, %2 \n"
6216+#else
6217+ " dsubu %0, %2 \n"
6218+#endif
6219+ " sd %0, %1 \n"
6220+#ifdef CONFIG_PAX_REFCOUNT
6221+ /* Note: Dest reg is not modified on overflow */
6222+ "2: \n"
6223+ _ASM_EXTABLE(1b, 2b)
6224+#endif
6225+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6226+ raw_local_irq_restore(flags);
6227+ }
6228+
6229+ smp_llsc_mb();
6230+
6231+ return result;
6232+}
6233+
6234+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6235 {
6236 long result;
6237
6238@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6239 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6240 * The function returns the old value of @v minus @i.
6241 */
6242-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6243+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6244 {
6245 long result;
6246
6247@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6248 return result;
6249 }
6250
6251-#define atomic64_cmpxchg(v, o, n) \
6252- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6253-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6254+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6255+{
6256+ return cmpxchg(&v->counter, old, new);
6257+}
6258+
6259+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6260+ long new)
6261+{
6262+ return cmpxchg(&(v->counter), old, new);
6263+}
6264+
6265+static inline long atomic64_xchg(atomic64_t *v, long new)
6266+{
6267+ return xchg(&v->counter, new);
6268+}
6269+
6270+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6271+{
6272+ return xchg(&(v->counter), new);
6273+}
6274
6275 /**
6276 * atomic64_add_unless - add unless the number is a given value
6277@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6278
6279 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6280 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6281+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6282
6283 /*
6284 * atomic64_sub_and_test - subtract value from variable and test result
6285@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6286 * other cases.
6287 */
6288 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6289+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6290
6291 /*
6292 * atomic64_dec_and_test - decrement by 1 and test
6293@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6294 * Atomically increments @v by 1.
6295 */
6296 #define atomic64_inc(v) atomic64_add(1, (v))
6297+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6298
6299 /*
6300 * atomic64_dec - decrement and test
6301@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6302 * Atomically decrements @v by 1.
6303 */
6304 #define atomic64_dec(v) atomic64_sub(1, (v))
6305+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6306
6307 /*
6308 * atomic64_add_negative - add and test if negative
6309diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6310index b4db69f..8f3b093 100644
6311--- a/arch/mips/include/asm/cache.h
6312+++ b/arch/mips/include/asm/cache.h
6313@@ -9,10 +9,11 @@
6314 #ifndef _ASM_CACHE_H
6315 #define _ASM_CACHE_H
6316
6317+#include <linux/const.h>
6318 #include <kmalloc.h>
6319
6320 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6321-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6322+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6323
6324 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6325 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6326diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6327index cf3ae24..238d22f 100644
6328--- a/arch/mips/include/asm/elf.h
6329+++ b/arch/mips/include/asm/elf.h
6330@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6331 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6332 #endif
6333
6334+#ifdef CONFIG_PAX_ASLR
6335+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6336+
6337+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6338+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6339+#endif
6340+
6341 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6342 struct linux_binprm;
6343 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6344 int uses_interp);
6345
6346-struct mm_struct;
6347-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6348-#define arch_randomize_brk arch_randomize_brk
6349-
6350 #endif /* _ASM_ELF_H */
6351diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6352index c1f6afa..38cc6e9 100644
6353--- a/arch/mips/include/asm/exec.h
6354+++ b/arch/mips/include/asm/exec.h
6355@@ -12,6 +12,6 @@
6356 #ifndef _ASM_EXEC_H
6357 #define _ASM_EXEC_H
6358
6359-extern unsigned long arch_align_stack(unsigned long sp);
6360+#define arch_align_stack(x) ((x) & ~0xfUL)
6361
6362 #endif /* _ASM_EXEC_H */
6363diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6364index d44622c..64990d2 100644
6365--- a/arch/mips/include/asm/local.h
6366+++ b/arch/mips/include/asm/local.h
6367@@ -12,15 +12,25 @@ typedef struct
6368 atomic_long_t a;
6369 } local_t;
6370
6371+typedef struct {
6372+ atomic_long_unchecked_t a;
6373+} local_unchecked_t;
6374+
6375 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6376
6377 #define local_read(l) atomic_long_read(&(l)->a)
6378+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6379 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6380+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6381
6382 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6383+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6384 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6385+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6386 #define local_inc(l) atomic_long_inc(&(l)->a)
6387+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6388 #define local_dec(l) atomic_long_dec(&(l)->a)
6389+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6390
6391 /*
6392 * Same as above, but return the result value
6393@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6394 return result;
6395 }
6396
6397+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6398+{
6399+ unsigned long result;
6400+
6401+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6402+ unsigned long temp;
6403+
6404+ __asm__ __volatile__(
6405+ " .set mips3 \n"
6406+ "1:" __LL "%1, %2 # local_add_return \n"
6407+ " addu %0, %1, %3 \n"
6408+ __SC "%0, %2 \n"
6409+ " beqzl %0, 1b \n"
6410+ " addu %0, %1, %3 \n"
6411+ " .set mips0 \n"
6412+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6413+ : "Ir" (i), "m" (l->a.counter)
6414+ : "memory");
6415+ } else if (kernel_uses_llsc) {
6416+ unsigned long temp;
6417+
6418+ __asm__ __volatile__(
6419+ " .set mips3 \n"
6420+ "1:" __LL "%1, %2 # local_add_return \n"
6421+ " addu %0, %1, %3 \n"
6422+ __SC "%0, %2 \n"
6423+ " beqz %0, 1b \n"
6424+ " addu %0, %1, %3 \n"
6425+ " .set mips0 \n"
6426+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6427+ : "Ir" (i), "m" (l->a.counter)
6428+ : "memory");
6429+ } else {
6430+ unsigned long flags;
6431+
6432+ local_irq_save(flags);
6433+ result = l->a.counter;
6434+ result += i;
6435+ l->a.counter = result;
6436+ local_irq_restore(flags);
6437+ }
6438+
6439+ return result;
6440+}
6441+
6442 static __inline__ long local_sub_return(long i, local_t * l)
6443 {
6444 unsigned long result;
6445@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6446
6447 #define local_cmpxchg(l, o, n) \
6448 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6449+#define local_cmpxchg_unchecked(l, o, n) \
6450+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6451 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6452
6453 /**
6454diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6455index f6be474..12ad554 100644
6456--- a/arch/mips/include/asm/page.h
6457+++ b/arch/mips/include/asm/page.h
6458@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6459 #ifdef CONFIG_CPU_MIPS32
6460 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6461 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6462- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6463+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6464 #else
6465 typedef struct { unsigned long long pte; } pte_t;
6466 #define pte_val(x) ((x).pte)
6467diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6468index 881d18b..cea38bc 100644
6469--- a/arch/mips/include/asm/pgalloc.h
6470+++ b/arch/mips/include/asm/pgalloc.h
6471@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6472 {
6473 set_pud(pud, __pud((unsigned long)pmd));
6474 }
6475+
6476+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6477+{
6478+ pud_populate(mm, pud, pmd);
6479+}
6480 #endif
6481
6482 /*
6483diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6484index 25da651..ae2a259 100644
6485--- a/arch/mips/include/asm/smtc_proc.h
6486+++ b/arch/mips/include/asm/smtc_proc.h
6487@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6488
6489 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6490
6491-extern atomic_t smtc_fpu_recoveries;
6492+extern atomic_unchecked_t smtc_fpu_recoveries;
6493
6494 #endif /* __ASM_SMTC_PROC_H */
6495diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6496index 61215a3..213ee0e 100644
6497--- a/arch/mips/include/asm/thread_info.h
6498+++ b/arch/mips/include/asm/thread_info.h
6499@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6500 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6501 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6502 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6503+/* li takes a 32bit immediate */
6504+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6505 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6506
6507 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6508@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6509 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6510 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6511 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6512+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6513
6514-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6515- _TIF_SYSCALL_AUDIT)
6516+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6517
6518 /* work to do in syscall_trace_leave() */
6519-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6520- _TIF_SYSCALL_AUDIT)
6521+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6522
6523 /* work to do on interrupt/exception return */
6524 #define _TIF_WORK_MASK \
6525 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6526 /* work to do on any return to u-space */
6527-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6528- _TIF_WORK_SYSCALL_EXIT)
6529+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6530
6531 #endif /* __KERNEL__ */
6532
6533diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6534index 1188e00..41cf144 100644
6535--- a/arch/mips/kernel/binfmt_elfn32.c
6536+++ b/arch/mips/kernel/binfmt_elfn32.c
6537@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6538 #undef ELF_ET_DYN_BASE
6539 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6540
6541+#ifdef CONFIG_PAX_ASLR
6542+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6543+
6544+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6545+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6546+#endif
6547+
6548 #include <asm/processor.h>
6549 #include <linux/module.h>
6550 #include <linux/elfcore.h>
6551diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6552index 202e581..689ca79 100644
6553--- a/arch/mips/kernel/binfmt_elfo32.c
6554+++ b/arch/mips/kernel/binfmt_elfo32.c
6555@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6556 #undef ELF_ET_DYN_BASE
6557 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6558
6559+#ifdef CONFIG_PAX_ASLR
6560+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6561+
6562+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6563+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6564+#endif
6565+
6566 #include <asm/processor.h>
6567
6568 /*
6569diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6570index d1fea7a..45602ea 100644
6571--- a/arch/mips/kernel/irq.c
6572+++ b/arch/mips/kernel/irq.c
6573@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6574 printk("unexpected IRQ # %d\n", irq);
6575 }
6576
6577-atomic_t irq_err_count;
6578+atomic_unchecked_t irq_err_count;
6579
6580 int arch_show_interrupts(struct seq_file *p, int prec)
6581 {
6582- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6583+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6584 return 0;
6585 }
6586
6587 asmlinkage void spurious_interrupt(void)
6588 {
6589- atomic_inc(&irq_err_count);
6590+ atomic_inc_unchecked(&irq_err_count);
6591 }
6592
6593 void __init init_IRQ(void)
6594diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6595index ddc7610..8c58f17 100644
6596--- a/arch/mips/kernel/process.c
6597+++ b/arch/mips/kernel/process.c
6598@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6599 out:
6600 return pc;
6601 }
6602-
6603-/*
6604- * Don't forget that the stack pointer must be aligned on a 8 bytes
6605- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6606- */
6607-unsigned long arch_align_stack(unsigned long sp)
6608-{
6609- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6610- sp -= get_random_int() & ~PAGE_MASK;
6611-
6612- return sp & ALMASK;
6613-}
6614diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6615index 8ae1ebe..1bcbf47 100644
6616--- a/arch/mips/kernel/ptrace.c
6617+++ b/arch/mips/kernel/ptrace.c
6618@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6619 return arch;
6620 }
6621
6622+#ifdef CONFIG_GRKERNSEC_SETXID
6623+extern void gr_delayed_cred_worker(void);
6624+#endif
6625+
6626 /*
6627 * Notification of system call entry/exit
6628 * - triggered by current->work.syscall_trace
6629@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6630 /* do the secure computing check first */
6631 secure_computing_strict(regs->regs[2]);
6632
6633+#ifdef CONFIG_GRKERNSEC_SETXID
6634+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6635+ gr_delayed_cred_worker();
6636+#endif
6637+
6638 if (!(current->ptrace & PT_PTRACED))
6639 goto out;
6640
6641diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6642index c10aa84..9ec2e60 100644
6643--- a/arch/mips/kernel/smtc-proc.c
6644+++ b/arch/mips/kernel/smtc-proc.c
6645@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6646
6647 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6648
6649-atomic_t smtc_fpu_recoveries;
6650+atomic_unchecked_t smtc_fpu_recoveries;
6651
6652 static int smtc_proc_show(struct seq_file *m, void *v)
6653 {
6654@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6655 for(i = 0; i < NR_CPUS; i++)
6656 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6657 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6658- atomic_read(&smtc_fpu_recoveries));
6659+ atomic_read_unchecked(&smtc_fpu_recoveries));
6660 return 0;
6661 }
6662
6663@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6664 smtc_cpu_stats[i].selfipis = 0;
6665 }
6666
6667- atomic_set(&smtc_fpu_recoveries, 0);
6668+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6669
6670 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6671 }
6672diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6673index dfc1b91..11a2c07 100644
6674--- a/arch/mips/kernel/smtc.c
6675+++ b/arch/mips/kernel/smtc.c
6676@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6677 }
6678 smtc_ipi_qdump();
6679 printk("%d Recoveries of \"stolen\" FPU\n",
6680- atomic_read(&smtc_fpu_recoveries));
6681+ atomic_read_unchecked(&smtc_fpu_recoveries));
6682 }
6683
6684
6685diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6686index 84536bf..79caa4d 100644
6687--- a/arch/mips/kernel/sync-r4k.c
6688+++ b/arch/mips/kernel/sync-r4k.c
6689@@ -21,8 +21,8 @@
6690 #include <asm/mipsregs.h>
6691
6692 static atomic_t count_start_flag = ATOMIC_INIT(0);
6693-static atomic_t count_count_start = ATOMIC_INIT(0);
6694-static atomic_t count_count_stop = ATOMIC_INIT(0);
6695+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6696+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6697 static atomic_t count_reference = ATOMIC_INIT(0);
6698
6699 #define COUNTON 100
6700@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6701
6702 for (i = 0; i < NR_LOOPS; i++) {
6703 /* slaves loop on '!= 2' */
6704- while (atomic_read(&count_count_start) != 1)
6705+ while (atomic_read_unchecked(&count_count_start) != 1)
6706 mb();
6707- atomic_set(&count_count_stop, 0);
6708+ atomic_set_unchecked(&count_count_stop, 0);
6709 smp_wmb();
6710
6711 /* this lets the slaves write their count register */
6712- atomic_inc(&count_count_start);
6713+ atomic_inc_unchecked(&count_count_start);
6714
6715 /*
6716 * Everyone initialises count in the last loop:
6717@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6718 /*
6719 * Wait for all slaves to leave the synchronization point:
6720 */
6721- while (atomic_read(&count_count_stop) != 1)
6722+ while (atomic_read_unchecked(&count_count_stop) != 1)
6723 mb();
6724- atomic_set(&count_count_start, 0);
6725+ atomic_set_unchecked(&count_count_start, 0);
6726 smp_wmb();
6727- atomic_inc(&count_count_stop);
6728+ atomic_inc_unchecked(&count_count_stop);
6729 }
6730 /* Arrange for an interrupt in a short while */
6731 write_c0_compare(read_c0_count() + COUNTON);
6732@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6733 initcount = atomic_read(&count_reference);
6734
6735 for (i = 0; i < NR_LOOPS; i++) {
6736- atomic_inc(&count_count_start);
6737- while (atomic_read(&count_count_start) != 2)
6738+ atomic_inc_unchecked(&count_count_start);
6739+ while (atomic_read_unchecked(&count_count_start) != 2)
6740 mb();
6741
6742 /*
6743@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6744 if (i == NR_LOOPS-1)
6745 write_c0_count(initcount);
6746
6747- atomic_inc(&count_count_stop);
6748- while (atomic_read(&count_count_stop) != 2)
6749+ atomic_inc_unchecked(&count_count_stop);
6750+ while (atomic_read_unchecked(&count_count_stop) != 2)
6751 mb();
6752 }
6753 /* Arrange for an interrupt in a short while */
6754diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6755index 524841f..3eef41e 100644
6756--- a/arch/mips/kernel/traps.c
6757+++ b/arch/mips/kernel/traps.c
6758@@ -684,7 +684,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6759 siginfo_t info;
6760
6761 prev_state = exception_enter();
6762- die_if_kernel("Integer overflow", regs);
6763+ if (unlikely(!user_mode(regs))) {
6764+
6765+#ifdef CONFIG_PAX_REFCOUNT
6766+ if (fixup_exception(regs)) {
6767+ pax_report_refcount_overflow(regs);
6768+ exception_exit(prev_state);
6769+ return;
6770+ }
6771+#endif
6772+
6773+ die("Integer overflow", regs);
6774+ }
6775
6776 info.si_code = FPE_INTOVF;
6777 info.si_signo = SIGFPE;
6778diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6779index becc42b..9e43d4b 100644
6780--- a/arch/mips/mm/fault.c
6781+++ b/arch/mips/mm/fault.c
6782@@ -28,6 +28,23 @@
6783 #include <asm/highmem.h> /* For VMALLOC_END */
6784 #include <linux/kdebug.h>
6785
6786+#ifdef CONFIG_PAX_PAGEEXEC
6787+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6788+{
6789+ unsigned long i;
6790+
6791+ printk(KERN_ERR "PAX: bytes at PC: ");
6792+ for (i = 0; i < 5; i++) {
6793+ unsigned int c;
6794+ if (get_user(c, (unsigned int *)pc+i))
6795+ printk(KERN_CONT "???????? ");
6796+ else
6797+ printk(KERN_CONT "%08x ", c);
6798+ }
6799+ printk("\n");
6800+}
6801+#endif
6802+
6803 /*
6804 * This routine handles page faults. It determines the address,
6805 * and the problem, and then passes it off to one of the appropriate
6806@@ -199,6 +216,14 @@ bad_area:
6807 bad_area_nosemaphore:
6808 /* User mode accesses just cause a SIGSEGV */
6809 if (user_mode(regs)) {
6810+
6811+#ifdef CONFIG_PAX_PAGEEXEC
6812+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6813+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6814+ do_group_exit(SIGKILL);
6815+ }
6816+#endif
6817+
6818 tsk->thread.cp0_badvaddr = address;
6819 tsk->thread.error_code = write;
6820 #if 0
6821diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6822index f1baadd..8537544 100644
6823--- a/arch/mips/mm/mmap.c
6824+++ b/arch/mips/mm/mmap.c
6825@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6826 struct vm_area_struct *vma;
6827 unsigned long addr = addr0;
6828 int do_color_align;
6829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6830 struct vm_unmapped_area_info info;
6831
6832 if (unlikely(len > TASK_SIZE))
6833@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6834 do_color_align = 1;
6835
6836 /* requesting a specific address */
6837+
6838+#ifdef CONFIG_PAX_RANDMMAP
6839+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6840+#endif
6841+
6842 if (addr) {
6843 if (do_color_align)
6844 addr = COLOUR_ALIGN(addr, pgoff);
6845@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6846 addr = PAGE_ALIGN(addr);
6847
6848 vma = find_vma(mm, addr);
6849- if (TASK_SIZE - len >= addr &&
6850- (!vma || addr + len <= vma->vm_start))
6851+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6852 return addr;
6853 }
6854
6855 info.length = len;
6856 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6857 info.align_offset = pgoff << PAGE_SHIFT;
6858+ info.threadstack_offset = offset;
6859
6860 if (dir == DOWN) {
6861 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6862@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6863 {
6864 unsigned long random_factor = 0UL;
6865
6866+#ifdef CONFIG_PAX_RANDMMAP
6867+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6868+#endif
6869+
6870 if (current->flags & PF_RANDOMIZE) {
6871 random_factor = get_random_int();
6872 random_factor = random_factor << PAGE_SHIFT;
6873@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6874
6875 if (mmap_is_legacy()) {
6876 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6877+
6878+#ifdef CONFIG_PAX_RANDMMAP
6879+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6880+ mm->mmap_base += mm->delta_mmap;
6881+#endif
6882+
6883 mm->get_unmapped_area = arch_get_unmapped_area;
6884 } else {
6885 mm->mmap_base = mmap_base(random_factor);
6886+
6887+#ifdef CONFIG_PAX_RANDMMAP
6888+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6889+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6890+#endif
6891+
6892 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6893 }
6894 }
6895
6896-static inline unsigned long brk_rnd(void)
6897-{
6898- unsigned long rnd = get_random_int();
6899-
6900- rnd = rnd << PAGE_SHIFT;
6901- /* 8MB for 32bit, 256MB for 64bit */
6902- if (TASK_IS_32BIT_ADDR)
6903- rnd = rnd & 0x7ffffful;
6904- else
6905- rnd = rnd & 0xffffffful;
6906-
6907- return rnd;
6908-}
6909-
6910-unsigned long arch_randomize_brk(struct mm_struct *mm)
6911-{
6912- unsigned long base = mm->brk;
6913- unsigned long ret;
6914-
6915- ret = PAGE_ALIGN(base + brk_rnd());
6916-
6917- if (ret < mm->brk)
6918- return mm->brk;
6919-
6920- return ret;
6921-}
6922-
6923 int __virt_addr_valid(const volatile void *kaddr)
6924 {
6925 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6926diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6927index a2358b4..7cead4f 100644
6928--- a/arch/mips/sgi-ip27/ip27-nmi.c
6929+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6930@@ -187,9 +187,9 @@ void
6931 cont_nmi_dump(void)
6932 {
6933 #ifndef REAL_NMI_SIGNAL
6934- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6935+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6936
6937- atomic_inc(&nmied_cpus);
6938+ atomic_inc_unchecked(&nmied_cpus);
6939 #endif
6940 /*
6941 * Only allow 1 cpu to proceed
6942@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6943 udelay(10000);
6944 }
6945 #else
6946- while (atomic_read(&nmied_cpus) != num_online_cpus());
6947+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6948 #endif
6949
6950 /*
6951diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6952index 967d144..db12197 100644
6953--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6954+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6955@@ -11,12 +11,14 @@
6956 #ifndef _ASM_PROC_CACHE_H
6957 #define _ASM_PROC_CACHE_H
6958
6959+#include <linux/const.h>
6960+
6961 /* L1 cache */
6962
6963 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6964 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6965-#define L1_CACHE_BYTES 16 /* bytes per entry */
6966 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6967+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6968 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6969
6970 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6971diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6972index bcb5df2..84fabd2 100644
6973--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6974+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6975@@ -16,13 +16,15 @@
6976 #ifndef _ASM_PROC_CACHE_H
6977 #define _ASM_PROC_CACHE_H
6978
6979+#include <linux/const.h>
6980+
6981 /*
6982 * L1 cache
6983 */
6984 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6985 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6986-#define L1_CACHE_BYTES 32 /* bytes per entry */
6987 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6988+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6989 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6990
6991 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6992diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6993index 4ce7a01..449202a 100644
6994--- a/arch/openrisc/include/asm/cache.h
6995+++ b/arch/openrisc/include/asm/cache.h
6996@@ -19,11 +19,13 @@
6997 #ifndef __ASM_OPENRISC_CACHE_H
6998 #define __ASM_OPENRISC_CACHE_H
6999
7000+#include <linux/const.h>
7001+
7002 /* FIXME: How can we replace these with values from the CPU...
7003 * they shouldn't be hard-coded!
7004 */
7005
7006-#define L1_CACHE_BYTES 16
7007 #define L1_CACHE_SHIFT 4
7008+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7009
7010 #endif /* __ASM_OPENRISC_CACHE_H */
7011diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7012index 472886c..00e7df9 100644
7013--- a/arch/parisc/include/asm/atomic.h
7014+++ b/arch/parisc/include/asm/atomic.h
7015@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7016 return dec;
7017 }
7018
7019+#define atomic64_read_unchecked(v) atomic64_read(v)
7020+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7021+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7022+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7023+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7024+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7025+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7026+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7027+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7028+
7029 #endif /* !CONFIG_64BIT */
7030
7031
7032diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7033index 47f11c7..3420df2 100644
7034--- a/arch/parisc/include/asm/cache.h
7035+++ b/arch/parisc/include/asm/cache.h
7036@@ -5,6 +5,7 @@
7037 #ifndef __ARCH_PARISC_CACHE_H
7038 #define __ARCH_PARISC_CACHE_H
7039
7040+#include <linux/const.h>
7041
7042 /*
7043 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7044@@ -15,13 +16,13 @@
7045 * just ruin performance.
7046 */
7047 #ifdef CONFIG_PA20
7048-#define L1_CACHE_BYTES 64
7049 #define L1_CACHE_SHIFT 6
7050 #else
7051-#define L1_CACHE_BYTES 32
7052 #define L1_CACHE_SHIFT 5
7053 #endif
7054
7055+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7056+
7057 #ifndef __ASSEMBLY__
7058
7059 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7060diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7061index ad2b503..bdf1651 100644
7062--- a/arch/parisc/include/asm/elf.h
7063+++ b/arch/parisc/include/asm/elf.h
7064@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7065
7066 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7067
7068+#ifdef CONFIG_PAX_ASLR
7069+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7070+
7071+#define PAX_DELTA_MMAP_LEN 16
7072+#define PAX_DELTA_STACK_LEN 16
7073+#endif
7074+
7075 /* This yields a mask that user programs can use to figure out what
7076 instruction set this CPU supports. This could be done in user space,
7077 but it's not easy, and we've already done it here. */
7078diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7079index fc987a1..6e068ef 100644
7080--- a/arch/parisc/include/asm/pgalloc.h
7081+++ b/arch/parisc/include/asm/pgalloc.h
7082@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7083 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7084 }
7085
7086+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7087+{
7088+ pgd_populate(mm, pgd, pmd);
7089+}
7090+
7091 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7092 {
7093 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7094@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7095 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7096 #define pmd_free(mm, x) do { } while (0)
7097 #define pgd_populate(mm, pmd, pte) BUG()
7098+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7099
7100 #endif
7101
7102diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7103index 34899b5..02dd060 100644
7104--- a/arch/parisc/include/asm/pgtable.h
7105+++ b/arch/parisc/include/asm/pgtable.h
7106@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7107 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7108 #define PAGE_COPY PAGE_EXECREAD
7109 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7110+
7111+#ifdef CONFIG_PAX_PAGEEXEC
7112+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7113+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7114+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7115+#else
7116+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7117+# define PAGE_COPY_NOEXEC PAGE_COPY
7118+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7119+#endif
7120+
7121 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7122 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7123 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7124diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7125index e0a8235..ce2f1e1 100644
7126--- a/arch/parisc/include/asm/uaccess.h
7127+++ b/arch/parisc/include/asm/uaccess.h
7128@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7129 const void __user *from,
7130 unsigned long n)
7131 {
7132- int sz = __compiletime_object_size(to);
7133+ size_t sz = __compiletime_object_size(to);
7134 int ret = -EFAULT;
7135
7136- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7137+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7138 ret = __copy_from_user(to, from, n);
7139 else
7140 copy_from_user_overflow();
7141diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7142index 2a625fb..9908930 100644
7143--- a/arch/parisc/kernel/module.c
7144+++ b/arch/parisc/kernel/module.c
7145@@ -98,16 +98,38 @@
7146
7147 /* three functions to determine where in the module core
7148 * or init pieces the location is */
7149+static inline int in_init_rx(struct module *me, void *loc)
7150+{
7151+ return (loc >= me->module_init_rx &&
7152+ loc < (me->module_init_rx + me->init_size_rx));
7153+}
7154+
7155+static inline int in_init_rw(struct module *me, void *loc)
7156+{
7157+ return (loc >= me->module_init_rw &&
7158+ loc < (me->module_init_rw + me->init_size_rw));
7159+}
7160+
7161 static inline int in_init(struct module *me, void *loc)
7162 {
7163- return (loc >= me->module_init &&
7164- loc <= (me->module_init + me->init_size));
7165+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7166+}
7167+
7168+static inline int in_core_rx(struct module *me, void *loc)
7169+{
7170+ return (loc >= me->module_core_rx &&
7171+ loc < (me->module_core_rx + me->core_size_rx));
7172+}
7173+
7174+static inline int in_core_rw(struct module *me, void *loc)
7175+{
7176+ return (loc >= me->module_core_rw &&
7177+ loc < (me->module_core_rw + me->core_size_rw));
7178 }
7179
7180 static inline int in_core(struct module *me, void *loc)
7181 {
7182- return (loc >= me->module_core &&
7183- loc <= (me->module_core + me->core_size));
7184+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7185 }
7186
7187 static inline int in_local(struct module *me, void *loc)
7188@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7189 }
7190
7191 /* align things a bit */
7192- me->core_size = ALIGN(me->core_size, 16);
7193- me->arch.got_offset = me->core_size;
7194- me->core_size += gots * sizeof(struct got_entry);
7195+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7196+ me->arch.got_offset = me->core_size_rw;
7197+ me->core_size_rw += gots * sizeof(struct got_entry);
7198
7199- me->core_size = ALIGN(me->core_size, 16);
7200- me->arch.fdesc_offset = me->core_size;
7201- me->core_size += fdescs * sizeof(Elf_Fdesc);
7202+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7203+ me->arch.fdesc_offset = me->core_size_rw;
7204+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7205
7206 me->arch.got_max = gots;
7207 me->arch.fdesc_max = fdescs;
7208@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7209
7210 BUG_ON(value == 0);
7211
7212- got = me->module_core + me->arch.got_offset;
7213+ got = me->module_core_rw + me->arch.got_offset;
7214 for (i = 0; got[i].addr; i++)
7215 if (got[i].addr == value)
7216 goto out;
7217@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7218 #ifdef CONFIG_64BIT
7219 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7220 {
7221- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7222+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7223
7224 if (!value) {
7225 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7226@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7227
7228 /* Create new one */
7229 fdesc->addr = value;
7230- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7231+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7232 return (Elf_Addr)fdesc;
7233 }
7234 #endif /* CONFIG_64BIT */
7235@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7236
7237 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7238 end = table + sechdrs[me->arch.unwind_section].sh_size;
7239- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7240+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7241
7242 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7243 me->arch.unwind_section, table, end, gp);
7244diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7245index 0d3a9d4..44975d0 100644
7246--- a/arch/parisc/kernel/sys_parisc.c
7247+++ b/arch/parisc/kernel/sys_parisc.c
7248@@ -33,9 +33,11 @@
7249 #include <linux/utsname.h>
7250 #include <linux/personality.h>
7251
7252-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7253+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7254+ unsigned long flags)
7255 {
7256 struct vm_unmapped_area_info info;
7257+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7258
7259 info.flags = 0;
7260 info.length = len;
7261@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7262 info.high_limit = TASK_SIZE;
7263 info.align_mask = 0;
7264 info.align_offset = 0;
7265+ info.threadstack_offset = offset;
7266 return vm_unmapped_area(&info);
7267 }
7268
7269@@ -69,15 +72,17 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7270 }
7271
7272 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7273- unsigned long len, unsigned long pgoff)
7274+ unsigned long len, unsigned long pgoff, unsigned long flags)
7275 {
7276 struct vm_unmapped_area_info info;
7277+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7278
7279 info.flags = 0;
7280 info.length = len;
7281 info.low_limit = PAGE_ALIGN(addr);
7282 info.high_limit = TASK_SIZE;
7283 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7284+ info.threadstack_offset = offset;
7285 info.align_offset = shared_align_offset(filp, pgoff);
7286 return vm_unmapped_area(&info);
7287 }
7288@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7289 return -EINVAL;
7290 return addr;
7291 }
7292- if (!addr)
7293+ if (!addr) {
7294 addr = TASK_UNMAPPED_BASE;
7295
7296+#ifdef CONFIG_PAX_RANDMMAP
7297+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7298+ addr += current->mm->delta_mmap;
7299+#endif
7300+
7301+ }
7302+
7303 if (filp || (flags & MAP_SHARED))
7304- addr = get_shared_area(filp, addr, len, pgoff);
7305+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7306 else
7307- addr = get_unshared_area(addr, len);
7308+ addr = get_unshared_area(addr, len, flags);
7309
7310 return addr;
7311 }
7312diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7313index 1cd1d0c..44ec918 100644
7314--- a/arch/parisc/kernel/traps.c
7315+++ b/arch/parisc/kernel/traps.c
7316@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7317
7318 down_read(&current->mm->mmap_sem);
7319 vma = find_vma(current->mm,regs->iaoq[0]);
7320- if (vma && (regs->iaoq[0] >= vma->vm_start)
7321- && (vma->vm_flags & VM_EXEC)) {
7322-
7323+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7324 fault_address = regs->iaoq[0];
7325 fault_space = regs->iasq[0];
7326
7327diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7328index 0293588..3b229aa 100644
7329--- a/arch/parisc/mm/fault.c
7330+++ b/arch/parisc/mm/fault.c
7331@@ -15,6 +15,7 @@
7332 #include <linux/sched.h>
7333 #include <linux/interrupt.h>
7334 #include <linux/module.h>
7335+#include <linux/unistd.h>
7336
7337 #include <asm/uaccess.h>
7338 #include <asm/traps.h>
7339@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7340 static unsigned long
7341 parisc_acctyp(unsigned long code, unsigned int inst)
7342 {
7343- if (code == 6 || code == 16)
7344+ if (code == 6 || code == 7 || code == 16)
7345 return VM_EXEC;
7346
7347 switch (inst & 0xf0000000) {
7348@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7349 }
7350 #endif
7351
7352+#ifdef CONFIG_PAX_PAGEEXEC
7353+/*
7354+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7355+ *
7356+ * returns 1 when task should be killed
7357+ * 2 when rt_sigreturn trampoline was detected
7358+ * 3 when unpatched PLT trampoline was detected
7359+ */
7360+static int pax_handle_fetch_fault(struct pt_regs *regs)
7361+{
7362+
7363+#ifdef CONFIG_PAX_EMUPLT
7364+ int err;
7365+
7366+ do { /* PaX: unpatched PLT emulation */
7367+ unsigned int bl, depwi;
7368+
7369+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7370+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7371+
7372+ if (err)
7373+ break;
7374+
7375+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7376+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7377+
7378+ err = get_user(ldw, (unsigned int *)addr);
7379+ err |= get_user(bv, (unsigned int *)(addr+4));
7380+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7381+
7382+ if (err)
7383+ break;
7384+
7385+ if (ldw == 0x0E801096U &&
7386+ bv == 0xEAC0C000U &&
7387+ ldw2 == 0x0E881095U)
7388+ {
7389+ unsigned int resolver, map;
7390+
7391+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7392+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7393+ if (err)
7394+ break;
7395+
7396+ regs->gr[20] = instruction_pointer(regs)+8;
7397+ regs->gr[21] = map;
7398+ regs->gr[22] = resolver;
7399+ regs->iaoq[0] = resolver | 3UL;
7400+ regs->iaoq[1] = regs->iaoq[0] + 4;
7401+ return 3;
7402+ }
7403+ }
7404+ } while (0);
7405+#endif
7406+
7407+#ifdef CONFIG_PAX_EMUTRAMP
7408+
7409+#ifndef CONFIG_PAX_EMUSIGRT
7410+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7411+ return 1;
7412+#endif
7413+
7414+ do { /* PaX: rt_sigreturn emulation */
7415+ unsigned int ldi1, ldi2, bel, nop;
7416+
7417+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7418+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7419+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7420+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7421+
7422+ if (err)
7423+ break;
7424+
7425+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7426+ ldi2 == 0x3414015AU &&
7427+ bel == 0xE4008200U &&
7428+ nop == 0x08000240U)
7429+ {
7430+ regs->gr[25] = (ldi1 & 2) >> 1;
7431+ regs->gr[20] = __NR_rt_sigreturn;
7432+ regs->gr[31] = regs->iaoq[1] + 16;
7433+ regs->sr[0] = regs->iasq[1];
7434+ regs->iaoq[0] = 0x100UL;
7435+ regs->iaoq[1] = regs->iaoq[0] + 4;
7436+ regs->iasq[0] = regs->sr[2];
7437+ regs->iasq[1] = regs->sr[2];
7438+ return 2;
7439+ }
7440+ } while (0);
7441+#endif
7442+
7443+ return 1;
7444+}
7445+
7446+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7447+{
7448+ unsigned long i;
7449+
7450+ printk(KERN_ERR "PAX: bytes at PC: ");
7451+ for (i = 0; i < 5; i++) {
7452+ unsigned int c;
7453+ if (get_user(c, (unsigned int *)pc+i))
7454+ printk(KERN_CONT "???????? ");
7455+ else
7456+ printk(KERN_CONT "%08x ", c);
7457+ }
7458+ printk("\n");
7459+}
7460+#endif
7461+
7462 int fixup_exception(struct pt_regs *regs)
7463 {
7464 const struct exception_table_entry *fix;
7465@@ -204,8 +315,33 @@ retry:
7466
7467 good_area:
7468
7469- if ((vma->vm_flags & acc_type) != acc_type)
7470+ if ((vma->vm_flags & acc_type) != acc_type) {
7471+
7472+#ifdef CONFIG_PAX_PAGEEXEC
7473+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7474+ (address & ~3UL) == instruction_pointer(regs))
7475+ {
7476+ up_read(&mm->mmap_sem);
7477+ switch (pax_handle_fetch_fault(regs)) {
7478+
7479+#ifdef CONFIG_PAX_EMUPLT
7480+ case 3:
7481+ return;
7482+#endif
7483+
7484+#ifdef CONFIG_PAX_EMUTRAMP
7485+ case 2:
7486+ return;
7487+#endif
7488+
7489+ }
7490+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7491+ do_group_exit(SIGKILL);
7492+ }
7493+#endif
7494+
7495 goto bad_area;
7496+ }
7497
7498 /*
7499 * If for any reason at all we couldn't handle the fault, make
7500diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7501index 38f3b7e..7e485c0 100644
7502--- a/arch/powerpc/Kconfig
7503+++ b/arch/powerpc/Kconfig
7504@@ -378,6 +378,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7505 config KEXEC
7506 bool "kexec system call"
7507 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7508+ depends on !GRKERNSEC_KMEM
7509 help
7510 kexec is a system call that implements the ability to shutdown your
7511 current kernel, and to start another kernel. It is like a reboot
7512diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7513index e3b1d41..8e81edf 100644
7514--- a/arch/powerpc/include/asm/atomic.h
7515+++ b/arch/powerpc/include/asm/atomic.h
7516@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7517 return t1;
7518 }
7519
7520+#define atomic64_read_unchecked(v) atomic64_read(v)
7521+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7522+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7523+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7524+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7525+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7526+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7527+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7528+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7529+
7530 #endif /* __powerpc64__ */
7531
7532 #endif /* __KERNEL__ */
7533diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7534index 9e495c9..b6878e5 100644
7535--- a/arch/powerpc/include/asm/cache.h
7536+++ b/arch/powerpc/include/asm/cache.h
7537@@ -3,6 +3,7 @@
7538
7539 #ifdef __KERNEL__
7540
7541+#include <linux/const.h>
7542
7543 /* bytes per L1 cache line */
7544 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7545@@ -22,7 +23,7 @@
7546 #define L1_CACHE_SHIFT 7
7547 #endif
7548
7549-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7550+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7551
7552 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7553
7554diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7555index cc0655a..13eac2e 100644
7556--- a/arch/powerpc/include/asm/elf.h
7557+++ b/arch/powerpc/include/asm/elf.h
7558@@ -28,8 +28,19 @@
7559 the loader. We need to make sure that it is out of the way of the program
7560 that it will "exec", and that there is sufficient room for the brk. */
7561
7562-extern unsigned long randomize_et_dyn(unsigned long base);
7563-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7564+#define ELF_ET_DYN_BASE (0x20000000)
7565+
7566+#ifdef CONFIG_PAX_ASLR
7567+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7568+
7569+#ifdef __powerpc64__
7570+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7571+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7572+#else
7573+#define PAX_DELTA_MMAP_LEN 15
7574+#define PAX_DELTA_STACK_LEN 15
7575+#endif
7576+#endif
7577
7578 /*
7579 * Our registers are always unsigned longs, whether we're a 32 bit
7580@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7581 (0x7ff >> (PAGE_SHIFT - 12)) : \
7582 (0x3ffff >> (PAGE_SHIFT - 12)))
7583
7584-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7585-#define arch_randomize_brk arch_randomize_brk
7586-
7587-
7588 #ifdef CONFIG_SPU_BASE
7589 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7590 #define NT_SPU 1
7591diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7592index 8196e9c..d83a9f3 100644
7593--- a/arch/powerpc/include/asm/exec.h
7594+++ b/arch/powerpc/include/asm/exec.h
7595@@ -4,6 +4,6 @@
7596 #ifndef _ASM_POWERPC_EXEC_H
7597 #define _ASM_POWERPC_EXEC_H
7598
7599-extern unsigned long arch_align_stack(unsigned long sp);
7600+#define arch_align_stack(x) ((x) & ~0xfUL)
7601
7602 #endif /* _ASM_POWERPC_EXEC_H */
7603diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7604index 5acabbd..7ea14fa 100644
7605--- a/arch/powerpc/include/asm/kmap_types.h
7606+++ b/arch/powerpc/include/asm/kmap_types.h
7607@@ -10,7 +10,7 @@
7608 * 2 of the License, or (at your option) any later version.
7609 */
7610
7611-#define KM_TYPE_NR 16
7612+#define KM_TYPE_NR 17
7613
7614 #endif /* __KERNEL__ */
7615 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7616diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7617index 8565c25..2865190 100644
7618--- a/arch/powerpc/include/asm/mman.h
7619+++ b/arch/powerpc/include/asm/mman.h
7620@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7621 }
7622 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7623
7624-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7625+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7626 {
7627 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7628 }
7629diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7630index b9f4262..dcf04f7 100644
7631--- a/arch/powerpc/include/asm/page.h
7632+++ b/arch/powerpc/include/asm/page.h
7633@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7634 * and needs to be executable. This means the whole heap ends
7635 * up being executable.
7636 */
7637-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7638- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7639+#define VM_DATA_DEFAULT_FLAGS32 \
7640+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7641+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7642
7643 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7644 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7645@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7646 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7647 #endif
7648
7649+#define ktla_ktva(addr) (addr)
7650+#define ktva_ktla(addr) (addr)
7651+
7652 #ifndef CONFIG_PPC_BOOK3S_64
7653 /*
7654 * Use the top bit of the higher-level page table entries to indicate whether
7655diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7656index 88693ce..ac6f9ab 100644
7657--- a/arch/powerpc/include/asm/page_64.h
7658+++ b/arch/powerpc/include/asm/page_64.h
7659@@ -153,15 +153,18 @@ do { \
7660 * stack by default, so in the absence of a PT_GNU_STACK program header
7661 * we turn execute permission off.
7662 */
7663-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7664- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7665+#define VM_STACK_DEFAULT_FLAGS32 \
7666+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7667+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7668
7669 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7670 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7671
7672+#ifndef CONFIG_PAX_PAGEEXEC
7673 #define VM_STACK_DEFAULT_FLAGS \
7674 (is_32bit_task() ? \
7675 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7676+#endif
7677
7678 #include <asm-generic/getorder.h>
7679
7680diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7681index f65e27b..23ffb5b 100644
7682--- a/arch/powerpc/include/asm/pgalloc-64.h
7683+++ b/arch/powerpc/include/asm/pgalloc-64.h
7684@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7685 #ifndef CONFIG_PPC_64K_PAGES
7686
7687 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7688+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7689
7690 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7691 {
7692@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7693 pud_set(pud, (unsigned long)pmd);
7694 }
7695
7696+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7697+{
7698+ pud_populate(mm, pud, pmd);
7699+}
7700+
7701 #define pmd_populate(mm, pmd, pte_page) \
7702 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7703 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7704@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7705 #endif
7706
7707 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7708+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7709
7710 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7711 pte_t *pte)
7712diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7713index 7d6eacf..14c0240 100644
7714--- a/arch/powerpc/include/asm/pgtable.h
7715+++ b/arch/powerpc/include/asm/pgtable.h
7716@@ -2,6 +2,7 @@
7717 #define _ASM_POWERPC_PGTABLE_H
7718 #ifdef __KERNEL__
7719
7720+#include <linux/const.h>
7721 #ifndef __ASSEMBLY__
7722 #include <asm/processor.h> /* For TASK_SIZE */
7723 #include <asm/mmu.h>
7724diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7725index 4aad413..85d86bf 100644
7726--- a/arch/powerpc/include/asm/pte-hash32.h
7727+++ b/arch/powerpc/include/asm/pte-hash32.h
7728@@ -21,6 +21,7 @@
7729 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7730 #define _PAGE_USER 0x004 /* usermode access allowed */
7731 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7732+#define _PAGE_EXEC _PAGE_GUARDED
7733 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7734 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7735 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7736diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7737index 10d1ef0..8f83abc 100644
7738--- a/arch/powerpc/include/asm/reg.h
7739+++ b/arch/powerpc/include/asm/reg.h
7740@@ -234,6 +234,7 @@
7741 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7742 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7743 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7744+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7745 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7746 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7747 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7748diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7749index 98da78e..dc68271 100644
7750--- a/arch/powerpc/include/asm/smp.h
7751+++ b/arch/powerpc/include/asm/smp.h
7752@@ -50,7 +50,7 @@ struct smp_ops_t {
7753 int (*cpu_disable)(void);
7754 void (*cpu_die)(unsigned int nr);
7755 int (*cpu_bootable)(unsigned int nr);
7756-};
7757+} __no_const;
7758
7759 extern void smp_send_debugger_break(void);
7760 extern void start_secondary_resume(void);
7761diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7762index ba7b197..d292e26 100644
7763--- a/arch/powerpc/include/asm/thread_info.h
7764+++ b/arch/powerpc/include/asm/thread_info.h
7765@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7766 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7767 TIF_NEED_RESCHED */
7768 #define TIF_32BIT 4 /* 32 bit binary */
7769-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7770 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7771 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7772 #define TIF_SINGLESTEP 8 /* singlestepping active */
7773@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7774 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7775 for stack store? */
7776 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7777+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7778+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7779+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7780
7781 /* as above, but as bit values */
7782 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7783@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7784 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7785 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7786 #define _TIF_NOHZ (1<<TIF_NOHZ)
7787+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7788 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7789 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7790- _TIF_NOHZ)
7791+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7792
7793 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7794 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7795diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7796index 9485b43..4718d50 100644
7797--- a/arch/powerpc/include/asm/uaccess.h
7798+++ b/arch/powerpc/include/asm/uaccess.h
7799@@ -318,52 +318,6 @@ do { \
7800 extern unsigned long __copy_tofrom_user(void __user *to,
7801 const void __user *from, unsigned long size);
7802
7803-#ifndef __powerpc64__
7804-
7805-static inline unsigned long copy_from_user(void *to,
7806- const void __user *from, unsigned long n)
7807-{
7808- unsigned long over;
7809-
7810- if (access_ok(VERIFY_READ, from, n))
7811- return __copy_tofrom_user((__force void __user *)to, from, n);
7812- if ((unsigned long)from < TASK_SIZE) {
7813- over = (unsigned long)from + n - TASK_SIZE;
7814- return __copy_tofrom_user((__force void __user *)to, from,
7815- n - over) + over;
7816- }
7817- return n;
7818-}
7819-
7820-static inline unsigned long copy_to_user(void __user *to,
7821- const void *from, unsigned long n)
7822-{
7823- unsigned long over;
7824-
7825- if (access_ok(VERIFY_WRITE, to, n))
7826- return __copy_tofrom_user(to, (__force void __user *)from, n);
7827- if ((unsigned long)to < TASK_SIZE) {
7828- over = (unsigned long)to + n - TASK_SIZE;
7829- return __copy_tofrom_user(to, (__force void __user *)from,
7830- n - over) + over;
7831- }
7832- return n;
7833-}
7834-
7835-#else /* __powerpc64__ */
7836-
7837-#define __copy_in_user(to, from, size) \
7838- __copy_tofrom_user((to), (from), (size))
7839-
7840-extern unsigned long copy_from_user(void *to, const void __user *from,
7841- unsigned long n);
7842-extern unsigned long copy_to_user(void __user *to, const void *from,
7843- unsigned long n);
7844-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7845- unsigned long n);
7846-
7847-#endif /* __powerpc64__ */
7848-
7849 static inline unsigned long __copy_from_user_inatomic(void *to,
7850 const void __user *from, unsigned long n)
7851 {
7852@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7853 if (ret == 0)
7854 return 0;
7855 }
7856+
7857+ if (!__builtin_constant_p(n))
7858+ check_object_size(to, n, false);
7859+
7860 return __copy_tofrom_user((__force void __user *)to, from, n);
7861 }
7862
7863@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7864 if (ret == 0)
7865 return 0;
7866 }
7867+
7868+ if (!__builtin_constant_p(n))
7869+ check_object_size(from, n, true);
7870+
7871 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7872 }
7873
7874@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7875 return __copy_to_user_inatomic(to, from, size);
7876 }
7877
7878+#ifndef __powerpc64__
7879+
7880+static inline unsigned long __must_check copy_from_user(void *to,
7881+ const void __user *from, unsigned long n)
7882+{
7883+ unsigned long over;
7884+
7885+ if ((long)n < 0)
7886+ return n;
7887+
7888+ if (access_ok(VERIFY_READ, from, n)) {
7889+ if (!__builtin_constant_p(n))
7890+ check_object_size(to, n, false);
7891+ return __copy_tofrom_user((__force void __user *)to, from, n);
7892+ }
7893+ if ((unsigned long)from < TASK_SIZE) {
7894+ over = (unsigned long)from + n - TASK_SIZE;
7895+ if (!__builtin_constant_p(n - over))
7896+ check_object_size(to, n - over, false);
7897+ return __copy_tofrom_user((__force void __user *)to, from,
7898+ n - over) + over;
7899+ }
7900+ return n;
7901+}
7902+
7903+static inline unsigned long __must_check copy_to_user(void __user *to,
7904+ const void *from, unsigned long n)
7905+{
7906+ unsigned long over;
7907+
7908+ if ((long)n < 0)
7909+ return n;
7910+
7911+ if (access_ok(VERIFY_WRITE, to, n)) {
7912+ if (!__builtin_constant_p(n))
7913+ check_object_size(from, n, true);
7914+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7915+ }
7916+ if ((unsigned long)to < TASK_SIZE) {
7917+ over = (unsigned long)to + n - TASK_SIZE;
7918+ if (!__builtin_constant_p(n))
7919+ check_object_size(from, n - over, true);
7920+ return __copy_tofrom_user(to, (__force void __user *)from,
7921+ n - over) + over;
7922+ }
7923+ return n;
7924+}
7925+
7926+#else /* __powerpc64__ */
7927+
7928+#define __copy_in_user(to, from, size) \
7929+ __copy_tofrom_user((to), (from), (size))
7930+
7931+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7932+{
7933+ if ((long)n < 0 || n > INT_MAX)
7934+ return n;
7935+
7936+ if (!__builtin_constant_p(n))
7937+ check_object_size(to, n, false);
7938+
7939+ if (likely(access_ok(VERIFY_READ, from, n)))
7940+ n = __copy_from_user(to, from, n);
7941+ else
7942+ memset(to, 0, n);
7943+ return n;
7944+}
7945+
7946+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7947+{
7948+ if ((long)n < 0 || n > INT_MAX)
7949+ return n;
7950+
7951+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7952+ if (!__builtin_constant_p(n))
7953+ check_object_size(from, n, true);
7954+ n = __copy_to_user(to, from, n);
7955+ }
7956+ return n;
7957+}
7958+
7959+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7960+ unsigned long n);
7961+
7962+#endif /* __powerpc64__ */
7963+
7964 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7965
7966 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7967diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7968index 2d06704..1616f1b 100644
7969--- a/arch/powerpc/kernel/exceptions-64e.S
7970+++ b/arch/powerpc/kernel/exceptions-64e.S
7971@@ -757,6 +757,7 @@ storage_fault_common:
7972 std r14,_DAR(r1)
7973 std r15,_DSISR(r1)
7974 addi r3,r1,STACK_FRAME_OVERHEAD
7975+ bl .save_nvgprs
7976 mr r4,r14
7977 mr r5,r15
7978 ld r14,PACA_EXGEN+EX_R14(r13)
7979@@ -765,8 +766,7 @@ storage_fault_common:
7980 cmpdi r3,0
7981 bne- 1f
7982 b .ret_from_except_lite
7983-1: bl .save_nvgprs
7984- mr r5,r3
7985+1: mr r5,r3
7986 addi r3,r1,STACK_FRAME_OVERHEAD
7987 ld r4,_DAR(r1)
7988 bl .bad_page_fault
7989diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7990index 3a9ed6a..b534681 100644
7991--- a/arch/powerpc/kernel/exceptions-64s.S
7992+++ b/arch/powerpc/kernel/exceptions-64s.S
7993@@ -1364,10 +1364,10 @@ handle_page_fault:
7994 11: ld r4,_DAR(r1)
7995 ld r5,_DSISR(r1)
7996 addi r3,r1,STACK_FRAME_OVERHEAD
7997+ bl .save_nvgprs
7998 bl .do_page_fault
7999 cmpdi r3,0
8000 beq+ 12f
8001- bl .save_nvgprs
8002 mr r5,r3
8003 addi r3,r1,STACK_FRAME_OVERHEAD
8004 lwz r4,_DAR(r1)
8005diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8006index 2e3200c..72095ce 100644
8007--- a/arch/powerpc/kernel/module_32.c
8008+++ b/arch/powerpc/kernel/module_32.c
8009@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8010 me->arch.core_plt_section = i;
8011 }
8012 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8013- printk("Module doesn't contain .plt or .init.plt sections.\n");
8014+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8015 return -ENOEXEC;
8016 }
8017
8018@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8019
8020 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8021 /* Init, or core PLT? */
8022- if (location >= mod->module_core
8023- && location < mod->module_core + mod->core_size)
8024+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8025+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8026 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8027- else
8028+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8029+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8030 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8031+ else {
8032+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8033+ return ~0UL;
8034+ }
8035
8036 /* Find this entry, or if that fails, the next avail. entry */
8037 while (entry->jump[0]) {
8038diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8039index 96d2fdf..f6d10c8 100644
8040--- a/arch/powerpc/kernel/process.c
8041+++ b/arch/powerpc/kernel/process.c
8042@@ -886,8 +886,8 @@ void show_regs(struct pt_regs * regs)
8043 * Lookup NIP late so we have the best change of getting the
8044 * above info out without failing
8045 */
8046- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8047- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8048+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8049+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8050 #endif
8051 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8052 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8053@@ -1352,10 +1352,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8054 newsp = stack[0];
8055 ip = stack[STACK_FRAME_LR_SAVE];
8056 if (!firstframe || ip != lr) {
8057- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8058+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8059 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8060 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8061- printk(" (%pS)",
8062+ printk(" (%pA)",
8063 (void *)current->ret_stack[curr_frame].ret);
8064 curr_frame--;
8065 }
8066@@ -1375,7 +1375,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8067 struct pt_regs *regs = (struct pt_regs *)
8068 (sp + STACK_FRAME_OVERHEAD);
8069 lr = regs->link;
8070- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8071+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8072 regs->trap, (void *)regs->nip, (void *)lr);
8073 firstframe = 1;
8074 }
8075@@ -1411,58 +1411,3 @@ void notrace __ppc64_runlatch_off(void)
8076 mtspr(SPRN_CTRLT, ctrl);
8077 }
8078 #endif /* CONFIG_PPC64 */
8079-
8080-unsigned long arch_align_stack(unsigned long sp)
8081-{
8082- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8083- sp -= get_random_int() & ~PAGE_MASK;
8084- return sp & ~0xf;
8085-}
8086-
8087-static inline unsigned long brk_rnd(void)
8088-{
8089- unsigned long rnd = 0;
8090-
8091- /* 8MB for 32bit, 1GB for 64bit */
8092- if (is_32bit_task())
8093- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8094- else
8095- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8096-
8097- return rnd << PAGE_SHIFT;
8098-}
8099-
8100-unsigned long arch_randomize_brk(struct mm_struct *mm)
8101-{
8102- unsigned long base = mm->brk;
8103- unsigned long ret;
8104-
8105-#ifdef CONFIG_PPC_STD_MMU_64
8106- /*
8107- * If we are using 1TB segments and we are allowed to randomise
8108- * the heap, we can put it above 1TB so it is backed by a 1TB
8109- * segment. Otherwise the heap will be in the bottom 1TB
8110- * which always uses 256MB segments and this may result in a
8111- * performance penalty.
8112- */
8113- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8114- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8115-#endif
8116-
8117- ret = PAGE_ALIGN(base + brk_rnd());
8118-
8119- if (ret < mm->brk)
8120- return mm->brk;
8121-
8122- return ret;
8123-}
8124-
8125-unsigned long randomize_et_dyn(unsigned long base)
8126-{
8127- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8128-
8129- if (ret < base)
8130- return base;
8131-
8132- return ret;
8133-}
8134diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8135index 9a0d24c..e7fbedf 100644
8136--- a/arch/powerpc/kernel/ptrace.c
8137+++ b/arch/powerpc/kernel/ptrace.c
8138@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8139 return ret;
8140 }
8141
8142+#ifdef CONFIG_GRKERNSEC_SETXID
8143+extern void gr_delayed_cred_worker(void);
8144+#endif
8145+
8146 /*
8147 * We must return the syscall number to actually look up in the table.
8148 * This can be -1L to skip running any syscall at all.
8149@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8150
8151 secure_computing_strict(regs->gpr[0]);
8152
8153+#ifdef CONFIG_GRKERNSEC_SETXID
8154+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8155+ gr_delayed_cred_worker();
8156+#endif
8157+
8158 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8159 tracehook_report_syscall_entry(regs))
8160 /*
8161@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8162 {
8163 int step;
8164
8165+#ifdef CONFIG_GRKERNSEC_SETXID
8166+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8167+ gr_delayed_cred_worker();
8168+#endif
8169+
8170 audit_syscall_exit(regs);
8171
8172 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8173diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8174index fea2dba..a779f6b 100644
8175--- a/arch/powerpc/kernel/signal_32.c
8176+++ b/arch/powerpc/kernel/signal_32.c
8177@@ -1002,7 +1002,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8178 /* Save user registers on the stack */
8179 frame = &rt_sf->uc.uc_mcontext;
8180 addr = frame;
8181- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8182+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8183 sigret = 0;
8184 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8185 } else {
8186diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8187index 1e7ba88..17afb1b 100644
8188--- a/arch/powerpc/kernel/signal_64.c
8189+++ b/arch/powerpc/kernel/signal_64.c
8190@@ -763,7 +763,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8191 #endif
8192
8193 /* Set up to return from userspace. */
8194- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8195+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8196 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8197 } else {
8198 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8199diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8200index f783c93..619baf1 100644
8201--- a/arch/powerpc/kernel/traps.c
8202+++ b/arch/powerpc/kernel/traps.c
8203@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8204 return flags;
8205 }
8206
8207+extern void gr_handle_kernel_exploit(void);
8208+
8209 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8210 int signr)
8211 {
8212@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8213 panic("Fatal exception in interrupt");
8214 if (panic_on_oops)
8215 panic("Fatal exception");
8216+
8217+ gr_handle_kernel_exploit();
8218+
8219 do_exit(signr);
8220 }
8221
8222diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8223index 1d9c926..25f4741 100644
8224--- a/arch/powerpc/kernel/vdso.c
8225+++ b/arch/powerpc/kernel/vdso.c
8226@@ -34,6 +34,7 @@
8227 #include <asm/firmware.h>
8228 #include <asm/vdso.h>
8229 #include <asm/vdso_datapage.h>
8230+#include <asm/mman.h>
8231
8232 #include "setup.h"
8233
8234@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8235 vdso_base = VDSO32_MBASE;
8236 #endif
8237
8238- current->mm->context.vdso_base = 0;
8239+ current->mm->context.vdso_base = ~0UL;
8240
8241 /* vDSO has a problem and was disabled, just don't "enable" it for the
8242 * process
8243@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8244 vdso_base = get_unmapped_area(NULL, vdso_base,
8245 (vdso_pages << PAGE_SHIFT) +
8246 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8247- 0, 0);
8248+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8249 if (IS_ERR_VALUE(vdso_base)) {
8250 rc = vdso_base;
8251 goto fail_mmapsem;
8252diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8253index 5eea6f3..5d10396 100644
8254--- a/arch/powerpc/lib/usercopy_64.c
8255+++ b/arch/powerpc/lib/usercopy_64.c
8256@@ -9,22 +9,6 @@
8257 #include <linux/module.h>
8258 #include <asm/uaccess.h>
8259
8260-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8261-{
8262- if (likely(access_ok(VERIFY_READ, from, n)))
8263- n = __copy_from_user(to, from, n);
8264- else
8265- memset(to, 0, n);
8266- return n;
8267-}
8268-
8269-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8270-{
8271- if (likely(access_ok(VERIFY_WRITE, to, n)))
8272- n = __copy_to_user(to, from, n);
8273- return n;
8274-}
8275-
8276 unsigned long copy_in_user(void __user *to, const void __user *from,
8277 unsigned long n)
8278 {
8279@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8280 return n;
8281 }
8282
8283-EXPORT_SYMBOL(copy_from_user);
8284-EXPORT_SYMBOL(copy_to_user);
8285 EXPORT_SYMBOL(copy_in_user);
8286
8287diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8288index 51ab9e7..7d3c78b 100644
8289--- a/arch/powerpc/mm/fault.c
8290+++ b/arch/powerpc/mm/fault.c
8291@@ -33,6 +33,10 @@
8292 #include <linux/magic.h>
8293 #include <linux/ratelimit.h>
8294 #include <linux/context_tracking.h>
8295+#include <linux/slab.h>
8296+#include <linux/pagemap.h>
8297+#include <linux/compiler.h>
8298+#include <linux/unistd.h>
8299
8300 #include <asm/firmware.h>
8301 #include <asm/page.h>
8302@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8303 }
8304 #endif
8305
8306+#ifdef CONFIG_PAX_PAGEEXEC
8307+/*
8308+ * PaX: decide what to do with offenders (regs->nip = fault address)
8309+ *
8310+ * returns 1 when task should be killed
8311+ */
8312+static int pax_handle_fetch_fault(struct pt_regs *regs)
8313+{
8314+ return 1;
8315+}
8316+
8317+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8318+{
8319+ unsigned long i;
8320+
8321+ printk(KERN_ERR "PAX: bytes at PC: ");
8322+ for (i = 0; i < 5; i++) {
8323+ unsigned int c;
8324+ if (get_user(c, (unsigned int __user *)pc+i))
8325+ printk(KERN_CONT "???????? ");
8326+ else
8327+ printk(KERN_CONT "%08x ", c);
8328+ }
8329+ printk("\n");
8330+}
8331+#endif
8332+
8333 /*
8334 * Check whether the instruction at regs->nip is a store using
8335 * an update addressing form which will update r1.
8336@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8337 * indicate errors in DSISR but can validly be set in SRR1.
8338 */
8339 if (trap == 0x400)
8340- error_code &= 0x48200000;
8341+ error_code &= 0x58200000;
8342 else
8343 is_write = error_code & DSISR_ISSTORE;
8344 #else
8345@@ -378,7 +409,7 @@ good_area:
8346 * "undefined". Of those that can be set, this is the only
8347 * one which seems bad.
8348 */
8349- if (error_code & 0x10000000)
8350+ if (error_code & DSISR_GUARDED)
8351 /* Guarded storage error. */
8352 goto bad_area;
8353 #endif /* CONFIG_8xx */
8354@@ -393,7 +424,7 @@ good_area:
8355 * processors use the same I/D cache coherency mechanism
8356 * as embedded.
8357 */
8358- if (error_code & DSISR_PROTFAULT)
8359+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8360 goto bad_area;
8361 #endif /* CONFIG_PPC_STD_MMU */
8362
8363@@ -483,6 +514,23 @@ bad_area:
8364 bad_area_nosemaphore:
8365 /* User mode accesses cause a SIGSEGV */
8366 if (user_mode(regs)) {
8367+
8368+#ifdef CONFIG_PAX_PAGEEXEC
8369+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8370+#ifdef CONFIG_PPC_STD_MMU
8371+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8372+#else
8373+ if (is_exec && regs->nip == address) {
8374+#endif
8375+ switch (pax_handle_fetch_fault(regs)) {
8376+ }
8377+
8378+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8379+ do_group_exit(SIGKILL);
8380+ }
8381+ }
8382+#endif
8383+
8384 _exception(SIGSEGV, regs, code, address);
8385 goto bail;
8386 }
8387diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8388index cb8bdbe..d770680 100644
8389--- a/arch/powerpc/mm/mmap.c
8390+++ b/arch/powerpc/mm/mmap.c
8391@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8392 {
8393 unsigned long rnd = 0;
8394
8395+#ifdef CONFIG_PAX_RANDMMAP
8396+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8397+#endif
8398+
8399 if (current->flags & PF_RANDOMIZE) {
8400 /* 8MB for 32bit, 1GB for 64bit */
8401 if (is_32bit_task())
8402@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8403 */
8404 if (mmap_is_legacy()) {
8405 mm->mmap_base = TASK_UNMAPPED_BASE;
8406+
8407+#ifdef CONFIG_PAX_RANDMMAP
8408+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8409+ mm->mmap_base += mm->delta_mmap;
8410+#endif
8411+
8412 mm->get_unmapped_area = arch_get_unmapped_area;
8413 } else {
8414 mm->mmap_base = mmap_base();
8415+
8416+#ifdef CONFIG_PAX_RANDMMAP
8417+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8418+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8419+#endif
8420+
8421 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8422 }
8423 }
8424diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8425index 7ce9cf3..a964087 100644
8426--- a/arch/powerpc/mm/slice.c
8427+++ b/arch/powerpc/mm/slice.c
8428@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8429 if ((mm->task_size - len) < addr)
8430 return 0;
8431 vma = find_vma(mm, addr);
8432- return (!vma || (addr + len) <= vma->vm_start);
8433+ return check_heap_stack_gap(vma, addr, len, 0);
8434 }
8435
8436 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8437@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8438 info.align_offset = 0;
8439
8440 addr = TASK_UNMAPPED_BASE;
8441+
8442+#ifdef CONFIG_PAX_RANDMMAP
8443+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8444+ addr += mm->delta_mmap;
8445+#endif
8446+
8447 while (addr < TASK_SIZE) {
8448 info.low_limit = addr;
8449 if (!slice_scan_available(addr, available, 1, &addr))
8450@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8451 if (fixed && addr > (mm->task_size - len))
8452 return -EINVAL;
8453
8454+#ifdef CONFIG_PAX_RANDMMAP
8455+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8456+ addr = 0;
8457+#endif
8458+
8459 /* If hint, make sure it matches our alignment restrictions */
8460 if (!fixed && addr) {
8461 addr = _ALIGN_UP(addr, 1ul << pshift);
8462diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8463index 9098692..3d54cd1 100644
8464--- a/arch/powerpc/platforms/cell/spufs/file.c
8465+++ b/arch/powerpc/platforms/cell/spufs/file.c
8466@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8467 return VM_FAULT_NOPAGE;
8468 }
8469
8470-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8471+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8472 unsigned long address,
8473- void *buf, int len, int write)
8474+ void *buf, size_t len, int write)
8475 {
8476 struct spu_context *ctx = vma->vm_file->private_data;
8477 unsigned long offset = address - vma->vm_start;
8478diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8479index c797832..ce575c8 100644
8480--- a/arch/s390/include/asm/atomic.h
8481+++ b/arch/s390/include/asm/atomic.h
8482@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8483 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8484 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8485
8486+#define atomic64_read_unchecked(v) atomic64_read(v)
8487+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8488+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8489+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8490+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8491+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8492+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8493+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8494+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8495+
8496 #define smp_mb__before_atomic_dec() smp_mb()
8497 #define smp_mb__after_atomic_dec() smp_mb()
8498 #define smp_mb__before_atomic_inc() smp_mb()
8499diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8500index 4d7ccac..d03d0ad 100644
8501--- a/arch/s390/include/asm/cache.h
8502+++ b/arch/s390/include/asm/cache.h
8503@@ -9,8 +9,10 @@
8504 #ifndef __ARCH_S390_CACHE_H
8505 #define __ARCH_S390_CACHE_H
8506
8507-#define L1_CACHE_BYTES 256
8508+#include <linux/const.h>
8509+
8510 #define L1_CACHE_SHIFT 8
8511+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8512 #define NET_SKB_PAD 32
8513
8514 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8515diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8516index 78f4f87..598ce39 100644
8517--- a/arch/s390/include/asm/elf.h
8518+++ b/arch/s390/include/asm/elf.h
8519@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8520 the loader. We need to make sure that it is out of the way of the program
8521 that it will "exec", and that there is sufficient room for the brk. */
8522
8523-extern unsigned long randomize_et_dyn(unsigned long base);
8524-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8525+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8526+
8527+#ifdef CONFIG_PAX_ASLR
8528+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8529+
8530+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8531+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8532+#endif
8533
8534 /* This yields a mask that user programs can use to figure out what
8535 instruction set this CPU supports. */
8536@@ -222,9 +228,6 @@ struct linux_binprm;
8537 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8538 int arch_setup_additional_pages(struct linux_binprm *, int);
8539
8540-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8541-#define arch_randomize_brk arch_randomize_brk
8542-
8543 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8544
8545 #endif
8546diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8547index c4a93d6..4d2a9b4 100644
8548--- a/arch/s390/include/asm/exec.h
8549+++ b/arch/s390/include/asm/exec.h
8550@@ -7,6 +7,6 @@
8551 #ifndef __ASM_EXEC_H
8552 #define __ASM_EXEC_H
8553
8554-extern unsigned long arch_align_stack(unsigned long sp);
8555+#define arch_align_stack(x) ((x) & ~0xfUL)
8556
8557 #endif /* __ASM_EXEC_H */
8558diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8559index 9c33ed4..e40cbef 100644
8560--- a/arch/s390/include/asm/uaccess.h
8561+++ b/arch/s390/include/asm/uaccess.h
8562@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8563 copy_to_user(void __user *to, const void *from, unsigned long n)
8564 {
8565 might_fault();
8566+
8567+ if ((long)n < 0)
8568+ return n;
8569+
8570 return __copy_to_user(to, from, n);
8571 }
8572
8573@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8574 static inline unsigned long __must_check
8575 __copy_from_user(void *to, const void __user *from, unsigned long n)
8576 {
8577+ if ((long)n < 0)
8578+ return n;
8579+
8580 if (__builtin_constant_p(n) && (n <= 256))
8581 return uaccess.copy_from_user_small(n, from, to);
8582 else
8583@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8584 static inline unsigned long __must_check
8585 copy_from_user(void *to, const void __user *from, unsigned long n)
8586 {
8587- unsigned int sz = __compiletime_object_size(to);
8588+ size_t sz = __compiletime_object_size(to);
8589
8590 might_fault();
8591- if (unlikely(sz != -1 && sz < n)) {
8592+
8593+ if ((long)n < 0)
8594+ return n;
8595+
8596+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8597 copy_from_user_overflow();
8598 return n;
8599 }
8600diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8601index 7845e15..59c4353 100644
8602--- a/arch/s390/kernel/module.c
8603+++ b/arch/s390/kernel/module.c
8604@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8605
8606 /* Increase core size by size of got & plt and set start
8607 offsets for got and plt. */
8608- me->core_size = ALIGN(me->core_size, 4);
8609- me->arch.got_offset = me->core_size;
8610- me->core_size += me->arch.got_size;
8611- me->arch.plt_offset = me->core_size;
8612- me->core_size += me->arch.plt_size;
8613+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8614+ me->arch.got_offset = me->core_size_rw;
8615+ me->core_size_rw += me->arch.got_size;
8616+ me->arch.plt_offset = me->core_size_rx;
8617+ me->core_size_rx += me->arch.plt_size;
8618 return 0;
8619 }
8620
8621@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8622 if (info->got_initialized == 0) {
8623 Elf_Addr *gotent;
8624
8625- gotent = me->module_core + me->arch.got_offset +
8626+ gotent = me->module_core_rw + me->arch.got_offset +
8627 info->got_offset;
8628 *gotent = val;
8629 info->got_initialized = 1;
8630@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8631 rc = apply_rela_bits(loc, val, 0, 64, 0);
8632 else if (r_type == R_390_GOTENT ||
8633 r_type == R_390_GOTPLTENT) {
8634- val += (Elf_Addr) me->module_core - loc;
8635+ val += (Elf_Addr) me->module_core_rw - loc;
8636 rc = apply_rela_bits(loc, val, 1, 32, 1);
8637 }
8638 break;
8639@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8640 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8641 if (info->plt_initialized == 0) {
8642 unsigned int *ip;
8643- ip = me->module_core + me->arch.plt_offset +
8644+ ip = me->module_core_rx + me->arch.plt_offset +
8645 info->plt_offset;
8646 #ifndef CONFIG_64BIT
8647 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8648@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8649 val - loc + 0xffffUL < 0x1ffffeUL) ||
8650 (r_type == R_390_PLT32DBL &&
8651 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8652- val = (Elf_Addr) me->module_core +
8653+ val = (Elf_Addr) me->module_core_rx +
8654 me->arch.plt_offset +
8655 info->plt_offset;
8656 val += rela->r_addend - loc;
8657@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8658 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8659 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8660 val = val + rela->r_addend -
8661- ((Elf_Addr) me->module_core + me->arch.got_offset);
8662+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8663 if (r_type == R_390_GOTOFF16)
8664 rc = apply_rela_bits(loc, val, 0, 16, 0);
8665 else if (r_type == R_390_GOTOFF32)
8666@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8667 break;
8668 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8669 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8670- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8671+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8672 rela->r_addend - loc;
8673 if (r_type == R_390_GOTPC)
8674 rc = apply_rela_bits(loc, val, 1, 32, 0);
8675diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8676index c5dbb33..b41f4ee 100644
8677--- a/arch/s390/kernel/process.c
8678+++ b/arch/s390/kernel/process.c
8679@@ -237,39 +237,3 @@ unsigned long get_wchan(struct task_struct *p)
8680 }
8681 return 0;
8682 }
8683-
8684-unsigned long arch_align_stack(unsigned long sp)
8685-{
8686- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8687- sp -= get_random_int() & ~PAGE_MASK;
8688- return sp & ~0xf;
8689-}
8690-
8691-static inline unsigned long brk_rnd(void)
8692-{
8693- /* 8MB for 32bit, 1GB for 64bit */
8694- if (is_32bit_task())
8695- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8696- else
8697- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8698-}
8699-
8700-unsigned long arch_randomize_brk(struct mm_struct *mm)
8701-{
8702- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8703-
8704- if (ret < mm->brk)
8705- return mm->brk;
8706- return ret;
8707-}
8708-
8709-unsigned long randomize_et_dyn(unsigned long base)
8710-{
8711- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8712-
8713- if (!(current->flags & PF_RANDOMIZE))
8714- return base;
8715- if (ret < base)
8716- return base;
8717- return ret;
8718-}
8719diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8720index 4002329..99b67cb 100644
8721--- a/arch/s390/mm/mmap.c
8722+++ b/arch/s390/mm/mmap.c
8723@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8724 */
8725 if (mmap_is_legacy()) {
8726 mm->mmap_base = TASK_UNMAPPED_BASE;
8727+
8728+#ifdef CONFIG_PAX_RANDMMAP
8729+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8730+ mm->mmap_base += mm->delta_mmap;
8731+#endif
8732+
8733 mm->get_unmapped_area = arch_get_unmapped_area;
8734 } else {
8735 mm->mmap_base = mmap_base();
8736+
8737+#ifdef CONFIG_PAX_RANDMMAP
8738+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8739+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8740+#endif
8741+
8742 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8743 }
8744 }
8745@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8746 */
8747 if (mmap_is_legacy()) {
8748 mm->mmap_base = TASK_UNMAPPED_BASE;
8749+
8750+#ifdef CONFIG_PAX_RANDMMAP
8751+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8752+ mm->mmap_base += mm->delta_mmap;
8753+#endif
8754+
8755 mm->get_unmapped_area = s390_get_unmapped_area;
8756 } else {
8757 mm->mmap_base = mmap_base();
8758+
8759+#ifdef CONFIG_PAX_RANDMMAP
8760+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8761+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8762+#endif
8763+
8764 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8765 }
8766 }
8767diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8768index ae3d59f..f65f075 100644
8769--- a/arch/score/include/asm/cache.h
8770+++ b/arch/score/include/asm/cache.h
8771@@ -1,7 +1,9 @@
8772 #ifndef _ASM_SCORE_CACHE_H
8773 #define _ASM_SCORE_CACHE_H
8774
8775+#include <linux/const.h>
8776+
8777 #define L1_CACHE_SHIFT 4
8778-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8779+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8780
8781 #endif /* _ASM_SCORE_CACHE_H */
8782diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8783index f9f3cd5..58ff438 100644
8784--- a/arch/score/include/asm/exec.h
8785+++ b/arch/score/include/asm/exec.h
8786@@ -1,6 +1,6 @@
8787 #ifndef _ASM_SCORE_EXEC_H
8788 #define _ASM_SCORE_EXEC_H
8789
8790-extern unsigned long arch_align_stack(unsigned long sp);
8791+#define arch_align_stack(x) (x)
8792
8793 #endif /* _ASM_SCORE_EXEC_H */
8794diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8795index a1519ad3..e8ac1ff 100644
8796--- a/arch/score/kernel/process.c
8797+++ b/arch/score/kernel/process.c
8798@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8799
8800 return task_pt_regs(task)->cp0_epc;
8801 }
8802-
8803-unsigned long arch_align_stack(unsigned long sp)
8804-{
8805- return sp;
8806-}
8807diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8808index ef9e555..331bd29 100644
8809--- a/arch/sh/include/asm/cache.h
8810+++ b/arch/sh/include/asm/cache.h
8811@@ -9,10 +9,11 @@
8812 #define __ASM_SH_CACHE_H
8813 #ifdef __KERNEL__
8814
8815+#include <linux/const.h>
8816 #include <linux/init.h>
8817 #include <cpu/cache.h>
8818
8819-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8820+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8821
8822 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8823
8824diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8825index 6777177..cb5e44f 100644
8826--- a/arch/sh/mm/mmap.c
8827+++ b/arch/sh/mm/mmap.c
8828@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8829 struct mm_struct *mm = current->mm;
8830 struct vm_area_struct *vma;
8831 int do_colour_align;
8832+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8833 struct vm_unmapped_area_info info;
8834
8835 if (flags & MAP_FIXED) {
8836@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8837 if (filp || (flags & MAP_SHARED))
8838 do_colour_align = 1;
8839
8840+#ifdef CONFIG_PAX_RANDMMAP
8841+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8842+#endif
8843+
8844 if (addr) {
8845 if (do_colour_align)
8846 addr = COLOUR_ALIGN(addr, pgoff);
8847@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8848 addr = PAGE_ALIGN(addr);
8849
8850 vma = find_vma(mm, addr);
8851- if (TASK_SIZE - len >= addr &&
8852- (!vma || addr + len <= vma->vm_start))
8853+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8854 return addr;
8855 }
8856
8857 info.flags = 0;
8858 info.length = len;
8859- info.low_limit = TASK_UNMAPPED_BASE;
8860+ info.low_limit = mm->mmap_base;
8861 info.high_limit = TASK_SIZE;
8862 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8863 info.align_offset = pgoff << PAGE_SHIFT;
8864@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8865 struct mm_struct *mm = current->mm;
8866 unsigned long addr = addr0;
8867 int do_colour_align;
8868+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8869 struct vm_unmapped_area_info info;
8870
8871 if (flags & MAP_FIXED) {
8872@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8873 if (filp || (flags & MAP_SHARED))
8874 do_colour_align = 1;
8875
8876+#ifdef CONFIG_PAX_RANDMMAP
8877+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8878+#endif
8879+
8880 /* requesting a specific address */
8881 if (addr) {
8882 if (do_colour_align)
8883@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8884 addr = PAGE_ALIGN(addr);
8885
8886 vma = find_vma(mm, addr);
8887- if (TASK_SIZE - len >= addr &&
8888- (!vma || addr + len <= vma->vm_start))
8889+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8890 return addr;
8891 }
8892
8893@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8894 VM_BUG_ON(addr != -ENOMEM);
8895 info.flags = 0;
8896 info.low_limit = TASK_UNMAPPED_BASE;
8897+
8898+#ifdef CONFIG_PAX_RANDMMAP
8899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8900+ info.low_limit += mm->delta_mmap;
8901+#endif
8902+
8903 info.high_limit = TASK_SIZE;
8904 addr = vm_unmapped_area(&info);
8905 }
8906diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8907index be56a24..443328f 100644
8908--- a/arch/sparc/include/asm/atomic_64.h
8909+++ b/arch/sparc/include/asm/atomic_64.h
8910@@ -14,18 +14,40 @@
8911 #define ATOMIC64_INIT(i) { (i) }
8912
8913 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8914+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8915+{
8916+ return v->counter;
8917+}
8918 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8919+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8920+{
8921+ return v->counter;
8922+}
8923
8924 #define atomic_set(v, i) (((v)->counter) = i)
8925+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8926+{
8927+ v->counter = i;
8928+}
8929 #define atomic64_set(v, i) (((v)->counter) = i)
8930+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8931+{
8932+ v->counter = i;
8933+}
8934
8935 extern void atomic_add(int, atomic_t *);
8936+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8937 extern void atomic64_add(long, atomic64_t *);
8938+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8939 extern void atomic_sub(int, atomic_t *);
8940+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8941 extern void atomic64_sub(long, atomic64_t *);
8942+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8943
8944 extern int atomic_add_ret(int, atomic_t *);
8945+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8946 extern long atomic64_add_ret(long, atomic64_t *);
8947+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8948 extern int atomic_sub_ret(int, atomic_t *);
8949 extern long atomic64_sub_ret(long, atomic64_t *);
8950
8951@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8952 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8953
8954 #define atomic_inc_return(v) atomic_add_ret(1, v)
8955+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8956+{
8957+ return atomic_add_ret_unchecked(1, v);
8958+}
8959 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8960+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8961+{
8962+ return atomic64_add_ret_unchecked(1, v);
8963+}
8964
8965 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8966 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8967
8968 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8969+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8970+{
8971+ return atomic_add_ret_unchecked(i, v);
8972+}
8973 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8974+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8975+{
8976+ return atomic64_add_ret_unchecked(i, v);
8977+}
8978
8979 /*
8980 * atomic_inc_and_test - increment and test
8981@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8982 * other cases.
8983 */
8984 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8985+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8986+{
8987+ return atomic_inc_return_unchecked(v) == 0;
8988+}
8989 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8990
8991 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8992@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8993 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8994
8995 #define atomic_inc(v) atomic_add(1, v)
8996+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8997+{
8998+ atomic_add_unchecked(1, v);
8999+}
9000 #define atomic64_inc(v) atomic64_add(1, v)
9001+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9002+{
9003+ atomic64_add_unchecked(1, v);
9004+}
9005
9006 #define atomic_dec(v) atomic_sub(1, v)
9007+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9008+{
9009+ atomic_sub_unchecked(1, v);
9010+}
9011 #define atomic64_dec(v) atomic64_sub(1, v)
9012+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9013+{
9014+ atomic64_sub_unchecked(1, v);
9015+}
9016
9017 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9018 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9019
9020 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9021+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9022+{
9023+ return cmpxchg(&v->counter, old, new);
9024+}
9025 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9026+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9027+{
9028+ return xchg(&v->counter, new);
9029+}
9030
9031 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9032 {
9033- int c, old;
9034+ int c, old, new;
9035 c = atomic_read(v);
9036 for (;;) {
9037- if (unlikely(c == (u)))
9038+ if (unlikely(c == u))
9039 break;
9040- old = atomic_cmpxchg((v), c, c + (a));
9041+
9042+ asm volatile("addcc %2, %0, %0\n"
9043+
9044+#ifdef CONFIG_PAX_REFCOUNT
9045+ "tvs %%icc, 6\n"
9046+#endif
9047+
9048+ : "=r" (new)
9049+ : "0" (c), "ir" (a)
9050+ : "cc");
9051+
9052+ old = atomic_cmpxchg(v, c, new);
9053 if (likely(old == c))
9054 break;
9055 c = old;
9056@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9057 #define atomic64_cmpxchg(v, o, n) \
9058 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9059 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9060+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9061+{
9062+ return xchg(&v->counter, new);
9063+}
9064
9065 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9066 {
9067- long c, old;
9068+ long c, old, new;
9069 c = atomic64_read(v);
9070 for (;;) {
9071- if (unlikely(c == (u)))
9072+ if (unlikely(c == u))
9073 break;
9074- old = atomic64_cmpxchg((v), c, c + (a));
9075+
9076+ asm volatile("addcc %2, %0, %0\n"
9077+
9078+#ifdef CONFIG_PAX_REFCOUNT
9079+ "tvs %%xcc, 6\n"
9080+#endif
9081+
9082+ : "=r" (new)
9083+ : "0" (c), "ir" (a)
9084+ : "cc");
9085+
9086+ old = atomic64_cmpxchg(v, c, new);
9087 if (likely(old == c))
9088 break;
9089 c = old;
9090 }
9091- return c != (u);
9092+ return c != u;
9093 }
9094
9095 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9096diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9097index 5bb6991..5c2132e 100644
9098--- a/arch/sparc/include/asm/cache.h
9099+++ b/arch/sparc/include/asm/cache.h
9100@@ -7,10 +7,12 @@
9101 #ifndef _SPARC_CACHE_H
9102 #define _SPARC_CACHE_H
9103
9104+#include <linux/const.h>
9105+
9106 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9107
9108 #define L1_CACHE_SHIFT 5
9109-#define L1_CACHE_BYTES 32
9110+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9111
9112 #ifdef CONFIG_SPARC32
9113 #define SMP_CACHE_BYTES_SHIFT 5
9114diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9115index a24e41f..47677ff 100644
9116--- a/arch/sparc/include/asm/elf_32.h
9117+++ b/arch/sparc/include/asm/elf_32.h
9118@@ -114,6 +114,13 @@ typedef struct {
9119
9120 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9121
9122+#ifdef CONFIG_PAX_ASLR
9123+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9124+
9125+#define PAX_DELTA_MMAP_LEN 16
9126+#define PAX_DELTA_STACK_LEN 16
9127+#endif
9128+
9129 /* This yields a mask that user programs can use to figure out what
9130 instruction set this cpu supports. This can NOT be done in userspace
9131 on Sparc. */
9132diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9133index 370ca1e..d4f4a98 100644
9134--- a/arch/sparc/include/asm/elf_64.h
9135+++ b/arch/sparc/include/asm/elf_64.h
9136@@ -189,6 +189,13 @@ typedef struct {
9137 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9138 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9139
9140+#ifdef CONFIG_PAX_ASLR
9141+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9142+
9143+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9144+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9145+#endif
9146+
9147 extern unsigned long sparc64_elf_hwcap;
9148 #define ELF_HWCAP sparc64_elf_hwcap
9149
9150diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9151index 9b1c36d..209298b 100644
9152--- a/arch/sparc/include/asm/pgalloc_32.h
9153+++ b/arch/sparc/include/asm/pgalloc_32.h
9154@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9155 }
9156
9157 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9158+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9159
9160 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9161 unsigned long address)
9162diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9163index bcfe063..b333142 100644
9164--- a/arch/sparc/include/asm/pgalloc_64.h
9165+++ b/arch/sparc/include/asm/pgalloc_64.h
9166@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9167 }
9168
9169 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9170+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9171
9172 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9173 {
9174diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9175index 502f632..da1917f 100644
9176--- a/arch/sparc/include/asm/pgtable_32.h
9177+++ b/arch/sparc/include/asm/pgtable_32.h
9178@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9179 #define PAGE_SHARED SRMMU_PAGE_SHARED
9180 #define PAGE_COPY SRMMU_PAGE_COPY
9181 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9182+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9183+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9184+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9185 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9186
9187 /* Top-level page directory - dummy used by init-mm.
9188@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9189
9190 /* xwr */
9191 #define __P000 PAGE_NONE
9192-#define __P001 PAGE_READONLY
9193-#define __P010 PAGE_COPY
9194-#define __P011 PAGE_COPY
9195+#define __P001 PAGE_READONLY_NOEXEC
9196+#define __P010 PAGE_COPY_NOEXEC
9197+#define __P011 PAGE_COPY_NOEXEC
9198 #define __P100 PAGE_READONLY
9199 #define __P101 PAGE_READONLY
9200 #define __P110 PAGE_COPY
9201 #define __P111 PAGE_COPY
9202
9203 #define __S000 PAGE_NONE
9204-#define __S001 PAGE_READONLY
9205-#define __S010 PAGE_SHARED
9206-#define __S011 PAGE_SHARED
9207+#define __S001 PAGE_READONLY_NOEXEC
9208+#define __S010 PAGE_SHARED_NOEXEC
9209+#define __S011 PAGE_SHARED_NOEXEC
9210 #define __S100 PAGE_READONLY
9211 #define __S101 PAGE_READONLY
9212 #define __S110 PAGE_SHARED
9213diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9214index 79da178..c2eede8 100644
9215--- a/arch/sparc/include/asm/pgtsrmmu.h
9216+++ b/arch/sparc/include/asm/pgtsrmmu.h
9217@@ -115,6 +115,11 @@
9218 SRMMU_EXEC | SRMMU_REF)
9219 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9220 SRMMU_EXEC | SRMMU_REF)
9221+
9222+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9223+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9224+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9225+
9226 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9227 SRMMU_DIRTY | SRMMU_REF)
9228
9229diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9230index 9689176..63c18ea 100644
9231--- a/arch/sparc/include/asm/spinlock_64.h
9232+++ b/arch/sparc/include/asm/spinlock_64.h
9233@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9234
9235 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9236
9237-static void inline arch_read_lock(arch_rwlock_t *lock)
9238+static inline void arch_read_lock(arch_rwlock_t *lock)
9239 {
9240 unsigned long tmp1, tmp2;
9241
9242 __asm__ __volatile__ (
9243 "1: ldsw [%2], %0\n"
9244 " brlz,pn %0, 2f\n"
9245-"4: add %0, 1, %1\n"
9246+"4: addcc %0, 1, %1\n"
9247+
9248+#ifdef CONFIG_PAX_REFCOUNT
9249+" tvs %%icc, 6\n"
9250+#endif
9251+
9252 " cas [%2], %0, %1\n"
9253 " cmp %0, %1\n"
9254 " bne,pn %%icc, 1b\n"
9255@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9256 " .previous"
9257 : "=&r" (tmp1), "=&r" (tmp2)
9258 : "r" (lock)
9259- : "memory");
9260+ : "memory", "cc");
9261 }
9262
9263-static int inline arch_read_trylock(arch_rwlock_t *lock)
9264+static inline int arch_read_trylock(arch_rwlock_t *lock)
9265 {
9266 int tmp1, tmp2;
9267
9268@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9269 "1: ldsw [%2], %0\n"
9270 " brlz,a,pn %0, 2f\n"
9271 " mov 0, %0\n"
9272-" add %0, 1, %1\n"
9273+" addcc %0, 1, %1\n"
9274+
9275+#ifdef CONFIG_PAX_REFCOUNT
9276+" tvs %%icc, 6\n"
9277+#endif
9278+
9279 " cas [%2], %0, %1\n"
9280 " cmp %0, %1\n"
9281 " bne,pn %%icc, 1b\n"
9282@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9283 return tmp1;
9284 }
9285
9286-static void inline arch_read_unlock(arch_rwlock_t *lock)
9287+static inline void arch_read_unlock(arch_rwlock_t *lock)
9288 {
9289 unsigned long tmp1, tmp2;
9290
9291 __asm__ __volatile__(
9292 "1: lduw [%2], %0\n"
9293-" sub %0, 1, %1\n"
9294+" subcc %0, 1, %1\n"
9295+
9296+#ifdef CONFIG_PAX_REFCOUNT
9297+" tvs %%icc, 6\n"
9298+#endif
9299+
9300 " cas [%2], %0, %1\n"
9301 " cmp %0, %1\n"
9302 " bne,pn %%xcc, 1b\n"
9303@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9304 : "memory");
9305 }
9306
9307-static void inline arch_write_lock(arch_rwlock_t *lock)
9308+static inline void arch_write_lock(arch_rwlock_t *lock)
9309 {
9310 unsigned long mask, tmp1, tmp2;
9311
9312@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9313 : "memory");
9314 }
9315
9316-static void inline arch_write_unlock(arch_rwlock_t *lock)
9317+static inline void arch_write_unlock(arch_rwlock_t *lock)
9318 {
9319 __asm__ __volatile__(
9320 " stw %%g0, [%0]"
9321@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9322 : "memory");
9323 }
9324
9325-static int inline arch_write_trylock(arch_rwlock_t *lock)
9326+static inline int arch_write_trylock(arch_rwlock_t *lock)
9327 {
9328 unsigned long mask, tmp1, tmp2, result;
9329
9330diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9331index dd38075..e7cac83 100644
9332--- a/arch/sparc/include/asm/thread_info_32.h
9333+++ b/arch/sparc/include/asm/thread_info_32.h
9334@@ -49,6 +49,8 @@ struct thread_info {
9335 unsigned long w_saved;
9336
9337 struct restart_block restart_block;
9338+
9339+ unsigned long lowest_stack;
9340 };
9341
9342 /*
9343diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9344index d5e5042..9bfee76 100644
9345--- a/arch/sparc/include/asm/thread_info_64.h
9346+++ b/arch/sparc/include/asm/thread_info_64.h
9347@@ -63,6 +63,8 @@ struct thread_info {
9348 struct pt_regs *kern_una_regs;
9349 unsigned int kern_una_insn;
9350
9351+ unsigned long lowest_stack;
9352+
9353 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9354 };
9355
9356@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9357 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9358 /* flag bit 6 is available */
9359 #define TIF_32BIT 7 /* 32-bit binary */
9360-/* flag bit 8 is available */
9361+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9362 #define TIF_SECCOMP 9 /* secure computing */
9363 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9364 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9365+
9366 /* NOTE: Thread flags >= 12 should be ones we have no interest
9367 * in using in assembly, else we can't use the mask as
9368 * an immediate value in instructions such as andcc.
9369@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9370 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9371 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9372 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9373+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9374
9375 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9376 _TIF_DO_NOTIFY_RESUME_MASK | \
9377 _TIF_NEED_RESCHED)
9378 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9379
9380+#define _TIF_WORK_SYSCALL \
9381+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9382+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9383+
9384+
9385 /*
9386 * Thread-synchronous status.
9387 *
9388diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9389index 0167d26..767bb0c 100644
9390--- a/arch/sparc/include/asm/uaccess.h
9391+++ b/arch/sparc/include/asm/uaccess.h
9392@@ -1,5 +1,6 @@
9393 #ifndef ___ASM_SPARC_UACCESS_H
9394 #define ___ASM_SPARC_UACCESS_H
9395+
9396 #if defined(__sparc__) && defined(__arch64__)
9397 #include <asm/uaccess_64.h>
9398 #else
9399diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9400index 53a28dd..50c38c3 100644
9401--- a/arch/sparc/include/asm/uaccess_32.h
9402+++ b/arch/sparc/include/asm/uaccess_32.h
9403@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9404
9405 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9406 {
9407- if (n && __access_ok((unsigned long) to, n))
9408+ if ((long)n < 0)
9409+ return n;
9410+
9411+ if (n && __access_ok((unsigned long) to, n)) {
9412+ if (!__builtin_constant_p(n))
9413+ check_object_size(from, n, true);
9414 return __copy_user(to, (__force void __user *) from, n);
9415- else
9416+ } else
9417 return n;
9418 }
9419
9420 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9421 {
9422+ if ((long)n < 0)
9423+ return n;
9424+
9425+ if (!__builtin_constant_p(n))
9426+ check_object_size(from, n, true);
9427+
9428 return __copy_user(to, (__force void __user *) from, n);
9429 }
9430
9431 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9432 {
9433- if (n && __access_ok((unsigned long) from, n))
9434+ if ((long)n < 0)
9435+ return n;
9436+
9437+ if (n && __access_ok((unsigned long) from, n)) {
9438+ if (!__builtin_constant_p(n))
9439+ check_object_size(to, n, false);
9440 return __copy_user((__force void __user *) to, from, n);
9441- else
9442+ } else
9443 return n;
9444 }
9445
9446 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9447 {
9448+ if ((long)n < 0)
9449+ return n;
9450+
9451 return __copy_user((__force void __user *) to, from, n);
9452 }
9453
9454diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9455index e562d3c..191f176 100644
9456--- a/arch/sparc/include/asm/uaccess_64.h
9457+++ b/arch/sparc/include/asm/uaccess_64.h
9458@@ -10,6 +10,7 @@
9459 #include <linux/compiler.h>
9460 #include <linux/string.h>
9461 #include <linux/thread_info.h>
9462+#include <linux/kernel.h>
9463 #include <asm/asi.h>
9464 #include <asm/spitfire.h>
9465 #include <asm-generic/uaccess-unaligned.h>
9466@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9467 static inline unsigned long __must_check
9468 copy_from_user(void *to, const void __user *from, unsigned long size)
9469 {
9470- unsigned long ret = ___copy_from_user(to, from, size);
9471+ unsigned long ret;
9472
9473+ if ((long)size < 0 || size > INT_MAX)
9474+ return size;
9475+
9476+ if (!__builtin_constant_p(size))
9477+ check_object_size(to, size, false);
9478+
9479+ ret = ___copy_from_user(to, from, size);
9480 if (unlikely(ret))
9481 ret = copy_from_user_fixup(to, from, size);
9482
9483@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9484 static inline unsigned long __must_check
9485 copy_to_user(void __user *to, const void *from, unsigned long size)
9486 {
9487- unsigned long ret = ___copy_to_user(to, from, size);
9488+ unsigned long ret;
9489
9490+ if ((long)size < 0 || size > INT_MAX)
9491+ return size;
9492+
9493+ if (!__builtin_constant_p(size))
9494+ check_object_size(from, size, true);
9495+
9496+ ret = ___copy_to_user(to, from, size);
9497 if (unlikely(ret))
9498 ret = copy_to_user_fixup(to, from, size);
9499 return ret;
9500diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9501index d15cc17..d0ae796 100644
9502--- a/arch/sparc/kernel/Makefile
9503+++ b/arch/sparc/kernel/Makefile
9504@@ -4,7 +4,7 @@
9505 #
9506
9507 asflags-y := -ansi
9508-ccflags-y := -Werror
9509+#ccflags-y := -Werror
9510
9511 extra-y := head_$(BITS).o
9512
9513diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9514index fdd819d..5af08c8 100644
9515--- a/arch/sparc/kernel/process_32.c
9516+++ b/arch/sparc/kernel/process_32.c
9517@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9518
9519 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9520 r->psr, r->pc, r->npc, r->y, print_tainted());
9521- printk("PC: <%pS>\n", (void *) r->pc);
9522+ printk("PC: <%pA>\n", (void *) r->pc);
9523 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9524 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9525 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9526 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9527 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9528 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9529- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9530+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9531
9532 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9533 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9534@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9535 rw = (struct reg_window32 *) fp;
9536 pc = rw->ins[7];
9537 printk("[%08lx : ", pc);
9538- printk("%pS ] ", (void *) pc);
9539+ printk("%pA ] ", (void *) pc);
9540 fp = rw->ins[6];
9541 } while (++count < 16);
9542 printk("\n");
9543diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9544index baebab2..9cd13b1 100644
9545--- a/arch/sparc/kernel/process_64.c
9546+++ b/arch/sparc/kernel/process_64.c
9547@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9548 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9549 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9550 if (regs->tstate & TSTATE_PRIV)
9551- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9552+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9553 }
9554
9555 void show_regs(struct pt_regs *regs)
9556@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9557
9558 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9559 regs->tpc, regs->tnpc, regs->y, print_tainted());
9560- printk("TPC: <%pS>\n", (void *) regs->tpc);
9561+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9562 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9563 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9564 regs->u_regs[3]);
9565@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9566 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9567 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9568 regs->u_regs[15]);
9569- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9570+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9571 show_regwindow(regs);
9572 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9573 }
9574@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9575 ((tp && tp->task) ? tp->task->pid : -1));
9576
9577 if (gp->tstate & TSTATE_PRIV) {
9578- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9579+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9580 (void *) gp->tpc,
9581 (void *) gp->o7,
9582 (void *) gp->i7,
9583diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9584index 79cc0d1..ec62734 100644
9585--- a/arch/sparc/kernel/prom_common.c
9586+++ b/arch/sparc/kernel/prom_common.c
9587@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9588
9589 unsigned int prom_early_allocated __initdata;
9590
9591-static struct of_pdt_ops prom_sparc_ops __initdata = {
9592+static struct of_pdt_ops prom_sparc_ops __initconst = {
9593 .nextprop = prom_common_nextprop,
9594 .getproplen = prom_getproplen,
9595 .getproperty = prom_getproperty,
9596diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9597index 773c1f2..a8bdd87 100644
9598--- a/arch/sparc/kernel/ptrace_64.c
9599+++ b/arch/sparc/kernel/ptrace_64.c
9600@@ -1059,6 +1059,10 @@ long arch_ptrace(struct task_struct *child, long request,
9601 return ret;
9602 }
9603
9604+#ifdef CONFIG_GRKERNSEC_SETXID
9605+extern void gr_delayed_cred_worker(void);
9606+#endif
9607+
9608 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9609 {
9610 int ret = 0;
9611@@ -1066,6 +1070,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9612 /* do the secure computing check first */
9613 secure_computing_strict(regs->u_regs[UREG_G1]);
9614
9615+#ifdef CONFIG_GRKERNSEC_SETXID
9616+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9617+ gr_delayed_cred_worker();
9618+#endif
9619+
9620 if (test_thread_flag(TIF_SYSCALL_TRACE))
9621 ret = tracehook_report_syscall_entry(regs);
9622
9623@@ -1086,6 +1095,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9624
9625 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9626 {
9627+#ifdef CONFIG_GRKERNSEC_SETXID
9628+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9629+ gr_delayed_cred_worker();
9630+#endif
9631+
9632 audit_syscall_exit(regs);
9633
9634 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9635diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9636index e142545..fd29654 100644
9637--- a/arch/sparc/kernel/smp_64.c
9638+++ b/arch/sparc/kernel/smp_64.c
9639@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9640 extern unsigned long xcall_flush_dcache_page_spitfire;
9641
9642 #ifdef CONFIG_DEBUG_DCFLUSH
9643-extern atomic_t dcpage_flushes;
9644-extern atomic_t dcpage_flushes_xcall;
9645+extern atomic_unchecked_t dcpage_flushes;
9646+extern atomic_unchecked_t dcpage_flushes_xcall;
9647 #endif
9648
9649 static inline void __local_flush_dcache_page(struct page *page)
9650@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9651 return;
9652
9653 #ifdef CONFIG_DEBUG_DCFLUSH
9654- atomic_inc(&dcpage_flushes);
9655+ atomic_inc_unchecked(&dcpage_flushes);
9656 #endif
9657
9658 this_cpu = get_cpu();
9659@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9660 xcall_deliver(data0, __pa(pg_addr),
9661 (u64) pg_addr, cpumask_of(cpu));
9662 #ifdef CONFIG_DEBUG_DCFLUSH
9663- atomic_inc(&dcpage_flushes_xcall);
9664+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9665 #endif
9666 }
9667 }
9668@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9669 preempt_disable();
9670
9671 #ifdef CONFIG_DEBUG_DCFLUSH
9672- atomic_inc(&dcpage_flushes);
9673+ atomic_inc_unchecked(&dcpage_flushes);
9674 #endif
9675 data0 = 0;
9676 pg_addr = page_address(page);
9677@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9678 xcall_deliver(data0, __pa(pg_addr),
9679 (u64) pg_addr, cpu_online_mask);
9680 #ifdef CONFIG_DEBUG_DCFLUSH
9681- atomic_inc(&dcpage_flushes_xcall);
9682+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9683 #endif
9684 }
9685 __local_flush_dcache_page(page);
9686diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9687index 3a8d184..49498a8 100644
9688--- a/arch/sparc/kernel/sys_sparc_32.c
9689+++ b/arch/sparc/kernel/sys_sparc_32.c
9690@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9691 if (len > TASK_SIZE - PAGE_SIZE)
9692 return -ENOMEM;
9693 if (!addr)
9694- addr = TASK_UNMAPPED_BASE;
9695+ addr = current->mm->mmap_base;
9696
9697 info.flags = 0;
9698 info.length = len;
9699diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9700index 51561b8..8256764 100644
9701--- a/arch/sparc/kernel/sys_sparc_64.c
9702+++ b/arch/sparc/kernel/sys_sparc_64.c
9703@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9704 struct vm_area_struct * vma;
9705 unsigned long task_size = TASK_SIZE;
9706 int do_color_align;
9707+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9708 struct vm_unmapped_area_info info;
9709
9710 if (flags & MAP_FIXED) {
9711 /* We do not accept a shared mapping if it would violate
9712 * cache aliasing constraints.
9713 */
9714- if ((flags & MAP_SHARED) &&
9715+ if ((filp || (flags & MAP_SHARED)) &&
9716 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9717 return -EINVAL;
9718 return addr;
9719@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9720 if (filp || (flags & MAP_SHARED))
9721 do_color_align = 1;
9722
9723+#ifdef CONFIG_PAX_RANDMMAP
9724+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9725+#endif
9726+
9727 if (addr) {
9728 if (do_color_align)
9729 addr = COLOR_ALIGN(addr, pgoff);
9730@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9731 addr = PAGE_ALIGN(addr);
9732
9733 vma = find_vma(mm, addr);
9734- if (task_size - len >= addr &&
9735- (!vma || addr + len <= vma->vm_start))
9736+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9737 return addr;
9738 }
9739
9740 info.flags = 0;
9741 info.length = len;
9742- info.low_limit = TASK_UNMAPPED_BASE;
9743+ info.low_limit = mm->mmap_base;
9744 info.high_limit = min(task_size, VA_EXCLUDE_START);
9745 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9746 info.align_offset = pgoff << PAGE_SHIFT;
9747+ info.threadstack_offset = offset;
9748 addr = vm_unmapped_area(&info);
9749
9750 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9751 VM_BUG_ON(addr != -ENOMEM);
9752 info.low_limit = VA_EXCLUDE_END;
9753+
9754+#ifdef CONFIG_PAX_RANDMMAP
9755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9756+ info.low_limit += mm->delta_mmap;
9757+#endif
9758+
9759 info.high_limit = task_size;
9760 addr = vm_unmapped_area(&info);
9761 }
9762@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9763 unsigned long task_size = STACK_TOP32;
9764 unsigned long addr = addr0;
9765 int do_color_align;
9766+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9767 struct vm_unmapped_area_info info;
9768
9769 /* This should only ever run for 32-bit processes. */
9770@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9771 /* We do not accept a shared mapping if it would violate
9772 * cache aliasing constraints.
9773 */
9774- if ((flags & MAP_SHARED) &&
9775+ if ((filp || (flags & MAP_SHARED)) &&
9776 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9777 return -EINVAL;
9778 return addr;
9779@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9780 if (filp || (flags & MAP_SHARED))
9781 do_color_align = 1;
9782
9783+#ifdef CONFIG_PAX_RANDMMAP
9784+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9785+#endif
9786+
9787 /* requesting a specific address */
9788 if (addr) {
9789 if (do_color_align)
9790@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9791 addr = PAGE_ALIGN(addr);
9792
9793 vma = find_vma(mm, addr);
9794- if (task_size - len >= addr &&
9795- (!vma || addr + len <= vma->vm_start))
9796+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9797 return addr;
9798 }
9799
9800@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9801 info.high_limit = mm->mmap_base;
9802 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9803 info.align_offset = pgoff << PAGE_SHIFT;
9804+ info.threadstack_offset = offset;
9805 addr = vm_unmapped_area(&info);
9806
9807 /*
9808@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9809 VM_BUG_ON(addr != -ENOMEM);
9810 info.flags = 0;
9811 info.low_limit = TASK_UNMAPPED_BASE;
9812+
9813+#ifdef CONFIG_PAX_RANDMMAP
9814+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9815+ info.low_limit += mm->delta_mmap;
9816+#endif
9817+
9818 info.high_limit = STACK_TOP32;
9819 addr = vm_unmapped_area(&info);
9820 }
9821@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9822 EXPORT_SYMBOL(get_fb_unmapped_area);
9823
9824 /* Essentially the same as PowerPC. */
9825-static unsigned long mmap_rnd(void)
9826+static unsigned long mmap_rnd(struct mm_struct *mm)
9827 {
9828 unsigned long rnd = 0UL;
9829
9830+#ifdef CONFIG_PAX_RANDMMAP
9831+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9832+#endif
9833+
9834 if (current->flags & PF_RANDOMIZE) {
9835 unsigned long val = get_random_int();
9836 if (test_thread_flag(TIF_32BIT))
9837@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9838
9839 void arch_pick_mmap_layout(struct mm_struct *mm)
9840 {
9841- unsigned long random_factor = mmap_rnd();
9842+ unsigned long random_factor = mmap_rnd(mm);
9843 unsigned long gap;
9844
9845 /*
9846@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9847 gap == RLIM_INFINITY ||
9848 sysctl_legacy_va_layout) {
9849 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9850+
9851+#ifdef CONFIG_PAX_RANDMMAP
9852+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9853+ mm->mmap_base += mm->delta_mmap;
9854+#endif
9855+
9856 mm->get_unmapped_area = arch_get_unmapped_area;
9857 } else {
9858 /* We know it's 32-bit */
9859@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9860 gap = (task_size / 6 * 5);
9861
9862 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9863+
9864+#ifdef CONFIG_PAX_RANDMMAP
9865+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9866+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9867+#endif
9868+
9869 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9870 }
9871 }
9872diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9873index d950197..192f9d8 100644
9874--- a/arch/sparc/kernel/syscalls.S
9875+++ b/arch/sparc/kernel/syscalls.S
9876@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9877 #endif
9878 .align 32
9879 1: ldx [%g6 + TI_FLAGS], %l5
9880- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9881+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9882 be,pt %icc, rtrap
9883 nop
9884 call syscall_trace_leave
9885@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9886
9887 srl %i3, 0, %o3 ! IEU0
9888 srl %i2, 0, %o2 ! IEU0 Group
9889- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9890+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9891 bne,pn %icc, linux_syscall_trace32 ! CTI
9892 mov %i0, %l5 ! IEU1
9893 5: call %l7 ! CTI Group brk forced
9894@@ -207,7 +207,7 @@ linux_sparc_syscall:
9895
9896 mov %i3, %o3 ! IEU1
9897 mov %i4, %o4 ! IEU0 Group
9898- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9899+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9900 bne,pn %icc, linux_syscall_trace ! CTI Group
9901 mov %i0, %l5 ! IEU0
9902 2: call %l7 ! CTI Group brk forced
9903@@ -223,7 +223,7 @@ ret_sys_call:
9904
9905 cmp %o0, -ERESTART_RESTARTBLOCK
9906 bgeu,pn %xcc, 1f
9907- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9908+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9909 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9910
9911 2:
9912diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9913index 6629829..036032d 100644
9914--- a/arch/sparc/kernel/traps_32.c
9915+++ b/arch/sparc/kernel/traps_32.c
9916@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9917 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9918 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9919
9920+extern void gr_handle_kernel_exploit(void);
9921+
9922 void die_if_kernel(char *str, struct pt_regs *regs)
9923 {
9924 static int die_counter;
9925@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9926 count++ < 30 &&
9927 (((unsigned long) rw) >= PAGE_OFFSET) &&
9928 !(((unsigned long) rw) & 0x7)) {
9929- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9930+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9931 (void *) rw->ins[7]);
9932 rw = (struct reg_window32 *)rw->ins[6];
9933 }
9934 }
9935 printk("Instruction DUMP:");
9936 instruction_dump ((unsigned long *) regs->pc);
9937- if(regs->psr & PSR_PS)
9938+ if(regs->psr & PSR_PS) {
9939+ gr_handle_kernel_exploit();
9940 do_exit(SIGKILL);
9941+ }
9942 do_exit(SIGSEGV);
9943 }
9944
9945diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9946index b3f833a..f485f80 100644
9947--- a/arch/sparc/kernel/traps_64.c
9948+++ b/arch/sparc/kernel/traps_64.c
9949@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9950 i + 1,
9951 p->trapstack[i].tstate, p->trapstack[i].tpc,
9952 p->trapstack[i].tnpc, p->trapstack[i].tt);
9953- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9954+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9955 }
9956 }
9957
9958@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9959
9960 lvl -= 0x100;
9961 if (regs->tstate & TSTATE_PRIV) {
9962+
9963+#ifdef CONFIG_PAX_REFCOUNT
9964+ if (lvl == 6)
9965+ pax_report_refcount_overflow(regs);
9966+#endif
9967+
9968 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9969 die_if_kernel(buffer, regs);
9970 }
9971@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9972 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9973 {
9974 char buffer[32];
9975-
9976+
9977 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9978 0, lvl, SIGTRAP) == NOTIFY_STOP)
9979 return;
9980
9981+#ifdef CONFIG_PAX_REFCOUNT
9982+ if (lvl == 6)
9983+ pax_report_refcount_overflow(regs);
9984+#endif
9985+
9986 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9987
9988 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9989@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9990 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9991 printk("%s" "ERROR(%d): ",
9992 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9993- printk("TPC<%pS>\n", (void *) regs->tpc);
9994+ printk("TPC<%pA>\n", (void *) regs->tpc);
9995 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9996 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9997 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9998@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9999 smp_processor_id(),
10000 (type & 0x1) ? 'I' : 'D',
10001 regs->tpc);
10002- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10003+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10004 panic("Irrecoverable Cheetah+ parity error.");
10005 }
10006
10007@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10008 smp_processor_id(),
10009 (type & 0x1) ? 'I' : 'D',
10010 regs->tpc);
10011- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10012+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10013 }
10014
10015 struct sun4v_error_entry {
10016@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10017 /*0x38*/u64 reserved_5;
10018 };
10019
10020-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10021-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10022+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10023+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10024
10025 static const char *sun4v_err_type_to_str(u8 type)
10026 {
10027@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10028 }
10029
10030 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10031- int cpu, const char *pfx, atomic_t *ocnt)
10032+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10033 {
10034 u64 *raw_ptr = (u64 *) ent;
10035 u32 attrs;
10036@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10037
10038 show_regs(regs);
10039
10040- if ((cnt = atomic_read(ocnt)) != 0) {
10041- atomic_set(ocnt, 0);
10042+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10043+ atomic_set_unchecked(ocnt, 0);
10044 wmb();
10045 printk("%s: Queue overflowed %d times.\n",
10046 pfx, cnt);
10047@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10048 */
10049 void sun4v_resum_overflow(struct pt_regs *regs)
10050 {
10051- atomic_inc(&sun4v_resum_oflow_cnt);
10052+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10053 }
10054
10055 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10056@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10057 /* XXX Actually even this can make not that much sense. Perhaps
10058 * XXX we should just pull the plug and panic directly from here?
10059 */
10060- atomic_inc(&sun4v_nonresum_oflow_cnt);
10061+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10062 }
10063
10064 unsigned long sun4v_err_itlb_vaddr;
10065@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10066
10067 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10068 regs->tpc, tl);
10069- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10070+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10071 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10072- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10073+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10074 (void *) regs->u_regs[UREG_I7]);
10075 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10076 "pte[%lx] error[%lx]\n",
10077@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10078
10079 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10080 regs->tpc, tl);
10081- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10082+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10083 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10084- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10085+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10086 (void *) regs->u_regs[UREG_I7]);
10087 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10088 "pte[%lx] error[%lx]\n",
10089@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10090 fp = (unsigned long)sf->fp + STACK_BIAS;
10091 }
10092
10093- printk(" [%016lx] %pS\n", pc, (void *) pc);
10094+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10095 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10096 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10097 int index = tsk->curr_ret_stack;
10098 if (tsk->ret_stack && index >= graph) {
10099 pc = tsk->ret_stack[index - graph].ret;
10100- printk(" [%016lx] %pS\n", pc, (void *) pc);
10101+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10102 graph++;
10103 }
10104 }
10105@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10106 return (struct reg_window *) (fp + STACK_BIAS);
10107 }
10108
10109+extern void gr_handle_kernel_exploit(void);
10110+
10111 void die_if_kernel(char *str, struct pt_regs *regs)
10112 {
10113 static int die_counter;
10114@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10115 while (rw &&
10116 count++ < 30 &&
10117 kstack_valid(tp, (unsigned long) rw)) {
10118- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10119+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10120 (void *) rw->ins[7]);
10121
10122 rw = kernel_stack_up(rw);
10123@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10124 }
10125 user_instruction_dump ((unsigned int __user *) regs->tpc);
10126 }
10127- if (regs->tstate & TSTATE_PRIV)
10128+ if (regs->tstate & TSTATE_PRIV) {
10129+ gr_handle_kernel_exploit();
10130 do_exit(SIGKILL);
10131+ }
10132 do_exit(SIGSEGV);
10133 }
10134 EXPORT_SYMBOL(die_if_kernel);
10135diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10136index 8201c25e..072a2a7 100644
10137--- a/arch/sparc/kernel/unaligned_64.c
10138+++ b/arch/sparc/kernel/unaligned_64.c
10139@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10140 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10141
10142 if (__ratelimit(&ratelimit)) {
10143- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10144+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10145 regs->tpc, (void *) regs->tpc);
10146 }
10147 }
10148diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10149index dbe119b..089c7c1 100644
10150--- a/arch/sparc/lib/Makefile
10151+++ b/arch/sparc/lib/Makefile
10152@@ -2,7 +2,7 @@
10153 #
10154
10155 asflags-y := -ansi -DST_DIV0=0x02
10156-ccflags-y := -Werror
10157+#ccflags-y := -Werror
10158
10159 lib-$(CONFIG_SPARC32) += ashrdi3.o
10160 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10161diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10162index 85c233d..68500e0 100644
10163--- a/arch/sparc/lib/atomic_64.S
10164+++ b/arch/sparc/lib/atomic_64.S
10165@@ -17,7 +17,12 @@
10166 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10167 BACKOFF_SETUP(%o2)
10168 1: lduw [%o1], %g1
10169- add %g1, %o0, %g7
10170+ addcc %g1, %o0, %g7
10171+
10172+#ifdef CONFIG_PAX_REFCOUNT
10173+ tvs %icc, 6
10174+#endif
10175+
10176 cas [%o1], %g1, %g7
10177 cmp %g1, %g7
10178 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10179@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10180 2: BACKOFF_SPIN(%o2, %o3, 1b)
10181 ENDPROC(atomic_add)
10182
10183+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10184+ BACKOFF_SETUP(%o2)
10185+1: lduw [%o1], %g1
10186+ add %g1, %o0, %g7
10187+ cas [%o1], %g1, %g7
10188+ cmp %g1, %g7
10189+ bne,pn %icc, 2f
10190+ nop
10191+ retl
10192+ nop
10193+2: BACKOFF_SPIN(%o2, %o3, 1b)
10194+ENDPROC(atomic_add_unchecked)
10195+
10196 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10197 BACKOFF_SETUP(%o2)
10198 1: lduw [%o1], %g1
10199- sub %g1, %o0, %g7
10200+ subcc %g1, %o0, %g7
10201+
10202+#ifdef CONFIG_PAX_REFCOUNT
10203+ tvs %icc, 6
10204+#endif
10205+
10206 cas [%o1], %g1, %g7
10207 cmp %g1, %g7
10208 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10209@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10210 2: BACKOFF_SPIN(%o2, %o3, 1b)
10211 ENDPROC(atomic_sub)
10212
10213+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10214+ BACKOFF_SETUP(%o2)
10215+1: lduw [%o1], %g1
10216+ sub %g1, %o0, %g7
10217+ cas [%o1], %g1, %g7
10218+ cmp %g1, %g7
10219+ bne,pn %icc, 2f
10220+ nop
10221+ retl
10222+ nop
10223+2: BACKOFF_SPIN(%o2, %o3, 1b)
10224+ENDPROC(atomic_sub_unchecked)
10225+
10226 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10227 BACKOFF_SETUP(%o2)
10228 1: lduw [%o1], %g1
10229- add %g1, %o0, %g7
10230+ addcc %g1, %o0, %g7
10231+
10232+#ifdef CONFIG_PAX_REFCOUNT
10233+ tvs %icc, 6
10234+#endif
10235+
10236 cas [%o1], %g1, %g7
10237 cmp %g1, %g7
10238 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10239@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10240 2: BACKOFF_SPIN(%o2, %o3, 1b)
10241 ENDPROC(atomic_add_ret)
10242
10243+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10244+ BACKOFF_SETUP(%o2)
10245+1: lduw [%o1], %g1
10246+ addcc %g1, %o0, %g7
10247+ cas [%o1], %g1, %g7
10248+ cmp %g1, %g7
10249+ bne,pn %icc, 2f
10250+ add %g7, %o0, %g7
10251+ sra %g7, 0, %o0
10252+ retl
10253+ nop
10254+2: BACKOFF_SPIN(%o2, %o3, 1b)
10255+ENDPROC(atomic_add_ret_unchecked)
10256+
10257 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10258 BACKOFF_SETUP(%o2)
10259 1: lduw [%o1], %g1
10260- sub %g1, %o0, %g7
10261+ subcc %g1, %o0, %g7
10262+
10263+#ifdef CONFIG_PAX_REFCOUNT
10264+ tvs %icc, 6
10265+#endif
10266+
10267 cas [%o1], %g1, %g7
10268 cmp %g1, %g7
10269 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10270@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10271 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10272 BACKOFF_SETUP(%o2)
10273 1: ldx [%o1], %g1
10274- add %g1, %o0, %g7
10275+ addcc %g1, %o0, %g7
10276+
10277+#ifdef CONFIG_PAX_REFCOUNT
10278+ tvs %xcc, 6
10279+#endif
10280+
10281 casx [%o1], %g1, %g7
10282 cmp %g1, %g7
10283 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10284@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10285 2: BACKOFF_SPIN(%o2, %o3, 1b)
10286 ENDPROC(atomic64_add)
10287
10288+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10289+ BACKOFF_SETUP(%o2)
10290+1: ldx [%o1], %g1
10291+ addcc %g1, %o0, %g7
10292+ casx [%o1], %g1, %g7
10293+ cmp %g1, %g7
10294+ bne,pn %xcc, 2f
10295+ nop
10296+ retl
10297+ nop
10298+2: BACKOFF_SPIN(%o2, %o3, 1b)
10299+ENDPROC(atomic64_add_unchecked)
10300+
10301 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10302 BACKOFF_SETUP(%o2)
10303 1: ldx [%o1], %g1
10304- sub %g1, %o0, %g7
10305+ subcc %g1, %o0, %g7
10306+
10307+#ifdef CONFIG_PAX_REFCOUNT
10308+ tvs %xcc, 6
10309+#endif
10310+
10311 casx [%o1], %g1, %g7
10312 cmp %g1, %g7
10313 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10314@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10315 2: BACKOFF_SPIN(%o2, %o3, 1b)
10316 ENDPROC(atomic64_sub)
10317
10318+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10319+ BACKOFF_SETUP(%o2)
10320+1: ldx [%o1], %g1
10321+ subcc %g1, %o0, %g7
10322+ casx [%o1], %g1, %g7
10323+ cmp %g1, %g7
10324+ bne,pn %xcc, 2f
10325+ nop
10326+ retl
10327+ nop
10328+2: BACKOFF_SPIN(%o2, %o3, 1b)
10329+ENDPROC(atomic64_sub_unchecked)
10330+
10331 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10332 BACKOFF_SETUP(%o2)
10333 1: ldx [%o1], %g1
10334- add %g1, %o0, %g7
10335+ addcc %g1, %o0, %g7
10336+
10337+#ifdef CONFIG_PAX_REFCOUNT
10338+ tvs %xcc, 6
10339+#endif
10340+
10341 casx [%o1], %g1, %g7
10342 cmp %g1, %g7
10343 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10344@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10345 2: BACKOFF_SPIN(%o2, %o3, 1b)
10346 ENDPROC(atomic64_add_ret)
10347
10348+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10349+ BACKOFF_SETUP(%o2)
10350+1: ldx [%o1], %g1
10351+ addcc %g1, %o0, %g7
10352+ casx [%o1], %g1, %g7
10353+ cmp %g1, %g7
10354+ bne,pn %xcc, 2f
10355+ add %g7, %o0, %g7
10356+ mov %g7, %o0
10357+ retl
10358+ nop
10359+2: BACKOFF_SPIN(%o2, %o3, 1b)
10360+ENDPROC(atomic64_add_ret_unchecked)
10361+
10362 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10363 BACKOFF_SETUP(%o2)
10364 1: ldx [%o1], %g1
10365- sub %g1, %o0, %g7
10366+ subcc %g1, %o0, %g7
10367+
10368+#ifdef CONFIG_PAX_REFCOUNT
10369+ tvs %xcc, 6
10370+#endif
10371+
10372 casx [%o1], %g1, %g7
10373 cmp %g1, %g7
10374 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10375diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10376index 323335b..ed85ea2 100644
10377--- a/arch/sparc/lib/ksyms.c
10378+++ b/arch/sparc/lib/ksyms.c
10379@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10380
10381 /* Atomic counter implementation. */
10382 EXPORT_SYMBOL(atomic_add);
10383+EXPORT_SYMBOL(atomic_add_unchecked);
10384 EXPORT_SYMBOL(atomic_add_ret);
10385+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10386 EXPORT_SYMBOL(atomic_sub);
10387+EXPORT_SYMBOL(atomic_sub_unchecked);
10388 EXPORT_SYMBOL(atomic_sub_ret);
10389 EXPORT_SYMBOL(atomic64_add);
10390+EXPORT_SYMBOL(atomic64_add_unchecked);
10391 EXPORT_SYMBOL(atomic64_add_ret);
10392+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10393 EXPORT_SYMBOL(atomic64_sub);
10394+EXPORT_SYMBOL(atomic64_sub_unchecked);
10395 EXPORT_SYMBOL(atomic64_sub_ret);
10396 EXPORT_SYMBOL(atomic64_dec_if_positive);
10397
10398diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10399index 30c3ecc..736f015 100644
10400--- a/arch/sparc/mm/Makefile
10401+++ b/arch/sparc/mm/Makefile
10402@@ -2,7 +2,7 @@
10403 #
10404
10405 asflags-y := -ansi
10406-ccflags-y := -Werror
10407+#ccflags-y := -Werror
10408
10409 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10410 obj-y += fault_$(BITS).o
10411diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10412index 59dbd46..1dd7f5e 100644
10413--- a/arch/sparc/mm/fault_32.c
10414+++ b/arch/sparc/mm/fault_32.c
10415@@ -21,6 +21,9 @@
10416 #include <linux/perf_event.h>
10417 #include <linux/interrupt.h>
10418 #include <linux/kdebug.h>
10419+#include <linux/slab.h>
10420+#include <linux/pagemap.h>
10421+#include <linux/compiler.h>
10422
10423 #include <asm/page.h>
10424 #include <asm/pgtable.h>
10425@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10426 return safe_compute_effective_address(regs, insn);
10427 }
10428
10429+#ifdef CONFIG_PAX_PAGEEXEC
10430+#ifdef CONFIG_PAX_DLRESOLVE
10431+static void pax_emuplt_close(struct vm_area_struct *vma)
10432+{
10433+ vma->vm_mm->call_dl_resolve = 0UL;
10434+}
10435+
10436+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10437+{
10438+ unsigned int *kaddr;
10439+
10440+ vmf->page = alloc_page(GFP_HIGHUSER);
10441+ if (!vmf->page)
10442+ return VM_FAULT_OOM;
10443+
10444+ kaddr = kmap(vmf->page);
10445+ memset(kaddr, 0, PAGE_SIZE);
10446+ kaddr[0] = 0x9DE3BFA8U; /* save */
10447+ flush_dcache_page(vmf->page);
10448+ kunmap(vmf->page);
10449+ return VM_FAULT_MAJOR;
10450+}
10451+
10452+static const struct vm_operations_struct pax_vm_ops = {
10453+ .close = pax_emuplt_close,
10454+ .fault = pax_emuplt_fault
10455+};
10456+
10457+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10458+{
10459+ int ret;
10460+
10461+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10462+ vma->vm_mm = current->mm;
10463+ vma->vm_start = addr;
10464+ vma->vm_end = addr + PAGE_SIZE;
10465+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10466+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10467+ vma->vm_ops = &pax_vm_ops;
10468+
10469+ ret = insert_vm_struct(current->mm, vma);
10470+ if (ret)
10471+ return ret;
10472+
10473+ ++current->mm->total_vm;
10474+ return 0;
10475+}
10476+#endif
10477+
10478+/*
10479+ * PaX: decide what to do with offenders (regs->pc = fault address)
10480+ *
10481+ * returns 1 when task should be killed
10482+ * 2 when patched PLT trampoline was detected
10483+ * 3 when unpatched PLT trampoline was detected
10484+ */
10485+static int pax_handle_fetch_fault(struct pt_regs *regs)
10486+{
10487+
10488+#ifdef CONFIG_PAX_EMUPLT
10489+ int err;
10490+
10491+ do { /* PaX: patched PLT emulation #1 */
10492+ unsigned int sethi1, sethi2, jmpl;
10493+
10494+ err = get_user(sethi1, (unsigned int *)regs->pc);
10495+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10496+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10497+
10498+ if (err)
10499+ break;
10500+
10501+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10502+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10503+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10504+ {
10505+ unsigned int addr;
10506+
10507+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10508+ addr = regs->u_regs[UREG_G1];
10509+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10510+ regs->pc = addr;
10511+ regs->npc = addr+4;
10512+ return 2;
10513+ }
10514+ } while (0);
10515+
10516+ do { /* PaX: patched PLT emulation #2 */
10517+ unsigned int ba;
10518+
10519+ err = get_user(ba, (unsigned int *)regs->pc);
10520+
10521+ if (err)
10522+ break;
10523+
10524+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10525+ unsigned int addr;
10526+
10527+ if ((ba & 0xFFC00000U) == 0x30800000U)
10528+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10529+ else
10530+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10531+ regs->pc = addr;
10532+ regs->npc = addr+4;
10533+ return 2;
10534+ }
10535+ } while (0);
10536+
10537+ do { /* PaX: patched PLT emulation #3 */
10538+ unsigned int sethi, bajmpl, nop;
10539+
10540+ err = get_user(sethi, (unsigned int *)regs->pc);
10541+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10542+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10543+
10544+ if (err)
10545+ break;
10546+
10547+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10548+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10549+ nop == 0x01000000U)
10550+ {
10551+ unsigned int addr;
10552+
10553+ addr = (sethi & 0x003FFFFFU) << 10;
10554+ regs->u_regs[UREG_G1] = addr;
10555+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10556+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10557+ else
10558+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10559+ regs->pc = addr;
10560+ regs->npc = addr+4;
10561+ return 2;
10562+ }
10563+ } while (0);
10564+
10565+ do { /* PaX: unpatched PLT emulation step 1 */
10566+ unsigned int sethi, ba, nop;
10567+
10568+ err = get_user(sethi, (unsigned int *)regs->pc);
10569+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10570+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10571+
10572+ if (err)
10573+ break;
10574+
10575+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10576+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10577+ nop == 0x01000000U)
10578+ {
10579+ unsigned int addr, save, call;
10580+
10581+ if ((ba & 0xFFC00000U) == 0x30800000U)
10582+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10583+ else
10584+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10585+
10586+ err = get_user(save, (unsigned int *)addr);
10587+ err |= get_user(call, (unsigned int *)(addr+4));
10588+ err |= get_user(nop, (unsigned int *)(addr+8));
10589+ if (err)
10590+ break;
10591+
10592+#ifdef CONFIG_PAX_DLRESOLVE
10593+ if (save == 0x9DE3BFA8U &&
10594+ (call & 0xC0000000U) == 0x40000000U &&
10595+ nop == 0x01000000U)
10596+ {
10597+ struct vm_area_struct *vma;
10598+ unsigned long call_dl_resolve;
10599+
10600+ down_read(&current->mm->mmap_sem);
10601+ call_dl_resolve = current->mm->call_dl_resolve;
10602+ up_read(&current->mm->mmap_sem);
10603+ if (likely(call_dl_resolve))
10604+ goto emulate;
10605+
10606+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10607+
10608+ down_write(&current->mm->mmap_sem);
10609+ if (current->mm->call_dl_resolve) {
10610+ call_dl_resolve = current->mm->call_dl_resolve;
10611+ up_write(&current->mm->mmap_sem);
10612+ if (vma)
10613+ kmem_cache_free(vm_area_cachep, vma);
10614+ goto emulate;
10615+ }
10616+
10617+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10618+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10619+ up_write(&current->mm->mmap_sem);
10620+ if (vma)
10621+ kmem_cache_free(vm_area_cachep, vma);
10622+ return 1;
10623+ }
10624+
10625+ if (pax_insert_vma(vma, call_dl_resolve)) {
10626+ up_write(&current->mm->mmap_sem);
10627+ kmem_cache_free(vm_area_cachep, vma);
10628+ return 1;
10629+ }
10630+
10631+ current->mm->call_dl_resolve = call_dl_resolve;
10632+ up_write(&current->mm->mmap_sem);
10633+
10634+emulate:
10635+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10636+ regs->pc = call_dl_resolve;
10637+ regs->npc = addr+4;
10638+ return 3;
10639+ }
10640+#endif
10641+
10642+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10643+ if ((save & 0xFFC00000U) == 0x05000000U &&
10644+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10645+ nop == 0x01000000U)
10646+ {
10647+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10648+ regs->u_regs[UREG_G2] = addr + 4;
10649+ addr = (save & 0x003FFFFFU) << 10;
10650+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10651+ regs->pc = addr;
10652+ regs->npc = addr+4;
10653+ return 3;
10654+ }
10655+ }
10656+ } while (0);
10657+
10658+ do { /* PaX: unpatched PLT emulation step 2 */
10659+ unsigned int save, call, nop;
10660+
10661+ err = get_user(save, (unsigned int *)(regs->pc-4));
10662+ err |= get_user(call, (unsigned int *)regs->pc);
10663+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10664+ if (err)
10665+ break;
10666+
10667+ if (save == 0x9DE3BFA8U &&
10668+ (call & 0xC0000000U) == 0x40000000U &&
10669+ nop == 0x01000000U)
10670+ {
10671+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10672+
10673+ regs->u_regs[UREG_RETPC] = regs->pc;
10674+ regs->pc = dl_resolve;
10675+ regs->npc = dl_resolve+4;
10676+ return 3;
10677+ }
10678+ } while (0);
10679+#endif
10680+
10681+ return 1;
10682+}
10683+
10684+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10685+{
10686+ unsigned long i;
10687+
10688+ printk(KERN_ERR "PAX: bytes at PC: ");
10689+ for (i = 0; i < 8; i++) {
10690+ unsigned int c;
10691+ if (get_user(c, (unsigned int *)pc+i))
10692+ printk(KERN_CONT "???????? ");
10693+ else
10694+ printk(KERN_CONT "%08x ", c);
10695+ }
10696+ printk("\n");
10697+}
10698+#endif
10699+
10700 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10701 int text_fault)
10702 {
10703@@ -229,6 +503,24 @@ good_area:
10704 if (!(vma->vm_flags & VM_WRITE))
10705 goto bad_area;
10706 } else {
10707+
10708+#ifdef CONFIG_PAX_PAGEEXEC
10709+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10710+ up_read(&mm->mmap_sem);
10711+ switch (pax_handle_fetch_fault(regs)) {
10712+
10713+#ifdef CONFIG_PAX_EMUPLT
10714+ case 2:
10715+ case 3:
10716+ return;
10717+#endif
10718+
10719+ }
10720+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10721+ do_group_exit(SIGKILL);
10722+ }
10723+#endif
10724+
10725 /* Allow reads even for write-only mappings */
10726 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10727 goto bad_area;
10728diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10729index 2ebec26..b212598 100644
10730--- a/arch/sparc/mm/fault_64.c
10731+++ b/arch/sparc/mm/fault_64.c
10732@@ -21,6 +21,9 @@
10733 #include <linux/kprobes.h>
10734 #include <linux/kdebug.h>
10735 #include <linux/percpu.h>
10736+#include <linux/slab.h>
10737+#include <linux/pagemap.h>
10738+#include <linux/compiler.h>
10739
10740 #include <asm/page.h>
10741 #include <asm/pgtable.h>
10742@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10743 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10744 regs->tpc);
10745 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10746- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10747+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10748 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10749 dump_stack();
10750 unhandled_fault(regs->tpc, current, regs);
10751@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10752 show_regs(regs);
10753 }
10754
10755+#ifdef CONFIG_PAX_PAGEEXEC
10756+#ifdef CONFIG_PAX_DLRESOLVE
10757+static void pax_emuplt_close(struct vm_area_struct *vma)
10758+{
10759+ vma->vm_mm->call_dl_resolve = 0UL;
10760+}
10761+
10762+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10763+{
10764+ unsigned int *kaddr;
10765+
10766+ vmf->page = alloc_page(GFP_HIGHUSER);
10767+ if (!vmf->page)
10768+ return VM_FAULT_OOM;
10769+
10770+ kaddr = kmap(vmf->page);
10771+ memset(kaddr, 0, PAGE_SIZE);
10772+ kaddr[0] = 0x9DE3BFA8U; /* save */
10773+ flush_dcache_page(vmf->page);
10774+ kunmap(vmf->page);
10775+ return VM_FAULT_MAJOR;
10776+}
10777+
10778+static const struct vm_operations_struct pax_vm_ops = {
10779+ .close = pax_emuplt_close,
10780+ .fault = pax_emuplt_fault
10781+};
10782+
10783+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10784+{
10785+ int ret;
10786+
10787+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10788+ vma->vm_mm = current->mm;
10789+ vma->vm_start = addr;
10790+ vma->vm_end = addr + PAGE_SIZE;
10791+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10792+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10793+ vma->vm_ops = &pax_vm_ops;
10794+
10795+ ret = insert_vm_struct(current->mm, vma);
10796+ if (ret)
10797+ return ret;
10798+
10799+ ++current->mm->total_vm;
10800+ return 0;
10801+}
10802+#endif
10803+
10804+/*
10805+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10806+ *
10807+ * returns 1 when task should be killed
10808+ * 2 when patched PLT trampoline was detected
10809+ * 3 when unpatched PLT trampoline was detected
10810+ */
10811+static int pax_handle_fetch_fault(struct pt_regs *regs)
10812+{
10813+
10814+#ifdef CONFIG_PAX_EMUPLT
10815+ int err;
10816+
10817+ do { /* PaX: patched PLT emulation #1 */
10818+ unsigned int sethi1, sethi2, jmpl;
10819+
10820+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10821+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10822+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10823+
10824+ if (err)
10825+ break;
10826+
10827+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10828+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10829+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10830+ {
10831+ unsigned long addr;
10832+
10833+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10834+ addr = regs->u_regs[UREG_G1];
10835+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10836+
10837+ if (test_thread_flag(TIF_32BIT))
10838+ addr &= 0xFFFFFFFFUL;
10839+
10840+ regs->tpc = addr;
10841+ regs->tnpc = addr+4;
10842+ return 2;
10843+ }
10844+ } while (0);
10845+
10846+ do { /* PaX: patched PLT emulation #2 */
10847+ unsigned int ba;
10848+
10849+ err = get_user(ba, (unsigned int *)regs->tpc);
10850+
10851+ if (err)
10852+ break;
10853+
10854+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10855+ unsigned long addr;
10856+
10857+ if ((ba & 0xFFC00000U) == 0x30800000U)
10858+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10859+ else
10860+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10861+
10862+ if (test_thread_flag(TIF_32BIT))
10863+ addr &= 0xFFFFFFFFUL;
10864+
10865+ regs->tpc = addr;
10866+ regs->tnpc = addr+4;
10867+ return 2;
10868+ }
10869+ } while (0);
10870+
10871+ do { /* PaX: patched PLT emulation #3 */
10872+ unsigned int sethi, bajmpl, nop;
10873+
10874+ err = get_user(sethi, (unsigned int *)regs->tpc);
10875+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10876+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10877+
10878+ if (err)
10879+ break;
10880+
10881+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10882+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10883+ nop == 0x01000000U)
10884+ {
10885+ unsigned long addr;
10886+
10887+ addr = (sethi & 0x003FFFFFU) << 10;
10888+ regs->u_regs[UREG_G1] = addr;
10889+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10890+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10891+ else
10892+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10893+
10894+ if (test_thread_flag(TIF_32BIT))
10895+ addr &= 0xFFFFFFFFUL;
10896+
10897+ regs->tpc = addr;
10898+ regs->tnpc = addr+4;
10899+ return 2;
10900+ }
10901+ } while (0);
10902+
10903+ do { /* PaX: patched PLT emulation #4 */
10904+ unsigned int sethi, mov1, call, mov2;
10905+
10906+ err = get_user(sethi, (unsigned int *)regs->tpc);
10907+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10908+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10909+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10910+
10911+ if (err)
10912+ break;
10913+
10914+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10915+ mov1 == 0x8210000FU &&
10916+ (call & 0xC0000000U) == 0x40000000U &&
10917+ mov2 == 0x9E100001U)
10918+ {
10919+ unsigned long addr;
10920+
10921+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10922+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10923+
10924+ if (test_thread_flag(TIF_32BIT))
10925+ addr &= 0xFFFFFFFFUL;
10926+
10927+ regs->tpc = addr;
10928+ regs->tnpc = addr+4;
10929+ return 2;
10930+ }
10931+ } while (0);
10932+
10933+ do { /* PaX: patched PLT emulation #5 */
10934+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10935+
10936+ err = get_user(sethi, (unsigned int *)regs->tpc);
10937+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10938+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10939+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10940+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10941+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10942+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10943+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10944+
10945+ if (err)
10946+ break;
10947+
10948+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10949+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10950+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10951+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10952+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10953+ sllx == 0x83287020U &&
10954+ jmpl == 0x81C04005U &&
10955+ nop == 0x01000000U)
10956+ {
10957+ unsigned long addr;
10958+
10959+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10960+ regs->u_regs[UREG_G1] <<= 32;
10961+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10962+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10963+ regs->tpc = addr;
10964+ regs->tnpc = addr+4;
10965+ return 2;
10966+ }
10967+ } while (0);
10968+
10969+ do { /* PaX: patched PLT emulation #6 */
10970+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10971+
10972+ err = get_user(sethi, (unsigned int *)regs->tpc);
10973+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10974+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10975+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10976+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10977+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10978+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10979+
10980+ if (err)
10981+ break;
10982+
10983+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10984+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10985+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10986+ sllx == 0x83287020U &&
10987+ (or & 0xFFFFE000U) == 0x8A116000U &&
10988+ jmpl == 0x81C04005U &&
10989+ nop == 0x01000000U)
10990+ {
10991+ unsigned long addr;
10992+
10993+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10994+ regs->u_regs[UREG_G1] <<= 32;
10995+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10996+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10997+ regs->tpc = addr;
10998+ regs->tnpc = addr+4;
10999+ return 2;
11000+ }
11001+ } while (0);
11002+
11003+ do { /* PaX: unpatched PLT emulation step 1 */
11004+ unsigned int sethi, ba, nop;
11005+
11006+ err = get_user(sethi, (unsigned int *)regs->tpc);
11007+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11008+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11009+
11010+ if (err)
11011+ break;
11012+
11013+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11014+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11015+ nop == 0x01000000U)
11016+ {
11017+ unsigned long addr;
11018+ unsigned int save, call;
11019+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11020+
11021+ if ((ba & 0xFFC00000U) == 0x30800000U)
11022+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11023+ else
11024+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11025+
11026+ if (test_thread_flag(TIF_32BIT))
11027+ addr &= 0xFFFFFFFFUL;
11028+
11029+ err = get_user(save, (unsigned int *)addr);
11030+ err |= get_user(call, (unsigned int *)(addr+4));
11031+ err |= get_user(nop, (unsigned int *)(addr+8));
11032+ if (err)
11033+ break;
11034+
11035+#ifdef CONFIG_PAX_DLRESOLVE
11036+ if (save == 0x9DE3BFA8U &&
11037+ (call & 0xC0000000U) == 0x40000000U &&
11038+ nop == 0x01000000U)
11039+ {
11040+ struct vm_area_struct *vma;
11041+ unsigned long call_dl_resolve;
11042+
11043+ down_read(&current->mm->mmap_sem);
11044+ call_dl_resolve = current->mm->call_dl_resolve;
11045+ up_read(&current->mm->mmap_sem);
11046+ if (likely(call_dl_resolve))
11047+ goto emulate;
11048+
11049+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11050+
11051+ down_write(&current->mm->mmap_sem);
11052+ if (current->mm->call_dl_resolve) {
11053+ call_dl_resolve = current->mm->call_dl_resolve;
11054+ up_write(&current->mm->mmap_sem);
11055+ if (vma)
11056+ kmem_cache_free(vm_area_cachep, vma);
11057+ goto emulate;
11058+ }
11059+
11060+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11061+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11062+ up_write(&current->mm->mmap_sem);
11063+ if (vma)
11064+ kmem_cache_free(vm_area_cachep, vma);
11065+ return 1;
11066+ }
11067+
11068+ if (pax_insert_vma(vma, call_dl_resolve)) {
11069+ up_write(&current->mm->mmap_sem);
11070+ kmem_cache_free(vm_area_cachep, vma);
11071+ return 1;
11072+ }
11073+
11074+ current->mm->call_dl_resolve = call_dl_resolve;
11075+ up_write(&current->mm->mmap_sem);
11076+
11077+emulate:
11078+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11079+ regs->tpc = call_dl_resolve;
11080+ regs->tnpc = addr+4;
11081+ return 3;
11082+ }
11083+#endif
11084+
11085+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11086+ if ((save & 0xFFC00000U) == 0x05000000U &&
11087+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11088+ nop == 0x01000000U)
11089+ {
11090+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11091+ regs->u_regs[UREG_G2] = addr + 4;
11092+ addr = (save & 0x003FFFFFU) << 10;
11093+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11094+
11095+ if (test_thread_flag(TIF_32BIT))
11096+ addr &= 0xFFFFFFFFUL;
11097+
11098+ regs->tpc = addr;
11099+ regs->tnpc = addr+4;
11100+ return 3;
11101+ }
11102+
11103+ /* PaX: 64-bit PLT stub */
11104+ err = get_user(sethi1, (unsigned int *)addr);
11105+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11106+ err |= get_user(or1, (unsigned int *)(addr+8));
11107+ err |= get_user(or2, (unsigned int *)(addr+12));
11108+ err |= get_user(sllx, (unsigned int *)(addr+16));
11109+ err |= get_user(add, (unsigned int *)(addr+20));
11110+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11111+ err |= get_user(nop, (unsigned int *)(addr+28));
11112+ if (err)
11113+ break;
11114+
11115+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11116+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11117+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11118+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11119+ sllx == 0x89293020U &&
11120+ add == 0x8A010005U &&
11121+ jmpl == 0x89C14000U &&
11122+ nop == 0x01000000U)
11123+ {
11124+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11125+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11126+ regs->u_regs[UREG_G4] <<= 32;
11127+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11128+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11129+ regs->u_regs[UREG_G4] = addr + 24;
11130+ addr = regs->u_regs[UREG_G5];
11131+ regs->tpc = addr;
11132+ regs->tnpc = addr+4;
11133+ return 3;
11134+ }
11135+ }
11136+ } while (0);
11137+
11138+#ifdef CONFIG_PAX_DLRESOLVE
11139+ do { /* PaX: unpatched PLT emulation step 2 */
11140+ unsigned int save, call, nop;
11141+
11142+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11143+ err |= get_user(call, (unsigned int *)regs->tpc);
11144+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11145+ if (err)
11146+ break;
11147+
11148+ if (save == 0x9DE3BFA8U &&
11149+ (call & 0xC0000000U) == 0x40000000U &&
11150+ nop == 0x01000000U)
11151+ {
11152+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11153+
11154+ if (test_thread_flag(TIF_32BIT))
11155+ dl_resolve &= 0xFFFFFFFFUL;
11156+
11157+ regs->u_regs[UREG_RETPC] = regs->tpc;
11158+ regs->tpc = dl_resolve;
11159+ regs->tnpc = dl_resolve+4;
11160+ return 3;
11161+ }
11162+ } while (0);
11163+#endif
11164+
11165+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11166+ unsigned int sethi, ba, nop;
11167+
11168+ err = get_user(sethi, (unsigned int *)regs->tpc);
11169+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11170+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11171+
11172+ if (err)
11173+ break;
11174+
11175+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11176+ (ba & 0xFFF00000U) == 0x30600000U &&
11177+ nop == 0x01000000U)
11178+ {
11179+ unsigned long addr;
11180+
11181+ addr = (sethi & 0x003FFFFFU) << 10;
11182+ regs->u_regs[UREG_G1] = addr;
11183+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11184+
11185+ if (test_thread_flag(TIF_32BIT))
11186+ addr &= 0xFFFFFFFFUL;
11187+
11188+ regs->tpc = addr;
11189+ regs->tnpc = addr+4;
11190+ return 2;
11191+ }
11192+ } while (0);
11193+
11194+#endif
11195+
11196+ return 1;
11197+}
11198+
11199+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11200+{
11201+ unsigned long i;
11202+
11203+ printk(KERN_ERR "PAX: bytes at PC: ");
11204+ for (i = 0; i < 8; i++) {
11205+ unsigned int c;
11206+ if (get_user(c, (unsigned int *)pc+i))
11207+ printk(KERN_CONT "???????? ");
11208+ else
11209+ printk(KERN_CONT "%08x ", c);
11210+ }
11211+ printk("\n");
11212+}
11213+#endif
11214+
11215 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11216 {
11217 struct mm_struct *mm = current->mm;
11218@@ -342,6 +805,29 @@ retry:
11219 if (!vma)
11220 goto bad_area;
11221
11222+#ifdef CONFIG_PAX_PAGEEXEC
11223+ /* PaX: detect ITLB misses on non-exec pages */
11224+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11225+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11226+ {
11227+ if (address != regs->tpc)
11228+ goto good_area;
11229+
11230+ up_read(&mm->mmap_sem);
11231+ switch (pax_handle_fetch_fault(regs)) {
11232+
11233+#ifdef CONFIG_PAX_EMUPLT
11234+ case 2:
11235+ case 3:
11236+ return;
11237+#endif
11238+
11239+ }
11240+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11241+ do_group_exit(SIGKILL);
11242+ }
11243+#endif
11244+
11245 /* Pure DTLB misses do not tell us whether the fault causing
11246 * load/store/atomic was a write or not, it only says that there
11247 * was no match. So in such a case we (carefully) read the
11248diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11249index 9639964..806cd0c 100644
11250--- a/arch/sparc/mm/hugetlbpage.c
11251+++ b/arch/sparc/mm/hugetlbpage.c
11252@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11253 unsigned long addr,
11254 unsigned long len,
11255 unsigned long pgoff,
11256- unsigned long flags)
11257+ unsigned long flags,
11258+ unsigned long offset)
11259 {
11260 unsigned long task_size = TASK_SIZE;
11261 struct vm_unmapped_area_info info;
11262@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11263
11264 info.flags = 0;
11265 info.length = len;
11266- info.low_limit = TASK_UNMAPPED_BASE;
11267+ info.low_limit = mm->mmap_base;
11268 info.high_limit = min(task_size, VA_EXCLUDE_START);
11269 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11270 info.align_offset = 0;
11271+ info.threadstack_offset = offset;
11272 addr = vm_unmapped_area(&info);
11273
11274 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11275 VM_BUG_ON(addr != -ENOMEM);
11276 info.low_limit = VA_EXCLUDE_END;
11277+
11278+#ifdef CONFIG_PAX_RANDMMAP
11279+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11280+ info.low_limit += mm->delta_mmap;
11281+#endif
11282+
11283 info.high_limit = task_size;
11284 addr = vm_unmapped_area(&info);
11285 }
11286@@ -58,7 +66,8 @@ static unsigned long
11287 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11288 const unsigned long len,
11289 const unsigned long pgoff,
11290- const unsigned long flags)
11291+ const unsigned long flags,
11292+ const unsigned long offset)
11293 {
11294 struct mm_struct *mm = current->mm;
11295 unsigned long addr = addr0;
11296@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11297 info.high_limit = mm->mmap_base;
11298 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11299 info.align_offset = 0;
11300+ info.threadstack_offset = offset;
11301 addr = vm_unmapped_area(&info);
11302
11303 /*
11304@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11305 VM_BUG_ON(addr != -ENOMEM);
11306 info.flags = 0;
11307 info.low_limit = TASK_UNMAPPED_BASE;
11308+
11309+#ifdef CONFIG_PAX_RANDMMAP
11310+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11311+ info.low_limit += mm->delta_mmap;
11312+#endif
11313+
11314 info.high_limit = STACK_TOP32;
11315 addr = vm_unmapped_area(&info);
11316 }
11317@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11318 struct mm_struct *mm = current->mm;
11319 struct vm_area_struct *vma;
11320 unsigned long task_size = TASK_SIZE;
11321+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11322
11323 if (test_thread_flag(TIF_32BIT))
11324 task_size = STACK_TOP32;
11325@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11326 return addr;
11327 }
11328
11329+#ifdef CONFIG_PAX_RANDMMAP
11330+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11331+#endif
11332+
11333 if (addr) {
11334 addr = ALIGN(addr, HPAGE_SIZE);
11335 vma = find_vma(mm, addr);
11336- if (task_size - len >= addr &&
11337- (!vma || addr + len <= vma->vm_start))
11338+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11339 return addr;
11340 }
11341 if (mm->get_unmapped_area == arch_get_unmapped_area)
11342 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11343- pgoff, flags);
11344+ pgoff, flags, offset);
11345 else
11346 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11347- pgoff, flags);
11348+ pgoff, flags, offset);
11349 }
11350
11351 pte_t *huge_pte_alloc(struct mm_struct *mm,
11352diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11353index ed82eda..0d80e77 100644
11354--- a/arch/sparc/mm/init_64.c
11355+++ b/arch/sparc/mm/init_64.c
11356@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11357 int num_kernel_image_mappings;
11358
11359 #ifdef CONFIG_DEBUG_DCFLUSH
11360-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11361+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11362 #ifdef CONFIG_SMP
11363-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11364+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11365 #endif
11366 #endif
11367
11368@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11369 {
11370 BUG_ON(tlb_type == hypervisor);
11371 #ifdef CONFIG_DEBUG_DCFLUSH
11372- atomic_inc(&dcpage_flushes);
11373+ atomic_inc_unchecked(&dcpage_flushes);
11374 #endif
11375
11376 #ifdef DCACHE_ALIASING_POSSIBLE
11377@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11378
11379 #ifdef CONFIG_DEBUG_DCFLUSH
11380 seq_printf(m, "DCPageFlushes\t: %d\n",
11381- atomic_read(&dcpage_flushes));
11382+ atomic_read_unchecked(&dcpage_flushes));
11383 #ifdef CONFIG_SMP
11384 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11385- atomic_read(&dcpage_flushes_xcall));
11386+ atomic_read_unchecked(&dcpage_flushes_xcall));
11387 #endif /* CONFIG_SMP */
11388 #endif /* CONFIG_DEBUG_DCFLUSH */
11389 }
11390diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11391index d45a2c4..3c05a78 100644
11392--- a/arch/tile/Kconfig
11393+++ b/arch/tile/Kconfig
11394@@ -185,6 +185,7 @@ source "kernel/Kconfig.hz"
11395
11396 config KEXEC
11397 bool "kexec system call"
11398+ depends on !GRKERNSEC_KMEM
11399 ---help---
11400 kexec is a system call that implements the ability to shutdown your
11401 current kernel, and to start another kernel. It is like a reboot
11402diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11403index ad220ee..2f537b3 100644
11404--- a/arch/tile/include/asm/atomic_64.h
11405+++ b/arch/tile/include/asm/atomic_64.h
11406@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11407
11408 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11409
11410+#define atomic64_read_unchecked(v) atomic64_read(v)
11411+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11412+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11413+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11414+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11415+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11416+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11417+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11418+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11419+
11420 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11421 #define smp_mb__before_atomic_dec() smp_mb()
11422 #define smp_mb__after_atomic_dec() smp_mb()
11423diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11424index 6160761..00cac88 100644
11425--- a/arch/tile/include/asm/cache.h
11426+++ b/arch/tile/include/asm/cache.h
11427@@ -15,11 +15,12 @@
11428 #ifndef _ASM_TILE_CACHE_H
11429 #define _ASM_TILE_CACHE_H
11430
11431+#include <linux/const.h>
11432 #include <arch/chip.h>
11433
11434 /* bytes per L1 data cache line */
11435 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11436-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11437+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11438
11439 /* bytes per L2 cache line */
11440 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11441diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11442index b6cde32..c0cb736 100644
11443--- a/arch/tile/include/asm/uaccess.h
11444+++ b/arch/tile/include/asm/uaccess.h
11445@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11446 const void __user *from,
11447 unsigned long n)
11448 {
11449- int sz = __compiletime_object_size(to);
11450+ size_t sz = __compiletime_object_size(to);
11451
11452- if (likely(sz == -1 || sz >= n))
11453+ if (likely(sz == (size_t)-1 || sz >= n))
11454 n = _copy_from_user(to, from, n);
11455 else
11456 copy_from_user_overflow();
11457diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11458index 0cb3bba..7338b2d 100644
11459--- a/arch/tile/mm/hugetlbpage.c
11460+++ b/arch/tile/mm/hugetlbpage.c
11461@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11462 info.high_limit = TASK_SIZE;
11463 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11464 info.align_offset = 0;
11465+ info.threadstack_offset = 0;
11466 return vm_unmapped_area(&info);
11467 }
11468
11469@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11470 info.high_limit = current->mm->mmap_base;
11471 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11472 info.align_offset = 0;
11473+ info.threadstack_offset = 0;
11474 addr = vm_unmapped_area(&info);
11475
11476 /*
11477diff --git a/arch/um/Makefile b/arch/um/Makefile
11478index 133f7de..1d6f2f1 100644
11479--- a/arch/um/Makefile
11480+++ b/arch/um/Makefile
11481@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11482 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11483 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11484
11485+ifdef CONSTIFY_PLUGIN
11486+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11487+endif
11488+
11489 #This will adjust *FLAGS accordingly to the platform.
11490 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11491
11492diff --git a/arch/um/defconfig b/arch/um/defconfig
11493index 2665e6b..3e3822b 100644
11494--- a/arch/um/defconfig
11495+++ b/arch/um/defconfig
11496@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11497 CONFIG_X86_L1_CACHE_SHIFT=5
11498 CONFIG_X86_XADD=y
11499 CONFIG_X86_PPRO_FENCE=y
11500-CONFIG_X86_WP_WORKS_OK=y
11501 CONFIG_X86_INVLPG=y
11502 CONFIG_X86_BSWAP=y
11503 CONFIG_X86_POPAD_OK=y
11504diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11505index 19e1bdd..3665b77 100644
11506--- a/arch/um/include/asm/cache.h
11507+++ b/arch/um/include/asm/cache.h
11508@@ -1,6 +1,7 @@
11509 #ifndef __UM_CACHE_H
11510 #define __UM_CACHE_H
11511
11512+#include <linux/const.h>
11513
11514 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11515 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11516@@ -12,6 +13,6 @@
11517 # define L1_CACHE_SHIFT 5
11518 #endif
11519
11520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11522
11523 #endif
11524diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11525index 2e0a6b1..a64d0f5 100644
11526--- a/arch/um/include/asm/kmap_types.h
11527+++ b/arch/um/include/asm/kmap_types.h
11528@@ -8,6 +8,6 @@
11529
11530 /* No more #include "asm/arch/kmap_types.h" ! */
11531
11532-#define KM_TYPE_NR 14
11533+#define KM_TYPE_NR 15
11534
11535 #endif
11536diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11537index 5ff53d9..5850cdf 100644
11538--- a/arch/um/include/asm/page.h
11539+++ b/arch/um/include/asm/page.h
11540@@ -14,6 +14,9 @@
11541 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11542 #define PAGE_MASK (~(PAGE_SIZE-1))
11543
11544+#define ktla_ktva(addr) (addr)
11545+#define ktva_ktla(addr) (addr)
11546+
11547 #ifndef __ASSEMBLY__
11548
11549 struct page;
11550diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11551index 0032f92..cd151e0 100644
11552--- a/arch/um/include/asm/pgtable-3level.h
11553+++ b/arch/um/include/asm/pgtable-3level.h
11554@@ -58,6 +58,7 @@
11555 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11556 #define pud_populate(mm, pud, pmd) \
11557 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11558+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11559
11560 #ifdef CONFIG_64BIT
11561 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11562diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11563index bbcef52..6a2a483 100644
11564--- a/arch/um/kernel/process.c
11565+++ b/arch/um/kernel/process.c
11566@@ -367,22 +367,6 @@ int singlestepping(void * t)
11567 return 2;
11568 }
11569
11570-/*
11571- * Only x86 and x86_64 have an arch_align_stack().
11572- * All other arches have "#define arch_align_stack(x) (x)"
11573- * in their asm/system.h
11574- * As this is included in UML from asm-um/system-generic.h,
11575- * we can use it to behave as the subarch does.
11576- */
11577-#ifndef arch_align_stack
11578-unsigned long arch_align_stack(unsigned long sp)
11579-{
11580- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11581- sp -= get_random_int() % 8192;
11582- return sp & ~0xf;
11583-}
11584-#endif
11585-
11586 unsigned long get_wchan(struct task_struct *p)
11587 {
11588 unsigned long stack_page, sp, ip;
11589diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11590index ad8f795..2c7eec6 100644
11591--- a/arch/unicore32/include/asm/cache.h
11592+++ b/arch/unicore32/include/asm/cache.h
11593@@ -12,8 +12,10 @@
11594 #ifndef __UNICORE_CACHE_H__
11595 #define __UNICORE_CACHE_H__
11596
11597-#define L1_CACHE_SHIFT (5)
11598-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11599+#include <linux/const.h>
11600+
11601+#define L1_CACHE_SHIFT 5
11602+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11603
11604 /*
11605 * Memory returned by kmalloc() may be used for DMA, so we must make
11606diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11607index f67e839..bfd4748 100644
11608--- a/arch/x86/Kconfig
11609+++ b/arch/x86/Kconfig
11610@@ -247,7 +247,7 @@ config X86_HT
11611
11612 config X86_32_LAZY_GS
11613 def_bool y
11614- depends on X86_32 && !CC_STACKPROTECTOR
11615+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11616
11617 config ARCH_HWEIGHT_CFLAGS
11618 string
11619@@ -1099,6 +1099,7 @@ config MICROCODE_EARLY
11620
11621 config X86_MSR
11622 tristate "/dev/cpu/*/msr - Model-specific register support"
11623+ depends on !GRKERNSEC_KMEM
11624 ---help---
11625 This device gives privileged processes access to the x86
11626 Model-Specific Registers (MSRs). It is a character device with
11627@@ -1122,7 +1123,7 @@ choice
11628
11629 config NOHIGHMEM
11630 bool "off"
11631- depends on !X86_NUMAQ
11632+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11633 ---help---
11634 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11635 However, the address space of 32-bit x86 processors is only 4
11636@@ -1159,7 +1160,7 @@ config NOHIGHMEM
11637
11638 config HIGHMEM4G
11639 bool "4GB"
11640- depends on !X86_NUMAQ
11641+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11642 ---help---
11643 Select this if you have a 32-bit processor and between 1 and 4
11644 gigabytes of physical RAM.
11645@@ -1212,7 +1213,7 @@ config PAGE_OFFSET
11646 hex
11647 default 0xB0000000 if VMSPLIT_3G_OPT
11648 default 0x80000000 if VMSPLIT_2G
11649- default 0x78000000 if VMSPLIT_2G_OPT
11650+ default 0x70000000 if VMSPLIT_2G_OPT
11651 default 0x40000000 if VMSPLIT_1G
11652 default 0xC0000000
11653 depends on X86_32
11654@@ -1614,6 +1615,7 @@ config SECCOMP
11655
11656 config CC_STACKPROTECTOR
11657 bool "Enable -fstack-protector buffer overflow detection"
11658+ depends on X86_64 || !PAX_MEMORY_UDEREF
11659 ---help---
11660 This option turns on the -fstack-protector GCC feature. This
11661 feature puts, at the beginning of functions, a canary value on
11662@@ -1632,6 +1634,7 @@ source kernel/Kconfig.hz
11663
11664 config KEXEC
11665 bool "kexec system call"
11666+ depends on !GRKERNSEC_KMEM
11667 ---help---
11668 kexec is a system call that implements the ability to shutdown your
11669 current kernel, and to start another kernel. It is like a reboot
11670@@ -1733,6 +1736,8 @@ config X86_NEED_RELOCS
11671 config PHYSICAL_ALIGN
11672 hex "Alignment value to which kernel should be aligned"
11673 default "0x1000000"
11674+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11675+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11676 range 0x2000 0x1000000 if X86_32
11677 range 0x200000 0x1000000 if X86_64
11678 ---help---
11679@@ -1812,9 +1817,10 @@ config DEBUG_HOTPLUG_CPU0
11680 If unsure, say N.
11681
11682 config COMPAT_VDSO
11683- def_bool y
11684+ def_bool n
11685 prompt "Compat VDSO support"
11686 depends on X86_32 || IA32_EMULATION
11687+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11688 ---help---
11689 Map the 32-bit VDSO to the predictable old-style address too.
11690
11691diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11692index c026cca..14657ae 100644
11693--- a/arch/x86/Kconfig.cpu
11694+++ b/arch/x86/Kconfig.cpu
11695@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11696
11697 config X86_F00F_BUG
11698 def_bool y
11699- depends on M586MMX || M586TSC || M586 || M486
11700+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11701
11702 config X86_INVD_BUG
11703 def_bool y
11704@@ -327,7 +327,7 @@ config X86_INVD_BUG
11705
11706 config X86_ALIGNMENT_16
11707 def_bool y
11708- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11709+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11710
11711 config X86_INTEL_USERCOPY
11712 def_bool y
11713@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11714 # generates cmov.
11715 config X86_CMOV
11716 def_bool y
11717- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11718+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11719
11720 config X86_MINIMUM_CPU_FAMILY
11721 int
11722diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11723index 78d91af..8ceb94b 100644
11724--- a/arch/x86/Kconfig.debug
11725+++ b/arch/x86/Kconfig.debug
11726@@ -74,7 +74,7 @@ config X86_PTDUMP
11727 config DEBUG_RODATA
11728 bool "Write protect kernel read-only data structures"
11729 default y
11730- depends on DEBUG_KERNEL
11731+ depends on DEBUG_KERNEL && BROKEN
11732 ---help---
11733 Mark the kernel read-only data as write-protected in the pagetables,
11734 in order to catch accidental (and incorrect) writes to such const
11735@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11736
11737 config DEBUG_SET_MODULE_RONX
11738 bool "Set loadable kernel module data as NX and text as RO"
11739- depends on MODULES
11740+ depends on MODULES && BROKEN
11741 ---help---
11742 This option helps catch unintended modifications to loadable
11743 kernel module's text and read-only data. It also prevents execution
11744diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11745index eda00f9..c511701 100644
11746--- a/arch/x86/Makefile
11747+++ b/arch/x86/Makefile
11748@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11749 # CPU-specific tuning. Anything which can be shared with UML should go here.
11750 include $(srctree)/arch/x86/Makefile_32.cpu
11751 KBUILD_CFLAGS += $(cflags-y)
11752-
11753- # temporary until string.h is fixed
11754- KBUILD_CFLAGS += -ffreestanding
11755 else
11756 BITS := 64
11757 UTS_MACHINE := x86_64
11758 CHECKFLAGS += -D__x86_64__ -m64
11759
11760+ biarch := $(call cc-option,-m64)
11761 KBUILD_AFLAGS += -m64
11762 KBUILD_CFLAGS += -m64
11763
11764@@ -89,6 +87,9 @@ else
11765 KBUILD_CFLAGS += -maccumulate-outgoing-args
11766 endif
11767
11768+# temporary until string.h is fixed
11769+KBUILD_CFLAGS += -ffreestanding
11770+
11771 ifdef CONFIG_CC_STACKPROTECTOR
11772 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11773 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11774@@ -247,3 +248,12 @@ define archhelp
11775 echo ' FDINITRD=file initrd for the booted kernel'
11776 echo ' kvmconfig - Enable additional options for guest kernel support'
11777 endef
11778+
11779+define OLD_LD
11780+
11781+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11782+*** Please upgrade your binutils to 2.18 or newer
11783+endef
11784+
11785+archprepare:
11786+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11787diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11788index 379814b..add62ce 100644
11789--- a/arch/x86/boot/Makefile
11790+++ b/arch/x86/boot/Makefile
11791@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11792 $(call cc-option, -fno-stack-protector) \
11793 $(call cc-option, -mpreferred-stack-boundary=2)
11794 KBUILD_CFLAGS += $(call cc-option, -m32)
11795+ifdef CONSTIFY_PLUGIN
11796+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11797+endif
11798 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11799 GCOV_PROFILE := n
11800
11801diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11802index 878e4b9..20537ab 100644
11803--- a/arch/x86/boot/bitops.h
11804+++ b/arch/x86/boot/bitops.h
11805@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11806 u8 v;
11807 const u32 *p = (const u32 *)addr;
11808
11809- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11810+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11811 return v;
11812 }
11813
11814@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11815
11816 static inline void set_bit(int nr, void *addr)
11817 {
11818- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11819+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11820 }
11821
11822 #endif /* BOOT_BITOPS_H */
11823diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11824index ef72bae..353a184 100644
11825--- a/arch/x86/boot/boot.h
11826+++ b/arch/x86/boot/boot.h
11827@@ -85,7 +85,7 @@ static inline void io_delay(void)
11828 static inline u16 ds(void)
11829 {
11830 u16 seg;
11831- asm("movw %%ds,%0" : "=rm" (seg));
11832+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11833 return seg;
11834 }
11835
11836@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11837 static inline int memcmp(const void *s1, const void *s2, size_t len)
11838 {
11839 u8 diff;
11840- asm("repe; cmpsb; setnz %0"
11841+ asm volatile("repe; cmpsb; setnz %0"
11842 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11843 return diff;
11844 }
11845diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11846index dcd90df..c830d7d 100644
11847--- a/arch/x86/boot/compressed/Makefile
11848+++ b/arch/x86/boot/compressed/Makefile
11849@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11850 KBUILD_CFLAGS += $(cflags-y)
11851 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11852 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11853+ifdef CONSTIFY_PLUGIN
11854+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11855+endif
11856
11857 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11858 GCOV_PROFILE := n
11859diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11860index b7388a4..03844ec 100644
11861--- a/arch/x86/boot/compressed/eboot.c
11862+++ b/arch/x86/boot/compressed/eboot.c
11863@@ -150,7 +150,6 @@ again:
11864 *addr = max_addr;
11865 }
11866
11867-free_pool:
11868 efi_call_phys1(sys_table->boottime->free_pool, map);
11869
11870 fail:
11871@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11872 if (i == map_size / desc_size)
11873 status = EFI_NOT_FOUND;
11874
11875-free_pool:
11876 efi_call_phys1(sys_table->boottime->free_pool, map);
11877 fail:
11878 return status;
11879diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11880index a53440e..c3dbf1e 100644
11881--- a/arch/x86/boot/compressed/efi_stub_32.S
11882+++ b/arch/x86/boot/compressed/efi_stub_32.S
11883@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11884 * parameter 2, ..., param n. To make things easy, we save the return
11885 * address of efi_call_phys in a global variable.
11886 */
11887- popl %ecx
11888- movl %ecx, saved_return_addr(%edx)
11889- /* get the function pointer into ECX*/
11890- popl %ecx
11891- movl %ecx, efi_rt_function_ptr(%edx)
11892+ popl saved_return_addr(%edx)
11893+ popl efi_rt_function_ptr(%edx)
11894
11895 /*
11896 * 3. Call the physical function.
11897 */
11898- call *%ecx
11899+ call *efi_rt_function_ptr(%edx)
11900
11901 /*
11902 * 4. Balance the stack. And because EAX contain the return value,
11903@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11904 1: popl %edx
11905 subl $1b, %edx
11906
11907- movl efi_rt_function_ptr(%edx), %ecx
11908- pushl %ecx
11909+ pushl efi_rt_function_ptr(%edx)
11910
11911 /*
11912 * 10. Push the saved return address onto the stack and return.
11913 */
11914- movl saved_return_addr(%edx), %ecx
11915- pushl %ecx
11916- ret
11917+ jmpl *saved_return_addr(%edx)
11918 ENDPROC(efi_call_phys)
11919 .previous
11920
11921diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11922index 5d6f689..9d06730 100644
11923--- a/arch/x86/boot/compressed/head_32.S
11924+++ b/arch/x86/boot/compressed/head_32.S
11925@@ -118,7 +118,7 @@ preferred_addr:
11926 notl %eax
11927 andl %eax, %ebx
11928 #else
11929- movl $LOAD_PHYSICAL_ADDR, %ebx
11930+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11931 #endif
11932
11933 /* Target address to relocate to for decompression */
11934diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11935index c337422..2c5be72 100644
11936--- a/arch/x86/boot/compressed/head_64.S
11937+++ b/arch/x86/boot/compressed/head_64.S
11938@@ -95,7 +95,7 @@ ENTRY(startup_32)
11939 notl %eax
11940 andl %eax, %ebx
11941 #else
11942- movl $LOAD_PHYSICAL_ADDR, %ebx
11943+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11944 #endif
11945
11946 /* Target address to relocate to for decompression */
11947@@ -270,7 +270,7 @@ preferred_addr:
11948 notq %rax
11949 andq %rax, %rbp
11950 #else
11951- movq $LOAD_PHYSICAL_ADDR, %rbp
11952+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11953 #endif
11954
11955 /* Target address to relocate to for decompression */
11956@@ -362,8 +362,8 @@ gdt:
11957 .long gdt
11958 .word 0
11959 .quad 0x0000000000000000 /* NULL descriptor */
11960- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11961- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11962+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11963+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11964 .quad 0x0080890000000000 /* TS descriptor */
11965 .quad 0x0000000000000000 /* TS continued */
11966 gdt_end:
11967diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11968index 434f077..b6b4b38 100644
11969--- a/arch/x86/boot/compressed/misc.c
11970+++ b/arch/x86/boot/compressed/misc.c
11971@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11972 * Calculate the delta between where vmlinux was linked to load
11973 * and where it was actually loaded.
11974 */
11975- delta = min_addr - LOAD_PHYSICAL_ADDR;
11976+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11977 if (!delta) {
11978 debug_putstr("No relocation needed... ");
11979 return;
11980@@ -380,7 +380,7 @@ static void parse_elf(void *output)
11981 case PT_LOAD:
11982 #ifdef CONFIG_RELOCATABLE
11983 dest = output;
11984- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11985+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11986 #else
11987 dest = (void *)(phdr->p_paddr);
11988 #endif
11989@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11990 error("Destination address too large");
11991 #endif
11992 #ifndef CONFIG_RELOCATABLE
11993- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11994+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11995 error("Wrong destination address");
11996 #endif
11997
11998diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11999index 4d3ff03..e4972ff 100644
12000--- a/arch/x86/boot/cpucheck.c
12001+++ b/arch/x86/boot/cpucheck.c
12002@@ -74,7 +74,7 @@ static int has_fpu(void)
12003 u16 fcw = -1, fsw = -1;
12004 u32 cr0;
12005
12006- asm("movl %%cr0,%0" : "=r" (cr0));
12007+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12008 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12009 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12010 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12011@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12012 {
12013 u32 f0, f1;
12014
12015- asm("pushfl ; "
12016+ asm volatile("pushfl ; "
12017 "pushfl ; "
12018 "popl %0 ; "
12019 "movl %0,%1 ; "
12020@@ -115,7 +115,7 @@ static void get_flags(void)
12021 set_bit(X86_FEATURE_FPU, cpu.flags);
12022
12023 if (has_eflag(X86_EFLAGS_ID)) {
12024- asm("cpuid"
12025+ asm volatile("cpuid"
12026 : "=a" (max_intel_level),
12027 "=b" (cpu_vendor[0]),
12028 "=d" (cpu_vendor[1]),
12029@@ -124,7 +124,7 @@ static void get_flags(void)
12030
12031 if (max_intel_level >= 0x00000001 &&
12032 max_intel_level <= 0x0000ffff) {
12033- asm("cpuid"
12034+ asm volatile("cpuid"
12035 : "=a" (tfms),
12036 "=c" (cpu.flags[4]),
12037 "=d" (cpu.flags[0])
12038@@ -136,7 +136,7 @@ static void get_flags(void)
12039 cpu.model += ((tfms >> 16) & 0xf) << 4;
12040 }
12041
12042- asm("cpuid"
12043+ asm volatile("cpuid"
12044 : "=a" (max_amd_level)
12045 : "a" (0x80000000)
12046 : "ebx", "ecx", "edx");
12047@@ -144,7 +144,7 @@ static void get_flags(void)
12048 if (max_amd_level >= 0x80000001 &&
12049 max_amd_level <= 0x8000ffff) {
12050 u32 eax = 0x80000001;
12051- asm("cpuid"
12052+ asm volatile("cpuid"
12053 : "+a" (eax),
12054 "=c" (cpu.flags[6]),
12055 "=d" (cpu.flags[1])
12056@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12057 u32 ecx = MSR_K7_HWCR;
12058 u32 eax, edx;
12059
12060- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12061+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12062 eax &= ~(1 << 15);
12063- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12064+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12065
12066 get_flags(); /* Make sure it really did something */
12067 err = check_flags();
12068@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12069 u32 ecx = MSR_VIA_FCR;
12070 u32 eax, edx;
12071
12072- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12073+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12074 eax |= (1<<1)|(1<<7);
12075- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12076+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12077
12078 set_bit(X86_FEATURE_CX8, cpu.flags);
12079 err = check_flags();
12080@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12081 u32 eax, edx;
12082 u32 level = 1;
12083
12084- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12085- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12086- asm("cpuid"
12087+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12088+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12089+ asm volatile("cpuid"
12090 : "+a" (level), "=d" (cpu.flags[0])
12091 : : "ecx", "ebx");
12092- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12093+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12094
12095 err = check_flags();
12096 }
12097diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12098index 9ec06a1..2c25e79 100644
12099--- a/arch/x86/boot/header.S
12100+++ b/arch/x86/boot/header.S
12101@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12102 # single linked list of
12103 # struct setup_data
12104
12105-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12106+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12107
12108 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12110+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12111+#else
12112 #define VO_INIT_SIZE (VO__end - VO__text)
12113+#endif
12114 #if ZO_INIT_SIZE > VO_INIT_SIZE
12115 #define INIT_SIZE ZO_INIT_SIZE
12116 #else
12117diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12118index db75d07..8e6d0af 100644
12119--- a/arch/x86/boot/memory.c
12120+++ b/arch/x86/boot/memory.c
12121@@ -19,7 +19,7 @@
12122
12123 static int detect_memory_e820(void)
12124 {
12125- int count = 0;
12126+ unsigned int count = 0;
12127 struct biosregs ireg, oreg;
12128 struct e820entry *desc = boot_params.e820_map;
12129 static struct e820entry buf; /* static so it is zeroed */
12130diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12131index 11e8c6e..fdbb1ed 100644
12132--- a/arch/x86/boot/video-vesa.c
12133+++ b/arch/x86/boot/video-vesa.c
12134@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12135
12136 boot_params.screen_info.vesapm_seg = oreg.es;
12137 boot_params.screen_info.vesapm_off = oreg.di;
12138+ boot_params.screen_info.vesapm_size = oreg.cx;
12139 }
12140
12141 /*
12142diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12143index 43eda28..5ab5fdb 100644
12144--- a/arch/x86/boot/video.c
12145+++ b/arch/x86/boot/video.c
12146@@ -96,7 +96,7 @@ static void store_mode_params(void)
12147 static unsigned int get_entry(void)
12148 {
12149 char entry_buf[4];
12150- int i, len = 0;
12151+ unsigned int i, len = 0;
12152 int key;
12153 unsigned int v;
12154
12155diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12156index 9105655..41779c1 100644
12157--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12158+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12159@@ -8,6 +8,8 @@
12160 * including this sentence is retained in full.
12161 */
12162
12163+#include <asm/alternative-asm.h>
12164+
12165 .extern crypto_ft_tab
12166 .extern crypto_it_tab
12167 .extern crypto_fl_tab
12168@@ -70,6 +72,8 @@
12169 je B192; \
12170 leaq 32(r9),r9;
12171
12172+#define ret pax_force_retaddr; ret
12173+
12174 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12175 movq r1,r2; \
12176 movq r3,r4; \
12177diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12178index 477e9d7..c92c7d8 100644
12179--- a/arch/x86/crypto/aesni-intel_asm.S
12180+++ b/arch/x86/crypto/aesni-intel_asm.S
12181@@ -31,6 +31,7 @@
12182
12183 #include <linux/linkage.h>
12184 #include <asm/inst.h>
12185+#include <asm/alternative-asm.h>
12186
12187 #ifdef __x86_64__
12188 .data
12189@@ -205,7 +206,7 @@ enc: .octa 0x2
12190 * num_initial_blocks = b mod 4
12191 * encrypt the initial num_initial_blocks blocks and apply ghash on
12192 * the ciphertext
12193-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12194+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12195 * are clobbered
12196 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12197 */
12198@@ -214,8 +215,8 @@ enc: .octa 0x2
12199 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12200 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12201 mov arg7, %r10 # %r10 = AAD
12202- mov arg8, %r12 # %r12 = aadLen
12203- mov %r12, %r11
12204+ mov arg8, %r15 # %r15 = aadLen
12205+ mov %r15, %r11
12206 pxor %xmm\i, %xmm\i
12207 _get_AAD_loop\num_initial_blocks\operation:
12208 movd (%r10), \TMP1
12209@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12210 psrldq $4, %xmm\i
12211 pxor \TMP1, %xmm\i
12212 add $4, %r10
12213- sub $4, %r12
12214+ sub $4, %r15
12215 jne _get_AAD_loop\num_initial_blocks\operation
12216 cmp $16, %r11
12217 je _get_AAD_loop2_done\num_initial_blocks\operation
12218- mov $16, %r12
12219+ mov $16, %r15
12220 _get_AAD_loop2\num_initial_blocks\operation:
12221 psrldq $4, %xmm\i
12222- sub $4, %r12
12223- cmp %r11, %r12
12224+ sub $4, %r15
12225+ cmp %r11, %r15
12226 jne _get_AAD_loop2\num_initial_blocks\operation
12227 _get_AAD_loop2_done\num_initial_blocks\operation:
12228 movdqa SHUF_MASK(%rip), %xmm14
12229@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12230 * num_initial_blocks = b mod 4
12231 * encrypt the initial num_initial_blocks blocks and apply ghash on
12232 * the ciphertext
12233-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12234+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12235 * are clobbered
12236 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12237 */
12238@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12239 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12240 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12241 mov arg7, %r10 # %r10 = AAD
12242- mov arg8, %r12 # %r12 = aadLen
12243- mov %r12, %r11
12244+ mov arg8, %r15 # %r15 = aadLen
12245+ mov %r15, %r11
12246 pxor %xmm\i, %xmm\i
12247 _get_AAD_loop\num_initial_blocks\operation:
12248 movd (%r10), \TMP1
12249@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12250 psrldq $4, %xmm\i
12251 pxor \TMP1, %xmm\i
12252 add $4, %r10
12253- sub $4, %r12
12254+ sub $4, %r15
12255 jne _get_AAD_loop\num_initial_blocks\operation
12256 cmp $16, %r11
12257 je _get_AAD_loop2_done\num_initial_blocks\operation
12258- mov $16, %r12
12259+ mov $16, %r15
12260 _get_AAD_loop2\num_initial_blocks\operation:
12261 psrldq $4, %xmm\i
12262- sub $4, %r12
12263- cmp %r11, %r12
12264+ sub $4, %r15
12265+ cmp %r11, %r15
12266 jne _get_AAD_loop2\num_initial_blocks\operation
12267 _get_AAD_loop2_done\num_initial_blocks\operation:
12268 movdqa SHUF_MASK(%rip), %xmm14
12269@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12270 *
12271 *****************************************************************************/
12272 ENTRY(aesni_gcm_dec)
12273- push %r12
12274+ push %r15
12275 push %r13
12276 push %r14
12277 mov %rsp, %r14
12278@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12279 */
12280 sub $VARIABLE_OFFSET, %rsp
12281 and $~63, %rsp # align rsp to 64 bytes
12282- mov %arg6, %r12
12283- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12284+ mov %arg6, %r15
12285+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12286 movdqa SHUF_MASK(%rip), %xmm2
12287 PSHUFB_XMM %xmm2, %xmm13
12288
12289@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12290 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12291 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12292 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12293- mov %r13, %r12
12294- and $(3<<4), %r12
12295+ mov %r13, %r15
12296+ and $(3<<4), %r15
12297 jz _initial_num_blocks_is_0_decrypt
12298- cmp $(2<<4), %r12
12299+ cmp $(2<<4), %r15
12300 jb _initial_num_blocks_is_1_decrypt
12301 je _initial_num_blocks_is_2_decrypt
12302 _initial_num_blocks_is_3_decrypt:
12303@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12304 sub $16, %r11
12305 add %r13, %r11
12306 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12307- lea SHIFT_MASK+16(%rip), %r12
12308- sub %r13, %r12
12309+ lea SHIFT_MASK+16(%rip), %r15
12310+ sub %r13, %r15
12311 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12312 # (%r13 is the number of bytes in plaintext mod 16)
12313- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12314+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12315 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12316
12317 movdqa %xmm1, %xmm2
12318 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12319- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12320+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12321 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12322 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12323 pand %xmm1, %xmm2
12324@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12325 sub $1, %r13
12326 jne _less_than_8_bytes_left_decrypt
12327 _multiple_of_16_bytes_decrypt:
12328- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12329- shl $3, %r12 # convert into number of bits
12330- movd %r12d, %xmm15 # len(A) in %xmm15
12331+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12332+ shl $3, %r15 # convert into number of bits
12333+ movd %r15d, %xmm15 # len(A) in %xmm15
12334 shl $3, %arg4 # len(C) in bits (*128)
12335 MOVQ_R64_XMM %arg4, %xmm1
12336 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12337@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12338 mov %r14, %rsp
12339 pop %r14
12340 pop %r13
12341- pop %r12
12342+ pop %r15
12343+ pax_force_retaddr
12344 ret
12345 ENDPROC(aesni_gcm_dec)
12346
12347@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12348 * poly = x^128 + x^127 + x^126 + x^121 + 1
12349 ***************************************************************************/
12350 ENTRY(aesni_gcm_enc)
12351- push %r12
12352+ push %r15
12353 push %r13
12354 push %r14
12355 mov %rsp, %r14
12356@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12357 #
12358 sub $VARIABLE_OFFSET, %rsp
12359 and $~63, %rsp
12360- mov %arg6, %r12
12361- movdqu (%r12), %xmm13
12362+ mov %arg6, %r15
12363+ movdqu (%r15), %xmm13
12364 movdqa SHUF_MASK(%rip), %xmm2
12365 PSHUFB_XMM %xmm2, %xmm13
12366
12367@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12368 movdqa %xmm13, HashKey(%rsp)
12369 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12370 and $-16, %r13
12371- mov %r13, %r12
12372+ mov %r13, %r15
12373
12374 # Encrypt first few blocks
12375
12376- and $(3<<4), %r12
12377+ and $(3<<4), %r15
12378 jz _initial_num_blocks_is_0_encrypt
12379- cmp $(2<<4), %r12
12380+ cmp $(2<<4), %r15
12381 jb _initial_num_blocks_is_1_encrypt
12382 je _initial_num_blocks_is_2_encrypt
12383 _initial_num_blocks_is_3_encrypt:
12384@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12385 sub $16, %r11
12386 add %r13, %r11
12387 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12388- lea SHIFT_MASK+16(%rip), %r12
12389- sub %r13, %r12
12390+ lea SHIFT_MASK+16(%rip), %r15
12391+ sub %r13, %r15
12392 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12393 # (%r13 is the number of bytes in plaintext mod 16)
12394- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12395+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12396 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12397 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12398- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12399+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12400 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12401 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12402 movdqa SHUF_MASK(%rip), %xmm10
12403@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12404 sub $1, %r13
12405 jne _less_than_8_bytes_left_encrypt
12406 _multiple_of_16_bytes_encrypt:
12407- mov arg8, %r12 # %r12 = addLen (number of bytes)
12408- shl $3, %r12
12409- movd %r12d, %xmm15 # len(A) in %xmm15
12410+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12411+ shl $3, %r15
12412+ movd %r15d, %xmm15 # len(A) in %xmm15
12413 shl $3, %arg4 # len(C) in bits (*128)
12414 MOVQ_R64_XMM %arg4, %xmm1
12415 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12416@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12417 mov %r14, %rsp
12418 pop %r14
12419 pop %r13
12420- pop %r12
12421+ pop %r15
12422+ pax_force_retaddr
12423 ret
12424 ENDPROC(aesni_gcm_enc)
12425
12426@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12427 pxor %xmm1, %xmm0
12428 movaps %xmm0, (TKEYP)
12429 add $0x10, TKEYP
12430+ pax_force_retaddr
12431 ret
12432 ENDPROC(_key_expansion_128)
12433 ENDPROC(_key_expansion_256a)
12434@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12435 shufps $0b01001110, %xmm2, %xmm1
12436 movaps %xmm1, 0x10(TKEYP)
12437 add $0x20, TKEYP
12438+ pax_force_retaddr
12439 ret
12440 ENDPROC(_key_expansion_192a)
12441
12442@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12443
12444 movaps %xmm0, (TKEYP)
12445 add $0x10, TKEYP
12446+ pax_force_retaddr
12447 ret
12448 ENDPROC(_key_expansion_192b)
12449
12450@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12451 pxor %xmm1, %xmm2
12452 movaps %xmm2, (TKEYP)
12453 add $0x10, TKEYP
12454+ pax_force_retaddr
12455 ret
12456 ENDPROC(_key_expansion_256b)
12457
12458@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12459 #ifndef __x86_64__
12460 popl KEYP
12461 #endif
12462+ pax_force_retaddr
12463 ret
12464 ENDPROC(aesni_set_key)
12465
12466@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12467 popl KLEN
12468 popl KEYP
12469 #endif
12470+ pax_force_retaddr
12471 ret
12472 ENDPROC(aesni_enc)
12473
12474@@ -1974,6 +1983,7 @@ _aesni_enc1:
12475 AESENC KEY STATE
12476 movaps 0x70(TKEYP), KEY
12477 AESENCLAST KEY STATE
12478+ pax_force_retaddr
12479 ret
12480 ENDPROC(_aesni_enc1)
12481
12482@@ -2083,6 +2093,7 @@ _aesni_enc4:
12483 AESENCLAST KEY STATE2
12484 AESENCLAST KEY STATE3
12485 AESENCLAST KEY STATE4
12486+ pax_force_retaddr
12487 ret
12488 ENDPROC(_aesni_enc4)
12489
12490@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12491 popl KLEN
12492 popl KEYP
12493 #endif
12494+ pax_force_retaddr
12495 ret
12496 ENDPROC(aesni_dec)
12497
12498@@ -2164,6 +2176,7 @@ _aesni_dec1:
12499 AESDEC KEY STATE
12500 movaps 0x70(TKEYP), KEY
12501 AESDECLAST KEY STATE
12502+ pax_force_retaddr
12503 ret
12504 ENDPROC(_aesni_dec1)
12505
12506@@ -2273,6 +2286,7 @@ _aesni_dec4:
12507 AESDECLAST KEY STATE2
12508 AESDECLAST KEY STATE3
12509 AESDECLAST KEY STATE4
12510+ pax_force_retaddr
12511 ret
12512 ENDPROC(_aesni_dec4)
12513
12514@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12515 popl KEYP
12516 popl LEN
12517 #endif
12518+ pax_force_retaddr
12519 ret
12520 ENDPROC(aesni_ecb_enc)
12521
12522@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12523 popl KEYP
12524 popl LEN
12525 #endif
12526+ pax_force_retaddr
12527 ret
12528 ENDPROC(aesni_ecb_dec)
12529
12530@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12531 popl LEN
12532 popl IVP
12533 #endif
12534+ pax_force_retaddr
12535 ret
12536 ENDPROC(aesni_cbc_enc)
12537
12538@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12539 popl LEN
12540 popl IVP
12541 #endif
12542+ pax_force_retaddr
12543 ret
12544 ENDPROC(aesni_cbc_dec)
12545
12546@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12547 mov $1, TCTR_LOW
12548 MOVQ_R64_XMM TCTR_LOW INC
12549 MOVQ_R64_XMM CTR TCTR_LOW
12550+ pax_force_retaddr
12551 ret
12552 ENDPROC(_aesni_inc_init)
12553
12554@@ -2579,6 +2598,7 @@ _aesni_inc:
12555 .Linc_low:
12556 movaps CTR, IV
12557 PSHUFB_XMM BSWAP_MASK IV
12558+ pax_force_retaddr
12559 ret
12560 ENDPROC(_aesni_inc)
12561
12562@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12563 .Lctr_enc_ret:
12564 movups IV, (IVP)
12565 .Lctr_enc_just_ret:
12566+ pax_force_retaddr
12567 ret
12568 ENDPROC(aesni_ctr_enc)
12569
12570@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12571 pxor INC, STATE4
12572 movdqu STATE4, 0x70(OUTP)
12573
12574+ pax_force_retaddr
12575 ret
12576 ENDPROC(aesni_xts_crypt8)
12577
12578diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12579index 246c670..466e2d6 100644
12580--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12581+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12582@@ -21,6 +21,7 @@
12583 */
12584
12585 #include <linux/linkage.h>
12586+#include <asm/alternative-asm.h>
12587
12588 .file "blowfish-x86_64-asm.S"
12589 .text
12590@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12591 jnz .L__enc_xor;
12592
12593 write_block();
12594+ pax_force_retaddr
12595 ret;
12596 .L__enc_xor:
12597 xor_block();
12598+ pax_force_retaddr
12599 ret;
12600 ENDPROC(__blowfish_enc_blk)
12601
12602@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12603
12604 movq %r11, %rbp;
12605
12606+ pax_force_retaddr
12607 ret;
12608 ENDPROC(blowfish_dec_blk)
12609
12610@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12611
12612 popq %rbx;
12613 popq %rbp;
12614+ pax_force_retaddr
12615 ret;
12616
12617 .L__enc_xor4:
12618@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12619
12620 popq %rbx;
12621 popq %rbp;
12622+ pax_force_retaddr
12623 ret;
12624 ENDPROC(__blowfish_enc_blk_4way)
12625
12626@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12627 popq %rbx;
12628 popq %rbp;
12629
12630+ pax_force_retaddr
12631 ret;
12632 ENDPROC(blowfish_dec_blk_4way)
12633diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12634index ce71f92..1dce7ec 100644
12635--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12636+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12637@@ -16,6 +16,7 @@
12638 */
12639
12640 #include <linux/linkage.h>
12641+#include <asm/alternative-asm.h>
12642
12643 #define CAMELLIA_TABLE_BYTE_LEN 272
12644
12645@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12646 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12647 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12648 %rcx, (%r9));
12649+ pax_force_retaddr
12650 ret;
12651 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12652
12653@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12654 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12655 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12656 %rax, (%r9));
12657+ pax_force_retaddr
12658 ret;
12659 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12660
12661@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12662 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12663 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12664
12665+ pax_force_retaddr
12666 ret;
12667
12668 .align 8
12669@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12670 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12671 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12672
12673+ pax_force_retaddr
12674 ret;
12675
12676 .align 8
12677@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12678 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12679 %xmm8, %rsi);
12680
12681+ pax_force_retaddr
12682 ret;
12683 ENDPROC(camellia_ecb_enc_16way)
12684
12685@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12686 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12687 %xmm8, %rsi);
12688
12689+ pax_force_retaddr
12690 ret;
12691 ENDPROC(camellia_ecb_dec_16way)
12692
12693@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12694 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12695 %xmm8, %rsi);
12696
12697+ pax_force_retaddr
12698 ret;
12699 ENDPROC(camellia_cbc_dec_16way)
12700
12701@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12702 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12703 %xmm8, %rsi);
12704
12705+ pax_force_retaddr
12706 ret;
12707 ENDPROC(camellia_ctr_16way)
12708
12709@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12710 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12711 %xmm8, %rsi);
12712
12713+ pax_force_retaddr
12714 ret;
12715 ENDPROC(camellia_xts_crypt_16way)
12716
12717diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12718index 0e0b886..5a3123c 100644
12719--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12720+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12721@@ -11,6 +11,7 @@
12722 */
12723
12724 #include <linux/linkage.h>
12725+#include <asm/alternative-asm.h>
12726
12727 #define CAMELLIA_TABLE_BYTE_LEN 272
12728
12729@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12730 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12731 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12732 %rcx, (%r9));
12733+ pax_force_retaddr
12734 ret;
12735 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12736
12737@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12738 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12739 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12740 %rax, (%r9));
12741+ pax_force_retaddr
12742 ret;
12743 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12744
12745@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12746 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12747 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12748
12749+ pax_force_retaddr
12750 ret;
12751
12752 .align 8
12753@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12754 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12755 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12756
12757+ pax_force_retaddr
12758 ret;
12759
12760 .align 8
12761@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12762
12763 vzeroupper;
12764
12765+ pax_force_retaddr
12766 ret;
12767 ENDPROC(camellia_ecb_enc_32way)
12768
12769@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12770
12771 vzeroupper;
12772
12773+ pax_force_retaddr
12774 ret;
12775 ENDPROC(camellia_ecb_dec_32way)
12776
12777@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12778
12779 vzeroupper;
12780
12781+ pax_force_retaddr
12782 ret;
12783 ENDPROC(camellia_cbc_dec_32way)
12784
12785@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12786
12787 vzeroupper;
12788
12789+ pax_force_retaddr
12790 ret;
12791 ENDPROC(camellia_ctr_32way)
12792
12793@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12794
12795 vzeroupper;
12796
12797+ pax_force_retaddr
12798 ret;
12799 ENDPROC(camellia_xts_crypt_32way)
12800
12801diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12802index 310319c..db3d7b5 100644
12803--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12804+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12805@@ -21,6 +21,7 @@
12806 */
12807
12808 #include <linux/linkage.h>
12809+#include <asm/alternative-asm.h>
12810
12811 .file "camellia-x86_64-asm_64.S"
12812 .text
12813@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12814 enc_outunpack(mov, RT1);
12815
12816 movq RRBP, %rbp;
12817+ pax_force_retaddr
12818 ret;
12819
12820 .L__enc_xor:
12821 enc_outunpack(xor, RT1);
12822
12823 movq RRBP, %rbp;
12824+ pax_force_retaddr
12825 ret;
12826 ENDPROC(__camellia_enc_blk)
12827
12828@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12829 dec_outunpack();
12830
12831 movq RRBP, %rbp;
12832+ pax_force_retaddr
12833 ret;
12834 ENDPROC(camellia_dec_blk)
12835
12836@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12837
12838 movq RRBP, %rbp;
12839 popq %rbx;
12840+ pax_force_retaddr
12841 ret;
12842
12843 .L__enc2_xor:
12844@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12845
12846 movq RRBP, %rbp;
12847 popq %rbx;
12848+ pax_force_retaddr
12849 ret;
12850 ENDPROC(__camellia_enc_blk_2way)
12851
12852@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12853
12854 movq RRBP, %rbp;
12855 movq RXOR, %rbx;
12856+ pax_force_retaddr
12857 ret;
12858 ENDPROC(camellia_dec_blk_2way)
12859diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12860index c35fd5d..2d8c7db 100644
12861--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12862+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12863@@ -24,6 +24,7 @@
12864 */
12865
12866 #include <linux/linkage.h>
12867+#include <asm/alternative-asm.h>
12868
12869 .file "cast5-avx-x86_64-asm_64.S"
12870
12871@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12872 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12873 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12874
12875+ pax_force_retaddr
12876 ret;
12877 ENDPROC(__cast5_enc_blk16)
12878
12879@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12880 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12881 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12882
12883+ pax_force_retaddr
12884 ret;
12885
12886 .L__skip_dec:
12887@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12888 vmovdqu RR4, (6*4*4)(%r11);
12889 vmovdqu RL4, (7*4*4)(%r11);
12890
12891+ pax_force_retaddr
12892 ret;
12893 ENDPROC(cast5_ecb_enc_16way)
12894
12895@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12896 vmovdqu RR4, (6*4*4)(%r11);
12897 vmovdqu RL4, (7*4*4)(%r11);
12898
12899+ pax_force_retaddr
12900 ret;
12901 ENDPROC(cast5_ecb_dec_16way)
12902
12903@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12904 * %rdx: src
12905 */
12906
12907- pushq %r12;
12908+ pushq %r14;
12909
12910 movq %rsi, %r11;
12911- movq %rdx, %r12;
12912+ movq %rdx, %r14;
12913
12914 vmovdqu (0*16)(%rdx), RL1;
12915 vmovdqu (1*16)(%rdx), RR1;
12916@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12917 call __cast5_dec_blk16;
12918
12919 /* xor with src */
12920- vmovq (%r12), RX;
12921+ vmovq (%r14), RX;
12922 vpshufd $0x4f, RX, RX;
12923 vpxor RX, RR1, RR1;
12924- vpxor 0*16+8(%r12), RL1, RL1;
12925- vpxor 1*16+8(%r12), RR2, RR2;
12926- vpxor 2*16+8(%r12), RL2, RL2;
12927- vpxor 3*16+8(%r12), RR3, RR3;
12928- vpxor 4*16+8(%r12), RL3, RL3;
12929- vpxor 5*16+8(%r12), RR4, RR4;
12930- vpxor 6*16+8(%r12), RL4, RL4;
12931+ vpxor 0*16+8(%r14), RL1, RL1;
12932+ vpxor 1*16+8(%r14), RR2, RR2;
12933+ vpxor 2*16+8(%r14), RL2, RL2;
12934+ vpxor 3*16+8(%r14), RR3, RR3;
12935+ vpxor 4*16+8(%r14), RL3, RL3;
12936+ vpxor 5*16+8(%r14), RR4, RR4;
12937+ vpxor 6*16+8(%r14), RL4, RL4;
12938
12939 vmovdqu RR1, (0*16)(%r11);
12940 vmovdqu RL1, (1*16)(%r11);
12941@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12942 vmovdqu RR4, (6*16)(%r11);
12943 vmovdqu RL4, (7*16)(%r11);
12944
12945- popq %r12;
12946+ popq %r14;
12947
12948+ pax_force_retaddr
12949 ret;
12950 ENDPROC(cast5_cbc_dec_16way)
12951
12952@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12953 * %rcx: iv (big endian, 64bit)
12954 */
12955
12956- pushq %r12;
12957+ pushq %r14;
12958
12959 movq %rsi, %r11;
12960- movq %rdx, %r12;
12961+ movq %rdx, %r14;
12962
12963 vpcmpeqd RTMP, RTMP, RTMP;
12964 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
12965@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
12966 call __cast5_enc_blk16;
12967
12968 /* dst = src ^ iv */
12969- vpxor (0*16)(%r12), RR1, RR1;
12970- vpxor (1*16)(%r12), RL1, RL1;
12971- vpxor (2*16)(%r12), RR2, RR2;
12972- vpxor (3*16)(%r12), RL2, RL2;
12973- vpxor (4*16)(%r12), RR3, RR3;
12974- vpxor (5*16)(%r12), RL3, RL3;
12975- vpxor (6*16)(%r12), RR4, RR4;
12976- vpxor (7*16)(%r12), RL4, RL4;
12977+ vpxor (0*16)(%r14), RR1, RR1;
12978+ vpxor (1*16)(%r14), RL1, RL1;
12979+ vpxor (2*16)(%r14), RR2, RR2;
12980+ vpxor (3*16)(%r14), RL2, RL2;
12981+ vpxor (4*16)(%r14), RR3, RR3;
12982+ vpxor (5*16)(%r14), RL3, RL3;
12983+ vpxor (6*16)(%r14), RR4, RR4;
12984+ vpxor (7*16)(%r14), RL4, RL4;
12985 vmovdqu RR1, (0*16)(%r11);
12986 vmovdqu RL1, (1*16)(%r11);
12987 vmovdqu RR2, (2*16)(%r11);
12988@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
12989 vmovdqu RR4, (6*16)(%r11);
12990 vmovdqu RL4, (7*16)(%r11);
12991
12992- popq %r12;
12993+ popq %r14;
12994
12995+ pax_force_retaddr
12996 ret;
12997 ENDPROC(cast5_ctr_16way)
12998diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12999index e3531f8..e123f35 100644
13000--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13001+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13002@@ -24,6 +24,7 @@
13003 */
13004
13005 #include <linux/linkage.h>
13006+#include <asm/alternative-asm.h>
13007 #include "glue_helper-asm-avx.S"
13008
13009 .file "cast6-avx-x86_64-asm_64.S"
13010@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13011 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13012 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13013
13014+ pax_force_retaddr
13015 ret;
13016 ENDPROC(__cast6_enc_blk8)
13017
13018@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13019 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13020 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13021
13022+ pax_force_retaddr
13023 ret;
13024 ENDPROC(__cast6_dec_blk8)
13025
13026@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13027
13028 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13029
13030+ pax_force_retaddr
13031 ret;
13032 ENDPROC(cast6_ecb_enc_8way)
13033
13034@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13035
13036 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13037
13038+ pax_force_retaddr
13039 ret;
13040 ENDPROC(cast6_ecb_dec_8way)
13041
13042@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13043 * %rdx: src
13044 */
13045
13046- pushq %r12;
13047+ pushq %r14;
13048
13049 movq %rsi, %r11;
13050- movq %rdx, %r12;
13051+ movq %rdx, %r14;
13052
13053 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13054
13055 call __cast6_dec_blk8;
13056
13057- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13058+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13059
13060- popq %r12;
13061+ popq %r14;
13062
13063+ pax_force_retaddr
13064 ret;
13065 ENDPROC(cast6_cbc_dec_8way)
13066
13067@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13068 * %rcx: iv (little endian, 128bit)
13069 */
13070
13071- pushq %r12;
13072+ pushq %r14;
13073
13074 movq %rsi, %r11;
13075- movq %rdx, %r12;
13076+ movq %rdx, %r14;
13077
13078 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13079 RD2, RX, RKR, RKM);
13080
13081 call __cast6_enc_blk8;
13082
13083- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13084+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13085
13086- popq %r12;
13087+ popq %r14;
13088
13089+ pax_force_retaddr
13090 ret;
13091 ENDPROC(cast6_ctr_8way)
13092
13093@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13094 /* dst <= regs xor IVs(in dst) */
13095 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13096
13097+ pax_force_retaddr
13098 ret;
13099 ENDPROC(cast6_xts_enc_8way)
13100
13101@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13102 /* dst <= regs xor IVs(in dst) */
13103 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13104
13105+ pax_force_retaddr
13106 ret;
13107 ENDPROC(cast6_xts_dec_8way)
13108diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13109index dbc4339..de6e120 100644
13110--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13111+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13112@@ -45,6 +45,7 @@
13113
13114 #include <asm/inst.h>
13115 #include <linux/linkage.h>
13116+#include <asm/alternative-asm.h>
13117
13118 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13119
13120@@ -312,6 +313,7 @@ do_return:
13121 popq %rsi
13122 popq %rdi
13123 popq %rbx
13124+ pax_force_retaddr
13125 ret
13126
13127 ################################################################
13128diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13129index 586f41a..d02851e 100644
13130--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13131+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13132@@ -18,6 +18,7 @@
13133
13134 #include <linux/linkage.h>
13135 #include <asm/inst.h>
13136+#include <asm/alternative-asm.h>
13137
13138 .data
13139
13140@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13141 psrlq $1, T2
13142 pxor T2, T1
13143 pxor T1, DATA
13144+ pax_force_retaddr
13145 ret
13146 ENDPROC(__clmul_gf128mul_ble)
13147
13148@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13149 call __clmul_gf128mul_ble
13150 PSHUFB_XMM BSWAP DATA
13151 movups DATA, (%rdi)
13152+ pax_force_retaddr
13153 ret
13154 ENDPROC(clmul_ghash_mul)
13155
13156@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13157 PSHUFB_XMM BSWAP DATA
13158 movups DATA, (%rdi)
13159 .Lupdate_just_ret:
13160+ pax_force_retaddr
13161 ret
13162 ENDPROC(clmul_ghash_update)
13163
13164@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13165 pand .Lpoly, %xmm1
13166 pxor %xmm1, %xmm0
13167 movups %xmm0, (%rdi)
13168+ pax_force_retaddr
13169 ret
13170 ENDPROC(clmul_ghash_setkey)
13171diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13172index 9279e0b..c4b3d2c 100644
13173--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13174+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13175@@ -1,4 +1,5 @@
13176 #include <linux/linkage.h>
13177+#include <asm/alternative-asm.h>
13178
13179 # enter salsa20_encrypt_bytes
13180 ENTRY(salsa20_encrypt_bytes)
13181@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13182 add %r11,%rsp
13183 mov %rdi,%rax
13184 mov %rsi,%rdx
13185+ pax_force_retaddr
13186 ret
13187 # bytesatleast65:
13188 ._bytesatleast65:
13189@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13190 add %r11,%rsp
13191 mov %rdi,%rax
13192 mov %rsi,%rdx
13193+ pax_force_retaddr
13194 ret
13195 ENDPROC(salsa20_keysetup)
13196
13197@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13198 add %r11,%rsp
13199 mov %rdi,%rax
13200 mov %rsi,%rdx
13201+ pax_force_retaddr
13202 ret
13203 ENDPROC(salsa20_ivsetup)
13204diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13205index 2f202f4..d9164d6 100644
13206--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13207+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13208@@ -24,6 +24,7 @@
13209 */
13210
13211 #include <linux/linkage.h>
13212+#include <asm/alternative-asm.h>
13213 #include "glue_helper-asm-avx.S"
13214
13215 .file "serpent-avx-x86_64-asm_64.S"
13216@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13217 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13218 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13219
13220+ pax_force_retaddr
13221 ret;
13222 ENDPROC(__serpent_enc_blk8_avx)
13223
13224@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13225 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13226 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13227
13228+ pax_force_retaddr
13229 ret;
13230 ENDPROC(__serpent_dec_blk8_avx)
13231
13232@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13233
13234 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13235
13236+ pax_force_retaddr
13237 ret;
13238 ENDPROC(serpent_ecb_enc_8way_avx)
13239
13240@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13241
13242 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13243
13244+ pax_force_retaddr
13245 ret;
13246 ENDPROC(serpent_ecb_dec_8way_avx)
13247
13248@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13249
13250 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13251
13252+ pax_force_retaddr
13253 ret;
13254 ENDPROC(serpent_cbc_dec_8way_avx)
13255
13256@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13257
13258 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13259
13260+ pax_force_retaddr
13261 ret;
13262 ENDPROC(serpent_ctr_8way_avx)
13263
13264@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13265 /* dst <= regs xor IVs(in dst) */
13266 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13267
13268+ pax_force_retaddr
13269 ret;
13270 ENDPROC(serpent_xts_enc_8way_avx)
13271
13272@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13273 /* dst <= regs xor IVs(in dst) */
13274 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13275
13276+ pax_force_retaddr
13277 ret;
13278 ENDPROC(serpent_xts_dec_8way_avx)
13279diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13280index b222085..abd483c 100644
13281--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13282+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13283@@ -15,6 +15,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287+#include <asm/alternative-asm.h>
13288 #include "glue_helper-asm-avx2.S"
13289
13290 .file "serpent-avx2-asm_64.S"
13291@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13292 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13293 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13294
13295+ pax_force_retaddr
13296 ret;
13297 ENDPROC(__serpent_enc_blk16)
13298
13299@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13300 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13301 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13302
13303+ pax_force_retaddr
13304 ret;
13305 ENDPROC(__serpent_dec_blk16)
13306
13307@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13308
13309 vzeroupper;
13310
13311+ pax_force_retaddr
13312 ret;
13313 ENDPROC(serpent_ecb_enc_16way)
13314
13315@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13316
13317 vzeroupper;
13318
13319+ pax_force_retaddr
13320 ret;
13321 ENDPROC(serpent_ecb_dec_16way)
13322
13323@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13324
13325 vzeroupper;
13326
13327+ pax_force_retaddr
13328 ret;
13329 ENDPROC(serpent_cbc_dec_16way)
13330
13331@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13332
13333 vzeroupper;
13334
13335+ pax_force_retaddr
13336 ret;
13337 ENDPROC(serpent_ctr_16way)
13338
13339@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13340
13341 vzeroupper;
13342
13343+ pax_force_retaddr
13344 ret;
13345 ENDPROC(serpent_xts_enc_16way)
13346
13347@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13348
13349 vzeroupper;
13350
13351+ pax_force_retaddr
13352 ret;
13353 ENDPROC(serpent_xts_dec_16way)
13354diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13355index acc066c..1559cc4 100644
13356--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13357+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13358@@ -25,6 +25,7 @@
13359 */
13360
13361 #include <linux/linkage.h>
13362+#include <asm/alternative-asm.h>
13363
13364 .file "serpent-sse2-x86_64-asm_64.S"
13365 .text
13366@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13367 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13368 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13369
13370+ pax_force_retaddr
13371 ret;
13372
13373 .L__enc_xor8:
13374 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13375 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13376
13377+ pax_force_retaddr
13378 ret;
13379 ENDPROC(__serpent_enc_blk_8way)
13380
13381@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13382 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13383 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13384
13385+ pax_force_retaddr
13386 ret;
13387 ENDPROC(serpent_dec_blk_8way)
13388diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13389index a410950..9dfe7ad 100644
13390--- a/arch/x86/crypto/sha1_ssse3_asm.S
13391+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13392@@ -29,6 +29,7 @@
13393 */
13394
13395 #include <linux/linkage.h>
13396+#include <asm/alternative-asm.h>
13397
13398 #define CTX %rdi // arg1
13399 #define BUF %rsi // arg2
13400@@ -75,9 +76,9 @@
13401
13402 push %rbx
13403 push %rbp
13404- push %r12
13405+ push %r14
13406
13407- mov %rsp, %r12
13408+ mov %rsp, %r14
13409 sub $64, %rsp # allocate workspace
13410 and $~15, %rsp # align stack
13411
13412@@ -99,11 +100,12 @@
13413 xor %rax, %rax
13414 rep stosq
13415
13416- mov %r12, %rsp # deallocate workspace
13417+ mov %r14, %rsp # deallocate workspace
13418
13419- pop %r12
13420+ pop %r14
13421 pop %rbp
13422 pop %rbx
13423+ pax_force_retaddr
13424 ret
13425
13426 ENDPROC(\name)
13427diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13428index 642f156..51a513c 100644
13429--- a/arch/x86/crypto/sha256-avx-asm.S
13430+++ b/arch/x86/crypto/sha256-avx-asm.S
13431@@ -49,6 +49,7 @@
13432
13433 #ifdef CONFIG_AS_AVX
13434 #include <linux/linkage.h>
13435+#include <asm/alternative-asm.h>
13436
13437 ## assume buffers not aligned
13438 #define VMOVDQ vmovdqu
13439@@ -460,6 +461,7 @@ done_hash:
13440 popq %r13
13441 popq %rbp
13442 popq %rbx
13443+ pax_force_retaddr
13444 ret
13445 ENDPROC(sha256_transform_avx)
13446
13447diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13448index 9e86944..3795e6a 100644
13449--- a/arch/x86/crypto/sha256-avx2-asm.S
13450+++ b/arch/x86/crypto/sha256-avx2-asm.S
13451@@ -50,6 +50,7 @@
13452
13453 #ifdef CONFIG_AS_AVX2
13454 #include <linux/linkage.h>
13455+#include <asm/alternative-asm.h>
13456
13457 ## assume buffers not aligned
13458 #define VMOVDQ vmovdqu
13459@@ -720,6 +721,7 @@ done_hash:
13460 popq %r12
13461 popq %rbp
13462 popq %rbx
13463+ pax_force_retaddr
13464 ret
13465 ENDPROC(sha256_transform_rorx)
13466
13467diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13468index f833b74..8c62a9e 100644
13469--- a/arch/x86/crypto/sha256-ssse3-asm.S
13470+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13471@@ -47,6 +47,7 @@
13472 ########################################################################
13473
13474 #include <linux/linkage.h>
13475+#include <asm/alternative-asm.h>
13476
13477 ## assume buffers not aligned
13478 #define MOVDQ movdqu
13479@@ -471,6 +472,7 @@ done_hash:
13480 popq %rbp
13481 popq %rbx
13482
13483+ pax_force_retaddr
13484 ret
13485 ENDPROC(sha256_transform_ssse3)
13486
13487diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13488index 974dde9..a823ff9 100644
13489--- a/arch/x86/crypto/sha512-avx-asm.S
13490+++ b/arch/x86/crypto/sha512-avx-asm.S
13491@@ -49,6 +49,7 @@
13492
13493 #ifdef CONFIG_AS_AVX
13494 #include <linux/linkage.h>
13495+#include <asm/alternative-asm.h>
13496
13497 .text
13498
13499@@ -364,6 +365,7 @@ updateblock:
13500 mov frame_RSPSAVE(%rsp), %rsp
13501
13502 nowork:
13503+ pax_force_retaddr
13504 ret
13505 ENDPROC(sha512_transform_avx)
13506
13507diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13508index 568b961..ed20c37 100644
13509--- a/arch/x86/crypto/sha512-avx2-asm.S
13510+++ b/arch/x86/crypto/sha512-avx2-asm.S
13511@@ -51,6 +51,7 @@
13512
13513 #ifdef CONFIG_AS_AVX2
13514 #include <linux/linkage.h>
13515+#include <asm/alternative-asm.h>
13516
13517 .text
13518
13519@@ -678,6 +679,7 @@ done_hash:
13520
13521 # Restore Stack Pointer
13522 mov frame_RSPSAVE(%rsp), %rsp
13523+ pax_force_retaddr
13524 ret
13525 ENDPROC(sha512_transform_rorx)
13526
13527diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13528index fb56855..6edd768 100644
13529--- a/arch/x86/crypto/sha512-ssse3-asm.S
13530+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13531@@ -48,6 +48,7 @@
13532 ########################################################################
13533
13534 #include <linux/linkage.h>
13535+#include <asm/alternative-asm.h>
13536
13537 .text
13538
13539@@ -363,6 +364,7 @@ updateblock:
13540 mov frame_RSPSAVE(%rsp), %rsp
13541
13542 nowork:
13543+ pax_force_retaddr
13544 ret
13545 ENDPROC(sha512_transform_ssse3)
13546
13547diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13548index 0505813..b067311 100644
13549--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13550+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13551@@ -24,6 +24,7 @@
13552 */
13553
13554 #include <linux/linkage.h>
13555+#include <asm/alternative-asm.h>
13556 #include "glue_helper-asm-avx.S"
13557
13558 .file "twofish-avx-x86_64-asm_64.S"
13559@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13560 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13561 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13562
13563+ pax_force_retaddr
13564 ret;
13565 ENDPROC(__twofish_enc_blk8)
13566
13567@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13568 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13569 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13570
13571+ pax_force_retaddr
13572 ret;
13573 ENDPROC(__twofish_dec_blk8)
13574
13575@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13576
13577 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13578
13579+ pax_force_retaddr
13580 ret;
13581 ENDPROC(twofish_ecb_enc_8way)
13582
13583@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13584
13585 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13586
13587+ pax_force_retaddr
13588 ret;
13589 ENDPROC(twofish_ecb_dec_8way)
13590
13591@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13592 * %rdx: src
13593 */
13594
13595- pushq %r12;
13596+ pushq %r14;
13597
13598 movq %rsi, %r11;
13599- movq %rdx, %r12;
13600+ movq %rdx, %r14;
13601
13602 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13603
13604 call __twofish_dec_blk8;
13605
13606- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13607+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13608
13609- popq %r12;
13610+ popq %r14;
13611
13612+ pax_force_retaddr
13613 ret;
13614 ENDPROC(twofish_cbc_dec_8way)
13615
13616@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13617 * %rcx: iv (little endian, 128bit)
13618 */
13619
13620- pushq %r12;
13621+ pushq %r14;
13622
13623 movq %rsi, %r11;
13624- movq %rdx, %r12;
13625+ movq %rdx, %r14;
13626
13627 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13628 RD2, RX0, RX1, RY0);
13629
13630 call __twofish_enc_blk8;
13631
13632- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13633+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13634
13635- popq %r12;
13636+ popq %r14;
13637
13638+ pax_force_retaddr
13639 ret;
13640 ENDPROC(twofish_ctr_8way)
13641
13642@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13643 /* dst <= regs xor IVs(in dst) */
13644 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13645
13646+ pax_force_retaddr
13647 ret;
13648 ENDPROC(twofish_xts_enc_8way)
13649
13650@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13651 /* dst <= regs xor IVs(in dst) */
13652 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13653
13654+ pax_force_retaddr
13655 ret;
13656 ENDPROC(twofish_xts_dec_8way)
13657diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13658index 1c3b7ce..02f578d 100644
13659--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13660+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13661@@ -21,6 +21,7 @@
13662 */
13663
13664 #include <linux/linkage.h>
13665+#include <asm/alternative-asm.h>
13666
13667 .file "twofish-x86_64-asm-3way.S"
13668 .text
13669@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13670 popq %r13;
13671 popq %r14;
13672 popq %r15;
13673+ pax_force_retaddr
13674 ret;
13675
13676 .L__enc_xor3:
13677@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13678 popq %r13;
13679 popq %r14;
13680 popq %r15;
13681+ pax_force_retaddr
13682 ret;
13683 ENDPROC(__twofish_enc_blk_3way)
13684
13685@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13686 popq %r13;
13687 popq %r14;
13688 popq %r15;
13689+ pax_force_retaddr
13690 ret;
13691 ENDPROC(twofish_dec_blk_3way)
13692diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13693index a039d21..524b8b2 100644
13694--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13695+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13696@@ -22,6 +22,7 @@
13697
13698 #include <linux/linkage.h>
13699 #include <asm/asm-offsets.h>
13700+#include <asm/alternative-asm.h>
13701
13702 #define a_offset 0
13703 #define b_offset 4
13704@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13705
13706 popq R1
13707 movq $1,%rax
13708+ pax_force_retaddr
13709 ret
13710 ENDPROC(twofish_enc_blk)
13711
13712@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13713
13714 popq R1
13715 movq $1,%rax
13716+ pax_force_retaddr
13717 ret
13718 ENDPROC(twofish_dec_blk)
13719diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13720index bae3aba..c1788c1 100644
13721--- a/arch/x86/ia32/ia32_aout.c
13722+++ b/arch/x86/ia32/ia32_aout.c
13723@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13724 unsigned long dump_start, dump_size;
13725 struct user32 dump;
13726
13727+ memset(&dump, 0, sizeof(dump));
13728+
13729 fs = get_fs();
13730 set_fs(KERNEL_DS);
13731 has_dumped = 1;
13732diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13733index 665a730..8e7a67a 100644
13734--- a/arch/x86/ia32/ia32_signal.c
13735+++ b/arch/x86/ia32/ia32_signal.c
13736@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13737 sp -= frame_size;
13738 /* Align the stack pointer according to the i386 ABI,
13739 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13740- sp = ((sp + 4) & -16ul) - 4;
13741+ sp = ((sp - 12) & -16ul) - 4;
13742 return (void __user *) sp;
13743 }
13744
13745@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13746 * These are actually not used anymore, but left because some
13747 * gdb versions depend on them as a marker.
13748 */
13749- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13750+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13751 } put_user_catch(err);
13752
13753 if (err)
13754@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13755 0xb8,
13756 __NR_ia32_rt_sigreturn,
13757 0x80cd,
13758- 0,
13759+ 0
13760 };
13761
13762 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13763@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13764
13765 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13766 restorer = ksig->ka.sa.sa_restorer;
13767+ else if (current->mm->context.vdso)
13768+ /* Return stub is in 32bit vsyscall page */
13769+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13770 else
13771- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13772- rt_sigreturn);
13773+ restorer = &frame->retcode;
13774 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13775
13776 /*
13777 * Not actually used anymore, but left because some gdb
13778 * versions need it.
13779 */
13780- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13781+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13782 } put_user_catch(err);
13783
13784 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13785diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13786index 4299eb0..c0687a7 100644
13787--- a/arch/x86/ia32/ia32entry.S
13788+++ b/arch/x86/ia32/ia32entry.S
13789@@ -15,8 +15,10 @@
13790 #include <asm/irqflags.h>
13791 #include <asm/asm.h>
13792 #include <asm/smap.h>
13793+#include <asm/pgtable.h>
13794 #include <linux/linkage.h>
13795 #include <linux/err.h>
13796+#include <asm/alternative-asm.h>
13797
13798 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13799 #include <linux/elf-em.h>
13800@@ -62,12 +64,12 @@
13801 */
13802 .macro LOAD_ARGS32 offset, _r9=0
13803 .if \_r9
13804- movl \offset+16(%rsp),%r9d
13805+ movl \offset+R9(%rsp),%r9d
13806 .endif
13807- movl \offset+40(%rsp),%ecx
13808- movl \offset+48(%rsp),%edx
13809- movl \offset+56(%rsp),%esi
13810- movl \offset+64(%rsp),%edi
13811+ movl \offset+RCX(%rsp),%ecx
13812+ movl \offset+RDX(%rsp),%edx
13813+ movl \offset+RSI(%rsp),%esi
13814+ movl \offset+RDI(%rsp),%edi
13815 movl %eax,%eax /* zero extension */
13816 .endm
13817
13818@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13819 ENDPROC(native_irq_enable_sysexit)
13820 #endif
13821
13822+ .macro pax_enter_kernel_user
13823+ pax_set_fptr_mask
13824+#ifdef CONFIG_PAX_MEMORY_UDEREF
13825+ call pax_enter_kernel_user
13826+#endif
13827+ .endm
13828+
13829+ .macro pax_exit_kernel_user
13830+#ifdef CONFIG_PAX_MEMORY_UDEREF
13831+ call pax_exit_kernel_user
13832+#endif
13833+#ifdef CONFIG_PAX_RANDKSTACK
13834+ pushq %rax
13835+ pushq %r11
13836+ call pax_randomize_kstack
13837+ popq %r11
13838+ popq %rax
13839+#endif
13840+ .endm
13841+
13842+ .macro pax_erase_kstack
13843+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13844+ call pax_erase_kstack
13845+#endif
13846+ .endm
13847+
13848 /*
13849 * 32bit SYSENTER instruction entry.
13850 *
13851@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13852 CFI_REGISTER rsp,rbp
13853 SWAPGS_UNSAFE_STACK
13854 movq PER_CPU_VAR(kernel_stack), %rsp
13855- addq $(KERNEL_STACK_OFFSET),%rsp
13856- /*
13857- * No need to follow this irqs on/off section: the syscall
13858- * disabled irqs, here we enable it straight after entry:
13859- */
13860- ENABLE_INTERRUPTS(CLBR_NONE)
13861 movl %ebp,%ebp /* zero extension */
13862 pushq_cfi $__USER32_DS
13863 /*CFI_REL_OFFSET ss,0*/
13864@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13865 CFI_REL_OFFSET rsp,0
13866 pushfq_cfi
13867 /*CFI_REL_OFFSET rflags,0*/
13868- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13869- CFI_REGISTER rip,r10
13870+ orl $X86_EFLAGS_IF,(%rsp)
13871+ GET_THREAD_INFO(%r11)
13872+ movl TI_sysenter_return(%r11), %r11d
13873+ CFI_REGISTER rip,r11
13874 pushq_cfi $__USER32_CS
13875 /*CFI_REL_OFFSET cs,0*/
13876 movl %eax, %eax
13877- pushq_cfi %r10
13878+ pushq_cfi %r11
13879 CFI_REL_OFFSET rip,0
13880 pushq_cfi %rax
13881 cld
13882 SAVE_ARGS 0,1,0
13883+ pax_enter_kernel_user
13884+
13885+#ifdef CONFIG_PAX_RANDKSTACK
13886+ pax_erase_kstack
13887+#endif
13888+
13889+ /*
13890+ * No need to follow this irqs on/off section: the syscall
13891+ * disabled irqs, here we enable it straight after entry:
13892+ */
13893+ ENABLE_INTERRUPTS(CLBR_NONE)
13894 /* no need to do an access_ok check here because rbp has been
13895 32bit zero extended */
13896+
13897+#ifdef CONFIG_PAX_MEMORY_UDEREF
13898+ addq pax_user_shadow_base,%rbp
13899+ ASM_PAX_OPEN_USERLAND
13900+#endif
13901+
13902 ASM_STAC
13903 1: movl (%rbp),%ebp
13904 _ASM_EXTABLE(1b,ia32_badarg)
13905 ASM_CLAC
13906- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13907- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13908+
13909+#ifdef CONFIG_PAX_MEMORY_UDEREF
13910+ ASM_PAX_CLOSE_USERLAND
13911+#endif
13912+
13913+ GET_THREAD_INFO(%r11)
13914+ orl $TS_COMPAT,TI_status(%r11)
13915+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13916 CFI_REMEMBER_STATE
13917 jnz sysenter_tracesys
13918 cmpq $(IA32_NR_syscalls-1),%rax
13919@@ -162,15 +209,18 @@ sysenter_do_call:
13920 sysenter_dispatch:
13921 call *ia32_sys_call_table(,%rax,8)
13922 movq %rax,RAX-ARGOFFSET(%rsp)
13923+ GET_THREAD_INFO(%r11)
13924 DISABLE_INTERRUPTS(CLBR_NONE)
13925 TRACE_IRQS_OFF
13926- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13927+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13928 jnz sysexit_audit
13929 sysexit_from_sys_call:
13930- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13931+ pax_exit_kernel_user
13932+ pax_erase_kstack
13933+ andl $~TS_COMPAT,TI_status(%r11)
13934 /* clear IF, that popfq doesn't enable interrupts early */
13935- andl $~0x200,EFLAGS-R11(%rsp)
13936- movl RIP-R11(%rsp),%edx /* User %eip */
13937+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13938+ movl RIP(%rsp),%edx /* User %eip */
13939 CFI_REGISTER rip,rdx
13940 RESTORE_ARGS 0,24,0,0,0,0
13941 xorq %r8,%r8
13942@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13943 movl %eax,%esi /* 2nd arg: syscall number */
13944 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13945 call __audit_syscall_entry
13946+
13947+ pax_erase_kstack
13948+
13949 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13950 cmpq $(IA32_NR_syscalls-1),%rax
13951 ja ia32_badsys
13952@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13953 .endm
13954
13955 .macro auditsys_exit exit
13956- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13957+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13958 jnz ia32_ret_from_sys_call
13959 TRACE_IRQS_ON
13960 ENABLE_INTERRUPTS(CLBR_NONE)
13961@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13962 1: setbe %al /* 1 if error, 0 if not */
13963 movzbl %al,%edi /* zero-extend that into %edi */
13964 call __audit_syscall_exit
13965+ GET_THREAD_INFO(%r11)
13966 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13967 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13968 DISABLE_INTERRUPTS(CLBR_NONE)
13969 TRACE_IRQS_OFF
13970- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13971+ testl %edi,TI_flags(%r11)
13972 jz \exit
13973 CLEAR_RREGS -ARGOFFSET
13974 jmp int_with_check
13975@@ -237,7 +291,7 @@ sysexit_audit:
13976
13977 sysenter_tracesys:
13978 #ifdef CONFIG_AUDITSYSCALL
13979- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13980+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13981 jz sysenter_auditsys
13982 #endif
13983 SAVE_REST
13984@@ -249,6 +303,9 @@ sysenter_tracesys:
13985 RESTORE_REST
13986 cmpq $(IA32_NR_syscalls-1),%rax
13987 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13988+
13989+ pax_erase_kstack
13990+
13991 jmp sysenter_do_call
13992 CFI_ENDPROC
13993 ENDPROC(ia32_sysenter_target)
13994@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13995 ENTRY(ia32_cstar_target)
13996 CFI_STARTPROC32 simple
13997 CFI_SIGNAL_FRAME
13998- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13999+ CFI_DEF_CFA rsp,0
14000 CFI_REGISTER rip,rcx
14001 /*CFI_REGISTER rflags,r11*/
14002 SWAPGS_UNSAFE_STACK
14003 movl %esp,%r8d
14004 CFI_REGISTER rsp,r8
14005 movq PER_CPU_VAR(kernel_stack),%rsp
14006+ SAVE_ARGS 8*6,0,0
14007+ pax_enter_kernel_user
14008+
14009+#ifdef CONFIG_PAX_RANDKSTACK
14010+ pax_erase_kstack
14011+#endif
14012+
14013 /*
14014 * No need to follow this irqs on/off section: the syscall
14015 * disabled irqs and here we enable it straight after entry:
14016 */
14017 ENABLE_INTERRUPTS(CLBR_NONE)
14018- SAVE_ARGS 8,0,0
14019 movl %eax,%eax /* zero extension */
14020 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14021 movq %rcx,RIP-ARGOFFSET(%rsp)
14022@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14023 /* no need to do an access_ok check here because r8 has been
14024 32bit zero extended */
14025 /* hardware stack frame is complete now */
14026+
14027+#ifdef CONFIG_PAX_MEMORY_UDEREF
14028+ ASM_PAX_OPEN_USERLAND
14029+ movq pax_user_shadow_base,%r8
14030+ addq RSP-ARGOFFSET(%rsp),%r8
14031+#endif
14032+
14033 ASM_STAC
14034 1: movl (%r8),%r9d
14035 _ASM_EXTABLE(1b,ia32_badarg)
14036 ASM_CLAC
14037- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14038- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14039+
14040+#ifdef CONFIG_PAX_MEMORY_UDEREF
14041+ ASM_PAX_CLOSE_USERLAND
14042+#endif
14043+
14044+ GET_THREAD_INFO(%r11)
14045+ orl $TS_COMPAT,TI_status(%r11)
14046+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14047 CFI_REMEMBER_STATE
14048 jnz cstar_tracesys
14049 cmpq $IA32_NR_syscalls-1,%rax
14050@@ -319,13 +395,16 @@ cstar_do_call:
14051 cstar_dispatch:
14052 call *ia32_sys_call_table(,%rax,8)
14053 movq %rax,RAX-ARGOFFSET(%rsp)
14054+ GET_THREAD_INFO(%r11)
14055 DISABLE_INTERRUPTS(CLBR_NONE)
14056 TRACE_IRQS_OFF
14057- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14058+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14059 jnz sysretl_audit
14060 sysretl_from_sys_call:
14061- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14062- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14063+ pax_exit_kernel_user
14064+ pax_erase_kstack
14065+ andl $~TS_COMPAT,TI_status(%r11)
14066+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14067 movl RIP-ARGOFFSET(%rsp),%ecx
14068 CFI_REGISTER rip,rcx
14069 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14070@@ -352,7 +431,7 @@ sysretl_audit:
14071
14072 cstar_tracesys:
14073 #ifdef CONFIG_AUDITSYSCALL
14074- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14075+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14076 jz cstar_auditsys
14077 #endif
14078 xchgl %r9d,%ebp
14079@@ -366,11 +445,19 @@ cstar_tracesys:
14080 xchgl %ebp,%r9d
14081 cmpq $(IA32_NR_syscalls-1),%rax
14082 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14083+
14084+ pax_erase_kstack
14085+
14086 jmp cstar_do_call
14087 END(ia32_cstar_target)
14088
14089 ia32_badarg:
14090 ASM_CLAC
14091+
14092+#ifdef CONFIG_PAX_MEMORY_UDEREF
14093+ ASM_PAX_CLOSE_USERLAND
14094+#endif
14095+
14096 movq $-EFAULT,%rax
14097 jmp ia32_sysret
14098 CFI_ENDPROC
14099@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14100 CFI_REL_OFFSET rip,RIP-RIP
14101 PARAVIRT_ADJUST_EXCEPTION_FRAME
14102 SWAPGS
14103- /*
14104- * No need to follow this irqs on/off section: the syscall
14105- * disabled irqs and here we enable it straight after entry:
14106- */
14107- ENABLE_INTERRUPTS(CLBR_NONE)
14108 movl %eax,%eax
14109 pushq_cfi %rax
14110 cld
14111 /* note the registers are not zero extended to the sf.
14112 this could be a problem. */
14113 SAVE_ARGS 0,1,0
14114- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14115- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14116+ pax_enter_kernel_user
14117+
14118+#ifdef CONFIG_PAX_RANDKSTACK
14119+ pax_erase_kstack
14120+#endif
14121+
14122+ /*
14123+ * No need to follow this irqs on/off section: the syscall
14124+ * disabled irqs and here we enable it straight after entry:
14125+ */
14126+ ENABLE_INTERRUPTS(CLBR_NONE)
14127+ GET_THREAD_INFO(%r11)
14128+ orl $TS_COMPAT,TI_status(%r11)
14129+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14130 jnz ia32_tracesys
14131 cmpq $(IA32_NR_syscalls-1),%rax
14132 ja ia32_badsys
14133@@ -442,6 +536,9 @@ ia32_tracesys:
14134 RESTORE_REST
14135 cmpq $(IA32_NR_syscalls-1),%rax
14136 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14137+
14138+ pax_erase_kstack
14139+
14140 jmp ia32_do_call
14141 END(ia32_syscall)
14142
14143diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14144index 8e0ceec..af13504 100644
14145--- a/arch/x86/ia32/sys_ia32.c
14146+++ b/arch/x86/ia32/sys_ia32.c
14147@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14148 */
14149 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14150 {
14151- typeof(ubuf->st_uid) uid = 0;
14152- typeof(ubuf->st_gid) gid = 0;
14153+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14154+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14155 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14156 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14157 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14158diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14159index 372231c..51b537d 100644
14160--- a/arch/x86/include/asm/alternative-asm.h
14161+++ b/arch/x86/include/asm/alternative-asm.h
14162@@ -18,6 +18,45 @@
14163 .endm
14164 #endif
14165
14166+#ifdef KERNEXEC_PLUGIN
14167+ .macro pax_force_retaddr_bts rip=0
14168+ btsq $63,\rip(%rsp)
14169+ .endm
14170+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14171+ .macro pax_force_retaddr rip=0, reload=0
14172+ btsq $63,\rip(%rsp)
14173+ .endm
14174+ .macro pax_force_fptr ptr
14175+ btsq $63,\ptr
14176+ .endm
14177+ .macro pax_set_fptr_mask
14178+ .endm
14179+#endif
14180+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14181+ .macro pax_force_retaddr rip=0, reload=0
14182+ .if \reload
14183+ pax_set_fptr_mask
14184+ .endif
14185+ orq %r12,\rip(%rsp)
14186+ .endm
14187+ .macro pax_force_fptr ptr
14188+ orq %r12,\ptr
14189+ .endm
14190+ .macro pax_set_fptr_mask
14191+ movabs $0x8000000000000000,%r12
14192+ .endm
14193+#endif
14194+#else
14195+ .macro pax_force_retaddr rip=0, reload=0
14196+ .endm
14197+ .macro pax_force_fptr ptr
14198+ .endm
14199+ .macro pax_force_retaddr_bts rip=0
14200+ .endm
14201+ .macro pax_set_fptr_mask
14202+ .endm
14203+#endif
14204+
14205 .macro altinstruction_entry orig alt feature orig_len alt_len
14206 .long \orig - .
14207 .long \alt - .
14208diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14209index 0a3f9c9..c9d081d 100644
14210--- a/arch/x86/include/asm/alternative.h
14211+++ b/arch/x86/include/asm/alternative.h
14212@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14213 ".pushsection .discard,\"aw\",@progbits\n" \
14214 DISCARD_ENTRY(1) \
14215 ".popsection\n" \
14216- ".pushsection .altinstr_replacement, \"ax\"\n" \
14217+ ".pushsection .altinstr_replacement, \"a\"\n" \
14218 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14219 ".popsection"
14220
14221@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14222 DISCARD_ENTRY(1) \
14223 DISCARD_ENTRY(2) \
14224 ".popsection\n" \
14225- ".pushsection .altinstr_replacement, \"ax\"\n" \
14226+ ".pushsection .altinstr_replacement, \"a\"\n" \
14227 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14228 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14229 ".popsection"
14230diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14231index 1d2091a..f5074c1 100644
14232--- a/arch/x86/include/asm/apic.h
14233+++ b/arch/x86/include/asm/apic.h
14234@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14235
14236 #ifdef CONFIG_X86_LOCAL_APIC
14237
14238-extern unsigned int apic_verbosity;
14239+extern int apic_verbosity;
14240 extern int local_apic_timer_c2_ok;
14241
14242 extern int disable_apic;
14243diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14244index 20370c6..a2eb9b0 100644
14245--- a/arch/x86/include/asm/apm.h
14246+++ b/arch/x86/include/asm/apm.h
14247@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14248 __asm__ __volatile__(APM_DO_ZERO_SEGS
14249 "pushl %%edi\n\t"
14250 "pushl %%ebp\n\t"
14251- "lcall *%%cs:apm_bios_entry\n\t"
14252+ "lcall *%%ss:apm_bios_entry\n\t"
14253 "setc %%al\n\t"
14254 "popl %%ebp\n\t"
14255 "popl %%edi\n\t"
14256@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14257 __asm__ __volatile__(APM_DO_ZERO_SEGS
14258 "pushl %%edi\n\t"
14259 "pushl %%ebp\n\t"
14260- "lcall *%%cs:apm_bios_entry\n\t"
14261+ "lcall *%%ss:apm_bios_entry\n\t"
14262 "setc %%bl\n\t"
14263 "popl %%ebp\n\t"
14264 "popl %%edi\n\t"
14265diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14266index 722aa3b..3a0bb27 100644
14267--- a/arch/x86/include/asm/atomic.h
14268+++ b/arch/x86/include/asm/atomic.h
14269@@ -22,7 +22,18 @@
14270 */
14271 static inline int atomic_read(const atomic_t *v)
14272 {
14273- return (*(volatile int *)&(v)->counter);
14274+ return (*(volatile const int *)&(v)->counter);
14275+}
14276+
14277+/**
14278+ * atomic_read_unchecked - read atomic variable
14279+ * @v: pointer of type atomic_unchecked_t
14280+ *
14281+ * Atomically reads the value of @v.
14282+ */
14283+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
14284+{
14285+ return (*(volatile const int *)&(v)->counter);
14286 }
14287
14288 /**
14289@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
14290 }
14291
14292 /**
14293+ * atomic_set_unchecked - set atomic variable
14294+ * @v: pointer of type atomic_unchecked_t
14295+ * @i: required value
14296+ *
14297+ * Atomically sets the value of @v to @i.
14298+ */
14299+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14300+{
14301+ v->counter = i;
14302+}
14303+
14304+/**
14305 * atomic_add - add integer to atomic variable
14306 * @i: integer value to add
14307 * @v: pointer of type atomic_t
14308@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
14309 */
14310 static inline void atomic_add(int i, atomic_t *v)
14311 {
14312- asm volatile(LOCK_PREFIX "addl %1,%0"
14313+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14314+
14315+#ifdef CONFIG_PAX_REFCOUNT
14316+ "jno 0f\n"
14317+ LOCK_PREFIX "subl %1,%0\n"
14318+ "int $4\n0:\n"
14319+ _ASM_EXTABLE(0b, 0b)
14320+#endif
14321+
14322+ : "+m" (v->counter)
14323+ : "ir" (i));
14324+}
14325+
14326+/**
14327+ * atomic_add_unchecked - add integer to atomic variable
14328+ * @i: integer value to add
14329+ * @v: pointer of type atomic_unchecked_t
14330+ *
14331+ * Atomically adds @i to @v.
14332+ */
14333+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14334+{
14335+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14336 : "+m" (v->counter)
14337 : "ir" (i));
14338 }
14339@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
14340 */
14341 static inline void atomic_sub(int i, atomic_t *v)
14342 {
14343- asm volatile(LOCK_PREFIX "subl %1,%0"
14344+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14345+
14346+#ifdef CONFIG_PAX_REFCOUNT
14347+ "jno 0f\n"
14348+ LOCK_PREFIX "addl %1,%0\n"
14349+ "int $4\n0:\n"
14350+ _ASM_EXTABLE(0b, 0b)
14351+#endif
14352+
14353+ : "+m" (v->counter)
14354+ : "ir" (i));
14355+}
14356+
14357+/**
14358+ * atomic_sub_unchecked - subtract integer from atomic variable
14359+ * @i: integer value to subtract
14360+ * @v: pointer of type atomic_unchecked_t
14361+ *
14362+ * Atomically subtracts @i from @v.
14363+ */
14364+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14365+{
14366+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14367 : "+m" (v->counter)
14368 : "ir" (i));
14369 }
14370@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14371 {
14372 unsigned char c;
14373
14374- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
14375+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
14376+
14377+#ifdef CONFIG_PAX_REFCOUNT
14378+ "jno 0f\n"
14379+ LOCK_PREFIX "addl %2,%0\n"
14380+ "int $4\n0:\n"
14381+ _ASM_EXTABLE(0b, 0b)
14382+#endif
14383+
14384+ "sete %1\n"
14385 : "+m" (v->counter), "=qm" (c)
14386 : "ir" (i) : "memory");
14387 return c;
14388@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14389 */
14390 static inline void atomic_inc(atomic_t *v)
14391 {
14392- asm volatile(LOCK_PREFIX "incl %0"
14393+ asm volatile(LOCK_PREFIX "incl %0\n"
14394+
14395+#ifdef CONFIG_PAX_REFCOUNT
14396+ "jno 0f\n"
14397+ LOCK_PREFIX "decl %0\n"
14398+ "int $4\n0:\n"
14399+ _ASM_EXTABLE(0b, 0b)
14400+#endif
14401+
14402+ : "+m" (v->counter));
14403+}
14404+
14405+/**
14406+ * atomic_inc_unchecked - increment atomic variable
14407+ * @v: pointer of type atomic_unchecked_t
14408+ *
14409+ * Atomically increments @v by 1.
14410+ */
14411+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14412+{
14413+ asm volatile(LOCK_PREFIX "incl %0\n"
14414 : "+m" (v->counter));
14415 }
14416
14417@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
14418 */
14419 static inline void atomic_dec(atomic_t *v)
14420 {
14421- asm volatile(LOCK_PREFIX "decl %0"
14422+ asm volatile(LOCK_PREFIX "decl %0\n"
14423+
14424+#ifdef CONFIG_PAX_REFCOUNT
14425+ "jno 0f\n"
14426+ LOCK_PREFIX "incl %0\n"
14427+ "int $4\n0:\n"
14428+ _ASM_EXTABLE(0b, 0b)
14429+#endif
14430+
14431+ : "+m" (v->counter));
14432+}
14433+
14434+/**
14435+ * atomic_dec_unchecked - decrement atomic variable
14436+ * @v: pointer of type atomic_unchecked_t
14437+ *
14438+ * Atomically decrements @v by 1.
14439+ */
14440+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14441+{
14442+ asm volatile(LOCK_PREFIX "decl %0\n"
14443 : "+m" (v->counter));
14444 }
14445
14446@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
14447 {
14448 unsigned char c;
14449
14450- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14451+ asm volatile(LOCK_PREFIX "decl %0\n"
14452+
14453+#ifdef CONFIG_PAX_REFCOUNT
14454+ "jno 0f\n"
14455+ LOCK_PREFIX "incl %0\n"
14456+ "int $4\n0:\n"
14457+ _ASM_EXTABLE(0b, 0b)
14458+#endif
14459+
14460+ "sete %1\n"
14461 : "+m" (v->counter), "=qm" (c)
14462 : : "memory");
14463 return c != 0;
14464@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14465 {
14466 unsigned char c;
14467
14468- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14469+ asm volatile(LOCK_PREFIX "incl %0\n"
14470+
14471+#ifdef CONFIG_PAX_REFCOUNT
14472+ "jno 0f\n"
14473+ LOCK_PREFIX "decl %0\n"
14474+ "int $4\n0:\n"
14475+ _ASM_EXTABLE(0b, 0b)
14476+#endif
14477+
14478+ "sete %1\n"
14479+ : "+m" (v->counter), "=qm" (c)
14480+ : : "memory");
14481+ return c != 0;
14482+}
14483+
14484+/**
14485+ * atomic_inc_and_test_unchecked - increment and test
14486+ * @v: pointer of type atomic_unchecked_t
14487+ *
14488+ * Atomically increments @v by 1
14489+ * and returns true if the result is zero, or false for all
14490+ * other cases.
14491+ */
14492+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14493+{
14494+ unsigned char c;
14495+
14496+ asm volatile(LOCK_PREFIX "incl %0\n"
14497+ "sete %1\n"
14498 : "+m" (v->counter), "=qm" (c)
14499 : : "memory");
14500 return c != 0;
14501@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14502 {
14503 unsigned char c;
14504
14505- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14506+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14507+
14508+#ifdef CONFIG_PAX_REFCOUNT
14509+ "jno 0f\n"
14510+ LOCK_PREFIX "subl %2,%0\n"
14511+ "int $4\n0:\n"
14512+ _ASM_EXTABLE(0b, 0b)
14513+#endif
14514+
14515+ "sets %1\n"
14516 : "+m" (v->counter), "=qm" (c)
14517 : "ir" (i) : "memory");
14518 return c;
14519@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14520 */
14521 static inline int atomic_add_return(int i, atomic_t *v)
14522 {
14523+ return i + xadd_check_overflow(&v->counter, i);
14524+}
14525+
14526+/**
14527+ * atomic_add_return_unchecked - add integer and return
14528+ * @i: integer value to add
14529+ * @v: pointer of type atomic_unchecked_t
14530+ *
14531+ * Atomically adds @i to @v and returns @i + @v
14532+ */
14533+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14534+{
14535 return i + xadd(&v->counter, i);
14536 }
14537
14538@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14539 }
14540
14541 #define atomic_inc_return(v) (atomic_add_return(1, v))
14542+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14543+{
14544+ return atomic_add_return_unchecked(1, v);
14545+}
14546 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14547
14548 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14549@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14550 return cmpxchg(&v->counter, old, new);
14551 }
14552
14553+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14554+{
14555+ return cmpxchg(&v->counter, old, new);
14556+}
14557+
14558 static inline int atomic_xchg(atomic_t *v, int new)
14559 {
14560 return xchg(&v->counter, new);
14561 }
14562
14563+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14564+{
14565+ return xchg(&v->counter, new);
14566+}
14567+
14568 /**
14569 * __atomic_add_unless - add unless the number is already a given value
14570 * @v: pointer of type atomic_t
14571@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14572 */
14573 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14574 {
14575- int c, old;
14576+ int c, old, new;
14577 c = atomic_read(v);
14578 for (;;) {
14579- if (unlikely(c == (u)))
14580+ if (unlikely(c == u))
14581 break;
14582- old = atomic_cmpxchg((v), c, c + (a));
14583+
14584+ asm volatile("addl %2,%0\n"
14585+
14586+#ifdef CONFIG_PAX_REFCOUNT
14587+ "jno 0f\n"
14588+ "subl %2,%0\n"
14589+ "int $4\n0:\n"
14590+ _ASM_EXTABLE(0b, 0b)
14591+#endif
14592+
14593+ : "=r" (new)
14594+ : "0" (c), "ir" (a));
14595+
14596+ old = atomic_cmpxchg(v, c, new);
14597 if (likely(old == c))
14598 break;
14599 c = old;
14600@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14601 }
14602
14603 /**
14604+ * atomic_inc_not_zero_hint - increment if not null
14605+ * @v: pointer of type atomic_t
14606+ * @hint: probable value of the atomic before the increment
14607+ *
14608+ * This version of atomic_inc_not_zero() gives a hint of probable
14609+ * value of the atomic. This helps processor to not read the memory
14610+ * before doing the atomic read/modify/write cycle, lowering
14611+ * number of bus transactions on some arches.
14612+ *
14613+ * Returns: 0 if increment was not done, 1 otherwise.
14614+ */
14615+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14616+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14617+{
14618+ int val, c = hint, new;
14619+
14620+ /* sanity test, should be removed by compiler if hint is a constant */
14621+ if (!hint)
14622+ return __atomic_add_unless(v, 1, 0);
14623+
14624+ do {
14625+ asm volatile("incl %0\n"
14626+
14627+#ifdef CONFIG_PAX_REFCOUNT
14628+ "jno 0f\n"
14629+ "decl %0\n"
14630+ "int $4\n0:\n"
14631+ _ASM_EXTABLE(0b, 0b)
14632+#endif
14633+
14634+ : "=r" (new)
14635+ : "0" (c));
14636+
14637+ val = atomic_cmpxchg(v, c, new);
14638+ if (val == c)
14639+ return 1;
14640+ c = val;
14641+ } while (c);
14642+
14643+ return 0;
14644+}
14645+
14646+/**
14647 * atomic_inc_short - increment of a short integer
14648 * @v: pointer to type int
14649 *
14650@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14651 #endif
14652
14653 /* These are x86-specific, used by some header files */
14654-#define atomic_clear_mask(mask, addr) \
14655- asm volatile(LOCK_PREFIX "andl %0,%1" \
14656- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14657+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14658+{
14659+ asm volatile(LOCK_PREFIX "andl %1,%0"
14660+ : "+m" (v->counter)
14661+ : "r" (~(mask))
14662+ : "memory");
14663+}
14664
14665-#define atomic_set_mask(mask, addr) \
14666- asm volatile(LOCK_PREFIX "orl %0,%1" \
14667- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14668- : "memory")
14669+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14670+{
14671+ asm volatile(LOCK_PREFIX "andl %1,%0"
14672+ : "+m" (v->counter)
14673+ : "r" (~(mask))
14674+ : "memory");
14675+}
14676+
14677+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14678+{
14679+ asm volatile(LOCK_PREFIX "orl %1,%0"
14680+ : "+m" (v->counter)
14681+ : "r" (mask)
14682+ : "memory");
14683+}
14684+
14685+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14686+{
14687+ asm volatile(LOCK_PREFIX "orl %1,%0"
14688+ : "+m" (v->counter)
14689+ : "r" (mask)
14690+ : "memory");
14691+}
14692
14693 /* Atomic operations are already serializing on x86 */
14694 #define smp_mb__before_atomic_dec() barrier()
14695diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14696index b154de7..aadebd8 100644
14697--- a/arch/x86/include/asm/atomic64_32.h
14698+++ b/arch/x86/include/asm/atomic64_32.h
14699@@ -12,6 +12,14 @@ typedef struct {
14700 u64 __aligned(8) counter;
14701 } atomic64_t;
14702
14703+#ifdef CONFIG_PAX_REFCOUNT
14704+typedef struct {
14705+ u64 __aligned(8) counter;
14706+} atomic64_unchecked_t;
14707+#else
14708+typedef atomic64_t atomic64_unchecked_t;
14709+#endif
14710+
14711 #define ATOMIC64_INIT(val) { (val) }
14712
14713 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14714@@ -37,21 +45,31 @@ typedef struct {
14715 ATOMIC64_DECL_ONE(sym##_386)
14716
14717 ATOMIC64_DECL_ONE(add_386);
14718+ATOMIC64_DECL_ONE(add_unchecked_386);
14719 ATOMIC64_DECL_ONE(sub_386);
14720+ATOMIC64_DECL_ONE(sub_unchecked_386);
14721 ATOMIC64_DECL_ONE(inc_386);
14722+ATOMIC64_DECL_ONE(inc_unchecked_386);
14723 ATOMIC64_DECL_ONE(dec_386);
14724+ATOMIC64_DECL_ONE(dec_unchecked_386);
14725 #endif
14726
14727 #define alternative_atomic64(f, out, in...) \
14728 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14729
14730 ATOMIC64_DECL(read);
14731+ATOMIC64_DECL(read_unchecked);
14732 ATOMIC64_DECL(set);
14733+ATOMIC64_DECL(set_unchecked);
14734 ATOMIC64_DECL(xchg);
14735 ATOMIC64_DECL(add_return);
14736+ATOMIC64_DECL(add_return_unchecked);
14737 ATOMIC64_DECL(sub_return);
14738+ATOMIC64_DECL(sub_return_unchecked);
14739 ATOMIC64_DECL(inc_return);
14740+ATOMIC64_DECL(inc_return_unchecked);
14741 ATOMIC64_DECL(dec_return);
14742+ATOMIC64_DECL(dec_return_unchecked);
14743 ATOMIC64_DECL(dec_if_positive);
14744 ATOMIC64_DECL(inc_not_zero);
14745 ATOMIC64_DECL(add_unless);
14746@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14747 }
14748
14749 /**
14750+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14751+ * @p: pointer to type atomic64_unchecked_t
14752+ * @o: expected value
14753+ * @n: new value
14754+ *
14755+ * Atomically sets @v to @n if it was equal to @o and returns
14756+ * the old value.
14757+ */
14758+
14759+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14760+{
14761+ return cmpxchg64(&v->counter, o, n);
14762+}
14763+
14764+/**
14765 * atomic64_xchg - xchg atomic64 variable
14766 * @v: pointer to type atomic64_t
14767 * @n: value to assign
14768@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14769 }
14770
14771 /**
14772+ * atomic64_set_unchecked - set atomic64 variable
14773+ * @v: pointer to type atomic64_unchecked_t
14774+ * @n: value to assign
14775+ *
14776+ * Atomically sets the value of @v to @n.
14777+ */
14778+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14779+{
14780+ unsigned high = (unsigned)(i >> 32);
14781+ unsigned low = (unsigned)i;
14782+ alternative_atomic64(set, /* no output */,
14783+ "S" (v), "b" (low), "c" (high)
14784+ : "eax", "edx", "memory");
14785+}
14786+
14787+/**
14788 * atomic64_read - read atomic64 variable
14789 * @v: pointer to type atomic64_t
14790 *
14791@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14792 }
14793
14794 /**
14795+ * atomic64_read_unchecked - read atomic64 variable
14796+ * @v: pointer to type atomic64_unchecked_t
14797+ *
14798+ * Atomically reads the value of @v and returns it.
14799+ */
14800+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14801+{
14802+ long long r;
14803+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14804+ return r;
14805+ }
14806+
14807+/**
14808 * atomic64_add_return - add and return
14809 * @i: integer value to add
14810 * @v: pointer to type atomic64_t
14811@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14812 return i;
14813 }
14814
14815+/**
14816+ * atomic64_add_return_unchecked - add and return
14817+ * @i: integer value to add
14818+ * @v: pointer to type atomic64_unchecked_t
14819+ *
14820+ * Atomically adds @i to @v and returns @i + *@v
14821+ */
14822+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14823+{
14824+ alternative_atomic64(add_return_unchecked,
14825+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14826+ ASM_NO_INPUT_CLOBBER("memory"));
14827+ return i;
14828+}
14829+
14830 /*
14831 * Other variants with different arithmetic operators:
14832 */
14833@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14834 return a;
14835 }
14836
14837+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14838+{
14839+ long long a;
14840+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14841+ "S" (v) : "memory", "ecx");
14842+ return a;
14843+}
14844+
14845 static inline long long atomic64_dec_return(atomic64_t *v)
14846 {
14847 long long a;
14848@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14849 }
14850
14851 /**
14852+ * atomic64_add_unchecked - add integer to atomic64 variable
14853+ * @i: integer value to add
14854+ * @v: pointer to type atomic64_unchecked_t
14855+ *
14856+ * Atomically adds @i to @v.
14857+ */
14858+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14859+{
14860+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14861+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14862+ ASM_NO_INPUT_CLOBBER("memory"));
14863+ return i;
14864+}
14865+
14866+/**
14867 * atomic64_sub - subtract the atomic64 variable
14868 * @i: integer value to subtract
14869 * @v: pointer to type atomic64_t
14870diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14871index 0e1cbfc..5623683 100644
14872--- a/arch/x86/include/asm/atomic64_64.h
14873+++ b/arch/x86/include/asm/atomic64_64.h
14874@@ -18,7 +18,19 @@
14875 */
14876 static inline long atomic64_read(const atomic64_t *v)
14877 {
14878- return (*(volatile long *)&(v)->counter);
14879+ return (*(volatile const long *)&(v)->counter);
14880+}
14881+
14882+/**
14883+ * atomic64_read_unchecked - read atomic64 variable
14884+ * @v: pointer of type atomic64_unchecked_t
14885+ *
14886+ * Atomically reads the value of @v.
14887+ * Doesn't imply a read memory barrier.
14888+ */
14889+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14890+{
14891+ return (*(volatile const long *)&(v)->counter);
14892 }
14893
14894 /**
14895@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14896 }
14897
14898 /**
14899+ * atomic64_set_unchecked - set atomic64 variable
14900+ * @v: pointer to type atomic64_unchecked_t
14901+ * @i: required value
14902+ *
14903+ * Atomically sets the value of @v to @i.
14904+ */
14905+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14906+{
14907+ v->counter = i;
14908+}
14909+
14910+/**
14911 * atomic64_add - add integer to atomic64 variable
14912 * @i: integer value to add
14913 * @v: pointer to type atomic64_t
14914@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14915 */
14916 static inline void atomic64_add(long i, atomic64_t *v)
14917 {
14918+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14919+
14920+#ifdef CONFIG_PAX_REFCOUNT
14921+ "jno 0f\n"
14922+ LOCK_PREFIX "subq %1,%0\n"
14923+ "int $4\n0:\n"
14924+ _ASM_EXTABLE(0b, 0b)
14925+#endif
14926+
14927+ : "=m" (v->counter)
14928+ : "er" (i), "m" (v->counter));
14929+}
14930+
14931+/**
14932+ * atomic64_add_unchecked - add integer to atomic64 variable
14933+ * @i: integer value to add
14934+ * @v: pointer to type atomic64_unchecked_t
14935+ *
14936+ * Atomically adds @i to @v.
14937+ */
14938+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14939+{
14940 asm volatile(LOCK_PREFIX "addq %1,%0"
14941 : "=m" (v->counter)
14942 : "er" (i), "m" (v->counter));
14943@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14944 */
14945 static inline void atomic64_sub(long i, atomic64_t *v)
14946 {
14947- asm volatile(LOCK_PREFIX "subq %1,%0"
14948+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14949+
14950+#ifdef CONFIG_PAX_REFCOUNT
14951+ "jno 0f\n"
14952+ LOCK_PREFIX "addq %1,%0\n"
14953+ "int $4\n0:\n"
14954+ _ASM_EXTABLE(0b, 0b)
14955+#endif
14956+
14957+ : "=m" (v->counter)
14958+ : "er" (i), "m" (v->counter));
14959+}
14960+
14961+/**
14962+ * atomic64_sub_unchecked - subtract the atomic64 variable
14963+ * @i: integer value to subtract
14964+ * @v: pointer to type atomic64_unchecked_t
14965+ *
14966+ * Atomically subtracts @i from @v.
14967+ */
14968+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14969+{
14970+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14971 : "=m" (v->counter)
14972 : "er" (i), "m" (v->counter));
14973 }
14974@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14975 {
14976 unsigned char c;
14977
14978- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14979+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14980+
14981+#ifdef CONFIG_PAX_REFCOUNT
14982+ "jno 0f\n"
14983+ LOCK_PREFIX "addq %2,%0\n"
14984+ "int $4\n0:\n"
14985+ _ASM_EXTABLE(0b, 0b)
14986+#endif
14987+
14988+ "sete %1\n"
14989 : "=m" (v->counter), "=qm" (c)
14990 : "er" (i), "m" (v->counter) : "memory");
14991 return c;
14992@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14993 */
14994 static inline void atomic64_inc(atomic64_t *v)
14995 {
14996+ asm volatile(LOCK_PREFIX "incq %0\n"
14997+
14998+#ifdef CONFIG_PAX_REFCOUNT
14999+ "jno 0f\n"
15000+ LOCK_PREFIX "decq %0\n"
15001+ "int $4\n0:\n"
15002+ _ASM_EXTABLE(0b, 0b)
15003+#endif
15004+
15005+ : "=m" (v->counter)
15006+ : "m" (v->counter));
15007+}
15008+
15009+/**
15010+ * atomic64_inc_unchecked - increment atomic64 variable
15011+ * @v: pointer to type atomic64_unchecked_t
15012+ *
15013+ * Atomically increments @v by 1.
15014+ */
15015+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15016+{
15017 asm volatile(LOCK_PREFIX "incq %0"
15018 : "=m" (v->counter)
15019 : "m" (v->counter));
15020@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
15021 */
15022 static inline void atomic64_dec(atomic64_t *v)
15023 {
15024- asm volatile(LOCK_PREFIX "decq %0"
15025+ asm volatile(LOCK_PREFIX "decq %0\n"
15026+
15027+#ifdef CONFIG_PAX_REFCOUNT
15028+ "jno 0f\n"
15029+ LOCK_PREFIX "incq %0\n"
15030+ "int $4\n0:\n"
15031+ _ASM_EXTABLE(0b, 0b)
15032+#endif
15033+
15034+ : "=m" (v->counter)
15035+ : "m" (v->counter));
15036+}
15037+
15038+/**
15039+ * atomic64_dec_unchecked - decrement atomic64 variable
15040+ * @v: pointer to type atomic64_t
15041+ *
15042+ * Atomically decrements @v by 1.
15043+ */
15044+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15045+{
15046+ asm volatile(LOCK_PREFIX "decq %0\n"
15047 : "=m" (v->counter)
15048 : "m" (v->counter));
15049 }
15050@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15051 {
15052 unsigned char c;
15053
15054- asm volatile(LOCK_PREFIX "decq %0; sete %1"
15055+ asm volatile(LOCK_PREFIX "decq %0\n"
15056+
15057+#ifdef CONFIG_PAX_REFCOUNT
15058+ "jno 0f\n"
15059+ LOCK_PREFIX "incq %0\n"
15060+ "int $4\n0:\n"
15061+ _ASM_EXTABLE(0b, 0b)
15062+#endif
15063+
15064+ "sete %1\n"
15065 : "=m" (v->counter), "=qm" (c)
15066 : "m" (v->counter) : "memory");
15067 return c != 0;
15068@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15069 {
15070 unsigned char c;
15071
15072- asm volatile(LOCK_PREFIX "incq %0; sete %1"
15073+ asm volatile(LOCK_PREFIX "incq %0\n"
15074+
15075+#ifdef CONFIG_PAX_REFCOUNT
15076+ "jno 0f\n"
15077+ LOCK_PREFIX "decq %0\n"
15078+ "int $4\n0:\n"
15079+ _ASM_EXTABLE(0b, 0b)
15080+#endif
15081+
15082+ "sete %1\n"
15083 : "=m" (v->counter), "=qm" (c)
15084 : "m" (v->counter) : "memory");
15085 return c != 0;
15086@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15087 {
15088 unsigned char c;
15089
15090- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
15091+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
15092+
15093+#ifdef CONFIG_PAX_REFCOUNT
15094+ "jno 0f\n"
15095+ LOCK_PREFIX "subq %2,%0\n"
15096+ "int $4\n0:\n"
15097+ _ASM_EXTABLE(0b, 0b)
15098+#endif
15099+
15100+ "sets %1\n"
15101 : "=m" (v->counter), "=qm" (c)
15102 : "er" (i), "m" (v->counter) : "memory");
15103 return c;
15104@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15105 */
15106 static inline long atomic64_add_return(long i, atomic64_t *v)
15107 {
15108+ return i + xadd_check_overflow(&v->counter, i);
15109+}
15110+
15111+/**
15112+ * atomic64_add_return_unchecked - add and return
15113+ * @i: integer value to add
15114+ * @v: pointer to type atomic64_unchecked_t
15115+ *
15116+ * Atomically adds @i to @v and returns @i + @v
15117+ */
15118+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15119+{
15120 return i + xadd(&v->counter, i);
15121 }
15122
15123@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15124 }
15125
15126 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15127+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15128+{
15129+ return atomic64_add_return_unchecked(1, v);
15130+}
15131 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15132
15133 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15134@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15135 return cmpxchg(&v->counter, old, new);
15136 }
15137
15138+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15139+{
15140+ return cmpxchg(&v->counter, old, new);
15141+}
15142+
15143 static inline long atomic64_xchg(atomic64_t *v, long new)
15144 {
15145 return xchg(&v->counter, new);
15146@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15147 */
15148 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15149 {
15150- long c, old;
15151+ long c, old, new;
15152 c = atomic64_read(v);
15153 for (;;) {
15154- if (unlikely(c == (u)))
15155+ if (unlikely(c == u))
15156 break;
15157- old = atomic64_cmpxchg((v), c, c + (a));
15158+
15159+ asm volatile("add %2,%0\n"
15160+
15161+#ifdef CONFIG_PAX_REFCOUNT
15162+ "jno 0f\n"
15163+ "sub %2,%0\n"
15164+ "int $4\n0:\n"
15165+ _ASM_EXTABLE(0b, 0b)
15166+#endif
15167+
15168+ : "=r" (new)
15169+ : "0" (c), "ir" (a));
15170+
15171+ old = atomic64_cmpxchg(v, c, new);
15172 if (likely(old == c))
15173 break;
15174 c = old;
15175 }
15176- return c != (u);
15177+ return c != u;
15178 }
15179
15180 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15181diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15182index 41639ce..ebce552 100644
15183--- a/arch/x86/include/asm/bitops.h
15184+++ b/arch/x86/include/asm/bitops.h
15185@@ -48,7 +48,7 @@
15186 * a mask operation on a byte.
15187 */
15188 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15189-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15190+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15191 #define CONST_MASK(nr) (1 << ((nr) & 7))
15192
15193 /**
15194@@ -361,7 +361,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15195 *
15196 * Undefined if no bit exists, so code should check against 0 first.
15197 */
15198-static inline unsigned long __ffs(unsigned long word)
15199+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15200 {
15201 asm("rep; bsf %1,%0"
15202 : "=r" (word)
15203@@ -375,7 +375,7 @@ static inline unsigned long __ffs(unsigned long word)
15204 *
15205 * Undefined if no zero exists, so code should check against ~0UL first.
15206 */
15207-static inline unsigned long ffz(unsigned long word)
15208+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15209 {
15210 asm("rep; bsf %1,%0"
15211 : "=r" (word)
15212@@ -389,7 +389,7 @@ static inline unsigned long ffz(unsigned long word)
15213 *
15214 * Undefined if no set bit exists, so code should check against 0 first.
15215 */
15216-static inline unsigned long __fls(unsigned long word)
15217+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15218 {
15219 asm("bsr %1,%0"
15220 : "=r" (word)
15221@@ -452,7 +452,7 @@ static inline int ffs(int x)
15222 * set bit if value is nonzero. The last (most significant) bit is
15223 * at position 32.
15224 */
15225-static inline int fls(int x)
15226+static inline int __intentional_overflow(-1) fls(int x)
15227 {
15228 int r;
15229
15230@@ -494,7 +494,7 @@ static inline int fls(int x)
15231 * at position 64.
15232 */
15233 #ifdef CONFIG_X86_64
15234-static __always_inline int fls64(__u64 x)
15235+static __always_inline long fls64(__u64 x)
15236 {
15237 int bitpos = -1;
15238 /*
15239diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15240index 4fa687a..60f2d39 100644
15241--- a/arch/x86/include/asm/boot.h
15242+++ b/arch/x86/include/asm/boot.h
15243@@ -6,10 +6,15 @@
15244 #include <uapi/asm/boot.h>
15245
15246 /* Physical address where kernel should be loaded. */
15247-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15248+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15249 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15250 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15251
15252+#ifndef __ASSEMBLY__
15253+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15254+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15255+#endif
15256+
15257 /* Minimum kernel alignment, as a power of two */
15258 #ifdef CONFIG_X86_64
15259 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15260diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15261index 48f99f1..d78ebf9 100644
15262--- a/arch/x86/include/asm/cache.h
15263+++ b/arch/x86/include/asm/cache.h
15264@@ -5,12 +5,13 @@
15265
15266 /* L1 cache line size */
15267 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15268-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15269+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15270
15271 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15272+#define __read_only __attribute__((__section__(".data..read_only")))
15273
15274 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15275-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15276+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15277
15278 #ifdef CONFIG_X86_VSMP
15279 #ifdef CONFIG_SMP
15280diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15281index 9863ee3..4a1f8e1 100644
15282--- a/arch/x86/include/asm/cacheflush.h
15283+++ b/arch/x86/include/asm/cacheflush.h
15284@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15285 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15286
15287 if (pg_flags == _PGMT_DEFAULT)
15288- return -1;
15289+ return ~0UL;
15290 else if (pg_flags == _PGMT_WC)
15291 return _PAGE_CACHE_WC;
15292 else if (pg_flags == _PGMT_UC_MINUS)
15293diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15294index 0fa6750..cb7b2c3 100644
15295--- a/arch/x86/include/asm/calling.h
15296+++ b/arch/x86/include/asm/calling.h
15297@@ -80,103 +80,113 @@ For 32-bit we have the following conventions - kernel is built with
15298 #define RSP 152
15299 #define SS 160
15300
15301-#define ARGOFFSET R11
15302-#define SWFRAME ORIG_RAX
15303+#define ARGOFFSET R15
15304
15305 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15306- subq $9*8+\addskip, %rsp
15307- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15308- movq_cfi rdi, 8*8
15309- movq_cfi rsi, 7*8
15310- movq_cfi rdx, 6*8
15311+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15312+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15313+ movq_cfi rdi, RDI
15314+ movq_cfi rsi, RSI
15315+ movq_cfi rdx, RDX
15316
15317 .if \save_rcx
15318- movq_cfi rcx, 5*8
15319+ movq_cfi rcx, RCX
15320 .endif
15321
15322- movq_cfi rax, 4*8
15323+ movq_cfi rax, RAX
15324
15325 .if \save_r891011
15326- movq_cfi r8, 3*8
15327- movq_cfi r9, 2*8
15328- movq_cfi r10, 1*8
15329- movq_cfi r11, 0*8
15330+ movq_cfi r8, R8
15331+ movq_cfi r9, R9
15332+ movq_cfi r10, R10
15333+ movq_cfi r11, R11
15334 .endif
15335
15336+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15337+ movq_cfi r12, R12
15338+#endif
15339+
15340 .endm
15341
15342-#define ARG_SKIP (9*8)
15343+#define ARG_SKIP ORIG_RAX
15344
15345 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15346 rstor_r8910=1, rstor_rdx=1
15347+
15348+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15349+ movq_cfi_restore R12, r12
15350+#endif
15351+
15352 .if \rstor_r11
15353- movq_cfi_restore 0*8, r11
15354+ movq_cfi_restore R11, r11
15355 .endif
15356
15357 .if \rstor_r8910
15358- movq_cfi_restore 1*8, r10
15359- movq_cfi_restore 2*8, r9
15360- movq_cfi_restore 3*8, r8
15361+ movq_cfi_restore R10, r10
15362+ movq_cfi_restore R9, r9
15363+ movq_cfi_restore R8, r8
15364 .endif
15365
15366 .if \rstor_rax
15367- movq_cfi_restore 4*8, rax
15368+ movq_cfi_restore RAX, rax
15369 .endif
15370
15371 .if \rstor_rcx
15372- movq_cfi_restore 5*8, rcx
15373+ movq_cfi_restore RCX, rcx
15374 .endif
15375
15376 .if \rstor_rdx
15377- movq_cfi_restore 6*8, rdx
15378+ movq_cfi_restore RDX, rdx
15379 .endif
15380
15381- movq_cfi_restore 7*8, rsi
15382- movq_cfi_restore 8*8, rdi
15383+ movq_cfi_restore RSI, rsi
15384+ movq_cfi_restore RDI, rdi
15385
15386- .if ARG_SKIP+\addskip > 0
15387- addq $ARG_SKIP+\addskip, %rsp
15388- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15389+ .if ORIG_RAX+\addskip > 0
15390+ addq $ORIG_RAX+\addskip, %rsp
15391+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15392 .endif
15393 .endm
15394
15395- .macro LOAD_ARGS offset, skiprax=0
15396- movq \offset(%rsp), %r11
15397- movq \offset+8(%rsp), %r10
15398- movq \offset+16(%rsp), %r9
15399- movq \offset+24(%rsp), %r8
15400- movq \offset+40(%rsp), %rcx
15401- movq \offset+48(%rsp), %rdx
15402- movq \offset+56(%rsp), %rsi
15403- movq \offset+64(%rsp), %rdi
15404+ .macro LOAD_ARGS skiprax=0
15405+ movq R11(%rsp), %r11
15406+ movq R10(%rsp), %r10
15407+ movq R9(%rsp), %r9
15408+ movq R8(%rsp), %r8
15409+ movq RCX(%rsp), %rcx
15410+ movq RDX(%rsp), %rdx
15411+ movq RSI(%rsp), %rsi
15412+ movq RDI(%rsp), %rdi
15413 .if \skiprax
15414 .else
15415- movq \offset+72(%rsp), %rax
15416+ movq RAX(%rsp), %rax
15417 .endif
15418 .endm
15419
15420-#define REST_SKIP (6*8)
15421-
15422 .macro SAVE_REST
15423- subq $REST_SKIP, %rsp
15424- CFI_ADJUST_CFA_OFFSET REST_SKIP
15425- movq_cfi rbx, 5*8
15426- movq_cfi rbp, 4*8
15427- movq_cfi r12, 3*8
15428- movq_cfi r13, 2*8
15429- movq_cfi r14, 1*8
15430- movq_cfi r15, 0*8
15431+ movq_cfi rbx, RBX
15432+ movq_cfi rbp, RBP
15433+
15434+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15435+ movq_cfi r12, R12
15436+#endif
15437+
15438+ movq_cfi r13, R13
15439+ movq_cfi r14, R14
15440+ movq_cfi r15, R15
15441 .endm
15442
15443 .macro RESTORE_REST
15444- movq_cfi_restore 0*8, r15
15445- movq_cfi_restore 1*8, r14
15446- movq_cfi_restore 2*8, r13
15447- movq_cfi_restore 3*8, r12
15448- movq_cfi_restore 4*8, rbp
15449- movq_cfi_restore 5*8, rbx
15450- addq $REST_SKIP, %rsp
15451- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15452+ movq_cfi_restore R15, r15
15453+ movq_cfi_restore R14, r14
15454+ movq_cfi_restore R13, r13
15455+
15456+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15457+ movq_cfi_restore R12, r12
15458+#endif
15459+
15460+ movq_cfi_restore RBP, rbp
15461+ movq_cfi_restore RBX, rbx
15462 .endm
15463
15464 .macro SAVE_ALL
15465diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15466index f50de69..2b0a458 100644
15467--- a/arch/x86/include/asm/checksum_32.h
15468+++ b/arch/x86/include/asm/checksum_32.h
15469@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15470 int len, __wsum sum,
15471 int *src_err_ptr, int *dst_err_ptr);
15472
15473+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15474+ int len, __wsum sum,
15475+ int *src_err_ptr, int *dst_err_ptr);
15476+
15477+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15478+ int len, __wsum sum,
15479+ int *src_err_ptr, int *dst_err_ptr);
15480+
15481 /*
15482 * Note: when you get a NULL pointer exception here this means someone
15483 * passed in an incorrect kernel address to one of these functions.
15484@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15485
15486 might_sleep();
15487 stac();
15488- ret = csum_partial_copy_generic((__force void *)src, dst,
15489+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15490 len, sum, err_ptr, NULL);
15491 clac();
15492
15493@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15494 might_sleep();
15495 if (access_ok(VERIFY_WRITE, dst, len)) {
15496 stac();
15497- ret = csum_partial_copy_generic(src, (__force void *)dst,
15498+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15499 len, sum, NULL, err_ptr);
15500 clac();
15501 return ret;
15502diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15503index d47786a..ce1b05d 100644
15504--- a/arch/x86/include/asm/cmpxchg.h
15505+++ b/arch/x86/include/asm/cmpxchg.h
15506@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15507 __compiletime_error("Bad argument size for cmpxchg");
15508 extern void __xadd_wrong_size(void)
15509 __compiletime_error("Bad argument size for xadd");
15510+extern void __xadd_check_overflow_wrong_size(void)
15511+ __compiletime_error("Bad argument size for xadd_check_overflow");
15512 extern void __add_wrong_size(void)
15513 __compiletime_error("Bad argument size for add");
15514+extern void __add_check_overflow_wrong_size(void)
15515+ __compiletime_error("Bad argument size for add_check_overflow");
15516
15517 /*
15518 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15519@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15520 __ret; \
15521 })
15522
15523+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15524+ ({ \
15525+ __typeof__ (*(ptr)) __ret = (arg); \
15526+ switch (sizeof(*(ptr))) { \
15527+ case __X86_CASE_L: \
15528+ asm volatile (lock #op "l %0, %1\n" \
15529+ "jno 0f\n" \
15530+ "mov %0,%1\n" \
15531+ "int $4\n0:\n" \
15532+ _ASM_EXTABLE(0b, 0b) \
15533+ : "+r" (__ret), "+m" (*(ptr)) \
15534+ : : "memory", "cc"); \
15535+ break; \
15536+ case __X86_CASE_Q: \
15537+ asm volatile (lock #op "q %q0, %1\n" \
15538+ "jno 0f\n" \
15539+ "mov %0,%1\n" \
15540+ "int $4\n0:\n" \
15541+ _ASM_EXTABLE(0b, 0b) \
15542+ : "+r" (__ret), "+m" (*(ptr)) \
15543+ : : "memory", "cc"); \
15544+ break; \
15545+ default: \
15546+ __ ## op ## _check_overflow_wrong_size(); \
15547+ } \
15548+ __ret; \
15549+ })
15550+
15551 /*
15552 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15553 * Since this is generally used to protect other memory information, we
15554@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15555 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15556 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15557
15558+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15559+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15560+
15561 #define __add(ptr, inc, lock) \
15562 ({ \
15563 __typeof__ (*(ptr)) __ret = (inc); \
15564diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15565index 59c6c40..5e0b22c 100644
15566--- a/arch/x86/include/asm/compat.h
15567+++ b/arch/x86/include/asm/compat.h
15568@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15569 typedef u32 compat_uint_t;
15570 typedef u32 compat_ulong_t;
15571 typedef u64 __attribute__((aligned(4))) compat_u64;
15572-typedef u32 compat_uptr_t;
15573+typedef u32 __user compat_uptr_t;
15574
15575 struct compat_timespec {
15576 compat_time_t tv_sec;
15577diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15578index 89270b4..f0abf8e 100644
15579--- a/arch/x86/include/asm/cpufeature.h
15580+++ b/arch/x86/include/asm/cpufeature.h
15581@@ -203,7 +203,7 @@
15582 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15583 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15584 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15585-
15586+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15587
15588 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15589 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15590@@ -211,7 +211,7 @@
15591 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15592 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15593 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15594-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15595+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15596 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15597 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15598 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15599@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15600 #undef cpu_has_centaur_mcr
15601 #define cpu_has_centaur_mcr 0
15602
15603+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15604 #endif /* CONFIG_X86_64 */
15605
15606 #if __GNUC__ >= 4
15607@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15608
15609 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15610 t_warn:
15611- warn_pre_alternatives();
15612+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15613+ warn_pre_alternatives();
15614 return false;
15615 #endif
15616
15617@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15618 ".section .discard,\"aw\",@progbits\n"
15619 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15620 ".previous\n"
15621- ".section .altinstr_replacement,\"ax\"\n"
15622+ ".section .altinstr_replacement,\"a\"\n"
15623 "3: movb $1,%0\n"
15624 "4:\n"
15625 ".previous\n"
15626@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15627 " .byte 2b - 1b\n" /* src len */
15628 " .byte 4f - 3f\n" /* repl len */
15629 ".previous\n"
15630- ".section .altinstr_replacement,\"ax\"\n"
15631+ ".section .altinstr_replacement,\"a\"\n"
15632 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15633 "4:\n"
15634 ".previous\n"
15635@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15636 ".section .discard,\"aw\",@progbits\n"
15637 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15638 ".previous\n"
15639- ".section .altinstr_replacement,\"ax\"\n"
15640+ ".section .altinstr_replacement,\"a\"\n"
15641 "3: movb $0,%0\n"
15642 "4:\n"
15643 ".previous\n"
15644@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15645 ".section .discard,\"aw\",@progbits\n"
15646 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15647 ".previous\n"
15648- ".section .altinstr_replacement,\"ax\"\n"
15649+ ".section .altinstr_replacement,\"a\"\n"
15650 "5: movb $1,%0\n"
15651 "6:\n"
15652 ".previous\n"
15653diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15654index b90e5df..b462c91 100644
15655--- a/arch/x86/include/asm/desc.h
15656+++ b/arch/x86/include/asm/desc.h
15657@@ -4,6 +4,7 @@
15658 #include <asm/desc_defs.h>
15659 #include <asm/ldt.h>
15660 #include <asm/mmu.h>
15661+#include <asm/pgtable.h>
15662
15663 #include <linux/smp.h>
15664 #include <linux/percpu.h>
15665@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15666
15667 desc->type = (info->read_exec_only ^ 1) << 1;
15668 desc->type |= info->contents << 2;
15669+ desc->type |= info->seg_not_present ^ 1;
15670
15671 desc->s = 1;
15672 desc->dpl = 0x3;
15673@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15674 }
15675
15676 extern struct desc_ptr idt_descr;
15677-extern gate_desc idt_table[];
15678-extern struct desc_ptr debug_idt_descr;
15679-extern gate_desc debug_idt_table[];
15680-
15681-struct gdt_page {
15682- struct desc_struct gdt[GDT_ENTRIES];
15683-} __attribute__((aligned(PAGE_SIZE)));
15684-
15685-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15686+extern gate_desc idt_table[IDT_ENTRIES];
15687+extern const struct desc_ptr debug_idt_descr;
15688+extern gate_desc debug_idt_table[IDT_ENTRIES];
15689
15690+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15691 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15692 {
15693- return per_cpu(gdt_page, cpu).gdt;
15694+ return cpu_gdt_table[cpu];
15695 }
15696
15697 #ifdef CONFIG_X86_64
15698@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15699 unsigned long base, unsigned dpl, unsigned flags,
15700 unsigned short seg)
15701 {
15702- gate->a = (seg << 16) | (base & 0xffff);
15703- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15704+ gate->gate.offset_low = base;
15705+ gate->gate.seg = seg;
15706+ gate->gate.reserved = 0;
15707+ gate->gate.type = type;
15708+ gate->gate.s = 0;
15709+ gate->gate.dpl = dpl;
15710+ gate->gate.p = 1;
15711+ gate->gate.offset_high = base >> 16;
15712 }
15713
15714 #endif
15715@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15716
15717 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15718 {
15719+ pax_open_kernel();
15720 memcpy(&idt[entry], gate, sizeof(*gate));
15721+ pax_close_kernel();
15722 }
15723
15724 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15725 {
15726+ pax_open_kernel();
15727 memcpy(&ldt[entry], desc, 8);
15728+ pax_close_kernel();
15729 }
15730
15731 static inline void
15732@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15733 default: size = sizeof(*gdt); break;
15734 }
15735
15736+ pax_open_kernel();
15737 memcpy(&gdt[entry], desc, size);
15738+ pax_close_kernel();
15739 }
15740
15741 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15742@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15743
15744 static inline void native_load_tr_desc(void)
15745 {
15746+ pax_open_kernel();
15747 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15748+ pax_close_kernel();
15749 }
15750
15751 static inline void native_load_gdt(const struct desc_ptr *dtr)
15752@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15753 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15754 unsigned int i;
15755
15756+ pax_open_kernel();
15757 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15758 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15759+ pax_close_kernel();
15760 }
15761
15762 #define _LDT_empty(info) \
15763@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15764 preempt_enable();
15765 }
15766
15767-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15768+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15769 {
15770 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15771 }
15772@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15773 }
15774
15775 #ifdef CONFIG_X86_64
15776-static inline void set_nmi_gate(int gate, void *addr)
15777+static inline void set_nmi_gate(int gate, const void *addr)
15778 {
15779 gate_desc s;
15780
15781@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15782 #endif
15783
15784 #ifdef CONFIG_TRACING
15785-extern struct desc_ptr trace_idt_descr;
15786-extern gate_desc trace_idt_table[];
15787+extern const struct desc_ptr trace_idt_descr;
15788+extern gate_desc trace_idt_table[IDT_ENTRIES];
15789 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15790 {
15791 write_idt_entry(trace_idt_table, entry, gate);
15792@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15793 }
15794 #endif
15795
15796-static inline void _set_gate(int gate, unsigned type, void *addr,
15797+static inline void _set_gate(int gate, unsigned type, const void *addr,
15798 unsigned dpl, unsigned ist, unsigned seg)
15799 {
15800 gate_desc s;
15801@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15802 * Pentium F0 0F bugfix can have resulted in the mapped
15803 * IDT being write-protected.
15804 */
15805-static inline void set_intr_gate(unsigned int n, void *addr)
15806+static inline void set_intr_gate(unsigned int n, const void *addr)
15807 {
15808 BUG_ON((unsigned)n > 0xFF);
15809 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15810@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15811 /*
15812 * This routine sets up an interrupt gate at directory privilege level 3.
15813 */
15814-static inline void set_system_intr_gate(unsigned int n, void *addr)
15815+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15816 {
15817 BUG_ON((unsigned)n > 0xFF);
15818 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15819 }
15820
15821-static inline void set_system_trap_gate(unsigned int n, void *addr)
15822+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15823 {
15824 BUG_ON((unsigned)n > 0xFF);
15825 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15826 }
15827
15828-static inline void set_trap_gate(unsigned int n, void *addr)
15829+static inline void set_trap_gate(unsigned int n, const void *addr)
15830 {
15831 BUG_ON((unsigned)n > 0xFF);
15832 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15833@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15834 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15835 {
15836 BUG_ON((unsigned)n > 0xFF);
15837- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15838+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15839 }
15840
15841-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15842+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15843 {
15844 BUG_ON((unsigned)n > 0xFF);
15845 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15846 }
15847
15848-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15849+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15850 {
15851 BUG_ON((unsigned)n > 0xFF);
15852 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15853@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15854 else
15855 load_idt((const struct desc_ptr *)&idt_descr);
15856 }
15857+
15858+#ifdef CONFIG_X86_32
15859+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15860+{
15861+ struct desc_struct d;
15862+
15863+ if (likely(limit))
15864+ limit = (limit - 1UL) >> PAGE_SHIFT;
15865+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15866+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15867+}
15868+#endif
15869+
15870 #endif /* _ASM_X86_DESC_H */
15871diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15872index 278441f..b95a174 100644
15873--- a/arch/x86/include/asm/desc_defs.h
15874+++ b/arch/x86/include/asm/desc_defs.h
15875@@ -31,6 +31,12 @@ struct desc_struct {
15876 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15877 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15878 };
15879+ struct {
15880+ u16 offset_low;
15881+ u16 seg;
15882+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15883+ unsigned offset_high: 16;
15884+ } gate;
15885 };
15886 } __attribute__((packed));
15887
15888diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15889index ced283a..ffe04cc 100644
15890--- a/arch/x86/include/asm/div64.h
15891+++ b/arch/x86/include/asm/div64.h
15892@@ -39,7 +39,7 @@
15893 __mod; \
15894 })
15895
15896-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15897+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15898 {
15899 union {
15900 u64 v64;
15901diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15902index 9c999c1..3860cb8 100644
15903--- a/arch/x86/include/asm/elf.h
15904+++ b/arch/x86/include/asm/elf.h
15905@@ -243,7 +243,25 @@ extern int force_personality32;
15906 the loader. We need to make sure that it is out of the way of the program
15907 that it will "exec", and that there is sufficient room for the brk. */
15908
15909+#ifdef CONFIG_PAX_SEGMEXEC
15910+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15911+#else
15912 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15913+#endif
15914+
15915+#ifdef CONFIG_PAX_ASLR
15916+#ifdef CONFIG_X86_32
15917+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15918+
15919+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15920+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15921+#else
15922+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15923+
15924+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15925+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15926+#endif
15927+#endif
15928
15929 /* This yields a mask that user programs can use to figure out what
15930 instruction set this CPU supports. This could be done in user space,
15931@@ -296,16 +314,12 @@ do { \
15932
15933 #define ARCH_DLINFO \
15934 do { \
15935- if (vdso_enabled) \
15936- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15937- (unsigned long)current->mm->context.vdso); \
15938+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15939 } while (0)
15940
15941 #define ARCH_DLINFO_X32 \
15942 do { \
15943- if (vdso_enabled) \
15944- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15945- (unsigned long)current->mm->context.vdso); \
15946+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15947 } while (0)
15948
15949 #define AT_SYSINFO 32
15950@@ -320,7 +334,7 @@ else \
15951
15952 #endif /* !CONFIG_X86_32 */
15953
15954-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15955+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15956
15957 #define VDSO_ENTRY \
15958 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15959@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15960 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15961 #define compat_arch_setup_additional_pages syscall32_setup_pages
15962
15963-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15964-#define arch_randomize_brk arch_randomize_brk
15965-
15966 /*
15967 * True on X86_32 or when emulating IA32 on X86_64
15968 */
15969diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15970index 77a99ac..39ff7f5 100644
15971--- a/arch/x86/include/asm/emergency-restart.h
15972+++ b/arch/x86/include/asm/emergency-restart.h
15973@@ -1,6 +1,6 @@
15974 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15975 #define _ASM_X86_EMERGENCY_RESTART_H
15976
15977-extern void machine_emergency_restart(void);
15978+extern void machine_emergency_restart(void) __noreturn;
15979
15980 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15981diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15982index 4d0bda7..221da4d 100644
15983--- a/arch/x86/include/asm/fpu-internal.h
15984+++ b/arch/x86/include/asm/fpu-internal.h
15985@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15986 #define user_insn(insn, output, input...) \
15987 ({ \
15988 int err; \
15989+ pax_open_userland(); \
15990 asm volatile(ASM_STAC "\n" \
15991- "1:" #insn "\n\t" \
15992+ "1:" \
15993+ __copyuser_seg \
15994+ #insn "\n\t" \
15995 "2: " ASM_CLAC "\n" \
15996 ".section .fixup,\"ax\"\n" \
15997 "3: movl $-1,%[err]\n" \
15998@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15999 _ASM_EXTABLE(1b, 3b) \
16000 : [err] "=r" (err), output \
16001 : "0"(0), input); \
16002+ pax_close_userland(); \
16003 err; \
16004 })
16005
16006@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16007 "emms\n\t" /* clear stack tags */
16008 "fildl %P[addr]", /* set F?P to defined value */
16009 X86_FEATURE_FXSAVE_LEAK,
16010- [addr] "m" (tsk->thread.fpu.has_fpu));
16011+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16012
16013 return fpu_restore_checking(&tsk->thread.fpu);
16014 }
16015diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16016index be27ba1..04a8801 100644
16017--- a/arch/x86/include/asm/futex.h
16018+++ b/arch/x86/include/asm/futex.h
16019@@ -12,6 +12,7 @@
16020 #include <asm/smap.h>
16021
16022 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16023+ typecheck(u32 __user *, uaddr); \
16024 asm volatile("\t" ASM_STAC "\n" \
16025 "1:\t" insn "\n" \
16026 "2:\t" ASM_CLAC "\n" \
16027@@ -20,15 +21,16 @@
16028 "\tjmp\t2b\n" \
16029 "\t.previous\n" \
16030 _ASM_EXTABLE(1b, 3b) \
16031- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16032+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16033 : "i" (-EFAULT), "0" (oparg), "1" (0))
16034
16035 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16036+ typecheck(u32 __user *, uaddr); \
16037 asm volatile("\t" ASM_STAC "\n" \
16038 "1:\tmovl %2, %0\n" \
16039 "\tmovl\t%0, %3\n" \
16040 "\t" insn "\n" \
16041- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16042+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16043 "\tjnz\t1b\n" \
16044 "3:\t" ASM_CLAC "\n" \
16045 "\t.section .fixup,\"ax\"\n" \
16046@@ -38,7 +40,7 @@
16047 _ASM_EXTABLE(1b, 4b) \
16048 _ASM_EXTABLE(2b, 4b) \
16049 : "=&a" (oldval), "=&r" (ret), \
16050- "+m" (*uaddr), "=&r" (tem) \
16051+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16052 : "r" (oparg), "i" (-EFAULT), "1" (0))
16053
16054 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16055@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16056
16057 pagefault_disable();
16058
16059+ pax_open_userland();
16060 switch (op) {
16061 case FUTEX_OP_SET:
16062- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16063+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16064 break;
16065 case FUTEX_OP_ADD:
16066- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16067+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16068 uaddr, oparg);
16069 break;
16070 case FUTEX_OP_OR:
16071@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16072 default:
16073 ret = -ENOSYS;
16074 }
16075+ pax_close_userland();
16076
16077 pagefault_enable();
16078
16079@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16080 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16081 return -EFAULT;
16082
16083+ pax_open_userland();
16084 asm volatile("\t" ASM_STAC "\n"
16085- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16086+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16087 "2:\t" ASM_CLAC "\n"
16088 "\t.section .fixup, \"ax\"\n"
16089 "3:\tmov %3, %0\n"
16090 "\tjmp 2b\n"
16091 "\t.previous\n"
16092 _ASM_EXTABLE(1b, 3b)
16093- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16094+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16095 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16096 : "memory"
16097 );
16098+ pax_close_userland();
16099
16100 *uval = oldval;
16101 return ret;
16102diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16103index 92b3bae..3866449 100644
16104--- a/arch/x86/include/asm/hw_irq.h
16105+++ b/arch/x86/include/asm/hw_irq.h
16106@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16107 extern void enable_IO_APIC(void);
16108
16109 /* Statistics */
16110-extern atomic_t irq_err_count;
16111-extern atomic_t irq_mis_count;
16112+extern atomic_unchecked_t irq_err_count;
16113+extern atomic_unchecked_t irq_mis_count;
16114
16115 /* EISA */
16116 extern void eisa_set_level_irq(unsigned int irq);
16117diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16118index a203659..9889f1c 100644
16119--- a/arch/x86/include/asm/i8259.h
16120+++ b/arch/x86/include/asm/i8259.h
16121@@ -62,7 +62,7 @@ struct legacy_pic {
16122 void (*init)(int auto_eoi);
16123 int (*irq_pending)(unsigned int irq);
16124 void (*make_irq)(unsigned int irq);
16125-};
16126+} __do_const;
16127
16128 extern struct legacy_pic *legacy_pic;
16129 extern struct legacy_pic null_legacy_pic;
16130diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16131index 34f69cb..6d95446 100644
16132--- a/arch/x86/include/asm/io.h
16133+++ b/arch/x86/include/asm/io.h
16134@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16135 "m" (*(volatile type __force *)addr) barrier); }
16136
16137 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16138-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16139-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16140+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16141+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16142
16143 build_mmio_read(__readb, "b", unsigned char, "=q", )
16144-build_mmio_read(__readw, "w", unsigned short, "=r", )
16145-build_mmio_read(__readl, "l", unsigned int, "=r", )
16146+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16147+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16148
16149 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16150 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16151@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16152 return ioremap_nocache(offset, size);
16153 }
16154
16155-extern void iounmap(volatile void __iomem *addr);
16156+extern void iounmap(const volatile void __iomem *addr);
16157
16158 extern void set_iounmap_nonlazy(void);
16159
16160@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16161
16162 #include <linux/vmalloc.h>
16163
16164+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16165+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16166+{
16167+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16168+}
16169+
16170+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16171+{
16172+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16173+}
16174+
16175 /*
16176 * Convert a virtual cached pointer to an uncached pointer
16177 */
16178diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16179index bba3cf8..06bc8da 100644
16180--- a/arch/x86/include/asm/irqflags.h
16181+++ b/arch/x86/include/asm/irqflags.h
16182@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16183 sti; \
16184 sysexit
16185
16186+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16187+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16188+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16189+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16190+
16191 #else
16192 #define INTERRUPT_RETURN iret
16193 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16194diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16195index 9454c16..e4100e3 100644
16196--- a/arch/x86/include/asm/kprobes.h
16197+++ b/arch/x86/include/asm/kprobes.h
16198@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16199 #define RELATIVEJUMP_SIZE 5
16200 #define RELATIVECALL_OPCODE 0xe8
16201 #define RELATIVE_ADDR_SIZE 4
16202-#define MAX_STACK_SIZE 64
16203-#define MIN_STACK_SIZE(ADDR) \
16204- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16205- THREAD_SIZE - (unsigned long)(ADDR))) \
16206- ? (MAX_STACK_SIZE) \
16207- : (((unsigned long)current_thread_info()) + \
16208- THREAD_SIZE - (unsigned long)(ADDR)))
16209+#define MAX_STACK_SIZE 64UL
16210+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16211
16212 #define flush_insn_slot(p) do { } while (0)
16213
16214diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16215index 2d89e39..baee879 100644
16216--- a/arch/x86/include/asm/local.h
16217+++ b/arch/x86/include/asm/local.h
16218@@ -10,33 +10,97 @@ typedef struct {
16219 atomic_long_t a;
16220 } local_t;
16221
16222+typedef struct {
16223+ atomic_long_unchecked_t a;
16224+} local_unchecked_t;
16225+
16226 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16227
16228 #define local_read(l) atomic_long_read(&(l)->a)
16229+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16230 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16231+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16232
16233 static inline void local_inc(local_t *l)
16234 {
16235- asm volatile(_ASM_INC "%0"
16236+ asm volatile(_ASM_INC "%0\n"
16237+
16238+#ifdef CONFIG_PAX_REFCOUNT
16239+ "jno 0f\n"
16240+ _ASM_DEC "%0\n"
16241+ "int $4\n0:\n"
16242+ _ASM_EXTABLE(0b, 0b)
16243+#endif
16244+
16245+ : "+m" (l->a.counter));
16246+}
16247+
16248+static inline void local_inc_unchecked(local_unchecked_t *l)
16249+{
16250+ asm volatile(_ASM_INC "%0\n"
16251 : "+m" (l->a.counter));
16252 }
16253
16254 static inline void local_dec(local_t *l)
16255 {
16256- asm volatile(_ASM_DEC "%0"
16257+ asm volatile(_ASM_DEC "%0\n"
16258+
16259+#ifdef CONFIG_PAX_REFCOUNT
16260+ "jno 0f\n"
16261+ _ASM_INC "%0\n"
16262+ "int $4\n0:\n"
16263+ _ASM_EXTABLE(0b, 0b)
16264+#endif
16265+
16266+ : "+m" (l->a.counter));
16267+}
16268+
16269+static inline void local_dec_unchecked(local_unchecked_t *l)
16270+{
16271+ asm volatile(_ASM_DEC "%0\n"
16272 : "+m" (l->a.counter));
16273 }
16274
16275 static inline void local_add(long i, local_t *l)
16276 {
16277- asm volatile(_ASM_ADD "%1,%0"
16278+ asm volatile(_ASM_ADD "%1,%0\n"
16279+
16280+#ifdef CONFIG_PAX_REFCOUNT
16281+ "jno 0f\n"
16282+ _ASM_SUB "%1,%0\n"
16283+ "int $4\n0:\n"
16284+ _ASM_EXTABLE(0b, 0b)
16285+#endif
16286+
16287+ : "+m" (l->a.counter)
16288+ : "ir" (i));
16289+}
16290+
16291+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16292+{
16293+ asm volatile(_ASM_ADD "%1,%0\n"
16294 : "+m" (l->a.counter)
16295 : "ir" (i));
16296 }
16297
16298 static inline void local_sub(long i, local_t *l)
16299 {
16300- asm volatile(_ASM_SUB "%1,%0"
16301+ asm volatile(_ASM_SUB "%1,%0\n"
16302+
16303+#ifdef CONFIG_PAX_REFCOUNT
16304+ "jno 0f\n"
16305+ _ASM_ADD "%1,%0\n"
16306+ "int $4\n0:\n"
16307+ _ASM_EXTABLE(0b, 0b)
16308+#endif
16309+
16310+ : "+m" (l->a.counter)
16311+ : "ir" (i));
16312+}
16313+
16314+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16315+{
16316+ asm volatile(_ASM_SUB "%1,%0\n"
16317 : "+m" (l->a.counter)
16318 : "ir" (i));
16319 }
16320@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
16321 {
16322 unsigned char c;
16323
16324- asm volatile(_ASM_SUB "%2,%0; sete %1"
16325+ asm volatile(_ASM_SUB "%2,%0\n"
16326+
16327+#ifdef CONFIG_PAX_REFCOUNT
16328+ "jno 0f\n"
16329+ _ASM_ADD "%2,%0\n"
16330+ "int $4\n0:\n"
16331+ _ASM_EXTABLE(0b, 0b)
16332+#endif
16333+
16334+ "sete %1\n"
16335 : "+m" (l->a.counter), "=qm" (c)
16336 : "ir" (i) : "memory");
16337 return c;
16338@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
16339 {
16340 unsigned char c;
16341
16342- asm volatile(_ASM_DEC "%0; sete %1"
16343+ asm volatile(_ASM_DEC "%0\n"
16344+
16345+#ifdef CONFIG_PAX_REFCOUNT
16346+ "jno 0f\n"
16347+ _ASM_INC "%0\n"
16348+ "int $4\n0:\n"
16349+ _ASM_EXTABLE(0b, 0b)
16350+#endif
16351+
16352+ "sete %1\n"
16353 : "+m" (l->a.counter), "=qm" (c)
16354 : : "memory");
16355 return c != 0;
16356@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
16357 {
16358 unsigned char c;
16359
16360- asm volatile(_ASM_INC "%0; sete %1"
16361+ asm volatile(_ASM_INC "%0\n"
16362+
16363+#ifdef CONFIG_PAX_REFCOUNT
16364+ "jno 0f\n"
16365+ _ASM_DEC "%0\n"
16366+ "int $4\n0:\n"
16367+ _ASM_EXTABLE(0b, 0b)
16368+#endif
16369+
16370+ "sete %1\n"
16371 : "+m" (l->a.counter), "=qm" (c)
16372 : : "memory");
16373 return c != 0;
16374@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
16375 {
16376 unsigned char c;
16377
16378- asm volatile(_ASM_ADD "%2,%0; sets %1"
16379+ asm volatile(_ASM_ADD "%2,%0\n"
16380+
16381+#ifdef CONFIG_PAX_REFCOUNT
16382+ "jno 0f\n"
16383+ _ASM_SUB "%2,%0\n"
16384+ "int $4\n0:\n"
16385+ _ASM_EXTABLE(0b, 0b)
16386+#endif
16387+
16388+ "sets %1\n"
16389 : "+m" (l->a.counter), "=qm" (c)
16390 : "ir" (i) : "memory");
16391 return c;
16392@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
16393 static inline long local_add_return(long i, local_t *l)
16394 {
16395 long __i = i;
16396+ asm volatile(_ASM_XADD "%0, %1\n"
16397+
16398+#ifdef CONFIG_PAX_REFCOUNT
16399+ "jno 0f\n"
16400+ _ASM_MOV "%0,%1\n"
16401+ "int $4\n0:\n"
16402+ _ASM_EXTABLE(0b, 0b)
16403+#endif
16404+
16405+ : "+r" (i), "+m" (l->a.counter)
16406+ : : "memory");
16407+ return i + __i;
16408+}
16409+
16410+/**
16411+ * local_add_return_unchecked - add and return
16412+ * @i: integer value to add
16413+ * @l: pointer to type local_unchecked_t
16414+ *
16415+ * Atomically adds @i to @l and returns @i + @l
16416+ */
16417+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16418+{
16419+ long __i = i;
16420 asm volatile(_ASM_XADD "%0, %1;"
16421 : "+r" (i), "+m" (l->a.counter)
16422 : : "memory");
16423@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
16424
16425 #define local_cmpxchg(l, o, n) \
16426 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16427+#define local_cmpxchg_unchecked(l, o, n) \
16428+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16429 /* Always has a lock prefix */
16430 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16431
16432diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16433new file mode 100644
16434index 0000000..2bfd3ba
16435--- /dev/null
16436+++ b/arch/x86/include/asm/mman.h
16437@@ -0,0 +1,15 @@
16438+#ifndef _X86_MMAN_H
16439+#define _X86_MMAN_H
16440+
16441+#include <uapi/asm/mman.h>
16442+
16443+#ifdef __KERNEL__
16444+#ifndef __ASSEMBLY__
16445+#ifdef CONFIG_X86_32
16446+#define arch_mmap_check i386_mmap_check
16447+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16448+#endif
16449+#endif
16450+#endif
16451+
16452+#endif /* X86_MMAN_H */
16453diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16454index 5f55e69..e20bfb1 100644
16455--- a/arch/x86/include/asm/mmu.h
16456+++ b/arch/x86/include/asm/mmu.h
16457@@ -9,7 +9,7 @@
16458 * we put the segment information here.
16459 */
16460 typedef struct {
16461- void *ldt;
16462+ struct desc_struct *ldt;
16463 int size;
16464
16465 #ifdef CONFIG_X86_64
16466@@ -18,7 +18,19 @@ typedef struct {
16467 #endif
16468
16469 struct mutex lock;
16470- void *vdso;
16471+ unsigned long vdso;
16472+
16473+#ifdef CONFIG_X86_32
16474+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16475+ unsigned long user_cs_base;
16476+ unsigned long user_cs_limit;
16477+
16478+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16479+ cpumask_t cpu_user_cs_mask;
16480+#endif
16481+
16482+#endif
16483+#endif
16484 } mm_context_t;
16485
16486 #ifdef CONFIG_SMP
16487diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16488index be12c53..4d24039 100644
16489--- a/arch/x86/include/asm/mmu_context.h
16490+++ b/arch/x86/include/asm/mmu_context.h
16491@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16492
16493 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16494 {
16495+
16496+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16497+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16498+ unsigned int i;
16499+ pgd_t *pgd;
16500+
16501+ pax_open_kernel();
16502+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16503+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16504+ set_pgd_batched(pgd+i, native_make_pgd(0));
16505+ pax_close_kernel();
16506+ }
16507+#endif
16508+
16509 #ifdef CONFIG_SMP
16510 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16511 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16512@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16513 struct task_struct *tsk)
16514 {
16515 unsigned cpu = smp_processor_id();
16516+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16517+ int tlbstate = TLBSTATE_OK;
16518+#endif
16519
16520 if (likely(prev != next)) {
16521 #ifdef CONFIG_SMP
16522+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16523+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16524+#endif
16525 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16526 this_cpu_write(cpu_tlbstate.active_mm, next);
16527 #endif
16528 cpumask_set_cpu(cpu, mm_cpumask(next));
16529
16530 /* Re-load page tables */
16531+#ifdef CONFIG_PAX_PER_CPU_PGD
16532+ pax_open_kernel();
16533+
16534+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16535+ if (static_cpu_has(X86_FEATURE_PCID))
16536+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16537+ else
16538+#endif
16539+
16540+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16541+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16542+ pax_close_kernel();
16543+ 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));
16544+
16545+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16546+ if (static_cpu_has(X86_FEATURE_PCID)) {
16547+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16548+ u64 descriptor[2];
16549+ descriptor[0] = PCID_USER;
16550+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16551+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16552+ descriptor[0] = PCID_KERNEL;
16553+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16554+ }
16555+ } else {
16556+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16557+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16558+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16559+ else
16560+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16561+ }
16562+ } else
16563+#endif
16564+
16565+ load_cr3(get_cpu_pgd(cpu, kernel));
16566+#else
16567 load_cr3(next->pgd);
16568+#endif
16569
16570 /* Stop flush ipis for the previous mm */
16571 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16572@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16573 /* Load the LDT, if the LDT is different: */
16574 if (unlikely(prev->context.ldt != next->context.ldt))
16575 load_LDT_nolock(&next->context);
16576+
16577+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16578+ if (!(__supported_pte_mask & _PAGE_NX)) {
16579+ smp_mb__before_clear_bit();
16580+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16581+ smp_mb__after_clear_bit();
16582+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16583+ }
16584+#endif
16585+
16586+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16587+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16588+ prev->context.user_cs_limit != next->context.user_cs_limit))
16589+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16590+#ifdef CONFIG_SMP
16591+ else if (unlikely(tlbstate != TLBSTATE_OK))
16592+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16593+#endif
16594+#endif
16595+
16596 }
16597+ else {
16598+
16599+#ifdef CONFIG_PAX_PER_CPU_PGD
16600+ pax_open_kernel();
16601+
16602+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16603+ if (static_cpu_has(X86_FEATURE_PCID))
16604+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16605+ else
16606+#endif
16607+
16608+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16609+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16610+ pax_close_kernel();
16611+ 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));
16612+
16613+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16614+ if (static_cpu_has(X86_FEATURE_PCID)) {
16615+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16616+ u64 descriptor[2];
16617+ descriptor[0] = PCID_USER;
16618+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16619+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16620+ descriptor[0] = PCID_KERNEL;
16621+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16622+ }
16623+ } else {
16624+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16625+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16626+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16627+ else
16628+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16629+ }
16630+ } else
16631+#endif
16632+
16633+ load_cr3(get_cpu_pgd(cpu, kernel));
16634+#endif
16635+
16636 #ifdef CONFIG_SMP
16637- else {
16638 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16639 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16640
16641@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16642 * tlb flush IPI delivery. We must reload CR3
16643 * to make sure to use no freed page tables.
16644 */
16645+
16646+#ifndef CONFIG_PAX_PER_CPU_PGD
16647 load_cr3(next->pgd);
16648+#endif
16649+
16650 load_LDT_nolock(&next->context);
16651+
16652+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16653+ if (!(__supported_pte_mask & _PAGE_NX))
16654+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16655+#endif
16656+
16657+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16658+#ifdef CONFIG_PAX_PAGEEXEC
16659+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16660+#endif
16661+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16662+#endif
16663+
16664 }
16665+#endif
16666 }
16667-#endif
16668 }
16669
16670 #define activate_mm(prev, next) \
16671diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16672index e3b7819..b257c64 100644
16673--- a/arch/x86/include/asm/module.h
16674+++ b/arch/x86/include/asm/module.h
16675@@ -5,6 +5,7 @@
16676
16677 #ifdef CONFIG_X86_64
16678 /* X86_64 does not define MODULE_PROC_FAMILY */
16679+#define MODULE_PROC_FAMILY ""
16680 #elif defined CONFIG_M486
16681 #define MODULE_PROC_FAMILY "486 "
16682 #elif defined CONFIG_M586
16683@@ -57,8 +58,20 @@
16684 #error unknown processor family
16685 #endif
16686
16687-#ifdef CONFIG_X86_32
16688-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16689+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16690+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16691+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16692+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16693+#else
16694+#define MODULE_PAX_KERNEXEC ""
16695 #endif
16696
16697+#ifdef CONFIG_PAX_MEMORY_UDEREF
16698+#define MODULE_PAX_UDEREF "UDEREF "
16699+#else
16700+#define MODULE_PAX_UDEREF ""
16701+#endif
16702+
16703+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16704+
16705 #endif /* _ASM_X86_MODULE_H */
16706diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16707index 86f9301..b365cda 100644
16708--- a/arch/x86/include/asm/nmi.h
16709+++ b/arch/x86/include/asm/nmi.h
16710@@ -40,11 +40,11 @@ struct nmiaction {
16711 nmi_handler_t handler;
16712 unsigned long flags;
16713 const char *name;
16714-};
16715+} __do_const;
16716
16717 #define register_nmi_handler(t, fn, fg, n, init...) \
16718 ({ \
16719- static struct nmiaction init fn##_na = { \
16720+ static const struct nmiaction init fn##_na = { \
16721 .handler = (fn), \
16722 .name = (n), \
16723 .flags = (fg), \
16724@@ -52,7 +52,7 @@ struct nmiaction {
16725 __register_nmi_handler((t), &fn##_na); \
16726 })
16727
16728-int __register_nmi_handler(unsigned int, struct nmiaction *);
16729+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16730
16731 void unregister_nmi_handler(unsigned int, const char *);
16732
16733diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16734index c878924..21f4889 100644
16735--- a/arch/x86/include/asm/page.h
16736+++ b/arch/x86/include/asm/page.h
16737@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16738 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16739
16740 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16741+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16742
16743 #define __boot_va(x) __va(x)
16744 #define __boot_pa(x) __pa(x)
16745diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16746index 0f1ddee..e2fc3d1 100644
16747--- a/arch/x86/include/asm/page_64.h
16748+++ b/arch/x86/include/asm/page_64.h
16749@@ -7,9 +7,9 @@
16750
16751 /* duplicated to the one in bootmem.h */
16752 extern unsigned long max_pfn;
16753-extern unsigned long phys_base;
16754+extern const unsigned long phys_base;
16755
16756-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16757+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16758 {
16759 unsigned long y = x - __START_KERNEL_map;
16760
16761diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16762index 401f350..dee5d13 100644
16763--- a/arch/x86/include/asm/paravirt.h
16764+++ b/arch/x86/include/asm/paravirt.h
16765@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16766 return (pmd_t) { ret };
16767 }
16768
16769-static inline pmdval_t pmd_val(pmd_t pmd)
16770+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16771 {
16772 pmdval_t ret;
16773
16774@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16775 val);
16776 }
16777
16778+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16779+{
16780+ pgdval_t val = native_pgd_val(pgd);
16781+
16782+ if (sizeof(pgdval_t) > sizeof(long))
16783+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16784+ val, (u64)val >> 32);
16785+ else
16786+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16787+ val);
16788+}
16789+
16790 static inline void pgd_clear(pgd_t *pgdp)
16791 {
16792 set_pgd(pgdp, __pgd(0));
16793@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16794 pv_mmu_ops.set_fixmap(idx, phys, flags);
16795 }
16796
16797+#ifdef CONFIG_PAX_KERNEXEC
16798+static inline unsigned long pax_open_kernel(void)
16799+{
16800+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16801+}
16802+
16803+static inline unsigned long pax_close_kernel(void)
16804+{
16805+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16806+}
16807+#else
16808+static inline unsigned long pax_open_kernel(void) { return 0; }
16809+static inline unsigned long pax_close_kernel(void) { return 0; }
16810+#endif
16811+
16812 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16813
16814 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16815@@ -906,7 +933,7 @@ extern void default_banner(void);
16816
16817 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16818 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16819-#define PARA_INDIRECT(addr) *%cs:addr
16820+#define PARA_INDIRECT(addr) *%ss:addr
16821 #endif
16822
16823 #define INTERRUPT_RETURN \
16824@@ -981,6 +1008,21 @@ extern void default_banner(void);
16825 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16826 CLBR_NONE, \
16827 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16828+
16829+#define GET_CR0_INTO_RDI \
16830+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16831+ mov %rax,%rdi
16832+
16833+#define SET_RDI_INTO_CR0 \
16834+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16835+
16836+#define GET_CR3_INTO_RDI \
16837+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16838+ mov %rax,%rdi
16839+
16840+#define SET_RDI_INTO_CR3 \
16841+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16842+
16843 #endif /* CONFIG_X86_32 */
16844
16845 #endif /* __ASSEMBLY__ */
16846diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16847index aab8f67..2531748 100644
16848--- a/arch/x86/include/asm/paravirt_types.h
16849+++ b/arch/x86/include/asm/paravirt_types.h
16850@@ -84,7 +84,7 @@ struct pv_init_ops {
16851 */
16852 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16853 unsigned long addr, unsigned len);
16854-};
16855+} __no_const;
16856
16857
16858 struct pv_lazy_ops {
16859@@ -98,7 +98,7 @@ struct pv_time_ops {
16860 unsigned long long (*sched_clock)(void);
16861 unsigned long long (*steal_clock)(int cpu);
16862 unsigned long (*get_tsc_khz)(void);
16863-};
16864+} __no_const;
16865
16866 struct pv_cpu_ops {
16867 /* hooks for various privileged instructions */
16868@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16869
16870 void (*start_context_switch)(struct task_struct *prev);
16871 void (*end_context_switch)(struct task_struct *next);
16872-};
16873+} __no_const;
16874
16875 struct pv_irq_ops {
16876 /*
16877@@ -223,7 +223,7 @@ struct pv_apic_ops {
16878 unsigned long start_eip,
16879 unsigned long start_esp);
16880 #endif
16881-};
16882+} __no_const;
16883
16884 struct pv_mmu_ops {
16885 unsigned long (*read_cr2)(void);
16886@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16887 struct paravirt_callee_save make_pud;
16888
16889 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16890+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16891 #endif /* PAGETABLE_LEVELS == 4 */
16892 #endif /* PAGETABLE_LEVELS >= 3 */
16893
16894@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16895 an mfn. We can tell which is which from the index. */
16896 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16897 phys_addr_t phys, pgprot_t flags);
16898+
16899+#ifdef CONFIG_PAX_KERNEXEC
16900+ unsigned long (*pax_open_kernel)(void);
16901+ unsigned long (*pax_close_kernel)(void);
16902+#endif
16903+
16904 };
16905
16906 struct arch_spinlock;
16907diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16908index b4389a4..7024269 100644
16909--- a/arch/x86/include/asm/pgalloc.h
16910+++ b/arch/x86/include/asm/pgalloc.h
16911@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16912 pmd_t *pmd, pte_t *pte)
16913 {
16914 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16915+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16916+}
16917+
16918+static inline void pmd_populate_user(struct mm_struct *mm,
16919+ pmd_t *pmd, pte_t *pte)
16920+{
16921+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16922 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16923 }
16924
16925@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16926
16927 #ifdef CONFIG_X86_PAE
16928 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16929+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16930+{
16931+ pud_populate(mm, pudp, pmd);
16932+}
16933 #else /* !CONFIG_X86_PAE */
16934 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16935 {
16936 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16937 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16938 }
16939+
16940+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16941+{
16942+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16943+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16944+}
16945 #endif /* CONFIG_X86_PAE */
16946
16947 #if PAGETABLE_LEVELS > 3
16948@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16949 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16950 }
16951
16952+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16953+{
16954+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16955+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16956+}
16957+
16958 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16959 {
16960 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16961diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16962index 3bf2dd0..23d2a9f 100644
16963--- a/arch/x86/include/asm/pgtable-2level.h
16964+++ b/arch/x86/include/asm/pgtable-2level.h
16965@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16966
16967 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16968 {
16969+ pax_open_kernel();
16970 *pmdp = pmd;
16971+ pax_close_kernel();
16972 }
16973
16974 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16975diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16976index 81bb91b..9392125 100644
16977--- a/arch/x86/include/asm/pgtable-3level.h
16978+++ b/arch/x86/include/asm/pgtable-3level.h
16979@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16980
16981 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16982 {
16983+ pax_open_kernel();
16984 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16985+ pax_close_kernel();
16986 }
16987
16988 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16989 {
16990+ pax_open_kernel();
16991 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16992+ pax_close_kernel();
16993 }
16994
16995 /*
16996diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16997index 3d19994..732a48c 100644
16998--- a/arch/x86/include/asm/pgtable.h
16999+++ b/arch/x86/include/asm/pgtable.h
17000@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17001
17002 #ifndef __PAGETABLE_PUD_FOLDED
17003 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17004+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17005 #define pgd_clear(pgd) native_pgd_clear(pgd)
17006 #endif
17007
17008@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17009
17010 #define arch_end_context_switch(prev) do {} while(0)
17011
17012+#define pax_open_kernel() native_pax_open_kernel()
17013+#define pax_close_kernel() native_pax_close_kernel()
17014 #endif /* CONFIG_PARAVIRT */
17015
17016+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17017+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17018+
17019+#ifdef CONFIG_PAX_KERNEXEC
17020+static inline unsigned long native_pax_open_kernel(void)
17021+{
17022+ unsigned long cr0;
17023+
17024+ preempt_disable();
17025+ barrier();
17026+ cr0 = read_cr0() ^ X86_CR0_WP;
17027+ BUG_ON(cr0 & X86_CR0_WP);
17028+ write_cr0(cr0);
17029+ return cr0 ^ X86_CR0_WP;
17030+}
17031+
17032+static inline unsigned long native_pax_close_kernel(void)
17033+{
17034+ unsigned long cr0;
17035+
17036+ cr0 = read_cr0() ^ X86_CR0_WP;
17037+ BUG_ON(!(cr0 & X86_CR0_WP));
17038+ write_cr0(cr0);
17039+ barrier();
17040+ preempt_enable_no_resched();
17041+ return cr0 ^ X86_CR0_WP;
17042+}
17043+#else
17044+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17045+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17046+#endif
17047+
17048 /*
17049 * The following only work if pte_present() is true.
17050 * Undefined behaviour if not..
17051 */
17052+static inline int pte_user(pte_t pte)
17053+{
17054+ return pte_val(pte) & _PAGE_USER;
17055+}
17056+
17057 static inline int pte_dirty(pte_t pte)
17058 {
17059 return pte_flags(pte) & _PAGE_DIRTY;
17060@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17061 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17062 }
17063
17064+static inline unsigned long pgd_pfn(pgd_t pgd)
17065+{
17066+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17067+}
17068+
17069 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17070
17071 static inline int pmd_large(pmd_t pte)
17072@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17073 return pte_clear_flags(pte, _PAGE_RW);
17074 }
17075
17076+static inline pte_t pte_mkread(pte_t pte)
17077+{
17078+ return __pte(pte_val(pte) | _PAGE_USER);
17079+}
17080+
17081 static inline pte_t pte_mkexec(pte_t pte)
17082 {
17083- return pte_clear_flags(pte, _PAGE_NX);
17084+#ifdef CONFIG_X86_PAE
17085+ if (__supported_pte_mask & _PAGE_NX)
17086+ return pte_clear_flags(pte, _PAGE_NX);
17087+ else
17088+#endif
17089+ return pte_set_flags(pte, _PAGE_USER);
17090+}
17091+
17092+static inline pte_t pte_exprotect(pte_t pte)
17093+{
17094+#ifdef CONFIG_X86_PAE
17095+ if (__supported_pte_mask & _PAGE_NX)
17096+ return pte_set_flags(pte, _PAGE_NX);
17097+ else
17098+#endif
17099+ return pte_clear_flags(pte, _PAGE_USER);
17100 }
17101
17102 static inline pte_t pte_mkdirty(pte_t pte)
17103@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17104 #endif
17105
17106 #ifndef __ASSEMBLY__
17107+
17108+#ifdef CONFIG_PAX_PER_CPU_PGD
17109+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17110+enum cpu_pgd_type {kernel = 0, user = 1};
17111+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17112+{
17113+ return cpu_pgd[cpu][type];
17114+}
17115+#endif
17116+
17117 #include <linux/mm_types.h>
17118 #include <linux/mmdebug.h>
17119 #include <linux/log2.h>
17120@@ -563,7 +638,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17121 * Currently stuck as a macro due to indirect forward reference to
17122 * linux/mmzone.h's __section_mem_map_addr() definition:
17123 */
17124-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17125+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17126
17127 /* Find an entry in the second-level page table.. */
17128 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17129@@ -603,7 +678,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17130 * Currently stuck as a macro due to indirect forward reference to
17131 * linux/mmzone.h's __section_mem_map_addr() definition:
17132 */
17133-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17134+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17135
17136 /* to find an entry in a page-table-directory. */
17137 static inline unsigned long pud_index(unsigned long address)
17138@@ -618,7 +693,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17139
17140 static inline int pgd_bad(pgd_t pgd)
17141 {
17142- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17143+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17144 }
17145
17146 static inline int pgd_none(pgd_t pgd)
17147@@ -641,7 +716,12 @@ static inline int pgd_none(pgd_t pgd)
17148 * pgd_offset() returns a (pgd_t *)
17149 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17150 */
17151-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17152+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17153+
17154+#ifdef CONFIG_PAX_PER_CPU_PGD
17155+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17156+#endif
17157+
17158 /*
17159 * a shortcut which implies the use of the kernel's pgd, instead
17160 * of a process's
17161@@ -652,6 +732,23 @@ static inline int pgd_none(pgd_t pgd)
17162 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17163 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17164
17165+#ifdef CONFIG_X86_32
17166+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17167+#else
17168+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17169+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17170+
17171+#ifdef CONFIG_PAX_MEMORY_UDEREF
17172+#ifdef __ASSEMBLY__
17173+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17174+#else
17175+extern unsigned long pax_user_shadow_base;
17176+extern pgdval_t clone_pgd_mask;
17177+#endif
17178+#endif
17179+
17180+#endif
17181+
17182 #ifndef __ASSEMBLY__
17183
17184 extern int direct_gbpages;
17185@@ -818,11 +915,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17186 * dst and src can be on the same page, but the range must not overlap,
17187 * and must not cross a page boundary.
17188 */
17189-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17190+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17191 {
17192- memcpy(dst, src, count * sizeof(pgd_t));
17193+ pax_open_kernel();
17194+ while (count--)
17195+ *dst++ = *src++;
17196+ pax_close_kernel();
17197 }
17198
17199+#ifdef CONFIG_PAX_PER_CPU_PGD
17200+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17201+#endif
17202+
17203+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17204+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17205+#else
17206+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17207+#endif
17208+
17209 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17210 static inline int page_level_shift(enum pg_level level)
17211 {
17212diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17213index 9ee3221..b979c6b 100644
17214--- a/arch/x86/include/asm/pgtable_32.h
17215+++ b/arch/x86/include/asm/pgtable_32.h
17216@@ -25,9 +25,6 @@
17217 struct mm_struct;
17218 struct vm_area_struct;
17219
17220-extern pgd_t swapper_pg_dir[1024];
17221-extern pgd_t initial_page_table[1024];
17222-
17223 static inline void pgtable_cache_init(void) { }
17224 static inline void check_pgt_cache(void) { }
17225 void paging_init(void);
17226@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17227 # include <asm/pgtable-2level.h>
17228 #endif
17229
17230+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17231+extern pgd_t initial_page_table[PTRS_PER_PGD];
17232+#ifdef CONFIG_X86_PAE
17233+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17234+#endif
17235+
17236 #if defined(CONFIG_HIGHPTE)
17237 #define pte_offset_map(dir, address) \
17238 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17239@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17240 /* Clear a kernel PTE and flush it from the TLB */
17241 #define kpte_clear_flush(ptep, vaddr) \
17242 do { \
17243+ pax_open_kernel(); \
17244 pte_clear(&init_mm, (vaddr), (ptep)); \
17245+ pax_close_kernel(); \
17246 __flush_tlb_one((vaddr)); \
17247 } while (0)
17248
17249 #endif /* !__ASSEMBLY__ */
17250
17251+#define HAVE_ARCH_UNMAPPED_AREA
17252+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17253+
17254 /*
17255 * kern_addr_valid() is (1) for FLATMEM and (0) for
17256 * SPARSEMEM and DISCONTIGMEM
17257diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17258index ed5903b..c7fe163 100644
17259--- a/arch/x86/include/asm/pgtable_32_types.h
17260+++ b/arch/x86/include/asm/pgtable_32_types.h
17261@@ -8,7 +8,7 @@
17262 */
17263 #ifdef CONFIG_X86_PAE
17264 # include <asm/pgtable-3level_types.h>
17265-# define PMD_SIZE (1UL << PMD_SHIFT)
17266+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17267 # define PMD_MASK (~(PMD_SIZE - 1))
17268 #else
17269 # include <asm/pgtable-2level_types.h>
17270@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17271 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17272 #endif
17273
17274+#ifdef CONFIG_PAX_KERNEXEC
17275+#ifndef __ASSEMBLY__
17276+extern unsigned char MODULES_EXEC_VADDR[];
17277+extern unsigned char MODULES_EXEC_END[];
17278+#endif
17279+#include <asm/boot.h>
17280+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17281+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17282+#else
17283+#define ktla_ktva(addr) (addr)
17284+#define ktva_ktla(addr) (addr)
17285+#endif
17286+
17287 #define MODULES_VADDR VMALLOC_START
17288 #define MODULES_END VMALLOC_END
17289 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17290diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17291index e22c1db..23a625a 100644
17292--- a/arch/x86/include/asm/pgtable_64.h
17293+++ b/arch/x86/include/asm/pgtable_64.h
17294@@ -16,10 +16,14 @@
17295
17296 extern pud_t level3_kernel_pgt[512];
17297 extern pud_t level3_ident_pgt[512];
17298+extern pud_t level3_vmalloc_start_pgt[512];
17299+extern pud_t level3_vmalloc_end_pgt[512];
17300+extern pud_t level3_vmemmap_pgt[512];
17301+extern pud_t level2_vmemmap_pgt[512];
17302 extern pmd_t level2_kernel_pgt[512];
17303 extern pmd_t level2_fixmap_pgt[512];
17304-extern pmd_t level2_ident_pgt[512];
17305-extern pgd_t init_level4_pgt[];
17306+extern pmd_t level2_ident_pgt[512*2];
17307+extern pgd_t init_level4_pgt[512];
17308
17309 #define swapper_pg_dir init_level4_pgt
17310
17311@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17312
17313 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17314 {
17315+ pax_open_kernel();
17316 *pmdp = pmd;
17317+ pax_close_kernel();
17318 }
17319
17320 static inline void native_pmd_clear(pmd_t *pmd)
17321@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17322
17323 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17324 {
17325+ pax_open_kernel();
17326 *pudp = pud;
17327+ pax_close_kernel();
17328 }
17329
17330 static inline void native_pud_clear(pud_t *pud)
17331@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17332
17333 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17334 {
17335+ pax_open_kernel();
17336+ *pgdp = pgd;
17337+ pax_close_kernel();
17338+}
17339+
17340+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17341+{
17342 *pgdp = pgd;
17343 }
17344
17345diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17346index 2d88344..4679fc3 100644
17347--- a/arch/x86/include/asm/pgtable_64_types.h
17348+++ b/arch/x86/include/asm/pgtable_64_types.h
17349@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17350 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17351 #define MODULES_END _AC(0xffffffffff000000, UL)
17352 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17353+#define MODULES_EXEC_VADDR MODULES_VADDR
17354+#define MODULES_EXEC_END MODULES_END
17355+
17356+#define ktla_ktva(addr) (addr)
17357+#define ktva_ktla(addr) (addr)
17358
17359 #define EARLY_DYNAMIC_PAGE_TABLES 64
17360
17361diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17362index 0ecac25..306c276 100644
17363--- a/arch/x86/include/asm/pgtable_types.h
17364+++ b/arch/x86/include/asm/pgtable_types.h
17365@@ -16,13 +16,12 @@
17366 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17367 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17368 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17369-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17370+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17371 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17372 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17373 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17374-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17375-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17376-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17377+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17378+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17379 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17380
17381 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17382@@ -40,7 +39,6 @@
17383 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17384 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17385 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17386-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17387 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17388 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17389 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17390@@ -87,8 +85,10 @@
17391
17392 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17393 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17394-#else
17395+#elif defined(CONFIG_KMEMCHECK)
17396 #define _PAGE_NX (_AT(pteval_t, 0))
17397+#else
17398+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17399 #endif
17400
17401 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17402@@ -146,6 +146,9 @@
17403 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17404 _PAGE_ACCESSED)
17405
17406+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17407+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17408+
17409 #define __PAGE_KERNEL_EXEC \
17410 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17411 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17412@@ -156,7 +159,7 @@
17413 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17414 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17415 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17416-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17417+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17418 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17419 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17420 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17421@@ -218,8 +221,8 @@
17422 * bits are combined, this will alow user to access the high address mapped
17423 * VDSO in the presence of CONFIG_COMPAT_VDSO
17424 */
17425-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17426-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17427+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17428+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17429 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17430 #endif
17431
17432@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17433 {
17434 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17435 }
17436+#endif
17437
17438+#if PAGETABLE_LEVELS == 3
17439+#include <asm-generic/pgtable-nopud.h>
17440+#endif
17441+
17442+#if PAGETABLE_LEVELS == 2
17443+#include <asm-generic/pgtable-nopmd.h>
17444+#endif
17445+
17446+#ifndef __ASSEMBLY__
17447 #if PAGETABLE_LEVELS > 3
17448 typedef struct { pudval_t pud; } pud_t;
17449
17450@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17451 return pud.pud;
17452 }
17453 #else
17454-#include <asm-generic/pgtable-nopud.h>
17455-
17456 static inline pudval_t native_pud_val(pud_t pud)
17457 {
17458 return native_pgd_val(pud.pgd);
17459@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17460 return pmd.pmd;
17461 }
17462 #else
17463-#include <asm-generic/pgtable-nopmd.h>
17464-
17465 static inline pmdval_t native_pmd_val(pmd_t pmd)
17466 {
17467 return native_pgd_val(pmd.pud.pgd);
17468@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17469
17470 extern pteval_t __supported_pte_mask;
17471 extern void set_nx(void);
17472-extern int nx_enabled;
17473
17474 #define pgprot_writecombine pgprot_writecombine
17475 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17476diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17477index 987c75e..2723054 100644
17478--- a/arch/x86/include/asm/processor.h
17479+++ b/arch/x86/include/asm/processor.h
17480@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17481 : "memory");
17482 }
17483
17484+/* invpcid (%rdx),%rax */
17485+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17486+
17487+#define INVPCID_SINGLE_ADDRESS 0UL
17488+#define INVPCID_SINGLE_CONTEXT 1UL
17489+#define INVPCID_ALL_GLOBAL 2UL
17490+#define INVPCID_ALL_MONGLOBAL 3UL
17491+
17492+#define PCID_KERNEL 0UL
17493+#define PCID_USER 1UL
17494+#define PCID_NOFLUSH (1UL << 63)
17495+
17496 static inline void load_cr3(pgd_t *pgdir)
17497 {
17498- write_cr3(__pa(pgdir));
17499+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17500 }
17501
17502 #ifdef CONFIG_X86_32
17503@@ -283,7 +295,7 @@ struct tss_struct {
17504
17505 } ____cacheline_aligned;
17506
17507-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17508+extern struct tss_struct init_tss[NR_CPUS];
17509
17510 /*
17511 * Save the original ist values for checking stack pointers during debugging
17512@@ -453,6 +465,7 @@ struct thread_struct {
17513 unsigned short ds;
17514 unsigned short fsindex;
17515 unsigned short gsindex;
17516+ unsigned short ss;
17517 #endif
17518 #ifdef CONFIG_X86_32
17519 unsigned long ip;
17520@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
17521 extern unsigned long mmu_cr4_features;
17522 extern u32 *trampoline_cr4_features;
17523
17524-static inline void set_in_cr4(unsigned long mask)
17525-{
17526- unsigned long cr4;
17527-
17528- mmu_cr4_features |= mask;
17529- if (trampoline_cr4_features)
17530- *trampoline_cr4_features = mmu_cr4_features;
17531- cr4 = read_cr4();
17532- cr4 |= mask;
17533- write_cr4(cr4);
17534-}
17535-
17536-static inline void clear_in_cr4(unsigned long mask)
17537-{
17538- unsigned long cr4;
17539-
17540- mmu_cr4_features &= ~mask;
17541- if (trampoline_cr4_features)
17542- *trampoline_cr4_features = mmu_cr4_features;
17543- cr4 = read_cr4();
17544- cr4 &= ~mask;
17545- write_cr4(cr4);
17546-}
17547+extern void set_in_cr4(unsigned long mask);
17548+extern void clear_in_cr4(unsigned long mask);
17549
17550 typedef struct {
17551 unsigned long seg;
17552@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
17553 */
17554 #define TASK_SIZE PAGE_OFFSET
17555 #define TASK_SIZE_MAX TASK_SIZE
17556+
17557+#ifdef CONFIG_PAX_SEGMEXEC
17558+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17559+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17560+#else
17561 #define STACK_TOP TASK_SIZE
17562-#define STACK_TOP_MAX STACK_TOP
17563+#endif
17564+
17565+#define STACK_TOP_MAX TASK_SIZE
17566
17567 #define INIT_THREAD { \
17568- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17569+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17570 .vm86_info = NULL, \
17571 .sysenter_cs = __KERNEL_CS, \
17572 .io_bitmap_ptr = NULL, \
17573@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
17574 */
17575 #define INIT_TSS { \
17576 .x86_tss = { \
17577- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17578+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17579 .ss0 = __KERNEL_DS, \
17580 .ss1 = __KERNEL_CS, \
17581 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17582@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
17583 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17584
17585 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17586-#define KSTK_TOP(info) \
17587-({ \
17588- unsigned long *__ptr = (unsigned long *)(info); \
17589- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17590-})
17591+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17592
17593 /*
17594 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17595@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17596 #define task_pt_regs(task) \
17597 ({ \
17598 struct pt_regs *__regs__; \
17599- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17600+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17601 __regs__ - 1; \
17602 })
17603
17604@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17605 /*
17606 * User space process size. 47bits minus one guard page.
17607 */
17608-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17609+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17610
17611 /* This decides where the kernel will search for a free chunk of vm
17612 * space during mmap's.
17613 */
17614 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17615- 0xc0000000 : 0xFFFFe000)
17616+ 0xc0000000 : 0xFFFFf000)
17617
17618 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17619 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17620@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17621 #define STACK_TOP_MAX TASK_SIZE_MAX
17622
17623 #define INIT_THREAD { \
17624- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17625+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17626 }
17627
17628 #define INIT_TSS { \
17629- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17630+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17631 }
17632
17633 /*
17634@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17635 */
17636 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17637
17638+#ifdef CONFIG_PAX_SEGMEXEC
17639+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17640+#endif
17641+
17642 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17643
17644 /* Get/set a process' ability to use the timestamp counter instruction */
17645@@ -957,7 +956,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17646 return 0;
17647 }
17648
17649-extern unsigned long arch_align_stack(unsigned long sp);
17650+#define arch_align_stack(x) ((x) & ~0xfUL)
17651 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17652
17653 void default_idle(void);
17654@@ -967,6 +966,6 @@ bool xen_set_default_idle(void);
17655 #define xen_set_default_idle 0
17656 #endif
17657
17658-void stop_this_cpu(void *dummy);
17659+void stop_this_cpu(void *dummy) __noreturn;
17660 void df_debug(struct pt_regs *regs, long error_code);
17661 #endif /* _ASM_X86_PROCESSOR_H */
17662diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17663index 942a086..6c26446 100644
17664--- a/arch/x86/include/asm/ptrace.h
17665+++ b/arch/x86/include/asm/ptrace.h
17666@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17667 }
17668
17669 /*
17670- * user_mode_vm(regs) determines whether a register set came from user mode.
17671+ * user_mode(regs) determines whether a register set came from user mode.
17672 * This is true if V8086 mode was enabled OR if the register set was from
17673 * protected mode with RPL-3 CS value. This tricky test checks that with
17674 * one comparison. Many places in the kernel can bypass this full check
17675- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17676+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17677+ * be used.
17678 */
17679-static inline int user_mode(struct pt_regs *regs)
17680+static inline int user_mode_novm(struct pt_regs *regs)
17681 {
17682 #ifdef CONFIG_X86_32
17683 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17684 #else
17685- return !!(regs->cs & 3);
17686+ return !!(regs->cs & SEGMENT_RPL_MASK);
17687 #endif
17688 }
17689
17690-static inline int user_mode_vm(struct pt_regs *regs)
17691+static inline int user_mode(struct pt_regs *regs)
17692 {
17693 #ifdef CONFIG_X86_32
17694 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17695 USER_RPL;
17696 #else
17697- return user_mode(regs);
17698+ return user_mode_novm(regs);
17699 #endif
17700 }
17701
17702@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17703 #ifdef CONFIG_X86_64
17704 static inline bool user_64bit_mode(struct pt_regs *regs)
17705 {
17706+ unsigned long cs = regs->cs & 0xffff;
17707 #ifndef CONFIG_PARAVIRT
17708 /*
17709 * On non-paravirt systems, this is the only long mode CPL 3
17710 * selector. We do not allow long mode selectors in the LDT.
17711 */
17712- return regs->cs == __USER_CS;
17713+ return cs == __USER_CS;
17714 #else
17715 /* Headers are too twisted for this to go in paravirt.h. */
17716- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17717+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17718 #endif
17719 }
17720
17721@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17722 * Traps from the kernel do not save sp and ss.
17723 * Use the helper function to retrieve sp.
17724 */
17725- if (offset == offsetof(struct pt_regs, sp) &&
17726- regs->cs == __KERNEL_CS)
17727- return kernel_stack_pointer(regs);
17728+ if (offset == offsetof(struct pt_regs, sp)) {
17729+ unsigned long cs = regs->cs & 0xffff;
17730+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17731+ return kernel_stack_pointer(regs);
17732+ }
17733 #endif
17734 return *(unsigned long *)((unsigned long)regs + offset);
17735 }
17736diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17737index 9c6b890..5305f53 100644
17738--- a/arch/x86/include/asm/realmode.h
17739+++ b/arch/x86/include/asm/realmode.h
17740@@ -22,16 +22,14 @@ struct real_mode_header {
17741 #endif
17742 /* APM/BIOS reboot */
17743 u32 machine_real_restart_asm;
17744-#ifdef CONFIG_X86_64
17745 u32 machine_real_restart_seg;
17746-#endif
17747 };
17748
17749 /* This must match data at trampoline_32/64.S */
17750 struct trampoline_header {
17751 #ifdef CONFIG_X86_32
17752 u32 start;
17753- u16 gdt_pad;
17754+ u16 boot_cs;
17755 u16 gdt_limit;
17756 u32 gdt_base;
17757 #else
17758diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17759index a82c4f1..ac45053 100644
17760--- a/arch/x86/include/asm/reboot.h
17761+++ b/arch/x86/include/asm/reboot.h
17762@@ -6,13 +6,13 @@
17763 struct pt_regs;
17764
17765 struct machine_ops {
17766- void (*restart)(char *cmd);
17767- void (*halt)(void);
17768- void (*power_off)(void);
17769+ void (* __noreturn restart)(char *cmd);
17770+ void (* __noreturn halt)(void);
17771+ void (* __noreturn power_off)(void);
17772 void (*shutdown)(void);
17773 void (*crash_shutdown)(struct pt_regs *);
17774- void (*emergency_restart)(void);
17775-};
17776+ void (* __noreturn emergency_restart)(void);
17777+} __no_const;
17778
17779 extern struct machine_ops machine_ops;
17780
17781diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17782index cad82c9..2e5c5c1 100644
17783--- a/arch/x86/include/asm/rwsem.h
17784+++ b/arch/x86/include/asm/rwsem.h
17785@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17786 {
17787 asm volatile("# beginning down_read\n\t"
17788 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17789+
17790+#ifdef CONFIG_PAX_REFCOUNT
17791+ "jno 0f\n"
17792+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17793+ "int $4\n0:\n"
17794+ _ASM_EXTABLE(0b, 0b)
17795+#endif
17796+
17797 /* adds 0x00000001 */
17798 " jns 1f\n"
17799 " call call_rwsem_down_read_failed\n"
17800@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17801 "1:\n\t"
17802 " mov %1,%2\n\t"
17803 " add %3,%2\n\t"
17804+
17805+#ifdef CONFIG_PAX_REFCOUNT
17806+ "jno 0f\n"
17807+ "sub %3,%2\n"
17808+ "int $4\n0:\n"
17809+ _ASM_EXTABLE(0b, 0b)
17810+#endif
17811+
17812 " jle 2f\n\t"
17813 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17814 " jnz 1b\n\t"
17815@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17816 long tmp;
17817 asm volatile("# beginning down_write\n\t"
17818 LOCK_PREFIX " xadd %1,(%2)\n\t"
17819+
17820+#ifdef CONFIG_PAX_REFCOUNT
17821+ "jno 0f\n"
17822+ "mov %1,(%2)\n"
17823+ "int $4\n0:\n"
17824+ _ASM_EXTABLE(0b, 0b)
17825+#endif
17826+
17827 /* adds 0xffff0001, returns the old value */
17828 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17829 /* was the active mask 0 before? */
17830@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17831 long tmp;
17832 asm volatile("# beginning __up_read\n\t"
17833 LOCK_PREFIX " xadd %1,(%2)\n\t"
17834+
17835+#ifdef CONFIG_PAX_REFCOUNT
17836+ "jno 0f\n"
17837+ "mov %1,(%2)\n"
17838+ "int $4\n0:\n"
17839+ _ASM_EXTABLE(0b, 0b)
17840+#endif
17841+
17842 /* subtracts 1, returns the old value */
17843 " jns 1f\n\t"
17844 " call call_rwsem_wake\n" /* expects old value in %edx */
17845@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17846 long tmp;
17847 asm volatile("# beginning __up_write\n\t"
17848 LOCK_PREFIX " xadd %1,(%2)\n\t"
17849+
17850+#ifdef CONFIG_PAX_REFCOUNT
17851+ "jno 0f\n"
17852+ "mov %1,(%2)\n"
17853+ "int $4\n0:\n"
17854+ _ASM_EXTABLE(0b, 0b)
17855+#endif
17856+
17857 /* subtracts 0xffff0001, returns the old value */
17858 " jns 1f\n\t"
17859 " call call_rwsem_wake\n" /* expects old value in %edx */
17860@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17861 {
17862 asm volatile("# beginning __downgrade_write\n\t"
17863 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17864+
17865+#ifdef CONFIG_PAX_REFCOUNT
17866+ "jno 0f\n"
17867+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17868+ "int $4\n0:\n"
17869+ _ASM_EXTABLE(0b, 0b)
17870+#endif
17871+
17872 /*
17873 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17874 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17875@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17876 */
17877 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17878 {
17879- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17880+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17881+
17882+#ifdef CONFIG_PAX_REFCOUNT
17883+ "jno 0f\n"
17884+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17885+ "int $4\n0:\n"
17886+ _ASM_EXTABLE(0b, 0b)
17887+#endif
17888+
17889 : "+m" (sem->count)
17890 : "er" (delta));
17891 }
17892@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17893 */
17894 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17895 {
17896- return delta + xadd(&sem->count, delta);
17897+ return delta + xadd_check_overflow(&sem->count, delta);
17898 }
17899
17900 #endif /* __KERNEL__ */
17901diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17902index c48a950..bc40804 100644
17903--- a/arch/x86/include/asm/segment.h
17904+++ b/arch/x86/include/asm/segment.h
17905@@ -64,10 +64,15 @@
17906 * 26 - ESPFIX small SS
17907 * 27 - per-cpu [ offset to per-cpu data area ]
17908 * 28 - stack_canary-20 [ for stack protector ]
17909- * 29 - unused
17910- * 30 - unused
17911+ * 29 - PCI BIOS CS
17912+ * 30 - PCI BIOS DS
17913 * 31 - TSS for double fault handler
17914 */
17915+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17916+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17917+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17918+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17919+
17920 #define GDT_ENTRY_TLS_MIN 6
17921 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17922
17923@@ -79,6 +84,8 @@
17924
17925 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17926
17927+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17928+
17929 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17930
17931 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17932@@ -104,6 +111,12 @@
17933 #define __KERNEL_STACK_CANARY 0
17934 #endif
17935
17936+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17937+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17938+
17939+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17940+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17941+
17942 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17943
17944 /*
17945@@ -141,7 +154,7 @@
17946 */
17947
17948 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17949-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17950+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17951
17952
17953 #else
17954@@ -165,6 +178,8 @@
17955 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17956 #define __USER32_DS __USER_DS
17957
17958+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17959+
17960 #define GDT_ENTRY_TSS 8 /* needs two entries */
17961 #define GDT_ENTRY_LDT 10 /* needs two entries */
17962 #define GDT_ENTRY_TLS_MIN 12
17963@@ -173,6 +188,8 @@
17964 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17965 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17966
17967+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17968+
17969 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17970 #define FS_TLS 0
17971 #define GS_TLS 1
17972@@ -180,12 +197,14 @@
17973 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17974 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17975
17976-#define GDT_ENTRIES 16
17977+#define GDT_ENTRIES 17
17978
17979 #endif
17980
17981 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17982+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17983 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17984+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17985 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17986 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17987 #ifndef CONFIG_PARAVIRT
17988@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17989 {
17990 unsigned long __limit;
17991 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17992- return __limit + 1;
17993+ return __limit;
17994 }
17995
17996 #endif /* !__ASSEMBLY__ */
17997diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17998index 8d3120f..352b440 100644
17999--- a/arch/x86/include/asm/smap.h
18000+++ b/arch/x86/include/asm/smap.h
18001@@ -25,11 +25,40 @@
18002
18003 #include <asm/alternative-asm.h>
18004
18005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18006+#define ASM_PAX_OPEN_USERLAND \
18007+ 661: jmp 663f; \
18008+ .pushsection .altinstr_replacement, "a" ; \
18009+ 662: pushq %rax; nop; \
18010+ .popsection ; \
18011+ .pushsection .altinstructions, "a" ; \
18012+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18013+ .popsection ; \
18014+ call __pax_open_userland; \
18015+ popq %rax; \
18016+ 663:
18017+
18018+#define ASM_PAX_CLOSE_USERLAND \
18019+ 661: jmp 663f; \
18020+ .pushsection .altinstr_replacement, "a" ; \
18021+ 662: pushq %rax; nop; \
18022+ .popsection; \
18023+ .pushsection .altinstructions, "a" ; \
18024+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18025+ .popsection; \
18026+ call __pax_close_userland; \
18027+ popq %rax; \
18028+ 663:
18029+#else
18030+#define ASM_PAX_OPEN_USERLAND
18031+#define ASM_PAX_CLOSE_USERLAND
18032+#endif
18033+
18034 #ifdef CONFIG_X86_SMAP
18035
18036 #define ASM_CLAC \
18037 661: ASM_NOP3 ; \
18038- .pushsection .altinstr_replacement, "ax" ; \
18039+ .pushsection .altinstr_replacement, "a" ; \
18040 662: __ASM_CLAC ; \
18041 .popsection ; \
18042 .pushsection .altinstructions, "a" ; \
18043@@ -38,7 +67,7 @@
18044
18045 #define ASM_STAC \
18046 661: ASM_NOP3 ; \
18047- .pushsection .altinstr_replacement, "ax" ; \
18048+ .pushsection .altinstr_replacement, "a" ; \
18049 662: __ASM_STAC ; \
18050 .popsection ; \
18051 .pushsection .altinstructions, "a" ; \
18052@@ -56,6 +85,37 @@
18053
18054 #include <asm/alternative.h>
18055
18056+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18057+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18058+
18059+extern void __pax_open_userland(void);
18060+static __always_inline unsigned long pax_open_userland(void)
18061+{
18062+
18063+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18064+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18065+ :
18066+ : [open] "i" (__pax_open_userland)
18067+ : "memory", "rax");
18068+#endif
18069+
18070+ return 0;
18071+}
18072+
18073+extern void __pax_close_userland(void);
18074+static __always_inline unsigned long pax_close_userland(void)
18075+{
18076+
18077+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18078+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18079+ :
18080+ : [close] "i" (__pax_close_userland)
18081+ : "memory", "rax");
18082+#endif
18083+
18084+ return 0;
18085+}
18086+
18087 #ifdef CONFIG_X86_SMAP
18088
18089 static __always_inline void clac(void)
18090diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18091index 4137890..03fa172 100644
18092--- a/arch/x86/include/asm/smp.h
18093+++ b/arch/x86/include/asm/smp.h
18094@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18095 /* cpus sharing the last level cache: */
18096 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18097 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18098-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18099+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18100
18101 static inline struct cpumask *cpu_sibling_mask(int cpu)
18102 {
18103@@ -79,7 +79,7 @@ struct smp_ops {
18104
18105 void (*send_call_func_ipi)(const struct cpumask *mask);
18106 void (*send_call_func_single_ipi)(int cpu);
18107-};
18108+} __no_const;
18109
18110 /* Globals due to paravirt */
18111 extern void set_cpu_sibling_map(int cpu);
18112@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18113 extern int safe_smp_processor_id(void);
18114
18115 #elif defined(CONFIG_X86_64_SMP)
18116-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18117-
18118-#define stack_smp_processor_id() \
18119-({ \
18120- struct thread_info *ti; \
18121- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18122- ti->cpu; \
18123-})
18124+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18125+#define stack_smp_processor_id() raw_smp_processor_id()
18126 #define safe_smp_processor_id() smp_processor_id()
18127
18128 #endif
18129diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18130index bf156de..1a782ab 100644
18131--- a/arch/x86/include/asm/spinlock.h
18132+++ b/arch/x86/include/asm/spinlock.h
18133@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18134 static inline void arch_read_lock(arch_rwlock_t *rw)
18135 {
18136 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18137+
18138+#ifdef CONFIG_PAX_REFCOUNT
18139+ "jno 0f\n"
18140+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18141+ "int $4\n0:\n"
18142+ _ASM_EXTABLE(0b, 0b)
18143+#endif
18144+
18145 "jns 1f\n"
18146 "call __read_lock_failed\n\t"
18147 "1:\n"
18148@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18149 static inline void arch_write_lock(arch_rwlock_t *rw)
18150 {
18151 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18152+
18153+#ifdef CONFIG_PAX_REFCOUNT
18154+ "jno 0f\n"
18155+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18156+ "int $4\n0:\n"
18157+ _ASM_EXTABLE(0b, 0b)
18158+#endif
18159+
18160 "jz 1f\n"
18161 "call __write_lock_failed\n\t"
18162 "1:\n"
18163@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18164
18165 static inline void arch_read_unlock(arch_rwlock_t *rw)
18166 {
18167- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18168+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18169+
18170+#ifdef CONFIG_PAX_REFCOUNT
18171+ "jno 0f\n"
18172+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18173+ "int $4\n0:\n"
18174+ _ASM_EXTABLE(0b, 0b)
18175+#endif
18176+
18177 :"+m" (rw->lock) : : "memory");
18178 }
18179
18180 static inline void arch_write_unlock(arch_rwlock_t *rw)
18181 {
18182- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18183+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18184+
18185+#ifdef CONFIG_PAX_REFCOUNT
18186+ "jno 0f\n"
18187+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18188+ "int $4\n0:\n"
18189+ _ASM_EXTABLE(0b, 0b)
18190+#endif
18191+
18192 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18193 }
18194
18195diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18196index 6a99859..03cb807 100644
18197--- a/arch/x86/include/asm/stackprotector.h
18198+++ b/arch/x86/include/asm/stackprotector.h
18199@@ -47,7 +47,7 @@
18200 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18201 */
18202 #define GDT_STACK_CANARY_INIT \
18203- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18204+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18205
18206 /*
18207 * Initialize the stackprotector canary value.
18208@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18209
18210 static inline void load_stack_canary_segment(void)
18211 {
18212-#ifdef CONFIG_X86_32
18213+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18214 asm volatile ("mov %0, %%gs" : : "r" (0));
18215 #endif
18216 }
18217diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18218index 70bbe39..4ae2bd4 100644
18219--- a/arch/x86/include/asm/stacktrace.h
18220+++ b/arch/x86/include/asm/stacktrace.h
18221@@ -11,28 +11,20 @@
18222
18223 extern int kstack_depth_to_print;
18224
18225-struct thread_info;
18226+struct task_struct;
18227 struct stacktrace_ops;
18228
18229-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18230- unsigned long *stack,
18231- unsigned long bp,
18232- const struct stacktrace_ops *ops,
18233- void *data,
18234- unsigned long *end,
18235- int *graph);
18236+typedef unsigned long walk_stack_t(struct task_struct *task,
18237+ void *stack_start,
18238+ unsigned long *stack,
18239+ unsigned long bp,
18240+ const struct stacktrace_ops *ops,
18241+ void *data,
18242+ unsigned long *end,
18243+ int *graph);
18244
18245-extern unsigned long
18246-print_context_stack(struct thread_info *tinfo,
18247- unsigned long *stack, unsigned long bp,
18248- const struct stacktrace_ops *ops, void *data,
18249- unsigned long *end, int *graph);
18250-
18251-extern unsigned long
18252-print_context_stack_bp(struct thread_info *tinfo,
18253- unsigned long *stack, unsigned long bp,
18254- const struct stacktrace_ops *ops, void *data,
18255- unsigned long *end, int *graph);
18256+extern walk_stack_t print_context_stack;
18257+extern walk_stack_t print_context_stack_bp;
18258
18259 /* Generic stack tracer with callbacks */
18260
18261@@ -40,7 +32,7 @@ struct stacktrace_ops {
18262 void (*address)(void *data, unsigned long address, int reliable);
18263 /* On negative return stop dumping */
18264 int (*stack)(void *data, char *name);
18265- walk_stack_t walk_stack;
18266+ walk_stack_t *walk_stack;
18267 };
18268
18269 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18270diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18271index d7f3b3b..3cc39f1 100644
18272--- a/arch/x86/include/asm/switch_to.h
18273+++ b/arch/x86/include/asm/switch_to.h
18274@@ -108,7 +108,7 @@ do { \
18275 "call __switch_to\n\t" \
18276 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18277 __switch_canary \
18278- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18279+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18280 "movq %%rax,%%rdi\n\t" \
18281 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18282 "jnz ret_from_fork\n\t" \
18283@@ -119,7 +119,7 @@ do { \
18284 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18285 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18286 [_tif_fork] "i" (_TIF_FORK), \
18287- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18288+ [thread_info] "m" (current_tinfo), \
18289 [current_task] "m" (current_task) \
18290 __switch_canary_iparam \
18291 : "memory", "cc" __EXTRA_CLOBBER)
18292diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18293index 2781119..618b59b 100644
18294--- a/arch/x86/include/asm/thread_info.h
18295+++ b/arch/x86/include/asm/thread_info.h
18296@@ -10,6 +10,7 @@
18297 #include <linux/compiler.h>
18298 #include <asm/page.h>
18299 #include <asm/types.h>
18300+#include <asm/percpu.h>
18301
18302 /*
18303 * low level task data that entry.S needs immediate access to
18304@@ -23,7 +24,6 @@ struct exec_domain;
18305 #include <linux/atomic.h>
18306
18307 struct thread_info {
18308- struct task_struct *task; /* main task structure */
18309 struct exec_domain *exec_domain; /* execution domain */
18310 __u32 flags; /* low level flags */
18311 __u32 status; /* thread synchronous flags */
18312@@ -33,19 +33,13 @@ struct thread_info {
18313 mm_segment_t addr_limit;
18314 struct restart_block restart_block;
18315 void __user *sysenter_return;
18316-#ifdef CONFIG_X86_32
18317- unsigned long previous_esp; /* ESP of the previous stack in
18318- case of nested (IRQ) stacks
18319- */
18320- __u8 supervisor_stack[0];
18321-#endif
18322+ unsigned long lowest_stack;
18323 unsigned int sig_on_uaccess_error:1;
18324 unsigned int uaccess_err:1; /* uaccess failed */
18325 };
18326
18327-#define INIT_THREAD_INFO(tsk) \
18328+#define INIT_THREAD_INFO \
18329 { \
18330- .task = &tsk, \
18331 .exec_domain = &default_exec_domain, \
18332 .flags = 0, \
18333 .cpu = 0, \
18334@@ -56,7 +50,7 @@ struct thread_info {
18335 }, \
18336 }
18337
18338-#define init_thread_info (init_thread_union.thread_info)
18339+#define init_thread_info (init_thread_union.stack)
18340 #define init_stack (init_thread_union.stack)
18341
18342 #else /* !__ASSEMBLY__ */
18343@@ -96,6 +90,7 @@ struct thread_info {
18344 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18345 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18346 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18347+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18348
18349 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18350 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18351@@ -119,17 +114,18 @@ struct thread_info {
18352 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18353 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18354 #define _TIF_X32 (1 << TIF_X32)
18355+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18356
18357 /* work to do in syscall_trace_enter() */
18358 #define _TIF_WORK_SYSCALL_ENTRY \
18359 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18360 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18361- _TIF_NOHZ)
18362+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18363
18364 /* work to do in syscall_trace_leave() */
18365 #define _TIF_WORK_SYSCALL_EXIT \
18366 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18367- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18368+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18369
18370 /* work to do on interrupt/exception return */
18371 #define _TIF_WORK_MASK \
18372@@ -140,7 +136,7 @@ struct thread_info {
18373 /* work to do on any return to user space */
18374 #define _TIF_ALLWORK_MASK \
18375 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18376- _TIF_NOHZ)
18377+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18378
18379 /* Only used for 64 bit */
18380 #define _TIF_DO_NOTIFY_MASK \
18381@@ -156,45 +152,40 @@ struct thread_info {
18382
18383 #define PREEMPT_ACTIVE 0x10000000
18384
18385-#ifdef CONFIG_X86_32
18386-
18387-#define STACK_WARN (THREAD_SIZE/8)
18388-/*
18389- * macros/functions for gaining access to the thread information structure
18390- *
18391- * preempt_count needs to be 1 initially, until the scheduler is functional.
18392- */
18393-#ifndef __ASSEMBLY__
18394-
18395-
18396-/* how to get the current stack pointer from C */
18397-register unsigned long current_stack_pointer asm("esp") __used;
18398-
18399-/* how to get the thread information struct from C */
18400-static inline struct thread_info *current_thread_info(void)
18401-{
18402- return (struct thread_info *)
18403- (current_stack_pointer & ~(THREAD_SIZE - 1));
18404-}
18405-
18406-#else /* !__ASSEMBLY__ */
18407-
18408+#ifdef __ASSEMBLY__
18409 /* how to get the thread information struct from ASM */
18410 #define GET_THREAD_INFO(reg) \
18411- movl $-THREAD_SIZE, reg; \
18412- andl %esp, reg
18413+ mov PER_CPU_VAR(current_tinfo), reg
18414
18415 /* use this one if reg already contains %esp */
18416-#define GET_THREAD_INFO_WITH_ESP(reg) \
18417- andl $-THREAD_SIZE, reg
18418+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18419+#else
18420+/* how to get the thread information struct from C */
18421+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18422+
18423+static __always_inline struct thread_info *current_thread_info(void)
18424+{
18425+ return this_cpu_read_stable(current_tinfo);
18426+}
18427+#endif
18428+
18429+#ifdef CONFIG_X86_32
18430+
18431+#define STACK_WARN (THREAD_SIZE/8)
18432+/*
18433+ * macros/functions for gaining access to the thread information structure
18434+ *
18435+ * preempt_count needs to be 1 initially, until the scheduler is functional.
18436+ */
18437+#ifndef __ASSEMBLY__
18438+
18439+/* how to get the current stack pointer from C */
18440+register unsigned long current_stack_pointer asm("esp") __used;
18441
18442 #endif
18443
18444 #else /* X86_32 */
18445
18446-#include <asm/percpu.h>
18447-#define KERNEL_STACK_OFFSET (5*8)
18448-
18449 /*
18450 * macros/functions for gaining access to the thread information structure
18451 * preempt_count needs to be 1 initially, until the scheduler is functional.
18452@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
18453 #ifndef __ASSEMBLY__
18454 DECLARE_PER_CPU(unsigned long, kernel_stack);
18455
18456-static inline struct thread_info *current_thread_info(void)
18457-{
18458- struct thread_info *ti;
18459- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18460- KERNEL_STACK_OFFSET - THREAD_SIZE);
18461- return ti;
18462-}
18463-
18464-#else /* !__ASSEMBLY__ */
18465-
18466-/* how to get the thread information struct from ASM */
18467-#define GET_THREAD_INFO(reg) \
18468- movq PER_CPU_VAR(kernel_stack),reg ; \
18469- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18470-
18471-/*
18472- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18473- * a certain register (to be used in assembler memory operands).
18474- */
18475-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18476-
18477+/* how to get the current stack pointer from C */
18478+register unsigned long current_stack_pointer asm("rsp") __used;
18479 #endif
18480
18481 #endif /* !X86_32 */
18482@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
18483 extern void arch_task_cache_init(void);
18484 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18485 extern void arch_release_task_struct(struct task_struct *tsk);
18486+
18487+#define __HAVE_THREAD_FUNCTIONS
18488+#define task_thread_info(task) (&(task)->tinfo)
18489+#define task_stack_page(task) ((task)->stack)
18490+#define setup_thread_stack(p, org) do {} while (0)
18491+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18492+
18493 #endif
18494 #endif /* _ASM_X86_THREAD_INFO_H */
18495diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18496index e6d90ba..0897f44 100644
18497--- a/arch/x86/include/asm/tlbflush.h
18498+++ b/arch/x86/include/asm/tlbflush.h
18499@@ -17,18 +17,44 @@
18500
18501 static inline void __native_flush_tlb(void)
18502 {
18503+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18504+ u64 descriptor[2];
18505+
18506+ descriptor[0] = PCID_KERNEL;
18507+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18508+ return;
18509+ }
18510+
18511+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18512+ if (static_cpu_has(X86_FEATURE_PCID)) {
18513+ unsigned int cpu = raw_get_cpu();
18514+
18515+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18516+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18517+ raw_put_cpu_no_resched();
18518+ return;
18519+ }
18520+#endif
18521+
18522 native_write_cr3(native_read_cr3());
18523 }
18524
18525 static inline void __native_flush_tlb_global_irq_disabled(void)
18526 {
18527- unsigned long cr4;
18528+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18529+ u64 descriptor[2];
18530
18531- cr4 = native_read_cr4();
18532- /* clear PGE */
18533- native_write_cr4(cr4 & ~X86_CR4_PGE);
18534- /* write old PGE again and flush TLBs */
18535- native_write_cr4(cr4);
18536+ descriptor[0] = PCID_KERNEL;
18537+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18538+ } else {
18539+ unsigned long cr4;
18540+
18541+ cr4 = native_read_cr4();
18542+ /* clear PGE */
18543+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18544+ /* write old PGE again and flush TLBs */
18545+ native_write_cr4(cr4);
18546+ }
18547 }
18548
18549 static inline void __native_flush_tlb_global(void)
18550@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18551
18552 static inline void __native_flush_tlb_single(unsigned long addr)
18553 {
18554+
18555+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18556+ u64 descriptor[2];
18557+
18558+ descriptor[0] = PCID_KERNEL;
18559+ descriptor[1] = addr;
18560+
18561+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18562+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18563+ if (addr < TASK_SIZE_MAX)
18564+ descriptor[1] += pax_user_shadow_base;
18565+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18566+ }
18567+
18568+ descriptor[0] = PCID_USER;
18569+ descriptor[1] = addr;
18570+#endif
18571+
18572+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18573+ return;
18574+ }
18575+
18576+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18577+ if (static_cpu_has(X86_FEATURE_PCID)) {
18578+ unsigned int cpu = raw_get_cpu();
18579+
18580+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18581+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18582+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18583+ raw_put_cpu_no_resched();
18584+
18585+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18586+ addr += pax_user_shadow_base;
18587+ }
18588+#endif
18589+
18590 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18591 }
18592
18593diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18594index 5838fa9..f7ae572 100644
18595--- a/arch/x86/include/asm/uaccess.h
18596+++ b/arch/x86/include/asm/uaccess.h
18597@@ -7,6 +7,7 @@
18598 #include <linux/compiler.h>
18599 #include <linux/thread_info.h>
18600 #include <linux/string.h>
18601+#include <linux/sched.h>
18602 #include <asm/asm.h>
18603 #include <asm/page.h>
18604 #include <asm/smap.h>
18605@@ -29,7 +30,12 @@
18606
18607 #define get_ds() (KERNEL_DS)
18608 #define get_fs() (current_thread_info()->addr_limit)
18609+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18610+void __set_fs(mm_segment_t x);
18611+void set_fs(mm_segment_t x);
18612+#else
18613 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18614+#endif
18615
18616 #define segment_eq(a, b) ((a).seg == (b).seg)
18617
18618@@ -77,8 +83,33 @@
18619 * checks that the pointer is in the user space range - after calling
18620 * this function, memory access functions may still return -EFAULT.
18621 */
18622-#define access_ok(type, addr, size) \
18623- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18624+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18625+#define access_ok(type, addr, size) \
18626+({ \
18627+ long __size = size; \
18628+ unsigned long __addr = (unsigned long)addr; \
18629+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18630+ unsigned long __end_ao = __addr + __size - 1; \
18631+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18632+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18633+ while(__addr_ao <= __end_ao) { \
18634+ char __c_ao; \
18635+ __addr_ao += PAGE_SIZE; \
18636+ if (__size > PAGE_SIZE) \
18637+ cond_resched(); \
18638+ if (__get_user(__c_ao, (char __user *)__addr)) \
18639+ break; \
18640+ if (type != VERIFY_WRITE) { \
18641+ __addr = __addr_ao; \
18642+ continue; \
18643+ } \
18644+ if (__put_user(__c_ao, (char __user *)__addr)) \
18645+ break; \
18646+ __addr = __addr_ao; \
18647+ } \
18648+ } \
18649+ __ret_ao; \
18650+})
18651
18652 /*
18653 * The exception table consists of pairs of addresses relative to the
18654@@ -168,10 +199,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18655 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18656 __chk_user_ptr(ptr); \
18657 might_fault(); \
18658+ pax_open_userland(); \
18659 asm volatile("call __get_user_%P3" \
18660 : "=a" (__ret_gu), "=r" (__val_gu) \
18661 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18662 (x) = (__typeof__(*(ptr))) __val_gu; \
18663+ pax_close_userland(); \
18664 __ret_gu; \
18665 })
18666
18667@@ -179,13 +212,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18668 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18669 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18670
18671-
18672+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18673+#define __copyuser_seg "gs;"
18674+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18675+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18676+#else
18677+#define __copyuser_seg
18678+#define __COPYUSER_SET_ES
18679+#define __COPYUSER_RESTORE_ES
18680+#endif
18681
18682 #ifdef CONFIG_X86_32
18683 #define __put_user_asm_u64(x, addr, err, errret) \
18684 asm volatile(ASM_STAC "\n" \
18685- "1: movl %%eax,0(%2)\n" \
18686- "2: movl %%edx,4(%2)\n" \
18687+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18688+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18689 "3: " ASM_CLAC "\n" \
18690 ".section .fixup,\"ax\"\n" \
18691 "4: movl %3,%0\n" \
18692@@ -198,8 +239,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18693
18694 #define __put_user_asm_ex_u64(x, addr) \
18695 asm volatile(ASM_STAC "\n" \
18696- "1: movl %%eax,0(%1)\n" \
18697- "2: movl %%edx,4(%1)\n" \
18698+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18699+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18700 "3: " ASM_CLAC "\n" \
18701 _ASM_EXTABLE_EX(1b, 2b) \
18702 _ASM_EXTABLE_EX(2b, 3b) \
18703@@ -249,7 +290,8 @@ extern void __put_user_8(void);
18704 __typeof__(*(ptr)) __pu_val; \
18705 __chk_user_ptr(ptr); \
18706 might_fault(); \
18707- __pu_val = x; \
18708+ __pu_val = (x); \
18709+ pax_open_userland(); \
18710 switch (sizeof(*(ptr))) { \
18711 case 1: \
18712 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18713@@ -267,6 +309,7 @@ extern void __put_user_8(void);
18714 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18715 break; \
18716 } \
18717+ pax_close_userland(); \
18718 __ret_pu; \
18719 })
18720
18721@@ -347,8 +390,10 @@ do { \
18722 } while (0)
18723
18724 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18725+do { \
18726+ pax_open_userland(); \
18727 asm volatile(ASM_STAC "\n" \
18728- "1: mov"itype" %2,%"rtype"1\n" \
18729+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18730 "2: " ASM_CLAC "\n" \
18731 ".section .fixup,\"ax\"\n" \
18732 "3: mov %3,%0\n" \
18733@@ -356,8 +401,10 @@ do { \
18734 " jmp 2b\n" \
18735 ".previous\n" \
18736 _ASM_EXTABLE(1b, 3b) \
18737- : "=r" (err), ltype(x) \
18738- : "m" (__m(addr)), "i" (errret), "0" (err))
18739+ : "=r" (err), ltype (x) \
18740+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18741+ pax_close_userland(); \
18742+} while (0)
18743
18744 #define __get_user_size_ex(x, ptr, size) \
18745 do { \
18746@@ -381,7 +428,7 @@ do { \
18747 } while (0)
18748
18749 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18750- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18751+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18752 "2:\n" \
18753 _ASM_EXTABLE_EX(1b, 2b) \
18754 : ltype(x) : "m" (__m(addr)))
18755@@ -398,13 +445,24 @@ do { \
18756 int __gu_err; \
18757 unsigned long __gu_val; \
18758 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18759- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18760+ (x) = (__typeof__(*(ptr)))__gu_val; \
18761 __gu_err; \
18762 })
18763
18764 /* FIXME: this hack is definitely wrong -AK */
18765 struct __large_struct { unsigned long buf[100]; };
18766-#define __m(x) (*(struct __large_struct __user *)(x))
18767+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18768+#define ____m(x) \
18769+({ \
18770+ unsigned long ____x = (unsigned long)(x); \
18771+ if (____x < pax_user_shadow_base) \
18772+ ____x += pax_user_shadow_base; \
18773+ (typeof(x))____x; \
18774+})
18775+#else
18776+#define ____m(x) (x)
18777+#endif
18778+#define __m(x) (*(struct __large_struct __user *)____m(x))
18779
18780 /*
18781 * Tell gcc we read from memory instead of writing: this is because
18782@@ -412,8 +470,10 @@ struct __large_struct { unsigned long buf[100]; };
18783 * aliasing issues.
18784 */
18785 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18786+do { \
18787+ pax_open_userland(); \
18788 asm volatile(ASM_STAC "\n" \
18789- "1: mov"itype" %"rtype"1,%2\n" \
18790+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18791 "2: " ASM_CLAC "\n" \
18792 ".section .fixup,\"ax\"\n" \
18793 "3: mov %3,%0\n" \
18794@@ -421,10 +481,12 @@ struct __large_struct { unsigned long buf[100]; };
18795 ".previous\n" \
18796 _ASM_EXTABLE(1b, 3b) \
18797 : "=r"(err) \
18798- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18799+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18800+ pax_close_userland(); \
18801+} while (0)
18802
18803 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18804- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18805+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18806 "2:\n" \
18807 _ASM_EXTABLE_EX(1b, 2b) \
18808 : : ltype(x), "m" (__m(addr)))
18809@@ -434,11 +496,13 @@ struct __large_struct { unsigned long buf[100]; };
18810 */
18811 #define uaccess_try do { \
18812 current_thread_info()->uaccess_err = 0; \
18813+ pax_open_userland(); \
18814 stac(); \
18815 barrier();
18816
18817 #define uaccess_catch(err) \
18818 clac(); \
18819+ pax_close_userland(); \
18820 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18821 } while (0)
18822
18823@@ -463,8 +527,12 @@ struct __large_struct { unsigned long buf[100]; };
18824 * On error, the variable @x is set to zero.
18825 */
18826
18827+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18828+#define __get_user(x, ptr) get_user((x), (ptr))
18829+#else
18830 #define __get_user(x, ptr) \
18831 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18832+#endif
18833
18834 /**
18835 * __put_user: - Write a simple value into user space, with less checking.
18836@@ -486,8 +554,12 @@ struct __large_struct { unsigned long buf[100]; };
18837 * Returns zero on success, or -EFAULT on error.
18838 */
18839
18840+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18841+#define __put_user(x, ptr) put_user((x), (ptr))
18842+#else
18843 #define __put_user(x, ptr) \
18844 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18845+#endif
18846
18847 #define __get_user_unaligned __get_user
18848 #define __put_user_unaligned __put_user
18849@@ -505,7 +577,7 @@ struct __large_struct { unsigned long buf[100]; };
18850 #define get_user_ex(x, ptr) do { \
18851 unsigned long __gue_val; \
18852 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18853- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18854+ (x) = (__typeof__(*(ptr)))__gue_val; \
18855 } while (0)
18856
18857 #define put_user_try uaccess_try
18858diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18859index 7f760a9..b596b9a 100644
18860--- a/arch/x86/include/asm/uaccess_32.h
18861+++ b/arch/x86/include/asm/uaccess_32.h
18862@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18863 static __always_inline unsigned long __must_check
18864 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18865 {
18866+ if ((long)n < 0)
18867+ return n;
18868+
18869+ check_object_size(from, n, true);
18870+
18871 if (__builtin_constant_p(n)) {
18872 unsigned long ret;
18873
18874@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18875 __copy_to_user(void __user *to, const void *from, unsigned long n)
18876 {
18877 might_fault();
18878+
18879 return __copy_to_user_inatomic(to, from, n);
18880 }
18881
18882 static __always_inline unsigned long
18883 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18884 {
18885+ if ((long)n < 0)
18886+ return n;
18887+
18888 /* Avoid zeroing the tail if the copy fails..
18889 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18890 * but as the zeroing behaviour is only significant when n is not
18891@@ -137,6 +146,12 @@ static __always_inline unsigned long
18892 __copy_from_user(void *to, const void __user *from, unsigned long n)
18893 {
18894 might_fault();
18895+
18896+ if ((long)n < 0)
18897+ return n;
18898+
18899+ check_object_size(to, n, false);
18900+
18901 if (__builtin_constant_p(n)) {
18902 unsigned long ret;
18903
18904@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18905 const void __user *from, unsigned long n)
18906 {
18907 might_fault();
18908+
18909+ if ((long)n < 0)
18910+ return n;
18911+
18912 if (__builtin_constant_p(n)) {
18913 unsigned long ret;
18914
18915@@ -181,15 +200,19 @@ static __always_inline unsigned long
18916 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18917 unsigned long n)
18918 {
18919- return __copy_from_user_ll_nocache_nozero(to, from, n);
18920+ if ((long)n < 0)
18921+ return n;
18922+
18923+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18924 }
18925
18926-unsigned long __must_check copy_to_user(void __user *to,
18927- const void *from, unsigned long n);
18928-unsigned long __must_check _copy_from_user(void *to,
18929- const void __user *from,
18930- unsigned long n);
18931-
18932+extern void copy_to_user_overflow(void)
18933+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18934+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18935+#else
18936+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18937+#endif
18938+;
18939
18940 extern void copy_from_user_overflow(void)
18941 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18942@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18943 #endif
18944 ;
18945
18946-static inline unsigned long __must_check copy_from_user(void *to,
18947- const void __user *from,
18948- unsigned long n)
18949+/**
18950+ * copy_to_user: - Copy a block of data into user space.
18951+ * @to: Destination address, in user space.
18952+ * @from: Source address, in kernel space.
18953+ * @n: Number of bytes to copy.
18954+ *
18955+ * Context: User context only. This function may sleep.
18956+ *
18957+ * Copy data from kernel space to user space.
18958+ *
18959+ * Returns number of bytes that could not be copied.
18960+ * On success, this will be zero.
18961+ */
18962+static inline unsigned long __must_check
18963+copy_to_user(void __user *to, const void *from, unsigned long n)
18964 {
18965- int sz = __compiletime_object_size(to);
18966+ size_t sz = __compiletime_object_size(from);
18967
18968- if (likely(sz == -1 || sz >= n))
18969- n = _copy_from_user(to, from, n);
18970- else
18971+ if (unlikely(sz != (size_t)-1 && sz < n))
18972+ copy_to_user_overflow();
18973+ else if (access_ok(VERIFY_WRITE, to, n))
18974+ n = __copy_to_user(to, from, n);
18975+ return n;
18976+}
18977+
18978+/**
18979+ * copy_from_user: - Copy a block of data from user space.
18980+ * @to: Destination address, in kernel space.
18981+ * @from: Source address, in user space.
18982+ * @n: Number of bytes to copy.
18983+ *
18984+ * Context: User context only. This function may sleep.
18985+ *
18986+ * Copy data from user space to kernel space.
18987+ *
18988+ * Returns number of bytes that could not be copied.
18989+ * On success, this will be zero.
18990+ *
18991+ * If some data could not be copied, this function will pad the copied
18992+ * data to the requested size using zero bytes.
18993+ */
18994+static inline unsigned long __must_check
18995+copy_from_user(void *to, const void __user *from, unsigned long n)
18996+{
18997+ size_t sz = __compiletime_object_size(to);
18998+
18999+ check_object_size(to, n, false);
19000+
19001+ if (unlikely(sz != (size_t)-1 && sz < n))
19002 copy_from_user_overflow();
19003-
19004+ else if (access_ok(VERIFY_READ, from, n))
19005+ n = __copy_from_user(to, from, n);
19006+ else if ((long)n > 0)
19007+ memset(to, 0, n);
19008 return n;
19009 }
19010
19011diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19012index 4f7923d..201b58d 100644
19013--- a/arch/x86/include/asm/uaccess_64.h
19014+++ b/arch/x86/include/asm/uaccess_64.h
19015@@ -10,6 +10,9 @@
19016 #include <asm/alternative.h>
19017 #include <asm/cpufeature.h>
19018 #include <asm/page.h>
19019+#include <asm/pgtable.h>
19020+
19021+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19022
19023 /*
19024 * Copy To/From Userspace
19025@@ -17,14 +20,14 @@
19026
19027 /* Handles exceptions in both to and from, but doesn't do access_ok */
19028 __must_check unsigned long
19029-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19030+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19031 __must_check unsigned long
19032-copy_user_generic_string(void *to, const void *from, unsigned len);
19033+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19034 __must_check unsigned long
19035-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19036+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19037
19038-static __always_inline __must_check unsigned long
19039-copy_user_generic(void *to, const void *from, unsigned len)
19040+static __always_inline __must_check unsigned long
19041+copy_user_generic(void *to, const void *from, unsigned long len)
19042 {
19043 unsigned ret;
19044
19045@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
19046 return ret;
19047 }
19048
19049+static __always_inline __must_check unsigned long
19050+__copy_to_user(void __user *to, const void *from, unsigned long len);
19051+static __always_inline __must_check unsigned long
19052+__copy_from_user(void *to, const void __user *from, unsigned long len);
19053 __must_check unsigned long
19054-_copy_to_user(void __user *to, const void *from, unsigned len);
19055-__must_check unsigned long
19056-_copy_from_user(void *to, const void __user *from, unsigned len);
19057-__must_check unsigned long
19058-copy_in_user(void __user *to, const void __user *from, unsigned len);
19059+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19060+
19061+extern void copy_to_user_overflow(void)
19062+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19063+ __compiletime_error("copy_to_user() buffer size is not provably correct")
19064+#else
19065+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
19066+#endif
19067+;
19068+
19069+extern void copy_from_user_overflow(void)
19070+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19071+ __compiletime_error("copy_from_user() buffer size is not provably correct")
19072+#else
19073+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
19074+#endif
19075+;
19076
19077 static inline unsigned long __must_check copy_from_user(void *to,
19078 const void __user *from,
19079 unsigned long n)
19080 {
19081- int sz = __compiletime_object_size(to);
19082-
19083 might_fault();
19084- if (likely(sz == -1 || sz >= n))
19085- n = _copy_from_user(to, from, n);
19086-#ifdef CONFIG_DEBUG_VM
19087- else
19088- WARN(1, "Buffer overflow detected!\n");
19089-#endif
19090+
19091+ check_object_size(to, n, false);
19092+
19093+ if (access_ok(VERIFY_READ, from, n))
19094+ n = __copy_from_user(to, from, n);
19095+ else if (n < INT_MAX)
19096+ memset(to, 0, n);
19097 return n;
19098 }
19099
19100 static __always_inline __must_check
19101-int copy_to_user(void __user *dst, const void *src, unsigned size)
19102+int copy_to_user(void __user *dst, const void *src, unsigned long size)
19103 {
19104 might_fault();
19105
19106- return _copy_to_user(dst, src, size);
19107+ if (access_ok(VERIFY_WRITE, dst, size))
19108+ size = __copy_to_user(dst, src, size);
19109+ return size;
19110 }
19111
19112 static __always_inline __must_check
19113-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19114+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19115 {
19116- int ret = 0;
19117+ size_t sz = __compiletime_object_size(dst);
19118+ unsigned ret = 0;
19119
19120 might_fault();
19121+
19122+ if (size > INT_MAX)
19123+ return size;
19124+
19125+ check_object_size(dst, size, false);
19126+
19127+#ifdef CONFIG_PAX_MEMORY_UDEREF
19128+ if (!__access_ok(VERIFY_READ, src, size))
19129+ return size;
19130+#endif
19131+
19132+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19133+ copy_from_user_overflow();
19134+ return size;
19135+ }
19136+
19137 if (!__builtin_constant_p(size))
19138- return copy_user_generic(dst, (__force void *)src, size);
19139+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19140 switch (size) {
19141- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19142+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19143 ret, "b", "b", "=q", 1);
19144 return ret;
19145- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19146+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19147 ret, "w", "w", "=r", 2);
19148 return ret;
19149- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19150+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19151 ret, "l", "k", "=r", 4);
19152 return ret;
19153- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19154+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19155 ret, "q", "", "=r", 8);
19156 return ret;
19157 case 10:
19158- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19159+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19160 ret, "q", "", "=r", 10);
19161 if (unlikely(ret))
19162 return ret;
19163 __get_user_asm(*(u16 *)(8 + (char *)dst),
19164- (u16 __user *)(8 + (char __user *)src),
19165+ (const u16 __user *)(8 + (const char __user *)src),
19166 ret, "w", "w", "=r", 2);
19167 return ret;
19168 case 16:
19169- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19170+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19171 ret, "q", "", "=r", 16);
19172 if (unlikely(ret))
19173 return ret;
19174 __get_user_asm(*(u64 *)(8 + (char *)dst),
19175- (u64 __user *)(8 + (char __user *)src),
19176+ (const u64 __user *)(8 + (const char __user *)src),
19177 ret, "q", "", "=r", 8);
19178 return ret;
19179 default:
19180- return copy_user_generic(dst, (__force void *)src, size);
19181+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19182 }
19183 }
19184
19185 static __always_inline __must_check
19186-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19187+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19188 {
19189- int ret = 0;
19190+ size_t sz = __compiletime_object_size(src);
19191+ unsigned ret = 0;
19192
19193 might_fault();
19194+
19195+ if (size > INT_MAX)
19196+ return size;
19197+
19198+ check_object_size(src, size, true);
19199+
19200+#ifdef CONFIG_PAX_MEMORY_UDEREF
19201+ if (!__access_ok(VERIFY_WRITE, dst, size))
19202+ return size;
19203+#endif
19204+
19205+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19206+ copy_to_user_overflow();
19207+ return size;
19208+ }
19209+
19210 if (!__builtin_constant_p(size))
19211- return copy_user_generic((__force void *)dst, src, size);
19212+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19213 switch (size) {
19214- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19215+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19216 ret, "b", "b", "iq", 1);
19217 return ret;
19218- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19219+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19220 ret, "w", "w", "ir", 2);
19221 return ret;
19222- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19223+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19224 ret, "l", "k", "ir", 4);
19225 return ret;
19226- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19227+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19228 ret, "q", "", "er", 8);
19229 return ret;
19230 case 10:
19231- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19232+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19233 ret, "q", "", "er", 10);
19234 if (unlikely(ret))
19235 return ret;
19236 asm("":::"memory");
19237- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19238+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19239 ret, "w", "w", "ir", 2);
19240 return ret;
19241 case 16:
19242- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19243+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19244 ret, "q", "", "er", 16);
19245 if (unlikely(ret))
19246 return ret;
19247 asm("":::"memory");
19248- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19249+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19250 ret, "q", "", "er", 8);
19251 return ret;
19252 default:
19253- return copy_user_generic((__force void *)dst, src, size);
19254+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19255 }
19256 }
19257
19258 static __always_inline __must_check
19259-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19260+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
19261 {
19262- int ret = 0;
19263+ unsigned ret = 0;
19264
19265 might_fault();
19266+
19267+ if (size > INT_MAX)
19268+ return size;
19269+
19270+#ifdef CONFIG_PAX_MEMORY_UDEREF
19271+ if (!__access_ok(VERIFY_READ, src, size))
19272+ return size;
19273+ if (!__access_ok(VERIFY_WRITE, dst, size))
19274+ return size;
19275+#endif
19276+
19277 if (!__builtin_constant_p(size))
19278- return copy_user_generic((__force void *)dst,
19279- (__force void *)src, size);
19280+ return copy_user_generic((__force_kernel void *)____m(dst),
19281+ (__force_kernel const void *)____m(src), size);
19282 switch (size) {
19283 case 1: {
19284 u8 tmp;
19285- __get_user_asm(tmp, (u8 __user *)src,
19286+ __get_user_asm(tmp, (const u8 __user *)src,
19287 ret, "b", "b", "=q", 1);
19288 if (likely(!ret))
19289 __put_user_asm(tmp, (u8 __user *)dst,
19290@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19291 }
19292 case 2: {
19293 u16 tmp;
19294- __get_user_asm(tmp, (u16 __user *)src,
19295+ __get_user_asm(tmp, (const u16 __user *)src,
19296 ret, "w", "w", "=r", 2);
19297 if (likely(!ret))
19298 __put_user_asm(tmp, (u16 __user *)dst,
19299@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19300
19301 case 4: {
19302 u32 tmp;
19303- __get_user_asm(tmp, (u32 __user *)src,
19304+ __get_user_asm(tmp, (const u32 __user *)src,
19305 ret, "l", "k", "=r", 4);
19306 if (likely(!ret))
19307 __put_user_asm(tmp, (u32 __user *)dst,
19308@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19309 }
19310 case 8: {
19311 u64 tmp;
19312- __get_user_asm(tmp, (u64 __user *)src,
19313+ __get_user_asm(tmp, (const u64 __user *)src,
19314 ret, "q", "", "=r", 8);
19315 if (likely(!ret))
19316 __put_user_asm(tmp, (u64 __user *)dst,
19317@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19318 return ret;
19319 }
19320 default:
19321- return copy_user_generic((__force void *)dst,
19322- (__force void *)src, size);
19323+ return copy_user_generic((__force_kernel void *)____m(dst),
19324+ (__force_kernel const void *)____m(src), size);
19325 }
19326 }
19327
19328-static __must_check __always_inline int
19329-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19330+static __must_check __always_inline unsigned long
19331+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19332 {
19333- return copy_user_generic(dst, (__force const void *)src, size);
19334+ if (size > INT_MAX)
19335+ return size;
19336+
19337+#ifdef CONFIG_PAX_MEMORY_UDEREF
19338+ if (!__access_ok(VERIFY_READ, src, size))
19339+ return size;
19340+#endif
19341+
19342+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19343 }
19344
19345-static __must_check __always_inline int
19346-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19347+static __must_check __always_inline unsigned long
19348+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19349 {
19350- return copy_user_generic((__force void *)dst, src, size);
19351+ if (size > INT_MAX)
19352+ return size;
19353+
19354+#ifdef CONFIG_PAX_MEMORY_UDEREF
19355+ if (!__access_ok(VERIFY_WRITE, dst, size))
19356+ return size;
19357+#endif
19358+
19359+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19360 }
19361
19362-extern long __copy_user_nocache(void *dst, const void __user *src,
19363- unsigned size, int zerorest);
19364+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19365+ unsigned long size, int zerorest);
19366
19367-static inline int
19368-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19369+static inline unsigned long
19370+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19371 {
19372 might_fault();
19373+
19374+ if (size > INT_MAX)
19375+ return size;
19376+
19377+#ifdef CONFIG_PAX_MEMORY_UDEREF
19378+ if (!__access_ok(VERIFY_READ, src, size))
19379+ return size;
19380+#endif
19381+
19382 return __copy_user_nocache(dst, src, size, 1);
19383 }
19384
19385-static inline int
19386+static inline unsigned long
19387 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19388- unsigned size)
19389+ unsigned long size)
19390 {
19391+ if (size > INT_MAX)
19392+ return size;
19393+
19394+#ifdef CONFIG_PAX_MEMORY_UDEREF
19395+ if (!__access_ok(VERIFY_READ, src, size))
19396+ return size;
19397+#endif
19398+
19399 return __copy_user_nocache(dst, src, size, 0);
19400 }
19401
19402 unsigned long
19403-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19404+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19405
19406 #endif /* _ASM_X86_UACCESS_64_H */
19407diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19408index 5b238981..77fdd78 100644
19409--- a/arch/x86/include/asm/word-at-a-time.h
19410+++ b/arch/x86/include/asm/word-at-a-time.h
19411@@ -11,7 +11,7 @@
19412 * and shift, for example.
19413 */
19414 struct word_at_a_time {
19415- const unsigned long one_bits, high_bits;
19416+ unsigned long one_bits, high_bits;
19417 };
19418
19419 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19420diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19421index 828a156..650e625 100644
19422--- a/arch/x86/include/asm/x86_init.h
19423+++ b/arch/x86/include/asm/x86_init.h
19424@@ -129,7 +129,7 @@ struct x86_init_ops {
19425 struct x86_init_timers timers;
19426 struct x86_init_iommu iommu;
19427 struct x86_init_pci pci;
19428-};
19429+} __no_const;
19430
19431 /**
19432 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19433@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19434 void (*setup_percpu_clockev)(void);
19435 void (*early_percpu_clock_init)(void);
19436 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19437-};
19438+} __no_const;
19439
19440 struct timespec;
19441
19442@@ -168,7 +168,7 @@ struct x86_platform_ops {
19443 void (*save_sched_clock_state)(void);
19444 void (*restore_sched_clock_state)(void);
19445 void (*apic_post_init)(void);
19446-};
19447+} __no_const;
19448
19449 struct pci_dev;
19450 struct msi_msg;
19451@@ -182,7 +182,7 @@ struct x86_msi_ops {
19452 void (*teardown_msi_irqs)(struct pci_dev *dev);
19453 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
19454 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19455-};
19456+} __no_const;
19457
19458 struct IO_APIC_route_entry;
19459 struct io_apic_irq_attr;
19460@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
19461 unsigned int destination, int vector,
19462 struct io_apic_irq_attr *attr);
19463 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19464-};
19465+} __no_const;
19466
19467 extern struct x86_init_ops x86_init;
19468 extern struct x86_cpuinit_ops x86_cpuinit;
19469diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19470index b913915..4f5a581 100644
19471--- a/arch/x86/include/asm/xen/page.h
19472+++ b/arch/x86/include/asm/xen/page.h
19473@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19474 extern struct page *m2p_find_override(unsigned long mfn);
19475 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19476
19477-static inline unsigned long pfn_to_mfn(unsigned long pfn)
19478+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19479 {
19480 unsigned long mfn;
19481
19482diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19483index 0415cda..3b22adc 100644
19484--- a/arch/x86/include/asm/xsave.h
19485+++ b/arch/x86/include/asm/xsave.h
19486@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19487 if (unlikely(err))
19488 return -EFAULT;
19489
19490+ pax_open_userland();
19491 __asm__ __volatile__(ASM_STAC "\n"
19492- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19493+ "1:"
19494+ __copyuser_seg
19495+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19496 "2: " ASM_CLAC "\n"
19497 ".section .fixup,\"ax\"\n"
19498 "3: movl $-1,%[err]\n"
19499@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19500 : [err] "=r" (err)
19501 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19502 : "memory");
19503+ pax_close_userland();
19504 return err;
19505 }
19506
19507 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19508 {
19509 int err;
19510- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19511+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19512 u32 lmask = mask;
19513 u32 hmask = mask >> 32;
19514
19515+ pax_open_userland();
19516 __asm__ __volatile__(ASM_STAC "\n"
19517- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19518+ "1:"
19519+ __copyuser_seg
19520+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19521 "2: " ASM_CLAC "\n"
19522 ".section .fixup,\"ax\"\n"
19523 "3: movl $-1,%[err]\n"
19524@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19525 : [err] "=r" (err)
19526 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19527 : "memory"); /* memory required? */
19528+ pax_close_userland();
19529 return err;
19530 }
19531
19532diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19533index bbae024..e1528f9 100644
19534--- a/arch/x86/include/uapi/asm/e820.h
19535+++ b/arch/x86/include/uapi/asm/e820.h
19536@@ -63,7 +63,7 @@ struct e820map {
19537 #define ISA_START_ADDRESS 0xa0000
19538 #define ISA_END_ADDRESS 0x100000
19539
19540-#define BIOS_BEGIN 0x000a0000
19541+#define BIOS_BEGIN 0x000c0000
19542 #define BIOS_END 0x00100000
19543
19544 #define BIOS_ROM_BASE 0xffe00000
19545diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19546index 7b0a55a..ad115bf 100644
19547--- a/arch/x86/include/uapi/asm/ptrace-abi.h
19548+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19549@@ -49,7 +49,6 @@
19550 #define EFLAGS 144
19551 #define RSP 152
19552 #define SS 160
19553-#define ARGOFFSET R11
19554 #endif /* __ASSEMBLY__ */
19555
19556 /* top of stack page */
19557diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19558index a5408b9..5133813 100644
19559--- a/arch/x86/kernel/Makefile
19560+++ b/arch/x86/kernel/Makefile
19561@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19562 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19563 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19564 obj-y += probe_roms.o
19565-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19566+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19567 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19568 obj-y += syscall_$(BITS).o
19569 obj-$(CONFIG_X86_64) += vsyscall_64.o
19570diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19571index 40c7660..f709f4b 100644
19572--- a/arch/x86/kernel/acpi/boot.c
19573+++ b/arch/x86/kernel/acpi/boot.c
19574@@ -1365,7 +1365,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19575 * If your system is blacklisted here, but you find that acpi=force
19576 * works for you, please contact linux-acpi@vger.kernel.org
19577 */
19578-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19579+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19580 /*
19581 * Boxes that need ACPI disabled
19582 */
19583@@ -1440,7 +1440,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19584 };
19585
19586 /* second table for DMI checks that should run after early-quirks */
19587-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19588+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19589 /*
19590 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19591 * which includes some code which overrides all temperature
19592diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19593index 3312010..a65ca7b 100644
19594--- a/arch/x86/kernel/acpi/sleep.c
19595+++ b/arch/x86/kernel/acpi/sleep.c
19596@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
19597 #else /* CONFIG_64BIT */
19598 #ifdef CONFIG_SMP
19599 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19600+
19601+ pax_open_kernel();
19602 early_gdt_descr.address =
19603 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19604+ pax_close_kernel();
19605+
19606 initial_gs = per_cpu_offset(smp_processor_id());
19607 #endif
19608 initial_code = (unsigned long)wakeup_long64;
19609diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19610index d1daa66..59fecba 100644
19611--- a/arch/x86/kernel/acpi/wakeup_32.S
19612+++ b/arch/x86/kernel/acpi/wakeup_32.S
19613@@ -29,13 +29,11 @@ wakeup_pmode_return:
19614 # and restore the stack ... but you need gdt for this to work
19615 movl saved_context_esp, %esp
19616
19617- movl %cs:saved_magic, %eax
19618- cmpl $0x12345678, %eax
19619+ cmpl $0x12345678, saved_magic
19620 jne bogus_magic
19621
19622 # jump to place where we left off
19623- movl saved_eip, %eax
19624- jmp *%eax
19625+ jmp *(saved_eip)
19626
19627 bogus_magic:
19628 jmp bogus_magic
19629diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19630index 15e8563..323cbe1 100644
19631--- a/arch/x86/kernel/alternative.c
19632+++ b/arch/x86/kernel/alternative.c
19633@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19634 */
19635 for (a = start; a < end; a++) {
19636 instr = (u8 *)&a->instr_offset + a->instr_offset;
19637+
19638+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19639+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19640+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19641+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19642+#endif
19643+
19644 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19645 BUG_ON(a->replacementlen > a->instrlen);
19646 BUG_ON(a->instrlen > sizeof(insnbuf));
19647@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19648 for (poff = start; poff < end; poff++) {
19649 u8 *ptr = (u8 *)poff + *poff;
19650
19651+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19652+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19653+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19654+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19655+#endif
19656+
19657 if (!*poff || ptr < text || ptr >= text_end)
19658 continue;
19659 /* turn DS segment override prefix into lock prefix */
19660- if (*ptr == 0x3e)
19661+ if (*ktla_ktva(ptr) == 0x3e)
19662 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19663 }
19664 mutex_unlock(&text_mutex);
19665@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19666 for (poff = start; poff < end; poff++) {
19667 u8 *ptr = (u8 *)poff + *poff;
19668
19669+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19670+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19671+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19672+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19673+#endif
19674+
19675 if (!*poff || ptr < text || ptr >= text_end)
19676 continue;
19677 /* turn lock prefix into DS segment override prefix */
19678- if (*ptr == 0xf0)
19679+ if (*ktla_ktva(ptr) == 0xf0)
19680 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19681 }
19682 mutex_unlock(&text_mutex);
19683@@ -469,7 +488,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19684
19685 BUG_ON(p->len > MAX_PATCH_LEN);
19686 /* prep the buffer with the original instructions */
19687- memcpy(insnbuf, p->instr, p->len);
19688+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19689 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19690 (unsigned long)p->instr, p->len);
19691
19692@@ -516,7 +535,7 @@ void __init alternative_instructions(void)
19693 if (!uniproc_patched || num_possible_cpus() == 1)
19694 free_init_pages("SMP alternatives",
19695 (unsigned long)__smp_locks,
19696- (unsigned long)__smp_locks_end);
19697+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19698 #endif
19699
19700 apply_paravirt(__parainstructions, __parainstructions_end);
19701@@ -536,13 +555,17 @@ void __init alternative_instructions(void)
19702 * instructions. And on the local CPU you need to be protected again NMI or MCE
19703 * handlers seeing an inconsistent instruction while you patch.
19704 */
19705-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19706+void *__kprobes text_poke_early(void *addr, const void *opcode,
19707 size_t len)
19708 {
19709 unsigned long flags;
19710 local_irq_save(flags);
19711- memcpy(addr, opcode, len);
19712+
19713+ pax_open_kernel();
19714+ memcpy(ktla_ktva(addr), opcode, len);
19715 sync_core();
19716+ pax_close_kernel();
19717+
19718 local_irq_restore(flags);
19719 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19720 that causes hangs on some VIA CPUs. */
19721@@ -564,36 +587,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19722 */
19723 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19724 {
19725- unsigned long flags;
19726- char *vaddr;
19727+ unsigned char *vaddr = ktla_ktva(addr);
19728 struct page *pages[2];
19729- int i;
19730+ size_t i;
19731
19732 if (!core_kernel_text((unsigned long)addr)) {
19733- pages[0] = vmalloc_to_page(addr);
19734- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19735+ pages[0] = vmalloc_to_page(vaddr);
19736+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19737 } else {
19738- pages[0] = virt_to_page(addr);
19739+ pages[0] = virt_to_page(vaddr);
19740 WARN_ON(!PageReserved(pages[0]));
19741- pages[1] = virt_to_page(addr + PAGE_SIZE);
19742+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19743 }
19744 BUG_ON(!pages[0]);
19745- local_irq_save(flags);
19746- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19747- if (pages[1])
19748- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19749- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19750- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19751- clear_fixmap(FIX_TEXT_POKE0);
19752- if (pages[1])
19753- clear_fixmap(FIX_TEXT_POKE1);
19754- local_flush_tlb();
19755- sync_core();
19756- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19757- that causes hangs on some VIA CPUs. */
19758+ text_poke_early(addr, opcode, len);
19759 for (i = 0; i < len; i++)
19760- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19761- local_irq_restore(flags);
19762+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19763 return addr;
19764 }
19765
19766@@ -613,7 +622,7 @@ int poke_int3_handler(struct pt_regs *regs)
19767 if (likely(!bp_patching_in_progress))
19768 return 0;
19769
19770- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19771+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19772 return 0;
19773
19774 /* set up the specified breakpoint handler */
19775@@ -647,7 +656,7 @@ int poke_int3_handler(struct pt_regs *regs)
19776 */
19777 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19778 {
19779- unsigned char int3 = 0xcc;
19780+ const unsigned char int3 = 0xcc;
19781
19782 bp_int3_handler = handler;
19783 bp_int3_addr = (u8 *)addr + sizeof(int3);
19784diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19785index a7eb82d..f6e52d4 100644
19786--- a/arch/x86/kernel/apic/apic.c
19787+++ b/arch/x86/kernel/apic/apic.c
19788@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19789 /*
19790 * Debug level, exported for io_apic.c
19791 */
19792-unsigned int apic_verbosity;
19793+int apic_verbosity;
19794
19795 int pic_mode;
19796
19797@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19798 apic_write(APIC_ESR, 0);
19799 v1 = apic_read(APIC_ESR);
19800 ack_APIC_irq();
19801- atomic_inc(&irq_err_count);
19802+ atomic_inc_unchecked(&irq_err_count);
19803
19804 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19805 smp_processor_id(), v0 , v1);
19806diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19807index 00c77cf..2dc6a2d 100644
19808--- a/arch/x86/kernel/apic/apic_flat_64.c
19809+++ b/arch/x86/kernel/apic/apic_flat_64.c
19810@@ -157,7 +157,7 @@ static int flat_probe(void)
19811 return 1;
19812 }
19813
19814-static struct apic apic_flat = {
19815+static struct apic apic_flat __read_only = {
19816 .name = "flat",
19817 .probe = flat_probe,
19818 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19819@@ -271,7 +271,7 @@ static int physflat_probe(void)
19820 return 0;
19821 }
19822
19823-static struct apic apic_physflat = {
19824+static struct apic apic_physflat __read_only = {
19825
19826 .name = "physical flat",
19827 .probe = physflat_probe,
19828diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19829index e145f28..2752888 100644
19830--- a/arch/x86/kernel/apic/apic_noop.c
19831+++ b/arch/x86/kernel/apic/apic_noop.c
19832@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19833 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19834 }
19835
19836-struct apic apic_noop = {
19837+struct apic apic_noop __read_only = {
19838 .name = "noop",
19839 .probe = noop_probe,
19840 .acpi_madt_oem_check = NULL,
19841diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19842index d50e364..543bee3 100644
19843--- a/arch/x86/kernel/apic/bigsmp_32.c
19844+++ b/arch/x86/kernel/apic/bigsmp_32.c
19845@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19846 return dmi_bigsmp;
19847 }
19848
19849-static struct apic apic_bigsmp = {
19850+static struct apic apic_bigsmp __read_only = {
19851
19852 .name = "bigsmp",
19853 .probe = probe_bigsmp,
19854diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19855index c552247..587a316 100644
19856--- a/arch/x86/kernel/apic/es7000_32.c
19857+++ b/arch/x86/kernel/apic/es7000_32.c
19858@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19859 return ret && es7000_apic_is_cluster();
19860 }
19861
19862-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19863-static struct apic __refdata apic_es7000_cluster = {
19864+static struct apic apic_es7000_cluster __read_only = {
19865
19866 .name = "es7000",
19867 .probe = probe_es7000,
19868@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19869 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19870 };
19871
19872-static struct apic __refdata apic_es7000 = {
19873+static struct apic apic_es7000 __read_only = {
19874
19875 .name = "es7000",
19876 .probe = probe_es7000,
19877diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19878index e63a5bd..c0babf8 100644
19879--- a/arch/x86/kernel/apic/io_apic.c
19880+++ b/arch/x86/kernel/apic/io_apic.c
19881@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19882 }
19883 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19884
19885-void lock_vector_lock(void)
19886+void lock_vector_lock(void) __acquires(vector_lock)
19887 {
19888 /* Used to the online set of cpus does not change
19889 * during assign_irq_vector.
19890@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19891 raw_spin_lock(&vector_lock);
19892 }
19893
19894-void unlock_vector_lock(void)
19895+void unlock_vector_lock(void) __releases(vector_lock)
19896 {
19897 raw_spin_unlock(&vector_lock);
19898 }
19899@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
19900 ack_APIC_irq();
19901 }
19902
19903-atomic_t irq_mis_count;
19904+atomic_unchecked_t irq_mis_count;
19905
19906 #ifdef CONFIG_GENERIC_PENDING_IRQ
19907 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19908@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
19909 * at the cpu.
19910 */
19911 if (!(v & (1 << (i & 0x1f)))) {
19912- atomic_inc(&irq_mis_count);
19913+ atomic_inc_unchecked(&irq_mis_count);
19914
19915 eoi_ioapic_irq(irq, cfg);
19916 }
19917diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19918index 1e42e8f..daacf44 100644
19919--- a/arch/x86/kernel/apic/numaq_32.c
19920+++ b/arch/x86/kernel/apic/numaq_32.c
19921@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19922 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19923 }
19924
19925-/* Use __refdata to keep false positive warning calm. */
19926-static struct apic __refdata apic_numaq = {
19927+static struct apic apic_numaq __read_only = {
19928
19929 .name = "NUMAQ",
19930 .probe = probe_numaq,
19931diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19932index eb35ef9..f184a21 100644
19933--- a/arch/x86/kernel/apic/probe_32.c
19934+++ b/arch/x86/kernel/apic/probe_32.c
19935@@ -72,7 +72,7 @@ static int probe_default(void)
19936 return 1;
19937 }
19938
19939-static struct apic apic_default = {
19940+static struct apic apic_default __read_only = {
19941
19942 .name = "default",
19943 .probe = probe_default,
19944diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19945index 77c95c0..434f8a4 100644
19946--- a/arch/x86/kernel/apic/summit_32.c
19947+++ b/arch/x86/kernel/apic/summit_32.c
19948@@ -486,7 +486,7 @@ void setup_summit(void)
19949 }
19950 #endif
19951
19952-static struct apic apic_summit = {
19953+static struct apic apic_summit __read_only = {
19954
19955 .name = "summit",
19956 .probe = probe_summit,
19957diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19958index 140e29d..d88bc95 100644
19959--- a/arch/x86/kernel/apic/x2apic_cluster.c
19960+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19961@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19962 return notifier_from_errno(err);
19963 }
19964
19965-static struct notifier_block __refdata x2apic_cpu_notifier = {
19966+static struct notifier_block x2apic_cpu_notifier = {
19967 .notifier_call = update_clusterinfo,
19968 };
19969
19970@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19971 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19972 }
19973
19974-static struct apic apic_x2apic_cluster = {
19975+static struct apic apic_x2apic_cluster __read_only = {
19976
19977 .name = "cluster x2apic",
19978 .probe = x2apic_cluster_probe,
19979diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19980index 562a76d..a003c0f 100644
19981--- a/arch/x86/kernel/apic/x2apic_phys.c
19982+++ b/arch/x86/kernel/apic/x2apic_phys.c
19983@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19984 return apic == &apic_x2apic_phys;
19985 }
19986
19987-static struct apic apic_x2apic_phys = {
19988+static struct apic apic_x2apic_phys __read_only = {
19989
19990 .name = "physical x2apic",
19991 .probe = x2apic_phys_probe,
19992diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19993index a419814..1dd34a0 100644
19994--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19995+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19996@@ -357,7 +357,7 @@ static int uv_probe(void)
19997 return apic == &apic_x2apic_uv_x;
19998 }
19999
20000-static struct apic __refdata apic_x2apic_uv_x = {
20001+static struct apic apic_x2apic_uv_x __read_only = {
20002
20003 .name = "UV large system",
20004 .probe = uv_probe,
20005diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20006index 3ab0343..814c4787 100644
20007--- a/arch/x86/kernel/apm_32.c
20008+++ b/arch/x86/kernel/apm_32.c
20009@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20010 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20011 * even though they are called in protected mode.
20012 */
20013-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20014+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20015 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20016
20017 static const char driver_version[] = "1.16ac"; /* no spaces */
20018@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20019 BUG_ON(cpu != 0);
20020 gdt = get_cpu_gdt_table(cpu);
20021 save_desc_40 = gdt[0x40 / 8];
20022+
20023+ pax_open_kernel();
20024 gdt[0x40 / 8] = bad_bios_desc;
20025+ pax_close_kernel();
20026
20027 apm_irq_save(flags);
20028 APM_DO_SAVE_SEGS;
20029@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20030 &call->esi);
20031 APM_DO_RESTORE_SEGS;
20032 apm_irq_restore(flags);
20033+
20034+ pax_open_kernel();
20035 gdt[0x40 / 8] = save_desc_40;
20036+ pax_close_kernel();
20037+
20038 put_cpu();
20039
20040 return call->eax & 0xff;
20041@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20042 BUG_ON(cpu != 0);
20043 gdt = get_cpu_gdt_table(cpu);
20044 save_desc_40 = gdt[0x40 / 8];
20045+
20046+ pax_open_kernel();
20047 gdt[0x40 / 8] = bad_bios_desc;
20048+ pax_close_kernel();
20049
20050 apm_irq_save(flags);
20051 APM_DO_SAVE_SEGS;
20052@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20053 &call->eax);
20054 APM_DO_RESTORE_SEGS;
20055 apm_irq_restore(flags);
20056+
20057+ pax_open_kernel();
20058 gdt[0x40 / 8] = save_desc_40;
20059+ pax_close_kernel();
20060+
20061 put_cpu();
20062 return error;
20063 }
20064@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20065 * code to that CPU.
20066 */
20067 gdt = get_cpu_gdt_table(0);
20068+
20069+ pax_open_kernel();
20070 set_desc_base(&gdt[APM_CS >> 3],
20071 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20072 set_desc_base(&gdt[APM_CS_16 >> 3],
20073 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20074 set_desc_base(&gdt[APM_DS >> 3],
20075 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20076+ pax_close_kernel();
20077
20078 proc_create("apm", 0, NULL, &apm_file_ops);
20079
20080diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20081index 2861082..6d4718e 100644
20082--- a/arch/x86/kernel/asm-offsets.c
20083+++ b/arch/x86/kernel/asm-offsets.c
20084@@ -33,6 +33,8 @@ void common(void) {
20085 OFFSET(TI_status, thread_info, status);
20086 OFFSET(TI_addr_limit, thread_info, addr_limit);
20087 OFFSET(TI_preempt_count, thread_info, preempt_count);
20088+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20089+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20090
20091 BLANK();
20092 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20093@@ -53,8 +55,26 @@ void common(void) {
20094 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20095 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20096 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20097+
20098+#ifdef CONFIG_PAX_KERNEXEC
20099+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20100 #endif
20101
20102+#ifdef CONFIG_PAX_MEMORY_UDEREF
20103+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20104+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20105+#ifdef CONFIG_X86_64
20106+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20107+#endif
20108+#endif
20109+
20110+#endif
20111+
20112+ BLANK();
20113+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20114+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20115+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20116+
20117 #ifdef CONFIG_XEN
20118 BLANK();
20119 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20120diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20121index e7c798b..2b2019b 100644
20122--- a/arch/x86/kernel/asm-offsets_64.c
20123+++ b/arch/x86/kernel/asm-offsets_64.c
20124@@ -77,6 +77,7 @@ int main(void)
20125 BLANK();
20126 #undef ENTRY
20127
20128+ DEFINE(TSS_size, sizeof(struct tss_struct));
20129 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20130 BLANK();
20131
20132diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20133index 47b56a7..efc2bc6 100644
20134--- a/arch/x86/kernel/cpu/Makefile
20135+++ b/arch/x86/kernel/cpu/Makefile
20136@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20137 CFLAGS_REMOVE_perf_event.o = -pg
20138 endif
20139
20140-# Make sure load_percpu_segment has no stackprotector
20141-nostackp := $(call cc-option, -fno-stack-protector)
20142-CFLAGS_common.o := $(nostackp)
20143-
20144 obj-y := intel_cacheinfo.o scattered.o topology.o
20145 obj-y += proc.o capflags.o powerflags.o common.o
20146 obj-y += rdrand.o
20147diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20148index 903a264..fc955f3 100644
20149--- a/arch/x86/kernel/cpu/amd.c
20150+++ b/arch/x86/kernel/cpu/amd.c
20151@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20152 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20153 {
20154 /* AMD errata T13 (order #21922) */
20155- if ((c->x86 == 6)) {
20156+ if (c->x86 == 6) {
20157 /* Duron Rev A0 */
20158 if (c->x86_model == 3 && c->x86_mask == 0)
20159 size = 64;
20160diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20161index 2793d1f..b4f313a 100644
20162--- a/arch/x86/kernel/cpu/common.c
20163+++ b/arch/x86/kernel/cpu/common.c
20164@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20165
20166 static const struct cpu_dev *this_cpu = &default_cpu;
20167
20168-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20169-#ifdef CONFIG_X86_64
20170- /*
20171- * We need valid kernel segments for data and code in long mode too
20172- * IRET will check the segment types kkeil 2000/10/28
20173- * Also sysret mandates a special GDT layout
20174- *
20175- * TLS descriptors are currently at a different place compared to i386.
20176- * Hopefully nobody expects them at a fixed place (Wine?)
20177- */
20178- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20179- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20180- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20181- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20182- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20183- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20184-#else
20185- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20186- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20187- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20188- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20189- /*
20190- * Segments used for calling PnP BIOS have byte granularity.
20191- * They code segments and data segments have fixed 64k limits,
20192- * the transfer segment sizes are set at run time.
20193- */
20194- /* 32-bit code */
20195- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20196- /* 16-bit code */
20197- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20198- /* 16-bit data */
20199- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20200- /* 16-bit data */
20201- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20202- /* 16-bit data */
20203- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20204- /*
20205- * The APM segments have byte granularity and their bases
20206- * are set at run time. All have 64k limits.
20207- */
20208- /* 32-bit code */
20209- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20210- /* 16-bit code */
20211- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20212- /* data */
20213- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20214-
20215- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20216- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20217- GDT_STACK_CANARY_INIT
20218-#endif
20219-} };
20220-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20221-
20222 static int __init x86_xsave_setup(char *s)
20223 {
20224 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20225@@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20226 set_in_cr4(X86_CR4_SMAP);
20227 }
20228
20229+#ifdef CONFIG_X86_64
20230+static __init int setup_disable_pcid(char *arg)
20231+{
20232+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20233+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20234+
20235+#ifdef CONFIG_PAX_MEMORY_UDEREF
20236+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20237+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20238+#endif
20239+
20240+ return 1;
20241+}
20242+__setup("nopcid", setup_disable_pcid);
20243+
20244+static void setup_pcid(struct cpuinfo_x86 *c)
20245+{
20246+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20247+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20248+
20249+#ifdef CONFIG_PAX_MEMORY_UDEREF
20250+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20251+ pax_open_kernel();
20252+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20253+ pax_close_kernel();
20254+ printk("PAX: slow and weak UDEREF enabled\n");
20255+ } else
20256+ printk("PAX: UDEREF disabled\n");
20257+#endif
20258+
20259+ return;
20260+ }
20261+
20262+ printk("PAX: PCID detected\n");
20263+ set_in_cr4(X86_CR4_PCIDE);
20264+
20265+#ifdef CONFIG_PAX_MEMORY_UDEREF
20266+ pax_open_kernel();
20267+ clone_pgd_mask = ~(pgdval_t)0UL;
20268+ pax_close_kernel();
20269+ if (pax_user_shadow_base)
20270+ printk("PAX: weak UDEREF enabled\n");
20271+ else {
20272+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20273+ printk("PAX: strong UDEREF enabled\n");
20274+ }
20275+#endif
20276+
20277+ if (cpu_has(c, X86_FEATURE_INVPCID))
20278+ printk("PAX: INVPCID detected\n");
20279+}
20280+#endif
20281+
20282 /*
20283 * Some CPU features depend on higher CPUID levels, which may not always
20284 * be available due to CPUID level capping or broken virtualization
20285@@ -386,7 +385,7 @@ void switch_to_new_gdt(int cpu)
20286 {
20287 struct desc_ptr gdt_descr;
20288
20289- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20290+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20291 gdt_descr.size = GDT_SIZE - 1;
20292 load_gdt(&gdt_descr);
20293 /* Reload the per-cpu base */
20294@@ -875,6 +874,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20295 setup_smep(c);
20296 setup_smap(c);
20297
20298+#ifdef CONFIG_X86_64
20299+ setup_pcid(c);
20300+#endif
20301+
20302 /*
20303 * The vendor-specific functions might have changed features.
20304 * Now we do "generic changes."
20305@@ -883,6 +886,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20306 /* Filter out anything that depends on CPUID levels we don't have */
20307 filter_cpuid_features(c, true);
20308
20309+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20310+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20311+#endif
20312+
20313 /* If the model name is still unset, do table lookup. */
20314 if (!c->x86_model_id[0]) {
20315 const char *p;
20316@@ -1070,10 +1077,12 @@ static __init int setup_disablecpuid(char *arg)
20317 }
20318 __setup("clearcpuid=", setup_disablecpuid);
20319
20320+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20321+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20322+
20323 #ifdef CONFIG_X86_64
20324-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20325-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20326- (unsigned long) debug_idt_table };
20327+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20328+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20329
20330 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20331 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20332@@ -1087,7 +1096,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20333 EXPORT_PER_CPU_SYMBOL(current_task);
20334
20335 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20336- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20337+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20338 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20339
20340 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20341@@ -1232,7 +1241,7 @@ void cpu_init(void)
20342 load_ucode_ap();
20343
20344 cpu = stack_smp_processor_id();
20345- t = &per_cpu(init_tss, cpu);
20346+ t = init_tss + cpu;
20347 oist = &per_cpu(orig_ist, cpu);
20348
20349 #ifdef CONFIG_NUMA
20350@@ -1267,7 +1276,6 @@ void cpu_init(void)
20351 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20352 barrier();
20353
20354- x86_configure_nx();
20355 enable_x2apic();
20356
20357 /*
20358@@ -1319,7 +1327,7 @@ void cpu_init(void)
20359 {
20360 int cpu = smp_processor_id();
20361 struct task_struct *curr = current;
20362- struct tss_struct *t = &per_cpu(init_tss, cpu);
20363+ struct tss_struct *t = init_tss + cpu;
20364 struct thread_struct *thread = &curr->thread;
20365
20366 show_ucode_info_early();
20367diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20368index 1414c90..1159406 100644
20369--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20370+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20371@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20372 };
20373
20374 #ifdef CONFIG_AMD_NB
20375+static struct attribute *default_attrs_amd_nb[] = {
20376+ &type.attr,
20377+ &level.attr,
20378+ &coherency_line_size.attr,
20379+ &physical_line_partition.attr,
20380+ &ways_of_associativity.attr,
20381+ &number_of_sets.attr,
20382+ &size.attr,
20383+ &shared_cpu_map.attr,
20384+ &shared_cpu_list.attr,
20385+ NULL,
20386+ NULL,
20387+ NULL,
20388+ NULL
20389+};
20390+
20391 static struct attribute **amd_l3_attrs(void)
20392 {
20393 static struct attribute **attrs;
20394@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20395
20396 n = ARRAY_SIZE(default_attrs);
20397
20398- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20399- n += 2;
20400-
20401- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20402- n += 1;
20403-
20404- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20405- if (attrs == NULL)
20406- return attrs = default_attrs;
20407-
20408- for (n = 0; default_attrs[n]; n++)
20409- attrs[n] = default_attrs[n];
20410+ attrs = default_attrs_amd_nb;
20411
20412 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20413 attrs[n++] = &cache_disable_0.attr;
20414@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20415 .default_attrs = default_attrs,
20416 };
20417
20418+#ifdef CONFIG_AMD_NB
20419+static struct kobj_type ktype_cache_amd_nb = {
20420+ .sysfs_ops = &sysfs_ops,
20421+ .default_attrs = default_attrs_amd_nb,
20422+};
20423+#endif
20424+
20425 static struct kobj_type ktype_percpu_entry = {
20426 .sysfs_ops = &sysfs_ops,
20427 };
20428@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20429 return retval;
20430 }
20431
20432+#ifdef CONFIG_AMD_NB
20433+ amd_l3_attrs();
20434+#endif
20435+
20436 for (i = 0; i < num_cache_leaves; i++) {
20437+ struct kobj_type *ktype;
20438+
20439 this_object = INDEX_KOBJECT_PTR(cpu, i);
20440 this_object->cpu = cpu;
20441 this_object->index = i;
20442
20443 this_leaf = CPUID4_INFO_IDX(cpu, i);
20444
20445- ktype_cache.default_attrs = default_attrs;
20446+ ktype = &ktype_cache;
20447 #ifdef CONFIG_AMD_NB
20448 if (this_leaf->base.nb)
20449- ktype_cache.default_attrs = amd_l3_attrs();
20450+ ktype = &ktype_cache_amd_nb;
20451 #endif
20452 retval = kobject_init_and_add(&(this_object->kobj),
20453- &ktype_cache,
20454+ ktype,
20455 per_cpu(ici_cache_kobject, cpu),
20456 "index%1lu", i);
20457 if (unlikely(retval)) {
20458diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20459index b3218cd..99a75de 100644
20460--- a/arch/x86/kernel/cpu/mcheck/mce.c
20461+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20462@@ -45,6 +45,7 @@
20463 #include <asm/processor.h>
20464 #include <asm/mce.h>
20465 #include <asm/msr.h>
20466+#include <asm/local.h>
20467
20468 #include "mce-internal.h"
20469
20470@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20471 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20472 m->cs, m->ip);
20473
20474- if (m->cs == __KERNEL_CS)
20475+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20476 print_symbol("{%s}", m->ip);
20477 pr_cont("\n");
20478 }
20479@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20480
20481 #define PANIC_TIMEOUT 5 /* 5 seconds */
20482
20483-static atomic_t mce_paniced;
20484+static atomic_unchecked_t mce_paniced;
20485
20486 static int fake_panic;
20487-static atomic_t mce_fake_paniced;
20488+static atomic_unchecked_t mce_fake_paniced;
20489
20490 /* Panic in progress. Enable interrupts and wait for final IPI */
20491 static void wait_for_panic(void)
20492@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20493 /*
20494 * Make sure only one CPU runs in machine check panic
20495 */
20496- if (atomic_inc_return(&mce_paniced) > 1)
20497+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20498 wait_for_panic();
20499 barrier();
20500
20501@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20502 console_verbose();
20503 } else {
20504 /* Don't log too much for fake panic */
20505- if (atomic_inc_return(&mce_fake_paniced) > 1)
20506+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20507 return;
20508 }
20509 /* First print corrected ones that are still unlogged */
20510@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20511 if (!fake_panic) {
20512 if (panic_timeout == 0)
20513 panic_timeout = mca_cfg.panic_timeout;
20514- panic(msg);
20515+ panic("%s", msg);
20516 } else
20517 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20518 }
20519@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20520 * might have been modified by someone else.
20521 */
20522 rmb();
20523- if (atomic_read(&mce_paniced))
20524+ if (atomic_read_unchecked(&mce_paniced))
20525 wait_for_panic();
20526 if (!mca_cfg.monarch_timeout)
20527 goto out;
20528@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20529 }
20530
20531 /* Call the installed machine check handler for this CPU setup. */
20532-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20533+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20534 unexpected_machine_check;
20535
20536 /*
20537@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20538 return;
20539 }
20540
20541+ pax_open_kernel();
20542 machine_check_vector = do_machine_check;
20543+ pax_close_kernel();
20544
20545 __mcheck_cpu_init_generic();
20546 __mcheck_cpu_init_vendor(c);
20547@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20548 */
20549
20550 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20551-static int mce_chrdev_open_count; /* #times opened */
20552+static local_t mce_chrdev_open_count; /* #times opened */
20553 static int mce_chrdev_open_exclu; /* already open exclusive? */
20554
20555 static int mce_chrdev_open(struct inode *inode, struct file *file)
20556@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20557 spin_lock(&mce_chrdev_state_lock);
20558
20559 if (mce_chrdev_open_exclu ||
20560- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20561+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20562 spin_unlock(&mce_chrdev_state_lock);
20563
20564 return -EBUSY;
20565@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20566
20567 if (file->f_flags & O_EXCL)
20568 mce_chrdev_open_exclu = 1;
20569- mce_chrdev_open_count++;
20570+ local_inc(&mce_chrdev_open_count);
20571
20572 spin_unlock(&mce_chrdev_state_lock);
20573
20574@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20575 {
20576 spin_lock(&mce_chrdev_state_lock);
20577
20578- mce_chrdev_open_count--;
20579+ local_dec(&mce_chrdev_open_count);
20580 mce_chrdev_open_exclu = 0;
20581
20582 spin_unlock(&mce_chrdev_state_lock);
20583@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20584
20585 for (i = 0; i < mca_cfg.banks; i++) {
20586 struct mce_bank *b = &mce_banks[i];
20587- struct device_attribute *a = &b->attr;
20588+ device_attribute_no_const *a = &b->attr;
20589
20590 sysfs_attr_init(&a->attr);
20591 a->attr.name = b->attrname;
20592@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20593 static void mce_reset(void)
20594 {
20595 cpu_missing = 0;
20596- atomic_set(&mce_fake_paniced, 0);
20597+ atomic_set_unchecked(&mce_fake_paniced, 0);
20598 atomic_set(&mce_executing, 0);
20599 atomic_set(&mce_callin, 0);
20600 atomic_set(&global_nwo, 0);
20601diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20602index 1c044b1..37a2a43 100644
20603--- a/arch/x86/kernel/cpu/mcheck/p5.c
20604+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20605@@ -11,6 +11,7 @@
20606 #include <asm/processor.h>
20607 #include <asm/mce.h>
20608 #include <asm/msr.h>
20609+#include <asm/pgtable.h>
20610
20611 /* By default disabled */
20612 int mce_p5_enabled __read_mostly;
20613@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20614 if (!cpu_has(c, X86_FEATURE_MCE))
20615 return;
20616
20617+ pax_open_kernel();
20618 machine_check_vector = pentium_machine_check;
20619+ pax_close_kernel();
20620 /* Make sure the vector pointer is visible before we enable MCEs: */
20621 wmb();
20622
20623diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20624index e9a701a..35317d6 100644
20625--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20626+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20627@@ -10,6 +10,7 @@
20628 #include <asm/processor.h>
20629 #include <asm/mce.h>
20630 #include <asm/msr.h>
20631+#include <asm/pgtable.h>
20632
20633 /* Machine check handler for WinChip C6: */
20634 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20635@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20636 {
20637 u32 lo, hi;
20638
20639+ pax_open_kernel();
20640 machine_check_vector = winchip_machine_check;
20641+ pax_close_kernel();
20642 /* Make sure the vector pointer is visible before we enable MCEs: */
20643 wmb();
20644
20645diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20646index f961de9..8a9d332 100644
20647--- a/arch/x86/kernel/cpu/mtrr/main.c
20648+++ b/arch/x86/kernel/cpu/mtrr/main.c
20649@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20650 u64 size_or_mask, size_and_mask;
20651 static bool mtrr_aps_delayed_init;
20652
20653-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20654+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20655
20656 const struct mtrr_ops *mtrr_if;
20657
20658diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20659index df5e41f..816c719 100644
20660--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20661+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20662@@ -25,7 +25,7 @@ struct mtrr_ops {
20663 int (*validate_add_page)(unsigned long base, unsigned long size,
20664 unsigned int type);
20665 int (*have_wrcomb)(void);
20666-};
20667+} __do_const;
20668
20669 extern int generic_get_free_region(unsigned long base, unsigned long size,
20670 int replace_reg);
20671diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20672index 8a87a32..682a22a 100644
20673--- a/arch/x86/kernel/cpu/perf_event.c
20674+++ b/arch/x86/kernel/cpu/perf_event.c
20675@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20676 pr_info("no hardware sampling interrupt available.\n");
20677 }
20678
20679-static struct attribute_group x86_pmu_format_group = {
20680+static attribute_group_no_const x86_pmu_format_group = {
20681 .name = "format",
20682 .attrs = NULL,
20683 };
20684@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20685 NULL,
20686 };
20687
20688-static struct attribute_group x86_pmu_events_group = {
20689+static attribute_group_no_const x86_pmu_events_group = {
20690 .name = "events",
20691 .attrs = events_attr,
20692 };
20693@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20694 if (idx > GDT_ENTRIES)
20695 return 0;
20696
20697- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20698+ desc = get_cpu_gdt_table(smp_processor_id());
20699 }
20700
20701 return get_desc_base(desc + idx);
20702@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20703 break;
20704
20705 perf_callchain_store(entry, frame.return_address);
20706- fp = frame.next_frame;
20707+ fp = (const void __force_user *)frame.next_frame;
20708 }
20709 }
20710
20711diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20712index 639d128..e92d7e5 100644
20713--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20714+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20715@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20716 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20717 {
20718 struct attribute **attrs;
20719- struct attribute_group *attr_group;
20720+ attribute_group_no_const *attr_group;
20721 int i = 0, j;
20722
20723 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20724diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20725index f31a165..7b46cd8 100644
20726--- a/arch/x86/kernel/cpu/perf_event_intel.c
20727+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20728@@ -2247,10 +2247,10 @@ __init int intel_pmu_init(void)
20729 * v2 and above have a perf capabilities MSR
20730 */
20731 if (version > 1) {
20732- u64 capabilities;
20733+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20734
20735- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20736- x86_pmu.intel_cap.capabilities = capabilities;
20737+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20738+ x86_pmu.intel_cap.capabilities = capabilities;
20739 }
20740
20741 intel_ds_init();
20742diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20743index 4118f9f..f91d0ab 100644
20744--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20745+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20746@@ -3204,7 +3204,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20747 static int __init uncore_type_init(struct intel_uncore_type *type)
20748 {
20749 struct intel_uncore_pmu *pmus;
20750- struct attribute_group *attr_group;
20751+ attribute_group_no_const *attr_group;
20752 struct attribute **attrs;
20753 int i, j;
20754
20755diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20756index a80ab71..4089da5 100644
20757--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20758+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20759@@ -498,7 +498,7 @@ struct intel_uncore_box {
20760 struct uncore_event_desc {
20761 struct kobj_attribute attr;
20762 const char *config;
20763-};
20764+} __do_const;
20765
20766 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20767 { \
20768diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20769index 7d9481c..99c7e4b 100644
20770--- a/arch/x86/kernel/cpuid.c
20771+++ b/arch/x86/kernel/cpuid.c
20772@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20773 return notifier_from_errno(err);
20774 }
20775
20776-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20777+static struct notifier_block cpuid_class_cpu_notifier =
20778 {
20779 .notifier_call = cpuid_class_cpu_callback,
20780 };
20781diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20782index 18677a9..f67c45b 100644
20783--- a/arch/x86/kernel/crash.c
20784+++ b/arch/x86/kernel/crash.c
20785@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20786 {
20787 #ifdef CONFIG_X86_32
20788 struct pt_regs fixed_regs;
20789-#endif
20790
20791-#ifdef CONFIG_X86_32
20792- if (!user_mode_vm(regs)) {
20793+ if (!user_mode(regs)) {
20794 crash_fixup_ss_esp(&fixed_regs, regs);
20795 regs = &fixed_regs;
20796 }
20797diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20798index afa64ad..dce67dd 100644
20799--- a/arch/x86/kernel/crash_dump_64.c
20800+++ b/arch/x86/kernel/crash_dump_64.c
20801@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20802 return -ENOMEM;
20803
20804 if (userbuf) {
20805- if (copy_to_user(buf, vaddr + offset, csize)) {
20806+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20807 iounmap(vaddr);
20808 return -EFAULT;
20809 }
20810diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20811index 5d3fe8d..02e1429 100644
20812--- a/arch/x86/kernel/doublefault.c
20813+++ b/arch/x86/kernel/doublefault.c
20814@@ -13,7 +13,7 @@
20815
20816 #define DOUBLEFAULT_STACKSIZE (1024)
20817 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20818-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20819+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20820
20821 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20822
20823@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20824 unsigned long gdt, tss;
20825
20826 native_store_gdt(&gdt_desc);
20827- gdt = gdt_desc.address;
20828+ gdt = (unsigned long)gdt_desc.address;
20829
20830 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20831
20832@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20833 /* 0x2 bit is always set */
20834 .flags = X86_EFLAGS_SF | 0x2,
20835 .sp = STACK_START,
20836- .es = __USER_DS,
20837+ .es = __KERNEL_DS,
20838 .cs = __KERNEL_CS,
20839 .ss = __KERNEL_DS,
20840- .ds = __USER_DS,
20841+ .ds = __KERNEL_DS,
20842 .fs = __KERNEL_PERCPU,
20843
20844 .__cr3 = __pa_nodebug(swapper_pg_dir),
20845diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20846index deb6421..76bbc12 100644
20847--- a/arch/x86/kernel/dumpstack.c
20848+++ b/arch/x86/kernel/dumpstack.c
20849@@ -2,6 +2,9 @@
20850 * Copyright (C) 1991, 1992 Linus Torvalds
20851 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20852 */
20853+#ifdef CONFIG_GRKERNSEC_HIDESYM
20854+#define __INCLUDED_BY_HIDESYM 1
20855+#endif
20856 #include <linux/kallsyms.h>
20857 #include <linux/kprobes.h>
20858 #include <linux/uaccess.h>
20859@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20860 static void
20861 print_ftrace_graph_addr(unsigned long addr, void *data,
20862 const struct stacktrace_ops *ops,
20863- struct thread_info *tinfo, int *graph)
20864+ struct task_struct *task, int *graph)
20865 {
20866- struct task_struct *task;
20867 unsigned long ret_addr;
20868 int index;
20869
20870 if (addr != (unsigned long)return_to_handler)
20871 return;
20872
20873- task = tinfo->task;
20874 index = task->curr_ret_stack;
20875
20876 if (!task->ret_stack || index < *graph)
20877@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20878 static inline void
20879 print_ftrace_graph_addr(unsigned long addr, void *data,
20880 const struct stacktrace_ops *ops,
20881- struct thread_info *tinfo, int *graph)
20882+ struct task_struct *task, int *graph)
20883 { }
20884 #endif
20885
20886@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20887 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20888 */
20889
20890-static inline int valid_stack_ptr(struct thread_info *tinfo,
20891- void *p, unsigned int size, void *end)
20892+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20893 {
20894- void *t = tinfo;
20895 if (end) {
20896 if (p < end && p >= (end-THREAD_SIZE))
20897 return 1;
20898@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20899 }
20900
20901 unsigned long
20902-print_context_stack(struct thread_info *tinfo,
20903+print_context_stack(struct task_struct *task, void *stack_start,
20904 unsigned long *stack, unsigned long bp,
20905 const struct stacktrace_ops *ops, void *data,
20906 unsigned long *end, int *graph)
20907 {
20908 struct stack_frame *frame = (struct stack_frame *)bp;
20909
20910- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20911+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20912 unsigned long addr;
20913
20914 addr = *stack;
20915@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20916 } else {
20917 ops->address(data, addr, 0);
20918 }
20919- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20920+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20921 }
20922 stack++;
20923 }
20924@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20925 EXPORT_SYMBOL_GPL(print_context_stack);
20926
20927 unsigned long
20928-print_context_stack_bp(struct thread_info *tinfo,
20929+print_context_stack_bp(struct task_struct *task, void *stack_start,
20930 unsigned long *stack, unsigned long bp,
20931 const struct stacktrace_ops *ops, void *data,
20932 unsigned long *end, int *graph)
20933@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20934 struct stack_frame *frame = (struct stack_frame *)bp;
20935 unsigned long *ret_addr = &frame->return_address;
20936
20937- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20938+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20939 unsigned long addr = *ret_addr;
20940
20941 if (!__kernel_text_address(addr))
20942@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20943 ops->address(data, addr, 1);
20944 frame = frame->next_frame;
20945 ret_addr = &frame->return_address;
20946- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20947+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20948 }
20949
20950 return (unsigned long)frame;
20951@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20952 static void print_trace_address(void *data, unsigned long addr, int reliable)
20953 {
20954 touch_nmi_watchdog();
20955- printk(data);
20956+ printk("%s", (char *)data);
20957 printk_address(addr, reliable);
20958 }
20959
20960@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20961 }
20962 EXPORT_SYMBOL_GPL(oops_begin);
20963
20964+extern void gr_handle_kernel_exploit(void);
20965+
20966 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20967 {
20968 if (regs && kexec_should_crash(current))
20969@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20970 panic("Fatal exception in interrupt");
20971 if (panic_on_oops)
20972 panic("Fatal exception");
20973- do_exit(signr);
20974+
20975+ gr_handle_kernel_exploit();
20976+
20977+ do_group_exit(signr);
20978 }
20979
20980 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20981@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20982 print_modules();
20983 show_regs(regs);
20984 #ifdef CONFIG_X86_32
20985- if (user_mode_vm(regs)) {
20986+ if (user_mode(regs)) {
20987 sp = regs->sp;
20988 ss = regs->ss & 0xffff;
20989 } else {
20990@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20991 unsigned long flags = oops_begin();
20992 int sig = SIGSEGV;
20993
20994- if (!user_mode_vm(regs))
20995+ if (!user_mode(regs))
20996 report_bug(regs->ip, regs);
20997
20998 if (__die(str, regs, err))
20999diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21000index f2a1770..540657f 100644
21001--- a/arch/x86/kernel/dumpstack_32.c
21002+++ b/arch/x86/kernel/dumpstack_32.c
21003@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21004 bp = stack_frame(task, regs);
21005
21006 for (;;) {
21007- struct thread_info *context;
21008+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21009
21010- context = (struct thread_info *)
21011- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21012- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21013+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21014
21015- stack = (unsigned long *)context->previous_esp;
21016- if (!stack)
21017+ if (stack_start == task_stack_page(task))
21018 break;
21019+ stack = *(unsigned long **)stack_start;
21020 if (ops->stack(data, "IRQ") < 0)
21021 break;
21022 touch_nmi_watchdog();
21023@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21024 int i;
21025
21026 show_regs_print_info(KERN_EMERG);
21027- __show_regs(regs, !user_mode_vm(regs));
21028+ __show_regs(regs, !user_mode(regs));
21029
21030 /*
21031 * When in-kernel, we also print out the stack and code at the
21032 * time of the fault..
21033 */
21034- if (!user_mode_vm(regs)) {
21035+ if (!user_mode(regs)) {
21036 unsigned int code_prologue = code_bytes * 43 / 64;
21037 unsigned int code_len = code_bytes;
21038 unsigned char c;
21039 u8 *ip;
21040+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21041
21042 pr_emerg("Stack:\n");
21043 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21044
21045 pr_emerg("Code:");
21046
21047- ip = (u8 *)regs->ip - code_prologue;
21048+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21049 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21050 /* try starting at IP */
21051- ip = (u8 *)regs->ip;
21052+ ip = (u8 *)regs->ip + cs_base;
21053 code_len = code_len - code_prologue + 1;
21054 }
21055 for (i = 0; i < code_len; i++, ip++) {
21056@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21057 pr_cont(" Bad EIP value.");
21058 break;
21059 }
21060- if (ip == (u8 *)regs->ip)
21061+ if (ip == (u8 *)regs->ip + cs_base)
21062 pr_cont(" <%02x>", c);
21063 else
21064 pr_cont(" %02x", c);
21065@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21066 {
21067 unsigned short ud2;
21068
21069+ ip = ktla_ktva(ip);
21070 if (ip < PAGE_OFFSET)
21071 return 0;
21072 if (probe_kernel_address((unsigned short *)ip, ud2))
21073@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21074
21075 return ud2 == 0x0b0f;
21076 }
21077+
21078+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21079+void pax_check_alloca(unsigned long size)
21080+{
21081+ unsigned long sp = (unsigned long)&sp, stack_left;
21082+
21083+ /* all kernel stacks are of the same size */
21084+ stack_left = sp & (THREAD_SIZE - 1);
21085+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21086+}
21087+EXPORT_SYMBOL(pax_check_alloca);
21088+#endif
21089diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21090index addb207..99635fa 100644
21091--- a/arch/x86/kernel/dumpstack_64.c
21092+++ b/arch/x86/kernel/dumpstack_64.c
21093@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21094 unsigned long *irq_stack_end =
21095 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21096 unsigned used = 0;
21097- struct thread_info *tinfo;
21098 int graph = 0;
21099 unsigned long dummy;
21100+ void *stack_start;
21101
21102 if (!task)
21103 task = current;
21104@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21105 * current stack address. If the stacks consist of nested
21106 * exceptions
21107 */
21108- tinfo = task_thread_info(task);
21109 for (;;) {
21110 char *id;
21111 unsigned long *estack_end;
21112+
21113 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21114 &used, &id);
21115
21116@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21117 if (ops->stack(data, id) < 0)
21118 break;
21119
21120- bp = ops->walk_stack(tinfo, stack, bp, ops,
21121+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21122 data, estack_end, &graph);
21123 ops->stack(data, "<EOE>");
21124 /*
21125@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21126 * second-to-last pointer (index -2 to end) in the
21127 * exception stack:
21128 */
21129+ if ((u16)estack_end[-1] != __KERNEL_DS)
21130+ goto out;
21131 stack = (unsigned long *) estack_end[-2];
21132 continue;
21133 }
21134@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21135 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21136 if (ops->stack(data, "IRQ") < 0)
21137 break;
21138- bp = ops->walk_stack(tinfo, stack, bp,
21139+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21140 ops, data, irq_stack_end, &graph);
21141 /*
21142 * We link to the next stack (which would be
21143@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21144 /*
21145 * This handles the process stack:
21146 */
21147- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21148+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21149+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21150+out:
21151 put_cpu();
21152 }
21153 EXPORT_SYMBOL(dump_trace);
21154@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21155
21156 return ud2 == 0x0b0f;
21157 }
21158+
21159+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21160+void pax_check_alloca(unsigned long size)
21161+{
21162+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21163+ unsigned cpu, used;
21164+ char *id;
21165+
21166+ /* check the process stack first */
21167+ stack_start = (unsigned long)task_stack_page(current);
21168+ stack_end = stack_start + THREAD_SIZE;
21169+ if (likely(stack_start <= sp && sp < stack_end)) {
21170+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21171+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21172+ return;
21173+ }
21174+
21175+ cpu = get_cpu();
21176+
21177+ /* check the irq stacks */
21178+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21179+ stack_start = stack_end - IRQ_STACK_SIZE;
21180+ if (stack_start <= sp && sp < stack_end) {
21181+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21182+ put_cpu();
21183+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21184+ return;
21185+ }
21186+
21187+ /* check the exception stacks */
21188+ used = 0;
21189+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21190+ stack_start = stack_end - EXCEPTION_STKSZ;
21191+ if (stack_end && stack_start <= sp && sp < stack_end) {
21192+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21193+ put_cpu();
21194+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21195+ return;
21196+ }
21197+
21198+ put_cpu();
21199+
21200+ /* unknown stack */
21201+ BUG();
21202+}
21203+EXPORT_SYMBOL(pax_check_alloca);
21204+#endif
21205diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21206index 174da5f..5e55606 100644
21207--- a/arch/x86/kernel/e820.c
21208+++ b/arch/x86/kernel/e820.c
21209@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21210
21211 static void early_panic(char *msg)
21212 {
21213- early_printk(msg);
21214- panic(msg);
21215+ early_printk("%s", msg);
21216+ panic("%s", msg);
21217 }
21218
21219 static int userdef __initdata;
21220diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21221index d15f575..d692043 100644
21222--- a/arch/x86/kernel/early_printk.c
21223+++ b/arch/x86/kernel/early_printk.c
21224@@ -7,6 +7,7 @@
21225 #include <linux/pci_regs.h>
21226 #include <linux/pci_ids.h>
21227 #include <linux/errno.h>
21228+#include <linux/sched.h>
21229 #include <asm/io.h>
21230 #include <asm/processor.h>
21231 #include <asm/fcntl.h>
21232diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21233index f0dcb0c..9f39b80 100644
21234--- a/arch/x86/kernel/entry_32.S
21235+++ b/arch/x86/kernel/entry_32.S
21236@@ -177,13 +177,153 @@
21237 /*CFI_REL_OFFSET gs, PT_GS*/
21238 .endm
21239 .macro SET_KERNEL_GS reg
21240+
21241+#ifdef CONFIG_CC_STACKPROTECTOR
21242 movl $(__KERNEL_STACK_CANARY), \reg
21243+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21244+ movl $(__USER_DS), \reg
21245+#else
21246+ xorl \reg, \reg
21247+#endif
21248+
21249 movl \reg, %gs
21250 .endm
21251
21252 #endif /* CONFIG_X86_32_LAZY_GS */
21253
21254-.macro SAVE_ALL
21255+.macro pax_enter_kernel
21256+#ifdef CONFIG_PAX_KERNEXEC
21257+ call pax_enter_kernel
21258+#endif
21259+.endm
21260+
21261+.macro pax_exit_kernel
21262+#ifdef CONFIG_PAX_KERNEXEC
21263+ call pax_exit_kernel
21264+#endif
21265+.endm
21266+
21267+#ifdef CONFIG_PAX_KERNEXEC
21268+ENTRY(pax_enter_kernel)
21269+#ifdef CONFIG_PARAVIRT
21270+ pushl %eax
21271+ pushl %ecx
21272+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21273+ mov %eax, %esi
21274+#else
21275+ mov %cr0, %esi
21276+#endif
21277+ bts $16, %esi
21278+ jnc 1f
21279+ mov %cs, %esi
21280+ cmp $__KERNEL_CS, %esi
21281+ jz 3f
21282+ ljmp $__KERNEL_CS, $3f
21283+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21284+2:
21285+#ifdef CONFIG_PARAVIRT
21286+ mov %esi, %eax
21287+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21288+#else
21289+ mov %esi, %cr0
21290+#endif
21291+3:
21292+#ifdef CONFIG_PARAVIRT
21293+ popl %ecx
21294+ popl %eax
21295+#endif
21296+ ret
21297+ENDPROC(pax_enter_kernel)
21298+
21299+ENTRY(pax_exit_kernel)
21300+#ifdef CONFIG_PARAVIRT
21301+ pushl %eax
21302+ pushl %ecx
21303+#endif
21304+ mov %cs, %esi
21305+ cmp $__KERNEXEC_KERNEL_CS, %esi
21306+ jnz 2f
21307+#ifdef CONFIG_PARAVIRT
21308+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21309+ mov %eax, %esi
21310+#else
21311+ mov %cr0, %esi
21312+#endif
21313+ btr $16, %esi
21314+ ljmp $__KERNEL_CS, $1f
21315+1:
21316+#ifdef CONFIG_PARAVIRT
21317+ mov %esi, %eax
21318+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21319+#else
21320+ mov %esi, %cr0
21321+#endif
21322+2:
21323+#ifdef CONFIG_PARAVIRT
21324+ popl %ecx
21325+ popl %eax
21326+#endif
21327+ ret
21328+ENDPROC(pax_exit_kernel)
21329+#endif
21330+
21331+ .macro pax_erase_kstack
21332+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21333+ call pax_erase_kstack
21334+#endif
21335+ .endm
21336+
21337+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21338+/*
21339+ * ebp: thread_info
21340+ */
21341+ENTRY(pax_erase_kstack)
21342+ pushl %edi
21343+ pushl %ecx
21344+ pushl %eax
21345+
21346+ mov TI_lowest_stack(%ebp), %edi
21347+ mov $-0xBEEF, %eax
21348+ std
21349+
21350+1: mov %edi, %ecx
21351+ and $THREAD_SIZE_asm - 1, %ecx
21352+ shr $2, %ecx
21353+ repne scasl
21354+ jecxz 2f
21355+
21356+ cmp $2*16, %ecx
21357+ jc 2f
21358+
21359+ mov $2*16, %ecx
21360+ repe scasl
21361+ jecxz 2f
21362+ jne 1b
21363+
21364+2: cld
21365+ mov %esp, %ecx
21366+ sub %edi, %ecx
21367+
21368+ cmp $THREAD_SIZE_asm, %ecx
21369+ jb 3f
21370+ ud2
21371+3:
21372+
21373+ shr $2, %ecx
21374+ rep stosl
21375+
21376+ mov TI_task_thread_sp0(%ebp), %edi
21377+ sub $128, %edi
21378+ mov %edi, TI_lowest_stack(%ebp)
21379+
21380+ popl %eax
21381+ popl %ecx
21382+ popl %edi
21383+ ret
21384+ENDPROC(pax_erase_kstack)
21385+#endif
21386+
21387+.macro __SAVE_ALL _DS
21388 cld
21389 PUSH_GS
21390 pushl_cfi %fs
21391@@ -206,7 +346,7 @@
21392 CFI_REL_OFFSET ecx, 0
21393 pushl_cfi %ebx
21394 CFI_REL_OFFSET ebx, 0
21395- movl $(__USER_DS), %edx
21396+ movl $\_DS, %edx
21397 movl %edx, %ds
21398 movl %edx, %es
21399 movl $(__KERNEL_PERCPU), %edx
21400@@ -214,6 +354,15 @@
21401 SET_KERNEL_GS %edx
21402 .endm
21403
21404+.macro SAVE_ALL
21405+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21406+ __SAVE_ALL __KERNEL_DS
21407+ pax_enter_kernel
21408+#else
21409+ __SAVE_ALL __USER_DS
21410+#endif
21411+.endm
21412+
21413 .macro RESTORE_INT_REGS
21414 popl_cfi %ebx
21415 CFI_RESTORE ebx
21416@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21417 popfl_cfi
21418 jmp syscall_exit
21419 CFI_ENDPROC
21420-END(ret_from_fork)
21421+ENDPROC(ret_from_fork)
21422
21423 ENTRY(ret_from_kernel_thread)
21424 CFI_STARTPROC
21425@@ -344,7 +493,15 @@ ret_from_intr:
21426 andl $SEGMENT_RPL_MASK, %eax
21427 #endif
21428 cmpl $USER_RPL, %eax
21429+
21430+#ifdef CONFIG_PAX_KERNEXEC
21431+ jae resume_userspace
21432+
21433+ pax_exit_kernel
21434+ jmp resume_kernel
21435+#else
21436 jb resume_kernel # not returning to v8086 or userspace
21437+#endif
21438
21439 ENTRY(resume_userspace)
21440 LOCKDEP_SYS_EXIT
21441@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21442 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21443 # int/exception return?
21444 jne work_pending
21445- jmp restore_all
21446-END(ret_from_exception)
21447+ jmp restore_all_pax
21448+ENDPROC(ret_from_exception)
21449
21450 #ifdef CONFIG_PREEMPT
21451 ENTRY(resume_kernel)
21452@@ -372,7 +529,7 @@ need_resched:
21453 jz restore_all
21454 call preempt_schedule_irq
21455 jmp need_resched
21456-END(resume_kernel)
21457+ENDPROC(resume_kernel)
21458 #endif
21459 CFI_ENDPROC
21460 /*
21461@@ -406,30 +563,45 @@ sysenter_past_esp:
21462 /*CFI_REL_OFFSET cs, 0*/
21463 /*
21464 * Push current_thread_info()->sysenter_return to the stack.
21465- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21466- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21467 */
21468- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21469+ pushl_cfi $0
21470 CFI_REL_OFFSET eip, 0
21471
21472 pushl_cfi %eax
21473 SAVE_ALL
21474+ GET_THREAD_INFO(%ebp)
21475+ movl TI_sysenter_return(%ebp),%ebp
21476+ movl %ebp,PT_EIP(%esp)
21477 ENABLE_INTERRUPTS(CLBR_NONE)
21478
21479 /*
21480 * Load the potential sixth argument from user stack.
21481 * Careful about security.
21482 */
21483+ movl PT_OLDESP(%esp),%ebp
21484+
21485+#ifdef CONFIG_PAX_MEMORY_UDEREF
21486+ mov PT_OLDSS(%esp),%ds
21487+1: movl %ds:(%ebp),%ebp
21488+ push %ss
21489+ pop %ds
21490+#else
21491 cmpl $__PAGE_OFFSET-3,%ebp
21492 jae syscall_fault
21493 ASM_STAC
21494 1: movl (%ebp),%ebp
21495 ASM_CLAC
21496+#endif
21497+
21498 movl %ebp,PT_EBP(%esp)
21499 _ASM_EXTABLE(1b,syscall_fault)
21500
21501 GET_THREAD_INFO(%ebp)
21502
21503+#ifdef CONFIG_PAX_RANDKSTACK
21504+ pax_erase_kstack
21505+#endif
21506+
21507 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21508 jnz sysenter_audit
21509 sysenter_do_call:
21510@@ -444,12 +616,24 @@ sysenter_do_call:
21511 testl $_TIF_ALLWORK_MASK, %ecx
21512 jne sysexit_audit
21513 sysenter_exit:
21514+
21515+#ifdef CONFIG_PAX_RANDKSTACK
21516+ pushl_cfi %eax
21517+ movl %esp, %eax
21518+ call pax_randomize_kstack
21519+ popl_cfi %eax
21520+#endif
21521+
21522+ pax_erase_kstack
21523+
21524 /* if something modifies registers it must also disable sysexit */
21525 movl PT_EIP(%esp), %edx
21526 movl PT_OLDESP(%esp), %ecx
21527 xorl %ebp,%ebp
21528 TRACE_IRQS_ON
21529 1: mov PT_FS(%esp), %fs
21530+2: mov PT_DS(%esp), %ds
21531+3: mov PT_ES(%esp), %es
21532 PTGS_TO_GS
21533 ENABLE_INTERRUPTS_SYSEXIT
21534
21535@@ -466,6 +650,9 @@ sysenter_audit:
21536 movl %eax,%edx /* 2nd arg: syscall number */
21537 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21538 call __audit_syscall_entry
21539+
21540+ pax_erase_kstack
21541+
21542 pushl_cfi %ebx
21543 movl PT_EAX(%esp),%eax /* reload syscall number */
21544 jmp sysenter_do_call
21545@@ -491,10 +678,16 @@ sysexit_audit:
21546
21547 CFI_ENDPROC
21548 .pushsection .fixup,"ax"
21549-2: movl $0,PT_FS(%esp)
21550+4: movl $0,PT_FS(%esp)
21551+ jmp 1b
21552+5: movl $0,PT_DS(%esp)
21553+ jmp 1b
21554+6: movl $0,PT_ES(%esp)
21555 jmp 1b
21556 .popsection
21557- _ASM_EXTABLE(1b,2b)
21558+ _ASM_EXTABLE(1b,4b)
21559+ _ASM_EXTABLE(2b,5b)
21560+ _ASM_EXTABLE(3b,6b)
21561 PTGS_TO_GS_EX
21562 ENDPROC(ia32_sysenter_target)
21563
21564@@ -509,6 +702,11 @@ ENTRY(system_call)
21565 pushl_cfi %eax # save orig_eax
21566 SAVE_ALL
21567 GET_THREAD_INFO(%ebp)
21568+
21569+#ifdef CONFIG_PAX_RANDKSTACK
21570+ pax_erase_kstack
21571+#endif
21572+
21573 # system call tracing in operation / emulation
21574 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21575 jnz syscall_trace_entry
21576@@ -527,6 +725,15 @@ syscall_exit:
21577 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21578 jne syscall_exit_work
21579
21580+restore_all_pax:
21581+
21582+#ifdef CONFIG_PAX_RANDKSTACK
21583+ movl %esp, %eax
21584+ call pax_randomize_kstack
21585+#endif
21586+
21587+ pax_erase_kstack
21588+
21589 restore_all:
21590 TRACE_IRQS_IRET
21591 restore_all_notrace:
21592@@ -583,14 +790,34 @@ ldt_ss:
21593 * compensating for the offset by changing to the ESPFIX segment with
21594 * a base address that matches for the difference.
21595 */
21596-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21597+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21598 mov %esp, %edx /* load kernel esp */
21599 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21600 mov %dx, %ax /* eax: new kernel esp */
21601 sub %eax, %edx /* offset (low word is 0) */
21602+#ifdef CONFIG_SMP
21603+ movl PER_CPU_VAR(cpu_number), %ebx
21604+ shll $PAGE_SHIFT_asm, %ebx
21605+ addl $cpu_gdt_table, %ebx
21606+#else
21607+ movl $cpu_gdt_table, %ebx
21608+#endif
21609 shr $16, %edx
21610- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21611- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21612+
21613+#ifdef CONFIG_PAX_KERNEXEC
21614+ mov %cr0, %esi
21615+ btr $16, %esi
21616+ mov %esi, %cr0
21617+#endif
21618+
21619+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21620+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21621+
21622+#ifdef CONFIG_PAX_KERNEXEC
21623+ bts $16, %esi
21624+ mov %esi, %cr0
21625+#endif
21626+
21627 pushl_cfi $__ESPFIX_SS
21628 pushl_cfi %eax /* new kernel esp */
21629 /* Disable interrupts, but do not irqtrace this section: we
21630@@ -619,20 +846,18 @@ work_resched:
21631 movl TI_flags(%ebp), %ecx
21632 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21633 # than syscall tracing?
21634- jz restore_all
21635+ jz restore_all_pax
21636 testb $_TIF_NEED_RESCHED, %cl
21637 jnz work_resched
21638
21639 work_notifysig: # deal with pending signals and
21640 # notify-resume requests
21641+ movl %esp, %eax
21642 #ifdef CONFIG_VM86
21643 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21644- movl %esp, %eax
21645 jne work_notifysig_v86 # returning to kernel-space or
21646 # vm86-space
21647 1:
21648-#else
21649- movl %esp, %eax
21650 #endif
21651 TRACE_IRQS_ON
21652 ENABLE_INTERRUPTS(CLBR_NONE)
21653@@ -653,7 +878,7 @@ work_notifysig_v86:
21654 movl %eax, %esp
21655 jmp 1b
21656 #endif
21657-END(work_pending)
21658+ENDPROC(work_pending)
21659
21660 # perform syscall exit tracing
21661 ALIGN
21662@@ -661,11 +886,14 @@ syscall_trace_entry:
21663 movl $-ENOSYS,PT_EAX(%esp)
21664 movl %esp, %eax
21665 call syscall_trace_enter
21666+
21667+ pax_erase_kstack
21668+
21669 /* What it returned is what we'll actually use. */
21670 cmpl $(NR_syscalls), %eax
21671 jnae syscall_call
21672 jmp syscall_exit
21673-END(syscall_trace_entry)
21674+ENDPROC(syscall_trace_entry)
21675
21676 # perform syscall exit tracing
21677 ALIGN
21678@@ -678,21 +906,25 @@ syscall_exit_work:
21679 movl %esp, %eax
21680 call syscall_trace_leave
21681 jmp resume_userspace
21682-END(syscall_exit_work)
21683+ENDPROC(syscall_exit_work)
21684 CFI_ENDPROC
21685
21686 RING0_INT_FRAME # can't unwind into user space anyway
21687 syscall_fault:
21688+#ifdef CONFIG_PAX_MEMORY_UDEREF
21689+ push %ss
21690+ pop %ds
21691+#endif
21692 ASM_CLAC
21693 GET_THREAD_INFO(%ebp)
21694 movl $-EFAULT,PT_EAX(%esp)
21695 jmp resume_userspace
21696-END(syscall_fault)
21697+ENDPROC(syscall_fault)
21698
21699 syscall_badsys:
21700 movl $-ENOSYS,PT_EAX(%esp)
21701 jmp resume_userspace
21702-END(syscall_badsys)
21703+ENDPROC(syscall_badsys)
21704 CFI_ENDPROC
21705 /*
21706 * End of kprobes section
21707@@ -708,8 +940,15 @@ END(syscall_badsys)
21708 * normal stack and adjusts ESP with the matching offset.
21709 */
21710 /* fixup the stack */
21711- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21712- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21713+#ifdef CONFIG_SMP
21714+ movl PER_CPU_VAR(cpu_number), %ebx
21715+ shll $PAGE_SHIFT_asm, %ebx
21716+ addl $cpu_gdt_table, %ebx
21717+#else
21718+ movl $cpu_gdt_table, %ebx
21719+#endif
21720+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21721+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21722 shl $16, %eax
21723 addl %esp, %eax /* the adjusted stack pointer */
21724 pushl_cfi $__KERNEL_DS
21725@@ -762,7 +1001,7 @@ vector=vector+1
21726 .endr
21727 2: jmp common_interrupt
21728 .endr
21729-END(irq_entries_start)
21730+ENDPROC(irq_entries_start)
21731
21732 .previous
21733 END(interrupt)
21734@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21735 pushl_cfi $do_coprocessor_error
21736 jmp error_code
21737 CFI_ENDPROC
21738-END(coprocessor_error)
21739+ENDPROC(coprocessor_error)
21740
21741 ENTRY(simd_coprocessor_error)
21742 RING0_INT_FRAME
21743@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21744 .section .altinstructions,"a"
21745 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21746 .previous
21747-.section .altinstr_replacement,"ax"
21748+.section .altinstr_replacement,"a"
21749 663: pushl $do_simd_coprocessor_error
21750 664:
21751 .previous
21752@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21753 #endif
21754 jmp error_code
21755 CFI_ENDPROC
21756-END(simd_coprocessor_error)
21757+ENDPROC(simd_coprocessor_error)
21758
21759 ENTRY(device_not_available)
21760 RING0_INT_FRAME
21761@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21762 pushl_cfi $do_device_not_available
21763 jmp error_code
21764 CFI_ENDPROC
21765-END(device_not_available)
21766+ENDPROC(device_not_available)
21767
21768 #ifdef CONFIG_PARAVIRT
21769 ENTRY(native_iret)
21770 iret
21771 _ASM_EXTABLE(native_iret, iret_exc)
21772-END(native_iret)
21773+ENDPROC(native_iret)
21774
21775 ENTRY(native_irq_enable_sysexit)
21776 sti
21777 sysexit
21778-END(native_irq_enable_sysexit)
21779+ENDPROC(native_irq_enable_sysexit)
21780 #endif
21781
21782 ENTRY(overflow)
21783@@ -875,7 +1114,7 @@ ENTRY(overflow)
21784 pushl_cfi $do_overflow
21785 jmp error_code
21786 CFI_ENDPROC
21787-END(overflow)
21788+ENDPROC(overflow)
21789
21790 ENTRY(bounds)
21791 RING0_INT_FRAME
21792@@ -884,7 +1123,7 @@ ENTRY(bounds)
21793 pushl_cfi $do_bounds
21794 jmp error_code
21795 CFI_ENDPROC
21796-END(bounds)
21797+ENDPROC(bounds)
21798
21799 ENTRY(invalid_op)
21800 RING0_INT_FRAME
21801@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21802 pushl_cfi $do_invalid_op
21803 jmp error_code
21804 CFI_ENDPROC
21805-END(invalid_op)
21806+ENDPROC(invalid_op)
21807
21808 ENTRY(coprocessor_segment_overrun)
21809 RING0_INT_FRAME
21810@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21811 pushl_cfi $do_coprocessor_segment_overrun
21812 jmp error_code
21813 CFI_ENDPROC
21814-END(coprocessor_segment_overrun)
21815+ENDPROC(coprocessor_segment_overrun)
21816
21817 ENTRY(invalid_TSS)
21818 RING0_EC_FRAME
21819@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21820 pushl_cfi $do_invalid_TSS
21821 jmp error_code
21822 CFI_ENDPROC
21823-END(invalid_TSS)
21824+ENDPROC(invalid_TSS)
21825
21826 ENTRY(segment_not_present)
21827 RING0_EC_FRAME
21828@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21829 pushl_cfi $do_segment_not_present
21830 jmp error_code
21831 CFI_ENDPROC
21832-END(segment_not_present)
21833+ENDPROC(segment_not_present)
21834
21835 ENTRY(stack_segment)
21836 RING0_EC_FRAME
21837@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21838 pushl_cfi $do_stack_segment
21839 jmp error_code
21840 CFI_ENDPROC
21841-END(stack_segment)
21842+ENDPROC(stack_segment)
21843
21844 ENTRY(alignment_check)
21845 RING0_EC_FRAME
21846@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21847 pushl_cfi $do_alignment_check
21848 jmp error_code
21849 CFI_ENDPROC
21850-END(alignment_check)
21851+ENDPROC(alignment_check)
21852
21853 ENTRY(divide_error)
21854 RING0_INT_FRAME
21855@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21856 pushl_cfi $do_divide_error
21857 jmp error_code
21858 CFI_ENDPROC
21859-END(divide_error)
21860+ENDPROC(divide_error)
21861
21862 #ifdef CONFIG_X86_MCE
21863 ENTRY(machine_check)
21864@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21865 pushl_cfi machine_check_vector
21866 jmp error_code
21867 CFI_ENDPROC
21868-END(machine_check)
21869+ENDPROC(machine_check)
21870 #endif
21871
21872 ENTRY(spurious_interrupt_bug)
21873@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21874 pushl_cfi $do_spurious_interrupt_bug
21875 jmp error_code
21876 CFI_ENDPROC
21877-END(spurious_interrupt_bug)
21878+ENDPROC(spurious_interrupt_bug)
21879 /*
21880 * End of kprobes section
21881 */
21882@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21883
21884 ENTRY(mcount)
21885 ret
21886-END(mcount)
21887+ENDPROC(mcount)
21888
21889 ENTRY(ftrace_caller)
21890 cmpl $0, function_trace_stop
21891@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21892 .globl ftrace_stub
21893 ftrace_stub:
21894 ret
21895-END(ftrace_caller)
21896+ENDPROC(ftrace_caller)
21897
21898 ENTRY(ftrace_regs_caller)
21899 pushf /* push flags before compare (in cs location) */
21900@@ -1210,7 +1449,7 @@ trace:
21901 popl %ecx
21902 popl %eax
21903 jmp ftrace_stub
21904-END(mcount)
21905+ENDPROC(mcount)
21906 #endif /* CONFIG_DYNAMIC_FTRACE */
21907 #endif /* CONFIG_FUNCTION_TRACER */
21908
21909@@ -1228,7 +1467,7 @@ ENTRY(ftrace_graph_caller)
21910 popl %ecx
21911 popl %eax
21912 ret
21913-END(ftrace_graph_caller)
21914+ENDPROC(ftrace_graph_caller)
21915
21916 .globl return_to_handler
21917 return_to_handler:
21918@@ -1284,15 +1523,18 @@ error_code:
21919 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21920 REG_TO_PTGS %ecx
21921 SET_KERNEL_GS %ecx
21922- movl $(__USER_DS), %ecx
21923+ movl $(__KERNEL_DS), %ecx
21924 movl %ecx, %ds
21925 movl %ecx, %es
21926+
21927+ pax_enter_kernel
21928+
21929 TRACE_IRQS_OFF
21930 movl %esp,%eax # pt_regs pointer
21931 call *%edi
21932 jmp ret_from_exception
21933 CFI_ENDPROC
21934-END(page_fault)
21935+ENDPROC(page_fault)
21936
21937 /*
21938 * Debug traps and NMI can happen at the one SYSENTER instruction
21939@@ -1335,7 +1577,7 @@ debug_stack_correct:
21940 call do_debug
21941 jmp ret_from_exception
21942 CFI_ENDPROC
21943-END(debug)
21944+ENDPROC(debug)
21945
21946 /*
21947 * NMI is doubly nasty. It can happen _while_ we're handling
21948@@ -1373,6 +1615,9 @@ nmi_stack_correct:
21949 xorl %edx,%edx # zero error code
21950 movl %esp,%eax # pt_regs pointer
21951 call do_nmi
21952+
21953+ pax_exit_kernel
21954+
21955 jmp restore_all_notrace
21956 CFI_ENDPROC
21957
21958@@ -1409,12 +1654,15 @@ nmi_espfix_stack:
21959 FIXUP_ESPFIX_STACK # %eax == %esp
21960 xorl %edx,%edx # zero error code
21961 call do_nmi
21962+
21963+ pax_exit_kernel
21964+
21965 RESTORE_REGS
21966 lss 12+4(%esp), %esp # back to espfix stack
21967 CFI_ADJUST_CFA_OFFSET -24
21968 jmp irq_return
21969 CFI_ENDPROC
21970-END(nmi)
21971+ENDPROC(nmi)
21972
21973 ENTRY(int3)
21974 RING0_INT_FRAME
21975@@ -1427,14 +1675,14 @@ ENTRY(int3)
21976 call do_int3
21977 jmp ret_from_exception
21978 CFI_ENDPROC
21979-END(int3)
21980+ENDPROC(int3)
21981
21982 ENTRY(general_protection)
21983 RING0_EC_FRAME
21984 pushl_cfi $do_general_protection
21985 jmp error_code
21986 CFI_ENDPROC
21987-END(general_protection)
21988+ENDPROC(general_protection)
21989
21990 #ifdef CONFIG_KVM_GUEST
21991 ENTRY(async_page_fault)
21992@@ -1443,7 +1691,7 @@ ENTRY(async_page_fault)
21993 pushl_cfi $do_async_page_fault
21994 jmp error_code
21995 CFI_ENDPROC
21996-END(async_page_fault)
21997+ENDPROC(async_page_fault)
21998 #endif
21999
22000 /*
22001diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22002index b077f4c..8e0df9f 100644
22003--- a/arch/x86/kernel/entry_64.S
22004+++ b/arch/x86/kernel/entry_64.S
22005@@ -59,6 +59,8 @@
22006 #include <asm/context_tracking.h>
22007 #include <asm/smap.h>
22008 #include <linux/err.h>
22009+#include <asm/pgtable.h>
22010+#include <asm/alternative-asm.h>
22011
22012 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22013 #include <linux/elf-em.h>
22014@@ -80,8 +82,9 @@
22015 #ifdef CONFIG_DYNAMIC_FTRACE
22016
22017 ENTRY(function_hook)
22018+ pax_force_retaddr
22019 retq
22020-END(function_hook)
22021+ENDPROC(function_hook)
22022
22023 /* skip is set if stack has been adjusted */
22024 .macro ftrace_caller_setup skip=0
22025@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22026 #endif
22027
22028 GLOBAL(ftrace_stub)
22029+ pax_force_retaddr
22030 retq
22031-END(ftrace_caller)
22032+ENDPROC(ftrace_caller)
22033
22034 ENTRY(ftrace_regs_caller)
22035 /* Save the current flags before compare (in SS location)*/
22036@@ -191,7 +195,7 @@ ftrace_restore_flags:
22037 popfq
22038 jmp ftrace_stub
22039
22040-END(ftrace_regs_caller)
22041+ENDPROC(ftrace_regs_caller)
22042
22043
22044 #else /* ! CONFIG_DYNAMIC_FTRACE */
22045@@ -212,6 +216,7 @@ ENTRY(function_hook)
22046 #endif
22047
22048 GLOBAL(ftrace_stub)
22049+ pax_force_retaddr
22050 retq
22051
22052 trace:
22053@@ -225,12 +230,13 @@ trace:
22054 #endif
22055 subq $MCOUNT_INSN_SIZE, %rdi
22056
22057+ pax_force_fptr ftrace_trace_function
22058 call *ftrace_trace_function
22059
22060 MCOUNT_RESTORE_FRAME
22061
22062 jmp ftrace_stub
22063-END(function_hook)
22064+ENDPROC(function_hook)
22065 #endif /* CONFIG_DYNAMIC_FTRACE */
22066 #endif /* CONFIG_FUNCTION_TRACER */
22067
22068@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22069
22070 MCOUNT_RESTORE_FRAME
22071
22072+ pax_force_retaddr
22073 retq
22074-END(ftrace_graph_caller)
22075+ENDPROC(ftrace_graph_caller)
22076
22077 GLOBAL(return_to_handler)
22078 subq $24, %rsp
22079@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22080 movq 8(%rsp), %rdx
22081 movq (%rsp), %rax
22082 addq $24, %rsp
22083+ pax_force_fptr %rdi
22084 jmp *%rdi
22085+ENDPROC(return_to_handler)
22086 #endif
22087
22088
22089@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22090 ENDPROC(native_usergs_sysret64)
22091 #endif /* CONFIG_PARAVIRT */
22092
22093+ .macro ljmpq sel, off
22094+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22095+ .byte 0x48; ljmp *1234f(%rip)
22096+ .pushsection .rodata
22097+ .align 16
22098+ 1234: .quad \off; .word \sel
22099+ .popsection
22100+#else
22101+ pushq $\sel
22102+ pushq $\off
22103+ lretq
22104+#endif
22105+ .endm
22106+
22107+ .macro pax_enter_kernel
22108+ pax_set_fptr_mask
22109+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22110+ call pax_enter_kernel
22111+#endif
22112+ .endm
22113+
22114+ .macro pax_exit_kernel
22115+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22116+ call pax_exit_kernel
22117+#endif
22118+
22119+ .endm
22120+
22121+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22122+ENTRY(pax_enter_kernel)
22123+ pushq %rdi
22124+
22125+#ifdef CONFIG_PARAVIRT
22126+ PV_SAVE_REGS(CLBR_RDI)
22127+#endif
22128+
22129+#ifdef CONFIG_PAX_KERNEXEC
22130+ GET_CR0_INTO_RDI
22131+ bts $16,%rdi
22132+ jnc 3f
22133+ mov %cs,%edi
22134+ cmp $__KERNEL_CS,%edi
22135+ jnz 2f
22136+1:
22137+#endif
22138+
22139+#ifdef CONFIG_PAX_MEMORY_UDEREF
22140+ 661: jmp 111f
22141+ .pushsection .altinstr_replacement, "a"
22142+ 662: ASM_NOP2
22143+ .popsection
22144+ .pushsection .altinstructions, "a"
22145+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22146+ .popsection
22147+ GET_CR3_INTO_RDI
22148+ cmp $0,%dil
22149+ jnz 112f
22150+ mov $__KERNEL_DS,%edi
22151+ mov %edi,%ss
22152+ jmp 111f
22153+112: cmp $1,%dil
22154+ jz 113f
22155+ ud2
22156+113: sub $4097,%rdi
22157+ bts $63,%rdi
22158+ SET_RDI_INTO_CR3
22159+ mov $__UDEREF_KERNEL_DS,%edi
22160+ mov %edi,%ss
22161+111:
22162+#endif
22163+
22164+#ifdef CONFIG_PARAVIRT
22165+ PV_RESTORE_REGS(CLBR_RDI)
22166+#endif
22167+
22168+ popq %rdi
22169+ pax_force_retaddr
22170+ retq
22171+
22172+#ifdef CONFIG_PAX_KERNEXEC
22173+2: ljmpq __KERNEL_CS,1b
22174+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22175+4: SET_RDI_INTO_CR0
22176+ jmp 1b
22177+#endif
22178+ENDPROC(pax_enter_kernel)
22179+
22180+ENTRY(pax_exit_kernel)
22181+ pushq %rdi
22182+
22183+#ifdef CONFIG_PARAVIRT
22184+ PV_SAVE_REGS(CLBR_RDI)
22185+#endif
22186+
22187+#ifdef CONFIG_PAX_KERNEXEC
22188+ mov %cs,%rdi
22189+ cmp $__KERNEXEC_KERNEL_CS,%edi
22190+ jz 2f
22191+ GET_CR0_INTO_RDI
22192+ bts $16,%rdi
22193+ jnc 4f
22194+1:
22195+#endif
22196+
22197+#ifdef CONFIG_PAX_MEMORY_UDEREF
22198+ 661: jmp 111f
22199+ .pushsection .altinstr_replacement, "a"
22200+ 662: ASM_NOP2
22201+ .popsection
22202+ .pushsection .altinstructions, "a"
22203+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22204+ .popsection
22205+ mov %ss,%edi
22206+ cmp $__UDEREF_KERNEL_DS,%edi
22207+ jnz 111f
22208+ GET_CR3_INTO_RDI
22209+ cmp $0,%dil
22210+ jz 112f
22211+ ud2
22212+112: add $4097,%rdi
22213+ bts $63,%rdi
22214+ SET_RDI_INTO_CR3
22215+ mov $__KERNEL_DS,%edi
22216+ mov %edi,%ss
22217+111:
22218+#endif
22219+
22220+#ifdef CONFIG_PARAVIRT
22221+ PV_RESTORE_REGS(CLBR_RDI);
22222+#endif
22223+
22224+ popq %rdi
22225+ pax_force_retaddr
22226+ retq
22227+
22228+#ifdef CONFIG_PAX_KERNEXEC
22229+2: GET_CR0_INTO_RDI
22230+ btr $16,%rdi
22231+ jnc 4f
22232+ ljmpq __KERNEL_CS,3f
22233+3: SET_RDI_INTO_CR0
22234+ jmp 1b
22235+4: ud2
22236+ jmp 4b
22237+#endif
22238+ENDPROC(pax_exit_kernel)
22239+#endif
22240+
22241+ .macro pax_enter_kernel_user
22242+ pax_set_fptr_mask
22243+#ifdef CONFIG_PAX_MEMORY_UDEREF
22244+ call pax_enter_kernel_user
22245+#endif
22246+ .endm
22247+
22248+ .macro pax_exit_kernel_user
22249+#ifdef CONFIG_PAX_MEMORY_UDEREF
22250+ call pax_exit_kernel_user
22251+#endif
22252+#ifdef CONFIG_PAX_RANDKSTACK
22253+ pushq %rax
22254+ pushq %r11
22255+ call pax_randomize_kstack
22256+ popq %r11
22257+ popq %rax
22258+#endif
22259+ .endm
22260+
22261+#ifdef CONFIG_PAX_MEMORY_UDEREF
22262+ENTRY(pax_enter_kernel_user)
22263+ pushq %rdi
22264+ pushq %rbx
22265+
22266+#ifdef CONFIG_PARAVIRT
22267+ PV_SAVE_REGS(CLBR_RDI)
22268+#endif
22269+
22270+ 661: jmp 111f
22271+ .pushsection .altinstr_replacement, "a"
22272+ 662: ASM_NOP2
22273+ .popsection
22274+ .pushsection .altinstructions, "a"
22275+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22276+ .popsection
22277+ GET_CR3_INTO_RDI
22278+ cmp $1,%dil
22279+ jnz 4f
22280+ sub $4097,%rdi
22281+ bts $63,%rdi
22282+ SET_RDI_INTO_CR3
22283+ jmp 3f
22284+111:
22285+
22286+ GET_CR3_INTO_RDI
22287+ mov %rdi,%rbx
22288+ add $__START_KERNEL_map,%rbx
22289+ sub phys_base(%rip),%rbx
22290+
22291+#ifdef CONFIG_PARAVIRT
22292+ cmpl $0, pv_info+PARAVIRT_enabled
22293+ jz 1f
22294+ pushq %rdi
22295+ i = 0
22296+ .rept USER_PGD_PTRS
22297+ mov i*8(%rbx),%rsi
22298+ mov $0,%sil
22299+ lea i*8(%rbx),%rdi
22300+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22301+ i = i + 1
22302+ .endr
22303+ popq %rdi
22304+ jmp 2f
22305+1:
22306+#endif
22307+
22308+ i = 0
22309+ .rept USER_PGD_PTRS
22310+ movb $0,i*8(%rbx)
22311+ i = i + 1
22312+ .endr
22313+
22314+2: SET_RDI_INTO_CR3
22315+
22316+#ifdef CONFIG_PAX_KERNEXEC
22317+ GET_CR0_INTO_RDI
22318+ bts $16,%rdi
22319+ SET_RDI_INTO_CR0
22320+#endif
22321+
22322+3:
22323+
22324+#ifdef CONFIG_PARAVIRT
22325+ PV_RESTORE_REGS(CLBR_RDI)
22326+#endif
22327+
22328+ popq %rbx
22329+ popq %rdi
22330+ pax_force_retaddr
22331+ retq
22332+4: ud2
22333+ENDPROC(pax_enter_kernel_user)
22334+
22335+ENTRY(pax_exit_kernel_user)
22336+ pushq %rdi
22337+ pushq %rbx
22338+
22339+#ifdef CONFIG_PARAVIRT
22340+ PV_SAVE_REGS(CLBR_RDI)
22341+#endif
22342+
22343+ GET_CR3_INTO_RDI
22344+ 661: jmp 1f
22345+ .pushsection .altinstr_replacement, "a"
22346+ 662: ASM_NOP2
22347+ .popsection
22348+ .pushsection .altinstructions, "a"
22349+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22350+ .popsection
22351+ cmp $0,%dil
22352+ jnz 3f
22353+ add $4097,%rdi
22354+ bts $63,%rdi
22355+ SET_RDI_INTO_CR3
22356+ jmp 2f
22357+1:
22358+
22359+ mov %rdi,%rbx
22360+
22361+#ifdef CONFIG_PAX_KERNEXEC
22362+ GET_CR0_INTO_RDI
22363+ btr $16,%rdi
22364+ jnc 3f
22365+ SET_RDI_INTO_CR0
22366+#endif
22367+
22368+ add $__START_KERNEL_map,%rbx
22369+ sub phys_base(%rip),%rbx
22370+
22371+#ifdef CONFIG_PARAVIRT
22372+ cmpl $0, pv_info+PARAVIRT_enabled
22373+ jz 1f
22374+ i = 0
22375+ .rept USER_PGD_PTRS
22376+ mov i*8(%rbx),%rsi
22377+ mov $0x67,%sil
22378+ lea i*8(%rbx),%rdi
22379+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22380+ i = i + 1
22381+ .endr
22382+ jmp 2f
22383+1:
22384+#endif
22385+
22386+ i = 0
22387+ .rept USER_PGD_PTRS
22388+ movb $0x67,i*8(%rbx)
22389+ i = i + 1
22390+ .endr
22391+2:
22392+
22393+#ifdef CONFIG_PARAVIRT
22394+ PV_RESTORE_REGS(CLBR_RDI)
22395+#endif
22396+
22397+ popq %rbx
22398+ popq %rdi
22399+ pax_force_retaddr
22400+ retq
22401+3: ud2
22402+ENDPROC(pax_exit_kernel_user)
22403+#endif
22404+
22405+ .macro pax_enter_kernel_nmi
22406+ pax_set_fptr_mask
22407+
22408+#ifdef CONFIG_PAX_KERNEXEC
22409+ GET_CR0_INTO_RDI
22410+ bts $16,%rdi
22411+ jc 110f
22412+ SET_RDI_INTO_CR0
22413+ or $2,%ebx
22414+110:
22415+#endif
22416+
22417+#ifdef CONFIG_PAX_MEMORY_UDEREF
22418+ 661: jmp 111f
22419+ .pushsection .altinstr_replacement, "a"
22420+ 662: ASM_NOP2
22421+ .popsection
22422+ .pushsection .altinstructions, "a"
22423+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22424+ .popsection
22425+ GET_CR3_INTO_RDI
22426+ cmp $0,%dil
22427+ jz 111f
22428+ sub $4097,%rdi
22429+ or $4,%ebx
22430+ bts $63,%rdi
22431+ SET_RDI_INTO_CR3
22432+ mov $__UDEREF_KERNEL_DS,%edi
22433+ mov %edi,%ss
22434+111:
22435+#endif
22436+ .endm
22437+
22438+ .macro pax_exit_kernel_nmi
22439+#ifdef CONFIG_PAX_KERNEXEC
22440+ btr $1,%ebx
22441+ jnc 110f
22442+ GET_CR0_INTO_RDI
22443+ btr $16,%rdi
22444+ SET_RDI_INTO_CR0
22445+110:
22446+#endif
22447+
22448+#ifdef CONFIG_PAX_MEMORY_UDEREF
22449+ btr $2,%ebx
22450+ jnc 111f
22451+ GET_CR3_INTO_RDI
22452+ add $4097,%rdi
22453+ bts $63,%rdi
22454+ SET_RDI_INTO_CR3
22455+ mov $__KERNEL_DS,%edi
22456+ mov %edi,%ss
22457+111:
22458+#endif
22459+ .endm
22460+
22461+ .macro pax_erase_kstack
22462+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22463+ call pax_erase_kstack
22464+#endif
22465+ .endm
22466+
22467+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22468+ENTRY(pax_erase_kstack)
22469+ pushq %rdi
22470+ pushq %rcx
22471+ pushq %rax
22472+ pushq %r11
22473+
22474+ GET_THREAD_INFO(%r11)
22475+ mov TI_lowest_stack(%r11), %rdi
22476+ mov $-0xBEEF, %rax
22477+ std
22478+
22479+1: mov %edi, %ecx
22480+ and $THREAD_SIZE_asm - 1, %ecx
22481+ shr $3, %ecx
22482+ repne scasq
22483+ jecxz 2f
22484+
22485+ cmp $2*8, %ecx
22486+ jc 2f
22487+
22488+ mov $2*8, %ecx
22489+ repe scasq
22490+ jecxz 2f
22491+ jne 1b
22492+
22493+2: cld
22494+ mov %esp, %ecx
22495+ sub %edi, %ecx
22496+
22497+ cmp $THREAD_SIZE_asm, %rcx
22498+ jb 3f
22499+ ud2
22500+3:
22501+
22502+ shr $3, %ecx
22503+ rep stosq
22504+
22505+ mov TI_task_thread_sp0(%r11), %rdi
22506+ sub $256, %rdi
22507+ mov %rdi, TI_lowest_stack(%r11)
22508+
22509+ popq %r11
22510+ popq %rax
22511+ popq %rcx
22512+ popq %rdi
22513+ pax_force_retaddr
22514+ ret
22515+ENDPROC(pax_erase_kstack)
22516+#endif
22517
22518 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22519 #ifdef CONFIG_TRACE_IRQFLAGS
22520@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22521 .endm
22522
22523 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22524- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22525+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22526 jnc 1f
22527 TRACE_IRQS_ON_DEBUG
22528 1:
22529@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22530 movq \tmp,R11+\offset(%rsp)
22531 .endm
22532
22533- .macro FAKE_STACK_FRAME child_rip
22534- /* push in order ss, rsp, eflags, cs, rip */
22535- xorl %eax, %eax
22536- pushq_cfi $__KERNEL_DS /* ss */
22537- /*CFI_REL_OFFSET ss,0*/
22538- pushq_cfi %rax /* rsp */
22539- CFI_REL_OFFSET rsp,0
22540- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22541- /*CFI_REL_OFFSET rflags,0*/
22542- pushq_cfi $__KERNEL_CS /* cs */
22543- /*CFI_REL_OFFSET cs,0*/
22544- pushq_cfi \child_rip /* rip */
22545- CFI_REL_OFFSET rip,0
22546- pushq_cfi %rax /* orig rax */
22547- .endm
22548-
22549- .macro UNFAKE_STACK_FRAME
22550- addq $8*6, %rsp
22551- CFI_ADJUST_CFA_OFFSET -(6*8)
22552- .endm
22553-
22554 /*
22555 * initial frame state for interrupts (and exceptions without error code)
22556 */
22557@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22558 /* save partial stack frame */
22559 .macro SAVE_ARGS_IRQ
22560 cld
22561- /* start from rbp in pt_regs and jump over */
22562- movq_cfi rdi, (RDI-RBP)
22563- movq_cfi rsi, (RSI-RBP)
22564- movq_cfi rdx, (RDX-RBP)
22565- movq_cfi rcx, (RCX-RBP)
22566- movq_cfi rax, (RAX-RBP)
22567- movq_cfi r8, (R8-RBP)
22568- movq_cfi r9, (R9-RBP)
22569- movq_cfi r10, (R10-RBP)
22570- movq_cfi r11, (R11-RBP)
22571+ /* start from r15 in pt_regs and jump over */
22572+ movq_cfi rdi, RDI
22573+ movq_cfi rsi, RSI
22574+ movq_cfi rdx, RDX
22575+ movq_cfi rcx, RCX
22576+ movq_cfi rax, RAX
22577+ movq_cfi r8, R8
22578+ movq_cfi r9, R9
22579+ movq_cfi r10, R10
22580+ movq_cfi r11, R11
22581+ movq_cfi r12, R12
22582
22583 /* Save rbp so that we can unwind from get_irq_regs() */
22584- movq_cfi rbp, 0
22585+ movq_cfi rbp, RBP
22586
22587 /* Save previous stack value */
22588 movq %rsp, %rsi
22589
22590- leaq -RBP(%rsp),%rdi /* arg1 for handler */
22591- testl $3, CS-RBP(%rsi)
22592+ movq %rsp,%rdi /* arg1 for handler */
22593+ testb $3, CS(%rsi)
22594 je 1f
22595 SWAPGS
22596 /*
22597@@ -514,9 +927,10 @@ ENTRY(save_paranoid)
22598 js 1f /* negative -> in kernel */
22599 SWAPGS
22600 xorl %ebx,%ebx
22601-1: ret
22602+1: pax_force_retaddr_bts
22603+ ret
22604 CFI_ENDPROC
22605-END(save_paranoid)
22606+ENDPROC(save_paranoid)
22607 .popsection
22608
22609 /*
22610@@ -538,7 +952,7 @@ ENTRY(ret_from_fork)
22611
22612 RESTORE_REST
22613
22614- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22615+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22616 jz 1f
22617
22618 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22619@@ -548,15 +962,13 @@ ENTRY(ret_from_fork)
22620 jmp ret_from_sys_call # go to the SYSRET fastpath
22621
22622 1:
22623- subq $REST_SKIP, %rsp # leave space for volatiles
22624- CFI_ADJUST_CFA_OFFSET REST_SKIP
22625 movq %rbp, %rdi
22626 call *%rbx
22627 movl $0, RAX(%rsp)
22628 RESTORE_REST
22629 jmp int_ret_from_sys_call
22630 CFI_ENDPROC
22631-END(ret_from_fork)
22632+ENDPROC(ret_from_fork)
22633
22634 /*
22635 * System call entry. Up to 6 arguments in registers are supported.
22636@@ -593,7 +1005,7 @@ END(ret_from_fork)
22637 ENTRY(system_call)
22638 CFI_STARTPROC simple
22639 CFI_SIGNAL_FRAME
22640- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22641+ CFI_DEF_CFA rsp,0
22642 CFI_REGISTER rip,rcx
22643 /*CFI_REGISTER rflags,r11*/
22644 SWAPGS_UNSAFE_STACK
22645@@ -606,16 +1018,23 @@ GLOBAL(system_call_after_swapgs)
22646
22647 movq %rsp,PER_CPU_VAR(old_rsp)
22648 movq PER_CPU_VAR(kernel_stack),%rsp
22649+ SAVE_ARGS 8*6,0
22650+ pax_enter_kernel_user
22651+
22652+#ifdef CONFIG_PAX_RANDKSTACK
22653+ pax_erase_kstack
22654+#endif
22655+
22656 /*
22657 * No need to follow this irqs off/on section - it's straight
22658 * and short:
22659 */
22660 ENABLE_INTERRUPTS(CLBR_NONE)
22661- SAVE_ARGS 8,0
22662 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22663 movq %rcx,RIP-ARGOFFSET(%rsp)
22664 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22665- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22666+ GET_THREAD_INFO(%rcx)
22667+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22668 jnz tracesys
22669 system_call_fastpath:
22670 #if __SYSCALL_MASK == ~0
22671@@ -639,10 +1058,13 @@ sysret_check:
22672 LOCKDEP_SYS_EXIT
22673 DISABLE_INTERRUPTS(CLBR_NONE)
22674 TRACE_IRQS_OFF
22675- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22676+ GET_THREAD_INFO(%rcx)
22677+ movl TI_flags(%rcx),%edx
22678 andl %edi,%edx
22679 jnz sysret_careful
22680 CFI_REMEMBER_STATE
22681+ pax_exit_kernel_user
22682+ pax_erase_kstack
22683 /*
22684 * sysretq will re-enable interrupts:
22685 */
22686@@ -701,6 +1123,9 @@ auditsys:
22687 movq %rax,%rsi /* 2nd arg: syscall number */
22688 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22689 call __audit_syscall_entry
22690+
22691+ pax_erase_kstack
22692+
22693 LOAD_ARGS 0 /* reload call-clobbered registers */
22694 jmp system_call_fastpath
22695
22696@@ -722,7 +1147,7 @@ sysret_audit:
22697 /* Do syscall tracing */
22698 tracesys:
22699 #ifdef CONFIG_AUDITSYSCALL
22700- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22701+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22702 jz auditsys
22703 #endif
22704 SAVE_REST
22705@@ -730,12 +1155,15 @@ tracesys:
22706 FIXUP_TOP_OF_STACK %rdi
22707 movq %rsp,%rdi
22708 call syscall_trace_enter
22709+
22710+ pax_erase_kstack
22711+
22712 /*
22713 * Reload arg registers from stack in case ptrace changed them.
22714 * We don't reload %rax because syscall_trace_enter() returned
22715 * the value it wants us to use in the table lookup.
22716 */
22717- LOAD_ARGS ARGOFFSET, 1
22718+ LOAD_ARGS 1
22719 RESTORE_REST
22720 #if __SYSCALL_MASK == ~0
22721 cmpq $__NR_syscall_max,%rax
22722@@ -765,7 +1193,9 @@ GLOBAL(int_with_check)
22723 andl %edi,%edx
22724 jnz int_careful
22725 andl $~TS_COMPAT,TI_status(%rcx)
22726- jmp retint_swapgs
22727+ pax_exit_kernel_user
22728+ pax_erase_kstack
22729+ jmp retint_swapgs_pax
22730
22731 /* Either reschedule or signal or syscall exit tracking needed. */
22732 /* First do a reschedule test. */
22733@@ -811,7 +1241,7 @@ int_restore_rest:
22734 TRACE_IRQS_OFF
22735 jmp int_with_check
22736 CFI_ENDPROC
22737-END(system_call)
22738+ENDPROC(system_call)
22739
22740 .macro FORK_LIKE func
22741 ENTRY(stub_\func)
22742@@ -824,9 +1254,10 @@ ENTRY(stub_\func)
22743 DEFAULT_FRAME 0 8 /* offset 8: return address */
22744 call sys_\func
22745 RESTORE_TOP_OF_STACK %r11, 8
22746- ret $REST_SKIP /* pop extended registers */
22747+ pax_force_retaddr
22748+ ret
22749 CFI_ENDPROC
22750-END(stub_\func)
22751+ENDPROC(stub_\func)
22752 .endm
22753
22754 .macro FIXED_FRAME label,func
22755@@ -836,9 +1267,10 @@ ENTRY(\label)
22756 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22757 call \func
22758 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22759+ pax_force_retaddr
22760 ret
22761 CFI_ENDPROC
22762-END(\label)
22763+ENDPROC(\label)
22764 .endm
22765
22766 FORK_LIKE clone
22767@@ -846,19 +1278,6 @@ END(\label)
22768 FORK_LIKE vfork
22769 FIXED_FRAME stub_iopl, sys_iopl
22770
22771-ENTRY(ptregscall_common)
22772- DEFAULT_FRAME 1 8 /* offset 8: return address */
22773- RESTORE_TOP_OF_STACK %r11, 8
22774- movq_cfi_restore R15+8, r15
22775- movq_cfi_restore R14+8, r14
22776- movq_cfi_restore R13+8, r13
22777- movq_cfi_restore R12+8, r12
22778- movq_cfi_restore RBP+8, rbp
22779- movq_cfi_restore RBX+8, rbx
22780- ret $REST_SKIP /* pop extended registers */
22781- CFI_ENDPROC
22782-END(ptregscall_common)
22783-
22784 ENTRY(stub_execve)
22785 CFI_STARTPROC
22786 addq $8, %rsp
22787@@ -870,7 +1289,7 @@ ENTRY(stub_execve)
22788 RESTORE_REST
22789 jmp int_ret_from_sys_call
22790 CFI_ENDPROC
22791-END(stub_execve)
22792+ENDPROC(stub_execve)
22793
22794 /*
22795 * sigreturn is special because it needs to restore all registers on return.
22796@@ -887,7 +1306,7 @@ ENTRY(stub_rt_sigreturn)
22797 RESTORE_REST
22798 jmp int_ret_from_sys_call
22799 CFI_ENDPROC
22800-END(stub_rt_sigreturn)
22801+ENDPROC(stub_rt_sigreturn)
22802
22803 #ifdef CONFIG_X86_X32_ABI
22804 ENTRY(stub_x32_rt_sigreturn)
22805@@ -901,7 +1320,7 @@ ENTRY(stub_x32_rt_sigreturn)
22806 RESTORE_REST
22807 jmp int_ret_from_sys_call
22808 CFI_ENDPROC
22809-END(stub_x32_rt_sigreturn)
22810+ENDPROC(stub_x32_rt_sigreturn)
22811
22812 ENTRY(stub_x32_execve)
22813 CFI_STARTPROC
22814@@ -915,7 +1334,7 @@ ENTRY(stub_x32_execve)
22815 RESTORE_REST
22816 jmp int_ret_from_sys_call
22817 CFI_ENDPROC
22818-END(stub_x32_execve)
22819+ENDPROC(stub_x32_execve)
22820
22821 #endif
22822
22823@@ -952,7 +1371,7 @@ vector=vector+1
22824 2: jmp common_interrupt
22825 .endr
22826 CFI_ENDPROC
22827-END(irq_entries_start)
22828+ENDPROC(irq_entries_start)
22829
22830 .previous
22831 END(interrupt)
22832@@ -969,9 +1388,19 @@ END(interrupt)
22833 /* 0(%rsp): ~(interrupt number) */
22834 .macro interrupt func
22835 /* reserve pt_regs for scratch regs and rbp */
22836- subq $ORIG_RAX-RBP, %rsp
22837- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22838+ subq $ORIG_RAX, %rsp
22839+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
22840 SAVE_ARGS_IRQ
22841+#ifdef CONFIG_PAX_MEMORY_UDEREF
22842+ testb $3, CS(%rdi)
22843+ jnz 1f
22844+ pax_enter_kernel
22845+ jmp 2f
22846+1: pax_enter_kernel_user
22847+2:
22848+#else
22849+ pax_enter_kernel
22850+#endif
22851 call \func
22852 .endm
22853
22854@@ -997,14 +1426,14 @@ ret_from_intr:
22855
22856 /* Restore saved previous stack */
22857 popq %rsi
22858- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
22859- leaq ARGOFFSET-RBP(%rsi), %rsp
22860+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
22861+ movq %rsi, %rsp
22862 CFI_DEF_CFA_REGISTER rsp
22863- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
22864+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
22865
22866 exit_intr:
22867 GET_THREAD_INFO(%rcx)
22868- testl $3,CS-ARGOFFSET(%rsp)
22869+ testb $3,CS-ARGOFFSET(%rsp)
22870 je retint_kernel
22871
22872 /* Interrupt came from user space */
22873@@ -1026,12 +1455,16 @@ retint_swapgs: /* return to user-space */
22874 * The iretq could re-enable interrupts:
22875 */
22876 DISABLE_INTERRUPTS(CLBR_ANY)
22877+ pax_exit_kernel_user
22878+retint_swapgs_pax:
22879 TRACE_IRQS_IRETQ
22880 SWAPGS
22881 jmp restore_args
22882
22883 retint_restore_args: /* return to kernel space */
22884 DISABLE_INTERRUPTS(CLBR_ANY)
22885+ pax_exit_kernel
22886+ pax_force_retaddr (RIP-ARGOFFSET)
22887 /*
22888 * The iretq could re-enable interrupts:
22889 */
22890@@ -1114,7 +1547,7 @@ ENTRY(retint_kernel)
22891 #endif
22892
22893 CFI_ENDPROC
22894-END(common_interrupt)
22895+ENDPROC(common_interrupt)
22896 /*
22897 * End of kprobes section
22898 */
22899@@ -1132,7 +1565,7 @@ ENTRY(\sym)
22900 interrupt \do_sym
22901 jmp ret_from_intr
22902 CFI_ENDPROC
22903-END(\sym)
22904+ENDPROC(\sym)
22905 .endm
22906
22907 #ifdef CONFIG_TRACING
22908@@ -1215,12 +1648,22 @@ ENTRY(\sym)
22909 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22910 call error_entry
22911 DEFAULT_FRAME 0
22912+#ifdef CONFIG_PAX_MEMORY_UDEREF
22913+ testb $3, CS(%rsp)
22914+ jnz 1f
22915+ pax_enter_kernel
22916+ jmp 2f
22917+1: pax_enter_kernel_user
22918+2:
22919+#else
22920+ pax_enter_kernel
22921+#endif
22922 movq %rsp,%rdi /* pt_regs pointer */
22923 xorl %esi,%esi /* no error code */
22924 call \do_sym
22925 jmp error_exit /* %ebx: no swapgs flag */
22926 CFI_ENDPROC
22927-END(\sym)
22928+ENDPROC(\sym)
22929 .endm
22930
22931 .macro paranoidzeroentry sym do_sym
22932@@ -1233,15 +1676,25 @@ ENTRY(\sym)
22933 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22934 call save_paranoid
22935 TRACE_IRQS_OFF
22936+#ifdef CONFIG_PAX_MEMORY_UDEREF
22937+ testb $3, CS(%rsp)
22938+ jnz 1f
22939+ pax_enter_kernel
22940+ jmp 2f
22941+1: pax_enter_kernel_user
22942+2:
22943+#else
22944+ pax_enter_kernel
22945+#endif
22946 movq %rsp,%rdi /* pt_regs pointer */
22947 xorl %esi,%esi /* no error code */
22948 call \do_sym
22949 jmp paranoid_exit /* %ebx: no swapgs flag */
22950 CFI_ENDPROC
22951-END(\sym)
22952+ENDPROC(\sym)
22953 .endm
22954
22955-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22956+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
22957 .macro paranoidzeroentry_ist sym do_sym ist
22958 ENTRY(\sym)
22959 INTR_FRAME
22960@@ -1252,14 +1705,30 @@ ENTRY(\sym)
22961 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22962 call save_paranoid
22963 TRACE_IRQS_OFF_DEBUG
22964+#ifdef CONFIG_PAX_MEMORY_UDEREF
22965+ testb $3, CS(%rsp)
22966+ jnz 1f
22967+ pax_enter_kernel
22968+ jmp 2f
22969+1: pax_enter_kernel_user
22970+2:
22971+#else
22972+ pax_enter_kernel
22973+#endif
22974 movq %rsp,%rdi /* pt_regs pointer */
22975 xorl %esi,%esi /* no error code */
22976+#ifdef CONFIG_SMP
22977+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
22978+ lea init_tss(%r13), %r13
22979+#else
22980+ lea init_tss(%rip), %r13
22981+#endif
22982 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22983 call \do_sym
22984 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22985 jmp paranoid_exit /* %ebx: no swapgs flag */
22986 CFI_ENDPROC
22987-END(\sym)
22988+ENDPROC(\sym)
22989 .endm
22990
22991 .macro errorentry sym do_sym
22992@@ -1271,13 +1740,23 @@ ENTRY(\sym)
22993 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22994 call error_entry
22995 DEFAULT_FRAME 0
22996+#ifdef CONFIG_PAX_MEMORY_UDEREF
22997+ testb $3, CS(%rsp)
22998+ jnz 1f
22999+ pax_enter_kernel
23000+ jmp 2f
23001+1: pax_enter_kernel_user
23002+2:
23003+#else
23004+ pax_enter_kernel
23005+#endif
23006 movq %rsp,%rdi /* pt_regs pointer */
23007 movq ORIG_RAX(%rsp),%rsi /* get error code */
23008 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23009 call \do_sym
23010 jmp error_exit /* %ebx: no swapgs flag */
23011 CFI_ENDPROC
23012-END(\sym)
23013+ENDPROC(\sym)
23014 .endm
23015
23016 /* error code is on the stack already */
23017@@ -1291,13 +1770,23 @@ ENTRY(\sym)
23018 call save_paranoid
23019 DEFAULT_FRAME 0
23020 TRACE_IRQS_OFF
23021+#ifdef CONFIG_PAX_MEMORY_UDEREF
23022+ testb $3, CS(%rsp)
23023+ jnz 1f
23024+ pax_enter_kernel
23025+ jmp 2f
23026+1: pax_enter_kernel_user
23027+2:
23028+#else
23029+ pax_enter_kernel
23030+#endif
23031 movq %rsp,%rdi /* pt_regs pointer */
23032 movq ORIG_RAX(%rsp),%rsi /* get error code */
23033 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
23034 call \do_sym
23035 jmp paranoid_exit /* %ebx: no swapgs flag */
23036 CFI_ENDPROC
23037-END(\sym)
23038+ENDPROC(\sym)
23039 .endm
23040
23041 zeroentry divide_error do_divide_error
23042@@ -1327,9 +1816,10 @@ gs_change:
23043 2: mfence /* workaround */
23044 SWAPGS
23045 popfq_cfi
23046+ pax_force_retaddr
23047 ret
23048 CFI_ENDPROC
23049-END(native_load_gs_index)
23050+ENDPROC(native_load_gs_index)
23051
23052 _ASM_EXTABLE(gs_change,bad_gs)
23053 .section .fixup,"ax"
23054@@ -1357,9 +1847,10 @@ ENTRY(call_softirq)
23055 CFI_DEF_CFA_REGISTER rsp
23056 CFI_ADJUST_CFA_OFFSET -8
23057 decl PER_CPU_VAR(irq_count)
23058+ pax_force_retaddr
23059 ret
23060 CFI_ENDPROC
23061-END(call_softirq)
23062+ENDPROC(call_softirq)
23063
23064 #ifdef CONFIG_XEN
23065 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23066@@ -1397,7 +1888,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23067 decl PER_CPU_VAR(irq_count)
23068 jmp error_exit
23069 CFI_ENDPROC
23070-END(xen_do_hypervisor_callback)
23071+ENDPROC(xen_do_hypervisor_callback)
23072
23073 /*
23074 * Hypervisor uses this for application faults while it executes.
23075@@ -1456,7 +1947,7 @@ ENTRY(xen_failsafe_callback)
23076 SAVE_ALL
23077 jmp error_exit
23078 CFI_ENDPROC
23079-END(xen_failsafe_callback)
23080+ENDPROC(xen_failsafe_callback)
23081
23082 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23083 xen_hvm_callback_vector xen_evtchn_do_upcall
23084@@ -1508,18 +1999,33 @@ ENTRY(paranoid_exit)
23085 DEFAULT_FRAME
23086 DISABLE_INTERRUPTS(CLBR_NONE)
23087 TRACE_IRQS_OFF_DEBUG
23088- testl %ebx,%ebx /* swapgs needed? */
23089+ testl $1,%ebx /* swapgs needed? */
23090 jnz paranoid_restore
23091- testl $3,CS(%rsp)
23092+ testb $3,CS(%rsp)
23093 jnz paranoid_userspace
23094+#ifdef CONFIG_PAX_MEMORY_UDEREF
23095+ pax_exit_kernel
23096+ TRACE_IRQS_IRETQ 0
23097+ SWAPGS_UNSAFE_STACK
23098+ RESTORE_ALL 8
23099+ pax_force_retaddr_bts
23100+ jmp irq_return
23101+#endif
23102 paranoid_swapgs:
23103+#ifdef CONFIG_PAX_MEMORY_UDEREF
23104+ pax_exit_kernel_user
23105+#else
23106+ pax_exit_kernel
23107+#endif
23108 TRACE_IRQS_IRETQ 0
23109 SWAPGS_UNSAFE_STACK
23110 RESTORE_ALL 8
23111 jmp irq_return
23112 paranoid_restore:
23113+ pax_exit_kernel
23114 TRACE_IRQS_IRETQ_DEBUG 0
23115 RESTORE_ALL 8
23116+ pax_force_retaddr_bts
23117 jmp irq_return
23118 paranoid_userspace:
23119 GET_THREAD_INFO(%rcx)
23120@@ -1548,7 +2054,7 @@ paranoid_schedule:
23121 TRACE_IRQS_OFF
23122 jmp paranoid_userspace
23123 CFI_ENDPROC
23124-END(paranoid_exit)
23125+ENDPROC(paranoid_exit)
23126
23127 /*
23128 * Exception entry point. This expects an error code/orig_rax on the stack.
23129@@ -1575,12 +2081,13 @@ ENTRY(error_entry)
23130 movq_cfi r14, R14+8
23131 movq_cfi r15, R15+8
23132 xorl %ebx,%ebx
23133- testl $3,CS+8(%rsp)
23134+ testb $3,CS+8(%rsp)
23135 je error_kernelspace
23136 error_swapgs:
23137 SWAPGS
23138 error_sti:
23139 TRACE_IRQS_OFF
23140+ pax_force_retaddr_bts
23141 ret
23142
23143 /*
23144@@ -1607,7 +2114,7 @@ bstep_iret:
23145 movq %rcx,RIP+8(%rsp)
23146 jmp error_swapgs
23147 CFI_ENDPROC
23148-END(error_entry)
23149+ENDPROC(error_entry)
23150
23151
23152 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23153@@ -1618,7 +2125,7 @@ ENTRY(error_exit)
23154 DISABLE_INTERRUPTS(CLBR_NONE)
23155 TRACE_IRQS_OFF
23156 GET_THREAD_INFO(%rcx)
23157- testl %eax,%eax
23158+ testl $1,%eax
23159 jne retint_kernel
23160 LOCKDEP_SYS_EXIT_IRQ
23161 movl TI_flags(%rcx),%edx
23162@@ -1627,7 +2134,7 @@ ENTRY(error_exit)
23163 jnz retint_careful
23164 jmp retint_swapgs
23165 CFI_ENDPROC
23166-END(error_exit)
23167+ENDPROC(error_exit)
23168
23169 /*
23170 * Test if a given stack is an NMI stack or not.
23171@@ -1685,9 +2192,11 @@ ENTRY(nmi)
23172 * If %cs was not the kernel segment, then the NMI triggered in user
23173 * space, which means it is definitely not nested.
23174 */
23175+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23176+ je 1f
23177 cmpl $__KERNEL_CS, 16(%rsp)
23178 jne first_nmi
23179-
23180+1:
23181 /*
23182 * Check the special variable on the stack to see if NMIs are
23183 * executing.
23184@@ -1721,8 +2230,7 @@ nested_nmi:
23185
23186 1:
23187 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23188- leaq -1*8(%rsp), %rdx
23189- movq %rdx, %rsp
23190+ subq $8, %rsp
23191 CFI_ADJUST_CFA_OFFSET 1*8
23192 leaq -10*8(%rsp), %rdx
23193 pushq_cfi $__KERNEL_DS
23194@@ -1740,6 +2248,7 @@ nested_nmi_out:
23195 CFI_RESTORE rdx
23196
23197 /* No need to check faults here */
23198+# pax_force_retaddr_bts
23199 INTERRUPT_RETURN
23200
23201 CFI_RESTORE_STATE
23202@@ -1852,9 +2361,11 @@ end_repeat_nmi:
23203 * NMI itself takes a page fault, the page fault that was preempted
23204 * will read the information from the NMI page fault and not the
23205 * origin fault. Save it off and restore it if it changes.
23206- * Use the r12 callee-saved register.
23207+ * Use the r13 callee-saved register.
23208 */
23209- movq %cr2, %r12
23210+ movq %cr2, %r13
23211+
23212+ pax_enter_kernel_nmi
23213
23214 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23215 movq %rsp,%rdi
23216@@ -1863,31 +2374,36 @@ end_repeat_nmi:
23217
23218 /* Did the NMI take a page fault? Restore cr2 if it did */
23219 movq %cr2, %rcx
23220- cmpq %rcx, %r12
23221+ cmpq %rcx, %r13
23222 je 1f
23223- movq %r12, %cr2
23224+ movq %r13, %cr2
23225 1:
23226
23227- testl %ebx,%ebx /* swapgs needed? */
23228+ testl $1,%ebx /* swapgs needed? */
23229 jnz nmi_restore
23230 nmi_swapgs:
23231 SWAPGS_UNSAFE_STACK
23232 nmi_restore:
23233+ pax_exit_kernel_nmi
23234 /* Pop the extra iret frame at once */
23235 RESTORE_ALL 6*8
23236+ testb $3, 8(%rsp)
23237+ jnz 1f
23238+ pax_force_retaddr_bts
23239+1:
23240
23241 /* Clear the NMI executing stack variable */
23242 movq $0, 5*8(%rsp)
23243 jmp irq_return
23244 CFI_ENDPROC
23245-END(nmi)
23246+ENDPROC(nmi)
23247
23248 ENTRY(ignore_sysret)
23249 CFI_STARTPROC
23250 mov $-ENOSYS,%eax
23251 sysret
23252 CFI_ENDPROC
23253-END(ignore_sysret)
23254+ENDPROC(ignore_sysret)
23255
23256 /*
23257 * End of kprobes section
23258diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23259index d4bdd25..912664c 100644
23260--- a/arch/x86/kernel/ftrace.c
23261+++ b/arch/x86/kernel/ftrace.c
23262@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23263 {
23264 unsigned char replaced[MCOUNT_INSN_SIZE];
23265
23266+ ip = ktla_ktva(ip);
23267+
23268 /*
23269 * Note: Due to modules and __init, code can
23270 * disappear and change, we need to protect against faulting
23271@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23272 unsigned char old[MCOUNT_INSN_SIZE], *new;
23273 int ret;
23274
23275- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23276+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23277 new = ftrace_call_replace(ip, (unsigned long)func);
23278
23279 /* See comment above by declaration of modifying_ftrace_code */
23280@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23281 /* Also update the regs callback function */
23282 if (!ret) {
23283 ip = (unsigned long)(&ftrace_regs_call);
23284- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23285+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23286 new = ftrace_call_replace(ip, (unsigned long)func);
23287 ret = ftrace_modify_code(ip, old, new);
23288 }
23289@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23290 * kernel identity mapping to modify code.
23291 */
23292 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23293- ip = (unsigned long)__va(__pa_symbol(ip));
23294+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23295
23296 return probe_kernel_write((void *)ip, val, size);
23297 }
23298@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23299 unsigned char replaced[MCOUNT_INSN_SIZE];
23300 unsigned char brk = BREAKPOINT_INSTRUCTION;
23301
23302- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23303+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23304 return -EFAULT;
23305
23306 /* Make sure it is what we expect it to be */
23307@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23308 return ret;
23309
23310 fail_update:
23311- probe_kernel_write((void *)ip, &old_code[0], 1);
23312+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23313 goto out;
23314 }
23315
23316@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23317 {
23318 unsigned char code[MCOUNT_INSN_SIZE];
23319
23320+ ip = ktla_ktva(ip);
23321+
23322 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23323 return -EFAULT;
23324
23325diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23326index 1be8e43..d9b9ef6 100644
23327--- a/arch/x86/kernel/head64.c
23328+++ b/arch/x86/kernel/head64.c
23329@@ -67,12 +67,12 @@ again:
23330 pgd = *pgd_p;
23331
23332 /*
23333- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23334- * critical -- __PAGE_OFFSET would point us back into the dynamic
23335+ * The use of __early_va rather than __va here is critical:
23336+ * __va would point us back into the dynamic
23337 * range and we might end up looping forever...
23338 */
23339 if (pgd)
23340- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23341+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23342 else {
23343 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23344 reset_early_page_tables();
23345@@ -82,13 +82,13 @@ again:
23346 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23347 for (i = 0; i < PTRS_PER_PUD; i++)
23348 pud_p[i] = 0;
23349- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23350+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23351 }
23352 pud_p += pud_index(address);
23353 pud = *pud_p;
23354
23355 if (pud)
23356- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23357+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23358 else {
23359 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23360 reset_early_page_tables();
23361@@ -98,7 +98,7 @@ again:
23362 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23363 for (i = 0; i < PTRS_PER_PMD; i++)
23364 pmd_p[i] = 0;
23365- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23366+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23367 }
23368 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23369 pmd_p[pmd_index(address)] = pmd;
23370@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23371 if (console_loglevel == 10)
23372 early_printk("Kernel alive\n");
23373
23374- clear_page(init_level4_pgt);
23375 /* set init_level4_pgt kernel high mapping*/
23376 init_level4_pgt[511] = early_level4_pgt[511];
23377
23378diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23379index 81ba276..30c5411 100644
23380--- a/arch/x86/kernel/head_32.S
23381+++ b/arch/x86/kernel/head_32.S
23382@@ -26,6 +26,12 @@
23383 /* Physical address */
23384 #define pa(X) ((X) - __PAGE_OFFSET)
23385
23386+#ifdef CONFIG_PAX_KERNEXEC
23387+#define ta(X) (X)
23388+#else
23389+#define ta(X) ((X) - __PAGE_OFFSET)
23390+#endif
23391+
23392 /*
23393 * References to members of the new_cpu_data structure.
23394 */
23395@@ -55,11 +61,7 @@
23396 * and small than max_low_pfn, otherwise will waste some page table entries
23397 */
23398
23399-#if PTRS_PER_PMD > 1
23400-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23401-#else
23402-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23403-#endif
23404+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23405
23406 /* Number of possible pages in the lowmem region */
23407 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23408@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23409 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23410
23411 /*
23412+ * Real beginning of normal "text" segment
23413+ */
23414+ENTRY(stext)
23415+ENTRY(_stext)
23416+
23417+/*
23418 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23419 * %esi points to the real-mode code as a 32-bit pointer.
23420 * CS and DS must be 4 GB flat segments, but we don't depend on
23421@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23422 * can.
23423 */
23424 __HEAD
23425+
23426+#ifdef CONFIG_PAX_KERNEXEC
23427+ jmp startup_32
23428+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23429+.fill PAGE_SIZE-5,1,0xcc
23430+#endif
23431+
23432 ENTRY(startup_32)
23433 movl pa(stack_start),%ecx
23434
23435@@ -106,6 +121,59 @@ ENTRY(startup_32)
23436 2:
23437 leal -__PAGE_OFFSET(%ecx),%esp
23438
23439+#ifdef CONFIG_SMP
23440+ movl $pa(cpu_gdt_table),%edi
23441+ movl $__per_cpu_load,%eax
23442+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23443+ rorl $16,%eax
23444+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23445+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23446+ movl $__per_cpu_end - 1,%eax
23447+ subl $__per_cpu_start,%eax
23448+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23449+#endif
23450+
23451+#ifdef CONFIG_PAX_MEMORY_UDEREF
23452+ movl $NR_CPUS,%ecx
23453+ movl $pa(cpu_gdt_table),%edi
23454+1:
23455+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23456+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23457+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23458+ addl $PAGE_SIZE_asm,%edi
23459+ loop 1b
23460+#endif
23461+
23462+#ifdef CONFIG_PAX_KERNEXEC
23463+ movl $pa(boot_gdt),%edi
23464+ movl $__LOAD_PHYSICAL_ADDR,%eax
23465+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23466+ rorl $16,%eax
23467+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23468+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23469+ rorl $16,%eax
23470+
23471+ ljmp $(__BOOT_CS),$1f
23472+1:
23473+
23474+ movl $NR_CPUS,%ecx
23475+ movl $pa(cpu_gdt_table),%edi
23476+ addl $__PAGE_OFFSET,%eax
23477+1:
23478+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23479+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23480+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23481+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23482+ rorl $16,%eax
23483+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23484+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23485+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23486+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23487+ rorl $16,%eax
23488+ addl $PAGE_SIZE_asm,%edi
23489+ loop 1b
23490+#endif
23491+
23492 /*
23493 * Clear BSS first so that there are no surprises...
23494 */
23495@@ -201,8 +269,11 @@ ENTRY(startup_32)
23496 movl %eax, pa(max_pfn_mapped)
23497
23498 /* Do early initialization of the fixmap area */
23499- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23500- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23501+#ifdef CONFIG_COMPAT_VDSO
23502+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23503+#else
23504+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23505+#endif
23506 #else /* Not PAE */
23507
23508 page_pde_offset = (__PAGE_OFFSET >> 20);
23509@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23510 movl %eax, pa(max_pfn_mapped)
23511
23512 /* Do early initialization of the fixmap area */
23513- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23514- movl %eax,pa(initial_page_table+0xffc)
23515+#ifdef CONFIG_COMPAT_VDSO
23516+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23517+#else
23518+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23519+#endif
23520 #endif
23521
23522 #ifdef CONFIG_PARAVIRT
23523@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23524 cmpl $num_subarch_entries, %eax
23525 jae bad_subarch
23526
23527- movl pa(subarch_entries)(,%eax,4), %eax
23528- subl $__PAGE_OFFSET, %eax
23529- jmp *%eax
23530+ jmp *pa(subarch_entries)(,%eax,4)
23531
23532 bad_subarch:
23533 WEAK(lguest_entry)
23534@@ -261,10 +333,10 @@ WEAK(xen_entry)
23535 __INITDATA
23536
23537 subarch_entries:
23538- .long default_entry /* normal x86/PC */
23539- .long lguest_entry /* lguest hypervisor */
23540- .long xen_entry /* Xen hypervisor */
23541- .long default_entry /* Moorestown MID */
23542+ .long ta(default_entry) /* normal x86/PC */
23543+ .long ta(lguest_entry) /* lguest hypervisor */
23544+ .long ta(xen_entry) /* Xen hypervisor */
23545+ .long ta(default_entry) /* Moorestown MID */
23546 num_subarch_entries = (. - subarch_entries) / 4
23547 .previous
23548 #else
23549@@ -354,6 +426,7 @@ default_entry:
23550 movl pa(mmu_cr4_features),%eax
23551 movl %eax,%cr4
23552
23553+#ifdef CONFIG_X86_PAE
23554 testb $X86_CR4_PAE, %al # check if PAE is enabled
23555 jz enable_paging
23556
23557@@ -382,6 +455,9 @@ default_entry:
23558 /* Make changes effective */
23559 wrmsr
23560
23561+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23562+#endif
23563+
23564 enable_paging:
23565
23566 /*
23567@@ -449,14 +525,20 @@ is486:
23568 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23569 movl %eax,%ss # after changing gdt.
23570
23571- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23572+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23573 movl %eax,%ds
23574 movl %eax,%es
23575
23576 movl $(__KERNEL_PERCPU), %eax
23577 movl %eax,%fs # set this cpu's percpu
23578
23579+#ifdef CONFIG_CC_STACKPROTECTOR
23580 movl $(__KERNEL_STACK_CANARY),%eax
23581+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23582+ movl $(__USER_DS),%eax
23583+#else
23584+ xorl %eax,%eax
23585+#endif
23586 movl %eax,%gs
23587
23588 xorl %eax,%eax # Clear LDT
23589@@ -512,8 +594,11 @@ setup_once:
23590 * relocation. Manually set base address in stack canary
23591 * segment descriptor.
23592 */
23593- movl $gdt_page,%eax
23594+ movl $cpu_gdt_table,%eax
23595 movl $stack_canary,%ecx
23596+#ifdef CONFIG_SMP
23597+ addl $__per_cpu_load,%ecx
23598+#endif
23599 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23600 shrl $16, %ecx
23601 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23602@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23603 /* This is global to keep gas from relaxing the jumps */
23604 ENTRY(early_idt_handler)
23605 cld
23606- cmpl $2,%ss:early_recursion_flag
23607+ cmpl $1,%ss:early_recursion_flag
23608 je hlt_loop
23609 incl %ss:early_recursion_flag
23610
23611@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23612 pushl (20+6*4)(%esp) /* trapno */
23613 pushl $fault_msg
23614 call printk
23615-#endif
23616 call dump_stack
23617+#endif
23618 hlt_loop:
23619 hlt
23620 jmp hlt_loop
23621@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23622 /* This is the default interrupt "handler" :-) */
23623 ALIGN
23624 ignore_int:
23625- cld
23626 #ifdef CONFIG_PRINTK
23627+ cmpl $2,%ss:early_recursion_flag
23628+ je hlt_loop
23629+ incl %ss:early_recursion_flag
23630+ cld
23631 pushl %eax
23632 pushl %ecx
23633 pushl %edx
23634@@ -612,9 +700,6 @@ ignore_int:
23635 movl $(__KERNEL_DS),%eax
23636 movl %eax,%ds
23637 movl %eax,%es
23638- cmpl $2,early_recursion_flag
23639- je hlt_loop
23640- incl early_recursion_flag
23641 pushl 16(%esp)
23642 pushl 24(%esp)
23643 pushl 32(%esp)
23644@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23645 /*
23646 * BSS section
23647 */
23648-__PAGE_ALIGNED_BSS
23649- .align PAGE_SIZE
23650 #ifdef CONFIG_X86_PAE
23651+.section .initial_pg_pmd,"a",@progbits
23652 initial_pg_pmd:
23653 .fill 1024*KPMDS,4,0
23654 #else
23655+.section .initial_page_table,"a",@progbits
23656 ENTRY(initial_page_table)
23657 .fill 1024,4,0
23658 #endif
23659+.section .initial_pg_fixmap,"a",@progbits
23660 initial_pg_fixmap:
23661 .fill 1024,4,0
23662+.section .empty_zero_page,"a",@progbits
23663 ENTRY(empty_zero_page)
23664 .fill 4096,1,0
23665+.section .swapper_pg_dir,"a",@progbits
23666 ENTRY(swapper_pg_dir)
23667+#ifdef CONFIG_X86_PAE
23668+ .fill 4,8,0
23669+#else
23670 .fill 1024,4,0
23671+#endif
23672
23673 /*
23674 * This starts the data section.
23675 */
23676 #ifdef CONFIG_X86_PAE
23677-__PAGE_ALIGNED_DATA
23678- /* Page-aligned for the benefit of paravirt? */
23679- .align PAGE_SIZE
23680+.section .initial_page_table,"a",@progbits
23681 ENTRY(initial_page_table)
23682 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23683 # if KPMDS == 3
23684@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23685 # error "Kernel PMDs should be 1, 2 or 3"
23686 # endif
23687 .align PAGE_SIZE /* needs to be page-sized too */
23688+
23689+#ifdef CONFIG_PAX_PER_CPU_PGD
23690+ENTRY(cpu_pgd)
23691+ .rept 2*NR_CPUS
23692+ .fill 4,8,0
23693+ .endr
23694+#endif
23695+
23696 #endif
23697
23698 .data
23699 .balign 4
23700 ENTRY(stack_start)
23701- .long init_thread_union+THREAD_SIZE
23702+ .long init_thread_union+THREAD_SIZE-8
23703
23704 __INITRODATA
23705 int_msg:
23706@@ -722,7 +820,7 @@ fault_msg:
23707 * segment size, and 32-bit linear address value:
23708 */
23709
23710- .data
23711+.section .rodata,"a",@progbits
23712 .globl boot_gdt_descr
23713 .globl idt_descr
23714
23715@@ -731,7 +829,7 @@ fault_msg:
23716 .word 0 # 32 bit align gdt_desc.address
23717 boot_gdt_descr:
23718 .word __BOOT_DS+7
23719- .long boot_gdt - __PAGE_OFFSET
23720+ .long pa(boot_gdt)
23721
23722 .word 0 # 32-bit align idt_desc.address
23723 idt_descr:
23724@@ -742,7 +840,7 @@ idt_descr:
23725 .word 0 # 32 bit align gdt_desc.address
23726 ENTRY(early_gdt_descr)
23727 .word GDT_ENTRIES*8-1
23728- .long gdt_page /* Overwritten for secondary CPUs */
23729+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23730
23731 /*
23732 * The boot_gdt must mirror the equivalent in setup.S and is
23733@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23734 .align L1_CACHE_BYTES
23735 ENTRY(boot_gdt)
23736 .fill GDT_ENTRY_BOOT_CS,8,0
23737- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23738- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23739+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23740+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23741+
23742+ .align PAGE_SIZE_asm
23743+ENTRY(cpu_gdt_table)
23744+ .rept NR_CPUS
23745+ .quad 0x0000000000000000 /* NULL descriptor */
23746+ .quad 0x0000000000000000 /* 0x0b reserved */
23747+ .quad 0x0000000000000000 /* 0x13 reserved */
23748+ .quad 0x0000000000000000 /* 0x1b reserved */
23749+
23750+#ifdef CONFIG_PAX_KERNEXEC
23751+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23752+#else
23753+ .quad 0x0000000000000000 /* 0x20 unused */
23754+#endif
23755+
23756+ .quad 0x0000000000000000 /* 0x28 unused */
23757+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23758+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23759+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23760+ .quad 0x0000000000000000 /* 0x4b reserved */
23761+ .quad 0x0000000000000000 /* 0x53 reserved */
23762+ .quad 0x0000000000000000 /* 0x5b reserved */
23763+
23764+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23765+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23766+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23767+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23768+
23769+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23770+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23771+
23772+ /*
23773+ * Segments used for calling PnP BIOS have byte granularity.
23774+ * The code segments and data segments have fixed 64k limits,
23775+ * the transfer segment sizes are set at run time.
23776+ */
23777+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23778+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23779+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23780+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23781+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23782+
23783+ /*
23784+ * The APM segments have byte granularity and their bases
23785+ * are set at run time. All have 64k limits.
23786+ */
23787+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23788+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23789+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23790+
23791+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23792+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23793+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23794+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23795+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23796+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23797+
23798+ /* Be sure this is zeroed to avoid false validations in Xen */
23799+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23800+ .endr
23801diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23802index e1aabdb..fee4fee 100644
23803--- a/arch/x86/kernel/head_64.S
23804+++ b/arch/x86/kernel/head_64.S
23805@@ -20,6 +20,8 @@
23806 #include <asm/processor-flags.h>
23807 #include <asm/percpu.h>
23808 #include <asm/nops.h>
23809+#include <asm/cpufeature.h>
23810+#include <asm/alternative-asm.h>
23811
23812 #ifdef CONFIG_PARAVIRT
23813 #include <asm/asm-offsets.h>
23814@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23815 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23816 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23817 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23818+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23819+L3_VMALLOC_START = pud_index(VMALLOC_START)
23820+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23821+L3_VMALLOC_END = pud_index(VMALLOC_END)
23822+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23823+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23824
23825 .text
23826 __HEAD
23827@@ -89,11 +97,24 @@ startup_64:
23828 * Fixup the physical addresses in the page table
23829 */
23830 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23831+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23832+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23833+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23834+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23835+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23836
23837- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23838- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23839+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23840+#ifndef CONFIG_XEN
23841+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23842+#endif
23843+
23844+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23845+
23846+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23847+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23848
23849 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23850+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23851
23852 /*
23853 * Set up the identity mapping for the switchover. These
23854@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23855 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23856 1:
23857
23858- /* Enable PAE mode and PGE */
23859- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23860+ /* Enable PAE mode and PSE/PGE */
23861+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23862 movq %rcx, %cr4
23863
23864 /* Setup early boot stage 4 level pagetables. */
23865@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23866 movl $MSR_EFER, %ecx
23867 rdmsr
23868 btsl $_EFER_SCE, %eax /* Enable System Call */
23869- btl $20,%edi /* No Execute supported? */
23870+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23871 jnc 1f
23872 btsl $_EFER_NX, %eax
23873 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23874+#ifndef CONFIG_EFI
23875+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23876+#endif
23877+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23878+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23879+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23880+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23881+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23882+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23883 1: wrmsr /* Make changes effective */
23884
23885 /* Setup cr0 */
23886@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23887 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23888 * address given in m16:64.
23889 */
23890+ pax_set_fptr_mask
23891 movq initial_code(%rip),%rax
23892 pushq $0 # fake return address to stop unwinder
23893 pushq $__KERNEL_CS # set correct cs
23894@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
23895 call dump_stack
23896 #ifdef CONFIG_KALLSYMS
23897 leaq early_idt_ripmsg(%rip),%rdi
23898- movq 40(%rsp),%rsi # %rip again
23899+ movq 88(%rsp),%rsi # %rip again
23900 call __print_symbol
23901 #endif
23902 #endif /* EARLY_PRINTK */
23903@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
23904 early_recursion_flag:
23905 .long 0
23906
23907+ .section .rodata,"a",@progbits
23908 #ifdef CONFIG_EARLY_PRINTK
23909 early_idt_msg:
23910 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23911@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
23912 NEXT_PAGE(early_dynamic_pgts)
23913 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23914
23915- .data
23916+ .section .rodata,"a",@progbits
23917
23918-#ifndef CONFIG_XEN
23919 NEXT_PAGE(init_level4_pgt)
23920- .fill 512,8,0
23921-#else
23922-NEXT_PAGE(init_level4_pgt)
23923- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23924 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23925 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23926+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23927+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23928+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23929+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23930+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23931+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23932 .org init_level4_pgt + L4_START_KERNEL*8, 0
23933 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23934 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23935
23936+#ifdef CONFIG_PAX_PER_CPU_PGD
23937+NEXT_PAGE(cpu_pgd)
23938+ .rept 2*NR_CPUS
23939+ .fill 512,8,0
23940+ .endr
23941+#endif
23942+
23943 NEXT_PAGE(level3_ident_pgt)
23944 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23945+#ifdef CONFIG_XEN
23946 .fill 511, 8, 0
23947+#else
23948+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23949+ .fill 510,8,0
23950+#endif
23951+
23952+NEXT_PAGE(level3_vmalloc_start_pgt)
23953+ .fill 512,8,0
23954+
23955+NEXT_PAGE(level3_vmalloc_end_pgt)
23956+ .fill 512,8,0
23957+
23958+NEXT_PAGE(level3_vmemmap_pgt)
23959+ .fill L3_VMEMMAP_START,8,0
23960+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23961+
23962 NEXT_PAGE(level2_ident_pgt)
23963- /* Since I easily can, map the first 1G.
23964+ /* Since I easily can, map the first 2G.
23965 * Don't set NX because code runs from these pages.
23966 */
23967- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23968-#endif
23969+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23970
23971 NEXT_PAGE(level3_kernel_pgt)
23972 .fill L3_START_KERNEL,8,0
23973@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
23974 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23975 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23976
23977+NEXT_PAGE(level2_vmemmap_pgt)
23978+ .fill 512,8,0
23979+
23980 NEXT_PAGE(level2_kernel_pgt)
23981 /*
23982 * 512 MB kernel mapping. We spend a full page on this pagetable
23983@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
23984 NEXT_PAGE(level2_fixmap_pgt)
23985 .fill 506,8,0
23986 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23987- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23988- .fill 5,8,0
23989+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23990+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23991+ .fill 4,8,0
23992
23993 NEXT_PAGE(level1_fixmap_pgt)
23994 .fill 512,8,0
23995
23996+NEXT_PAGE(level1_vsyscall_pgt)
23997+ .fill 512,8,0
23998+
23999 #undef PMDS
24000
24001- .data
24002+ .align PAGE_SIZE
24003+ENTRY(cpu_gdt_table)
24004+ .rept NR_CPUS
24005+ .quad 0x0000000000000000 /* NULL descriptor */
24006+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24007+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24008+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24009+ .quad 0x00cffb000000ffff /* __USER32_CS */
24010+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24011+ .quad 0x00affb000000ffff /* __USER_CS */
24012+
24013+#ifdef CONFIG_PAX_KERNEXEC
24014+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24015+#else
24016+ .quad 0x0 /* unused */
24017+#endif
24018+
24019+ .quad 0,0 /* TSS */
24020+ .quad 0,0 /* LDT */
24021+ .quad 0,0,0 /* three TLS descriptors */
24022+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24023+ /* asm/segment.h:GDT_ENTRIES must match this */
24024+
24025+#ifdef CONFIG_PAX_MEMORY_UDEREF
24026+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24027+#else
24028+ .quad 0x0 /* unused */
24029+#endif
24030+
24031+ /* zero the remaining page */
24032+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24033+ .endr
24034+
24035 .align 16
24036 .globl early_gdt_descr
24037 early_gdt_descr:
24038 .word GDT_ENTRIES*8-1
24039 early_gdt_descr_base:
24040- .quad INIT_PER_CPU_VAR(gdt_page)
24041+ .quad cpu_gdt_table
24042
24043 ENTRY(phys_base)
24044 /* This must match the first entry in level2_kernel_pgt */
24045 .quad 0x0000000000000000
24046
24047 #include "../../x86/xen/xen-head.S"
24048-
24049- __PAGE_ALIGNED_BSS
24050+
24051+ .section .rodata,"a",@progbits
24052 NEXT_PAGE(empty_zero_page)
24053 .skip PAGE_SIZE
24054diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24055index 0fa6912..b37438b 100644
24056--- a/arch/x86/kernel/i386_ksyms_32.c
24057+++ b/arch/x86/kernel/i386_ksyms_32.c
24058@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24059 EXPORT_SYMBOL(cmpxchg8b_emu);
24060 #endif
24061
24062+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24063+
24064 /* Networking helper routines. */
24065 EXPORT_SYMBOL(csum_partial_copy_generic);
24066+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24067+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24068
24069 EXPORT_SYMBOL(__get_user_1);
24070 EXPORT_SYMBOL(__get_user_2);
24071@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
24072
24073 EXPORT_SYMBOL(csum_partial);
24074 EXPORT_SYMBOL(empty_zero_page);
24075+
24076+#ifdef CONFIG_PAX_KERNEXEC
24077+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24078+#endif
24079+
24080+#ifdef CONFIG_PAX_PER_CPU_PGD
24081+EXPORT_SYMBOL(cpu_pgd);
24082+#endif
24083diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24084index 5d576ab..1403a03 100644
24085--- a/arch/x86/kernel/i387.c
24086+++ b/arch/x86/kernel/i387.c
24087@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24088 static inline bool interrupted_user_mode(void)
24089 {
24090 struct pt_regs *regs = get_irq_regs();
24091- return regs && user_mode_vm(regs);
24092+ return regs && user_mode(regs);
24093 }
24094
24095 /*
24096diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24097index 9a5c460..84868423 100644
24098--- a/arch/x86/kernel/i8259.c
24099+++ b/arch/x86/kernel/i8259.c
24100@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24101 static void make_8259A_irq(unsigned int irq)
24102 {
24103 disable_irq_nosync(irq);
24104- io_apic_irqs &= ~(1<<irq);
24105+ io_apic_irqs &= ~(1UL<<irq);
24106 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24107 i8259A_chip.name);
24108 enable_irq(irq);
24109@@ -209,7 +209,7 @@ spurious_8259A_irq:
24110 "spurious 8259A interrupt: IRQ%d.\n", irq);
24111 spurious_irq_mask |= irqmask;
24112 }
24113- atomic_inc(&irq_err_count);
24114+ atomic_inc_unchecked(&irq_err_count);
24115 /*
24116 * Theoretically we do not have to handle this IRQ,
24117 * but in Linux this does not cause problems and is
24118@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
24119 /* (slave's support for AEOI in flat mode is to be investigated) */
24120 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24121
24122+ pax_open_kernel();
24123 if (auto_eoi)
24124 /*
24125 * In AEOI mode we just have to mask the interrupt
24126 * when acking.
24127 */
24128- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24129+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24130 else
24131- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24132+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24133+ pax_close_kernel();
24134
24135 udelay(100); /* wait for 8259A to initialize */
24136
24137diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24138index a979b5b..1d6db75 100644
24139--- a/arch/x86/kernel/io_delay.c
24140+++ b/arch/x86/kernel/io_delay.c
24141@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24142 * Quirk table for systems that misbehave (lock up, etc.) if port
24143 * 0x80 is used:
24144 */
24145-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24146+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24147 {
24148 .callback = dmi_io_delay_0xed_port,
24149 .ident = "Compaq Presario V6000",
24150diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24151index 4ddaf66..49d5c18 100644
24152--- a/arch/x86/kernel/ioport.c
24153+++ b/arch/x86/kernel/ioport.c
24154@@ -6,6 +6,7 @@
24155 #include <linux/sched.h>
24156 #include <linux/kernel.h>
24157 #include <linux/capability.h>
24158+#include <linux/security.h>
24159 #include <linux/errno.h>
24160 #include <linux/types.h>
24161 #include <linux/ioport.h>
24162@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24163 return -EINVAL;
24164 if (turn_on && !capable(CAP_SYS_RAWIO))
24165 return -EPERM;
24166+#ifdef CONFIG_GRKERNSEC_IO
24167+ if (turn_on && grsec_disable_privio) {
24168+ gr_handle_ioperm();
24169+ return -ENODEV;
24170+ }
24171+#endif
24172
24173 /*
24174 * If it's the first ioperm() call in this thread's lifetime, set the
24175@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24176 * because the ->io_bitmap_max value must match the bitmap
24177 * contents:
24178 */
24179- tss = &per_cpu(init_tss, get_cpu());
24180+ tss = init_tss + get_cpu();
24181
24182 if (turn_on)
24183 bitmap_clear(t->io_bitmap_ptr, from, num);
24184@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24185 if (level > old) {
24186 if (!capable(CAP_SYS_RAWIO))
24187 return -EPERM;
24188+#ifdef CONFIG_GRKERNSEC_IO
24189+ if (grsec_disable_privio) {
24190+ gr_handle_iopl();
24191+ return -ENODEV;
24192+ }
24193+#endif
24194 }
24195 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24196 t->iopl = level << 12;
24197diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24198index 22d0687..e07b2a5 100644
24199--- a/arch/x86/kernel/irq.c
24200+++ b/arch/x86/kernel/irq.c
24201@@ -21,7 +21,7 @@
24202 #define CREATE_TRACE_POINTS
24203 #include <asm/trace/irq_vectors.h>
24204
24205-atomic_t irq_err_count;
24206+atomic_unchecked_t irq_err_count;
24207
24208 /* Function pointer for generic interrupt vector handling */
24209 void (*x86_platform_ipi_callback)(void) = NULL;
24210@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24211 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24212 seq_printf(p, " Machine check polls\n");
24213 #endif
24214- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24215+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24216 #if defined(CONFIG_X86_IO_APIC)
24217- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24218+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24219 #endif
24220 return 0;
24221 }
24222@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24223
24224 u64 arch_irq_stat(void)
24225 {
24226- u64 sum = atomic_read(&irq_err_count);
24227+ u64 sum = atomic_read_unchecked(&irq_err_count);
24228 return sum;
24229 }
24230
24231diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24232index 4186755..784efa0 100644
24233--- a/arch/x86/kernel/irq_32.c
24234+++ b/arch/x86/kernel/irq_32.c
24235@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24236 __asm__ __volatile__("andl %%esp,%0" :
24237 "=r" (sp) : "0" (THREAD_SIZE - 1));
24238
24239- return sp < (sizeof(struct thread_info) + STACK_WARN);
24240+ return sp < STACK_WARN;
24241 }
24242
24243 static void print_stack_overflow(void)
24244@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24245 * per-CPU IRQ handling contexts (thread information and stack)
24246 */
24247 union irq_ctx {
24248- struct thread_info tinfo;
24249- u32 stack[THREAD_SIZE/sizeof(u32)];
24250+ unsigned long previous_esp;
24251+ u32 stack[THREAD_SIZE/sizeof(u32)];
24252 } __attribute__((aligned(THREAD_SIZE)));
24253
24254 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24255@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24256 static inline int
24257 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24258 {
24259- union irq_ctx *curctx, *irqctx;
24260+ union irq_ctx *irqctx;
24261 u32 *isp, arg1, arg2;
24262
24263- curctx = (union irq_ctx *) current_thread_info();
24264 irqctx = __this_cpu_read(hardirq_ctx);
24265
24266 /*
24267@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24268 * handler) we can't do that and just have to keep using the
24269 * current stack (which is the irq stack already after all)
24270 */
24271- if (unlikely(curctx == irqctx))
24272+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24273 return 0;
24274
24275 /* build the stack frame on the IRQ stack */
24276- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24277- irqctx->tinfo.task = curctx->tinfo.task;
24278- irqctx->tinfo.previous_esp = current_stack_pointer;
24279+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24280+ irqctx->previous_esp = current_stack_pointer;
24281
24282- /* Copy the preempt_count so that the [soft]irq checks work. */
24283- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
24284+#ifdef CONFIG_PAX_MEMORY_UDEREF
24285+ __set_fs(MAKE_MM_SEG(0));
24286+#endif
24287
24288 if (unlikely(overflow))
24289 call_on_stack(print_stack_overflow, isp);
24290@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24291 : "0" (irq), "1" (desc), "2" (isp),
24292 "D" (desc->handle_irq)
24293 : "memory", "cc", "ecx");
24294+
24295+#ifdef CONFIG_PAX_MEMORY_UDEREF
24296+ __set_fs(current_thread_info()->addr_limit);
24297+#endif
24298+
24299 return 1;
24300 }
24301
24302@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24303 */
24304 void irq_ctx_init(int cpu)
24305 {
24306- union irq_ctx *irqctx;
24307-
24308 if (per_cpu(hardirq_ctx, cpu))
24309 return;
24310
24311- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24312- THREADINFO_GFP,
24313- THREAD_SIZE_ORDER));
24314- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24315- irqctx->tinfo.cpu = cpu;
24316- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
24317- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24318+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24319+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24320
24321- per_cpu(hardirq_ctx, cpu) = irqctx;
24322-
24323- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24324- THREADINFO_GFP,
24325- THREAD_SIZE_ORDER));
24326- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24327- irqctx->tinfo.cpu = cpu;
24328- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24329-
24330- per_cpu(softirq_ctx, cpu) = irqctx;
24331+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24332+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24333
24334 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24335 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24336@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
24337 asmlinkage void do_softirq(void)
24338 {
24339 unsigned long flags;
24340- struct thread_info *curctx;
24341 union irq_ctx *irqctx;
24342 u32 *isp;
24343
24344@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
24345 local_irq_save(flags);
24346
24347 if (local_softirq_pending()) {
24348- curctx = current_thread_info();
24349 irqctx = __this_cpu_read(softirq_ctx);
24350- irqctx->tinfo.task = curctx->task;
24351- irqctx->tinfo.previous_esp = current_stack_pointer;
24352+ irqctx->previous_esp = current_stack_pointer;
24353
24354 /* build the stack frame on the softirq stack */
24355- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24356+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24357+
24358+#ifdef CONFIG_PAX_MEMORY_UDEREF
24359+ __set_fs(MAKE_MM_SEG(0));
24360+#endif
24361
24362 call_on_stack(__do_softirq, isp);
24363+
24364+#ifdef CONFIG_PAX_MEMORY_UDEREF
24365+ __set_fs(current_thread_info()->addr_limit);
24366+#endif
24367+
24368 /*
24369 * Shouldn't happen, we returned above if in_interrupt():
24370 */
24371@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24372 if (unlikely(!desc))
24373 return false;
24374
24375- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24376+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24377 if (unlikely(overflow))
24378 print_stack_overflow();
24379 desc->handle_irq(irq, desc);
24380diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24381index d04d3ec..ea4b374 100644
24382--- a/arch/x86/kernel/irq_64.c
24383+++ b/arch/x86/kernel/irq_64.c
24384@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24385 u64 estack_top, estack_bottom;
24386 u64 curbase = (u64)task_stack_page(current);
24387
24388- if (user_mode_vm(regs))
24389+ if (user_mode(regs))
24390 return;
24391
24392 if (regs->sp >= curbase + sizeof(struct thread_info) +
24393diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24394index ee11b7d..4df4d0c 100644
24395--- a/arch/x86/kernel/jump_label.c
24396+++ b/arch/x86/kernel/jump_label.c
24397@@ -49,7 +49,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24398 * We are enabling this jump label. If it is not a nop
24399 * then something must have gone wrong.
24400 */
24401- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) != 0))
24402+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5) != 0))
24403 bug_at((void *)entry->code, __LINE__);
24404
24405 code.jump = 0xe9;
24406@@ -64,13 +64,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24407 */
24408 if (init) {
24409 const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
24410- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24411+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24412 bug_at((void *)entry->code, __LINE__);
24413 } else {
24414 code.jump = 0xe9;
24415 code.offset = entry->target -
24416 (entry->code + JUMP_LABEL_NOP_SIZE);
24417- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24418+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24419 bug_at((void *)entry->code, __LINE__);
24420 }
24421 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24422diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24423index 836f832..a8bda67 100644
24424--- a/arch/x86/kernel/kgdb.c
24425+++ b/arch/x86/kernel/kgdb.c
24426@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24427 #ifdef CONFIG_X86_32
24428 switch (regno) {
24429 case GDB_SS:
24430- if (!user_mode_vm(regs))
24431+ if (!user_mode(regs))
24432 *(unsigned long *)mem = __KERNEL_DS;
24433 break;
24434 case GDB_SP:
24435- if (!user_mode_vm(regs))
24436+ if (!user_mode(regs))
24437 *(unsigned long *)mem = kernel_stack_pointer(regs);
24438 break;
24439 case GDB_GS:
24440@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24441 bp->attr.bp_addr = breakinfo[breakno].addr;
24442 bp->attr.bp_len = breakinfo[breakno].len;
24443 bp->attr.bp_type = breakinfo[breakno].type;
24444- info->address = breakinfo[breakno].addr;
24445+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24446+ info->address = ktla_ktva(breakinfo[breakno].addr);
24447+ else
24448+ info->address = breakinfo[breakno].addr;
24449 info->len = breakinfo[breakno].len;
24450 info->type = breakinfo[breakno].type;
24451 val = arch_install_hw_breakpoint(bp);
24452@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24453 case 'k':
24454 /* clear the trace bit */
24455 linux_regs->flags &= ~X86_EFLAGS_TF;
24456- atomic_set(&kgdb_cpu_doing_single_step, -1);
24457+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24458
24459 /* set the trace bit if we're stepping */
24460 if (remcomInBuffer[0] == 's') {
24461 linux_regs->flags |= X86_EFLAGS_TF;
24462- atomic_set(&kgdb_cpu_doing_single_step,
24463+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24464 raw_smp_processor_id());
24465 }
24466
24467@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24468
24469 switch (cmd) {
24470 case DIE_DEBUG:
24471- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24472+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24473 if (user_mode(regs))
24474 return single_step_cont(regs, args);
24475 break;
24476@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24477 #endif /* CONFIG_DEBUG_RODATA */
24478
24479 bpt->type = BP_BREAKPOINT;
24480- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24481+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24482 BREAK_INSTR_SIZE);
24483 if (err)
24484 return err;
24485- err = probe_kernel_write((char *)bpt->bpt_addr,
24486+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24487 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24488 #ifdef CONFIG_DEBUG_RODATA
24489 if (!err)
24490@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24491 return -EBUSY;
24492 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24493 BREAK_INSTR_SIZE);
24494- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24495+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24496 if (err)
24497 return err;
24498 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24499@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24500 if (mutex_is_locked(&text_mutex))
24501 goto knl_write;
24502 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24503- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24504+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24505 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24506 goto knl_write;
24507 return err;
24508 knl_write:
24509 #endif /* CONFIG_DEBUG_RODATA */
24510- return probe_kernel_write((char *)bpt->bpt_addr,
24511+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24512 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24513 }
24514
24515diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24516index 79a3f96..6ba030a 100644
24517--- a/arch/x86/kernel/kprobes/core.c
24518+++ b/arch/x86/kernel/kprobes/core.c
24519@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24520 s32 raddr;
24521 } __packed *insn;
24522
24523- insn = (struct __arch_relative_insn *)from;
24524+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24525+
24526+ pax_open_kernel();
24527 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24528 insn->op = op;
24529+ pax_close_kernel();
24530 }
24531
24532 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24533@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24534 kprobe_opcode_t opcode;
24535 kprobe_opcode_t *orig_opcodes = opcodes;
24536
24537- if (search_exception_tables((unsigned long)opcodes))
24538+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24539 return 0; /* Page fault may occur on this address. */
24540
24541 retry:
24542@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24543 * for the first byte, we can recover the original instruction
24544 * from it and kp->opcode.
24545 */
24546- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24547+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24548 buf[0] = kp->opcode;
24549- return (unsigned long)buf;
24550+ return ktva_ktla((unsigned long)buf);
24551 }
24552
24553 /*
24554@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24555 /* Another subsystem puts a breakpoint, failed to recover */
24556 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24557 return 0;
24558+ pax_open_kernel();
24559 memcpy(dest, insn.kaddr, insn.length);
24560+ pax_close_kernel();
24561
24562 #ifdef CONFIG_X86_64
24563 if (insn_rip_relative(&insn)) {
24564@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24565 return 0;
24566 }
24567 disp = (u8 *) dest + insn_offset_displacement(&insn);
24568+ pax_open_kernel();
24569 *(s32 *) disp = (s32) newdisp;
24570+ pax_close_kernel();
24571 }
24572 #endif
24573 return insn.length;
24574@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24575 * nor set current_kprobe, because it doesn't use single
24576 * stepping.
24577 */
24578- regs->ip = (unsigned long)p->ainsn.insn;
24579+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24580 preempt_enable_no_resched();
24581 return;
24582 }
24583@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24584 regs->flags &= ~X86_EFLAGS_IF;
24585 /* single step inline if the instruction is an int3 */
24586 if (p->opcode == BREAKPOINT_INSTRUCTION)
24587- regs->ip = (unsigned long)p->addr;
24588+ regs->ip = ktla_ktva((unsigned long)p->addr);
24589 else
24590- regs->ip = (unsigned long)p->ainsn.insn;
24591+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24592 }
24593
24594 /*
24595@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24596 setup_singlestep(p, regs, kcb, 0);
24597 return 1;
24598 }
24599- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24600+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24601 /*
24602 * The breakpoint instruction was removed right
24603 * after we hit it. Another cpu has removed
24604@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24605 " movq %rax, 152(%rsp)\n"
24606 RESTORE_REGS_STRING
24607 " popfq\n"
24608+#ifdef KERNEXEC_PLUGIN
24609+ " btsq $63,(%rsp)\n"
24610+#endif
24611 #else
24612 " pushf\n"
24613 SAVE_REGS_STRING
24614@@ -779,7 +789,7 @@ static void __kprobes
24615 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24616 {
24617 unsigned long *tos = stack_addr(regs);
24618- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24619+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24620 unsigned long orig_ip = (unsigned long)p->addr;
24621 kprobe_opcode_t *insn = p->ainsn.insn;
24622
24623@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24624 struct die_args *args = data;
24625 int ret = NOTIFY_DONE;
24626
24627- if (args->regs && user_mode_vm(args->regs))
24628+ if (args->regs && user_mode(args->regs))
24629 return ret;
24630
24631 switch (val) {
24632diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24633index 898160b..758cde8 100644
24634--- a/arch/x86/kernel/kprobes/opt.c
24635+++ b/arch/x86/kernel/kprobes/opt.c
24636@@ -79,6 +79,7 @@ found:
24637 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24638 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24639 {
24640+ pax_open_kernel();
24641 #ifdef CONFIG_X86_64
24642 *addr++ = 0x48;
24643 *addr++ = 0xbf;
24644@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24645 *addr++ = 0xb8;
24646 #endif
24647 *(unsigned long *)addr = val;
24648+ pax_close_kernel();
24649 }
24650
24651 asm (
24652@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24653 * Verify if the address gap is in 2GB range, because this uses
24654 * a relative jump.
24655 */
24656- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24657+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24658 if (abs(rel) > 0x7fffffff)
24659 return -ERANGE;
24660
24661@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24662 op->optinsn.size = ret;
24663
24664 /* Copy arch-dep-instance from template */
24665- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24666+ pax_open_kernel();
24667+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24668+ pax_close_kernel();
24669
24670 /* Set probe information */
24671 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24672
24673 /* Set probe function call */
24674- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24675+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24676
24677 /* Set returning jmp instruction at the tail of out-of-line buffer */
24678- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24679+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24680 (u8 *)op->kp.addr + op->optinsn.size);
24681
24682 flush_icache_range((unsigned long) buf,
24683@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24684 WARN_ON(kprobe_disabled(&op->kp));
24685
24686 /* Backup instructions which will be replaced by jump address */
24687- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24688+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24689 RELATIVE_ADDR_SIZE);
24690
24691 insn_buf[0] = RELATIVEJUMP_OPCODE;
24692@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24693 /* This kprobe is really able to run optimized path. */
24694 op = container_of(p, struct optimized_kprobe, kp);
24695 /* Detour through copied instructions */
24696- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24697+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24698 if (!reenter)
24699 reset_current_kprobe();
24700 preempt_enable_no_resched();
24701diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24702index ebc9873..1b9724b 100644
24703--- a/arch/x86/kernel/ldt.c
24704+++ b/arch/x86/kernel/ldt.c
24705@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24706 if (reload) {
24707 #ifdef CONFIG_SMP
24708 preempt_disable();
24709- load_LDT(pc);
24710+ load_LDT_nolock(pc);
24711 if (!cpumask_equal(mm_cpumask(current->mm),
24712 cpumask_of(smp_processor_id())))
24713 smp_call_function(flush_ldt, current->mm, 1);
24714 preempt_enable();
24715 #else
24716- load_LDT(pc);
24717+ load_LDT_nolock(pc);
24718 #endif
24719 }
24720 if (oldsize) {
24721@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24722 return err;
24723
24724 for (i = 0; i < old->size; i++)
24725- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24726+ write_ldt_entry(new->ldt, i, old->ldt + i);
24727 return 0;
24728 }
24729
24730@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24731 retval = copy_ldt(&mm->context, &old_mm->context);
24732 mutex_unlock(&old_mm->context.lock);
24733 }
24734+
24735+ if (tsk == current) {
24736+ mm->context.vdso = 0;
24737+
24738+#ifdef CONFIG_X86_32
24739+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24740+ mm->context.user_cs_base = 0UL;
24741+ mm->context.user_cs_limit = ~0UL;
24742+
24743+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24744+ cpus_clear(mm->context.cpu_user_cs_mask);
24745+#endif
24746+
24747+#endif
24748+#endif
24749+
24750+ }
24751+
24752 return retval;
24753 }
24754
24755@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24756 }
24757 }
24758
24759+#ifdef CONFIG_PAX_SEGMEXEC
24760+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24761+ error = -EINVAL;
24762+ goto out_unlock;
24763+ }
24764+#endif
24765+
24766 fill_ldt(&ldt, &ldt_info);
24767 if (oldmode)
24768 ldt.avl = 0;
24769diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24770index 5b19e4d..6476a76 100644
24771--- a/arch/x86/kernel/machine_kexec_32.c
24772+++ b/arch/x86/kernel/machine_kexec_32.c
24773@@ -26,7 +26,7 @@
24774 #include <asm/cacheflush.h>
24775 #include <asm/debugreg.h>
24776
24777-static void set_idt(void *newidt, __u16 limit)
24778+static void set_idt(struct desc_struct *newidt, __u16 limit)
24779 {
24780 struct desc_ptr curidt;
24781
24782@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24783 }
24784
24785
24786-static void set_gdt(void *newgdt, __u16 limit)
24787+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24788 {
24789 struct desc_ptr curgdt;
24790
24791@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24792 }
24793
24794 control_page = page_address(image->control_code_page);
24795- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24796+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24797
24798 relocate_kernel_ptr = control_page;
24799 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24800diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24801index 15c9876..0a43909 100644
24802--- a/arch/x86/kernel/microcode_core.c
24803+++ b/arch/x86/kernel/microcode_core.c
24804@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24805 return NOTIFY_OK;
24806 }
24807
24808-static struct notifier_block __refdata mc_cpu_notifier = {
24809+static struct notifier_block mc_cpu_notifier = {
24810 .notifier_call = mc_cpu_callback,
24811 };
24812
24813diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24814index 5fb2ceb..3ae90bb 100644
24815--- a/arch/x86/kernel/microcode_intel.c
24816+++ b/arch/x86/kernel/microcode_intel.c
24817@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24818
24819 static int get_ucode_user(void *to, const void *from, size_t n)
24820 {
24821- return copy_from_user(to, from, n);
24822+ return copy_from_user(to, (const void __force_user *)from, n);
24823 }
24824
24825 static enum ucode_state
24826 request_microcode_user(int cpu, const void __user *buf, size_t size)
24827 {
24828- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24829+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24830 }
24831
24832 static void microcode_fini_cpu(int cpu)
24833diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24834index 216a4d7..228255a 100644
24835--- a/arch/x86/kernel/module.c
24836+++ b/arch/x86/kernel/module.c
24837@@ -43,15 +43,60 @@ do { \
24838 } while (0)
24839 #endif
24840
24841-void *module_alloc(unsigned long size)
24842+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24843 {
24844- if (PAGE_ALIGN(size) > MODULES_LEN)
24845+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24846 return NULL;
24847 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24848- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24849+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24850 -1, __builtin_return_address(0));
24851 }
24852
24853+void *module_alloc(unsigned long size)
24854+{
24855+
24856+#ifdef CONFIG_PAX_KERNEXEC
24857+ return __module_alloc(size, PAGE_KERNEL);
24858+#else
24859+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24860+#endif
24861+
24862+}
24863+
24864+#ifdef CONFIG_PAX_KERNEXEC
24865+#ifdef CONFIG_X86_32
24866+void *module_alloc_exec(unsigned long size)
24867+{
24868+ struct vm_struct *area;
24869+
24870+ if (size == 0)
24871+ return NULL;
24872+
24873+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24874+ return area ? area->addr : NULL;
24875+}
24876+EXPORT_SYMBOL(module_alloc_exec);
24877+
24878+void module_free_exec(struct module *mod, void *module_region)
24879+{
24880+ vunmap(module_region);
24881+}
24882+EXPORT_SYMBOL(module_free_exec);
24883+#else
24884+void module_free_exec(struct module *mod, void *module_region)
24885+{
24886+ module_free(mod, module_region);
24887+}
24888+EXPORT_SYMBOL(module_free_exec);
24889+
24890+void *module_alloc_exec(unsigned long size)
24891+{
24892+ return __module_alloc(size, PAGE_KERNEL_RX);
24893+}
24894+EXPORT_SYMBOL(module_alloc_exec);
24895+#endif
24896+#endif
24897+
24898 #ifdef CONFIG_X86_32
24899 int apply_relocate(Elf32_Shdr *sechdrs,
24900 const char *strtab,
24901@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24902 unsigned int i;
24903 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24904 Elf32_Sym *sym;
24905- uint32_t *location;
24906+ uint32_t *plocation, location;
24907
24908 DEBUGP("Applying relocate section %u to %u\n",
24909 relsec, sechdrs[relsec].sh_info);
24910 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24911 /* This is where to make the change */
24912- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24913- + rel[i].r_offset;
24914+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24915+ location = (uint32_t)plocation;
24916+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24917+ plocation = ktla_ktva((void *)plocation);
24918 /* This is the symbol it is referring to. Note that all
24919 undefined symbols have been resolved. */
24920 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24921@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24922 switch (ELF32_R_TYPE(rel[i].r_info)) {
24923 case R_386_32:
24924 /* We add the value into the location given */
24925- *location += sym->st_value;
24926+ pax_open_kernel();
24927+ *plocation += sym->st_value;
24928+ pax_close_kernel();
24929 break;
24930 case R_386_PC32:
24931 /* Add the value, subtract its position */
24932- *location += sym->st_value - (uint32_t)location;
24933+ pax_open_kernel();
24934+ *plocation += sym->st_value - location;
24935+ pax_close_kernel();
24936 break;
24937 default:
24938 pr_err("%s: Unknown relocation: %u\n",
24939@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24940 case R_X86_64_NONE:
24941 break;
24942 case R_X86_64_64:
24943+ pax_open_kernel();
24944 *(u64 *)loc = val;
24945+ pax_close_kernel();
24946 break;
24947 case R_X86_64_32:
24948+ pax_open_kernel();
24949 *(u32 *)loc = val;
24950+ pax_close_kernel();
24951 if (val != *(u32 *)loc)
24952 goto overflow;
24953 break;
24954 case R_X86_64_32S:
24955+ pax_open_kernel();
24956 *(s32 *)loc = val;
24957+ pax_close_kernel();
24958 if ((s64)val != *(s32 *)loc)
24959 goto overflow;
24960 break;
24961 case R_X86_64_PC32:
24962 val -= (u64)loc;
24963+ pax_open_kernel();
24964 *(u32 *)loc = val;
24965+ pax_close_kernel();
24966+
24967 #if 0
24968 if ((s64)val != *(s32 *)loc)
24969 goto overflow;
24970diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24971index 88458fa..349f7a4 100644
24972--- a/arch/x86/kernel/msr.c
24973+++ b/arch/x86/kernel/msr.c
24974@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24975 return notifier_from_errno(err);
24976 }
24977
24978-static struct notifier_block __refdata msr_class_cpu_notifier = {
24979+static struct notifier_block msr_class_cpu_notifier = {
24980 .notifier_call = msr_class_cpu_callback,
24981 };
24982
24983diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24984index 6fcb49c..5b3f4ff 100644
24985--- a/arch/x86/kernel/nmi.c
24986+++ b/arch/x86/kernel/nmi.c
24987@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24988 return handled;
24989 }
24990
24991-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24992+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24993 {
24994 struct nmi_desc *desc = nmi_to_desc(type);
24995 unsigned long flags;
24996@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24997 * event confuses some handlers (kdump uses this flag)
24998 */
24999 if (action->flags & NMI_FLAG_FIRST)
25000- list_add_rcu(&action->list, &desc->head);
25001+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25002 else
25003- list_add_tail_rcu(&action->list, &desc->head);
25004+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25005
25006 spin_unlock_irqrestore(&desc->lock, flags);
25007 return 0;
25008@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25009 if (!strcmp(n->name, name)) {
25010 WARN(in_nmi(),
25011 "Trying to free NMI (%s) from NMI context!\n", n->name);
25012- list_del_rcu(&n->list);
25013+ pax_list_del_rcu((struct list_head *)&n->list);
25014 break;
25015 }
25016 }
25017@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25018 dotraplinkage notrace __kprobes void
25019 do_nmi(struct pt_regs *regs, long error_code)
25020 {
25021+
25022+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25023+ if (!user_mode(regs)) {
25024+ unsigned long cs = regs->cs & 0xFFFF;
25025+ unsigned long ip = ktva_ktla(regs->ip);
25026+
25027+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25028+ regs->ip = ip;
25029+ }
25030+#endif
25031+
25032 nmi_nesting_preprocess(regs);
25033
25034 nmi_enter();
25035diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25036index 6d9582e..f746287 100644
25037--- a/arch/x86/kernel/nmi_selftest.c
25038+++ b/arch/x86/kernel/nmi_selftest.c
25039@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25040 {
25041 /* trap all the unknown NMIs we may generate */
25042 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25043- __initdata);
25044+ __initconst);
25045 }
25046
25047 static void __init cleanup_nmi_testsuite(void)
25048@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25049 unsigned long timeout;
25050
25051 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25052- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25053+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25054 nmi_fail = FAILURE;
25055 return;
25056 }
25057diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25058index bbb6c73..24a58ef 100644
25059--- a/arch/x86/kernel/paravirt-spinlocks.c
25060+++ b/arch/x86/kernel/paravirt-spinlocks.c
25061@@ -8,7 +8,7 @@
25062
25063 #include <asm/paravirt.h>
25064
25065-struct pv_lock_ops pv_lock_ops = {
25066+struct pv_lock_ops pv_lock_ops __read_only = {
25067 #ifdef CONFIG_SMP
25068 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25069 .unlock_kick = paravirt_nop,
25070diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25071index 1b10af8..0b58cbc 100644
25072--- a/arch/x86/kernel/paravirt.c
25073+++ b/arch/x86/kernel/paravirt.c
25074@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25075 {
25076 return x;
25077 }
25078+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25079+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25080+#endif
25081
25082 void __init default_banner(void)
25083 {
25084@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25085 if (opfunc == NULL)
25086 /* If there's no function, patch it with a ud2a (BUG) */
25087 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25088- else if (opfunc == _paravirt_nop)
25089+ else if (opfunc == (void *)_paravirt_nop)
25090 /* If the operation is a nop, then nop the callsite */
25091 ret = paravirt_patch_nop();
25092
25093 /* identity functions just return their single argument */
25094- else if (opfunc == _paravirt_ident_32)
25095+ else if (opfunc == (void *)_paravirt_ident_32)
25096 ret = paravirt_patch_ident_32(insnbuf, len);
25097- else if (opfunc == _paravirt_ident_64)
25098+ else if (opfunc == (void *)_paravirt_ident_64)
25099 ret = paravirt_patch_ident_64(insnbuf, len);
25100+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25101+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25102+ ret = paravirt_patch_ident_64(insnbuf, len);
25103+#endif
25104
25105 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25106 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25107@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25108 if (insn_len > len || start == NULL)
25109 insn_len = len;
25110 else
25111- memcpy(insnbuf, start, insn_len);
25112+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25113
25114 return insn_len;
25115 }
25116@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25117 return this_cpu_read(paravirt_lazy_mode);
25118 }
25119
25120-struct pv_info pv_info = {
25121+struct pv_info pv_info __read_only = {
25122 .name = "bare hardware",
25123 .paravirt_enabled = 0,
25124 .kernel_rpl = 0,
25125@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25126 #endif
25127 };
25128
25129-struct pv_init_ops pv_init_ops = {
25130+struct pv_init_ops pv_init_ops __read_only = {
25131 .patch = native_patch,
25132 };
25133
25134-struct pv_time_ops pv_time_ops = {
25135+struct pv_time_ops pv_time_ops __read_only = {
25136 .sched_clock = native_sched_clock,
25137 .steal_clock = native_steal_clock,
25138 };
25139
25140-__visible struct pv_irq_ops pv_irq_ops = {
25141+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25142 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25143 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25144 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25145@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25146 #endif
25147 };
25148
25149-__visible struct pv_cpu_ops pv_cpu_ops = {
25150+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25151 .cpuid = native_cpuid,
25152 .get_debugreg = native_get_debugreg,
25153 .set_debugreg = native_set_debugreg,
25154@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25155 .end_context_switch = paravirt_nop,
25156 };
25157
25158-struct pv_apic_ops pv_apic_ops = {
25159+struct pv_apic_ops pv_apic_ops __read_only= {
25160 #ifdef CONFIG_X86_LOCAL_APIC
25161 .startup_ipi_hook = paravirt_nop,
25162 #endif
25163 };
25164
25165-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25166+#ifdef CONFIG_X86_32
25167+#ifdef CONFIG_X86_PAE
25168+/* 64-bit pagetable entries */
25169+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25170+#else
25171 /* 32-bit pagetable entries */
25172 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25173+#endif
25174 #else
25175 /* 64-bit pagetable entries */
25176 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25177 #endif
25178
25179-struct pv_mmu_ops pv_mmu_ops = {
25180+struct pv_mmu_ops pv_mmu_ops __read_only = {
25181
25182 .read_cr2 = native_read_cr2,
25183 .write_cr2 = native_write_cr2,
25184@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25185 .make_pud = PTE_IDENT,
25186
25187 .set_pgd = native_set_pgd,
25188+ .set_pgd_batched = native_set_pgd_batched,
25189 #endif
25190 #endif /* PAGETABLE_LEVELS >= 3 */
25191
25192@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25193 },
25194
25195 .set_fixmap = native_set_fixmap,
25196+
25197+#ifdef CONFIG_PAX_KERNEXEC
25198+ .pax_open_kernel = native_pax_open_kernel,
25199+ .pax_close_kernel = native_pax_close_kernel,
25200+#endif
25201+
25202 };
25203
25204 EXPORT_SYMBOL_GPL(pv_time_ops);
25205diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25206index 299d493..2ccb0ee 100644
25207--- a/arch/x86/kernel/pci-calgary_64.c
25208+++ b/arch/x86/kernel/pci-calgary_64.c
25209@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25210 tce_space = be64_to_cpu(readq(target));
25211 tce_space = tce_space & TAR_SW_BITS;
25212
25213- tce_space = tce_space & (~specified_table_size);
25214+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25215 info->tce_space = (u64 *)__va(tce_space);
25216 }
25217 }
25218diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25219index 35ccf75..7a15747 100644
25220--- a/arch/x86/kernel/pci-iommu_table.c
25221+++ b/arch/x86/kernel/pci-iommu_table.c
25222@@ -2,7 +2,7 @@
25223 #include <asm/iommu_table.h>
25224 #include <linux/string.h>
25225 #include <linux/kallsyms.h>
25226-
25227+#include <linux/sched.h>
25228
25229 #define DEBUG 1
25230
25231diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25232index 6c483ba..d10ce2f 100644
25233--- a/arch/x86/kernel/pci-swiotlb.c
25234+++ b/arch/x86/kernel/pci-swiotlb.c
25235@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25236 void *vaddr, dma_addr_t dma_addr,
25237 struct dma_attrs *attrs)
25238 {
25239- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25240+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25241 }
25242
25243 static struct dma_map_ops swiotlb_dma_ops = {
25244diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25245index 3fb8d95..254dc51 100644
25246--- a/arch/x86/kernel/process.c
25247+++ b/arch/x86/kernel/process.c
25248@@ -36,7 +36,8 @@
25249 * section. Since TSS's are completely CPU-local, we want them
25250 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25251 */
25252-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25253+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25254+EXPORT_SYMBOL(init_tss);
25255
25256 #ifdef CONFIG_X86_64
25257 static DEFINE_PER_CPU(unsigned char, is_idle);
25258@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25259 task_xstate_cachep =
25260 kmem_cache_create("task_xstate", xstate_size,
25261 __alignof__(union thread_xstate),
25262- SLAB_PANIC | SLAB_NOTRACK, NULL);
25263+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25264 }
25265
25266 /*
25267@@ -105,7 +106,7 @@ void exit_thread(void)
25268 unsigned long *bp = t->io_bitmap_ptr;
25269
25270 if (bp) {
25271- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25272+ struct tss_struct *tss = init_tss + get_cpu();
25273
25274 t->io_bitmap_ptr = NULL;
25275 clear_thread_flag(TIF_IO_BITMAP);
25276@@ -125,6 +126,9 @@ void flush_thread(void)
25277 {
25278 struct task_struct *tsk = current;
25279
25280+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25281+ loadsegment(gs, 0);
25282+#endif
25283 flush_ptrace_hw_breakpoint(tsk);
25284 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25285 drop_init_fpu(tsk);
25286@@ -271,7 +275,7 @@ static void __exit_idle(void)
25287 void exit_idle(void)
25288 {
25289 /* idle loop has pid 0 */
25290- if (current->pid)
25291+ if (task_pid_nr(current))
25292 return;
25293 __exit_idle();
25294 }
25295@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25296 return ret;
25297 }
25298 #endif
25299-void stop_this_cpu(void *dummy)
25300+__noreturn void stop_this_cpu(void *dummy)
25301 {
25302 local_irq_disable();
25303 /*
25304@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25305 }
25306 early_param("idle", idle_setup);
25307
25308-unsigned long arch_align_stack(unsigned long sp)
25309+#ifdef CONFIG_PAX_RANDKSTACK
25310+void pax_randomize_kstack(struct pt_regs *regs)
25311 {
25312- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25313- sp -= get_random_int() % 8192;
25314- return sp & ~0xf;
25315-}
25316+ struct thread_struct *thread = &current->thread;
25317+ unsigned long time;
25318
25319-unsigned long arch_randomize_brk(struct mm_struct *mm)
25320-{
25321- unsigned long range_end = mm->brk + 0x02000000;
25322- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25323-}
25324+ if (!randomize_va_space)
25325+ return;
25326+
25327+ if (v8086_mode(regs))
25328+ return;
25329
25330+ rdtscl(time);
25331+
25332+ /* P4 seems to return a 0 LSB, ignore it */
25333+#ifdef CONFIG_MPENTIUM4
25334+ time &= 0x3EUL;
25335+ time <<= 2;
25336+#elif defined(CONFIG_X86_64)
25337+ time &= 0xFUL;
25338+ time <<= 4;
25339+#else
25340+ time &= 0x1FUL;
25341+ time <<= 3;
25342+#endif
25343+
25344+ thread->sp0 ^= time;
25345+ load_sp0(init_tss + smp_processor_id(), thread);
25346+
25347+#ifdef CONFIG_X86_64
25348+ this_cpu_write(kernel_stack, thread->sp0);
25349+#endif
25350+}
25351+#endif
25352diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25353index 884f98f..ec23e04 100644
25354--- a/arch/x86/kernel/process_32.c
25355+++ b/arch/x86/kernel/process_32.c
25356@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25357 unsigned long thread_saved_pc(struct task_struct *tsk)
25358 {
25359 return ((unsigned long *)tsk->thread.sp)[3];
25360+//XXX return tsk->thread.eip;
25361 }
25362
25363 void __show_regs(struct pt_regs *regs, int all)
25364@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25365 unsigned long sp;
25366 unsigned short ss, gs;
25367
25368- if (user_mode_vm(regs)) {
25369+ if (user_mode(regs)) {
25370 sp = regs->sp;
25371 ss = regs->ss & 0xffff;
25372- gs = get_user_gs(regs);
25373 } else {
25374 sp = kernel_stack_pointer(regs);
25375 savesegment(ss, ss);
25376- savesegment(gs, gs);
25377 }
25378+ gs = get_user_gs(regs);
25379
25380 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25381 (u16)regs->cs, regs->ip, regs->flags,
25382- smp_processor_id());
25383+ raw_smp_processor_id());
25384 print_symbol("EIP is at %s\n", regs->ip);
25385
25386 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25387@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25388 int copy_thread(unsigned long clone_flags, unsigned long sp,
25389 unsigned long arg, struct task_struct *p)
25390 {
25391- struct pt_regs *childregs = task_pt_regs(p);
25392+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25393 struct task_struct *tsk;
25394 int err;
25395
25396 p->thread.sp = (unsigned long) childregs;
25397 p->thread.sp0 = (unsigned long) (childregs+1);
25398+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25399
25400 if (unlikely(p->flags & PF_KTHREAD)) {
25401 /* kernel thread */
25402 memset(childregs, 0, sizeof(struct pt_regs));
25403 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25404- task_user_gs(p) = __KERNEL_STACK_CANARY;
25405- childregs->ds = __USER_DS;
25406- childregs->es = __USER_DS;
25407+ savesegment(gs, childregs->gs);
25408+ childregs->ds = __KERNEL_DS;
25409+ childregs->es = __KERNEL_DS;
25410 childregs->fs = __KERNEL_PERCPU;
25411 childregs->bx = sp; /* function */
25412 childregs->bp = arg;
25413@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25414 struct thread_struct *prev = &prev_p->thread,
25415 *next = &next_p->thread;
25416 int cpu = smp_processor_id();
25417- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25418+ struct tss_struct *tss = init_tss + cpu;
25419 fpu_switch_t fpu;
25420
25421 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25422@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25423 */
25424 lazy_save_gs(prev->gs);
25425
25426+#ifdef CONFIG_PAX_MEMORY_UDEREF
25427+ __set_fs(task_thread_info(next_p)->addr_limit);
25428+#endif
25429+
25430 /*
25431 * Load the per-thread Thread-Local Storage descriptor.
25432 */
25433@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25434 */
25435 arch_end_context_switch(next_p);
25436
25437+ this_cpu_write(current_task, next_p);
25438+ this_cpu_write(current_tinfo, &next_p->tinfo);
25439+
25440 /*
25441 * Restore %gs if needed (which is common)
25442 */
25443@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25444
25445 switch_fpu_finish(next_p, fpu);
25446
25447- this_cpu_write(current_task, next_p);
25448-
25449 return prev_p;
25450 }
25451
25452@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
25453 } while (count++ < 16);
25454 return 0;
25455 }
25456-
25457diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25458index bb1dc51..08dda7f 100644
25459--- a/arch/x86/kernel/process_64.c
25460+++ b/arch/x86/kernel/process_64.c
25461@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25462 struct pt_regs *childregs;
25463 struct task_struct *me = current;
25464
25465- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25466+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25467 childregs = task_pt_regs(p);
25468 p->thread.sp = (unsigned long) childregs;
25469 p->thread.usersp = me->thread.usersp;
25470+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25471 set_tsk_thread_flag(p, TIF_FORK);
25472 p->fpu_counter = 0;
25473 p->thread.io_bitmap_ptr = NULL;
25474@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25475 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25476 savesegment(es, p->thread.es);
25477 savesegment(ds, p->thread.ds);
25478+ savesegment(ss, p->thread.ss);
25479+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25480 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25481
25482 if (unlikely(p->flags & PF_KTHREAD)) {
25483@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25484 struct thread_struct *prev = &prev_p->thread;
25485 struct thread_struct *next = &next_p->thread;
25486 int cpu = smp_processor_id();
25487- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25488+ struct tss_struct *tss = init_tss + cpu;
25489 unsigned fsindex, gsindex;
25490 fpu_switch_t fpu;
25491
25492@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25493 if (unlikely(next->ds | prev->ds))
25494 loadsegment(ds, next->ds);
25495
25496+ savesegment(ss, prev->ss);
25497+ if (unlikely(next->ss != prev->ss))
25498+ loadsegment(ss, next->ss);
25499
25500 /* We must save %fs and %gs before load_TLS() because
25501 * %fs and %gs may be cleared by load_TLS().
25502@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25503 prev->usersp = this_cpu_read(old_rsp);
25504 this_cpu_write(old_rsp, next->usersp);
25505 this_cpu_write(current_task, next_p);
25506+ this_cpu_write(current_tinfo, &next_p->tinfo);
25507
25508- this_cpu_write(kernel_stack,
25509- (unsigned long)task_stack_page(next_p) +
25510- THREAD_SIZE - KERNEL_STACK_OFFSET);
25511+ this_cpu_write(kernel_stack, next->sp0);
25512
25513 /*
25514 * Now maybe reload the debug registers and handle I/O bitmaps
25515@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
25516 if (!p || p == current || p->state == TASK_RUNNING)
25517 return 0;
25518 stack = (unsigned long)task_stack_page(p);
25519- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25520+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25521 return 0;
25522 fp = *(u64 *)(p->thread.sp);
25523 do {
25524- if (fp < (unsigned long)stack ||
25525- fp >= (unsigned long)stack+THREAD_SIZE)
25526+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25527 return 0;
25528 ip = *(u64 *)(fp+8);
25529 if (!in_sched_functions(ip))
25530diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25531index 7461f50..1334029 100644
25532--- a/arch/x86/kernel/ptrace.c
25533+++ b/arch/x86/kernel/ptrace.c
25534@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25535 {
25536 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25537 unsigned long sp = (unsigned long)&regs->sp;
25538- struct thread_info *tinfo;
25539
25540- if (context == (sp & ~(THREAD_SIZE - 1)))
25541+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25542 return sp;
25543
25544- tinfo = (struct thread_info *)context;
25545- if (tinfo->previous_esp)
25546- return tinfo->previous_esp;
25547+ sp = *(unsigned long *)context;
25548+ if (sp)
25549+ return sp;
25550
25551 return (unsigned long)regs;
25552 }
25553@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25554 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25555 {
25556 int i;
25557- int dr7 = 0;
25558+ unsigned long dr7 = 0;
25559 struct arch_hw_breakpoint *info;
25560
25561 for (i = 0; i < HBP_NUM; i++) {
25562@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25563 unsigned long addr, unsigned long data)
25564 {
25565 int ret;
25566- unsigned long __user *datap = (unsigned long __user *)data;
25567+ unsigned long __user *datap = (__force unsigned long __user *)data;
25568
25569 switch (request) {
25570 /* read the word at location addr in the USER area. */
25571@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25572 if ((int) addr < 0)
25573 return -EIO;
25574 ret = do_get_thread_area(child, addr,
25575- (struct user_desc __user *)data);
25576+ (__force struct user_desc __user *) data);
25577 break;
25578
25579 case PTRACE_SET_THREAD_AREA:
25580 if ((int) addr < 0)
25581 return -EIO;
25582 ret = do_set_thread_area(child, addr,
25583- (struct user_desc __user *)data, 0);
25584+ (__force struct user_desc __user *) data, 0);
25585 break;
25586 #endif
25587
25588@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25589
25590 #ifdef CONFIG_X86_64
25591
25592-static struct user_regset x86_64_regsets[] __read_mostly = {
25593+static user_regset_no_const x86_64_regsets[] __read_only = {
25594 [REGSET_GENERAL] = {
25595 .core_note_type = NT_PRSTATUS,
25596 .n = sizeof(struct user_regs_struct) / sizeof(long),
25597@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25598 #endif /* CONFIG_X86_64 */
25599
25600 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25601-static struct user_regset x86_32_regsets[] __read_mostly = {
25602+static user_regset_no_const x86_32_regsets[] __read_only = {
25603 [REGSET_GENERAL] = {
25604 .core_note_type = NT_PRSTATUS,
25605 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25606@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25607 */
25608 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25609
25610-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25611+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25612 {
25613 #ifdef CONFIG_X86_64
25614 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25615@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25616 memset(info, 0, sizeof(*info));
25617 info->si_signo = SIGTRAP;
25618 info->si_code = si_code;
25619- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25620+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25621 }
25622
25623 void user_single_step_siginfo(struct task_struct *tsk,
25624@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25625 # define IS_IA32 0
25626 #endif
25627
25628+#ifdef CONFIG_GRKERNSEC_SETXID
25629+extern void gr_delayed_cred_worker(void);
25630+#endif
25631+
25632 /*
25633 * We must return the syscall number to actually look up in the table.
25634 * This can be -1L to skip running any syscall at all.
25635@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25636
25637 user_exit();
25638
25639+#ifdef CONFIG_GRKERNSEC_SETXID
25640+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25641+ gr_delayed_cred_worker();
25642+#endif
25643+
25644 /*
25645 * If we stepped into a sysenter/syscall insn, it trapped in
25646 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25647@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25648 */
25649 user_exit();
25650
25651+#ifdef CONFIG_GRKERNSEC_SETXID
25652+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25653+ gr_delayed_cred_worker();
25654+#endif
25655+
25656 audit_syscall_exit(regs);
25657
25658 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25659diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25660index a16bae3..1f65f25 100644
25661--- a/arch/x86/kernel/pvclock.c
25662+++ b/arch/x86/kernel/pvclock.c
25663@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
25664 return pv_tsc_khz;
25665 }
25666
25667-static atomic64_t last_value = ATOMIC64_INIT(0);
25668+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25669
25670 void pvclock_resume(void)
25671 {
25672- atomic64_set(&last_value, 0);
25673+ atomic64_set_unchecked(&last_value, 0);
25674 }
25675
25676 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25677@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25678 * updating at the same time, and one of them could be slightly behind,
25679 * making the assumption that last_value always go forward fail to hold.
25680 */
25681- last = atomic64_read(&last_value);
25682+ last = atomic64_read_unchecked(&last_value);
25683 do {
25684 if (ret < last)
25685 return last;
25686- last = atomic64_cmpxchg(&last_value, last, ret);
25687+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25688 } while (unlikely(last != ret));
25689
25690 return ret;
25691diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25692index 618ce26..ec7e21c 100644
25693--- a/arch/x86/kernel/reboot.c
25694+++ b/arch/x86/kernel/reboot.c
25695@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25696
25697 void __noreturn machine_real_restart(unsigned int type)
25698 {
25699+
25700+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25701+ struct desc_struct *gdt;
25702+#endif
25703+
25704 local_irq_disable();
25705
25706 /*
25707@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25708
25709 /* Jump to the identity-mapped low memory code */
25710 #ifdef CONFIG_X86_32
25711- asm volatile("jmpl *%0" : :
25712+
25713+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25714+ gdt = get_cpu_gdt_table(smp_processor_id());
25715+ pax_open_kernel();
25716+#ifdef CONFIG_PAX_MEMORY_UDEREF
25717+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25718+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25719+ loadsegment(ds, __KERNEL_DS);
25720+ loadsegment(es, __KERNEL_DS);
25721+ loadsegment(ss, __KERNEL_DS);
25722+#endif
25723+#ifdef CONFIG_PAX_KERNEXEC
25724+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25725+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25726+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25727+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25728+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25729+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25730+#endif
25731+ pax_close_kernel();
25732+#endif
25733+
25734+ asm volatile("ljmpl *%0" : :
25735 "rm" (real_mode_header->machine_real_restart_asm),
25736 "a" (type));
25737 #else
25738@@ -466,7 +493,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25739 * try to force a triple fault and then cycle between hitting the keyboard
25740 * controller and doing that
25741 */
25742-static void native_machine_emergency_restart(void)
25743+static void __noreturn native_machine_emergency_restart(void)
25744 {
25745 int i;
25746 int attempt = 0;
25747@@ -575,13 +602,13 @@ void native_machine_shutdown(void)
25748 #endif
25749 }
25750
25751-static void __machine_emergency_restart(int emergency)
25752+static void __noreturn __machine_emergency_restart(int emergency)
25753 {
25754 reboot_emergency = emergency;
25755 machine_ops.emergency_restart();
25756 }
25757
25758-static void native_machine_restart(char *__unused)
25759+static void __noreturn native_machine_restart(char *__unused)
25760 {
25761 pr_notice("machine restart\n");
25762
25763@@ -590,7 +617,7 @@ static void native_machine_restart(char *__unused)
25764 __machine_emergency_restart(0);
25765 }
25766
25767-static void native_machine_halt(void)
25768+static void __noreturn native_machine_halt(void)
25769 {
25770 /* Stop other cpus and apics */
25771 machine_shutdown();
25772@@ -600,7 +627,7 @@ static void native_machine_halt(void)
25773 stop_this_cpu(NULL);
25774 }
25775
25776-static void native_machine_power_off(void)
25777+static void __noreturn native_machine_power_off(void)
25778 {
25779 if (pm_power_off) {
25780 if (!reboot_force)
25781@@ -609,9 +636,10 @@ static void native_machine_power_off(void)
25782 }
25783 /* A fallback in case there is no PM info available */
25784 tboot_shutdown(TB_SHUTDOWN_HALT);
25785+ unreachable();
25786 }
25787
25788-struct machine_ops machine_ops = {
25789+struct machine_ops machine_ops __read_only = {
25790 .power_off = native_machine_power_off,
25791 .shutdown = native_machine_shutdown,
25792 .emergency_restart = native_machine_emergency_restart,
25793diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25794index c8e41e9..64049ef 100644
25795--- a/arch/x86/kernel/reboot_fixups_32.c
25796+++ b/arch/x86/kernel/reboot_fixups_32.c
25797@@ -57,7 +57,7 @@ struct device_fixup {
25798 unsigned int vendor;
25799 unsigned int device;
25800 void (*reboot_fixup)(struct pci_dev *);
25801-};
25802+} __do_const;
25803
25804 /*
25805 * PCI ids solely used for fixups_table go here
25806diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25807index 3fd2c69..16ef367 100644
25808--- a/arch/x86/kernel/relocate_kernel_64.S
25809+++ b/arch/x86/kernel/relocate_kernel_64.S
25810@@ -11,6 +11,7 @@
25811 #include <asm/kexec.h>
25812 #include <asm/processor-flags.h>
25813 #include <asm/pgtable_types.h>
25814+#include <asm/alternative-asm.h>
25815
25816 /*
25817 * Must be relocatable PIC code callable as a C function
25818@@ -96,8 +97,7 @@ relocate_kernel:
25819
25820 /* jump to identity mapped page */
25821 addq $(identity_mapped - relocate_kernel), %r8
25822- pushq %r8
25823- ret
25824+ jmp *%r8
25825
25826 identity_mapped:
25827 /* set return address to 0 if not preserving context */
25828@@ -167,6 +167,7 @@ identity_mapped:
25829 xorl %r14d, %r14d
25830 xorl %r15d, %r15d
25831
25832+ pax_force_retaddr 0, 1
25833 ret
25834
25835 1:
25836diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25837index f0de629..a4978a8f 100644
25838--- a/arch/x86/kernel/setup.c
25839+++ b/arch/x86/kernel/setup.c
25840@@ -110,6 +110,7 @@
25841 #include <asm/mce.h>
25842 #include <asm/alternative.h>
25843 #include <asm/prom.h>
25844+#include <asm/boot.h>
25845
25846 /*
25847 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25848@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25849 #endif
25850
25851
25852-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25853-__visible unsigned long mmu_cr4_features;
25854+#ifdef CONFIG_X86_64
25855+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25856+#elif defined(CONFIG_X86_PAE)
25857+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25858 #else
25859-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
25860+__visible unsigned long mmu_cr4_features __read_only;
25861 #endif
25862
25863+void set_in_cr4(unsigned long mask)
25864+{
25865+ unsigned long cr4 = read_cr4();
25866+
25867+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25868+ return;
25869+
25870+ pax_open_kernel();
25871+ mmu_cr4_features |= mask;
25872+ pax_close_kernel();
25873+
25874+ if (trampoline_cr4_features)
25875+ *trampoline_cr4_features = mmu_cr4_features;
25876+ cr4 |= mask;
25877+ write_cr4(cr4);
25878+}
25879+EXPORT_SYMBOL(set_in_cr4);
25880+
25881+void clear_in_cr4(unsigned long mask)
25882+{
25883+ unsigned long cr4 = read_cr4();
25884+
25885+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25886+ return;
25887+
25888+ pax_open_kernel();
25889+ mmu_cr4_features &= ~mask;
25890+ pax_close_kernel();
25891+
25892+ if (trampoline_cr4_features)
25893+ *trampoline_cr4_features = mmu_cr4_features;
25894+ cr4 &= ~mask;
25895+ write_cr4(cr4);
25896+}
25897+EXPORT_SYMBOL(clear_in_cr4);
25898+
25899 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25900 int bootloader_type, bootloader_version;
25901
25902@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25903 * area (640->1Mb) as ram even though it is not.
25904 * take them out.
25905 */
25906- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25907+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25908
25909 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25910 }
25911@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25912 /* called before trim_bios_range() to spare extra sanitize */
25913 static void __init e820_add_kernel_range(void)
25914 {
25915- u64 start = __pa_symbol(_text);
25916+ u64 start = __pa_symbol(ktla_ktva(_text));
25917 u64 size = __pa_symbol(_end) - start;
25918
25919 /*
25920@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25921
25922 void __init setup_arch(char **cmdline_p)
25923 {
25924+#ifdef CONFIG_X86_32
25925+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25926+#else
25927 memblock_reserve(__pa_symbol(_text),
25928 (unsigned long)__bss_stop - (unsigned long)_text);
25929+#endif
25930
25931 early_reserve_initrd();
25932
25933@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25934
25935 if (!boot_params.hdr.root_flags)
25936 root_mountflags &= ~MS_RDONLY;
25937- init_mm.start_code = (unsigned long) _text;
25938- init_mm.end_code = (unsigned long) _etext;
25939+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25940+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25941 init_mm.end_data = (unsigned long) _edata;
25942 init_mm.brk = _brk_end;
25943
25944- code_resource.start = __pa_symbol(_text);
25945- code_resource.end = __pa_symbol(_etext)-1;
25946- data_resource.start = __pa_symbol(_etext);
25947+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25948+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25949+ data_resource.start = __pa_symbol(_sdata);
25950 data_resource.end = __pa_symbol(_edata)-1;
25951 bss_resource.start = __pa_symbol(__bss_start);
25952 bss_resource.end = __pa_symbol(__bss_stop)-1;
25953diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25954index 5cdff03..80fa283 100644
25955--- a/arch/x86/kernel/setup_percpu.c
25956+++ b/arch/x86/kernel/setup_percpu.c
25957@@ -21,19 +21,17 @@
25958 #include <asm/cpu.h>
25959 #include <asm/stackprotector.h>
25960
25961-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25962+#ifdef CONFIG_SMP
25963+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25964 EXPORT_PER_CPU_SYMBOL(cpu_number);
25965+#endif
25966
25967-#ifdef CONFIG_X86_64
25968 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25969-#else
25970-#define BOOT_PERCPU_OFFSET 0
25971-#endif
25972
25973 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25974 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25975
25976-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25977+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25978 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25979 };
25980 EXPORT_SYMBOL(__per_cpu_offset);
25981@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25982 {
25983 #ifdef CONFIG_NEED_MULTIPLE_NODES
25984 pg_data_t *last = NULL;
25985- unsigned int cpu;
25986+ int cpu;
25987
25988 for_each_possible_cpu(cpu) {
25989 int node = early_cpu_to_node(cpu);
25990@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25991 {
25992 #ifdef CONFIG_X86_32
25993 struct desc_struct gdt;
25994+ unsigned long base = per_cpu_offset(cpu);
25995
25996- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25997- 0x2 | DESCTYPE_S, 0x8);
25998- gdt.s = 1;
25999+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26000+ 0x83 | DESCTYPE_S, 0xC);
26001 write_gdt_entry(get_cpu_gdt_table(cpu),
26002 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26003 #endif
26004@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26005 /* alrighty, percpu areas up and running */
26006 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26007 for_each_possible_cpu(cpu) {
26008+#ifdef CONFIG_CC_STACKPROTECTOR
26009+#ifdef CONFIG_X86_32
26010+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26011+#endif
26012+#endif
26013 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26014 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26015 per_cpu(cpu_number, cpu) = cpu;
26016@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26017 */
26018 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26019 #endif
26020+#ifdef CONFIG_CC_STACKPROTECTOR
26021+#ifdef CONFIG_X86_32
26022+ if (!cpu)
26023+ per_cpu(stack_canary.canary, cpu) = canary;
26024+#endif
26025+#endif
26026 /*
26027 * Up to this point, the boot CPU has been using .init.data
26028 * area. Reload any changed state for the boot CPU.
26029diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26030index 9e5de68..16c53cb 100644
26031--- a/arch/x86/kernel/signal.c
26032+++ b/arch/x86/kernel/signal.c
26033@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26034 * Align the stack pointer according to the i386 ABI,
26035 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26036 */
26037- sp = ((sp + 4) & -16ul) - 4;
26038+ sp = ((sp - 12) & -16ul) - 4;
26039 #else /* !CONFIG_X86_32 */
26040 sp = round_down(sp, 16) - 8;
26041 #endif
26042@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26043 }
26044
26045 if (current->mm->context.vdso)
26046- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26047+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26048 else
26049- restorer = &frame->retcode;
26050+ restorer = (void __user *)&frame->retcode;
26051 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26052 restorer = ksig->ka.sa.sa_restorer;
26053
26054@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26055 * reasons and because gdb uses it as a signature to notice
26056 * signal handler stack frames.
26057 */
26058- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26059+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26060
26061 if (err)
26062 return -EFAULT;
26063@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26064 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26065
26066 /* Set up to return from userspace. */
26067- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26068+ if (current->mm->context.vdso)
26069+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26070+ else
26071+ restorer = (void __user *)&frame->retcode;
26072 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26073 restorer = ksig->ka.sa.sa_restorer;
26074 put_user_ex(restorer, &frame->pretcode);
26075@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26076 * reasons and because gdb uses it as a signature to notice
26077 * signal handler stack frames.
26078 */
26079- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26080+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26081 } put_user_catch(err);
26082
26083 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26084@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26085 {
26086 int usig = signr_convert(ksig->sig);
26087 sigset_t *set = sigmask_to_save();
26088- compat_sigset_t *cset = (compat_sigset_t *) set;
26089+ sigset_t sigcopy;
26090+ compat_sigset_t *cset;
26091+
26092+ sigcopy = *set;
26093+
26094+ cset = (compat_sigset_t *) &sigcopy;
26095
26096 /* Set up the stack frame */
26097 if (is_ia32_frame()) {
26098@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26099 } else if (is_x32_frame()) {
26100 return x32_setup_rt_frame(ksig, cset, regs);
26101 } else {
26102- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26103+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26104 }
26105 }
26106
26107diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26108index 7c3a5a6..f0a8961 100644
26109--- a/arch/x86/kernel/smp.c
26110+++ b/arch/x86/kernel/smp.c
26111@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26112
26113 __setup("nonmi_ipi", nonmi_ipi_setup);
26114
26115-struct smp_ops smp_ops = {
26116+struct smp_ops smp_ops __read_only = {
26117 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26118 .smp_prepare_cpus = native_smp_prepare_cpus,
26119 .smp_cpus_done = native_smp_cpus_done,
26120diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26121index 6cacab6..750636a 100644
26122--- a/arch/x86/kernel/smpboot.c
26123+++ b/arch/x86/kernel/smpboot.c
26124@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
26125
26126 enable_start_cpu0 = 0;
26127
26128-#ifdef CONFIG_X86_32
26129- /* switch away from the initial page table */
26130- load_cr3(swapper_pg_dir);
26131- __flush_tlb_all();
26132-#endif
26133-
26134 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26135 barrier();
26136+
26137+ /* switch away from the initial page table */
26138+#ifdef CONFIG_PAX_PER_CPU_PGD
26139+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26140+ __flush_tlb_all();
26141+#elif defined(CONFIG_X86_32)
26142+ load_cr3(swapper_pg_dir);
26143+ __flush_tlb_all();
26144+#endif
26145+
26146 /*
26147 * Check TSC synchronization with the BP:
26148 */
26149@@ -749,6 +753,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26150 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26151 (THREAD_SIZE + task_stack_page(idle))) - 1);
26152 per_cpu(current_task, cpu) = idle;
26153+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26154
26155 #ifdef CONFIG_X86_32
26156 /* Stack for startup_32 can be just as for start_secondary onwards */
26157@@ -756,11 +761,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26158 #else
26159 clear_tsk_thread_flag(idle, TIF_FORK);
26160 initial_gs = per_cpu_offset(cpu);
26161- per_cpu(kernel_stack, cpu) =
26162- (unsigned long)task_stack_page(idle) -
26163- KERNEL_STACK_OFFSET + THREAD_SIZE;
26164+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26165 #endif
26166+
26167+ pax_open_kernel();
26168 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26169+ pax_close_kernel();
26170+
26171 initial_code = (unsigned long)start_secondary;
26172 stack_start = idle->thread.sp;
26173
26174@@ -909,6 +916,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26175 /* the FPU context is blank, nobody can own it */
26176 __cpu_disable_lazy_restore(cpu);
26177
26178+#ifdef CONFIG_PAX_PER_CPU_PGD
26179+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26180+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26181+ KERNEL_PGD_PTRS);
26182+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26183+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26184+ KERNEL_PGD_PTRS);
26185+#endif
26186+
26187 err = do_boot_cpu(apicid, cpu, tidle);
26188 if (err) {
26189 pr_debug("do_boot_cpu failed %d\n", err);
26190diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26191index 9b4d51d..5d28b58 100644
26192--- a/arch/x86/kernel/step.c
26193+++ b/arch/x86/kernel/step.c
26194@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26195 struct desc_struct *desc;
26196 unsigned long base;
26197
26198- seg &= ~7UL;
26199+ seg >>= 3;
26200
26201 mutex_lock(&child->mm->context.lock);
26202- if (unlikely((seg >> 3) >= child->mm->context.size))
26203+ if (unlikely(seg >= child->mm->context.size))
26204 addr = -1L; /* bogus selector, access would fault */
26205 else {
26206 desc = child->mm->context.ldt + seg;
26207@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26208 addr += base;
26209 }
26210 mutex_unlock(&child->mm->context.lock);
26211- }
26212+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26213+ addr = ktla_ktva(addr);
26214
26215 return addr;
26216 }
26217@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26218 unsigned char opcode[15];
26219 unsigned long addr = convert_ip_to_linear(child, regs);
26220
26221+ if (addr == -EINVAL)
26222+ return 0;
26223+
26224 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26225 for (i = 0; i < copied; i++) {
26226 switch (opcode[i]) {
26227diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26228new file mode 100644
26229index 0000000..5877189
26230--- /dev/null
26231+++ b/arch/x86/kernel/sys_i386_32.c
26232@@ -0,0 +1,189 @@
26233+/*
26234+ * This file contains various random system calls that
26235+ * have a non-standard calling sequence on the Linux/i386
26236+ * platform.
26237+ */
26238+
26239+#include <linux/errno.h>
26240+#include <linux/sched.h>
26241+#include <linux/mm.h>
26242+#include <linux/fs.h>
26243+#include <linux/smp.h>
26244+#include <linux/sem.h>
26245+#include <linux/msg.h>
26246+#include <linux/shm.h>
26247+#include <linux/stat.h>
26248+#include <linux/syscalls.h>
26249+#include <linux/mman.h>
26250+#include <linux/file.h>
26251+#include <linux/utsname.h>
26252+#include <linux/ipc.h>
26253+#include <linux/elf.h>
26254+
26255+#include <linux/uaccess.h>
26256+#include <linux/unistd.h>
26257+
26258+#include <asm/syscalls.h>
26259+
26260+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26261+{
26262+ unsigned long pax_task_size = TASK_SIZE;
26263+
26264+#ifdef CONFIG_PAX_SEGMEXEC
26265+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26266+ pax_task_size = SEGMEXEC_TASK_SIZE;
26267+#endif
26268+
26269+ if (flags & MAP_FIXED)
26270+ if (len > pax_task_size || addr > pax_task_size - len)
26271+ return -EINVAL;
26272+
26273+ return 0;
26274+}
26275+
26276+/*
26277+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26278+ */
26279+static unsigned long get_align_mask(void)
26280+{
26281+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26282+ return 0;
26283+
26284+ if (!(current->flags & PF_RANDOMIZE))
26285+ return 0;
26286+
26287+ return va_align.mask;
26288+}
26289+
26290+unsigned long
26291+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26292+ unsigned long len, unsigned long pgoff, unsigned long flags)
26293+{
26294+ struct mm_struct *mm = current->mm;
26295+ struct vm_area_struct *vma;
26296+ unsigned long pax_task_size = TASK_SIZE;
26297+ struct vm_unmapped_area_info info;
26298+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26299+
26300+#ifdef CONFIG_PAX_SEGMEXEC
26301+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26302+ pax_task_size = SEGMEXEC_TASK_SIZE;
26303+#endif
26304+
26305+ pax_task_size -= PAGE_SIZE;
26306+
26307+ if (len > pax_task_size)
26308+ return -ENOMEM;
26309+
26310+ if (flags & MAP_FIXED)
26311+ return addr;
26312+
26313+#ifdef CONFIG_PAX_RANDMMAP
26314+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26315+#endif
26316+
26317+ if (addr) {
26318+ addr = PAGE_ALIGN(addr);
26319+ if (pax_task_size - len >= addr) {
26320+ vma = find_vma(mm, addr);
26321+ if (check_heap_stack_gap(vma, addr, len, offset))
26322+ return addr;
26323+ }
26324+ }
26325+
26326+ info.flags = 0;
26327+ info.length = len;
26328+ info.align_mask = filp ? get_align_mask() : 0;
26329+ info.align_offset = pgoff << PAGE_SHIFT;
26330+ info.threadstack_offset = offset;
26331+
26332+#ifdef CONFIG_PAX_PAGEEXEC
26333+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26334+ info.low_limit = 0x00110000UL;
26335+ info.high_limit = mm->start_code;
26336+
26337+#ifdef CONFIG_PAX_RANDMMAP
26338+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26339+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26340+#endif
26341+
26342+ if (info.low_limit < info.high_limit) {
26343+ addr = vm_unmapped_area(&info);
26344+ if (!IS_ERR_VALUE(addr))
26345+ return addr;
26346+ }
26347+ } else
26348+#endif
26349+
26350+ info.low_limit = mm->mmap_base;
26351+ info.high_limit = pax_task_size;
26352+
26353+ return vm_unmapped_area(&info);
26354+}
26355+
26356+unsigned long
26357+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26358+ const unsigned long len, const unsigned long pgoff,
26359+ const unsigned long flags)
26360+{
26361+ struct vm_area_struct *vma;
26362+ struct mm_struct *mm = current->mm;
26363+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26364+ struct vm_unmapped_area_info info;
26365+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26366+
26367+#ifdef CONFIG_PAX_SEGMEXEC
26368+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26369+ pax_task_size = SEGMEXEC_TASK_SIZE;
26370+#endif
26371+
26372+ pax_task_size -= PAGE_SIZE;
26373+
26374+ /* requested length too big for entire address space */
26375+ if (len > pax_task_size)
26376+ return -ENOMEM;
26377+
26378+ if (flags & MAP_FIXED)
26379+ return addr;
26380+
26381+#ifdef CONFIG_PAX_PAGEEXEC
26382+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26383+ goto bottomup;
26384+#endif
26385+
26386+#ifdef CONFIG_PAX_RANDMMAP
26387+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26388+#endif
26389+
26390+ /* requesting a specific address */
26391+ if (addr) {
26392+ addr = PAGE_ALIGN(addr);
26393+ if (pax_task_size - len >= addr) {
26394+ vma = find_vma(mm, addr);
26395+ if (check_heap_stack_gap(vma, addr, len, offset))
26396+ return addr;
26397+ }
26398+ }
26399+
26400+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26401+ info.length = len;
26402+ info.low_limit = PAGE_SIZE;
26403+ info.high_limit = mm->mmap_base;
26404+ info.align_mask = filp ? get_align_mask() : 0;
26405+ info.align_offset = pgoff << PAGE_SHIFT;
26406+ info.threadstack_offset = offset;
26407+
26408+ addr = vm_unmapped_area(&info);
26409+ if (!(addr & ~PAGE_MASK))
26410+ return addr;
26411+ VM_BUG_ON(addr != -ENOMEM);
26412+
26413+bottomup:
26414+ /*
26415+ * A failed mmap() very likely causes application failure,
26416+ * so fall back to the bottom-up function here. This scenario
26417+ * can happen with large stack limits and large mmap()
26418+ * allocations.
26419+ */
26420+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26421+}
26422diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26423index 30277e2..5664a29 100644
26424--- a/arch/x86/kernel/sys_x86_64.c
26425+++ b/arch/x86/kernel/sys_x86_64.c
26426@@ -81,8 +81,8 @@ out:
26427 return error;
26428 }
26429
26430-static void find_start_end(unsigned long flags, unsigned long *begin,
26431- unsigned long *end)
26432+static void find_start_end(struct mm_struct *mm, unsigned long flags,
26433+ unsigned long *begin, unsigned long *end)
26434 {
26435 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26436 unsigned long new_begin;
26437@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26438 *begin = new_begin;
26439 }
26440 } else {
26441- *begin = current->mm->mmap_legacy_base;
26442+ *begin = mm->mmap_legacy_base;
26443 *end = TASK_SIZE;
26444 }
26445 }
26446@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26447 struct vm_area_struct *vma;
26448 struct vm_unmapped_area_info info;
26449 unsigned long begin, end;
26450+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26451
26452 if (flags & MAP_FIXED)
26453 return addr;
26454
26455- find_start_end(flags, &begin, &end);
26456+ find_start_end(mm, flags, &begin, &end);
26457
26458 if (len > end)
26459 return -ENOMEM;
26460
26461+#ifdef CONFIG_PAX_RANDMMAP
26462+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26463+#endif
26464+
26465 if (addr) {
26466 addr = PAGE_ALIGN(addr);
26467 vma = find_vma(mm, addr);
26468- if (end - len >= addr &&
26469- (!vma || addr + len <= vma->vm_start))
26470+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26471 return addr;
26472 }
26473
26474@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26475 info.high_limit = end;
26476 info.align_mask = filp ? get_align_mask() : 0;
26477 info.align_offset = pgoff << PAGE_SHIFT;
26478+ info.threadstack_offset = offset;
26479 return vm_unmapped_area(&info);
26480 }
26481
26482@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26483 struct mm_struct *mm = current->mm;
26484 unsigned long addr = addr0;
26485 struct vm_unmapped_area_info info;
26486+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26487
26488 /* requested length too big for entire address space */
26489 if (len > TASK_SIZE)
26490@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26491 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26492 goto bottomup;
26493
26494+#ifdef CONFIG_PAX_RANDMMAP
26495+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26496+#endif
26497+
26498 /* requesting a specific address */
26499 if (addr) {
26500 addr = PAGE_ALIGN(addr);
26501 vma = find_vma(mm, addr);
26502- if (TASK_SIZE - len >= addr &&
26503- (!vma || addr + len <= vma->vm_start))
26504+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26505 return addr;
26506 }
26507
26508@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26509 info.high_limit = mm->mmap_base;
26510 info.align_mask = filp ? get_align_mask() : 0;
26511 info.align_offset = pgoff << PAGE_SHIFT;
26512+ info.threadstack_offset = offset;
26513 addr = vm_unmapped_area(&info);
26514 if (!(addr & ~PAGE_MASK))
26515 return addr;
26516diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26517index 91a4496..1730bff 100644
26518--- a/arch/x86/kernel/tboot.c
26519+++ b/arch/x86/kernel/tboot.c
26520@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26521
26522 void tboot_shutdown(u32 shutdown_type)
26523 {
26524- void (*shutdown)(void);
26525+ void (* __noreturn shutdown)(void);
26526
26527 if (!tboot_enabled())
26528 return;
26529@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26530
26531 switch_to_tboot_pt();
26532
26533- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26534+ shutdown = (void *)tboot->shutdown_entry;
26535 shutdown();
26536
26537 /* should not reach here */
26538@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26539 return -ENODEV;
26540 }
26541
26542-static atomic_t ap_wfs_count;
26543+static atomic_unchecked_t ap_wfs_count;
26544
26545 static int tboot_wait_for_aps(int num_aps)
26546 {
26547@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26548 {
26549 switch (action) {
26550 case CPU_DYING:
26551- atomic_inc(&ap_wfs_count);
26552+ atomic_inc_unchecked(&ap_wfs_count);
26553 if (num_online_cpus() == 1)
26554- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26555+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26556 return NOTIFY_BAD;
26557 break;
26558 }
26559@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26560
26561 tboot_create_trampoline();
26562
26563- atomic_set(&ap_wfs_count, 0);
26564+ atomic_set_unchecked(&ap_wfs_count, 0);
26565 register_hotcpu_notifier(&tboot_cpu_notifier);
26566
26567 #ifdef CONFIG_DEBUG_FS
26568diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26569index 24d3c91..d06b473 100644
26570--- a/arch/x86/kernel/time.c
26571+++ b/arch/x86/kernel/time.c
26572@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26573 {
26574 unsigned long pc = instruction_pointer(regs);
26575
26576- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26577+ if (!user_mode(regs) && in_lock_functions(pc)) {
26578 #ifdef CONFIG_FRAME_POINTER
26579- return *(unsigned long *)(regs->bp + sizeof(long));
26580+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26581 #else
26582 unsigned long *sp =
26583 (unsigned long *)kernel_stack_pointer(regs);
26584@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26585 * or above a saved flags. Eflags has bits 22-31 zero,
26586 * kernel addresses don't.
26587 */
26588+
26589+#ifdef CONFIG_PAX_KERNEXEC
26590+ return ktla_ktva(sp[0]);
26591+#else
26592 if (sp[0] >> 22)
26593 return sp[0];
26594 if (sp[1] >> 22)
26595 return sp[1];
26596 #endif
26597+
26598+#endif
26599 }
26600 return pc;
26601 }
26602diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26603index f7fec09..9991981 100644
26604--- a/arch/x86/kernel/tls.c
26605+++ b/arch/x86/kernel/tls.c
26606@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26607 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26608 return -EINVAL;
26609
26610+#ifdef CONFIG_PAX_SEGMEXEC
26611+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26612+ return -EINVAL;
26613+#endif
26614+
26615 set_tls_desc(p, idx, &info, 1);
26616
26617 return 0;
26618@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26619
26620 if (kbuf)
26621 info = kbuf;
26622- else if (__copy_from_user(infobuf, ubuf, count))
26623+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26624 return -EFAULT;
26625 else
26626 info = infobuf;
26627diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26628index 1c113db..287b42e 100644
26629--- a/arch/x86/kernel/tracepoint.c
26630+++ b/arch/x86/kernel/tracepoint.c
26631@@ -9,11 +9,11 @@
26632 #include <linux/atomic.h>
26633
26634 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26635-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26636+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26637 (unsigned long) trace_idt_table };
26638
26639 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26640-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26641+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26642
26643 static int trace_irq_vector_refcount;
26644 static DEFINE_MUTEX(irq_vector_mutex);
26645diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26646index 8c8093b..c93f581 100644
26647--- a/arch/x86/kernel/traps.c
26648+++ b/arch/x86/kernel/traps.c
26649@@ -66,7 +66,7 @@
26650 #include <asm/proto.h>
26651
26652 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26653-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26654+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26655 #else
26656 #include <asm/processor-flags.h>
26657 #include <asm/setup.h>
26658@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26659 #endif
26660
26661 /* Must be page-aligned because the real IDT is used in a fixmap. */
26662-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26663+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26664
26665 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26666 EXPORT_SYMBOL_GPL(used_vectors);
26667@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26668 }
26669
26670 static int __kprobes
26671-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26672+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26673 struct pt_regs *regs, long error_code)
26674 {
26675 #ifdef CONFIG_X86_32
26676- if (regs->flags & X86_VM_MASK) {
26677+ if (v8086_mode(regs)) {
26678 /*
26679 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26680 * On nmi (interrupt 2), do_trap should not be called.
26681@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26682 return -1;
26683 }
26684 #endif
26685- if (!user_mode(regs)) {
26686+ if (!user_mode_novm(regs)) {
26687 if (!fixup_exception(regs)) {
26688 tsk->thread.error_code = error_code;
26689 tsk->thread.trap_nr = trapnr;
26690+
26691+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26692+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26693+ str = "PAX: suspicious stack segment fault";
26694+#endif
26695+
26696 die(str, regs, error_code);
26697 }
26698+
26699+#ifdef CONFIG_PAX_REFCOUNT
26700+ if (trapnr == 4)
26701+ pax_report_refcount_overflow(regs);
26702+#endif
26703+
26704 return 0;
26705 }
26706
26707@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26708 }
26709
26710 static void __kprobes
26711-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26712+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26713 long error_code, siginfo_t *info)
26714 {
26715 struct task_struct *tsk = current;
26716@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26717 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26718 printk_ratelimit()) {
26719 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26720- tsk->comm, tsk->pid, str,
26721+ tsk->comm, task_pid_nr(tsk), str,
26722 regs->ip, regs->sp, error_code);
26723 print_vma_addr(" in ", regs->ip);
26724 pr_cont("\n");
26725@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26726 conditional_sti(regs);
26727
26728 #ifdef CONFIG_X86_32
26729- if (regs->flags & X86_VM_MASK) {
26730+ if (v8086_mode(regs)) {
26731 local_irq_enable();
26732 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26733 goto exit;
26734@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26735 #endif
26736
26737 tsk = current;
26738- if (!user_mode(regs)) {
26739+ if (!user_mode_novm(regs)) {
26740 if (fixup_exception(regs))
26741 goto exit;
26742
26743 tsk->thread.error_code = error_code;
26744 tsk->thread.trap_nr = X86_TRAP_GP;
26745 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26746- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26747+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26748+
26749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26750+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26751+ die("PAX: suspicious general protection fault", regs, error_code);
26752+ else
26753+#endif
26754+
26755 die("general protection fault", regs, error_code);
26756+ }
26757 goto exit;
26758 }
26759
26760+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26761+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26762+ struct mm_struct *mm = tsk->mm;
26763+ unsigned long limit;
26764+
26765+ down_write(&mm->mmap_sem);
26766+ limit = mm->context.user_cs_limit;
26767+ if (limit < TASK_SIZE) {
26768+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26769+ up_write(&mm->mmap_sem);
26770+ return;
26771+ }
26772+ up_write(&mm->mmap_sem);
26773+ }
26774+#endif
26775+
26776 tsk->thread.error_code = error_code;
26777 tsk->thread.trap_nr = X86_TRAP_GP;
26778
26779@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26780 /* It's safe to allow irq's after DR6 has been saved */
26781 preempt_conditional_sti(regs);
26782
26783- if (regs->flags & X86_VM_MASK) {
26784+ if (v8086_mode(regs)) {
26785 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26786 X86_TRAP_DB);
26787 preempt_conditional_cli(regs);
26788@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26789 * We already checked v86 mode above, so we can check for kernel mode
26790 * by just checking the CPL of CS.
26791 */
26792- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26793+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26794 tsk->thread.debugreg6 &= ~DR_STEP;
26795 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26796 regs->flags &= ~X86_EFLAGS_TF;
26797@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26798 return;
26799 conditional_sti(regs);
26800
26801- if (!user_mode_vm(regs))
26802+ if (!user_mode(regs))
26803 {
26804 if (!fixup_exception(regs)) {
26805 task->thread.error_code = error_code;
26806diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26807index 2ed8459..7cf329f 100644
26808--- a/arch/x86/kernel/uprobes.c
26809+++ b/arch/x86/kernel/uprobes.c
26810@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26811 int ret = NOTIFY_DONE;
26812
26813 /* We are only interested in userspace traps */
26814- if (regs && !user_mode_vm(regs))
26815+ if (regs && !user_mode(regs))
26816 return NOTIFY_DONE;
26817
26818 switch (val) {
26819@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26820
26821 if (ncopied != rasize) {
26822 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26823- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26824+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26825
26826 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26827 }
26828diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26829index b9242ba..50c5edd 100644
26830--- a/arch/x86/kernel/verify_cpu.S
26831+++ b/arch/x86/kernel/verify_cpu.S
26832@@ -20,6 +20,7 @@
26833 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26834 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26835 * arch/x86/kernel/head_32.S: processor startup
26836+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26837 *
26838 * verify_cpu, returns the status of longmode and SSE in register %eax.
26839 * 0: Success 1: Failure
26840diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26841index e8edcf5..27f9344 100644
26842--- a/arch/x86/kernel/vm86_32.c
26843+++ b/arch/x86/kernel/vm86_32.c
26844@@ -44,6 +44,7 @@
26845 #include <linux/ptrace.h>
26846 #include <linux/audit.h>
26847 #include <linux/stddef.h>
26848+#include <linux/grsecurity.h>
26849
26850 #include <asm/uaccess.h>
26851 #include <asm/io.h>
26852@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26853 do_exit(SIGSEGV);
26854 }
26855
26856- tss = &per_cpu(init_tss, get_cpu());
26857+ tss = init_tss + get_cpu();
26858 current->thread.sp0 = current->thread.saved_sp0;
26859 current->thread.sysenter_cs = __KERNEL_CS;
26860 load_sp0(tss, &current->thread);
26861@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26862
26863 if (tsk->thread.saved_sp0)
26864 return -EPERM;
26865+
26866+#ifdef CONFIG_GRKERNSEC_VM86
26867+ if (!capable(CAP_SYS_RAWIO)) {
26868+ gr_handle_vm86();
26869+ return -EPERM;
26870+ }
26871+#endif
26872+
26873 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26874 offsetof(struct kernel_vm86_struct, vm86plus) -
26875 sizeof(info.regs));
26876@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26877 int tmp;
26878 struct vm86plus_struct __user *v86;
26879
26880+#ifdef CONFIG_GRKERNSEC_VM86
26881+ if (!capable(CAP_SYS_RAWIO)) {
26882+ gr_handle_vm86();
26883+ return -EPERM;
26884+ }
26885+#endif
26886+
26887 tsk = current;
26888 switch (cmd) {
26889 case VM86_REQUEST_IRQ:
26890@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26891 tsk->thread.saved_fs = info->regs32->fs;
26892 tsk->thread.saved_gs = get_user_gs(info->regs32);
26893
26894- tss = &per_cpu(init_tss, get_cpu());
26895+ tss = init_tss + get_cpu();
26896 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26897 if (cpu_has_sep)
26898 tsk->thread.sysenter_cs = 0;
26899@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26900 goto cannot_handle;
26901 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26902 goto cannot_handle;
26903- intr_ptr = (unsigned long __user *) (i << 2);
26904+ intr_ptr = (__force unsigned long __user *) (i << 2);
26905 if (get_user(segoffs, intr_ptr))
26906 goto cannot_handle;
26907 if ((segoffs >> 16) == BIOSSEG)
26908diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26909index 10c4f30..65408b9 100644
26910--- a/arch/x86/kernel/vmlinux.lds.S
26911+++ b/arch/x86/kernel/vmlinux.lds.S
26912@@ -26,6 +26,13 @@
26913 #include <asm/page_types.h>
26914 #include <asm/cache.h>
26915 #include <asm/boot.h>
26916+#include <asm/segment.h>
26917+
26918+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26919+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26920+#else
26921+#define __KERNEL_TEXT_OFFSET 0
26922+#endif
26923
26924 #undef i386 /* in case the preprocessor is a 32bit one */
26925
26926@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26927
26928 PHDRS {
26929 text PT_LOAD FLAGS(5); /* R_E */
26930+#ifdef CONFIG_X86_32
26931+ module PT_LOAD FLAGS(5); /* R_E */
26932+#endif
26933+#ifdef CONFIG_XEN
26934+ rodata PT_LOAD FLAGS(5); /* R_E */
26935+#else
26936+ rodata PT_LOAD FLAGS(4); /* R__ */
26937+#endif
26938 data PT_LOAD FLAGS(6); /* RW_ */
26939-#ifdef CONFIG_X86_64
26940+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26941 #ifdef CONFIG_SMP
26942 percpu PT_LOAD FLAGS(6); /* RW_ */
26943 #endif
26944+ text.init PT_LOAD FLAGS(5); /* R_E */
26945+ text.exit PT_LOAD FLAGS(5); /* R_E */
26946 init PT_LOAD FLAGS(7); /* RWE */
26947-#endif
26948 note PT_NOTE FLAGS(0); /* ___ */
26949 }
26950
26951 SECTIONS
26952 {
26953 #ifdef CONFIG_X86_32
26954- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26955- phys_startup_32 = startup_32 - LOAD_OFFSET;
26956+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26957 #else
26958- . = __START_KERNEL;
26959- phys_startup_64 = startup_64 - LOAD_OFFSET;
26960+ . = __START_KERNEL;
26961 #endif
26962
26963 /* Text and read-only data */
26964- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26965- _text = .;
26966+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26967 /* bootstrapping code */
26968+#ifdef CONFIG_X86_32
26969+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26970+#else
26971+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26972+#endif
26973+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26974+ _text = .;
26975 HEAD_TEXT
26976 . = ALIGN(8);
26977 _stext = .;
26978@@ -104,13 +124,47 @@ SECTIONS
26979 IRQENTRY_TEXT
26980 *(.fixup)
26981 *(.gnu.warning)
26982- /* End of text section */
26983- _etext = .;
26984 } :text = 0x9090
26985
26986- NOTES :text :note
26987+ . += __KERNEL_TEXT_OFFSET;
26988
26989- EXCEPTION_TABLE(16) :text = 0x9090
26990+#ifdef CONFIG_X86_32
26991+ . = ALIGN(PAGE_SIZE);
26992+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26993+
26994+#ifdef CONFIG_PAX_KERNEXEC
26995+ MODULES_EXEC_VADDR = .;
26996+ BYTE(0)
26997+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26998+ . = ALIGN(HPAGE_SIZE) - 1;
26999+ MODULES_EXEC_END = .;
27000+#endif
27001+
27002+ } :module
27003+#endif
27004+
27005+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27006+ /* End of text section */
27007+ BYTE(0)
27008+ _etext = . - __KERNEL_TEXT_OFFSET;
27009+ }
27010+
27011+#ifdef CONFIG_X86_32
27012+ . = ALIGN(PAGE_SIZE);
27013+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27014+ . = ALIGN(PAGE_SIZE);
27015+ *(.empty_zero_page)
27016+ *(.initial_pg_fixmap)
27017+ *(.initial_pg_pmd)
27018+ *(.initial_page_table)
27019+ *(.swapper_pg_dir)
27020+ } :rodata
27021+#endif
27022+
27023+ . = ALIGN(PAGE_SIZE);
27024+ NOTES :rodata :note
27025+
27026+ EXCEPTION_TABLE(16) :rodata
27027
27028 #if defined(CONFIG_DEBUG_RODATA)
27029 /* .text should occupy whole number of pages */
27030@@ -122,16 +176,20 @@ SECTIONS
27031
27032 /* Data */
27033 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27034+
27035+#ifdef CONFIG_PAX_KERNEXEC
27036+ . = ALIGN(HPAGE_SIZE);
27037+#else
27038+ . = ALIGN(PAGE_SIZE);
27039+#endif
27040+
27041 /* Start of data section */
27042 _sdata = .;
27043
27044 /* init_task */
27045 INIT_TASK_DATA(THREAD_SIZE)
27046
27047-#ifdef CONFIG_X86_32
27048- /* 32 bit has nosave before _edata */
27049 NOSAVE_DATA
27050-#endif
27051
27052 PAGE_ALIGNED_DATA(PAGE_SIZE)
27053
27054@@ -172,12 +230,19 @@ SECTIONS
27055 #endif /* CONFIG_X86_64 */
27056
27057 /* Init code and data - will be freed after init */
27058- . = ALIGN(PAGE_SIZE);
27059 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27060+ BYTE(0)
27061+
27062+#ifdef CONFIG_PAX_KERNEXEC
27063+ . = ALIGN(HPAGE_SIZE);
27064+#else
27065+ . = ALIGN(PAGE_SIZE);
27066+#endif
27067+
27068 __init_begin = .; /* paired with __init_end */
27069- }
27070+ } :init.begin
27071
27072-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27073+#ifdef CONFIG_SMP
27074 /*
27075 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27076 * output PHDR, so the next output section - .init.text - should
27077@@ -186,12 +251,27 @@ SECTIONS
27078 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27079 #endif
27080
27081- INIT_TEXT_SECTION(PAGE_SIZE)
27082-#ifdef CONFIG_X86_64
27083- :init
27084-#endif
27085+ . = ALIGN(PAGE_SIZE);
27086+ init_begin = .;
27087+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27088+ VMLINUX_SYMBOL(_sinittext) = .;
27089+ INIT_TEXT
27090+ VMLINUX_SYMBOL(_einittext) = .;
27091+ . = ALIGN(PAGE_SIZE);
27092+ } :text.init
27093
27094- INIT_DATA_SECTION(16)
27095+ /*
27096+ * .exit.text is discard at runtime, not link time, to deal with
27097+ * references from .altinstructions and .eh_frame
27098+ */
27099+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27100+ EXIT_TEXT
27101+ . = ALIGN(16);
27102+ } :text.exit
27103+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27104+
27105+ . = ALIGN(PAGE_SIZE);
27106+ INIT_DATA_SECTION(16) :init
27107
27108 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27109 __x86_cpu_dev_start = .;
27110@@ -253,19 +333,12 @@ SECTIONS
27111 }
27112
27113 . = ALIGN(8);
27114- /*
27115- * .exit.text is discard at runtime, not link time, to deal with
27116- * references from .altinstructions and .eh_frame
27117- */
27118- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27119- EXIT_TEXT
27120- }
27121
27122 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27123 EXIT_DATA
27124 }
27125
27126-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27127+#ifndef CONFIG_SMP
27128 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27129 #endif
27130
27131@@ -284,16 +357,10 @@ SECTIONS
27132 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27133 __smp_locks = .;
27134 *(.smp_locks)
27135- . = ALIGN(PAGE_SIZE);
27136 __smp_locks_end = .;
27137+ . = ALIGN(PAGE_SIZE);
27138 }
27139
27140-#ifdef CONFIG_X86_64
27141- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27142- NOSAVE_DATA
27143- }
27144-#endif
27145-
27146 /* BSS */
27147 . = ALIGN(PAGE_SIZE);
27148 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27149@@ -309,6 +376,7 @@ SECTIONS
27150 __brk_base = .;
27151 . += 64 * 1024; /* 64k alignment slop space */
27152 *(.brk_reservation) /* areas brk users have reserved */
27153+ . = ALIGN(HPAGE_SIZE);
27154 __brk_limit = .;
27155 }
27156
27157@@ -335,13 +403,12 @@ SECTIONS
27158 * for the boot processor.
27159 */
27160 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27161-INIT_PER_CPU(gdt_page);
27162 INIT_PER_CPU(irq_stack_union);
27163
27164 /*
27165 * Build-time check on the image size:
27166 */
27167-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27168+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27169 "kernel image bigger than KERNEL_IMAGE_SIZE");
27170
27171 #ifdef CONFIG_SMP
27172diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27173index 1f96f93..d5c8f7a 100644
27174--- a/arch/x86/kernel/vsyscall_64.c
27175+++ b/arch/x86/kernel/vsyscall_64.c
27176@@ -56,15 +56,13 @@
27177 DEFINE_VVAR(int, vgetcpu_mode);
27178 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27179
27180-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27181+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27182
27183 static int __init vsyscall_setup(char *str)
27184 {
27185 if (str) {
27186 if (!strcmp("emulate", str))
27187 vsyscall_mode = EMULATE;
27188- else if (!strcmp("native", str))
27189- vsyscall_mode = NATIVE;
27190 else if (!strcmp("none", str))
27191 vsyscall_mode = NONE;
27192 else
27193@@ -323,8 +321,7 @@ do_ret:
27194 return true;
27195
27196 sigsegv:
27197- force_sig(SIGSEGV, current);
27198- return true;
27199+ do_group_exit(SIGKILL);
27200 }
27201
27202 /*
27203@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27204 extern char __vvar_page;
27205 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27206
27207- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27208- vsyscall_mode == NATIVE
27209- ? PAGE_KERNEL_VSYSCALL
27210- : PAGE_KERNEL_VVAR);
27211+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27212 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27213 (unsigned long)VSYSCALL_START);
27214
27215diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27216index b014d94..e775258 100644
27217--- a/arch/x86/kernel/x8664_ksyms_64.c
27218+++ b/arch/x86/kernel/x8664_ksyms_64.c
27219@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27220 EXPORT_SYMBOL(copy_user_generic_unrolled);
27221 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27222 EXPORT_SYMBOL(__copy_user_nocache);
27223-EXPORT_SYMBOL(_copy_from_user);
27224-EXPORT_SYMBOL(_copy_to_user);
27225
27226 EXPORT_SYMBOL(copy_page);
27227 EXPORT_SYMBOL(clear_page);
27228@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
27229 #ifndef CONFIG_PARAVIRT
27230 EXPORT_SYMBOL(native_load_gs_index);
27231 #endif
27232+
27233+#ifdef CONFIG_PAX_PER_CPU_PGD
27234+EXPORT_SYMBOL(cpu_pgd);
27235+#endif
27236diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27237index 8ce0072..431a0e7 100644
27238--- a/arch/x86/kernel/x86_init.c
27239+++ b/arch/x86/kernel/x86_init.c
27240@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27241 static void default_nmi_init(void) { };
27242 static int default_i8042_detect(void) { return 1; };
27243
27244-struct x86_platform_ops x86_platform = {
27245+struct x86_platform_ops x86_platform __read_only = {
27246 .calibrate_tsc = native_calibrate_tsc,
27247 .get_wallclock = mach_get_cmos_time,
27248 .set_wallclock = mach_set_rtc_mmss,
27249@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27250 EXPORT_SYMBOL_GPL(x86_platform);
27251
27252 #if defined(CONFIG_PCI_MSI)
27253-struct x86_msi_ops x86_msi = {
27254+struct x86_msi_ops x86_msi __read_only = {
27255 .setup_msi_irqs = native_setup_msi_irqs,
27256 .compose_msi_msg = native_compose_msi_msg,
27257 .teardown_msi_irq = native_teardown_msi_irq,
27258@@ -140,7 +140,7 @@ void arch_restore_msi_irqs(struct pci_dev *dev, int irq)
27259 }
27260 #endif
27261
27262-struct x86_io_apic_ops x86_io_apic_ops = {
27263+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27264 .init = native_io_apic_init_mappings,
27265 .read = native_io_apic_read,
27266 .write = native_io_apic_write,
27267diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27268index 422fd82..c3687ca 100644
27269--- a/arch/x86/kernel/xsave.c
27270+++ b/arch/x86/kernel/xsave.c
27271@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27272 {
27273 int err;
27274
27275+ buf = (struct xsave_struct __user *)____m(buf);
27276 if (use_xsave())
27277 err = xsave_user(buf);
27278 else if (use_fxsr())
27279@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27280 */
27281 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27282 {
27283+ buf = (void __user *)____m(buf);
27284 if (use_xsave()) {
27285 if ((unsigned long)buf % 64 || fx_only) {
27286 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27287diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27288index b110fe6..d9c19f2 100644
27289--- a/arch/x86/kvm/cpuid.c
27290+++ b/arch/x86/kvm/cpuid.c
27291@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27292 struct kvm_cpuid2 *cpuid,
27293 struct kvm_cpuid_entry2 __user *entries)
27294 {
27295- int r;
27296+ int r, i;
27297
27298 r = -E2BIG;
27299 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27300 goto out;
27301 r = -EFAULT;
27302- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27303- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27304+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27305 goto out;
27306+ for (i = 0; i < cpuid->nent; ++i) {
27307+ struct kvm_cpuid_entry2 cpuid_entry;
27308+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27309+ goto out;
27310+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
27311+ }
27312 vcpu->arch.cpuid_nent = cpuid->nent;
27313 kvm_apic_set_version(vcpu);
27314 kvm_x86_ops->cpuid_update(vcpu);
27315@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27316 struct kvm_cpuid2 *cpuid,
27317 struct kvm_cpuid_entry2 __user *entries)
27318 {
27319- int r;
27320+ int r, i;
27321
27322 r = -E2BIG;
27323 if (cpuid->nent < vcpu->arch.cpuid_nent)
27324 goto out;
27325 r = -EFAULT;
27326- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27327- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27328+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27329 goto out;
27330+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27331+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27332+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27333+ goto out;
27334+ }
27335 return 0;
27336
27337 out:
27338diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27339index 5439117..f4d21f7 100644
27340--- a/arch/x86/kvm/lapic.c
27341+++ b/arch/x86/kvm/lapic.c
27342@@ -55,7 +55,7 @@
27343 #define APIC_BUS_CYCLE_NS 1
27344
27345 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27346-#define apic_debug(fmt, arg...)
27347+#define apic_debug(fmt, arg...) do {} while (0)
27348
27349 #define APIC_LVT_NUM 6
27350 /* 14 is the version for Xeon and Pentium 8.4.8*/
27351@@ -143,6 +143,8 @@ static inline int kvm_apic_id(struct kvm_lapic *apic)
27352 return (kvm_apic_get_reg(apic, APIC_ID) >> 24) & 0xff;
27353 }
27354
27355+#define KVM_X2APIC_CID_BITS 0
27356+
27357 static void recalculate_apic_map(struct kvm *kvm)
27358 {
27359 struct kvm_apic_map *new, *old = NULL;
27360@@ -180,7 +182,8 @@ static void recalculate_apic_map(struct kvm *kvm)
27361 if (apic_x2apic_mode(apic)) {
27362 new->ldr_bits = 32;
27363 new->cid_shift = 16;
27364- new->cid_mask = new->lid_mask = 0xffff;
27365+ new->cid_mask = (1 << KVM_X2APIC_CID_BITS) - 1;
27366+ new->lid_mask = 0xffff;
27367 } else if (kvm_apic_sw_enabled(apic) &&
27368 !new->cid_mask /* flat mode */ &&
27369 kvm_apic_get_reg(apic, APIC_DFR) == APIC_DFR_CLUSTER) {
27370@@ -841,7 +844,8 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
27371 ASSERT(apic != NULL);
27372
27373 /* if initial count is 0, current count should also be 0 */
27374- if (kvm_apic_get_reg(apic, APIC_TMICT) == 0)
27375+ if (kvm_apic_get_reg(apic, APIC_TMICT) == 0 ||
27376+ apic->lapic_timer.period == 0)
27377 return 0;
27378
27379 remaining = hrtimer_get_remaining(&apic->lapic_timer.timer);
27380@@ -1691,7 +1695,6 @@ static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu,
27381 void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu)
27382 {
27383 u32 data;
27384- void *vapic;
27385
27386 if (test_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention))
27387 apic_sync_pv_eoi_from_guest(vcpu, vcpu->arch.apic);
27388@@ -1699,9 +1702,8 @@ void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu)
27389 if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
27390 return;
27391
27392- vapic = kmap_atomic(vcpu->arch.apic->vapic_page);
27393- data = *(u32 *)(vapic + offset_in_page(vcpu->arch.apic->vapic_addr));
27394- kunmap_atomic(vapic);
27395+ kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
27396+ sizeof(u32));
27397
27398 apic_set_tpr(vcpu->arch.apic, data & 0xff);
27399 }
27400@@ -1737,7 +1739,6 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu)
27401 u32 data, tpr;
27402 int max_irr, max_isr;
27403 struct kvm_lapic *apic = vcpu->arch.apic;
27404- void *vapic;
27405
27406 apic_sync_pv_eoi_to_guest(vcpu, apic);
27407
27408@@ -1753,18 +1754,24 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu)
27409 max_isr = 0;
27410 data = (tpr & 0xff) | ((max_isr & 0xf0) << 8) | (max_irr << 24);
27411
27412- vapic = kmap_atomic(vcpu->arch.apic->vapic_page);
27413- *(u32 *)(vapic + offset_in_page(vcpu->arch.apic->vapic_addr)) = data;
27414- kunmap_atomic(vapic);
27415+ kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
27416+ sizeof(u32));
27417 }
27418
27419-void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr)
27420+int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr)
27421 {
27422- vcpu->arch.apic->vapic_addr = vapic_addr;
27423- if (vapic_addr)
27424+ if (vapic_addr) {
27425+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
27426+ &vcpu->arch.apic->vapic_cache,
27427+ vapic_addr, sizeof(u32)))
27428+ return -EINVAL;
27429 __set_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention);
27430- else
27431+ } else {
27432 __clear_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention);
27433+ }
27434+
27435+ vcpu->arch.apic->vapic_addr = vapic_addr;
27436+ return 0;
27437 }
27438
27439 int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data)
27440diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
27441index c730ac9..c8b0d0d 100644
27442--- a/arch/x86/kvm/lapic.h
27443+++ b/arch/x86/kvm/lapic.h
27444@@ -34,7 +34,7 @@ struct kvm_lapic {
27445 */
27446 void *regs;
27447 gpa_t vapic_addr;
27448- struct page *vapic_page;
27449+ struct gfn_to_hva_cache vapic_cache;
27450 unsigned long pending_events;
27451 unsigned int sipi_vector;
27452 };
27453@@ -76,7 +76,7 @@ void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data);
27454 void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset);
27455 void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector);
27456
27457-void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
27458+int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
27459 void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu);
27460 void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
27461
27462diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27463index ad75d77..a679d32 100644
27464--- a/arch/x86/kvm/paging_tmpl.h
27465+++ b/arch/x86/kvm/paging_tmpl.h
27466@@ -331,7 +331,7 @@ retry_walk:
27467 if (unlikely(kvm_is_error_hva(host_addr)))
27468 goto error;
27469
27470- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27471+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27472 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27473 goto error;
27474 walker->ptep_user[walker->level - 1] = ptep_user;
27475diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27476index c0bc803..6837a50 100644
27477--- a/arch/x86/kvm/svm.c
27478+++ b/arch/x86/kvm/svm.c
27479@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27480 int cpu = raw_smp_processor_id();
27481
27482 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27483+
27484+ pax_open_kernel();
27485 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27486+ pax_close_kernel();
27487+
27488 load_TR_desc();
27489 }
27490
27491@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27492 #endif
27493 #endif
27494
27495+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27496+ __set_fs(current_thread_info()->addr_limit);
27497+#endif
27498+
27499 reload_tss(vcpu);
27500
27501 local_irq_disable();
27502diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27503index 2b2fce1..da76be4 100644
27504--- a/arch/x86/kvm/vmx.c
27505+++ b/arch/x86/kvm/vmx.c
27506@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27507 #endif
27508 }
27509
27510-static void vmcs_clear_bits(unsigned long field, u32 mask)
27511+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27512 {
27513 vmcs_writel(field, vmcs_readl(field) & ~mask);
27514 }
27515
27516-static void vmcs_set_bits(unsigned long field, u32 mask)
27517+static void vmcs_set_bits(unsigned long field, unsigned long mask)
27518 {
27519 vmcs_writel(field, vmcs_readl(field) | mask);
27520 }
27521@@ -1522,7 +1522,11 @@ static void reload_tss(void)
27522 struct desc_struct *descs;
27523
27524 descs = (void *)gdt->address;
27525+
27526+ pax_open_kernel();
27527 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27528+ pax_close_kernel();
27529+
27530 load_TR_desc();
27531 }
27532
27533@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27534 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27535 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27536
27537+#ifdef CONFIG_PAX_PER_CPU_PGD
27538+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27539+#endif
27540+
27541 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27542 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27543 vmx->loaded_vmcs->cpu = cpu;
27544@@ -2037,7 +2045,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27545 * reads and returns guest's timestamp counter "register"
27546 * guest_tsc = host_tsc + tsc_offset -- 21.3
27547 */
27548-static u64 guest_read_tsc(void)
27549+static u64 __intentional_overflow(-1) guest_read_tsc(void)
27550 {
27551 u64 host_tsc, tsc_offset;
27552
27553@@ -2982,8 +2990,11 @@ static __init int hardware_setup(void)
27554 if (!cpu_has_vmx_flexpriority())
27555 flexpriority_enabled = 0;
27556
27557- if (!cpu_has_vmx_tpr_shadow())
27558- kvm_x86_ops->update_cr8_intercept = NULL;
27559+ if (!cpu_has_vmx_tpr_shadow()) {
27560+ pax_open_kernel();
27561+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27562+ pax_close_kernel();
27563+ }
27564
27565 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27566 kvm_disable_largepages();
27567@@ -2994,13 +3005,15 @@ static __init int hardware_setup(void)
27568 if (!cpu_has_vmx_apicv())
27569 enable_apicv = 0;
27570
27571+ pax_open_kernel();
27572 if (enable_apicv)
27573- kvm_x86_ops->update_cr8_intercept = NULL;
27574+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27575 else {
27576- kvm_x86_ops->hwapic_irr_update = NULL;
27577- kvm_x86_ops->deliver_posted_interrupt = NULL;
27578- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27579+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27580+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27581+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27582 }
27583+ pax_close_kernel();
27584
27585 if (nested)
27586 nested_vmx_setup_ctls_msrs();
27587@@ -4127,7 +4140,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27588
27589 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27590 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27591+
27592+#ifndef CONFIG_PAX_PER_CPU_PGD
27593 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27594+#endif
27595
27596 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27597 #ifdef CONFIG_X86_64
27598@@ -4149,7 +4165,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27599 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27600 vmx->host_idt_base = dt.address;
27601
27602- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27603+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27604
27605 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27606 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27607@@ -7191,6 +7207,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27608 "jmp 2f \n\t"
27609 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27610 "2: "
27611+
27612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27613+ "ljmp %[cs],$3f\n\t"
27614+ "3: "
27615+#endif
27616+
27617 /* Save guest registers, load host registers, keep flags */
27618 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27619 "pop %0 \n\t"
27620@@ -7243,6 +7265,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27621 #endif
27622 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27623 [wordsize]"i"(sizeof(ulong))
27624+
27625+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27626+ ,[cs]"i"(__KERNEL_CS)
27627+#endif
27628+
27629 : "cc", "memory"
27630 #ifdef CONFIG_X86_64
27631 , "rax", "rbx", "rdi", "rsi"
27632@@ -7256,7 +7283,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27633 if (debugctlmsr)
27634 update_debugctlmsr(debugctlmsr);
27635
27636-#ifndef CONFIG_X86_64
27637+#ifdef CONFIG_X86_32
27638 /*
27639 * The sysexit path does not restore ds/es, so we must set them to
27640 * a reasonable value ourselves.
27641@@ -7265,8 +7292,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27642 * may be executed in interrupt context, which saves and restore segments
27643 * around it, nullifying its effect.
27644 */
27645- loadsegment(ds, __USER_DS);
27646- loadsegment(es, __USER_DS);
27647+ loadsegment(ds, __KERNEL_DS);
27648+ loadsegment(es, __KERNEL_DS);
27649+ loadsegment(ss, __KERNEL_DS);
27650+
27651+#ifdef CONFIG_PAX_KERNEXEC
27652+ loadsegment(fs, __KERNEL_PERCPU);
27653+#endif
27654+
27655+#ifdef CONFIG_PAX_MEMORY_UDEREF
27656+ __set_fs(current_thread_info()->addr_limit);
27657+#endif
27658+
27659 #endif
27660
27661 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27662diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27663index e5ca72a..0f30b12 100644
27664--- a/arch/x86/kvm/x86.c
27665+++ b/arch/x86/kvm/x86.c
27666@@ -1779,8 +1779,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27667 {
27668 struct kvm *kvm = vcpu->kvm;
27669 int lm = is_long_mode(vcpu);
27670- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27671- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27672+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27673+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27674 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27675 : kvm->arch.xen_hvm_config.blob_size_32;
27676 u32 page_num = data & ~PAGE_MASK;
27677@@ -2663,6 +2663,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27678 if (n < msr_list.nmsrs)
27679 goto out;
27680 r = -EFAULT;
27681+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27682+ goto out;
27683 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27684 num_msrs_to_save * sizeof(u32)))
27685 goto out;
27686@@ -3192,8 +3194,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
27687 r = -EFAULT;
27688 if (copy_from_user(&va, argp, sizeof va))
27689 goto out;
27690- r = 0;
27691- kvm_lapic_set_vapic_addr(vcpu, va.vapic_addr);
27692+ r = kvm_lapic_set_vapic_addr(vcpu, va.vapic_addr);
27693 break;
27694 }
27695 case KVM_X86_SETUP_MCE: {
27696@@ -5462,7 +5463,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27697 };
27698 #endif
27699
27700-int kvm_arch_init(void *opaque)
27701+int kvm_arch_init(const void *opaque)
27702 {
27703 int r;
27704 struct kvm_x86_ops *ops = opaque;
27705@@ -5718,36 +5719,6 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu)
27706 !kvm_event_needs_reinjection(vcpu);
27707 }
27708
27709-static int vapic_enter(struct kvm_vcpu *vcpu)
27710-{
27711- struct kvm_lapic *apic = vcpu->arch.apic;
27712- struct page *page;
27713-
27714- if (!apic || !apic->vapic_addr)
27715- return 0;
27716-
27717- page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
27718- if (is_error_page(page))
27719- return -EFAULT;
27720-
27721- vcpu->arch.apic->vapic_page = page;
27722- return 0;
27723-}
27724-
27725-static void vapic_exit(struct kvm_vcpu *vcpu)
27726-{
27727- struct kvm_lapic *apic = vcpu->arch.apic;
27728- int idx;
27729-
27730- if (!apic || !apic->vapic_addr)
27731- return;
27732-
27733- idx = srcu_read_lock(&vcpu->kvm->srcu);
27734- kvm_release_page_dirty(apic->vapic_page);
27735- mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
27736- srcu_read_unlock(&vcpu->kvm->srcu, idx);
27737-}
27738-
27739 static void update_cr8_intercept(struct kvm_vcpu *vcpu)
27740 {
27741 int max_irr, tpr;
27742@@ -6047,11 +6018,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
27743 struct kvm *kvm = vcpu->kvm;
27744
27745 vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
27746- r = vapic_enter(vcpu);
27747- if (r) {
27748- srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
27749- return r;
27750- }
27751
27752 r = 1;
27753 while (r > 0) {
27754@@ -6110,8 +6076,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
27755
27756 srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
27757
27758- vapic_exit(vcpu);
27759-
27760 return r;
27761 }
27762
27763diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27764index bdf8532..f63c587 100644
27765--- a/arch/x86/lguest/boot.c
27766+++ b/arch/x86/lguest/boot.c
27767@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27768 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27769 * Launcher to reboot us.
27770 */
27771-static void lguest_restart(char *reason)
27772+static __noreturn void lguest_restart(char *reason)
27773 {
27774 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27775+ BUG();
27776 }
27777
27778 /*G:050
27779diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27780index 00933d5..3a64af9 100644
27781--- a/arch/x86/lib/atomic64_386_32.S
27782+++ b/arch/x86/lib/atomic64_386_32.S
27783@@ -48,6 +48,10 @@ BEGIN(read)
27784 movl (v), %eax
27785 movl 4(v), %edx
27786 RET_ENDP
27787+BEGIN(read_unchecked)
27788+ movl (v), %eax
27789+ movl 4(v), %edx
27790+RET_ENDP
27791 #undef v
27792
27793 #define v %esi
27794@@ -55,6 +59,10 @@ BEGIN(set)
27795 movl %ebx, (v)
27796 movl %ecx, 4(v)
27797 RET_ENDP
27798+BEGIN(set_unchecked)
27799+ movl %ebx, (v)
27800+ movl %ecx, 4(v)
27801+RET_ENDP
27802 #undef v
27803
27804 #define v %esi
27805@@ -70,6 +78,20 @@ RET_ENDP
27806 BEGIN(add)
27807 addl %eax, (v)
27808 adcl %edx, 4(v)
27809+
27810+#ifdef CONFIG_PAX_REFCOUNT
27811+ jno 0f
27812+ subl %eax, (v)
27813+ sbbl %edx, 4(v)
27814+ int $4
27815+0:
27816+ _ASM_EXTABLE(0b, 0b)
27817+#endif
27818+
27819+RET_ENDP
27820+BEGIN(add_unchecked)
27821+ addl %eax, (v)
27822+ adcl %edx, 4(v)
27823 RET_ENDP
27824 #undef v
27825
27826@@ -77,6 +99,24 @@ RET_ENDP
27827 BEGIN(add_return)
27828 addl (v), %eax
27829 adcl 4(v), %edx
27830+
27831+#ifdef CONFIG_PAX_REFCOUNT
27832+ into
27833+1234:
27834+ _ASM_EXTABLE(1234b, 2f)
27835+#endif
27836+
27837+ movl %eax, (v)
27838+ movl %edx, 4(v)
27839+
27840+#ifdef CONFIG_PAX_REFCOUNT
27841+2:
27842+#endif
27843+
27844+RET_ENDP
27845+BEGIN(add_return_unchecked)
27846+ addl (v), %eax
27847+ adcl 4(v), %edx
27848 movl %eax, (v)
27849 movl %edx, 4(v)
27850 RET_ENDP
27851@@ -86,6 +126,20 @@ RET_ENDP
27852 BEGIN(sub)
27853 subl %eax, (v)
27854 sbbl %edx, 4(v)
27855+
27856+#ifdef CONFIG_PAX_REFCOUNT
27857+ jno 0f
27858+ addl %eax, (v)
27859+ adcl %edx, 4(v)
27860+ int $4
27861+0:
27862+ _ASM_EXTABLE(0b, 0b)
27863+#endif
27864+
27865+RET_ENDP
27866+BEGIN(sub_unchecked)
27867+ subl %eax, (v)
27868+ sbbl %edx, 4(v)
27869 RET_ENDP
27870 #undef v
27871
27872@@ -96,6 +150,27 @@ BEGIN(sub_return)
27873 sbbl $0, %edx
27874 addl (v), %eax
27875 adcl 4(v), %edx
27876+
27877+#ifdef CONFIG_PAX_REFCOUNT
27878+ into
27879+1234:
27880+ _ASM_EXTABLE(1234b, 2f)
27881+#endif
27882+
27883+ movl %eax, (v)
27884+ movl %edx, 4(v)
27885+
27886+#ifdef CONFIG_PAX_REFCOUNT
27887+2:
27888+#endif
27889+
27890+RET_ENDP
27891+BEGIN(sub_return_unchecked)
27892+ negl %edx
27893+ negl %eax
27894+ sbbl $0, %edx
27895+ addl (v), %eax
27896+ adcl 4(v), %edx
27897 movl %eax, (v)
27898 movl %edx, 4(v)
27899 RET_ENDP
27900@@ -105,6 +180,20 @@ RET_ENDP
27901 BEGIN(inc)
27902 addl $1, (v)
27903 adcl $0, 4(v)
27904+
27905+#ifdef CONFIG_PAX_REFCOUNT
27906+ jno 0f
27907+ subl $1, (v)
27908+ sbbl $0, 4(v)
27909+ int $4
27910+0:
27911+ _ASM_EXTABLE(0b, 0b)
27912+#endif
27913+
27914+RET_ENDP
27915+BEGIN(inc_unchecked)
27916+ addl $1, (v)
27917+ adcl $0, 4(v)
27918 RET_ENDP
27919 #undef v
27920
27921@@ -114,6 +203,26 @@ BEGIN(inc_return)
27922 movl 4(v), %edx
27923 addl $1, %eax
27924 adcl $0, %edx
27925+
27926+#ifdef CONFIG_PAX_REFCOUNT
27927+ into
27928+1234:
27929+ _ASM_EXTABLE(1234b, 2f)
27930+#endif
27931+
27932+ movl %eax, (v)
27933+ movl %edx, 4(v)
27934+
27935+#ifdef CONFIG_PAX_REFCOUNT
27936+2:
27937+#endif
27938+
27939+RET_ENDP
27940+BEGIN(inc_return_unchecked)
27941+ movl (v), %eax
27942+ movl 4(v), %edx
27943+ addl $1, %eax
27944+ adcl $0, %edx
27945 movl %eax, (v)
27946 movl %edx, 4(v)
27947 RET_ENDP
27948@@ -123,6 +232,20 @@ RET_ENDP
27949 BEGIN(dec)
27950 subl $1, (v)
27951 sbbl $0, 4(v)
27952+
27953+#ifdef CONFIG_PAX_REFCOUNT
27954+ jno 0f
27955+ addl $1, (v)
27956+ adcl $0, 4(v)
27957+ int $4
27958+0:
27959+ _ASM_EXTABLE(0b, 0b)
27960+#endif
27961+
27962+RET_ENDP
27963+BEGIN(dec_unchecked)
27964+ subl $1, (v)
27965+ sbbl $0, 4(v)
27966 RET_ENDP
27967 #undef v
27968
27969@@ -132,6 +255,26 @@ BEGIN(dec_return)
27970 movl 4(v), %edx
27971 subl $1, %eax
27972 sbbl $0, %edx
27973+
27974+#ifdef CONFIG_PAX_REFCOUNT
27975+ into
27976+1234:
27977+ _ASM_EXTABLE(1234b, 2f)
27978+#endif
27979+
27980+ movl %eax, (v)
27981+ movl %edx, 4(v)
27982+
27983+#ifdef CONFIG_PAX_REFCOUNT
27984+2:
27985+#endif
27986+
27987+RET_ENDP
27988+BEGIN(dec_return_unchecked)
27989+ movl (v), %eax
27990+ movl 4(v), %edx
27991+ subl $1, %eax
27992+ sbbl $0, %edx
27993 movl %eax, (v)
27994 movl %edx, 4(v)
27995 RET_ENDP
27996@@ -143,6 +286,13 @@ BEGIN(add_unless)
27997 adcl %edx, %edi
27998 addl (v), %eax
27999 adcl 4(v), %edx
28000+
28001+#ifdef CONFIG_PAX_REFCOUNT
28002+ into
28003+1234:
28004+ _ASM_EXTABLE(1234b, 2f)
28005+#endif
28006+
28007 cmpl %eax, %ecx
28008 je 3f
28009 1:
28010@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28011 1:
28012 addl $1, %eax
28013 adcl $0, %edx
28014+
28015+#ifdef CONFIG_PAX_REFCOUNT
28016+ into
28017+1234:
28018+ _ASM_EXTABLE(1234b, 2f)
28019+#endif
28020+
28021 movl %eax, (v)
28022 movl %edx, 4(v)
28023 movl $1, %eax
28024@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28025 movl 4(v), %edx
28026 subl $1, %eax
28027 sbbl $0, %edx
28028+
28029+#ifdef CONFIG_PAX_REFCOUNT
28030+ into
28031+1234:
28032+ _ASM_EXTABLE(1234b, 1f)
28033+#endif
28034+
28035 js 1f
28036 movl %eax, (v)
28037 movl %edx, 4(v)
28038diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28039index f5cc9eb..51fa319 100644
28040--- a/arch/x86/lib/atomic64_cx8_32.S
28041+++ b/arch/x86/lib/atomic64_cx8_32.S
28042@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28043 CFI_STARTPROC
28044
28045 read64 %ecx
28046+ pax_force_retaddr
28047 ret
28048 CFI_ENDPROC
28049 ENDPROC(atomic64_read_cx8)
28050
28051+ENTRY(atomic64_read_unchecked_cx8)
28052+ CFI_STARTPROC
28053+
28054+ read64 %ecx
28055+ pax_force_retaddr
28056+ ret
28057+ CFI_ENDPROC
28058+ENDPROC(atomic64_read_unchecked_cx8)
28059+
28060 ENTRY(atomic64_set_cx8)
28061 CFI_STARTPROC
28062
28063@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28064 cmpxchg8b (%esi)
28065 jne 1b
28066
28067+ pax_force_retaddr
28068 ret
28069 CFI_ENDPROC
28070 ENDPROC(atomic64_set_cx8)
28071
28072+ENTRY(atomic64_set_unchecked_cx8)
28073+ CFI_STARTPROC
28074+
28075+1:
28076+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28077+ * are atomic on 586 and newer */
28078+ cmpxchg8b (%esi)
28079+ jne 1b
28080+
28081+ pax_force_retaddr
28082+ ret
28083+ CFI_ENDPROC
28084+ENDPROC(atomic64_set_unchecked_cx8)
28085+
28086 ENTRY(atomic64_xchg_cx8)
28087 CFI_STARTPROC
28088
28089@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28090 cmpxchg8b (%esi)
28091 jne 1b
28092
28093+ pax_force_retaddr
28094 ret
28095 CFI_ENDPROC
28096 ENDPROC(atomic64_xchg_cx8)
28097
28098-.macro addsub_return func ins insc
28099-ENTRY(atomic64_\func\()_return_cx8)
28100+.macro addsub_return func ins insc unchecked=""
28101+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28102 CFI_STARTPROC
28103 SAVE ebp
28104 SAVE ebx
28105@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28106 movl %edx, %ecx
28107 \ins\()l %esi, %ebx
28108 \insc\()l %edi, %ecx
28109+
28110+.ifb \unchecked
28111+#ifdef CONFIG_PAX_REFCOUNT
28112+ into
28113+2:
28114+ _ASM_EXTABLE(2b, 3f)
28115+#endif
28116+.endif
28117+
28118 LOCK_PREFIX
28119 cmpxchg8b (%ebp)
28120 jne 1b
28121-
28122-10:
28123 movl %ebx, %eax
28124 movl %ecx, %edx
28125+
28126+.ifb \unchecked
28127+#ifdef CONFIG_PAX_REFCOUNT
28128+3:
28129+#endif
28130+.endif
28131+
28132 RESTORE edi
28133 RESTORE esi
28134 RESTORE ebx
28135 RESTORE ebp
28136+ pax_force_retaddr
28137 ret
28138 CFI_ENDPROC
28139-ENDPROC(atomic64_\func\()_return_cx8)
28140+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28141 .endm
28142
28143 addsub_return add add adc
28144 addsub_return sub sub sbb
28145+addsub_return add add adc _unchecked
28146+addsub_return sub sub sbb _unchecked
28147
28148-.macro incdec_return func ins insc
28149-ENTRY(atomic64_\func\()_return_cx8)
28150+.macro incdec_return func ins insc unchecked=""
28151+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28152 CFI_STARTPROC
28153 SAVE ebx
28154
28155@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28156 movl %edx, %ecx
28157 \ins\()l $1, %ebx
28158 \insc\()l $0, %ecx
28159+
28160+.ifb \unchecked
28161+#ifdef CONFIG_PAX_REFCOUNT
28162+ into
28163+2:
28164+ _ASM_EXTABLE(2b, 3f)
28165+#endif
28166+.endif
28167+
28168 LOCK_PREFIX
28169 cmpxchg8b (%esi)
28170 jne 1b
28171
28172-10:
28173 movl %ebx, %eax
28174 movl %ecx, %edx
28175+
28176+.ifb \unchecked
28177+#ifdef CONFIG_PAX_REFCOUNT
28178+3:
28179+#endif
28180+.endif
28181+
28182 RESTORE ebx
28183+ pax_force_retaddr
28184 ret
28185 CFI_ENDPROC
28186-ENDPROC(atomic64_\func\()_return_cx8)
28187+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28188 .endm
28189
28190 incdec_return inc add adc
28191 incdec_return dec sub sbb
28192+incdec_return inc add adc _unchecked
28193+incdec_return dec sub sbb _unchecked
28194
28195 ENTRY(atomic64_dec_if_positive_cx8)
28196 CFI_STARTPROC
28197@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28198 movl %edx, %ecx
28199 subl $1, %ebx
28200 sbb $0, %ecx
28201+
28202+#ifdef CONFIG_PAX_REFCOUNT
28203+ into
28204+1234:
28205+ _ASM_EXTABLE(1234b, 2f)
28206+#endif
28207+
28208 js 2f
28209 LOCK_PREFIX
28210 cmpxchg8b (%esi)
28211@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28212 movl %ebx, %eax
28213 movl %ecx, %edx
28214 RESTORE ebx
28215+ pax_force_retaddr
28216 ret
28217 CFI_ENDPROC
28218 ENDPROC(atomic64_dec_if_positive_cx8)
28219@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28220 movl %edx, %ecx
28221 addl %ebp, %ebx
28222 adcl %edi, %ecx
28223+
28224+#ifdef CONFIG_PAX_REFCOUNT
28225+ into
28226+1234:
28227+ _ASM_EXTABLE(1234b, 3f)
28228+#endif
28229+
28230 LOCK_PREFIX
28231 cmpxchg8b (%esi)
28232 jne 1b
28233@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28234 CFI_ADJUST_CFA_OFFSET -8
28235 RESTORE ebx
28236 RESTORE ebp
28237+ pax_force_retaddr
28238 ret
28239 4:
28240 cmpl %edx, 4(%esp)
28241@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28242 xorl %ecx, %ecx
28243 addl $1, %ebx
28244 adcl %edx, %ecx
28245+
28246+#ifdef CONFIG_PAX_REFCOUNT
28247+ into
28248+1234:
28249+ _ASM_EXTABLE(1234b, 3f)
28250+#endif
28251+
28252 LOCK_PREFIX
28253 cmpxchg8b (%esi)
28254 jne 1b
28255@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28256 movl $1, %eax
28257 3:
28258 RESTORE ebx
28259+ pax_force_retaddr
28260 ret
28261 CFI_ENDPROC
28262 ENDPROC(atomic64_inc_not_zero_cx8)
28263diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28264index e78b8ee..7e173a8 100644
28265--- a/arch/x86/lib/checksum_32.S
28266+++ b/arch/x86/lib/checksum_32.S
28267@@ -29,7 +29,8 @@
28268 #include <asm/dwarf2.h>
28269 #include <asm/errno.h>
28270 #include <asm/asm.h>
28271-
28272+#include <asm/segment.h>
28273+
28274 /*
28275 * computes a partial checksum, e.g. for TCP/UDP fragments
28276 */
28277@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28278
28279 #define ARGBASE 16
28280 #define FP 12
28281-
28282-ENTRY(csum_partial_copy_generic)
28283+
28284+ENTRY(csum_partial_copy_generic_to_user)
28285 CFI_STARTPROC
28286+
28287+#ifdef CONFIG_PAX_MEMORY_UDEREF
28288+ pushl_cfi %gs
28289+ popl_cfi %es
28290+ jmp csum_partial_copy_generic
28291+#endif
28292+
28293+ENTRY(csum_partial_copy_generic_from_user)
28294+
28295+#ifdef CONFIG_PAX_MEMORY_UDEREF
28296+ pushl_cfi %gs
28297+ popl_cfi %ds
28298+#endif
28299+
28300+ENTRY(csum_partial_copy_generic)
28301 subl $4,%esp
28302 CFI_ADJUST_CFA_OFFSET 4
28303 pushl_cfi %edi
28304@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28305 jmp 4f
28306 SRC(1: movw (%esi), %bx )
28307 addl $2, %esi
28308-DST( movw %bx, (%edi) )
28309+DST( movw %bx, %es:(%edi) )
28310 addl $2, %edi
28311 addw %bx, %ax
28312 adcl $0, %eax
28313@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28314 SRC(1: movl (%esi), %ebx )
28315 SRC( movl 4(%esi), %edx )
28316 adcl %ebx, %eax
28317-DST( movl %ebx, (%edi) )
28318+DST( movl %ebx, %es:(%edi) )
28319 adcl %edx, %eax
28320-DST( movl %edx, 4(%edi) )
28321+DST( movl %edx, %es:4(%edi) )
28322
28323 SRC( movl 8(%esi), %ebx )
28324 SRC( movl 12(%esi), %edx )
28325 adcl %ebx, %eax
28326-DST( movl %ebx, 8(%edi) )
28327+DST( movl %ebx, %es:8(%edi) )
28328 adcl %edx, %eax
28329-DST( movl %edx, 12(%edi) )
28330+DST( movl %edx, %es:12(%edi) )
28331
28332 SRC( movl 16(%esi), %ebx )
28333 SRC( movl 20(%esi), %edx )
28334 adcl %ebx, %eax
28335-DST( movl %ebx, 16(%edi) )
28336+DST( movl %ebx, %es:16(%edi) )
28337 adcl %edx, %eax
28338-DST( movl %edx, 20(%edi) )
28339+DST( movl %edx, %es:20(%edi) )
28340
28341 SRC( movl 24(%esi), %ebx )
28342 SRC( movl 28(%esi), %edx )
28343 adcl %ebx, %eax
28344-DST( movl %ebx, 24(%edi) )
28345+DST( movl %ebx, %es:24(%edi) )
28346 adcl %edx, %eax
28347-DST( movl %edx, 28(%edi) )
28348+DST( movl %edx, %es:28(%edi) )
28349
28350 lea 32(%esi), %esi
28351 lea 32(%edi), %edi
28352@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28353 shrl $2, %edx # This clears CF
28354 SRC(3: movl (%esi), %ebx )
28355 adcl %ebx, %eax
28356-DST( movl %ebx, (%edi) )
28357+DST( movl %ebx, %es:(%edi) )
28358 lea 4(%esi), %esi
28359 lea 4(%edi), %edi
28360 dec %edx
28361@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28362 jb 5f
28363 SRC( movw (%esi), %cx )
28364 leal 2(%esi), %esi
28365-DST( movw %cx, (%edi) )
28366+DST( movw %cx, %es:(%edi) )
28367 leal 2(%edi), %edi
28368 je 6f
28369 shll $16,%ecx
28370 SRC(5: movb (%esi), %cl )
28371-DST( movb %cl, (%edi) )
28372+DST( movb %cl, %es:(%edi) )
28373 6: addl %ecx, %eax
28374 adcl $0, %eax
28375 7:
28376@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28377
28378 6001:
28379 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28380- movl $-EFAULT, (%ebx)
28381+ movl $-EFAULT, %ss:(%ebx)
28382
28383 # zero the complete destination - computing the rest
28384 # is too much work
28385@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28386
28387 6002:
28388 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28389- movl $-EFAULT,(%ebx)
28390+ movl $-EFAULT,%ss:(%ebx)
28391 jmp 5000b
28392
28393 .previous
28394
28395+ pushl_cfi %ss
28396+ popl_cfi %ds
28397+ pushl_cfi %ss
28398+ popl_cfi %es
28399 popl_cfi %ebx
28400 CFI_RESTORE ebx
28401 popl_cfi %esi
28402@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28403 popl_cfi %ecx # equivalent to addl $4,%esp
28404 ret
28405 CFI_ENDPROC
28406-ENDPROC(csum_partial_copy_generic)
28407+ENDPROC(csum_partial_copy_generic_to_user)
28408
28409 #else
28410
28411 /* Version for PentiumII/PPro */
28412
28413 #define ROUND1(x) \
28414+ nop; nop; nop; \
28415 SRC(movl x(%esi), %ebx ) ; \
28416 addl %ebx, %eax ; \
28417- DST(movl %ebx, x(%edi) ) ;
28418+ DST(movl %ebx, %es:x(%edi)) ;
28419
28420 #define ROUND(x) \
28421+ nop; nop; nop; \
28422 SRC(movl x(%esi), %ebx ) ; \
28423 adcl %ebx, %eax ; \
28424- DST(movl %ebx, x(%edi) ) ;
28425+ DST(movl %ebx, %es:x(%edi)) ;
28426
28427 #define ARGBASE 12
28428-
28429-ENTRY(csum_partial_copy_generic)
28430+
28431+ENTRY(csum_partial_copy_generic_to_user)
28432 CFI_STARTPROC
28433+
28434+#ifdef CONFIG_PAX_MEMORY_UDEREF
28435+ pushl_cfi %gs
28436+ popl_cfi %es
28437+ jmp csum_partial_copy_generic
28438+#endif
28439+
28440+ENTRY(csum_partial_copy_generic_from_user)
28441+
28442+#ifdef CONFIG_PAX_MEMORY_UDEREF
28443+ pushl_cfi %gs
28444+ popl_cfi %ds
28445+#endif
28446+
28447+ENTRY(csum_partial_copy_generic)
28448 pushl_cfi %ebx
28449 CFI_REL_OFFSET ebx, 0
28450 pushl_cfi %edi
28451@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28452 subl %ebx, %edi
28453 lea -1(%esi),%edx
28454 andl $-32,%edx
28455- lea 3f(%ebx,%ebx), %ebx
28456+ lea 3f(%ebx,%ebx,2), %ebx
28457 testl %esi, %esi
28458 jmp *%ebx
28459 1: addl $64,%esi
28460@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28461 jb 5f
28462 SRC( movw (%esi), %dx )
28463 leal 2(%esi), %esi
28464-DST( movw %dx, (%edi) )
28465+DST( movw %dx, %es:(%edi) )
28466 leal 2(%edi), %edi
28467 je 6f
28468 shll $16,%edx
28469 5:
28470 SRC( movb (%esi), %dl )
28471-DST( movb %dl, (%edi) )
28472+DST( movb %dl, %es:(%edi) )
28473 6: addl %edx, %eax
28474 adcl $0, %eax
28475 7:
28476 .section .fixup, "ax"
28477 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28478- movl $-EFAULT, (%ebx)
28479+ movl $-EFAULT, %ss:(%ebx)
28480 # zero the complete destination (computing the rest is too much work)
28481 movl ARGBASE+8(%esp),%edi # dst
28482 movl ARGBASE+12(%esp),%ecx # len
28483@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28484 rep; stosb
28485 jmp 7b
28486 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28487- movl $-EFAULT, (%ebx)
28488+ movl $-EFAULT, %ss:(%ebx)
28489 jmp 7b
28490 .previous
28491
28492+#ifdef CONFIG_PAX_MEMORY_UDEREF
28493+ pushl_cfi %ss
28494+ popl_cfi %ds
28495+ pushl_cfi %ss
28496+ popl_cfi %es
28497+#endif
28498+
28499 popl_cfi %esi
28500 CFI_RESTORE esi
28501 popl_cfi %edi
28502@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28503 CFI_RESTORE ebx
28504 ret
28505 CFI_ENDPROC
28506-ENDPROC(csum_partial_copy_generic)
28507+ENDPROC(csum_partial_copy_generic_to_user)
28508
28509 #undef ROUND
28510 #undef ROUND1
28511diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28512index f2145cf..cea889d 100644
28513--- a/arch/x86/lib/clear_page_64.S
28514+++ b/arch/x86/lib/clear_page_64.S
28515@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28516 movl $4096/8,%ecx
28517 xorl %eax,%eax
28518 rep stosq
28519+ pax_force_retaddr
28520 ret
28521 CFI_ENDPROC
28522 ENDPROC(clear_page_c)
28523@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28524 movl $4096,%ecx
28525 xorl %eax,%eax
28526 rep stosb
28527+ pax_force_retaddr
28528 ret
28529 CFI_ENDPROC
28530 ENDPROC(clear_page_c_e)
28531@@ -43,6 +45,7 @@ ENTRY(clear_page)
28532 leaq 64(%rdi),%rdi
28533 jnz .Lloop
28534 nop
28535+ pax_force_retaddr
28536 ret
28537 CFI_ENDPROC
28538 .Lclear_page_end:
28539@@ -58,7 +61,7 @@ ENDPROC(clear_page)
28540
28541 #include <asm/cpufeature.h>
28542
28543- .section .altinstr_replacement,"ax"
28544+ .section .altinstr_replacement,"a"
28545 1: .byte 0xeb /* jmp <disp8> */
28546 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28547 2: .byte 0xeb /* jmp <disp8> */
28548diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28549index 1e572c5..2a162cd 100644
28550--- a/arch/x86/lib/cmpxchg16b_emu.S
28551+++ b/arch/x86/lib/cmpxchg16b_emu.S
28552@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28553
28554 popf
28555 mov $1, %al
28556+ pax_force_retaddr
28557 ret
28558
28559 not_same:
28560 popf
28561 xor %al,%al
28562+ pax_force_retaddr
28563 ret
28564
28565 CFI_ENDPROC
28566diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28567index 176cca6..e0d658e 100644
28568--- a/arch/x86/lib/copy_page_64.S
28569+++ b/arch/x86/lib/copy_page_64.S
28570@@ -9,6 +9,7 @@ copy_page_rep:
28571 CFI_STARTPROC
28572 movl $4096/8, %ecx
28573 rep movsq
28574+ pax_force_retaddr
28575 ret
28576 CFI_ENDPROC
28577 ENDPROC(copy_page_rep)
28578@@ -24,8 +25,8 @@ ENTRY(copy_page)
28579 CFI_ADJUST_CFA_OFFSET 2*8
28580 movq %rbx, (%rsp)
28581 CFI_REL_OFFSET rbx, 0
28582- movq %r12, 1*8(%rsp)
28583- CFI_REL_OFFSET r12, 1*8
28584+ movq %r13, 1*8(%rsp)
28585+ CFI_REL_OFFSET r13, 1*8
28586
28587 movl $(4096/64)-5, %ecx
28588 .p2align 4
28589@@ -38,7 +39,7 @@ ENTRY(copy_page)
28590 movq 0x8*4(%rsi), %r9
28591 movq 0x8*5(%rsi), %r10
28592 movq 0x8*6(%rsi), %r11
28593- movq 0x8*7(%rsi), %r12
28594+ movq 0x8*7(%rsi), %r13
28595
28596 prefetcht0 5*64(%rsi)
28597
28598@@ -49,7 +50,7 @@ ENTRY(copy_page)
28599 movq %r9, 0x8*4(%rdi)
28600 movq %r10, 0x8*5(%rdi)
28601 movq %r11, 0x8*6(%rdi)
28602- movq %r12, 0x8*7(%rdi)
28603+ movq %r13, 0x8*7(%rdi)
28604
28605 leaq 64 (%rsi), %rsi
28606 leaq 64 (%rdi), %rdi
28607@@ -68,7 +69,7 @@ ENTRY(copy_page)
28608 movq 0x8*4(%rsi), %r9
28609 movq 0x8*5(%rsi), %r10
28610 movq 0x8*6(%rsi), %r11
28611- movq 0x8*7(%rsi), %r12
28612+ movq 0x8*7(%rsi), %r13
28613
28614 movq %rax, 0x8*0(%rdi)
28615 movq %rbx, 0x8*1(%rdi)
28616@@ -77,7 +78,7 @@ ENTRY(copy_page)
28617 movq %r9, 0x8*4(%rdi)
28618 movq %r10, 0x8*5(%rdi)
28619 movq %r11, 0x8*6(%rdi)
28620- movq %r12, 0x8*7(%rdi)
28621+ movq %r13, 0x8*7(%rdi)
28622
28623 leaq 64(%rdi), %rdi
28624 leaq 64(%rsi), %rsi
28625@@ -85,10 +86,11 @@ ENTRY(copy_page)
28626
28627 movq (%rsp), %rbx
28628 CFI_RESTORE rbx
28629- movq 1*8(%rsp), %r12
28630- CFI_RESTORE r12
28631+ movq 1*8(%rsp), %r13
28632+ CFI_RESTORE r13
28633 addq $2*8, %rsp
28634 CFI_ADJUST_CFA_OFFSET -2*8
28635+ pax_force_retaddr
28636 ret
28637 .Lcopy_page_end:
28638 CFI_ENDPROC
28639@@ -99,7 +101,7 @@ ENDPROC(copy_page)
28640
28641 #include <asm/cpufeature.h>
28642
28643- .section .altinstr_replacement,"ax"
28644+ .section .altinstr_replacement,"a"
28645 1: .byte 0xeb /* jmp <disp8> */
28646 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28647 2:
28648diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28649index a30ca15..407412b 100644
28650--- a/arch/x86/lib/copy_user_64.S
28651+++ b/arch/x86/lib/copy_user_64.S
28652@@ -18,31 +18,7 @@
28653 #include <asm/alternative-asm.h>
28654 #include <asm/asm.h>
28655 #include <asm/smap.h>
28656-
28657-/*
28658- * By placing feature2 after feature1 in altinstructions section, we logically
28659- * implement:
28660- * If CPU has feature2, jmp to alt2 is used
28661- * else if CPU has feature1, jmp to alt1 is used
28662- * else jmp to orig is used.
28663- */
28664- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28665-0:
28666- .byte 0xe9 /* 32bit jump */
28667- .long \orig-1f /* by default jump to orig */
28668-1:
28669- .section .altinstr_replacement,"ax"
28670-2: .byte 0xe9 /* near jump with 32bit immediate */
28671- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28672-3: .byte 0xe9 /* near jump with 32bit immediate */
28673- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28674- .previous
28675-
28676- .section .altinstructions,"a"
28677- altinstruction_entry 0b,2b,\feature1,5,5
28678- altinstruction_entry 0b,3b,\feature2,5,5
28679- .previous
28680- .endm
28681+#include <asm/pgtable.h>
28682
28683 .macro ALIGN_DESTINATION
28684 #ifdef FIX_ALIGNMENT
28685@@ -70,52 +46,6 @@
28686 #endif
28687 .endm
28688
28689-/* Standard copy_to_user with segment limit checking */
28690-ENTRY(_copy_to_user)
28691- CFI_STARTPROC
28692- GET_THREAD_INFO(%rax)
28693- movq %rdi,%rcx
28694- addq %rdx,%rcx
28695- jc bad_to_user
28696- cmpq TI_addr_limit(%rax),%rcx
28697- ja bad_to_user
28698- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28699- copy_user_generic_unrolled,copy_user_generic_string, \
28700- copy_user_enhanced_fast_string
28701- CFI_ENDPROC
28702-ENDPROC(_copy_to_user)
28703-
28704-/* Standard copy_from_user with segment limit checking */
28705-ENTRY(_copy_from_user)
28706- CFI_STARTPROC
28707- GET_THREAD_INFO(%rax)
28708- movq %rsi,%rcx
28709- addq %rdx,%rcx
28710- jc bad_from_user
28711- cmpq TI_addr_limit(%rax),%rcx
28712- ja bad_from_user
28713- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28714- copy_user_generic_unrolled,copy_user_generic_string, \
28715- copy_user_enhanced_fast_string
28716- CFI_ENDPROC
28717-ENDPROC(_copy_from_user)
28718-
28719- .section .fixup,"ax"
28720- /* must zero dest */
28721-ENTRY(bad_from_user)
28722-bad_from_user:
28723- CFI_STARTPROC
28724- movl %edx,%ecx
28725- xorl %eax,%eax
28726- rep
28727- stosb
28728-bad_to_user:
28729- movl %edx,%eax
28730- ret
28731- CFI_ENDPROC
28732-ENDPROC(bad_from_user)
28733- .previous
28734-
28735 /*
28736 * copy_user_generic_unrolled - memory copy with exception handling.
28737 * This version is for CPUs like P4 that don't have efficient micro
28738@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28739 */
28740 ENTRY(copy_user_generic_unrolled)
28741 CFI_STARTPROC
28742+ ASM_PAX_OPEN_USERLAND
28743 ASM_STAC
28744 cmpl $8,%edx
28745 jb 20f /* less then 8 bytes, go to byte copy loop */
28746@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28747 jnz 21b
28748 23: xor %eax,%eax
28749 ASM_CLAC
28750+ ASM_PAX_CLOSE_USERLAND
28751+ pax_force_retaddr
28752 ret
28753
28754 .section .fixup,"ax"
28755@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28756 */
28757 ENTRY(copy_user_generic_string)
28758 CFI_STARTPROC
28759+ ASM_PAX_OPEN_USERLAND
28760 ASM_STAC
28761 andl %edx,%edx
28762 jz 4f
28763@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28764 movsb
28765 4: xorl %eax,%eax
28766 ASM_CLAC
28767+ ASM_PAX_CLOSE_USERLAND
28768+ pax_force_retaddr
28769 ret
28770
28771 .section .fixup,"ax"
28772@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28773 */
28774 ENTRY(copy_user_enhanced_fast_string)
28775 CFI_STARTPROC
28776+ ASM_PAX_OPEN_USERLAND
28777 ASM_STAC
28778 andl %edx,%edx
28779 jz 2f
28780@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28781 movsb
28782 2: xorl %eax,%eax
28783 ASM_CLAC
28784+ ASM_PAX_CLOSE_USERLAND
28785+ pax_force_retaddr
28786 ret
28787
28788 .section .fixup,"ax"
28789diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28790index 6a4f43c..c70fb52 100644
28791--- a/arch/x86/lib/copy_user_nocache_64.S
28792+++ b/arch/x86/lib/copy_user_nocache_64.S
28793@@ -8,6 +8,7 @@
28794
28795 #include <linux/linkage.h>
28796 #include <asm/dwarf2.h>
28797+#include <asm/alternative-asm.h>
28798
28799 #define FIX_ALIGNMENT 1
28800
28801@@ -16,6 +17,7 @@
28802 #include <asm/thread_info.h>
28803 #include <asm/asm.h>
28804 #include <asm/smap.h>
28805+#include <asm/pgtable.h>
28806
28807 .macro ALIGN_DESTINATION
28808 #ifdef FIX_ALIGNMENT
28809@@ -49,6 +51,16 @@
28810 */
28811 ENTRY(__copy_user_nocache)
28812 CFI_STARTPROC
28813+
28814+#ifdef CONFIG_PAX_MEMORY_UDEREF
28815+ mov pax_user_shadow_base,%rcx
28816+ cmp %rcx,%rsi
28817+ jae 1f
28818+ add %rcx,%rsi
28819+1:
28820+#endif
28821+
28822+ ASM_PAX_OPEN_USERLAND
28823 ASM_STAC
28824 cmpl $8,%edx
28825 jb 20f /* less then 8 bytes, go to byte copy loop */
28826@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28827 jnz 21b
28828 23: xorl %eax,%eax
28829 ASM_CLAC
28830+ ASM_PAX_CLOSE_USERLAND
28831 sfence
28832+ pax_force_retaddr
28833 ret
28834
28835 .section .fixup,"ax"
28836diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28837index 2419d5f..fe52d0e 100644
28838--- a/arch/x86/lib/csum-copy_64.S
28839+++ b/arch/x86/lib/csum-copy_64.S
28840@@ -9,6 +9,7 @@
28841 #include <asm/dwarf2.h>
28842 #include <asm/errno.h>
28843 #include <asm/asm.h>
28844+#include <asm/alternative-asm.h>
28845
28846 /*
28847 * Checksum copy with exception handling.
28848@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28849 CFI_ADJUST_CFA_OFFSET 7*8
28850 movq %rbx, 2*8(%rsp)
28851 CFI_REL_OFFSET rbx, 2*8
28852- movq %r12, 3*8(%rsp)
28853- CFI_REL_OFFSET r12, 3*8
28854+ movq %r15, 3*8(%rsp)
28855+ CFI_REL_OFFSET r15, 3*8
28856 movq %r14, 4*8(%rsp)
28857 CFI_REL_OFFSET r14, 4*8
28858 movq %r13, 5*8(%rsp)
28859@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28860 movl %edx, %ecx
28861
28862 xorl %r9d, %r9d
28863- movq %rcx, %r12
28864+ movq %rcx, %r15
28865
28866- shrq $6, %r12
28867+ shrq $6, %r15
28868 jz .Lhandle_tail /* < 64 */
28869
28870 clc
28871
28872 /* main loop. clear in 64 byte blocks */
28873 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28874- /* r11: temp3, rdx: temp4, r12 loopcnt */
28875+ /* r11: temp3, rdx: temp4, r15 loopcnt */
28876 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28877 .p2align 4
28878 .Lloop:
28879@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28880 adcq %r14, %rax
28881 adcq %r13, %rax
28882
28883- decl %r12d
28884+ decl %r15d
28885
28886 dest
28887 movq %rbx, (%rsi)
28888@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28889 .Lende:
28890 movq 2*8(%rsp), %rbx
28891 CFI_RESTORE rbx
28892- movq 3*8(%rsp), %r12
28893- CFI_RESTORE r12
28894+ movq 3*8(%rsp), %r15
28895+ CFI_RESTORE r15
28896 movq 4*8(%rsp), %r14
28897 CFI_RESTORE r14
28898 movq 5*8(%rsp), %r13
28899@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28900 CFI_RESTORE rbp
28901 addq $7*8, %rsp
28902 CFI_ADJUST_CFA_OFFSET -7*8
28903+ pax_force_retaddr
28904 ret
28905 CFI_RESTORE_STATE
28906
28907diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28908index 7609e0e..b449b98 100644
28909--- a/arch/x86/lib/csum-wrappers_64.c
28910+++ b/arch/x86/lib/csum-wrappers_64.c
28911@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28912 len -= 2;
28913 }
28914 }
28915+ pax_open_userland();
28916 stac();
28917- isum = csum_partial_copy_generic((__force const void *)src,
28918+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28919 dst, len, isum, errp, NULL);
28920 clac();
28921+ pax_close_userland();
28922 if (unlikely(*errp))
28923 goto out_err;
28924
28925@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28926 }
28927
28928 *errp = 0;
28929+ pax_open_userland();
28930 stac();
28931- ret = csum_partial_copy_generic(src, (void __force *)dst,
28932+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28933 len, isum, NULL, errp);
28934 clac();
28935+ pax_close_userland();
28936 return ret;
28937 }
28938 EXPORT_SYMBOL(csum_partial_copy_to_user);
28939diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28940index a451235..1daa956 100644
28941--- a/arch/x86/lib/getuser.S
28942+++ b/arch/x86/lib/getuser.S
28943@@ -33,17 +33,40 @@
28944 #include <asm/thread_info.h>
28945 #include <asm/asm.h>
28946 #include <asm/smap.h>
28947+#include <asm/segment.h>
28948+#include <asm/pgtable.h>
28949+#include <asm/alternative-asm.h>
28950+
28951+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28952+#define __copyuser_seg gs;
28953+#else
28954+#define __copyuser_seg
28955+#endif
28956
28957 .text
28958 ENTRY(__get_user_1)
28959 CFI_STARTPROC
28960+
28961+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28962 GET_THREAD_INFO(%_ASM_DX)
28963 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28964 jae bad_get_user
28965 ASM_STAC
28966-1: movzbl (%_ASM_AX),%edx
28967+
28968+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28969+ mov pax_user_shadow_base,%_ASM_DX
28970+ cmp %_ASM_DX,%_ASM_AX
28971+ jae 1234f
28972+ add %_ASM_DX,%_ASM_AX
28973+1234:
28974+#endif
28975+
28976+#endif
28977+
28978+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28979 xor %eax,%eax
28980 ASM_CLAC
28981+ pax_force_retaddr
28982 ret
28983 CFI_ENDPROC
28984 ENDPROC(__get_user_1)
28985@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28986 ENTRY(__get_user_2)
28987 CFI_STARTPROC
28988 add $1,%_ASM_AX
28989+
28990+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28991 jc bad_get_user
28992 GET_THREAD_INFO(%_ASM_DX)
28993 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28994 jae bad_get_user
28995 ASM_STAC
28996-2: movzwl -1(%_ASM_AX),%edx
28997+
28998+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28999+ mov pax_user_shadow_base,%_ASM_DX
29000+ cmp %_ASM_DX,%_ASM_AX
29001+ jae 1234f
29002+ add %_ASM_DX,%_ASM_AX
29003+1234:
29004+#endif
29005+
29006+#endif
29007+
29008+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29009 xor %eax,%eax
29010 ASM_CLAC
29011+ pax_force_retaddr
29012 ret
29013 CFI_ENDPROC
29014 ENDPROC(__get_user_2)
29015@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29016 ENTRY(__get_user_4)
29017 CFI_STARTPROC
29018 add $3,%_ASM_AX
29019+
29020+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29021 jc bad_get_user
29022 GET_THREAD_INFO(%_ASM_DX)
29023 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29024 jae bad_get_user
29025 ASM_STAC
29026-3: movl -3(%_ASM_AX),%edx
29027+
29028+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29029+ mov pax_user_shadow_base,%_ASM_DX
29030+ cmp %_ASM_DX,%_ASM_AX
29031+ jae 1234f
29032+ add %_ASM_DX,%_ASM_AX
29033+1234:
29034+#endif
29035+
29036+#endif
29037+
29038+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29039 xor %eax,%eax
29040 ASM_CLAC
29041+ pax_force_retaddr
29042 ret
29043 CFI_ENDPROC
29044 ENDPROC(__get_user_4)
29045@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29046 GET_THREAD_INFO(%_ASM_DX)
29047 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29048 jae bad_get_user
29049+
29050+#ifdef CONFIG_PAX_MEMORY_UDEREF
29051+ mov pax_user_shadow_base,%_ASM_DX
29052+ cmp %_ASM_DX,%_ASM_AX
29053+ jae 1234f
29054+ add %_ASM_DX,%_ASM_AX
29055+1234:
29056+#endif
29057+
29058 ASM_STAC
29059 4: movq -7(%_ASM_AX),%rdx
29060 xor %eax,%eax
29061 ASM_CLAC
29062+ pax_force_retaddr
29063 ret
29064 #else
29065 add $7,%_ASM_AX
29066@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29067 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29068 jae bad_get_user_8
29069 ASM_STAC
29070-4: movl -7(%_ASM_AX),%edx
29071-5: movl -3(%_ASM_AX),%ecx
29072+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29073+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29074 xor %eax,%eax
29075 ASM_CLAC
29076+ pax_force_retaddr
29077 ret
29078 #endif
29079 CFI_ENDPROC
29080@@ -113,6 +175,7 @@ bad_get_user:
29081 xor %edx,%edx
29082 mov $(-EFAULT),%_ASM_AX
29083 ASM_CLAC
29084+ pax_force_retaddr
29085 ret
29086 CFI_ENDPROC
29087 END(bad_get_user)
29088@@ -124,6 +187,7 @@ bad_get_user_8:
29089 xor %ecx,%ecx
29090 mov $(-EFAULT),%_ASM_AX
29091 ASM_CLAC
29092+ pax_force_retaddr
29093 ret
29094 CFI_ENDPROC
29095 END(bad_get_user_8)
29096diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29097index 54fcffe..7be149e 100644
29098--- a/arch/x86/lib/insn.c
29099+++ b/arch/x86/lib/insn.c
29100@@ -20,8 +20,10 @@
29101
29102 #ifdef __KERNEL__
29103 #include <linux/string.h>
29104+#include <asm/pgtable_types.h>
29105 #else
29106 #include <string.h>
29107+#define ktla_ktva(addr) addr
29108 #endif
29109 #include <asm/inat.h>
29110 #include <asm/insn.h>
29111@@ -53,8 +55,8 @@
29112 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29113 {
29114 memset(insn, 0, sizeof(*insn));
29115- insn->kaddr = kaddr;
29116- insn->next_byte = kaddr;
29117+ insn->kaddr = ktla_ktva(kaddr);
29118+ insn->next_byte = ktla_ktva(kaddr);
29119 insn->x86_64 = x86_64 ? 1 : 0;
29120 insn->opnd_bytes = 4;
29121 if (x86_64)
29122diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29123index 05a95e7..326f2fa 100644
29124--- a/arch/x86/lib/iomap_copy_64.S
29125+++ b/arch/x86/lib/iomap_copy_64.S
29126@@ -17,6 +17,7 @@
29127
29128 #include <linux/linkage.h>
29129 #include <asm/dwarf2.h>
29130+#include <asm/alternative-asm.h>
29131
29132 /*
29133 * override generic version in lib/iomap_copy.c
29134@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29135 CFI_STARTPROC
29136 movl %edx,%ecx
29137 rep movsd
29138+ pax_force_retaddr
29139 ret
29140 CFI_ENDPROC
29141 ENDPROC(__iowrite32_copy)
29142diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29143index 56313a3..0db417e 100644
29144--- a/arch/x86/lib/memcpy_64.S
29145+++ b/arch/x86/lib/memcpy_64.S
29146@@ -24,7 +24,7 @@
29147 * This gets patched over the unrolled variant (below) via the
29148 * alternative instructions framework:
29149 */
29150- .section .altinstr_replacement, "ax", @progbits
29151+ .section .altinstr_replacement, "a", @progbits
29152 .Lmemcpy_c:
29153 movq %rdi, %rax
29154 movq %rdx, %rcx
29155@@ -33,6 +33,7 @@
29156 rep movsq
29157 movl %edx, %ecx
29158 rep movsb
29159+ pax_force_retaddr
29160 ret
29161 .Lmemcpy_e:
29162 .previous
29163@@ -44,11 +45,12 @@
29164 * This gets patched over the unrolled variant (below) via the
29165 * alternative instructions framework:
29166 */
29167- .section .altinstr_replacement, "ax", @progbits
29168+ .section .altinstr_replacement, "a", @progbits
29169 .Lmemcpy_c_e:
29170 movq %rdi, %rax
29171 movq %rdx, %rcx
29172 rep movsb
29173+ pax_force_retaddr
29174 ret
29175 .Lmemcpy_e_e:
29176 .previous
29177@@ -136,6 +138,7 @@ ENTRY(memcpy)
29178 movq %r9, 1*8(%rdi)
29179 movq %r10, -2*8(%rdi, %rdx)
29180 movq %r11, -1*8(%rdi, %rdx)
29181+ pax_force_retaddr
29182 retq
29183 .p2align 4
29184 .Lless_16bytes:
29185@@ -148,6 +151,7 @@ ENTRY(memcpy)
29186 movq -1*8(%rsi, %rdx), %r9
29187 movq %r8, 0*8(%rdi)
29188 movq %r9, -1*8(%rdi, %rdx)
29189+ pax_force_retaddr
29190 retq
29191 .p2align 4
29192 .Lless_8bytes:
29193@@ -161,6 +165,7 @@ ENTRY(memcpy)
29194 movl -4(%rsi, %rdx), %r8d
29195 movl %ecx, (%rdi)
29196 movl %r8d, -4(%rdi, %rdx)
29197+ pax_force_retaddr
29198 retq
29199 .p2align 4
29200 .Lless_3bytes:
29201@@ -179,6 +184,7 @@ ENTRY(memcpy)
29202 movb %cl, (%rdi)
29203
29204 .Lend:
29205+ pax_force_retaddr
29206 retq
29207 CFI_ENDPROC
29208 ENDPROC(memcpy)
29209diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29210index 65268a6..dd1de11 100644
29211--- a/arch/x86/lib/memmove_64.S
29212+++ b/arch/x86/lib/memmove_64.S
29213@@ -202,14 +202,16 @@ ENTRY(memmove)
29214 movb (%rsi), %r11b
29215 movb %r11b, (%rdi)
29216 13:
29217+ pax_force_retaddr
29218 retq
29219 CFI_ENDPROC
29220
29221- .section .altinstr_replacement,"ax"
29222+ .section .altinstr_replacement,"a"
29223 .Lmemmove_begin_forward_efs:
29224 /* Forward moving data. */
29225 movq %rdx, %rcx
29226 rep movsb
29227+ pax_force_retaddr
29228 retq
29229 .Lmemmove_end_forward_efs:
29230 .previous
29231diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29232index 2dcb380..2eb79fe 100644
29233--- a/arch/x86/lib/memset_64.S
29234+++ b/arch/x86/lib/memset_64.S
29235@@ -16,7 +16,7 @@
29236 *
29237 * rax original destination
29238 */
29239- .section .altinstr_replacement, "ax", @progbits
29240+ .section .altinstr_replacement, "a", @progbits
29241 .Lmemset_c:
29242 movq %rdi,%r9
29243 movq %rdx,%rcx
29244@@ -30,6 +30,7 @@
29245 movl %edx,%ecx
29246 rep stosb
29247 movq %r9,%rax
29248+ pax_force_retaddr
29249 ret
29250 .Lmemset_e:
29251 .previous
29252@@ -45,13 +46,14 @@
29253 *
29254 * rax original destination
29255 */
29256- .section .altinstr_replacement, "ax", @progbits
29257+ .section .altinstr_replacement, "a", @progbits
29258 .Lmemset_c_e:
29259 movq %rdi,%r9
29260 movb %sil,%al
29261 movq %rdx,%rcx
29262 rep stosb
29263 movq %r9,%rax
29264+ pax_force_retaddr
29265 ret
29266 .Lmemset_e_e:
29267 .previous
29268@@ -118,6 +120,7 @@ ENTRY(__memset)
29269
29270 .Lende:
29271 movq %r10,%rax
29272+ pax_force_retaddr
29273 ret
29274
29275 CFI_RESTORE_STATE
29276diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29277index c9f2d9b..e7fd2c0 100644
29278--- a/arch/x86/lib/mmx_32.c
29279+++ b/arch/x86/lib/mmx_32.c
29280@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29281 {
29282 void *p;
29283 int i;
29284+ unsigned long cr0;
29285
29286 if (unlikely(in_interrupt()))
29287 return __memcpy(to, from, len);
29288@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29289 kernel_fpu_begin();
29290
29291 __asm__ __volatile__ (
29292- "1: prefetch (%0)\n" /* This set is 28 bytes */
29293- " prefetch 64(%0)\n"
29294- " prefetch 128(%0)\n"
29295- " prefetch 192(%0)\n"
29296- " prefetch 256(%0)\n"
29297+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29298+ " prefetch 64(%1)\n"
29299+ " prefetch 128(%1)\n"
29300+ " prefetch 192(%1)\n"
29301+ " prefetch 256(%1)\n"
29302 "2: \n"
29303 ".section .fixup, \"ax\"\n"
29304- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29305+ "3: \n"
29306+
29307+#ifdef CONFIG_PAX_KERNEXEC
29308+ " movl %%cr0, %0\n"
29309+ " movl %0, %%eax\n"
29310+ " andl $0xFFFEFFFF, %%eax\n"
29311+ " movl %%eax, %%cr0\n"
29312+#endif
29313+
29314+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29315+
29316+#ifdef CONFIG_PAX_KERNEXEC
29317+ " movl %0, %%cr0\n"
29318+#endif
29319+
29320 " jmp 2b\n"
29321 ".previous\n"
29322 _ASM_EXTABLE(1b, 3b)
29323- : : "r" (from));
29324+ : "=&r" (cr0) : "r" (from) : "ax");
29325
29326 for ( ; i > 5; i--) {
29327 __asm__ __volatile__ (
29328- "1: prefetch 320(%0)\n"
29329- "2: movq (%0), %%mm0\n"
29330- " movq 8(%0), %%mm1\n"
29331- " movq 16(%0), %%mm2\n"
29332- " movq 24(%0), %%mm3\n"
29333- " movq %%mm0, (%1)\n"
29334- " movq %%mm1, 8(%1)\n"
29335- " movq %%mm2, 16(%1)\n"
29336- " movq %%mm3, 24(%1)\n"
29337- " movq 32(%0), %%mm0\n"
29338- " movq 40(%0), %%mm1\n"
29339- " movq 48(%0), %%mm2\n"
29340- " movq 56(%0), %%mm3\n"
29341- " movq %%mm0, 32(%1)\n"
29342- " movq %%mm1, 40(%1)\n"
29343- " movq %%mm2, 48(%1)\n"
29344- " movq %%mm3, 56(%1)\n"
29345+ "1: prefetch 320(%1)\n"
29346+ "2: movq (%1), %%mm0\n"
29347+ " movq 8(%1), %%mm1\n"
29348+ " movq 16(%1), %%mm2\n"
29349+ " movq 24(%1), %%mm3\n"
29350+ " movq %%mm0, (%2)\n"
29351+ " movq %%mm1, 8(%2)\n"
29352+ " movq %%mm2, 16(%2)\n"
29353+ " movq %%mm3, 24(%2)\n"
29354+ " movq 32(%1), %%mm0\n"
29355+ " movq 40(%1), %%mm1\n"
29356+ " movq 48(%1), %%mm2\n"
29357+ " movq 56(%1), %%mm3\n"
29358+ " movq %%mm0, 32(%2)\n"
29359+ " movq %%mm1, 40(%2)\n"
29360+ " movq %%mm2, 48(%2)\n"
29361+ " movq %%mm3, 56(%2)\n"
29362 ".section .fixup, \"ax\"\n"
29363- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29364+ "3:\n"
29365+
29366+#ifdef CONFIG_PAX_KERNEXEC
29367+ " movl %%cr0, %0\n"
29368+ " movl %0, %%eax\n"
29369+ " andl $0xFFFEFFFF, %%eax\n"
29370+ " movl %%eax, %%cr0\n"
29371+#endif
29372+
29373+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29374+
29375+#ifdef CONFIG_PAX_KERNEXEC
29376+ " movl %0, %%cr0\n"
29377+#endif
29378+
29379 " jmp 2b\n"
29380 ".previous\n"
29381 _ASM_EXTABLE(1b, 3b)
29382- : : "r" (from), "r" (to) : "memory");
29383+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29384
29385 from += 64;
29386 to += 64;
29387@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29388 static void fast_copy_page(void *to, void *from)
29389 {
29390 int i;
29391+ unsigned long cr0;
29392
29393 kernel_fpu_begin();
29394
29395@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29396 * but that is for later. -AV
29397 */
29398 __asm__ __volatile__(
29399- "1: prefetch (%0)\n"
29400- " prefetch 64(%0)\n"
29401- " prefetch 128(%0)\n"
29402- " prefetch 192(%0)\n"
29403- " prefetch 256(%0)\n"
29404+ "1: prefetch (%1)\n"
29405+ " prefetch 64(%1)\n"
29406+ " prefetch 128(%1)\n"
29407+ " prefetch 192(%1)\n"
29408+ " prefetch 256(%1)\n"
29409 "2: \n"
29410 ".section .fixup, \"ax\"\n"
29411- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29412+ "3: \n"
29413+
29414+#ifdef CONFIG_PAX_KERNEXEC
29415+ " movl %%cr0, %0\n"
29416+ " movl %0, %%eax\n"
29417+ " andl $0xFFFEFFFF, %%eax\n"
29418+ " movl %%eax, %%cr0\n"
29419+#endif
29420+
29421+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29422+
29423+#ifdef CONFIG_PAX_KERNEXEC
29424+ " movl %0, %%cr0\n"
29425+#endif
29426+
29427 " jmp 2b\n"
29428 ".previous\n"
29429- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29430+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29431
29432 for (i = 0; i < (4096-320)/64; i++) {
29433 __asm__ __volatile__ (
29434- "1: prefetch 320(%0)\n"
29435- "2: movq (%0), %%mm0\n"
29436- " movntq %%mm0, (%1)\n"
29437- " movq 8(%0), %%mm1\n"
29438- " movntq %%mm1, 8(%1)\n"
29439- " movq 16(%0), %%mm2\n"
29440- " movntq %%mm2, 16(%1)\n"
29441- " movq 24(%0), %%mm3\n"
29442- " movntq %%mm3, 24(%1)\n"
29443- " movq 32(%0), %%mm4\n"
29444- " movntq %%mm4, 32(%1)\n"
29445- " movq 40(%0), %%mm5\n"
29446- " movntq %%mm5, 40(%1)\n"
29447- " movq 48(%0), %%mm6\n"
29448- " movntq %%mm6, 48(%1)\n"
29449- " movq 56(%0), %%mm7\n"
29450- " movntq %%mm7, 56(%1)\n"
29451+ "1: prefetch 320(%1)\n"
29452+ "2: movq (%1), %%mm0\n"
29453+ " movntq %%mm0, (%2)\n"
29454+ " movq 8(%1), %%mm1\n"
29455+ " movntq %%mm1, 8(%2)\n"
29456+ " movq 16(%1), %%mm2\n"
29457+ " movntq %%mm2, 16(%2)\n"
29458+ " movq 24(%1), %%mm3\n"
29459+ " movntq %%mm3, 24(%2)\n"
29460+ " movq 32(%1), %%mm4\n"
29461+ " movntq %%mm4, 32(%2)\n"
29462+ " movq 40(%1), %%mm5\n"
29463+ " movntq %%mm5, 40(%2)\n"
29464+ " movq 48(%1), %%mm6\n"
29465+ " movntq %%mm6, 48(%2)\n"
29466+ " movq 56(%1), %%mm7\n"
29467+ " movntq %%mm7, 56(%2)\n"
29468 ".section .fixup, \"ax\"\n"
29469- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29470+ "3:\n"
29471+
29472+#ifdef CONFIG_PAX_KERNEXEC
29473+ " movl %%cr0, %0\n"
29474+ " movl %0, %%eax\n"
29475+ " andl $0xFFFEFFFF, %%eax\n"
29476+ " movl %%eax, %%cr0\n"
29477+#endif
29478+
29479+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29480+
29481+#ifdef CONFIG_PAX_KERNEXEC
29482+ " movl %0, %%cr0\n"
29483+#endif
29484+
29485 " jmp 2b\n"
29486 ".previous\n"
29487- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29488+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29489
29490 from += 64;
29491 to += 64;
29492@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29493 static void fast_copy_page(void *to, void *from)
29494 {
29495 int i;
29496+ unsigned long cr0;
29497
29498 kernel_fpu_begin();
29499
29500 __asm__ __volatile__ (
29501- "1: prefetch (%0)\n"
29502- " prefetch 64(%0)\n"
29503- " prefetch 128(%0)\n"
29504- " prefetch 192(%0)\n"
29505- " prefetch 256(%0)\n"
29506+ "1: prefetch (%1)\n"
29507+ " prefetch 64(%1)\n"
29508+ " prefetch 128(%1)\n"
29509+ " prefetch 192(%1)\n"
29510+ " prefetch 256(%1)\n"
29511 "2: \n"
29512 ".section .fixup, \"ax\"\n"
29513- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29514+ "3: \n"
29515+
29516+#ifdef CONFIG_PAX_KERNEXEC
29517+ " movl %%cr0, %0\n"
29518+ " movl %0, %%eax\n"
29519+ " andl $0xFFFEFFFF, %%eax\n"
29520+ " movl %%eax, %%cr0\n"
29521+#endif
29522+
29523+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29524+
29525+#ifdef CONFIG_PAX_KERNEXEC
29526+ " movl %0, %%cr0\n"
29527+#endif
29528+
29529 " jmp 2b\n"
29530 ".previous\n"
29531- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29532+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29533
29534 for (i = 0; i < 4096/64; i++) {
29535 __asm__ __volatile__ (
29536- "1: prefetch 320(%0)\n"
29537- "2: movq (%0), %%mm0\n"
29538- " movq 8(%0), %%mm1\n"
29539- " movq 16(%0), %%mm2\n"
29540- " movq 24(%0), %%mm3\n"
29541- " movq %%mm0, (%1)\n"
29542- " movq %%mm1, 8(%1)\n"
29543- " movq %%mm2, 16(%1)\n"
29544- " movq %%mm3, 24(%1)\n"
29545- " movq 32(%0), %%mm0\n"
29546- " movq 40(%0), %%mm1\n"
29547- " movq 48(%0), %%mm2\n"
29548- " movq 56(%0), %%mm3\n"
29549- " movq %%mm0, 32(%1)\n"
29550- " movq %%mm1, 40(%1)\n"
29551- " movq %%mm2, 48(%1)\n"
29552- " movq %%mm3, 56(%1)\n"
29553+ "1: prefetch 320(%1)\n"
29554+ "2: movq (%1), %%mm0\n"
29555+ " movq 8(%1), %%mm1\n"
29556+ " movq 16(%1), %%mm2\n"
29557+ " movq 24(%1), %%mm3\n"
29558+ " movq %%mm0, (%2)\n"
29559+ " movq %%mm1, 8(%2)\n"
29560+ " movq %%mm2, 16(%2)\n"
29561+ " movq %%mm3, 24(%2)\n"
29562+ " movq 32(%1), %%mm0\n"
29563+ " movq 40(%1), %%mm1\n"
29564+ " movq 48(%1), %%mm2\n"
29565+ " movq 56(%1), %%mm3\n"
29566+ " movq %%mm0, 32(%2)\n"
29567+ " movq %%mm1, 40(%2)\n"
29568+ " movq %%mm2, 48(%2)\n"
29569+ " movq %%mm3, 56(%2)\n"
29570 ".section .fixup, \"ax\"\n"
29571- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29572+ "3:\n"
29573+
29574+#ifdef CONFIG_PAX_KERNEXEC
29575+ " movl %%cr0, %0\n"
29576+ " movl %0, %%eax\n"
29577+ " andl $0xFFFEFFFF, %%eax\n"
29578+ " movl %%eax, %%cr0\n"
29579+#endif
29580+
29581+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29582+
29583+#ifdef CONFIG_PAX_KERNEXEC
29584+ " movl %0, %%cr0\n"
29585+#endif
29586+
29587 " jmp 2b\n"
29588 ".previous\n"
29589 _ASM_EXTABLE(1b, 3b)
29590- : : "r" (from), "r" (to) : "memory");
29591+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29592
29593 from += 64;
29594 to += 64;
29595diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29596index f6d13ee..d789440 100644
29597--- a/arch/x86/lib/msr-reg.S
29598+++ b/arch/x86/lib/msr-reg.S
29599@@ -3,6 +3,7 @@
29600 #include <asm/dwarf2.h>
29601 #include <asm/asm.h>
29602 #include <asm/msr.h>
29603+#include <asm/alternative-asm.h>
29604
29605 #ifdef CONFIG_X86_64
29606 /*
29607@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29608 movl %edi, 28(%r10)
29609 popq_cfi %rbp
29610 popq_cfi %rbx
29611+ pax_force_retaddr
29612 ret
29613 3:
29614 CFI_RESTORE_STATE
29615diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29616index fc6ba17..d4d989d 100644
29617--- a/arch/x86/lib/putuser.S
29618+++ b/arch/x86/lib/putuser.S
29619@@ -16,7 +16,9 @@
29620 #include <asm/errno.h>
29621 #include <asm/asm.h>
29622 #include <asm/smap.h>
29623-
29624+#include <asm/segment.h>
29625+#include <asm/pgtable.h>
29626+#include <asm/alternative-asm.h>
29627
29628 /*
29629 * __put_user_X
29630@@ -30,57 +32,125 @@
29631 * as they get called from within inline assembly.
29632 */
29633
29634-#define ENTER CFI_STARTPROC ; \
29635- GET_THREAD_INFO(%_ASM_BX)
29636-#define EXIT ASM_CLAC ; \
29637- ret ; \
29638+#define ENTER CFI_STARTPROC
29639+#define EXIT ASM_CLAC ; \
29640+ pax_force_retaddr ; \
29641+ ret ; \
29642 CFI_ENDPROC
29643
29644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29645+#define _DEST %_ASM_CX,%_ASM_BX
29646+#else
29647+#define _DEST %_ASM_CX
29648+#endif
29649+
29650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29651+#define __copyuser_seg gs;
29652+#else
29653+#define __copyuser_seg
29654+#endif
29655+
29656 .text
29657 ENTRY(__put_user_1)
29658 ENTER
29659+
29660+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29661+ GET_THREAD_INFO(%_ASM_BX)
29662 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29663 jae bad_put_user
29664 ASM_STAC
29665-1: movb %al,(%_ASM_CX)
29666+
29667+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29668+ mov pax_user_shadow_base,%_ASM_BX
29669+ cmp %_ASM_BX,%_ASM_CX
29670+ jb 1234f
29671+ xor %ebx,%ebx
29672+1234:
29673+#endif
29674+
29675+#endif
29676+
29677+1: __copyuser_seg movb %al,(_DEST)
29678 xor %eax,%eax
29679 EXIT
29680 ENDPROC(__put_user_1)
29681
29682 ENTRY(__put_user_2)
29683 ENTER
29684+
29685+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29686+ GET_THREAD_INFO(%_ASM_BX)
29687 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29688 sub $1,%_ASM_BX
29689 cmp %_ASM_BX,%_ASM_CX
29690 jae bad_put_user
29691 ASM_STAC
29692-2: movw %ax,(%_ASM_CX)
29693+
29694+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29695+ mov pax_user_shadow_base,%_ASM_BX
29696+ cmp %_ASM_BX,%_ASM_CX
29697+ jb 1234f
29698+ xor %ebx,%ebx
29699+1234:
29700+#endif
29701+
29702+#endif
29703+
29704+2: __copyuser_seg movw %ax,(_DEST)
29705 xor %eax,%eax
29706 EXIT
29707 ENDPROC(__put_user_2)
29708
29709 ENTRY(__put_user_4)
29710 ENTER
29711+
29712+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29713+ GET_THREAD_INFO(%_ASM_BX)
29714 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29715 sub $3,%_ASM_BX
29716 cmp %_ASM_BX,%_ASM_CX
29717 jae bad_put_user
29718 ASM_STAC
29719-3: movl %eax,(%_ASM_CX)
29720+
29721+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29722+ mov pax_user_shadow_base,%_ASM_BX
29723+ cmp %_ASM_BX,%_ASM_CX
29724+ jb 1234f
29725+ xor %ebx,%ebx
29726+1234:
29727+#endif
29728+
29729+#endif
29730+
29731+3: __copyuser_seg movl %eax,(_DEST)
29732 xor %eax,%eax
29733 EXIT
29734 ENDPROC(__put_user_4)
29735
29736 ENTRY(__put_user_8)
29737 ENTER
29738+
29739+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29740+ GET_THREAD_INFO(%_ASM_BX)
29741 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29742 sub $7,%_ASM_BX
29743 cmp %_ASM_BX,%_ASM_CX
29744 jae bad_put_user
29745 ASM_STAC
29746-4: mov %_ASM_AX,(%_ASM_CX)
29747+
29748+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29749+ mov pax_user_shadow_base,%_ASM_BX
29750+ cmp %_ASM_BX,%_ASM_CX
29751+ jb 1234f
29752+ xor %ebx,%ebx
29753+1234:
29754+#endif
29755+
29756+#endif
29757+
29758+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29759 #ifdef CONFIG_X86_32
29760-5: movl %edx,4(%_ASM_CX)
29761+5: __copyuser_seg movl %edx,4(_DEST)
29762 #endif
29763 xor %eax,%eax
29764 EXIT
29765diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29766index 1cad221..de671ee 100644
29767--- a/arch/x86/lib/rwlock.S
29768+++ b/arch/x86/lib/rwlock.S
29769@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29770 FRAME
29771 0: LOCK_PREFIX
29772 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29773+
29774+#ifdef CONFIG_PAX_REFCOUNT
29775+ jno 1234f
29776+ LOCK_PREFIX
29777+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29778+ int $4
29779+1234:
29780+ _ASM_EXTABLE(1234b, 1234b)
29781+#endif
29782+
29783 1: rep; nop
29784 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29785 jne 1b
29786 LOCK_PREFIX
29787 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29788+
29789+#ifdef CONFIG_PAX_REFCOUNT
29790+ jno 1234f
29791+ LOCK_PREFIX
29792+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29793+ int $4
29794+1234:
29795+ _ASM_EXTABLE(1234b, 1234b)
29796+#endif
29797+
29798 jnz 0b
29799 ENDFRAME
29800+ pax_force_retaddr
29801 ret
29802 CFI_ENDPROC
29803 END(__write_lock_failed)
29804@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29805 FRAME
29806 0: LOCK_PREFIX
29807 READ_LOCK_SIZE(inc) (%__lock_ptr)
29808+
29809+#ifdef CONFIG_PAX_REFCOUNT
29810+ jno 1234f
29811+ LOCK_PREFIX
29812+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29813+ int $4
29814+1234:
29815+ _ASM_EXTABLE(1234b, 1234b)
29816+#endif
29817+
29818 1: rep; nop
29819 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29820 js 1b
29821 LOCK_PREFIX
29822 READ_LOCK_SIZE(dec) (%__lock_ptr)
29823+
29824+#ifdef CONFIG_PAX_REFCOUNT
29825+ jno 1234f
29826+ LOCK_PREFIX
29827+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29828+ int $4
29829+1234:
29830+ _ASM_EXTABLE(1234b, 1234b)
29831+#endif
29832+
29833 js 0b
29834 ENDFRAME
29835+ pax_force_retaddr
29836 ret
29837 CFI_ENDPROC
29838 END(__read_lock_failed)
29839diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29840index 5dff5f0..cadebf4 100644
29841--- a/arch/x86/lib/rwsem.S
29842+++ b/arch/x86/lib/rwsem.S
29843@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29844 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29845 CFI_RESTORE __ASM_REG(dx)
29846 restore_common_regs
29847+ pax_force_retaddr
29848 ret
29849 CFI_ENDPROC
29850 ENDPROC(call_rwsem_down_read_failed)
29851@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29852 movq %rax,%rdi
29853 call rwsem_down_write_failed
29854 restore_common_regs
29855+ pax_force_retaddr
29856 ret
29857 CFI_ENDPROC
29858 ENDPROC(call_rwsem_down_write_failed)
29859@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29860 movq %rax,%rdi
29861 call rwsem_wake
29862 restore_common_regs
29863-1: ret
29864+1: pax_force_retaddr
29865+ ret
29866 CFI_ENDPROC
29867 ENDPROC(call_rwsem_wake)
29868
29869@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29870 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29871 CFI_RESTORE __ASM_REG(dx)
29872 restore_common_regs
29873+ pax_force_retaddr
29874 ret
29875 CFI_ENDPROC
29876 ENDPROC(call_rwsem_downgrade_wake)
29877diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29878index a63efd6..8149fbe 100644
29879--- a/arch/x86/lib/thunk_64.S
29880+++ b/arch/x86/lib/thunk_64.S
29881@@ -8,6 +8,7 @@
29882 #include <linux/linkage.h>
29883 #include <asm/dwarf2.h>
29884 #include <asm/calling.h>
29885+#include <asm/alternative-asm.h>
29886
29887 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29888 .macro THUNK name, func, put_ret_addr_in_rdi=0
29889@@ -15,11 +16,11 @@
29890 \name:
29891 CFI_STARTPROC
29892
29893- /* this one pushes 9 elems, the next one would be %rIP */
29894- SAVE_ARGS
29895+ /* this one pushes 15+1 elems, the next one would be %rIP */
29896+ SAVE_ARGS 8
29897
29898 .if \put_ret_addr_in_rdi
29899- movq_cfi_restore 9*8, rdi
29900+ movq_cfi_restore RIP, rdi
29901 .endif
29902
29903 call \func
29904@@ -38,8 +39,9 @@
29905
29906 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29907 CFI_STARTPROC
29908- SAVE_ARGS
29909+ SAVE_ARGS 8
29910 restore:
29911- RESTORE_ARGS
29912+ RESTORE_ARGS 1,8
29913+ pax_force_retaddr
29914 ret
29915 CFI_ENDPROC
29916diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29917index 3eb18ac..4b22130 100644
29918--- a/arch/x86/lib/usercopy_32.c
29919+++ b/arch/x86/lib/usercopy_32.c
29920@@ -42,11 +42,13 @@ do { \
29921 int __d0; \
29922 might_fault(); \
29923 __asm__ __volatile__( \
29924+ __COPYUSER_SET_ES \
29925 ASM_STAC "\n" \
29926 "0: rep; stosl\n" \
29927 " movl %2,%0\n" \
29928 "1: rep; stosb\n" \
29929 "2: " ASM_CLAC "\n" \
29930+ __COPYUSER_RESTORE_ES \
29931 ".section .fixup,\"ax\"\n" \
29932 "3: lea 0(%2,%0,4),%0\n" \
29933 " jmp 2b\n" \
29934@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29935
29936 #ifdef CONFIG_X86_INTEL_USERCOPY
29937 static unsigned long
29938-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29939+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29940 {
29941 int d0, d1;
29942 __asm__ __volatile__(
29943@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29944 " .align 2,0x90\n"
29945 "3: movl 0(%4), %%eax\n"
29946 "4: movl 4(%4), %%edx\n"
29947- "5: movl %%eax, 0(%3)\n"
29948- "6: movl %%edx, 4(%3)\n"
29949+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29950+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29951 "7: movl 8(%4), %%eax\n"
29952 "8: movl 12(%4),%%edx\n"
29953- "9: movl %%eax, 8(%3)\n"
29954- "10: movl %%edx, 12(%3)\n"
29955+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29956+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29957 "11: movl 16(%4), %%eax\n"
29958 "12: movl 20(%4), %%edx\n"
29959- "13: movl %%eax, 16(%3)\n"
29960- "14: movl %%edx, 20(%3)\n"
29961+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29962+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29963 "15: movl 24(%4), %%eax\n"
29964 "16: movl 28(%4), %%edx\n"
29965- "17: movl %%eax, 24(%3)\n"
29966- "18: movl %%edx, 28(%3)\n"
29967+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29968+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29969 "19: movl 32(%4), %%eax\n"
29970 "20: movl 36(%4), %%edx\n"
29971- "21: movl %%eax, 32(%3)\n"
29972- "22: movl %%edx, 36(%3)\n"
29973+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29974+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29975 "23: movl 40(%4), %%eax\n"
29976 "24: movl 44(%4), %%edx\n"
29977- "25: movl %%eax, 40(%3)\n"
29978- "26: movl %%edx, 44(%3)\n"
29979+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29980+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29981 "27: movl 48(%4), %%eax\n"
29982 "28: movl 52(%4), %%edx\n"
29983- "29: movl %%eax, 48(%3)\n"
29984- "30: movl %%edx, 52(%3)\n"
29985+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29986+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29987 "31: movl 56(%4), %%eax\n"
29988 "32: movl 60(%4), %%edx\n"
29989- "33: movl %%eax, 56(%3)\n"
29990- "34: movl %%edx, 60(%3)\n"
29991+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29992+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29993 " addl $-64, %0\n"
29994 " addl $64, %4\n"
29995 " addl $64, %3\n"
29996@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29997 " shrl $2, %0\n"
29998 " andl $3, %%eax\n"
29999 " cld\n"
30000+ __COPYUSER_SET_ES
30001 "99: rep; movsl\n"
30002 "36: movl %%eax, %0\n"
30003 "37: rep; movsb\n"
30004 "100:\n"
30005+ __COPYUSER_RESTORE_ES
30006+ ".section .fixup,\"ax\"\n"
30007+ "101: lea 0(%%eax,%0,4),%0\n"
30008+ " jmp 100b\n"
30009+ ".previous\n"
30010+ _ASM_EXTABLE(1b,100b)
30011+ _ASM_EXTABLE(2b,100b)
30012+ _ASM_EXTABLE(3b,100b)
30013+ _ASM_EXTABLE(4b,100b)
30014+ _ASM_EXTABLE(5b,100b)
30015+ _ASM_EXTABLE(6b,100b)
30016+ _ASM_EXTABLE(7b,100b)
30017+ _ASM_EXTABLE(8b,100b)
30018+ _ASM_EXTABLE(9b,100b)
30019+ _ASM_EXTABLE(10b,100b)
30020+ _ASM_EXTABLE(11b,100b)
30021+ _ASM_EXTABLE(12b,100b)
30022+ _ASM_EXTABLE(13b,100b)
30023+ _ASM_EXTABLE(14b,100b)
30024+ _ASM_EXTABLE(15b,100b)
30025+ _ASM_EXTABLE(16b,100b)
30026+ _ASM_EXTABLE(17b,100b)
30027+ _ASM_EXTABLE(18b,100b)
30028+ _ASM_EXTABLE(19b,100b)
30029+ _ASM_EXTABLE(20b,100b)
30030+ _ASM_EXTABLE(21b,100b)
30031+ _ASM_EXTABLE(22b,100b)
30032+ _ASM_EXTABLE(23b,100b)
30033+ _ASM_EXTABLE(24b,100b)
30034+ _ASM_EXTABLE(25b,100b)
30035+ _ASM_EXTABLE(26b,100b)
30036+ _ASM_EXTABLE(27b,100b)
30037+ _ASM_EXTABLE(28b,100b)
30038+ _ASM_EXTABLE(29b,100b)
30039+ _ASM_EXTABLE(30b,100b)
30040+ _ASM_EXTABLE(31b,100b)
30041+ _ASM_EXTABLE(32b,100b)
30042+ _ASM_EXTABLE(33b,100b)
30043+ _ASM_EXTABLE(34b,100b)
30044+ _ASM_EXTABLE(35b,100b)
30045+ _ASM_EXTABLE(36b,100b)
30046+ _ASM_EXTABLE(37b,100b)
30047+ _ASM_EXTABLE(99b,101b)
30048+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30049+ : "1"(to), "2"(from), "0"(size)
30050+ : "eax", "edx", "memory");
30051+ return size;
30052+}
30053+
30054+static unsigned long
30055+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30056+{
30057+ int d0, d1;
30058+ __asm__ __volatile__(
30059+ " .align 2,0x90\n"
30060+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30061+ " cmpl $67, %0\n"
30062+ " jbe 3f\n"
30063+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30064+ " .align 2,0x90\n"
30065+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30066+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30067+ "5: movl %%eax, 0(%3)\n"
30068+ "6: movl %%edx, 4(%3)\n"
30069+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30070+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30071+ "9: movl %%eax, 8(%3)\n"
30072+ "10: movl %%edx, 12(%3)\n"
30073+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30074+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30075+ "13: movl %%eax, 16(%3)\n"
30076+ "14: movl %%edx, 20(%3)\n"
30077+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30078+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30079+ "17: movl %%eax, 24(%3)\n"
30080+ "18: movl %%edx, 28(%3)\n"
30081+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30082+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30083+ "21: movl %%eax, 32(%3)\n"
30084+ "22: movl %%edx, 36(%3)\n"
30085+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30086+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30087+ "25: movl %%eax, 40(%3)\n"
30088+ "26: movl %%edx, 44(%3)\n"
30089+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30090+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30091+ "29: movl %%eax, 48(%3)\n"
30092+ "30: movl %%edx, 52(%3)\n"
30093+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30094+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30095+ "33: movl %%eax, 56(%3)\n"
30096+ "34: movl %%edx, 60(%3)\n"
30097+ " addl $-64, %0\n"
30098+ " addl $64, %4\n"
30099+ " addl $64, %3\n"
30100+ " cmpl $63, %0\n"
30101+ " ja 1b\n"
30102+ "35: movl %0, %%eax\n"
30103+ " shrl $2, %0\n"
30104+ " andl $3, %%eax\n"
30105+ " cld\n"
30106+ "99: rep; "__copyuser_seg" movsl\n"
30107+ "36: movl %%eax, %0\n"
30108+ "37: rep; "__copyuser_seg" movsb\n"
30109+ "100:\n"
30110 ".section .fixup,\"ax\"\n"
30111 "101: lea 0(%%eax,%0,4),%0\n"
30112 " jmp 100b\n"
30113@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30114 int d0, d1;
30115 __asm__ __volatile__(
30116 " .align 2,0x90\n"
30117- "0: movl 32(%4), %%eax\n"
30118+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30119 " cmpl $67, %0\n"
30120 " jbe 2f\n"
30121- "1: movl 64(%4), %%eax\n"
30122+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30123 " .align 2,0x90\n"
30124- "2: movl 0(%4), %%eax\n"
30125- "21: movl 4(%4), %%edx\n"
30126+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30127+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30128 " movl %%eax, 0(%3)\n"
30129 " movl %%edx, 4(%3)\n"
30130- "3: movl 8(%4), %%eax\n"
30131- "31: movl 12(%4),%%edx\n"
30132+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30133+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30134 " movl %%eax, 8(%3)\n"
30135 " movl %%edx, 12(%3)\n"
30136- "4: movl 16(%4), %%eax\n"
30137- "41: movl 20(%4), %%edx\n"
30138+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30139+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30140 " movl %%eax, 16(%3)\n"
30141 " movl %%edx, 20(%3)\n"
30142- "10: movl 24(%4), %%eax\n"
30143- "51: movl 28(%4), %%edx\n"
30144+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30145+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30146 " movl %%eax, 24(%3)\n"
30147 " movl %%edx, 28(%3)\n"
30148- "11: movl 32(%4), %%eax\n"
30149- "61: movl 36(%4), %%edx\n"
30150+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30151+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30152 " movl %%eax, 32(%3)\n"
30153 " movl %%edx, 36(%3)\n"
30154- "12: movl 40(%4), %%eax\n"
30155- "71: movl 44(%4), %%edx\n"
30156+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30157+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30158 " movl %%eax, 40(%3)\n"
30159 " movl %%edx, 44(%3)\n"
30160- "13: movl 48(%4), %%eax\n"
30161- "81: movl 52(%4), %%edx\n"
30162+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30163+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30164 " movl %%eax, 48(%3)\n"
30165 " movl %%edx, 52(%3)\n"
30166- "14: movl 56(%4), %%eax\n"
30167- "91: movl 60(%4), %%edx\n"
30168+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30169+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30170 " movl %%eax, 56(%3)\n"
30171 " movl %%edx, 60(%3)\n"
30172 " addl $-64, %0\n"
30173@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30174 " shrl $2, %0\n"
30175 " andl $3, %%eax\n"
30176 " cld\n"
30177- "6: rep; movsl\n"
30178+ "6: rep; "__copyuser_seg" movsl\n"
30179 " movl %%eax,%0\n"
30180- "7: rep; movsb\n"
30181+ "7: rep; "__copyuser_seg" movsb\n"
30182 "8:\n"
30183 ".section .fixup,\"ax\"\n"
30184 "9: lea 0(%%eax,%0,4),%0\n"
30185@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30186
30187 __asm__ __volatile__(
30188 " .align 2,0x90\n"
30189- "0: movl 32(%4), %%eax\n"
30190+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30191 " cmpl $67, %0\n"
30192 " jbe 2f\n"
30193- "1: movl 64(%4), %%eax\n"
30194+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30195 " .align 2,0x90\n"
30196- "2: movl 0(%4), %%eax\n"
30197- "21: movl 4(%4), %%edx\n"
30198+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30199+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30200 " movnti %%eax, 0(%3)\n"
30201 " movnti %%edx, 4(%3)\n"
30202- "3: movl 8(%4), %%eax\n"
30203- "31: movl 12(%4),%%edx\n"
30204+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30205+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30206 " movnti %%eax, 8(%3)\n"
30207 " movnti %%edx, 12(%3)\n"
30208- "4: movl 16(%4), %%eax\n"
30209- "41: movl 20(%4), %%edx\n"
30210+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30211+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30212 " movnti %%eax, 16(%3)\n"
30213 " movnti %%edx, 20(%3)\n"
30214- "10: movl 24(%4), %%eax\n"
30215- "51: movl 28(%4), %%edx\n"
30216+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30217+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30218 " movnti %%eax, 24(%3)\n"
30219 " movnti %%edx, 28(%3)\n"
30220- "11: movl 32(%4), %%eax\n"
30221- "61: movl 36(%4), %%edx\n"
30222+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30223+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30224 " movnti %%eax, 32(%3)\n"
30225 " movnti %%edx, 36(%3)\n"
30226- "12: movl 40(%4), %%eax\n"
30227- "71: movl 44(%4), %%edx\n"
30228+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30229+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30230 " movnti %%eax, 40(%3)\n"
30231 " movnti %%edx, 44(%3)\n"
30232- "13: movl 48(%4), %%eax\n"
30233- "81: movl 52(%4), %%edx\n"
30234+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30235+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30236 " movnti %%eax, 48(%3)\n"
30237 " movnti %%edx, 52(%3)\n"
30238- "14: movl 56(%4), %%eax\n"
30239- "91: movl 60(%4), %%edx\n"
30240+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30241+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30242 " movnti %%eax, 56(%3)\n"
30243 " movnti %%edx, 60(%3)\n"
30244 " addl $-64, %0\n"
30245@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30246 " shrl $2, %0\n"
30247 " andl $3, %%eax\n"
30248 " cld\n"
30249- "6: rep; movsl\n"
30250+ "6: rep; "__copyuser_seg" movsl\n"
30251 " movl %%eax,%0\n"
30252- "7: rep; movsb\n"
30253+ "7: rep; "__copyuser_seg" movsb\n"
30254 "8:\n"
30255 ".section .fixup,\"ax\"\n"
30256 "9: lea 0(%%eax,%0,4),%0\n"
30257@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30258
30259 __asm__ __volatile__(
30260 " .align 2,0x90\n"
30261- "0: movl 32(%4), %%eax\n"
30262+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30263 " cmpl $67, %0\n"
30264 " jbe 2f\n"
30265- "1: movl 64(%4), %%eax\n"
30266+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30267 " .align 2,0x90\n"
30268- "2: movl 0(%4), %%eax\n"
30269- "21: movl 4(%4), %%edx\n"
30270+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30271+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30272 " movnti %%eax, 0(%3)\n"
30273 " movnti %%edx, 4(%3)\n"
30274- "3: movl 8(%4), %%eax\n"
30275- "31: movl 12(%4),%%edx\n"
30276+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30277+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30278 " movnti %%eax, 8(%3)\n"
30279 " movnti %%edx, 12(%3)\n"
30280- "4: movl 16(%4), %%eax\n"
30281- "41: movl 20(%4), %%edx\n"
30282+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30283+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30284 " movnti %%eax, 16(%3)\n"
30285 " movnti %%edx, 20(%3)\n"
30286- "10: movl 24(%4), %%eax\n"
30287- "51: movl 28(%4), %%edx\n"
30288+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30289+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30290 " movnti %%eax, 24(%3)\n"
30291 " movnti %%edx, 28(%3)\n"
30292- "11: movl 32(%4), %%eax\n"
30293- "61: movl 36(%4), %%edx\n"
30294+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30295+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30296 " movnti %%eax, 32(%3)\n"
30297 " movnti %%edx, 36(%3)\n"
30298- "12: movl 40(%4), %%eax\n"
30299- "71: movl 44(%4), %%edx\n"
30300+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30301+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30302 " movnti %%eax, 40(%3)\n"
30303 " movnti %%edx, 44(%3)\n"
30304- "13: movl 48(%4), %%eax\n"
30305- "81: movl 52(%4), %%edx\n"
30306+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30307+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30308 " movnti %%eax, 48(%3)\n"
30309 " movnti %%edx, 52(%3)\n"
30310- "14: movl 56(%4), %%eax\n"
30311- "91: movl 60(%4), %%edx\n"
30312+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30313+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30314 " movnti %%eax, 56(%3)\n"
30315 " movnti %%edx, 60(%3)\n"
30316 " addl $-64, %0\n"
30317@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30318 " shrl $2, %0\n"
30319 " andl $3, %%eax\n"
30320 " cld\n"
30321- "6: rep; movsl\n"
30322+ "6: rep; "__copyuser_seg" movsl\n"
30323 " movl %%eax,%0\n"
30324- "7: rep; movsb\n"
30325+ "7: rep; "__copyuser_seg" movsb\n"
30326 "8:\n"
30327 ".section .fixup,\"ax\"\n"
30328 "9: lea 0(%%eax,%0,4),%0\n"
30329@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30330 */
30331 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30332 unsigned long size);
30333-unsigned long __copy_user_intel(void __user *to, const void *from,
30334+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30335+ unsigned long size);
30336+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30337 unsigned long size);
30338 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30339 const void __user *from, unsigned long size);
30340 #endif /* CONFIG_X86_INTEL_USERCOPY */
30341
30342 /* Generic arbitrary sized copy. */
30343-#define __copy_user(to, from, size) \
30344+#define __copy_user(to, from, size, prefix, set, restore) \
30345 do { \
30346 int __d0, __d1, __d2; \
30347 __asm__ __volatile__( \
30348+ set \
30349 " cmp $7,%0\n" \
30350 " jbe 1f\n" \
30351 " movl %1,%0\n" \
30352 " negl %0\n" \
30353 " andl $7,%0\n" \
30354 " subl %0,%3\n" \
30355- "4: rep; movsb\n" \
30356+ "4: rep; "prefix"movsb\n" \
30357 " movl %3,%0\n" \
30358 " shrl $2,%0\n" \
30359 " andl $3,%3\n" \
30360 " .align 2,0x90\n" \
30361- "0: rep; movsl\n" \
30362+ "0: rep; "prefix"movsl\n" \
30363 " movl %3,%0\n" \
30364- "1: rep; movsb\n" \
30365+ "1: rep; "prefix"movsb\n" \
30366 "2:\n" \
30367+ restore \
30368 ".section .fixup,\"ax\"\n" \
30369 "5: addl %3,%0\n" \
30370 " jmp 2b\n" \
30371@@ -538,14 +650,14 @@ do { \
30372 " negl %0\n" \
30373 " andl $7,%0\n" \
30374 " subl %0,%3\n" \
30375- "4: rep; movsb\n" \
30376+ "4: rep; "__copyuser_seg"movsb\n" \
30377 " movl %3,%0\n" \
30378 " shrl $2,%0\n" \
30379 " andl $3,%3\n" \
30380 " .align 2,0x90\n" \
30381- "0: rep; movsl\n" \
30382+ "0: rep; "__copyuser_seg"movsl\n" \
30383 " movl %3,%0\n" \
30384- "1: rep; movsb\n" \
30385+ "1: rep; "__copyuser_seg"movsb\n" \
30386 "2:\n" \
30387 ".section .fixup,\"ax\"\n" \
30388 "5: addl %3,%0\n" \
30389@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30390 {
30391 stac();
30392 if (movsl_is_ok(to, from, n))
30393- __copy_user(to, from, n);
30394+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30395 else
30396- n = __copy_user_intel(to, from, n);
30397+ n = __generic_copy_to_user_intel(to, from, n);
30398 clac();
30399 return n;
30400 }
30401@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30402 {
30403 stac();
30404 if (movsl_is_ok(to, from, n))
30405- __copy_user(to, from, n);
30406+ __copy_user(to, from, n, __copyuser_seg, "", "");
30407 else
30408- n = __copy_user_intel((void __user *)to,
30409- (const void *)from, n);
30410+ n = __generic_copy_from_user_intel(to, from, n);
30411 clac();
30412 return n;
30413 }
30414@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30415 if (n > 64 && cpu_has_xmm2)
30416 n = __copy_user_intel_nocache(to, from, n);
30417 else
30418- __copy_user(to, from, n);
30419+ __copy_user(to, from, n, __copyuser_seg, "", "");
30420 #else
30421- __copy_user(to, from, n);
30422+ __copy_user(to, from, n, __copyuser_seg, "", "");
30423 #endif
30424 clac();
30425 return n;
30426 }
30427 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30428
30429-/**
30430- * copy_to_user: - Copy a block of data into user space.
30431- * @to: Destination address, in user space.
30432- * @from: Source address, in kernel space.
30433- * @n: Number of bytes to copy.
30434- *
30435- * Context: User context only. This function may sleep.
30436- *
30437- * Copy data from kernel space to user space.
30438- *
30439- * Returns number of bytes that could not be copied.
30440- * On success, this will be zero.
30441- */
30442-unsigned long
30443-copy_to_user(void __user *to, const void *from, unsigned long n)
30444+#ifdef CONFIG_PAX_MEMORY_UDEREF
30445+void __set_fs(mm_segment_t x)
30446 {
30447- if (access_ok(VERIFY_WRITE, to, n))
30448- n = __copy_to_user(to, from, n);
30449- return n;
30450+ switch (x.seg) {
30451+ case 0:
30452+ loadsegment(gs, 0);
30453+ break;
30454+ case TASK_SIZE_MAX:
30455+ loadsegment(gs, __USER_DS);
30456+ break;
30457+ case -1UL:
30458+ loadsegment(gs, __KERNEL_DS);
30459+ break;
30460+ default:
30461+ BUG();
30462+ }
30463 }
30464-EXPORT_SYMBOL(copy_to_user);
30465+EXPORT_SYMBOL(__set_fs);
30466
30467-/**
30468- * copy_from_user: - Copy a block of data from user space.
30469- * @to: Destination address, in kernel space.
30470- * @from: Source address, in user space.
30471- * @n: Number of bytes to copy.
30472- *
30473- * Context: User context only. This function may sleep.
30474- *
30475- * Copy data from user space to kernel space.
30476- *
30477- * Returns number of bytes that could not be copied.
30478- * On success, this will be zero.
30479- *
30480- * If some data could not be copied, this function will pad the copied
30481- * data to the requested size using zero bytes.
30482- */
30483-unsigned long
30484-_copy_from_user(void *to, const void __user *from, unsigned long n)
30485+void set_fs(mm_segment_t x)
30486 {
30487- if (access_ok(VERIFY_READ, from, n))
30488- n = __copy_from_user(to, from, n);
30489- else
30490- memset(to, 0, n);
30491- return n;
30492+ current_thread_info()->addr_limit = x;
30493+ __set_fs(x);
30494 }
30495-EXPORT_SYMBOL(_copy_from_user);
30496+EXPORT_SYMBOL(set_fs);
30497+#endif
30498diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30499index c905e89..01ab928 100644
30500--- a/arch/x86/lib/usercopy_64.c
30501+++ b/arch/x86/lib/usercopy_64.c
30502@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30503 might_fault();
30504 /* no memory constraint because it doesn't change any memory gcc knows
30505 about */
30506+ pax_open_userland();
30507 stac();
30508 asm volatile(
30509 " testq %[size8],%[size8]\n"
30510@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30511 _ASM_EXTABLE(0b,3b)
30512 _ASM_EXTABLE(1b,2b)
30513 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30514- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30515+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30516 [zero] "r" (0UL), [eight] "r" (8UL));
30517 clac();
30518+ pax_close_userland();
30519 return size;
30520 }
30521 EXPORT_SYMBOL(__clear_user);
30522@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30523 }
30524 EXPORT_SYMBOL(clear_user);
30525
30526-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30527+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30528 {
30529- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30530- return copy_user_generic((__force void *)to, (__force void *)from, len);
30531- }
30532- return len;
30533+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30534+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30535+ return len;
30536 }
30537 EXPORT_SYMBOL(copy_in_user);
30538
30539@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30540 * it is not necessary to optimize tail handling.
30541 */
30542 __visible unsigned long
30543-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30544+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30545 {
30546 char c;
30547 unsigned zero_len;
30548
30549+ clac();
30550+ pax_close_userland();
30551 for (; len; --len, to++) {
30552 if (__get_user_nocheck(c, from++, sizeof(char)))
30553 break;
30554@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30555 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30556 if (__put_user_nocheck(c, to++, sizeof(char)))
30557 break;
30558- clac();
30559 return len;
30560 }
30561diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30562index 23d8e5f..9ccc13a 100644
30563--- a/arch/x86/mm/Makefile
30564+++ b/arch/x86/mm/Makefile
30565@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30566 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30567
30568 obj-$(CONFIG_MEMTEST) += memtest.o
30569+
30570+quote:="
30571+obj-$(CONFIG_X86_64) += uderef_64.o
30572+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30573diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30574index 903ec1e..c4166b2 100644
30575--- a/arch/x86/mm/extable.c
30576+++ b/arch/x86/mm/extable.c
30577@@ -6,12 +6,24 @@
30578 static inline unsigned long
30579 ex_insn_addr(const struct exception_table_entry *x)
30580 {
30581- return (unsigned long)&x->insn + x->insn;
30582+ unsigned long reloc = 0;
30583+
30584+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30585+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30586+#endif
30587+
30588+ return (unsigned long)&x->insn + x->insn + reloc;
30589 }
30590 static inline unsigned long
30591 ex_fixup_addr(const struct exception_table_entry *x)
30592 {
30593- return (unsigned long)&x->fixup + x->fixup;
30594+ unsigned long reloc = 0;
30595+
30596+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30597+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30598+#endif
30599+
30600+ return (unsigned long)&x->fixup + x->fixup + reloc;
30601 }
30602
30603 int fixup_exception(struct pt_regs *regs)
30604@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30605 unsigned long new_ip;
30606
30607 #ifdef CONFIG_PNPBIOS
30608- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30609+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30610 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30611 extern u32 pnp_bios_is_utter_crap;
30612 pnp_bios_is_utter_crap = 1;
30613@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30614 i += 4;
30615 p->fixup -= i;
30616 i += 4;
30617+
30618+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30619+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30620+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30621+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30622+#endif
30623+
30624 }
30625 }
30626
30627diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30628index 3aaeffc..42ea9fb 100644
30629--- a/arch/x86/mm/fault.c
30630+++ b/arch/x86/mm/fault.c
30631@@ -14,11 +14,18 @@
30632 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30633 #include <linux/prefetch.h> /* prefetchw */
30634 #include <linux/context_tracking.h> /* exception_enter(), ... */
30635+#include <linux/unistd.h>
30636+#include <linux/compiler.h>
30637
30638 #include <asm/traps.h> /* dotraplinkage, ... */
30639 #include <asm/pgalloc.h> /* pgd_*(), ... */
30640 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30641 #include <asm/fixmap.h> /* VSYSCALL_START */
30642+#include <asm/tlbflush.h>
30643+
30644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30645+#include <asm/stacktrace.h>
30646+#endif
30647
30648 /*
30649 * Page fault error code bits:
30650@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
30651 int ret = 0;
30652
30653 /* kprobe_running() needs smp_processor_id() */
30654- if (kprobes_built_in() && !user_mode_vm(regs)) {
30655+ if (kprobes_built_in() && !user_mode(regs)) {
30656 preempt_disable();
30657 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30658 ret = 1;
30659@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30660 return !instr_lo || (instr_lo>>1) == 1;
30661 case 0x00:
30662 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30663- if (probe_kernel_address(instr, opcode))
30664+ if (user_mode(regs)) {
30665+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30666+ return 0;
30667+ } else if (probe_kernel_address(instr, opcode))
30668 return 0;
30669
30670 *prefetch = (instr_lo == 0xF) &&
30671@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30672 while (instr < max_instr) {
30673 unsigned char opcode;
30674
30675- if (probe_kernel_address(instr, opcode))
30676+ if (user_mode(regs)) {
30677+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30678+ break;
30679+ } else if (probe_kernel_address(instr, opcode))
30680 break;
30681
30682 instr++;
30683@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30684 force_sig_info(si_signo, &info, tsk);
30685 }
30686
30687+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30688+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30689+#endif
30690+
30691+#ifdef CONFIG_PAX_EMUTRAMP
30692+static int pax_handle_fetch_fault(struct pt_regs *regs);
30693+#endif
30694+
30695+#ifdef CONFIG_PAX_PAGEEXEC
30696+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30697+{
30698+ pgd_t *pgd;
30699+ pud_t *pud;
30700+ pmd_t *pmd;
30701+
30702+ pgd = pgd_offset(mm, address);
30703+ if (!pgd_present(*pgd))
30704+ return NULL;
30705+ pud = pud_offset(pgd, address);
30706+ if (!pud_present(*pud))
30707+ return NULL;
30708+ pmd = pmd_offset(pud, address);
30709+ if (!pmd_present(*pmd))
30710+ return NULL;
30711+ return pmd;
30712+}
30713+#endif
30714+
30715 DEFINE_SPINLOCK(pgd_lock);
30716 LIST_HEAD(pgd_list);
30717
30718@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30719 for (address = VMALLOC_START & PMD_MASK;
30720 address >= TASK_SIZE && address < FIXADDR_TOP;
30721 address += PMD_SIZE) {
30722+
30723+#ifdef CONFIG_PAX_PER_CPU_PGD
30724+ unsigned long cpu;
30725+#else
30726 struct page *page;
30727+#endif
30728
30729 spin_lock(&pgd_lock);
30730+
30731+#ifdef CONFIG_PAX_PER_CPU_PGD
30732+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30733+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30734+ pmd_t *ret;
30735+
30736+ ret = vmalloc_sync_one(pgd, address);
30737+ if (!ret)
30738+ break;
30739+ pgd = get_cpu_pgd(cpu, kernel);
30740+#else
30741 list_for_each_entry(page, &pgd_list, lru) {
30742+ pgd_t *pgd;
30743 spinlock_t *pgt_lock;
30744 pmd_t *ret;
30745
30746@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30747 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30748
30749 spin_lock(pgt_lock);
30750- ret = vmalloc_sync_one(page_address(page), address);
30751+ pgd = page_address(page);
30752+#endif
30753+
30754+ ret = vmalloc_sync_one(pgd, address);
30755+
30756+#ifndef CONFIG_PAX_PER_CPU_PGD
30757 spin_unlock(pgt_lock);
30758+#endif
30759
30760 if (!ret)
30761 break;
30762@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30763 * an interrupt in the middle of a task switch..
30764 */
30765 pgd_paddr = read_cr3();
30766+
30767+#ifdef CONFIG_PAX_PER_CPU_PGD
30768+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30769+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30770+#endif
30771+
30772 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30773 if (!pmd_k)
30774 return -1;
30775@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30776 * happen within a race in page table update. In the later
30777 * case just flush:
30778 */
30779- pgd = pgd_offset(current->active_mm, address);
30780+
30781 pgd_ref = pgd_offset_k(address);
30782 if (pgd_none(*pgd_ref))
30783 return -1;
30784
30785+#ifdef CONFIG_PAX_PER_CPU_PGD
30786+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30787+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30788+ if (pgd_none(*pgd)) {
30789+ set_pgd(pgd, *pgd_ref);
30790+ arch_flush_lazy_mmu_mode();
30791+ } else {
30792+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30793+ }
30794+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30795+#else
30796+ pgd = pgd_offset(current->active_mm, address);
30797+#endif
30798+
30799 if (pgd_none(*pgd)) {
30800 set_pgd(pgd, *pgd_ref);
30801 arch_flush_lazy_mmu_mode();
30802@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30803 static int is_errata100(struct pt_regs *regs, unsigned long address)
30804 {
30805 #ifdef CONFIG_X86_64
30806- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30807+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30808 return 1;
30809 #endif
30810 return 0;
30811@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30812 }
30813
30814 static const char nx_warning[] = KERN_CRIT
30815-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30816+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30817
30818 static void
30819 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30820@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30821 if (!oops_may_print())
30822 return;
30823
30824- if (error_code & PF_INSTR) {
30825+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30826 unsigned int level;
30827
30828 pte_t *pte = lookup_address(address, &level);
30829
30830 if (pte && pte_present(*pte) && !pte_exec(*pte))
30831- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30832+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30833 }
30834
30835+#ifdef CONFIG_PAX_KERNEXEC
30836+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30837+ if (current->signal->curr_ip)
30838+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30839+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30840+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30841+ else
30842+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30843+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30844+ }
30845+#endif
30846+
30847 printk(KERN_ALERT "BUG: unable to handle kernel ");
30848 if (address < PAGE_SIZE)
30849 printk(KERN_CONT "NULL pointer dereference");
30850@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30851 return;
30852 }
30853 #endif
30854+
30855+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30856+ if (pax_is_fetch_fault(regs, error_code, address)) {
30857+
30858+#ifdef CONFIG_PAX_EMUTRAMP
30859+ switch (pax_handle_fetch_fault(regs)) {
30860+ case 2:
30861+ return;
30862+ }
30863+#endif
30864+
30865+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30866+ do_group_exit(SIGKILL);
30867+ }
30868+#endif
30869+
30870 /* Kernel addresses are always protection faults: */
30871 if (address >= TASK_SIZE)
30872 error_code |= PF_PROT;
30873@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30874 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30875 printk(KERN_ERR
30876 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30877- tsk->comm, tsk->pid, address);
30878+ tsk->comm, task_pid_nr(tsk), address);
30879 code = BUS_MCEERR_AR;
30880 }
30881 #endif
30882@@ -889,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30883 return 1;
30884 }
30885
30886+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30887+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30888+{
30889+ pte_t *pte;
30890+ pmd_t *pmd;
30891+ spinlock_t *ptl;
30892+ unsigned char pte_mask;
30893+
30894+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30895+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30896+ return 0;
30897+
30898+ /* PaX: it's our fault, let's handle it if we can */
30899+
30900+ /* PaX: take a look at read faults before acquiring any locks */
30901+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30902+ /* instruction fetch attempt from a protected page in user mode */
30903+ up_read(&mm->mmap_sem);
30904+
30905+#ifdef CONFIG_PAX_EMUTRAMP
30906+ switch (pax_handle_fetch_fault(regs)) {
30907+ case 2:
30908+ return 1;
30909+ }
30910+#endif
30911+
30912+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30913+ do_group_exit(SIGKILL);
30914+ }
30915+
30916+ pmd = pax_get_pmd(mm, address);
30917+ if (unlikely(!pmd))
30918+ return 0;
30919+
30920+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30921+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30922+ pte_unmap_unlock(pte, ptl);
30923+ return 0;
30924+ }
30925+
30926+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30927+ /* write attempt to a protected page in user mode */
30928+ pte_unmap_unlock(pte, ptl);
30929+ return 0;
30930+ }
30931+
30932+#ifdef CONFIG_SMP
30933+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30934+#else
30935+ if (likely(address > get_limit(regs->cs)))
30936+#endif
30937+ {
30938+ set_pte(pte, pte_mkread(*pte));
30939+ __flush_tlb_one(address);
30940+ pte_unmap_unlock(pte, ptl);
30941+ up_read(&mm->mmap_sem);
30942+ return 1;
30943+ }
30944+
30945+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30946+
30947+ /*
30948+ * PaX: fill DTLB with user rights and retry
30949+ */
30950+ __asm__ __volatile__ (
30951+ "orb %2,(%1)\n"
30952+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30953+/*
30954+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30955+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30956+ * page fault when examined during a TLB load attempt. this is true not only
30957+ * for PTEs holding a non-present entry but also present entries that will
30958+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30959+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30960+ * for our target pages since their PTEs are simply not in the TLBs at all.
30961+
30962+ * the best thing in omitting it is that we gain around 15-20% speed in the
30963+ * fast path of the page fault handler and can get rid of tracing since we
30964+ * can no longer flush unintended entries.
30965+ */
30966+ "invlpg (%0)\n"
30967+#endif
30968+ __copyuser_seg"testb $0,(%0)\n"
30969+ "xorb %3,(%1)\n"
30970+ :
30971+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30972+ : "memory", "cc");
30973+ pte_unmap_unlock(pte, ptl);
30974+ up_read(&mm->mmap_sem);
30975+ return 1;
30976+}
30977+#endif
30978+
30979 /*
30980 * Handle a spurious fault caused by a stale TLB entry.
30981 *
30982@@ -955,6 +1160,9 @@ int show_unhandled_signals = 1;
30983 static inline int
30984 access_error(unsigned long error_code, struct vm_area_struct *vma)
30985 {
30986+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30987+ return 1;
30988+
30989 if (error_code & PF_WRITE) {
30990 /* write, present and write, not present: */
30991 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30992@@ -983,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30993 if (error_code & PF_USER)
30994 return false;
30995
30996- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30997+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30998 return false;
30999
31000 return true;
31001@@ -1010,6 +1218,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31002 /* Get the faulting address: */
31003 address = read_cr2();
31004
31005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31006+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31007+ if (!search_exception_tables(regs->ip)) {
31008+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31009+ bad_area_nosemaphore(regs, error_code, address);
31010+ return;
31011+ }
31012+ if (address < pax_user_shadow_base) {
31013+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31014+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31015+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31016+ } else
31017+ address -= pax_user_shadow_base;
31018+ }
31019+#endif
31020+
31021 /*
31022 * Detect and handle instructions that would cause a page fault for
31023 * both a tracked kernel page and a userspace page.
31024@@ -1069,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31025 * User-mode registers count as a user access even for any
31026 * potential system fault or CPU buglet:
31027 */
31028- if (user_mode_vm(regs)) {
31029+ if (user_mode(regs)) {
31030 local_irq_enable();
31031 error_code |= PF_USER;
31032 flags |= FAULT_FLAG_USER;
31033@@ -1135,6 +1359,11 @@ retry:
31034 might_sleep();
31035 }
31036
31037+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31038+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31039+ return;
31040+#endif
31041+
31042 vma = find_vma(mm, address);
31043 if (unlikely(!vma)) {
31044 bad_area(regs, error_code, address);
31045@@ -1146,18 +1375,24 @@ retry:
31046 bad_area(regs, error_code, address);
31047 return;
31048 }
31049- if (error_code & PF_USER) {
31050- /*
31051- * Accessing the stack below %sp is always a bug.
31052- * The large cushion allows instructions like enter
31053- * and pusha to work. ("enter $65535, $31" pushes
31054- * 32 pointers and then decrements %sp by 65535.)
31055- */
31056- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31057- bad_area(regs, error_code, address);
31058- return;
31059- }
31060+ /*
31061+ * Accessing the stack below %sp is always a bug.
31062+ * The large cushion allows instructions like enter
31063+ * and pusha to work. ("enter $65535, $31" pushes
31064+ * 32 pointers and then decrements %sp by 65535.)
31065+ */
31066+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31067+ bad_area(regs, error_code, address);
31068+ return;
31069 }
31070+
31071+#ifdef CONFIG_PAX_SEGMEXEC
31072+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31073+ bad_area(regs, error_code, address);
31074+ return;
31075+ }
31076+#endif
31077+
31078 if (unlikely(expand_stack(vma, address))) {
31079 bad_area(regs, error_code, address);
31080 return;
31081@@ -1231,3 +1466,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
31082 __do_page_fault(regs, error_code);
31083 exception_exit(prev_state);
31084 }
31085+
31086+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31087+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31088+{
31089+ struct mm_struct *mm = current->mm;
31090+ unsigned long ip = regs->ip;
31091+
31092+ if (v8086_mode(regs))
31093+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31094+
31095+#ifdef CONFIG_PAX_PAGEEXEC
31096+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31097+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31098+ return true;
31099+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31100+ return true;
31101+ return false;
31102+ }
31103+#endif
31104+
31105+#ifdef CONFIG_PAX_SEGMEXEC
31106+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31107+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31108+ return true;
31109+ return false;
31110+ }
31111+#endif
31112+
31113+ return false;
31114+}
31115+#endif
31116+
31117+#ifdef CONFIG_PAX_EMUTRAMP
31118+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31119+{
31120+ int err;
31121+
31122+ do { /* PaX: libffi trampoline emulation */
31123+ unsigned char mov, jmp;
31124+ unsigned int addr1, addr2;
31125+
31126+#ifdef CONFIG_X86_64
31127+ if ((regs->ip + 9) >> 32)
31128+ break;
31129+#endif
31130+
31131+ err = get_user(mov, (unsigned char __user *)regs->ip);
31132+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31133+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31134+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31135+
31136+ if (err)
31137+ break;
31138+
31139+ if (mov == 0xB8 && jmp == 0xE9) {
31140+ regs->ax = addr1;
31141+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31142+ return 2;
31143+ }
31144+ } while (0);
31145+
31146+ do { /* PaX: gcc trampoline emulation #1 */
31147+ unsigned char mov1, mov2;
31148+ unsigned short jmp;
31149+ unsigned int addr1, addr2;
31150+
31151+#ifdef CONFIG_X86_64
31152+ if ((regs->ip + 11) >> 32)
31153+ break;
31154+#endif
31155+
31156+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31157+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31158+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31159+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31160+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31161+
31162+ if (err)
31163+ break;
31164+
31165+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31166+ regs->cx = addr1;
31167+ regs->ax = addr2;
31168+ regs->ip = addr2;
31169+ return 2;
31170+ }
31171+ } while (0);
31172+
31173+ do { /* PaX: gcc trampoline emulation #2 */
31174+ unsigned char mov, jmp;
31175+ unsigned int addr1, addr2;
31176+
31177+#ifdef CONFIG_X86_64
31178+ if ((regs->ip + 9) >> 32)
31179+ break;
31180+#endif
31181+
31182+ err = get_user(mov, (unsigned char __user *)regs->ip);
31183+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31184+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31185+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31186+
31187+ if (err)
31188+ break;
31189+
31190+ if (mov == 0xB9 && jmp == 0xE9) {
31191+ regs->cx = addr1;
31192+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31193+ return 2;
31194+ }
31195+ } while (0);
31196+
31197+ return 1; /* PaX in action */
31198+}
31199+
31200+#ifdef CONFIG_X86_64
31201+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31202+{
31203+ int err;
31204+
31205+ do { /* PaX: libffi trampoline emulation */
31206+ unsigned short mov1, mov2, jmp1;
31207+ unsigned char stcclc, jmp2;
31208+ unsigned long addr1, addr2;
31209+
31210+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31211+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31212+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31213+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31214+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31215+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31216+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31217+
31218+ if (err)
31219+ break;
31220+
31221+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31222+ regs->r11 = addr1;
31223+ regs->r10 = addr2;
31224+ if (stcclc == 0xF8)
31225+ regs->flags &= ~X86_EFLAGS_CF;
31226+ else
31227+ regs->flags |= X86_EFLAGS_CF;
31228+ regs->ip = addr1;
31229+ return 2;
31230+ }
31231+ } while (0);
31232+
31233+ do { /* PaX: gcc trampoline emulation #1 */
31234+ unsigned short mov1, mov2, jmp1;
31235+ unsigned char jmp2;
31236+ unsigned int addr1;
31237+ unsigned long addr2;
31238+
31239+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31240+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31241+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31242+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31243+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31244+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31245+
31246+ if (err)
31247+ break;
31248+
31249+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31250+ regs->r11 = addr1;
31251+ regs->r10 = addr2;
31252+ regs->ip = addr1;
31253+ return 2;
31254+ }
31255+ } while (0);
31256+
31257+ do { /* PaX: gcc trampoline emulation #2 */
31258+ unsigned short mov1, mov2, jmp1;
31259+ unsigned char jmp2;
31260+ unsigned long addr1, addr2;
31261+
31262+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31263+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31264+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31265+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31266+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31267+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31268+
31269+ if (err)
31270+ break;
31271+
31272+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31273+ regs->r11 = addr1;
31274+ regs->r10 = addr2;
31275+ regs->ip = addr1;
31276+ return 2;
31277+ }
31278+ } while (0);
31279+
31280+ return 1; /* PaX in action */
31281+}
31282+#endif
31283+
31284+/*
31285+ * PaX: decide what to do with offenders (regs->ip = fault address)
31286+ *
31287+ * returns 1 when task should be killed
31288+ * 2 when gcc trampoline was detected
31289+ */
31290+static int pax_handle_fetch_fault(struct pt_regs *regs)
31291+{
31292+ if (v8086_mode(regs))
31293+ return 1;
31294+
31295+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31296+ return 1;
31297+
31298+#ifdef CONFIG_X86_32
31299+ return pax_handle_fetch_fault_32(regs);
31300+#else
31301+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31302+ return pax_handle_fetch_fault_32(regs);
31303+ else
31304+ return pax_handle_fetch_fault_64(regs);
31305+#endif
31306+}
31307+#endif
31308+
31309+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31310+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31311+{
31312+ long i;
31313+
31314+ printk(KERN_ERR "PAX: bytes at PC: ");
31315+ for (i = 0; i < 20; i++) {
31316+ unsigned char c;
31317+ if (get_user(c, (unsigned char __force_user *)pc+i))
31318+ printk(KERN_CONT "?? ");
31319+ else
31320+ printk(KERN_CONT "%02x ", c);
31321+ }
31322+ printk("\n");
31323+
31324+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31325+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31326+ unsigned long c;
31327+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31328+#ifdef CONFIG_X86_32
31329+ printk(KERN_CONT "???????? ");
31330+#else
31331+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31332+ printk(KERN_CONT "???????? ???????? ");
31333+ else
31334+ printk(KERN_CONT "???????????????? ");
31335+#endif
31336+ } else {
31337+#ifdef CONFIG_X86_64
31338+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31339+ printk(KERN_CONT "%08x ", (unsigned int)c);
31340+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31341+ } else
31342+#endif
31343+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31344+ }
31345+ }
31346+ printk("\n");
31347+}
31348+#endif
31349+
31350+/**
31351+ * probe_kernel_write(): safely attempt to write to a location
31352+ * @dst: address to write to
31353+ * @src: pointer to the data that shall be written
31354+ * @size: size of the data chunk
31355+ *
31356+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31357+ * happens, handle that and return -EFAULT.
31358+ */
31359+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31360+{
31361+ long ret;
31362+ mm_segment_t old_fs = get_fs();
31363+
31364+ set_fs(KERNEL_DS);
31365+ pagefault_disable();
31366+ pax_open_kernel();
31367+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31368+ pax_close_kernel();
31369+ pagefault_enable();
31370+ set_fs(old_fs);
31371+
31372+ return ret ? -EFAULT : 0;
31373+}
31374diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31375index dd74e46..0970b01 100644
31376--- a/arch/x86/mm/gup.c
31377+++ b/arch/x86/mm/gup.c
31378@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31379 addr = start;
31380 len = (unsigned long) nr_pages << PAGE_SHIFT;
31381 end = start + len;
31382- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31383+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31384 (void __user *)start, len)))
31385 return 0;
31386
31387@@ -331,6 +331,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31388 goto slow_irqon;
31389 #endif
31390
31391+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31392+ (void __user *)start, len)))
31393+ return 0;
31394+
31395 /*
31396 * XXX: batch / limit 'nr', to avoid large irq off latency
31397 * needs some instrumenting to determine the common sizes used by
31398diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31399index 4500142..53a363c 100644
31400--- a/arch/x86/mm/highmem_32.c
31401+++ b/arch/x86/mm/highmem_32.c
31402@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31403 idx = type + KM_TYPE_NR*smp_processor_id();
31404 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31405 BUG_ON(!pte_none(*(kmap_pte-idx)));
31406+
31407+ pax_open_kernel();
31408 set_pte(kmap_pte-idx, mk_pte(page, prot));
31409+ pax_close_kernel();
31410+
31411 arch_flush_lazy_mmu_mode();
31412
31413 return (void *)vaddr;
31414diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31415index 9d980d8..6bbfacb 100644
31416--- a/arch/x86/mm/hugetlbpage.c
31417+++ b/arch/x86/mm/hugetlbpage.c
31418@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31419 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31420 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31421 unsigned long addr, unsigned long len,
31422- unsigned long pgoff, unsigned long flags)
31423+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31424 {
31425 struct hstate *h = hstate_file(file);
31426 struct vm_unmapped_area_info info;
31427-
31428+
31429 info.flags = 0;
31430 info.length = len;
31431 info.low_limit = TASK_UNMAPPED_BASE;
31432+
31433+#ifdef CONFIG_PAX_RANDMMAP
31434+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31435+ info.low_limit += current->mm->delta_mmap;
31436+#endif
31437+
31438 info.high_limit = TASK_SIZE;
31439 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31440 info.align_offset = 0;
31441+ info.threadstack_offset = offset;
31442 return vm_unmapped_area(&info);
31443 }
31444
31445 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31446 unsigned long addr0, unsigned long len,
31447- unsigned long pgoff, unsigned long flags)
31448+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31449 {
31450 struct hstate *h = hstate_file(file);
31451 struct vm_unmapped_area_info info;
31452@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31453 info.high_limit = current->mm->mmap_base;
31454 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31455 info.align_offset = 0;
31456+ info.threadstack_offset = offset;
31457 addr = vm_unmapped_area(&info);
31458
31459 /*
31460@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31461 VM_BUG_ON(addr != -ENOMEM);
31462 info.flags = 0;
31463 info.low_limit = TASK_UNMAPPED_BASE;
31464+
31465+#ifdef CONFIG_PAX_RANDMMAP
31466+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31467+ info.low_limit += current->mm->delta_mmap;
31468+#endif
31469+
31470 info.high_limit = TASK_SIZE;
31471 addr = vm_unmapped_area(&info);
31472 }
31473@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31474 struct hstate *h = hstate_file(file);
31475 struct mm_struct *mm = current->mm;
31476 struct vm_area_struct *vma;
31477+ unsigned long pax_task_size = TASK_SIZE;
31478+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31479
31480 if (len & ~huge_page_mask(h))
31481 return -EINVAL;
31482- if (len > TASK_SIZE)
31483+
31484+#ifdef CONFIG_PAX_SEGMEXEC
31485+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31486+ pax_task_size = SEGMEXEC_TASK_SIZE;
31487+#endif
31488+
31489+ pax_task_size -= PAGE_SIZE;
31490+
31491+ if (len > pax_task_size)
31492 return -ENOMEM;
31493
31494 if (flags & MAP_FIXED) {
31495@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31496 return addr;
31497 }
31498
31499+#ifdef CONFIG_PAX_RANDMMAP
31500+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31501+#endif
31502+
31503 if (addr) {
31504 addr = ALIGN(addr, huge_page_size(h));
31505 vma = find_vma(mm, addr);
31506- if (TASK_SIZE - len >= addr &&
31507- (!vma || addr + len <= vma->vm_start))
31508+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31509 return addr;
31510 }
31511 if (mm->get_unmapped_area == arch_get_unmapped_area)
31512 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31513- pgoff, flags);
31514+ pgoff, flags, offset);
31515 else
31516 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31517- pgoff, flags);
31518+ pgoff, flags, offset);
31519 }
31520
31521 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31522diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31523index 04664cd..dae6e5d 100644
31524--- a/arch/x86/mm/init.c
31525+++ b/arch/x86/mm/init.c
31526@@ -4,6 +4,7 @@
31527 #include <linux/swap.h>
31528 #include <linux/memblock.h>
31529 #include <linux/bootmem.h> /* for max_low_pfn */
31530+#include <linux/tboot.h>
31531
31532 #include <asm/cacheflush.h>
31533 #include <asm/e820.h>
31534@@ -17,6 +18,8 @@
31535 #include <asm/proto.h>
31536 #include <asm/dma.h> /* for MAX_DMA_PFN */
31537 #include <asm/microcode.h>
31538+#include <asm/desc.h>
31539+#include <asm/bios_ebda.h>
31540
31541 #include "mm_internal.h"
31542
31543@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
31544 early_ioremap_page_table_range_init();
31545 #endif
31546
31547+#ifdef CONFIG_PAX_PER_CPU_PGD
31548+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31549+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31550+ KERNEL_PGD_PTRS);
31551+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31552+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31553+ KERNEL_PGD_PTRS);
31554+ load_cr3(get_cpu_pgd(0, kernel));
31555+#else
31556 load_cr3(swapper_pg_dir);
31557+#endif
31558+
31559 __flush_tlb_all();
31560
31561 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31562@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
31563 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31564 * mmio resources as well as potential bios/acpi data regions.
31565 */
31566+
31567+#ifdef CONFIG_GRKERNSEC_KMEM
31568+static unsigned int ebda_start __read_only;
31569+static unsigned int ebda_end __read_only;
31570+#endif
31571+
31572 int devmem_is_allowed(unsigned long pagenr)
31573 {
31574- if (pagenr < 256)
31575+#ifdef CONFIG_GRKERNSEC_KMEM
31576+ /* allow BDA */
31577+ if (!pagenr)
31578 return 1;
31579+ /* allow EBDA */
31580+ if (pagenr >= ebda_start && pagenr < ebda_end)
31581+ return 1;
31582+ /* if tboot is in use, allow access to its hardcoded serial log range */
31583+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31584+ return 1;
31585+#else
31586+ if (!pagenr)
31587+ return 1;
31588+#ifdef CONFIG_VM86
31589+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31590+ return 1;
31591+#endif
31592+#endif
31593+
31594+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31595+ return 1;
31596+#ifdef CONFIG_GRKERNSEC_KMEM
31597+ /* throw out everything else below 1MB */
31598+ if (pagenr <= 256)
31599+ return 0;
31600+#endif
31601 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31602 return 0;
31603 if (!page_is_ram(pagenr))
31604@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31605 #endif
31606 }
31607
31608+#ifdef CONFIG_GRKERNSEC_KMEM
31609+static inline void gr_init_ebda(void)
31610+{
31611+ unsigned int ebda_addr;
31612+ unsigned int ebda_size = 0;
31613+
31614+ ebda_addr = get_bios_ebda();
31615+ if (ebda_addr) {
31616+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31617+ ebda_size <<= 10;
31618+ }
31619+ if (ebda_addr && ebda_size) {
31620+ ebda_start = ebda_addr >> PAGE_SHIFT;
31621+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31622+ } else {
31623+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31624+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31625+ }
31626+}
31627+#else
31628+static inline void gr_init_ebda(void) { }
31629+#endif
31630+
31631 void free_initmem(void)
31632 {
31633+#ifdef CONFIG_PAX_KERNEXEC
31634+#ifdef CONFIG_X86_32
31635+ /* PaX: limit KERNEL_CS to actual size */
31636+ unsigned long addr, limit;
31637+ struct desc_struct d;
31638+ int cpu;
31639+#else
31640+ pgd_t *pgd;
31641+ pud_t *pud;
31642+ pmd_t *pmd;
31643+ unsigned long addr, end;
31644+#endif
31645+#endif
31646+
31647+ gr_init_ebda();
31648+
31649+#ifdef CONFIG_PAX_KERNEXEC
31650+#ifdef CONFIG_X86_32
31651+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31652+ limit = (limit - 1UL) >> PAGE_SHIFT;
31653+
31654+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31655+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31656+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31657+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31658+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31659+ }
31660+
31661+ /* PaX: make KERNEL_CS read-only */
31662+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31663+ if (!paravirt_enabled())
31664+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31665+/*
31666+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31667+ pgd = pgd_offset_k(addr);
31668+ pud = pud_offset(pgd, addr);
31669+ pmd = pmd_offset(pud, addr);
31670+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31671+ }
31672+*/
31673+#ifdef CONFIG_X86_PAE
31674+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31675+/*
31676+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31677+ pgd = pgd_offset_k(addr);
31678+ pud = pud_offset(pgd, addr);
31679+ pmd = pmd_offset(pud, addr);
31680+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31681+ }
31682+*/
31683+#endif
31684+
31685+#ifdef CONFIG_MODULES
31686+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31687+#endif
31688+
31689+#else
31690+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31691+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31692+ pgd = pgd_offset_k(addr);
31693+ pud = pud_offset(pgd, addr);
31694+ pmd = pmd_offset(pud, addr);
31695+ if (!pmd_present(*pmd))
31696+ continue;
31697+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31698+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31699+ else
31700+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31701+ }
31702+
31703+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31704+ end = addr + KERNEL_IMAGE_SIZE;
31705+ for (; addr < end; addr += PMD_SIZE) {
31706+ pgd = pgd_offset_k(addr);
31707+ pud = pud_offset(pgd, addr);
31708+ pmd = pmd_offset(pud, addr);
31709+ if (!pmd_present(*pmd))
31710+ continue;
31711+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31712+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31713+ }
31714+#endif
31715+
31716+ flush_tlb_all();
31717+#endif
31718+
31719 free_init_pages("unused kernel",
31720 (unsigned long)(&__init_begin),
31721 (unsigned long)(&__init_end));
31722diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31723index 4287f1f..3b99c71 100644
31724--- a/arch/x86/mm/init_32.c
31725+++ b/arch/x86/mm/init_32.c
31726@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31727 bool __read_mostly __vmalloc_start_set = false;
31728
31729 /*
31730- * Creates a middle page table and puts a pointer to it in the
31731- * given global directory entry. This only returns the gd entry
31732- * in non-PAE compilation mode, since the middle layer is folded.
31733- */
31734-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31735-{
31736- pud_t *pud;
31737- pmd_t *pmd_table;
31738-
31739-#ifdef CONFIG_X86_PAE
31740- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31741- pmd_table = (pmd_t *)alloc_low_page();
31742- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31743- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31744- pud = pud_offset(pgd, 0);
31745- BUG_ON(pmd_table != pmd_offset(pud, 0));
31746-
31747- return pmd_table;
31748- }
31749-#endif
31750- pud = pud_offset(pgd, 0);
31751- pmd_table = pmd_offset(pud, 0);
31752-
31753- return pmd_table;
31754-}
31755-
31756-/*
31757 * Create a page table and place a pointer to it in a middle page
31758 * directory entry:
31759 */
31760@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31761 pte_t *page_table = (pte_t *)alloc_low_page();
31762
31763 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31764+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31765+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31766+#else
31767 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31768+#endif
31769 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31770 }
31771
31772 return pte_offset_kernel(pmd, 0);
31773 }
31774
31775+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31776+{
31777+ pud_t *pud;
31778+ pmd_t *pmd_table;
31779+
31780+ pud = pud_offset(pgd, 0);
31781+ pmd_table = pmd_offset(pud, 0);
31782+
31783+ return pmd_table;
31784+}
31785+
31786 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31787 {
31788 int pgd_idx = pgd_index(vaddr);
31789@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31790 int pgd_idx, pmd_idx;
31791 unsigned long vaddr;
31792 pgd_t *pgd;
31793+ pud_t *pud;
31794 pmd_t *pmd;
31795 pte_t *pte = NULL;
31796 unsigned long count = page_table_range_init_count(start, end);
31797@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31798 pgd = pgd_base + pgd_idx;
31799
31800 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31801- pmd = one_md_table_init(pgd);
31802- pmd = pmd + pmd_index(vaddr);
31803+ pud = pud_offset(pgd, vaddr);
31804+ pmd = pmd_offset(pud, vaddr);
31805+
31806+#ifdef CONFIG_X86_PAE
31807+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31808+#endif
31809+
31810 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31811 pmd++, pmd_idx++) {
31812 pte = page_table_kmap_check(one_page_table_init(pmd),
31813@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31814 }
31815 }
31816
31817-static inline int is_kernel_text(unsigned long addr)
31818+static inline int is_kernel_text(unsigned long start, unsigned long end)
31819 {
31820- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31821- return 1;
31822- return 0;
31823+ if ((start > ktla_ktva((unsigned long)_etext) ||
31824+ end <= ktla_ktva((unsigned long)_stext)) &&
31825+ (start > ktla_ktva((unsigned long)_einittext) ||
31826+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31827+
31828+#ifdef CONFIG_ACPI_SLEEP
31829+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31830+#endif
31831+
31832+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31833+ return 0;
31834+ return 1;
31835 }
31836
31837 /*
31838@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31839 unsigned long last_map_addr = end;
31840 unsigned long start_pfn, end_pfn;
31841 pgd_t *pgd_base = swapper_pg_dir;
31842- int pgd_idx, pmd_idx, pte_ofs;
31843+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31844 unsigned long pfn;
31845 pgd_t *pgd;
31846+ pud_t *pud;
31847 pmd_t *pmd;
31848 pte_t *pte;
31849 unsigned pages_2m, pages_4k;
31850@@ -291,8 +295,13 @@ repeat:
31851 pfn = start_pfn;
31852 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31853 pgd = pgd_base + pgd_idx;
31854- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31855- pmd = one_md_table_init(pgd);
31856+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31857+ pud = pud_offset(pgd, 0);
31858+ pmd = pmd_offset(pud, 0);
31859+
31860+#ifdef CONFIG_X86_PAE
31861+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31862+#endif
31863
31864 if (pfn >= end_pfn)
31865 continue;
31866@@ -304,14 +313,13 @@ repeat:
31867 #endif
31868 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31869 pmd++, pmd_idx++) {
31870- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31871+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31872
31873 /*
31874 * Map with big pages if possible, otherwise
31875 * create normal page tables:
31876 */
31877 if (use_pse) {
31878- unsigned int addr2;
31879 pgprot_t prot = PAGE_KERNEL_LARGE;
31880 /*
31881 * first pass will use the same initial
31882@@ -322,11 +330,7 @@ repeat:
31883 _PAGE_PSE);
31884
31885 pfn &= PMD_MASK >> PAGE_SHIFT;
31886- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31887- PAGE_OFFSET + PAGE_SIZE-1;
31888-
31889- if (is_kernel_text(addr) ||
31890- is_kernel_text(addr2))
31891+ if (is_kernel_text(address, address + PMD_SIZE))
31892 prot = PAGE_KERNEL_LARGE_EXEC;
31893
31894 pages_2m++;
31895@@ -343,7 +347,7 @@ repeat:
31896 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31897 pte += pte_ofs;
31898 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31899- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31900+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31901 pgprot_t prot = PAGE_KERNEL;
31902 /*
31903 * first pass will use the same initial
31904@@ -351,7 +355,7 @@ repeat:
31905 */
31906 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31907
31908- if (is_kernel_text(addr))
31909+ if (is_kernel_text(address, address + PAGE_SIZE))
31910 prot = PAGE_KERNEL_EXEC;
31911
31912 pages_4k++;
31913@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31914
31915 pud = pud_offset(pgd, va);
31916 pmd = pmd_offset(pud, va);
31917- if (!pmd_present(*pmd))
31918+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31919 break;
31920
31921 /* should not be large page here */
31922@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31923
31924 static void __init pagetable_init(void)
31925 {
31926- pgd_t *pgd_base = swapper_pg_dir;
31927-
31928- permanent_kmaps_init(pgd_base);
31929+ permanent_kmaps_init(swapper_pg_dir);
31930 }
31931
31932-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31933+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31934 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31935
31936 /* user-defined highmem size */
31937@@ -787,10 +789,10 @@ void __init mem_init(void)
31938 ((unsigned long)&__init_end -
31939 (unsigned long)&__init_begin) >> 10,
31940
31941- (unsigned long)&_etext, (unsigned long)&_edata,
31942- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31943+ (unsigned long)&_sdata, (unsigned long)&_edata,
31944+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31945
31946- (unsigned long)&_text, (unsigned long)&_etext,
31947+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31948 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31949
31950 /*
31951@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31952 if (!kernel_set_to_readonly)
31953 return;
31954
31955+ start = ktla_ktva(start);
31956 pr_debug("Set kernel text: %lx - %lx for read write\n",
31957 start, start+size);
31958
31959@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31960 if (!kernel_set_to_readonly)
31961 return;
31962
31963+ start = ktla_ktva(start);
31964 pr_debug("Set kernel text: %lx - %lx for read only\n",
31965 start, start+size);
31966
31967@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31968 unsigned long start = PFN_ALIGN(_text);
31969 unsigned long size = PFN_ALIGN(_etext) - start;
31970
31971+ start = ktla_ktva(start);
31972 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31973 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31974 size >> 10);
31975diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31976index 104d56a..62ba13f1 100644
31977--- a/arch/x86/mm/init_64.c
31978+++ b/arch/x86/mm/init_64.c
31979@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31980 * around without checking the pgd every time.
31981 */
31982
31983-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31984+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31985 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31986
31987 int force_personality32;
31988@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31989
31990 for (address = start; address <= end; address += PGDIR_SIZE) {
31991 const pgd_t *pgd_ref = pgd_offset_k(address);
31992+
31993+#ifdef CONFIG_PAX_PER_CPU_PGD
31994+ unsigned long cpu;
31995+#else
31996 struct page *page;
31997+#endif
31998
31999 if (pgd_none(*pgd_ref))
32000 continue;
32001
32002 spin_lock(&pgd_lock);
32003+
32004+#ifdef CONFIG_PAX_PER_CPU_PGD
32005+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32006+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32007+
32008+ if (pgd_none(*pgd))
32009+ set_pgd(pgd, *pgd_ref);
32010+ else
32011+ BUG_ON(pgd_page_vaddr(*pgd)
32012+ != pgd_page_vaddr(*pgd_ref));
32013+ pgd = pgd_offset_cpu(cpu, kernel, address);
32014+#else
32015 list_for_each_entry(page, &pgd_list, lru) {
32016 pgd_t *pgd;
32017 spinlock_t *pgt_lock;
32018@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32019 /* the pgt_lock only for Xen */
32020 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32021 spin_lock(pgt_lock);
32022+#endif
32023
32024 if (pgd_none(*pgd))
32025 set_pgd(pgd, *pgd_ref);
32026@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32027 BUG_ON(pgd_page_vaddr(*pgd)
32028 != pgd_page_vaddr(*pgd_ref));
32029
32030+#ifndef CONFIG_PAX_PER_CPU_PGD
32031 spin_unlock(pgt_lock);
32032+#endif
32033+
32034 }
32035 spin_unlock(&pgd_lock);
32036 }
32037@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32038 {
32039 if (pgd_none(*pgd)) {
32040 pud_t *pud = (pud_t *)spp_getpage();
32041- pgd_populate(&init_mm, pgd, pud);
32042+ pgd_populate_kernel(&init_mm, pgd, pud);
32043 if (pud != pud_offset(pgd, 0))
32044 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32045 pud, pud_offset(pgd, 0));
32046@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32047 {
32048 if (pud_none(*pud)) {
32049 pmd_t *pmd = (pmd_t *) spp_getpage();
32050- pud_populate(&init_mm, pud, pmd);
32051+ pud_populate_kernel(&init_mm, pud, pmd);
32052 if (pmd != pmd_offset(pud, 0))
32053 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32054 pmd, pmd_offset(pud, 0));
32055@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32056 pmd = fill_pmd(pud, vaddr);
32057 pte = fill_pte(pmd, vaddr);
32058
32059+ pax_open_kernel();
32060 set_pte(pte, new_pte);
32061+ pax_close_kernel();
32062
32063 /*
32064 * It's enough to flush this one mapping.
32065@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32066 pgd = pgd_offset_k((unsigned long)__va(phys));
32067 if (pgd_none(*pgd)) {
32068 pud = (pud_t *) spp_getpage();
32069- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32070- _PAGE_USER));
32071+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32072 }
32073 pud = pud_offset(pgd, (unsigned long)__va(phys));
32074 if (pud_none(*pud)) {
32075 pmd = (pmd_t *) spp_getpage();
32076- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32077- _PAGE_USER));
32078+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32079 }
32080 pmd = pmd_offset(pud, phys);
32081 BUG_ON(!pmd_none(*pmd));
32082@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32083 prot);
32084
32085 spin_lock(&init_mm.page_table_lock);
32086- pud_populate(&init_mm, pud, pmd);
32087+ pud_populate_kernel(&init_mm, pud, pmd);
32088 spin_unlock(&init_mm.page_table_lock);
32089 }
32090 __flush_tlb_all();
32091@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32092 page_size_mask);
32093
32094 spin_lock(&init_mm.page_table_lock);
32095- pgd_populate(&init_mm, pgd, pud);
32096+ pgd_populate_kernel(&init_mm, pgd, pud);
32097 spin_unlock(&init_mm.page_table_lock);
32098 pgd_changed = true;
32099 }
32100@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32101 static struct vm_area_struct gate_vma = {
32102 .vm_start = VSYSCALL_START,
32103 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32104- .vm_page_prot = PAGE_READONLY_EXEC,
32105- .vm_flags = VM_READ | VM_EXEC
32106+ .vm_page_prot = PAGE_READONLY,
32107+ .vm_flags = VM_READ
32108 };
32109
32110 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32111@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32112
32113 const char *arch_vma_name(struct vm_area_struct *vma)
32114 {
32115- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32116+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32117 return "[vdso]";
32118 if (vma == &gate_vma)
32119 return "[vsyscall]";
32120diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32121index 7b179b4..6bd17777 100644
32122--- a/arch/x86/mm/iomap_32.c
32123+++ b/arch/x86/mm/iomap_32.c
32124@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32125 type = kmap_atomic_idx_push();
32126 idx = type + KM_TYPE_NR * smp_processor_id();
32127 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32128+
32129+ pax_open_kernel();
32130 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32131+ pax_close_kernel();
32132+
32133 arch_flush_lazy_mmu_mode();
32134
32135 return (void *)vaddr;
32136diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32137index 799580c..72f9fe0 100644
32138--- a/arch/x86/mm/ioremap.c
32139+++ b/arch/x86/mm/ioremap.c
32140@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32141 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32142 int is_ram = page_is_ram(pfn);
32143
32144- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32145+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32146 return NULL;
32147 WARN_ON_ONCE(is_ram);
32148 }
32149@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32150 *
32151 * Caller must ensure there is only one unmapping for the same pointer.
32152 */
32153-void iounmap(volatile void __iomem *addr)
32154+void iounmap(const volatile void __iomem *addr)
32155 {
32156 struct vm_struct *p, *o;
32157
32158@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32159
32160 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32161 if (page_is_ram(start >> PAGE_SHIFT))
32162+#ifdef CONFIG_HIGHMEM
32163+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32164+#endif
32165 return __va(phys);
32166
32167 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32168@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32169 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32170 {
32171 if (page_is_ram(phys >> PAGE_SHIFT))
32172+#ifdef CONFIG_HIGHMEM
32173+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32174+#endif
32175 return;
32176
32177 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32178@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32179 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32180
32181 static __initdata int after_paging_init;
32182-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32183+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32184
32185 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32186 {
32187@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32188 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32189
32190 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32191- memset(bm_pte, 0, sizeof(bm_pte));
32192- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32193+ pmd_populate_user(&init_mm, pmd, bm_pte);
32194
32195 /*
32196 * The boot-ioremap range spans multiple pmds, for which
32197diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32198index d87dd6d..bf3fa66 100644
32199--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32200+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32201@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32202 * memory (e.g. tracked pages)? For now, we need this to avoid
32203 * invoking kmemcheck for PnP BIOS calls.
32204 */
32205- if (regs->flags & X86_VM_MASK)
32206+ if (v8086_mode(regs))
32207 return false;
32208- if (regs->cs != __KERNEL_CS)
32209+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32210 return false;
32211
32212 pte = kmemcheck_pte_lookup(address);
32213diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32214index 25e7e13..1964579 100644
32215--- a/arch/x86/mm/mmap.c
32216+++ b/arch/x86/mm/mmap.c
32217@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32218 * Leave an at least ~128 MB hole with possible stack randomization.
32219 */
32220 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32221-#define MAX_GAP (TASK_SIZE/6*5)
32222+#define MAX_GAP (pax_task_size/6*5)
32223
32224 static int mmap_is_legacy(void)
32225 {
32226@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32227 return rnd << PAGE_SHIFT;
32228 }
32229
32230-static unsigned long mmap_base(void)
32231+static unsigned long mmap_base(struct mm_struct *mm)
32232 {
32233 unsigned long gap = rlimit(RLIMIT_STACK);
32234+ unsigned long pax_task_size = TASK_SIZE;
32235+
32236+#ifdef CONFIG_PAX_SEGMEXEC
32237+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32238+ pax_task_size = SEGMEXEC_TASK_SIZE;
32239+#endif
32240
32241 if (gap < MIN_GAP)
32242 gap = MIN_GAP;
32243 else if (gap > MAX_GAP)
32244 gap = MAX_GAP;
32245
32246- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32247+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32248 }
32249
32250 /*
32251 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32252 * does, but not when emulating X86_32
32253 */
32254-static unsigned long mmap_legacy_base(void)
32255+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32256 {
32257- if (mmap_is_ia32())
32258+ if (mmap_is_ia32()) {
32259+
32260+#ifdef CONFIG_PAX_SEGMEXEC
32261+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32262+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32263+ else
32264+#endif
32265+
32266 return TASK_UNMAPPED_BASE;
32267- else
32268+ } else
32269 return TASK_UNMAPPED_BASE + mmap_rnd();
32270 }
32271
32272@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32273 */
32274 void arch_pick_mmap_layout(struct mm_struct *mm)
32275 {
32276- mm->mmap_legacy_base = mmap_legacy_base();
32277- mm->mmap_base = mmap_base();
32278+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32279+ mm->mmap_base = mmap_base(mm);
32280+
32281+#ifdef CONFIG_PAX_RANDMMAP
32282+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32283+ mm->mmap_legacy_base += mm->delta_mmap;
32284+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32285+ }
32286+#endif
32287
32288 if (mmap_is_legacy()) {
32289 mm->mmap_base = mm->mmap_legacy_base;
32290diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32291index 0057a7a..95c7edd 100644
32292--- a/arch/x86/mm/mmio-mod.c
32293+++ b/arch/x86/mm/mmio-mod.c
32294@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32295 break;
32296 default:
32297 {
32298- unsigned char *ip = (unsigned char *)instptr;
32299+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32300 my_trace->opcode = MMIO_UNKNOWN_OP;
32301 my_trace->width = 0;
32302 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32303@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32304 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32305 void __iomem *addr)
32306 {
32307- static atomic_t next_id;
32308+ static atomic_unchecked_t next_id;
32309 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32310 /* These are page-unaligned. */
32311 struct mmiotrace_map map = {
32312@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32313 .private = trace
32314 },
32315 .phys = offset,
32316- .id = atomic_inc_return(&next_id)
32317+ .id = atomic_inc_return_unchecked(&next_id)
32318 };
32319 map.map_id = trace->id;
32320
32321@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32322 ioremap_trace_core(offset, size, addr);
32323 }
32324
32325-static void iounmap_trace_core(volatile void __iomem *addr)
32326+static void iounmap_trace_core(const volatile void __iomem *addr)
32327 {
32328 struct mmiotrace_map map = {
32329 .phys = 0,
32330@@ -328,7 +328,7 @@ not_enabled:
32331 }
32332 }
32333
32334-void mmiotrace_iounmap(volatile void __iomem *addr)
32335+void mmiotrace_iounmap(const volatile void __iomem *addr)
32336 {
32337 might_sleep();
32338 if (is_enabled()) /* recheck and proper locking in *_core() */
32339diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32340index 8bf93ba..dbcd670 100644
32341--- a/arch/x86/mm/numa.c
32342+++ b/arch/x86/mm/numa.c
32343@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32344 return true;
32345 }
32346
32347-static int __init numa_register_memblks(struct numa_meminfo *mi)
32348+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32349 {
32350 unsigned long uninitialized_var(pfn_align);
32351 int i, nid;
32352diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32353index d0b1773..4c3327c 100644
32354--- a/arch/x86/mm/pageattr-test.c
32355+++ b/arch/x86/mm/pageattr-test.c
32356@@ -36,7 +36,7 @@ enum {
32357
32358 static int pte_testbit(pte_t pte)
32359 {
32360- return pte_flags(pte) & _PAGE_UNUSED1;
32361+ return pte_flags(pte) & _PAGE_CPA_TEST;
32362 }
32363
32364 struct split_state {
32365diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32366index bb32480..75f2f5e 100644
32367--- a/arch/x86/mm/pageattr.c
32368+++ b/arch/x86/mm/pageattr.c
32369@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32370 */
32371 #ifdef CONFIG_PCI_BIOS
32372 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32373- pgprot_val(forbidden) |= _PAGE_NX;
32374+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32375 #endif
32376
32377 /*
32378@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32379 * Does not cover __inittext since that is gone later on. On
32380 * 64bit we do not enforce !NX on the low mapping
32381 */
32382- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32383- pgprot_val(forbidden) |= _PAGE_NX;
32384+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32385+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32386
32387+#ifdef CONFIG_DEBUG_RODATA
32388 /*
32389 * The .rodata section needs to be read-only. Using the pfn
32390 * catches all aliases.
32391@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32392 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32393 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32394 pgprot_val(forbidden) |= _PAGE_RW;
32395+#endif
32396
32397 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32398 /*
32399@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32400 }
32401 #endif
32402
32403+#ifdef CONFIG_PAX_KERNEXEC
32404+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32405+ pgprot_val(forbidden) |= _PAGE_RW;
32406+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32407+ }
32408+#endif
32409+
32410 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32411
32412 return prot;
32413@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32414 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32415 {
32416 /* change init_mm */
32417+ pax_open_kernel();
32418 set_pte_atomic(kpte, pte);
32419+
32420 #ifdef CONFIG_X86_32
32421 if (!SHARED_KERNEL_PMD) {
32422+
32423+#ifdef CONFIG_PAX_PER_CPU_PGD
32424+ unsigned long cpu;
32425+#else
32426 struct page *page;
32427+#endif
32428
32429+#ifdef CONFIG_PAX_PER_CPU_PGD
32430+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32431+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32432+#else
32433 list_for_each_entry(page, &pgd_list, lru) {
32434- pgd_t *pgd;
32435+ pgd_t *pgd = (pgd_t *)page_address(page);
32436+#endif
32437+
32438 pud_t *pud;
32439 pmd_t *pmd;
32440
32441- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32442+ pgd += pgd_index(address);
32443 pud = pud_offset(pgd, address);
32444 pmd = pmd_offset(pud, address);
32445 set_pte_atomic((pte_t *)pmd, pte);
32446 }
32447 }
32448 #endif
32449+ pax_close_kernel();
32450 }
32451
32452 static int
32453diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32454index 6574388..87e9bef 100644
32455--- a/arch/x86/mm/pat.c
32456+++ b/arch/x86/mm/pat.c
32457@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32458
32459 if (!entry) {
32460 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32461- current->comm, current->pid, start, end - 1);
32462+ current->comm, task_pid_nr(current), start, end - 1);
32463 return -EINVAL;
32464 }
32465
32466@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32467
32468 while (cursor < to) {
32469 if (!devmem_is_allowed(pfn)) {
32470- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32471- current->comm, from, to - 1);
32472+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32473+ current->comm, from, to - 1, cursor);
32474 return 0;
32475 }
32476 cursor += PAGE_SIZE;
32477@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32478 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32479 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32480 "for [mem %#010Lx-%#010Lx]\n",
32481- current->comm, current->pid,
32482+ current->comm, task_pid_nr(current),
32483 cattr_name(flags),
32484 base, (unsigned long long)(base + size-1));
32485 return -EINVAL;
32486@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32487 flags = lookup_memtype(paddr);
32488 if (want_flags != flags) {
32489 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32490- current->comm, current->pid,
32491+ current->comm, task_pid_nr(current),
32492 cattr_name(want_flags),
32493 (unsigned long long)paddr,
32494 (unsigned long long)(paddr + size - 1),
32495@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32496 free_memtype(paddr, paddr + size);
32497 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32498 " for [mem %#010Lx-%#010Lx], got %s\n",
32499- current->comm, current->pid,
32500+ current->comm, task_pid_nr(current),
32501 cattr_name(want_flags),
32502 (unsigned long long)paddr,
32503 (unsigned long long)(paddr + size - 1),
32504diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32505index 415f6c4..d319983 100644
32506--- a/arch/x86/mm/pat_rbtree.c
32507+++ b/arch/x86/mm/pat_rbtree.c
32508@@ -160,7 +160,7 @@ success:
32509
32510 failure:
32511 printk(KERN_INFO "%s:%d conflicting memory types "
32512- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32513+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32514 end, cattr_name(found_type), cattr_name(match->type));
32515 return -EBUSY;
32516 }
32517diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32518index 9f0614d..92ae64a 100644
32519--- a/arch/x86/mm/pf_in.c
32520+++ b/arch/x86/mm/pf_in.c
32521@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32522 int i;
32523 enum reason_type rv = OTHERS;
32524
32525- p = (unsigned char *)ins_addr;
32526+ p = (unsigned char *)ktla_ktva(ins_addr);
32527 p += skip_prefix(p, &prf);
32528 p += get_opcode(p, &opcode);
32529
32530@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32531 struct prefix_bits prf;
32532 int i;
32533
32534- p = (unsigned char *)ins_addr;
32535+ p = (unsigned char *)ktla_ktva(ins_addr);
32536 p += skip_prefix(p, &prf);
32537 p += get_opcode(p, &opcode);
32538
32539@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32540 struct prefix_bits prf;
32541 int i;
32542
32543- p = (unsigned char *)ins_addr;
32544+ p = (unsigned char *)ktla_ktva(ins_addr);
32545 p += skip_prefix(p, &prf);
32546 p += get_opcode(p, &opcode);
32547
32548@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32549 struct prefix_bits prf;
32550 int i;
32551
32552- p = (unsigned char *)ins_addr;
32553+ p = (unsigned char *)ktla_ktva(ins_addr);
32554 p += skip_prefix(p, &prf);
32555 p += get_opcode(p, &opcode);
32556 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32557@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32558 struct prefix_bits prf;
32559 int i;
32560
32561- p = (unsigned char *)ins_addr;
32562+ p = (unsigned char *)ktla_ktva(ins_addr);
32563 p += skip_prefix(p, &prf);
32564 p += get_opcode(p, &opcode);
32565 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32566diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32567index dfa537a..fd45c64 100644
32568--- a/arch/x86/mm/pgtable.c
32569+++ b/arch/x86/mm/pgtable.c
32570@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
32571 list_del(&page->lru);
32572 }
32573
32574-#define UNSHARED_PTRS_PER_PGD \
32575- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32576+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32577+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32578
32579+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32580+{
32581+ unsigned int count = USER_PGD_PTRS;
32582
32583+ if (!pax_user_shadow_base)
32584+ return;
32585+
32586+ while (count--)
32587+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32588+}
32589+#endif
32590+
32591+#ifdef CONFIG_PAX_PER_CPU_PGD
32592+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32593+{
32594+ unsigned int count = USER_PGD_PTRS;
32595+
32596+ while (count--) {
32597+ pgd_t pgd;
32598+
32599+#ifdef CONFIG_X86_64
32600+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32601+#else
32602+ pgd = *src++;
32603+#endif
32604+
32605+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32606+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32607+#endif
32608+
32609+ *dst++ = pgd;
32610+ }
32611+
32612+}
32613+#endif
32614+
32615+#ifdef CONFIG_X86_64
32616+#define pxd_t pud_t
32617+#define pyd_t pgd_t
32618+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32619+#define pxd_free(mm, pud) pud_free((mm), (pud))
32620+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32621+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32622+#define PYD_SIZE PGDIR_SIZE
32623+#else
32624+#define pxd_t pmd_t
32625+#define pyd_t pud_t
32626+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32627+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32628+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32629+#define pyd_offset(mm, address) pud_offset((mm), (address))
32630+#define PYD_SIZE PUD_SIZE
32631+#endif
32632+
32633+#ifdef CONFIG_PAX_PER_CPU_PGD
32634+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32635+static inline void pgd_dtor(pgd_t *pgd) {}
32636+#else
32637 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32638 {
32639 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32640@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
32641 pgd_list_del(pgd);
32642 spin_unlock(&pgd_lock);
32643 }
32644+#endif
32645
32646 /*
32647 * List of all pgd's needed for non-PAE so it can invalidate entries
32648@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
32649 * -- nyc
32650 */
32651
32652-#ifdef CONFIG_X86_PAE
32653+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32654 /*
32655 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32656 * updating the top-level pagetable entries to guarantee the
32657@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
32658 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32659 * and initialize the kernel pmds here.
32660 */
32661-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32662+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32663
32664 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32665 {
32666@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32667 */
32668 flush_tlb_mm(mm);
32669 }
32670+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32671+#define PREALLOCATED_PXDS USER_PGD_PTRS
32672 #else /* !CONFIG_X86_PAE */
32673
32674 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32675-#define PREALLOCATED_PMDS 0
32676+#define PREALLOCATED_PXDS 0
32677
32678 #endif /* CONFIG_X86_PAE */
32679
32680-static void free_pmds(pmd_t *pmds[])
32681+static void free_pxds(pxd_t *pxds[])
32682 {
32683 int i;
32684
32685- for(i = 0; i < PREALLOCATED_PMDS; i++)
32686- if (pmds[i])
32687- free_page((unsigned long)pmds[i]);
32688+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32689+ if (pxds[i])
32690+ free_page((unsigned long)pxds[i]);
32691 }
32692
32693-static int preallocate_pmds(pmd_t *pmds[])
32694+static int preallocate_pxds(pxd_t *pxds[])
32695 {
32696 int i;
32697 bool failed = false;
32698
32699- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32700- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32701- if (pmd == NULL)
32702+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32703+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32704+ if (pxd == NULL)
32705 failed = true;
32706- pmds[i] = pmd;
32707+ pxds[i] = pxd;
32708 }
32709
32710 if (failed) {
32711- free_pmds(pmds);
32712+ free_pxds(pxds);
32713 return -ENOMEM;
32714 }
32715
32716@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32717 * preallocate which never got a corresponding vma will need to be
32718 * freed manually.
32719 */
32720-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32721+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32722 {
32723 int i;
32724
32725- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32726+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32727 pgd_t pgd = pgdp[i];
32728
32729 if (pgd_val(pgd) != 0) {
32730- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32731+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32732
32733- pgdp[i] = native_make_pgd(0);
32734+ set_pgd(pgdp + i, native_make_pgd(0));
32735
32736- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32737- pmd_free(mm, pmd);
32738+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32739+ pxd_free(mm, pxd);
32740 }
32741 }
32742 }
32743
32744-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32745+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32746 {
32747- pud_t *pud;
32748+ pyd_t *pyd;
32749 int i;
32750
32751- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32752+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32753 return;
32754
32755- pud = pud_offset(pgd, 0);
32756-
32757- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32758- pmd_t *pmd = pmds[i];
32759+#ifdef CONFIG_X86_64
32760+ pyd = pyd_offset(mm, 0L);
32761+#else
32762+ pyd = pyd_offset(pgd, 0L);
32763+#endif
32764
32765+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32766+ pxd_t *pxd = pxds[i];
32767 if (i >= KERNEL_PGD_BOUNDARY)
32768- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32769- sizeof(pmd_t) * PTRS_PER_PMD);
32770+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32771+ sizeof(pxd_t) * PTRS_PER_PMD);
32772
32773- pud_populate(mm, pud, pmd);
32774+ pyd_populate(mm, pyd, pxd);
32775 }
32776 }
32777
32778 pgd_t *pgd_alloc(struct mm_struct *mm)
32779 {
32780 pgd_t *pgd;
32781- pmd_t *pmds[PREALLOCATED_PMDS];
32782+ pxd_t *pxds[PREALLOCATED_PXDS];
32783
32784 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32785
32786@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32787
32788 mm->pgd = pgd;
32789
32790- if (preallocate_pmds(pmds) != 0)
32791+ if (preallocate_pxds(pxds) != 0)
32792 goto out_free_pgd;
32793
32794 if (paravirt_pgd_alloc(mm) != 0)
32795- goto out_free_pmds;
32796+ goto out_free_pxds;
32797
32798 /*
32799 * Make sure that pre-populating the pmds is atomic with
32800@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32801 spin_lock(&pgd_lock);
32802
32803 pgd_ctor(mm, pgd);
32804- pgd_prepopulate_pmd(mm, pgd, pmds);
32805+ pgd_prepopulate_pxd(mm, pgd, pxds);
32806
32807 spin_unlock(&pgd_lock);
32808
32809 return pgd;
32810
32811-out_free_pmds:
32812- free_pmds(pmds);
32813+out_free_pxds:
32814+ free_pxds(pxds);
32815 out_free_pgd:
32816 free_page((unsigned long)pgd);
32817 out:
32818@@ -300,7 +363,7 @@ out:
32819
32820 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32821 {
32822- pgd_mop_up_pmds(mm, pgd);
32823+ pgd_mop_up_pxds(mm, pgd);
32824 pgd_dtor(pgd);
32825 paravirt_pgd_free(mm, pgd);
32826 free_page((unsigned long)pgd);
32827diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32828index a69bcb8..19068ab 100644
32829--- a/arch/x86/mm/pgtable_32.c
32830+++ b/arch/x86/mm/pgtable_32.c
32831@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32832 return;
32833 }
32834 pte = pte_offset_kernel(pmd, vaddr);
32835+
32836+ pax_open_kernel();
32837 if (pte_val(pteval))
32838 set_pte_at(&init_mm, vaddr, pte, pteval);
32839 else
32840 pte_clear(&init_mm, vaddr, pte);
32841+ pax_close_kernel();
32842
32843 /*
32844 * It's enough to flush this one mapping.
32845diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32846index e666cbb..61788c45 100644
32847--- a/arch/x86/mm/physaddr.c
32848+++ b/arch/x86/mm/physaddr.c
32849@@ -10,7 +10,7 @@
32850 #ifdef CONFIG_X86_64
32851
32852 #ifdef CONFIG_DEBUG_VIRTUAL
32853-unsigned long __phys_addr(unsigned long x)
32854+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32855 {
32856 unsigned long y = x - __START_KERNEL_map;
32857
32858@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32859 #else
32860
32861 #ifdef CONFIG_DEBUG_VIRTUAL
32862-unsigned long __phys_addr(unsigned long x)
32863+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32864 {
32865 unsigned long phys_addr = x - PAGE_OFFSET;
32866 /* VMALLOC_* aren't constants */
32867diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32868index 90555bf..f5f1828 100644
32869--- a/arch/x86/mm/setup_nx.c
32870+++ b/arch/x86/mm/setup_nx.c
32871@@ -5,8 +5,10 @@
32872 #include <asm/pgtable.h>
32873 #include <asm/proto.h>
32874
32875+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32876 static int disable_nx;
32877
32878+#ifndef CONFIG_PAX_PAGEEXEC
32879 /*
32880 * noexec = on|off
32881 *
32882@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32883 return 0;
32884 }
32885 early_param("noexec", noexec_setup);
32886+#endif
32887+
32888+#endif
32889
32890 void x86_configure_nx(void)
32891 {
32892+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32893 if (cpu_has_nx && !disable_nx)
32894 __supported_pte_mask |= _PAGE_NX;
32895 else
32896+#endif
32897 __supported_pte_mask &= ~_PAGE_NX;
32898 }
32899
32900diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32901index ae699b3..f1b2ad2 100644
32902--- a/arch/x86/mm/tlb.c
32903+++ b/arch/x86/mm/tlb.c
32904@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32905 BUG();
32906 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32907 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32908+
32909+#ifndef CONFIG_PAX_PER_CPU_PGD
32910 load_cr3(swapper_pg_dir);
32911+#endif
32912+
32913 }
32914 }
32915 EXPORT_SYMBOL_GPL(leave_mm);
32916diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32917new file mode 100644
32918index 0000000..dace51c
32919--- /dev/null
32920+++ b/arch/x86/mm/uderef_64.c
32921@@ -0,0 +1,37 @@
32922+#include <linux/mm.h>
32923+#include <asm/pgtable.h>
32924+#include <asm/uaccess.h>
32925+
32926+#ifdef CONFIG_PAX_MEMORY_UDEREF
32927+/* PaX: due to the special call convention these functions must
32928+ * - remain leaf functions under all configurations,
32929+ * - never be called directly, only dereferenced from the wrappers.
32930+ */
32931+void __pax_open_userland(void)
32932+{
32933+ unsigned int cpu;
32934+
32935+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32936+ return;
32937+
32938+ cpu = raw_get_cpu();
32939+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32940+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32941+ raw_put_cpu_no_resched();
32942+}
32943+EXPORT_SYMBOL(__pax_open_userland);
32944+
32945+void __pax_close_userland(void)
32946+{
32947+ unsigned int cpu;
32948+
32949+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32950+ return;
32951+
32952+ cpu = raw_get_cpu();
32953+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32954+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32955+ raw_put_cpu_no_resched();
32956+}
32957+EXPORT_SYMBOL(__pax_close_userland);
32958+#endif
32959diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32960index 877b9a1..a8ecf42 100644
32961--- a/arch/x86/net/bpf_jit.S
32962+++ b/arch/x86/net/bpf_jit.S
32963@@ -9,6 +9,7 @@
32964 */
32965 #include <linux/linkage.h>
32966 #include <asm/dwarf2.h>
32967+#include <asm/alternative-asm.h>
32968
32969 /*
32970 * Calling convention :
32971@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32972 jle bpf_slow_path_word
32973 mov (SKBDATA,%rsi),%eax
32974 bswap %eax /* ntohl() */
32975+ pax_force_retaddr
32976 ret
32977
32978 sk_load_half:
32979@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32980 jle bpf_slow_path_half
32981 movzwl (SKBDATA,%rsi),%eax
32982 rol $8,%ax # ntohs()
32983+ pax_force_retaddr
32984 ret
32985
32986 sk_load_byte:
32987@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32988 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32989 jle bpf_slow_path_byte
32990 movzbl (SKBDATA,%rsi),%eax
32991+ pax_force_retaddr
32992 ret
32993
32994 /**
32995@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32996 movzbl (SKBDATA,%rsi),%ebx
32997 and $15,%bl
32998 shl $2,%bl
32999+ pax_force_retaddr
33000 ret
33001
33002 /* rsi contains offset and can be scratched */
33003@@ -109,6 +114,7 @@ bpf_slow_path_word:
33004 js bpf_error
33005 mov -12(%rbp),%eax
33006 bswap %eax
33007+ pax_force_retaddr
33008 ret
33009
33010 bpf_slow_path_half:
33011@@ -117,12 +123,14 @@ bpf_slow_path_half:
33012 mov -12(%rbp),%ax
33013 rol $8,%ax
33014 movzwl %ax,%eax
33015+ pax_force_retaddr
33016 ret
33017
33018 bpf_slow_path_byte:
33019 bpf_slow_path_common(1)
33020 js bpf_error
33021 movzbl -12(%rbp),%eax
33022+ pax_force_retaddr
33023 ret
33024
33025 bpf_slow_path_byte_msh:
33026@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33027 and $15,%al
33028 shl $2,%al
33029 xchg %eax,%ebx
33030+ pax_force_retaddr
33031 ret
33032
33033 #define sk_negative_common(SIZE) \
33034@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33035 sk_negative_common(4)
33036 mov (%rax), %eax
33037 bswap %eax
33038+ pax_force_retaddr
33039 ret
33040
33041 bpf_slow_path_half_neg:
33042@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33043 mov (%rax),%ax
33044 rol $8,%ax
33045 movzwl %ax,%eax
33046+ pax_force_retaddr
33047 ret
33048
33049 bpf_slow_path_byte_neg:
33050@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33051 .globl sk_load_byte_negative_offset
33052 sk_negative_common(1)
33053 movzbl (%rax), %eax
33054+ pax_force_retaddr
33055 ret
33056
33057 bpf_slow_path_byte_msh_neg:
33058@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33059 and $15,%al
33060 shl $2,%al
33061 xchg %eax,%ebx
33062+ pax_force_retaddr
33063 ret
33064
33065 bpf_error:
33066@@ -197,4 +210,5 @@ bpf_error:
33067 xor %eax,%eax
33068 mov -8(%rbp),%rbx
33069 leaveq
33070+ pax_force_retaddr
33071 ret
33072diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33073index 26328e8..5f96c25 100644
33074--- a/arch/x86/net/bpf_jit_comp.c
33075+++ b/arch/x86/net/bpf_jit_comp.c
33076@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33077 return ptr + len;
33078 }
33079
33080+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33081+#define MAX_INSTR_CODE_SIZE 96
33082+#else
33083+#define MAX_INSTR_CODE_SIZE 64
33084+#endif
33085+
33086 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33087
33088 #define EMIT1(b1) EMIT(b1, 1)
33089 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33090 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33091 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33092+
33093+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33094+/* original constant will appear in ecx */
33095+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33096+do { \
33097+ /* mov ecx, randkey */ \
33098+ EMIT1(0xb9); \
33099+ EMIT(_key, 4); \
33100+ /* xor ecx, randkey ^ off */ \
33101+ EMIT2(0x81, 0xf1); \
33102+ EMIT((_key) ^ (_off), 4); \
33103+} while (0)
33104+
33105+#define EMIT1_off32(b1, _off) \
33106+do { \
33107+ switch (b1) { \
33108+ case 0x05: /* add eax, imm32 */ \
33109+ case 0x2d: /* sub eax, imm32 */ \
33110+ case 0x25: /* and eax, imm32 */ \
33111+ case 0x0d: /* or eax, imm32 */ \
33112+ case 0xb8: /* mov eax, imm32 */ \
33113+ case 0x35: /* xor eax, imm32 */ \
33114+ case 0x3d: /* cmp eax, imm32 */ \
33115+ case 0xa9: /* test eax, imm32 */ \
33116+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33117+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33118+ break; \
33119+ case 0xbb: /* mov ebx, imm32 */ \
33120+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33121+ /* mov ebx, ecx */ \
33122+ EMIT2(0x89, 0xcb); \
33123+ break; \
33124+ case 0xbe: /* mov esi, imm32 */ \
33125+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33126+ /* mov esi, ecx */ \
33127+ EMIT2(0x89, 0xce); \
33128+ break; \
33129+ case 0xe8: /* call rel imm32, always to known funcs */ \
33130+ EMIT1(b1); \
33131+ EMIT(_off, 4); \
33132+ break; \
33133+ case 0xe9: /* jmp rel imm32 */ \
33134+ EMIT1(b1); \
33135+ EMIT(_off, 4); \
33136+ /* prevent fall-through, we're not called if off = 0 */ \
33137+ EMIT(0xcccccccc, 4); \
33138+ EMIT(0xcccccccc, 4); \
33139+ break; \
33140+ default: \
33141+ BUILD_BUG(); \
33142+ } \
33143+} while (0)
33144+
33145+#define EMIT2_off32(b1, b2, _off) \
33146+do { \
33147+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33148+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33149+ EMIT(randkey, 4); \
33150+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33151+ EMIT((_off) - randkey, 4); \
33152+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33153+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33154+ /* imul eax, ecx */ \
33155+ EMIT3(0x0f, 0xaf, 0xc1); \
33156+ } else { \
33157+ BUILD_BUG(); \
33158+ } \
33159+} while (0)
33160+#else
33161 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33162+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33163+#endif
33164
33165 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33166 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33167@@ -91,6 +168,24 @@ do { \
33168 #define X86_JBE 0x76
33169 #define X86_JA 0x77
33170
33171+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33172+#define APPEND_FLOW_VERIFY() \
33173+do { \
33174+ /* mov ecx, randkey */ \
33175+ EMIT1(0xb9); \
33176+ EMIT(randkey, 4); \
33177+ /* cmp ecx, randkey */ \
33178+ EMIT2(0x81, 0xf9); \
33179+ EMIT(randkey, 4); \
33180+ /* jz after 8 int 3s */ \
33181+ EMIT2(0x74, 0x08); \
33182+ EMIT(0xcccccccc, 4); \
33183+ EMIT(0xcccccccc, 4); \
33184+} while (0)
33185+#else
33186+#define APPEND_FLOW_VERIFY() do { } while (0)
33187+#endif
33188+
33189 #define EMIT_COND_JMP(op, offset) \
33190 do { \
33191 if (is_near(offset)) \
33192@@ -98,6 +193,7 @@ do { \
33193 else { \
33194 EMIT2(0x0f, op + 0x10); \
33195 EMIT(offset, 4); /* jxx .+off32 */ \
33196+ APPEND_FLOW_VERIFY(); \
33197 } \
33198 } while (0)
33199
33200@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33201 return -1;
33202 }
33203
33204-struct bpf_binary_header {
33205- unsigned int pages;
33206- /* Note : for security reasons, bpf code will follow a randomly
33207- * sized amount of int3 instructions
33208- */
33209- u8 image[];
33210-};
33211-
33212-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33213+/* Note : for security reasons, bpf code will follow a randomly
33214+ * sized amount of int3 instructions
33215+ */
33216+static u8 *bpf_alloc_binary(unsigned int proglen,
33217 u8 **image_ptr)
33218 {
33219 unsigned int sz, hole;
33220- struct bpf_binary_header *header;
33221+ u8 *header;
33222
33223 /* Most of BPF filters are really small,
33224 * but if some of them fill a page, allow at least
33225 * 128 extra bytes to insert a random section of int3
33226 */
33227- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33228- header = module_alloc(sz);
33229+ sz = round_up(proglen + 128, PAGE_SIZE);
33230+ header = module_alloc_exec(sz);
33231 if (!header)
33232 return NULL;
33233
33234+ pax_open_kernel();
33235 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33236+ pax_close_kernel();
33237
33238- header->pages = sz / PAGE_SIZE;
33239- hole = sz - (proglen + sizeof(*header));
33240+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33241
33242 /* insert a random number of int3 instructions before BPF code */
33243- *image_ptr = &header->image[prandom_u32() % hole];
33244+ *image_ptr = &header[prandom_u32() % hole];
33245 return header;
33246 }
33247
33248 void bpf_jit_compile(struct sk_filter *fp)
33249 {
33250- u8 temp[64];
33251+ u8 temp[MAX_INSTR_CODE_SIZE];
33252 u8 *prog;
33253 unsigned int proglen, oldproglen = 0;
33254 int ilen, i;
33255 int t_offset, f_offset;
33256 u8 t_op, f_op, seen = 0, pass;
33257 u8 *image = NULL;
33258- struct bpf_binary_header *header = NULL;
33259+ u8 *header = NULL;
33260 u8 *func;
33261 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33262 unsigned int cleanup_addr; /* epilogue code offset */
33263 unsigned int *addrs;
33264 const struct sock_filter *filter = fp->insns;
33265 int flen = fp->len;
33266+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33267+ unsigned int randkey;
33268+#endif
33269
33270 if (!bpf_jit_enable)
33271 return;
33272@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33273 if (addrs == NULL)
33274 return;
33275
33276+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33277+ randkey = get_random_int();
33278+#endif
33279+
33280 /* Before first pass, make a rough estimation of addrs[]
33281- * each bpf instruction is translated to less than 64 bytes
33282+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33283 */
33284 for (proglen = 0, i = 0; i < flen; i++) {
33285- proglen += 64;
33286+ proglen += MAX_INSTR_CODE_SIZE;
33287 addrs[i] = proglen;
33288 }
33289 cleanup_addr = proglen; /* epilogue address */
33290@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33291 case BPF_S_ALU_MUL_K: /* A *= K */
33292 if (is_imm8(K))
33293 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33294- else {
33295- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33296- EMIT(K, 4);
33297- }
33298+ else
33299+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33300 break;
33301 case BPF_S_ALU_DIV_X: /* A /= X; */
33302 seen |= SEEN_XREG;
33303@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
33304 break;
33305 case BPF_S_ALU_MOD_K: /* A %= K; */
33306 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33307+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33308+ DILUTE_CONST_SEQUENCE(K, randkey);
33309+#else
33310 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33311+#endif
33312 EMIT2(0xf7, 0xf1); /* div %ecx */
33313 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33314 break;
33315 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
33316+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33317+ DILUTE_CONST_SEQUENCE(K, randkey);
33318+ // imul rax, rcx
33319+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
33320+#else
33321 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
33322 EMIT(K, 4);
33323+#endif
33324 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
33325 break;
33326 case BPF_S_ALU_AND_X:
33327@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33328 if (is_imm8(K)) {
33329 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33330 } else {
33331- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33332- EMIT(K, 4);
33333+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33334 }
33335 } else {
33336 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33337@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33338 if (unlikely(proglen + ilen > oldproglen)) {
33339 pr_err("bpb_jit_compile fatal error\n");
33340 kfree(addrs);
33341- module_free(NULL, header);
33342+ module_free_exec(NULL, image);
33343 return;
33344 }
33345+ pax_open_kernel();
33346 memcpy(image + proglen, temp, ilen);
33347+ pax_close_kernel();
33348 }
33349 proglen += ilen;
33350 addrs[i] = proglen;
33351@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33352
33353 if (image) {
33354 bpf_flush_icache(header, image + proglen);
33355- set_memory_ro((unsigned long)header, header->pages);
33356 fp->bpf_func = (void *)image;
33357 }
33358 out:
33359@@ -776,10 +883,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33360 {
33361 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33362 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33363- struct bpf_binary_header *header = (void *)addr;
33364
33365- set_memory_rw(addr, header->pages);
33366- module_free(NULL, header);
33367+ set_memory_rw(addr, 1);
33368+ module_free_exec(NULL, (void *)addr);
33369 kfree(fp);
33370 }
33371
33372diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33373index d6aa6e8..266395a 100644
33374--- a/arch/x86/oprofile/backtrace.c
33375+++ b/arch/x86/oprofile/backtrace.c
33376@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33377 struct stack_frame_ia32 *fp;
33378 unsigned long bytes;
33379
33380- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33381+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33382 if (bytes != sizeof(bufhead))
33383 return NULL;
33384
33385- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33386+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33387
33388 oprofile_add_trace(bufhead[0].return_address);
33389
33390@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33391 struct stack_frame bufhead[2];
33392 unsigned long bytes;
33393
33394- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33395+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33396 if (bytes != sizeof(bufhead))
33397 return NULL;
33398
33399@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33400 {
33401 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33402
33403- if (!user_mode_vm(regs)) {
33404+ if (!user_mode(regs)) {
33405 unsigned long stack = kernel_stack_pointer(regs);
33406 if (depth)
33407 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33408diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33409index 6890d84..1dad1f1 100644
33410--- a/arch/x86/oprofile/nmi_int.c
33411+++ b/arch/x86/oprofile/nmi_int.c
33412@@ -23,6 +23,7 @@
33413 #include <asm/nmi.h>
33414 #include <asm/msr.h>
33415 #include <asm/apic.h>
33416+#include <asm/pgtable.h>
33417
33418 #include "op_counter.h"
33419 #include "op_x86_model.h"
33420@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33421 if (ret)
33422 return ret;
33423
33424- if (!model->num_virt_counters)
33425- model->num_virt_counters = model->num_counters;
33426+ if (!model->num_virt_counters) {
33427+ pax_open_kernel();
33428+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33429+ pax_close_kernel();
33430+ }
33431
33432 mux_init(ops);
33433
33434diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33435index 50d86c0..7985318 100644
33436--- a/arch/x86/oprofile/op_model_amd.c
33437+++ b/arch/x86/oprofile/op_model_amd.c
33438@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33439 num_counters = AMD64_NUM_COUNTERS;
33440 }
33441
33442- op_amd_spec.num_counters = num_counters;
33443- op_amd_spec.num_controls = num_counters;
33444- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33445+ pax_open_kernel();
33446+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33447+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33448+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33449+ pax_close_kernel();
33450
33451 return 0;
33452 }
33453diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33454index d90528e..0127e2b 100644
33455--- a/arch/x86/oprofile/op_model_ppro.c
33456+++ b/arch/x86/oprofile/op_model_ppro.c
33457@@ -19,6 +19,7 @@
33458 #include <asm/msr.h>
33459 #include <asm/apic.h>
33460 #include <asm/nmi.h>
33461+#include <asm/pgtable.h>
33462
33463 #include "op_x86_model.h"
33464 #include "op_counter.h"
33465@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33466
33467 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33468
33469- op_arch_perfmon_spec.num_counters = num_counters;
33470- op_arch_perfmon_spec.num_controls = num_counters;
33471+ pax_open_kernel();
33472+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33473+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33474+ pax_close_kernel();
33475 }
33476
33477 static int arch_perfmon_init(struct oprofile_operations *ignore)
33478diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33479index 71e8a67..6a313bb 100644
33480--- a/arch/x86/oprofile/op_x86_model.h
33481+++ b/arch/x86/oprofile/op_x86_model.h
33482@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33483 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33484 struct op_msrs const * const msrs);
33485 #endif
33486-};
33487+} __do_const;
33488
33489 struct op_counter_config;
33490
33491diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33492index 372e9b8..e775a6c 100644
33493--- a/arch/x86/pci/irq.c
33494+++ b/arch/x86/pci/irq.c
33495@@ -50,7 +50,7 @@ struct irq_router {
33496 struct irq_router_handler {
33497 u16 vendor;
33498 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33499-};
33500+} __do_const;
33501
33502 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33503 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33504@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33505 return 0;
33506 }
33507
33508-static __initdata struct irq_router_handler pirq_routers[] = {
33509+static __initconst const struct irq_router_handler pirq_routers[] = {
33510 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33511 { PCI_VENDOR_ID_AL, ali_router_probe },
33512 { PCI_VENDOR_ID_ITE, ite_router_probe },
33513@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33514 static void __init pirq_find_router(struct irq_router *r)
33515 {
33516 struct irq_routing_table *rt = pirq_table;
33517- struct irq_router_handler *h;
33518+ const struct irq_router_handler *h;
33519
33520 #ifdef CONFIG_PCI_BIOS
33521 if (!rt->signature) {
33522@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33523 return 0;
33524 }
33525
33526-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33527+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33528 {
33529 .callback = fix_broken_hp_bios_irq9,
33530 .ident = "HP Pavilion N5400 Series Laptop",
33531diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
33532index 903fded..94b0d88 100644
33533--- a/arch/x86/pci/mrst.c
33534+++ b/arch/x86/pci/mrst.c
33535@@ -241,7 +241,9 @@ int __init pci_mrst_init(void)
33536 pr_info("Intel MID platform detected, using MID PCI ops\n");
33537 pci_mmcfg_late_init();
33538 pcibios_enable_irq = mrst_pci_irq_enable;
33539- pci_root_ops = pci_mrst_ops;
33540+ pax_open_kernel();
33541+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
33542+ pax_close_kernel();
33543 pci_soc_mode = 1;
33544 /* Continue with standard init */
33545 return 1;
33546diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33547index c77b24a..c979855 100644
33548--- a/arch/x86/pci/pcbios.c
33549+++ b/arch/x86/pci/pcbios.c
33550@@ -79,7 +79,7 @@ union bios32 {
33551 static struct {
33552 unsigned long address;
33553 unsigned short segment;
33554-} bios32_indirect = { 0, __KERNEL_CS };
33555+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33556
33557 /*
33558 * Returns the entry point for the given service, NULL on error
33559@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33560 unsigned long length; /* %ecx */
33561 unsigned long entry; /* %edx */
33562 unsigned long flags;
33563+ struct desc_struct d, *gdt;
33564
33565 local_irq_save(flags);
33566- __asm__("lcall *(%%edi); cld"
33567+
33568+ gdt = get_cpu_gdt_table(smp_processor_id());
33569+
33570+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33571+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33572+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33573+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33574+
33575+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33576 : "=a" (return_code),
33577 "=b" (address),
33578 "=c" (length),
33579 "=d" (entry)
33580 : "0" (service),
33581 "1" (0),
33582- "D" (&bios32_indirect));
33583+ "D" (&bios32_indirect),
33584+ "r"(__PCIBIOS_DS)
33585+ : "memory");
33586+
33587+ pax_open_kernel();
33588+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33589+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33590+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33591+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33592+ pax_close_kernel();
33593+
33594 local_irq_restore(flags);
33595
33596 switch (return_code) {
33597- case 0:
33598- return address + entry;
33599- case 0x80: /* Not present */
33600- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33601- return 0;
33602- default: /* Shouldn't happen */
33603- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33604- service, return_code);
33605+ case 0: {
33606+ int cpu;
33607+ unsigned char flags;
33608+
33609+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33610+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33611+ printk(KERN_WARNING "bios32_service: not valid\n");
33612 return 0;
33613+ }
33614+ address = address + PAGE_OFFSET;
33615+ length += 16UL; /* some BIOSs underreport this... */
33616+ flags = 4;
33617+ if (length >= 64*1024*1024) {
33618+ length >>= PAGE_SHIFT;
33619+ flags |= 8;
33620+ }
33621+
33622+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33623+ gdt = get_cpu_gdt_table(cpu);
33624+ pack_descriptor(&d, address, length, 0x9b, flags);
33625+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33626+ pack_descriptor(&d, address, length, 0x93, flags);
33627+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33628+ }
33629+ return entry;
33630+ }
33631+ case 0x80: /* Not present */
33632+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33633+ return 0;
33634+ default: /* Shouldn't happen */
33635+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33636+ service, return_code);
33637+ return 0;
33638 }
33639 }
33640
33641 static struct {
33642 unsigned long address;
33643 unsigned short segment;
33644-} pci_indirect = { 0, __KERNEL_CS };
33645+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33646
33647-static int pci_bios_present;
33648+static int pci_bios_present __read_only;
33649
33650 static int check_pcibios(void)
33651 {
33652@@ -131,11 +174,13 @@ static int check_pcibios(void)
33653 unsigned long flags, pcibios_entry;
33654
33655 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33656- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33657+ pci_indirect.address = pcibios_entry;
33658
33659 local_irq_save(flags);
33660- __asm__(
33661- "lcall *(%%edi); cld\n\t"
33662+ __asm__("movw %w6, %%ds\n\t"
33663+ "lcall *%%ss:(%%edi); cld\n\t"
33664+ "push %%ss\n\t"
33665+ "pop %%ds\n\t"
33666 "jc 1f\n\t"
33667 "xor %%ah, %%ah\n"
33668 "1:"
33669@@ -144,7 +189,8 @@ static int check_pcibios(void)
33670 "=b" (ebx),
33671 "=c" (ecx)
33672 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33673- "D" (&pci_indirect)
33674+ "D" (&pci_indirect),
33675+ "r" (__PCIBIOS_DS)
33676 : "memory");
33677 local_irq_restore(flags);
33678
33679@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33680
33681 switch (len) {
33682 case 1:
33683- __asm__("lcall *(%%esi); cld\n\t"
33684+ __asm__("movw %w6, %%ds\n\t"
33685+ "lcall *%%ss:(%%esi); cld\n\t"
33686+ "push %%ss\n\t"
33687+ "pop %%ds\n\t"
33688 "jc 1f\n\t"
33689 "xor %%ah, %%ah\n"
33690 "1:"
33691@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33692 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33693 "b" (bx),
33694 "D" ((long)reg),
33695- "S" (&pci_indirect));
33696+ "S" (&pci_indirect),
33697+ "r" (__PCIBIOS_DS));
33698 /*
33699 * Zero-extend the result beyond 8 bits, do not trust the
33700 * BIOS having done it:
33701@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33702 *value &= 0xff;
33703 break;
33704 case 2:
33705- __asm__("lcall *(%%esi); cld\n\t"
33706+ __asm__("movw %w6, %%ds\n\t"
33707+ "lcall *%%ss:(%%esi); cld\n\t"
33708+ "push %%ss\n\t"
33709+ "pop %%ds\n\t"
33710 "jc 1f\n\t"
33711 "xor %%ah, %%ah\n"
33712 "1:"
33713@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33714 : "1" (PCIBIOS_READ_CONFIG_WORD),
33715 "b" (bx),
33716 "D" ((long)reg),
33717- "S" (&pci_indirect));
33718+ "S" (&pci_indirect),
33719+ "r" (__PCIBIOS_DS));
33720 /*
33721 * Zero-extend the result beyond 16 bits, do not trust the
33722 * BIOS having done it:
33723@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33724 *value &= 0xffff;
33725 break;
33726 case 4:
33727- __asm__("lcall *(%%esi); cld\n\t"
33728+ __asm__("movw %w6, %%ds\n\t"
33729+ "lcall *%%ss:(%%esi); cld\n\t"
33730+ "push %%ss\n\t"
33731+ "pop %%ds\n\t"
33732 "jc 1f\n\t"
33733 "xor %%ah, %%ah\n"
33734 "1:"
33735@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33736 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33737 "b" (bx),
33738 "D" ((long)reg),
33739- "S" (&pci_indirect));
33740+ "S" (&pci_indirect),
33741+ "r" (__PCIBIOS_DS));
33742 break;
33743 }
33744
33745@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33746
33747 switch (len) {
33748 case 1:
33749- __asm__("lcall *(%%esi); cld\n\t"
33750+ __asm__("movw %w6, %%ds\n\t"
33751+ "lcall *%%ss:(%%esi); cld\n\t"
33752+ "push %%ss\n\t"
33753+ "pop %%ds\n\t"
33754 "jc 1f\n\t"
33755 "xor %%ah, %%ah\n"
33756 "1:"
33757@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33758 "c" (value),
33759 "b" (bx),
33760 "D" ((long)reg),
33761- "S" (&pci_indirect));
33762+ "S" (&pci_indirect),
33763+ "r" (__PCIBIOS_DS));
33764 break;
33765 case 2:
33766- __asm__("lcall *(%%esi); cld\n\t"
33767+ __asm__("movw %w6, %%ds\n\t"
33768+ "lcall *%%ss:(%%esi); cld\n\t"
33769+ "push %%ss\n\t"
33770+ "pop %%ds\n\t"
33771 "jc 1f\n\t"
33772 "xor %%ah, %%ah\n"
33773 "1:"
33774@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33775 "c" (value),
33776 "b" (bx),
33777 "D" ((long)reg),
33778- "S" (&pci_indirect));
33779+ "S" (&pci_indirect),
33780+ "r" (__PCIBIOS_DS));
33781 break;
33782 case 4:
33783- __asm__("lcall *(%%esi); cld\n\t"
33784+ __asm__("movw %w6, %%ds\n\t"
33785+ "lcall *%%ss:(%%esi); cld\n\t"
33786+ "push %%ss\n\t"
33787+ "pop %%ds\n\t"
33788 "jc 1f\n\t"
33789 "xor %%ah, %%ah\n"
33790 "1:"
33791@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33792 "c" (value),
33793 "b" (bx),
33794 "D" ((long)reg),
33795- "S" (&pci_indirect));
33796+ "S" (&pci_indirect),
33797+ "r" (__PCIBIOS_DS));
33798 break;
33799 }
33800
33801@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33802
33803 DBG("PCI: Fetching IRQ routing table... ");
33804 __asm__("push %%es\n\t"
33805+ "movw %w8, %%ds\n\t"
33806 "push %%ds\n\t"
33807 "pop %%es\n\t"
33808- "lcall *(%%esi); cld\n\t"
33809+ "lcall *%%ss:(%%esi); cld\n\t"
33810 "pop %%es\n\t"
33811+ "push %%ss\n\t"
33812+ "pop %%ds\n"
33813 "jc 1f\n\t"
33814 "xor %%ah, %%ah\n"
33815 "1:"
33816@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33817 "1" (0),
33818 "D" ((long) &opt),
33819 "S" (&pci_indirect),
33820- "m" (opt)
33821+ "m" (opt),
33822+ "r" (__PCIBIOS_DS)
33823 : "memory");
33824 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33825 if (ret & 0xff00)
33826@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33827 {
33828 int ret;
33829
33830- __asm__("lcall *(%%esi); cld\n\t"
33831+ __asm__("movw %w5, %%ds\n\t"
33832+ "lcall *%%ss:(%%esi); cld\n\t"
33833+ "push %%ss\n\t"
33834+ "pop %%ds\n"
33835 "jc 1f\n\t"
33836 "xor %%ah, %%ah\n"
33837 "1:"
33838@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33839 : "0" (PCIBIOS_SET_PCI_HW_INT),
33840 "b" ((dev->bus->number << 8) | dev->devfn),
33841 "c" ((irq << 8) | (pin + 10)),
33842- "S" (&pci_indirect));
33843+ "S" (&pci_indirect),
33844+ "r" (__PCIBIOS_DS));
33845 return !(ret & 0xff00);
33846 }
33847 EXPORT_SYMBOL(pcibios_set_irq_routing);
33848diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33849index 40e4469..d915bf9 100644
33850--- a/arch/x86/platform/efi/efi_32.c
33851+++ b/arch/x86/platform/efi/efi_32.c
33852@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33853 {
33854 struct desc_ptr gdt_descr;
33855
33856+#ifdef CONFIG_PAX_KERNEXEC
33857+ struct desc_struct d;
33858+#endif
33859+
33860 local_irq_save(efi_rt_eflags);
33861
33862 load_cr3(initial_page_table);
33863 __flush_tlb_all();
33864
33865+#ifdef CONFIG_PAX_KERNEXEC
33866+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33867+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33868+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33869+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33870+#endif
33871+
33872 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33873 gdt_descr.size = GDT_SIZE - 1;
33874 load_gdt(&gdt_descr);
33875@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33876 {
33877 struct desc_ptr gdt_descr;
33878
33879+#ifdef CONFIG_PAX_KERNEXEC
33880+ struct desc_struct d;
33881+
33882+ memset(&d, 0, sizeof d);
33883+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33884+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33885+#endif
33886+
33887 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33888 gdt_descr.size = GDT_SIZE - 1;
33889 load_gdt(&gdt_descr);
33890
33891+#ifdef CONFIG_PAX_PER_CPU_PGD
33892+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33893+#else
33894 load_cr3(swapper_pg_dir);
33895+#endif
33896+
33897 __flush_tlb_all();
33898
33899 local_irq_restore(efi_rt_eflags);
33900diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33901index 39a0e7f1..872396e 100644
33902--- a/arch/x86/platform/efi/efi_64.c
33903+++ b/arch/x86/platform/efi/efi_64.c
33904@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33905 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33906 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33907 }
33908+
33909+#ifdef CONFIG_PAX_PER_CPU_PGD
33910+ load_cr3(swapper_pg_dir);
33911+#endif
33912+
33913 __flush_tlb_all();
33914 }
33915
33916@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33917 for (pgd = 0; pgd < n_pgds; pgd++)
33918 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33919 kfree(save_pgd);
33920+
33921+#ifdef CONFIG_PAX_PER_CPU_PGD
33922+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33923+#endif
33924+
33925 __flush_tlb_all();
33926 local_irq_restore(efi_flags);
33927 early_code_mapping_set_exec(0);
33928diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33929index fbe66e6..eae5e38 100644
33930--- a/arch/x86/platform/efi/efi_stub_32.S
33931+++ b/arch/x86/platform/efi/efi_stub_32.S
33932@@ -6,7 +6,9 @@
33933 */
33934
33935 #include <linux/linkage.h>
33936+#include <linux/init.h>
33937 #include <asm/page_types.h>
33938+#include <asm/segment.h>
33939
33940 /*
33941 * efi_call_phys(void *, ...) is a function with variable parameters.
33942@@ -20,7 +22,7 @@
33943 * service functions will comply with gcc calling convention, too.
33944 */
33945
33946-.text
33947+__INIT
33948 ENTRY(efi_call_phys)
33949 /*
33950 * 0. The function can only be called in Linux kernel. So CS has been
33951@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33952 * The mapping of lower virtual memory has been created in prelog and
33953 * epilog.
33954 */
33955- movl $1f, %edx
33956- subl $__PAGE_OFFSET, %edx
33957- jmp *%edx
33958+#ifdef CONFIG_PAX_KERNEXEC
33959+ movl $(__KERNEXEC_EFI_DS), %edx
33960+ mov %edx, %ds
33961+ mov %edx, %es
33962+ mov %edx, %ss
33963+ addl $2f,(1f)
33964+ ljmp *(1f)
33965+
33966+__INITDATA
33967+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33968+.previous
33969+
33970+2:
33971+ subl $2b,(1b)
33972+#else
33973+ jmp 1f-__PAGE_OFFSET
33974 1:
33975+#endif
33976
33977 /*
33978 * 2. Now on the top of stack is the return
33979@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33980 * parameter 2, ..., param n. To make things easy, we save the return
33981 * address of efi_call_phys in a global variable.
33982 */
33983- popl %edx
33984- movl %edx, saved_return_addr
33985- /* get the function pointer into ECX*/
33986- popl %ecx
33987- movl %ecx, efi_rt_function_ptr
33988- movl $2f, %edx
33989- subl $__PAGE_OFFSET, %edx
33990- pushl %edx
33991+ popl (saved_return_addr)
33992+ popl (efi_rt_function_ptr)
33993
33994 /*
33995 * 3. Clear PG bit in %CR0.
33996@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33997 /*
33998 * 5. Call the physical function.
33999 */
34000- jmp *%ecx
34001+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34002
34003-2:
34004 /*
34005 * 6. After EFI runtime service returns, control will return to
34006 * following instruction. We'd better readjust stack pointer first.
34007@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34008 movl %cr0, %edx
34009 orl $0x80000000, %edx
34010 movl %edx, %cr0
34011- jmp 1f
34012-1:
34013+
34014 /*
34015 * 8. Now restore the virtual mode from flat mode by
34016 * adding EIP with PAGE_OFFSET.
34017 */
34018- movl $1f, %edx
34019- jmp *%edx
34020+#ifdef CONFIG_PAX_KERNEXEC
34021+ movl $(__KERNEL_DS), %edx
34022+ mov %edx, %ds
34023+ mov %edx, %es
34024+ mov %edx, %ss
34025+ ljmp $(__KERNEL_CS),$1f
34026+#else
34027+ jmp 1f+__PAGE_OFFSET
34028+#endif
34029 1:
34030
34031 /*
34032 * 9. Balance the stack. And because EAX contain the return value,
34033 * we'd better not clobber it.
34034 */
34035- leal efi_rt_function_ptr, %edx
34036- movl (%edx), %ecx
34037- pushl %ecx
34038+ pushl (efi_rt_function_ptr)
34039
34040 /*
34041- * 10. Push the saved return address onto the stack and return.
34042+ * 10. Return to the saved return address.
34043 */
34044- leal saved_return_addr, %edx
34045- movl (%edx), %ecx
34046- pushl %ecx
34047- ret
34048+ jmpl *(saved_return_addr)
34049 ENDPROC(efi_call_phys)
34050 .previous
34051
34052-.data
34053+__INITDATA
34054 saved_return_addr:
34055 .long 0
34056 efi_rt_function_ptr:
34057diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34058index 4c07cca..2c8427d 100644
34059--- a/arch/x86/platform/efi/efi_stub_64.S
34060+++ b/arch/x86/platform/efi/efi_stub_64.S
34061@@ -7,6 +7,7 @@
34062 */
34063
34064 #include <linux/linkage.h>
34065+#include <asm/alternative-asm.h>
34066
34067 #define SAVE_XMM \
34068 mov %rsp, %rax; \
34069@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34070 call *%rdi
34071 addq $32, %rsp
34072 RESTORE_XMM
34073+ pax_force_retaddr 0, 1
34074 ret
34075 ENDPROC(efi_call0)
34076
34077@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34078 call *%rdi
34079 addq $32, %rsp
34080 RESTORE_XMM
34081+ pax_force_retaddr 0, 1
34082 ret
34083 ENDPROC(efi_call1)
34084
34085@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34086 call *%rdi
34087 addq $32, %rsp
34088 RESTORE_XMM
34089+ pax_force_retaddr 0, 1
34090 ret
34091 ENDPROC(efi_call2)
34092
34093@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34094 call *%rdi
34095 addq $32, %rsp
34096 RESTORE_XMM
34097+ pax_force_retaddr 0, 1
34098 ret
34099 ENDPROC(efi_call3)
34100
34101@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34102 call *%rdi
34103 addq $32, %rsp
34104 RESTORE_XMM
34105+ pax_force_retaddr 0, 1
34106 ret
34107 ENDPROC(efi_call4)
34108
34109@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34110 call *%rdi
34111 addq $48, %rsp
34112 RESTORE_XMM
34113+ pax_force_retaddr 0, 1
34114 ret
34115 ENDPROC(efi_call5)
34116
34117@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34118 call *%rdi
34119 addq $48, %rsp
34120 RESTORE_XMM
34121+ pax_force_retaddr 0, 1
34122 ret
34123 ENDPROC(efi_call6)
34124diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
34125index 3ca5957..7909c18 100644
34126--- a/arch/x86/platform/mrst/mrst.c
34127+++ b/arch/x86/platform/mrst/mrst.c
34128@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
34129 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
34130 int sfi_mrtc_num;
34131
34132-static void mrst_power_off(void)
34133+static __noreturn void mrst_power_off(void)
34134 {
34135+ BUG();
34136 }
34137
34138-static void mrst_reboot(void)
34139+static __noreturn void mrst_reboot(void)
34140 {
34141 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34142+ BUG();
34143 }
34144
34145 /* parse all the mtimer info to a static mtimer array */
34146diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34147index d6ee929..3637cb5 100644
34148--- a/arch/x86/platform/olpc/olpc_dt.c
34149+++ b/arch/x86/platform/olpc/olpc_dt.c
34150@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34151 return res;
34152 }
34153
34154-static struct of_pdt_ops prom_olpc_ops __initdata = {
34155+static struct of_pdt_ops prom_olpc_ops __initconst = {
34156 .nextprop = olpc_dt_nextprop,
34157 .getproplen = olpc_dt_getproplen,
34158 .getproperty = olpc_dt_getproperty,
34159diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34160index 424f4c9..f2a2988 100644
34161--- a/arch/x86/power/cpu.c
34162+++ b/arch/x86/power/cpu.c
34163@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34164 static void fix_processor_context(void)
34165 {
34166 int cpu = smp_processor_id();
34167- struct tss_struct *t = &per_cpu(init_tss, cpu);
34168-#ifdef CONFIG_X86_64
34169- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34170- tss_desc tss;
34171-#endif
34172+ struct tss_struct *t = init_tss + cpu;
34173+
34174 set_tss_desc(cpu, t); /*
34175 * This just modifies memory; should not be
34176 * necessary. But... This is necessary, because
34177@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34178 */
34179
34180 #ifdef CONFIG_X86_64
34181- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34182- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34183- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34184-
34185 syscall_init(); /* This sets MSR_*STAR and related */
34186 #endif
34187 load_TR_desc(); /* This does ltr */
34188diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34189index a44f457..9140171 100644
34190--- a/arch/x86/realmode/init.c
34191+++ b/arch/x86/realmode/init.c
34192@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34193 __va(real_mode_header->trampoline_header);
34194
34195 #ifdef CONFIG_X86_32
34196- trampoline_header->start = __pa_symbol(startup_32_smp);
34197+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34198+
34199+#ifdef CONFIG_PAX_KERNEXEC
34200+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34201+#endif
34202+
34203+ trampoline_header->boot_cs = __BOOT_CS;
34204 trampoline_header->gdt_limit = __BOOT_DS + 7;
34205 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34206 #else
34207@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34208 *trampoline_cr4_features = read_cr4();
34209
34210 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34211- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34212+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34213 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34214 #endif
34215 }
34216diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34217index 8869287..d577672 100644
34218--- a/arch/x86/realmode/rm/Makefile
34219+++ b/arch/x86/realmode/rm/Makefile
34220@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34221 $(call cc-option, -fno-unit-at-a-time)) \
34222 $(call cc-option, -fno-stack-protector) \
34223 $(call cc-option, -mpreferred-stack-boundary=2)
34224+ifdef CONSTIFY_PLUGIN
34225+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34226+endif
34227 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34228 GCOV_PROFILE := n
34229diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34230index a28221d..93c40f1 100644
34231--- a/arch/x86/realmode/rm/header.S
34232+++ b/arch/x86/realmode/rm/header.S
34233@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34234 #endif
34235 /* APM/BIOS reboot */
34236 .long pa_machine_real_restart_asm
34237-#ifdef CONFIG_X86_64
34238+#ifdef CONFIG_X86_32
34239+ .long __KERNEL_CS
34240+#else
34241 .long __KERNEL32_CS
34242 #endif
34243 END(real_mode_header)
34244diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34245index c1b2791..f9e31c7 100644
34246--- a/arch/x86/realmode/rm/trampoline_32.S
34247+++ b/arch/x86/realmode/rm/trampoline_32.S
34248@@ -25,6 +25,12 @@
34249 #include <asm/page_types.h>
34250 #include "realmode.h"
34251
34252+#ifdef CONFIG_PAX_KERNEXEC
34253+#define ta(X) (X)
34254+#else
34255+#define ta(X) (pa_ ## X)
34256+#endif
34257+
34258 .text
34259 .code16
34260
34261@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34262
34263 cli # We should be safe anyway
34264
34265- movl tr_start, %eax # where we need to go
34266-
34267 movl $0xA5A5A5A5, trampoline_status
34268 # write marker for master knows we're running
34269
34270@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34271 movw $1, %dx # protected mode (PE) bit
34272 lmsw %dx # into protected mode
34273
34274- ljmpl $__BOOT_CS, $pa_startup_32
34275+ ljmpl *(trampoline_header)
34276
34277 .section ".text32","ax"
34278 .code32
34279@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34280 .balign 8
34281 GLOBAL(trampoline_header)
34282 tr_start: .space 4
34283- tr_gdt_pad: .space 2
34284+ tr_boot_cs: .space 2
34285 tr_gdt: .space 6
34286 END(trampoline_header)
34287
34288diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34289index bb360dc..d0fd8f8 100644
34290--- a/arch/x86/realmode/rm/trampoline_64.S
34291+++ b/arch/x86/realmode/rm/trampoline_64.S
34292@@ -94,6 +94,7 @@ ENTRY(startup_32)
34293 movl %edx, %gs
34294
34295 movl pa_tr_cr4, %eax
34296+ andl $~X86_CR4_PCIDE, %eax
34297 movl %eax, %cr4 # Enable PAE mode
34298
34299 # Setup trampoline 4 level pagetables
34300@@ -107,7 +108,7 @@ ENTRY(startup_32)
34301 wrmsr
34302
34303 # Enable paging and in turn activate Long Mode
34304- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34305+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34306 movl %eax, %cr0
34307
34308 /*
34309diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34310index e812034..c747134 100644
34311--- a/arch/x86/tools/Makefile
34312+++ b/arch/x86/tools/Makefile
34313@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34314
34315 $(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
34316
34317-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34318+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34319 hostprogs-y += relocs
34320 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34321 relocs: $(obj)/relocs
34322diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34323index f7bab68..b6d9886 100644
34324--- a/arch/x86/tools/relocs.c
34325+++ b/arch/x86/tools/relocs.c
34326@@ -1,5 +1,7 @@
34327 /* This is included from relocs_32/64.c */
34328
34329+#include "../../../include/generated/autoconf.h"
34330+
34331 #define ElfW(type) _ElfW(ELF_BITS, type)
34332 #define _ElfW(bits, type) __ElfW(bits, type)
34333 #define __ElfW(bits, type) Elf##bits##_##type
34334@@ -11,6 +13,7 @@
34335 #define Elf_Sym ElfW(Sym)
34336
34337 static Elf_Ehdr ehdr;
34338+static Elf_Phdr *phdr;
34339
34340 struct relocs {
34341 uint32_t *offset;
34342@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34343 }
34344 }
34345
34346+static void read_phdrs(FILE *fp)
34347+{
34348+ unsigned int i;
34349+
34350+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34351+ if (!phdr) {
34352+ die("Unable to allocate %d program headers\n",
34353+ ehdr.e_phnum);
34354+ }
34355+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34356+ die("Seek to %d failed: %s\n",
34357+ ehdr.e_phoff, strerror(errno));
34358+ }
34359+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34360+ die("Cannot read ELF program headers: %s\n",
34361+ strerror(errno));
34362+ }
34363+ for(i = 0; i < ehdr.e_phnum; i++) {
34364+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34365+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34366+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34367+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34368+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34369+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34370+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34371+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34372+ }
34373+
34374+}
34375+
34376 static void read_shdrs(FILE *fp)
34377 {
34378- int i;
34379+ unsigned int i;
34380 Elf_Shdr shdr;
34381
34382 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34383@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34384
34385 static void read_strtabs(FILE *fp)
34386 {
34387- int i;
34388+ unsigned int i;
34389 for (i = 0; i < ehdr.e_shnum; i++) {
34390 struct section *sec = &secs[i];
34391 if (sec->shdr.sh_type != SHT_STRTAB) {
34392@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34393
34394 static void read_symtabs(FILE *fp)
34395 {
34396- int i,j;
34397+ unsigned int i,j;
34398 for (i = 0; i < ehdr.e_shnum; i++) {
34399 struct section *sec = &secs[i];
34400 if (sec->shdr.sh_type != SHT_SYMTAB) {
34401@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34402 }
34403
34404
34405-static void read_relocs(FILE *fp)
34406+static void read_relocs(FILE *fp, int use_real_mode)
34407 {
34408- int i,j;
34409+ unsigned int i,j;
34410+ uint32_t base;
34411+
34412 for (i = 0; i < ehdr.e_shnum; i++) {
34413 struct section *sec = &secs[i];
34414 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34415@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34416 die("Cannot read symbol table: %s\n",
34417 strerror(errno));
34418 }
34419+ base = 0;
34420+
34421+#ifdef CONFIG_X86_32
34422+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34423+ if (phdr[j].p_type != PT_LOAD )
34424+ continue;
34425+ 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)
34426+ continue;
34427+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34428+ break;
34429+ }
34430+#endif
34431+
34432 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34433 Elf_Rel *rel = &sec->reltab[j];
34434- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34435+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34436 rel->r_info = elf_xword_to_cpu(rel->r_info);
34437 #if (SHT_REL_TYPE == SHT_RELA)
34438 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34439@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34440
34441 static void print_absolute_symbols(void)
34442 {
34443- int i;
34444+ unsigned int i;
34445 const char *format;
34446
34447 if (ELF_BITS == 64)
34448@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34449 for (i = 0; i < ehdr.e_shnum; i++) {
34450 struct section *sec = &secs[i];
34451 char *sym_strtab;
34452- int j;
34453+ unsigned int j;
34454
34455 if (sec->shdr.sh_type != SHT_SYMTAB) {
34456 continue;
34457@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34458
34459 static void print_absolute_relocs(void)
34460 {
34461- int i, printed = 0;
34462+ unsigned int i, printed = 0;
34463 const char *format;
34464
34465 if (ELF_BITS == 64)
34466@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34467 struct section *sec_applies, *sec_symtab;
34468 char *sym_strtab;
34469 Elf_Sym *sh_symtab;
34470- int j;
34471+ unsigned int j;
34472 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34473 continue;
34474 }
34475@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34476 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34477 Elf_Sym *sym, const char *symname))
34478 {
34479- int i;
34480+ unsigned int i;
34481 /* Walk through the relocations */
34482 for (i = 0; i < ehdr.e_shnum; i++) {
34483 char *sym_strtab;
34484 Elf_Sym *sh_symtab;
34485 struct section *sec_applies, *sec_symtab;
34486- int j;
34487+ unsigned int j;
34488 struct section *sec = &secs[i];
34489
34490 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34491@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34492 {
34493 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34494 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34495+ char *sym_strtab = sec->link->link->strtab;
34496+
34497+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34498+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34499+ return 0;
34500+
34501+#ifdef CONFIG_PAX_KERNEXEC
34502+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34503+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34504+ return 0;
34505+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34506+ return 0;
34507+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34508+ return 0;
34509+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34510+ return 0;
34511+#endif
34512
34513 switch (r_type) {
34514 case R_386_NONE:
34515@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34516
34517 static void emit_relocs(int as_text, int use_real_mode)
34518 {
34519- int i;
34520+ unsigned int i;
34521 int (*write_reloc)(uint32_t, FILE *) = write32;
34522 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34523 const char *symname);
34524@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34525 {
34526 regex_init(use_real_mode);
34527 read_ehdr(fp);
34528+ read_phdrs(fp);
34529 read_shdrs(fp);
34530 read_strtabs(fp);
34531 read_symtabs(fp);
34532- read_relocs(fp);
34533+ read_relocs(fp, use_real_mode);
34534 if (ELF_BITS == 64)
34535 percpu_init();
34536 if (show_absolute_syms) {
34537diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34538index 80ffa5b..a33bd15 100644
34539--- a/arch/x86/um/tls_32.c
34540+++ b/arch/x86/um/tls_32.c
34541@@ -260,7 +260,7 @@ out:
34542 if (unlikely(task == current &&
34543 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34544 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34545- "without flushed TLS.", current->pid);
34546+ "without flushed TLS.", task_pid_nr(current));
34547 }
34548
34549 return 0;
34550diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34551index fd14be1..e3c79c0 100644
34552--- a/arch/x86/vdso/Makefile
34553+++ b/arch/x86/vdso/Makefile
34554@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34555 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34556 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34557
34558-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34559+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34560 GCOV_PROFILE := n
34561
34562 #
34563diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34564index d6bfb87..876ee18 100644
34565--- a/arch/x86/vdso/vdso32-setup.c
34566+++ b/arch/x86/vdso/vdso32-setup.c
34567@@ -25,6 +25,7 @@
34568 #include <asm/tlbflush.h>
34569 #include <asm/vdso.h>
34570 #include <asm/proto.h>
34571+#include <asm/mman.h>
34572
34573 enum {
34574 VDSO_DISABLED = 0,
34575@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34576 void enable_sep_cpu(void)
34577 {
34578 int cpu = get_cpu();
34579- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34580+ struct tss_struct *tss = init_tss + cpu;
34581
34582 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34583 put_cpu();
34584@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34585 gate_vma.vm_start = FIXADDR_USER_START;
34586 gate_vma.vm_end = FIXADDR_USER_END;
34587 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34588- gate_vma.vm_page_prot = __P101;
34589+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34590
34591 return 0;
34592 }
34593@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34594 if (compat)
34595 addr = VDSO_HIGH_BASE;
34596 else {
34597- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34598+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34599 if (IS_ERR_VALUE(addr)) {
34600 ret = addr;
34601 goto up_fail;
34602 }
34603 }
34604
34605- current->mm->context.vdso = (void *)addr;
34606+ current->mm->context.vdso = addr;
34607
34608 if (compat_uses_vma || !compat) {
34609 /*
34610@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34611 }
34612
34613 current_thread_info()->sysenter_return =
34614- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34615+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34616
34617 up_fail:
34618 if (ret)
34619- current->mm->context.vdso = NULL;
34620+ current->mm->context.vdso = 0;
34621
34622 up_write(&mm->mmap_sem);
34623
34624@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34625
34626 const char *arch_vma_name(struct vm_area_struct *vma)
34627 {
34628- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34629+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34630 return "[vdso]";
34631+
34632+#ifdef CONFIG_PAX_SEGMEXEC
34633+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34634+ return "[vdso]";
34635+#endif
34636+
34637 return NULL;
34638 }
34639
34640@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34641 * Check to see if the corresponding task was created in compat vdso
34642 * mode.
34643 */
34644- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34645+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34646 return &gate_vma;
34647 return NULL;
34648 }
34649diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34650index 431e875..cbb23f3 100644
34651--- a/arch/x86/vdso/vma.c
34652+++ b/arch/x86/vdso/vma.c
34653@@ -16,8 +16,6 @@
34654 #include <asm/vdso.h>
34655 #include <asm/page.h>
34656
34657-unsigned int __read_mostly vdso_enabled = 1;
34658-
34659 extern char vdso_start[], vdso_end[];
34660 extern unsigned short vdso_sync_cpuid;
34661
34662@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34663 * unaligned here as a result of stack start randomization.
34664 */
34665 addr = PAGE_ALIGN(addr);
34666- addr = align_vdso_addr(addr);
34667
34668 return addr;
34669 }
34670@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34671 unsigned size)
34672 {
34673 struct mm_struct *mm = current->mm;
34674- unsigned long addr;
34675+ unsigned long addr = 0;
34676 int ret;
34677
34678- if (!vdso_enabled)
34679- return 0;
34680-
34681 down_write(&mm->mmap_sem);
34682+
34683+#ifdef CONFIG_PAX_RANDMMAP
34684+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34685+#endif
34686+
34687 addr = vdso_addr(mm->start_stack, size);
34688+ addr = align_vdso_addr(addr);
34689 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34690 if (IS_ERR_VALUE(addr)) {
34691 ret = addr;
34692 goto up_fail;
34693 }
34694
34695- current->mm->context.vdso = (void *)addr;
34696+ mm->context.vdso = addr;
34697
34698 ret = install_special_mapping(mm, addr, size,
34699 VM_READ|VM_EXEC|
34700 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34701 pages);
34702- if (ret) {
34703- current->mm->context.vdso = NULL;
34704- goto up_fail;
34705- }
34706+ if (ret)
34707+ mm->context.vdso = 0;
34708
34709 up_fail:
34710 up_write(&mm->mmap_sem);
34711@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34712 vdsox32_size);
34713 }
34714 #endif
34715-
34716-static __init int vdso_setup(char *s)
34717-{
34718- vdso_enabled = simple_strtoul(s, NULL, 0);
34719- return 0;
34720-}
34721-__setup("vdso=", vdso_setup);
34722diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34723index fa6ade7..73da73a5 100644
34724--- a/arch/x86/xen/enlighten.c
34725+++ b/arch/x86/xen/enlighten.c
34726@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34727
34728 struct shared_info xen_dummy_shared_info;
34729
34730-void *xen_initial_gdt;
34731-
34732 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34733 __read_mostly int xen_have_vector_callback;
34734 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34735@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34736 {
34737 unsigned long va = dtr->address;
34738 unsigned int size = dtr->size + 1;
34739- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34740- unsigned long frames[pages];
34741+ unsigned long frames[65536 / PAGE_SIZE];
34742 int f;
34743
34744 /*
34745@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34746 {
34747 unsigned long va = dtr->address;
34748 unsigned int size = dtr->size + 1;
34749- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34750- unsigned long frames[pages];
34751+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34752 int f;
34753
34754 /*
34755@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34756 * 8-byte entries, or 16 4k pages..
34757 */
34758
34759- BUG_ON(size > 65536);
34760+ BUG_ON(size > GDT_SIZE);
34761 BUG_ON(va & ~PAGE_MASK);
34762
34763 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34764@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34765 return 0;
34766 }
34767
34768-static void set_xen_basic_apic_ops(void)
34769+static void __init set_xen_basic_apic_ops(void)
34770 {
34771 apic->read = xen_apic_read;
34772 apic->write = xen_apic_write;
34773@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34774 #endif
34775 };
34776
34777-static void xen_reboot(int reason)
34778+static __noreturn void xen_reboot(int reason)
34779 {
34780 struct sched_shutdown r = { .reason = reason };
34781
34782- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34783- BUG();
34784+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34785+ BUG();
34786 }
34787
34788-static void xen_restart(char *msg)
34789+static __noreturn void xen_restart(char *msg)
34790 {
34791 xen_reboot(SHUTDOWN_reboot);
34792 }
34793
34794-static void xen_emergency_restart(void)
34795+static __noreturn void xen_emergency_restart(void)
34796 {
34797 xen_reboot(SHUTDOWN_reboot);
34798 }
34799
34800-static void xen_machine_halt(void)
34801+static __noreturn void xen_machine_halt(void)
34802 {
34803 xen_reboot(SHUTDOWN_poweroff);
34804 }
34805
34806-static void xen_machine_power_off(void)
34807+static __noreturn void xen_machine_power_off(void)
34808 {
34809 if (pm_power_off)
34810 pm_power_off();
34811@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34812 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34813
34814 /* Work out if we support NX */
34815- x86_configure_nx();
34816+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34817+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34818+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34819+ unsigned l, h;
34820+
34821+ __supported_pte_mask |= _PAGE_NX;
34822+ rdmsr(MSR_EFER, l, h);
34823+ l |= EFER_NX;
34824+ wrmsr(MSR_EFER, l, h);
34825+ }
34826+#endif
34827
34828 xen_setup_features();
34829
34830@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34831
34832 machine_ops = xen_machine_ops;
34833
34834- /*
34835- * The only reliable way to retain the initial address of the
34836- * percpu gdt_page is to remember it here, so we can go and
34837- * mark it RW later, when the initial percpu area is freed.
34838- */
34839- xen_initial_gdt = &per_cpu(gdt_page, 0);
34840-
34841 xen_smp_init();
34842
34843 #ifdef CONFIG_ACPI_NUMA
34844diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34845index fdc3ba2..23cae00 100644
34846--- a/arch/x86/xen/mmu.c
34847+++ b/arch/x86/xen/mmu.c
34848@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34849 return val;
34850 }
34851
34852-static pteval_t pte_pfn_to_mfn(pteval_t val)
34853+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34854 {
34855 if (val & _PAGE_PRESENT) {
34856 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34857@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34858 /* L3_k[510] -> level2_kernel_pgt
34859 * L3_i[511] -> level2_fixmap_pgt */
34860 convert_pfn_mfn(level3_kernel_pgt);
34861+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34862+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34863+ convert_pfn_mfn(level3_vmemmap_pgt);
34864
34865 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34866 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34867@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34868 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34869 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34870 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34871+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34872+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34873+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34874 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34875 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34876+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34877 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34878 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34879
34880@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34881 pv_mmu_ops.set_pud = xen_set_pud;
34882 #if PAGETABLE_LEVELS == 4
34883 pv_mmu_ops.set_pgd = xen_set_pgd;
34884+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34885 #endif
34886
34887 /* This will work as long as patching hasn't happened yet
34888@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34889 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34890 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34891 .set_pgd = xen_set_pgd_hyper,
34892+ .set_pgd_batched = xen_set_pgd_hyper,
34893
34894 .alloc_pud = xen_alloc_pmd_init,
34895 .release_pud = xen_release_pmd_init,
34896diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34897index 31d0475..51af671 100644
34898--- a/arch/x86/xen/smp.c
34899+++ b/arch/x86/xen/smp.c
34900@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34901 native_smp_prepare_boot_cpu();
34902
34903 if (xen_pv_domain()) {
34904- /* We've switched to the "real" per-cpu gdt, so make sure the
34905- old memory can be recycled */
34906- make_lowmem_page_readwrite(xen_initial_gdt);
34907-
34908 #ifdef CONFIG_X86_32
34909 /*
34910 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34911 * expects __USER_DS
34912 */
34913- loadsegment(ds, __USER_DS);
34914- loadsegment(es, __USER_DS);
34915+ loadsegment(ds, __KERNEL_DS);
34916+ loadsegment(es, __KERNEL_DS);
34917 #endif
34918
34919 xen_filter_cpu_maps();
34920@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34921 ctxt->user_regs.ss = __KERNEL_DS;
34922 #ifdef CONFIG_X86_32
34923 ctxt->user_regs.fs = __KERNEL_PERCPU;
34924- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34925+ savesegment(gs, ctxt->user_regs.gs);
34926 #else
34927 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34928 #endif
34929@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34930
34931 {
34932 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34933- ctxt->user_regs.ds = __USER_DS;
34934- ctxt->user_regs.es = __USER_DS;
34935+ ctxt->user_regs.ds = __KERNEL_DS;
34936+ ctxt->user_regs.es = __KERNEL_DS;
34937
34938 xen_copy_trap_info(ctxt->trap_ctxt);
34939
34940@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34941 int rc;
34942
34943 per_cpu(current_task, cpu) = idle;
34944+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34945 #ifdef CONFIG_X86_32
34946 irq_ctx_init(cpu);
34947 #else
34948 clear_tsk_thread_flag(idle, TIF_FORK);
34949- per_cpu(kernel_stack, cpu) =
34950- (unsigned long)task_stack_page(idle) -
34951- KERNEL_STACK_OFFSET + THREAD_SIZE;
34952+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34953 #endif
34954 xen_setup_runstate_info(cpu);
34955 xen_setup_timer(cpu);
34956@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34957
34958 void __init xen_smp_init(void)
34959 {
34960- smp_ops = xen_smp_ops;
34961+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34962 xen_fill_possible_map();
34963 }
34964
34965diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34966index 33ca6e4..0ded929 100644
34967--- a/arch/x86/xen/xen-asm_32.S
34968+++ b/arch/x86/xen/xen-asm_32.S
34969@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34970 ESP_OFFSET=4 # bytes pushed onto stack
34971
34972 /*
34973- * Store vcpu_info pointer for easy access. Do it this way to
34974- * avoid having to reload %fs
34975+ * Store vcpu_info pointer for easy access.
34976 */
34977 #ifdef CONFIG_SMP
34978- GET_THREAD_INFO(%eax)
34979- movl %ss:TI_cpu(%eax), %eax
34980- movl %ss:__per_cpu_offset(,%eax,4), %eax
34981- mov %ss:xen_vcpu(%eax), %eax
34982+ push %fs
34983+ mov $(__KERNEL_PERCPU), %eax
34984+ mov %eax, %fs
34985+ mov PER_CPU_VAR(xen_vcpu), %eax
34986+ pop %fs
34987 #else
34988 movl %ss:xen_vcpu, %eax
34989 #endif
34990diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34991index 7faed58..ba4427c 100644
34992--- a/arch/x86/xen/xen-head.S
34993+++ b/arch/x86/xen/xen-head.S
34994@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34995 #ifdef CONFIG_X86_32
34996 mov %esi,xen_start_info
34997 mov $init_thread_union+THREAD_SIZE,%esp
34998+#ifdef CONFIG_SMP
34999+ movl $cpu_gdt_table,%edi
35000+ movl $__per_cpu_load,%eax
35001+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35002+ rorl $16,%eax
35003+ movb %al,__KERNEL_PERCPU + 4(%edi)
35004+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35005+ movl $__per_cpu_end - 1,%eax
35006+ subl $__per_cpu_start,%eax
35007+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35008+#endif
35009 #else
35010 mov %rsi,xen_start_info
35011 mov $init_thread_union+THREAD_SIZE,%rsp
35012diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35013index 95f8c61..611d6e8 100644
35014--- a/arch/x86/xen/xen-ops.h
35015+++ b/arch/x86/xen/xen-ops.h
35016@@ -10,8 +10,6 @@
35017 extern const char xen_hypervisor_callback[];
35018 extern const char xen_failsafe_callback[];
35019
35020-extern void *xen_initial_gdt;
35021-
35022 struct trap_info;
35023 void xen_copy_trap_info(struct trap_info *traps);
35024
35025diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35026index 525bd3d..ef888b1 100644
35027--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35028+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35029@@ -119,9 +119,9 @@
35030 ----------------------------------------------------------------------*/
35031
35032 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35033-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35034 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35035 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35036+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35037
35038 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35039 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35040diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35041index 2f33760..835e50a 100644
35042--- a/arch/xtensa/variants/fsf/include/variant/core.h
35043+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35044@@ -11,6 +11,7 @@
35045 #ifndef _XTENSA_CORE_H
35046 #define _XTENSA_CORE_H
35047
35048+#include <linux/const.h>
35049
35050 /****************************************************************************
35051 Parameters Useful for Any Code, USER or PRIVILEGED
35052@@ -112,9 +113,9 @@
35053 ----------------------------------------------------------------------*/
35054
35055 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35056-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35057 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35058 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35059+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35060
35061 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35062 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35063diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35064index af00795..2bb8105 100644
35065--- a/arch/xtensa/variants/s6000/include/variant/core.h
35066+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35067@@ -11,6 +11,7 @@
35068 #ifndef _XTENSA_CORE_CONFIGURATION_H
35069 #define _XTENSA_CORE_CONFIGURATION_H
35070
35071+#include <linux/const.h>
35072
35073 /****************************************************************************
35074 Parameters Useful for Any Code, USER or PRIVILEGED
35075@@ -118,9 +119,9 @@
35076 ----------------------------------------------------------------------*/
35077
35078 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35079-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35080 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35081 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35082+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35083
35084 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35085 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35086diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35087index 4e491d9..c8e18e4 100644
35088--- a/block/blk-cgroup.c
35089+++ b/block/blk-cgroup.c
35090@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35091 static struct cgroup_subsys_state *
35092 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35093 {
35094- static atomic64_t id_seq = ATOMIC64_INIT(0);
35095+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35096 struct blkcg *blkcg;
35097
35098 if (!parent_css) {
35099@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35100
35101 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35102 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35103- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35104+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35105 done:
35106 spin_lock_init(&blkcg->lock);
35107 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35108diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35109index 4b8d9b54..a7178c0 100644
35110--- a/block/blk-iopoll.c
35111+++ b/block/blk-iopoll.c
35112@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35113 }
35114 EXPORT_SYMBOL(blk_iopoll_complete);
35115
35116-static void blk_iopoll_softirq(struct softirq_action *h)
35117+static __latent_entropy void blk_iopoll_softirq(void)
35118 {
35119 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
35120 int rearm = 0, budget = blk_iopoll_budget;
35121diff --git a/block/blk-map.c b/block/blk-map.c
35122index 623e1cd..ca1e109 100644
35123--- a/block/blk-map.c
35124+++ b/block/blk-map.c
35125@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35126 if (!len || !kbuf)
35127 return -EINVAL;
35128
35129- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35130+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35131 if (do_copy)
35132 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35133 else
35134diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35135index ec9e606..3f38839 100644
35136--- a/block/blk-softirq.c
35137+++ b/block/blk-softirq.c
35138@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35139 * Softirq action handler - move entries to local list and loop over them
35140 * while passing them to the queue registered handler.
35141 */
35142-static void blk_done_softirq(struct softirq_action *h)
35143+static __latent_entropy void blk_done_softirq(void)
35144 {
35145 struct list_head *cpu_list, local_list;
35146
35147diff --git a/block/bsg.c b/block/bsg.c
35148index 420a5a9..23834aa 100644
35149--- a/block/bsg.c
35150+++ b/block/bsg.c
35151@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35152 struct sg_io_v4 *hdr, struct bsg_device *bd,
35153 fmode_t has_write_perm)
35154 {
35155+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35156+ unsigned char *cmdptr;
35157+
35158 if (hdr->request_len > BLK_MAX_CDB) {
35159 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35160 if (!rq->cmd)
35161 return -ENOMEM;
35162- }
35163+ cmdptr = rq->cmd;
35164+ } else
35165+ cmdptr = tmpcmd;
35166
35167- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35168+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35169 hdr->request_len))
35170 return -EFAULT;
35171
35172+ if (cmdptr != rq->cmd)
35173+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35174+
35175 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35176 if (blk_verify_command(rq->cmd, has_write_perm))
35177 return -EPERM;
35178diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35179index fbd5a67..5d631b5 100644
35180--- a/block/compat_ioctl.c
35181+++ b/block/compat_ioctl.c
35182@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35183 err |= __get_user(f->spec1, &uf->spec1);
35184 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35185 err |= __get_user(name, &uf->name);
35186- f->name = compat_ptr(name);
35187+ f->name = (void __force_kernel *)compat_ptr(name);
35188 if (err) {
35189 err = -EFAULT;
35190 goto out;
35191diff --git a/block/genhd.c b/block/genhd.c
35192index 791f419..89f21c4 100644
35193--- a/block/genhd.c
35194+++ b/block/genhd.c
35195@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35196
35197 /*
35198 * Register device numbers dev..(dev+range-1)
35199- * range must be nonzero
35200+ * Noop if @range is zero.
35201 * The hash chain is sorted on range, so that subranges can override.
35202 */
35203 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35204 struct kobject *(*probe)(dev_t, int *, void *),
35205 int (*lock)(dev_t, void *), void *data)
35206 {
35207- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35208+ if (range)
35209+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35210 }
35211
35212 EXPORT_SYMBOL(blk_register_region);
35213
35214+/* undo blk_register_region(), noop if @range is zero */
35215 void blk_unregister_region(dev_t devt, unsigned long range)
35216 {
35217- kobj_unmap(bdev_map, devt, range);
35218+ if (range)
35219+ kobj_unmap(bdev_map, devt, range);
35220 }
35221
35222 EXPORT_SYMBOL(blk_unregister_region);
35223diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35224index a8287b4..241a48e 100644
35225--- a/block/partitions/efi.c
35226+++ b/block/partitions/efi.c
35227@@ -292,14 +292,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35228 if (!gpt)
35229 return NULL;
35230
35231+ if (!le32_to_cpu(gpt->num_partition_entries))
35232+ return NULL;
35233+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35234+ if (!pte)
35235+ return NULL;
35236+
35237 count = le32_to_cpu(gpt->num_partition_entries) *
35238 le32_to_cpu(gpt->sizeof_partition_entry);
35239- if (!count)
35240- return NULL;
35241- pte = kmalloc(count, GFP_KERNEL);
35242- if (!pte)
35243- return NULL;
35244-
35245 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35246 (u8 *) pte, count) < count) {
35247 kfree(pte);
35248diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35249index a5ffcc9..e057498 100644
35250--- a/block/scsi_ioctl.c
35251+++ b/block/scsi_ioctl.c
35252@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35253 return put_user(0, p);
35254 }
35255
35256-static int sg_get_timeout(struct request_queue *q)
35257+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35258 {
35259 return jiffies_to_clock_t(q->sg_timeout);
35260 }
35261@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35262 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35263 struct sg_io_hdr *hdr, fmode_t mode)
35264 {
35265- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35266+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35267+ unsigned char *cmdptr;
35268+
35269+ if (rq->cmd != rq->__cmd)
35270+ cmdptr = rq->cmd;
35271+ else
35272+ cmdptr = tmpcmd;
35273+
35274+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35275 return -EFAULT;
35276+
35277+ if (cmdptr != rq->cmd)
35278+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35279+
35280 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35281 return -EPERM;
35282
35283@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35284 int err;
35285 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35286 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35287+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35288+ unsigned char *cmdptr;
35289
35290 if (!sic)
35291 return -EINVAL;
35292@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35293 */
35294 err = -EFAULT;
35295 rq->cmd_len = cmdlen;
35296- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35297+
35298+ if (rq->cmd != rq->__cmd)
35299+ cmdptr = rq->cmd;
35300+ else
35301+ cmdptr = tmpcmd;
35302+
35303+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35304 goto error;
35305
35306+ if (rq->cmd != cmdptr)
35307+ memcpy(rq->cmd, cmdptr, cmdlen);
35308+
35309 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35310 goto error;
35311
35312diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35313index 7bdd61b..afec999 100644
35314--- a/crypto/cryptd.c
35315+++ b/crypto/cryptd.c
35316@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35317
35318 struct cryptd_blkcipher_request_ctx {
35319 crypto_completion_t complete;
35320-};
35321+} __no_const;
35322
35323 struct cryptd_hash_ctx {
35324 struct crypto_shash *child;
35325@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35326
35327 struct cryptd_aead_request_ctx {
35328 crypto_completion_t complete;
35329-};
35330+} __no_const;
35331
35332 static void cryptd_queue_worker(struct work_struct *work);
35333
35334diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35335index f8c920c..ab2cb5a 100644
35336--- a/crypto/pcrypt.c
35337+++ b/crypto/pcrypt.c
35338@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35339 int ret;
35340
35341 pinst->kobj.kset = pcrypt_kset;
35342- ret = kobject_add(&pinst->kobj, NULL, name);
35343+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35344 if (!ret)
35345 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35346
35347diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35348index f220d64..d359ad6 100644
35349--- a/drivers/acpi/apei/apei-internal.h
35350+++ b/drivers/acpi/apei/apei-internal.h
35351@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35352 struct apei_exec_ins_type {
35353 u32 flags;
35354 apei_exec_ins_func_t run;
35355-};
35356+} __do_const;
35357
35358 struct apei_exec_context {
35359 u32 ip;
35360diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
35361index 33dc6a0..4b24b47 100644
35362--- a/drivers/acpi/apei/cper.c
35363+++ b/drivers/acpi/apei/cper.c
35364@@ -39,12 +39,12 @@
35365 */
35366 u64 cper_next_record_id(void)
35367 {
35368- static atomic64_t seq;
35369+ static atomic64_unchecked_t seq;
35370
35371- if (!atomic64_read(&seq))
35372- atomic64_set(&seq, ((u64)get_seconds()) << 32);
35373+ if (!atomic64_read_unchecked(&seq))
35374+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
35375
35376- return atomic64_inc_return(&seq);
35377+ return atomic64_inc_return_unchecked(&seq);
35378 }
35379 EXPORT_SYMBOL_GPL(cper_next_record_id);
35380
35381diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35382index 8ec37bb..b0716e5 100644
35383--- a/drivers/acpi/apei/ghes.c
35384+++ b/drivers/acpi/apei/ghes.c
35385@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35386 const struct acpi_hest_generic *generic,
35387 const struct acpi_hest_generic_status *estatus)
35388 {
35389- static atomic_t seqno;
35390+ static atomic_unchecked_t seqno;
35391 unsigned int curr_seqno;
35392 char pfx_seq[64];
35393
35394@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35395 else
35396 pfx = KERN_ERR;
35397 }
35398- curr_seqno = atomic_inc_return(&seqno);
35399+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35400 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35401 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35402 pfx_seq, generic->header.source_id);
35403diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35404index a83e3c6..c3d617f 100644
35405--- a/drivers/acpi/bgrt.c
35406+++ b/drivers/acpi/bgrt.c
35407@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35408 if (!bgrt_image)
35409 return -ENODEV;
35410
35411- bin_attr_image.private = bgrt_image;
35412- bin_attr_image.size = bgrt_image_size;
35413+ pax_open_kernel();
35414+ *(void **)&bin_attr_image.private = bgrt_image;
35415+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35416+ pax_close_kernel();
35417
35418 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35419 if (!bgrt_kobj)
35420diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35421index 9515f18..4b149c9 100644
35422--- a/drivers/acpi/blacklist.c
35423+++ b/drivers/acpi/blacklist.c
35424@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35425 u32 is_critical_error;
35426 };
35427
35428-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35429+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35430
35431 /*
35432 * POLICY: If *anything* doesn't work, put it on the blacklist.
35433@@ -199,7 +199,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35434 return 0;
35435 }
35436
35437-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35438+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35439 {
35440 .callback = dmi_disable_osi_vista,
35441 .ident = "Fujitsu Siemens",
35442diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35443index c7414a5..d5afd71 100644
35444--- a/drivers/acpi/processor_idle.c
35445+++ b/drivers/acpi/processor_idle.c
35446@@ -966,7 +966,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35447 {
35448 int i, count = CPUIDLE_DRIVER_STATE_START;
35449 struct acpi_processor_cx *cx;
35450- struct cpuidle_state *state;
35451+ cpuidle_state_no_const *state;
35452 struct cpuidle_driver *drv = &acpi_idle_driver;
35453
35454 if (!pr->flags.power_setup_done)
35455diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35456index 05306a5..733d1f0 100644
35457--- a/drivers/acpi/sysfs.c
35458+++ b/drivers/acpi/sysfs.c
35459@@ -423,11 +423,11 @@ static u32 num_counters;
35460 static struct attribute **all_attrs;
35461 static u32 acpi_gpe_count;
35462
35463-static struct attribute_group interrupt_stats_attr_group = {
35464+static attribute_group_no_const interrupt_stats_attr_group = {
35465 .name = "interrupts",
35466 };
35467
35468-static struct kobj_attribute *counter_attrs;
35469+static kobj_attribute_no_const *counter_attrs;
35470
35471 static void delete_gpe_attr_array(void)
35472 {
35473diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35474index cfb7447..98f2149 100644
35475--- a/drivers/ata/libahci.c
35476+++ b/drivers/ata/libahci.c
35477@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35478 }
35479 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35480
35481-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35482+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35483 struct ata_taskfile *tf, int is_cmd, u16 flags,
35484 unsigned long timeout_msec)
35485 {
35486diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35487index 81a94a3..b711c74 100644
35488--- a/drivers/ata/libata-core.c
35489+++ b/drivers/ata/libata-core.c
35490@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35491 static void ata_dev_xfermask(struct ata_device *dev);
35492 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35493
35494-atomic_t ata_print_id = ATOMIC_INIT(0);
35495+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35496
35497 struct ata_force_param {
35498 const char *name;
35499@@ -4809,7 +4809,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35500 struct ata_port *ap;
35501 unsigned int tag;
35502
35503- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35504+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35505 ap = qc->ap;
35506
35507 qc->flags = 0;
35508@@ -4825,7 +4825,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35509 struct ata_port *ap;
35510 struct ata_link *link;
35511
35512- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35513+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35514 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35515 ap = qc->ap;
35516 link = qc->dev->link;
35517@@ -5944,6 +5944,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35518 return;
35519
35520 spin_lock(&lock);
35521+ pax_open_kernel();
35522
35523 for (cur = ops->inherits; cur; cur = cur->inherits) {
35524 void **inherit = (void **)cur;
35525@@ -5957,8 +5958,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35526 if (IS_ERR(*pp))
35527 *pp = NULL;
35528
35529- ops->inherits = NULL;
35530+ *(struct ata_port_operations **)&ops->inherits = NULL;
35531
35532+ pax_close_kernel();
35533 spin_unlock(&lock);
35534 }
35535
35536@@ -6151,7 +6153,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35537
35538 /* give ports names and add SCSI hosts */
35539 for (i = 0; i < host->n_ports; i++) {
35540- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35541+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35542 host->ports[i]->local_port_no = i + 1;
35543 }
35544
35545diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35546index ab58556..ed19dd2 100644
35547--- a/drivers/ata/libata-scsi.c
35548+++ b/drivers/ata/libata-scsi.c
35549@@ -4114,7 +4114,7 @@ int ata_sas_port_init(struct ata_port *ap)
35550
35551 if (rc)
35552 return rc;
35553- ap->print_id = atomic_inc_return(&ata_print_id);
35554+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35555 return 0;
35556 }
35557 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35558diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35559index 45b5ab3..98446b8 100644
35560--- a/drivers/ata/libata.h
35561+++ b/drivers/ata/libata.h
35562@@ -53,7 +53,7 @@ enum {
35563 ATA_DNXFER_QUIET = (1 << 31),
35564 };
35565
35566-extern atomic_t ata_print_id;
35567+extern atomic_unchecked_t ata_print_id;
35568 extern int atapi_passthru16;
35569 extern int libata_fua;
35570 extern int libata_noacpi;
35571diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35572index 853f610..97d24da 100644
35573--- a/drivers/ata/pata_arasan_cf.c
35574+++ b/drivers/ata/pata_arasan_cf.c
35575@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35576 /* Handle platform specific quirks */
35577 if (quirk) {
35578 if (quirk & CF_BROKEN_PIO) {
35579- ap->ops->set_piomode = NULL;
35580+ pax_open_kernel();
35581+ *(void **)&ap->ops->set_piomode = NULL;
35582+ pax_close_kernel();
35583 ap->pio_mask = 0;
35584 }
35585 if (quirk & CF_BROKEN_MWDMA)
35586diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35587index f9b983a..887b9d8 100644
35588--- a/drivers/atm/adummy.c
35589+++ b/drivers/atm/adummy.c
35590@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35591 vcc->pop(vcc, skb);
35592 else
35593 dev_kfree_skb_any(skb);
35594- atomic_inc(&vcc->stats->tx);
35595+ atomic_inc_unchecked(&vcc->stats->tx);
35596
35597 return 0;
35598 }
35599diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35600index 62a7607..cc4be104 100644
35601--- a/drivers/atm/ambassador.c
35602+++ b/drivers/atm/ambassador.c
35603@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35604 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35605
35606 // VC layer stats
35607- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35608+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35609
35610 // free the descriptor
35611 kfree (tx_descr);
35612@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35613 dump_skb ("<<<", vc, skb);
35614
35615 // VC layer stats
35616- atomic_inc(&atm_vcc->stats->rx);
35617+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35618 __net_timestamp(skb);
35619 // end of our responsibility
35620 atm_vcc->push (atm_vcc, skb);
35621@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35622 } else {
35623 PRINTK (KERN_INFO, "dropped over-size frame");
35624 // should we count this?
35625- atomic_inc(&atm_vcc->stats->rx_drop);
35626+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35627 }
35628
35629 } else {
35630@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35631 }
35632
35633 if (check_area (skb->data, skb->len)) {
35634- atomic_inc(&atm_vcc->stats->tx_err);
35635+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35636 return -ENOMEM; // ?
35637 }
35638
35639diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35640index 0e3f8f9..765a7a5 100644
35641--- a/drivers/atm/atmtcp.c
35642+++ b/drivers/atm/atmtcp.c
35643@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35644 if (vcc->pop) vcc->pop(vcc,skb);
35645 else dev_kfree_skb(skb);
35646 if (dev_data) return 0;
35647- atomic_inc(&vcc->stats->tx_err);
35648+ atomic_inc_unchecked(&vcc->stats->tx_err);
35649 return -ENOLINK;
35650 }
35651 size = skb->len+sizeof(struct atmtcp_hdr);
35652@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35653 if (!new_skb) {
35654 if (vcc->pop) vcc->pop(vcc,skb);
35655 else dev_kfree_skb(skb);
35656- atomic_inc(&vcc->stats->tx_err);
35657+ atomic_inc_unchecked(&vcc->stats->tx_err);
35658 return -ENOBUFS;
35659 }
35660 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35661@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35662 if (vcc->pop) vcc->pop(vcc,skb);
35663 else dev_kfree_skb(skb);
35664 out_vcc->push(out_vcc,new_skb);
35665- atomic_inc(&vcc->stats->tx);
35666- atomic_inc(&out_vcc->stats->rx);
35667+ atomic_inc_unchecked(&vcc->stats->tx);
35668+ atomic_inc_unchecked(&out_vcc->stats->rx);
35669 return 0;
35670 }
35671
35672@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35673 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35674 read_unlock(&vcc_sklist_lock);
35675 if (!out_vcc) {
35676- atomic_inc(&vcc->stats->tx_err);
35677+ atomic_inc_unchecked(&vcc->stats->tx_err);
35678 goto done;
35679 }
35680 skb_pull(skb,sizeof(struct atmtcp_hdr));
35681@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35682 __net_timestamp(new_skb);
35683 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35684 out_vcc->push(out_vcc,new_skb);
35685- atomic_inc(&vcc->stats->tx);
35686- atomic_inc(&out_vcc->stats->rx);
35687+ atomic_inc_unchecked(&vcc->stats->tx);
35688+ atomic_inc_unchecked(&out_vcc->stats->rx);
35689 done:
35690 if (vcc->pop) vcc->pop(vcc,skb);
35691 else dev_kfree_skb(skb);
35692diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35693index b1955ba..b179940 100644
35694--- a/drivers/atm/eni.c
35695+++ b/drivers/atm/eni.c
35696@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35697 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35698 vcc->dev->number);
35699 length = 0;
35700- atomic_inc(&vcc->stats->rx_err);
35701+ atomic_inc_unchecked(&vcc->stats->rx_err);
35702 }
35703 else {
35704 length = ATM_CELL_SIZE-1; /* no HEC */
35705@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35706 size);
35707 }
35708 eff = length = 0;
35709- atomic_inc(&vcc->stats->rx_err);
35710+ atomic_inc_unchecked(&vcc->stats->rx_err);
35711 }
35712 else {
35713 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35714@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35715 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35716 vcc->dev->number,vcc->vci,length,size << 2,descr);
35717 length = eff = 0;
35718- atomic_inc(&vcc->stats->rx_err);
35719+ atomic_inc_unchecked(&vcc->stats->rx_err);
35720 }
35721 }
35722 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35723@@ -767,7 +767,7 @@ rx_dequeued++;
35724 vcc->push(vcc,skb);
35725 pushed++;
35726 }
35727- atomic_inc(&vcc->stats->rx);
35728+ atomic_inc_unchecked(&vcc->stats->rx);
35729 }
35730 wake_up(&eni_dev->rx_wait);
35731 }
35732@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35733 PCI_DMA_TODEVICE);
35734 if (vcc->pop) vcc->pop(vcc,skb);
35735 else dev_kfree_skb_irq(skb);
35736- atomic_inc(&vcc->stats->tx);
35737+ atomic_inc_unchecked(&vcc->stats->tx);
35738 wake_up(&eni_dev->tx_wait);
35739 dma_complete++;
35740 }
35741diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35742index b41c948..a002b17 100644
35743--- a/drivers/atm/firestream.c
35744+++ b/drivers/atm/firestream.c
35745@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35746 }
35747 }
35748
35749- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35750+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35751
35752 fs_dprintk (FS_DEBUG_TXMEM, "i");
35753 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35754@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35755 #endif
35756 skb_put (skb, qe->p1 & 0xffff);
35757 ATM_SKB(skb)->vcc = atm_vcc;
35758- atomic_inc(&atm_vcc->stats->rx);
35759+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35760 __net_timestamp(skb);
35761 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35762 atm_vcc->push (atm_vcc, skb);
35763@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35764 kfree (pe);
35765 }
35766 if (atm_vcc)
35767- atomic_inc(&atm_vcc->stats->rx_drop);
35768+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35769 break;
35770 case 0x1f: /* Reassembly abort: no buffers. */
35771 /* Silently increment error counter. */
35772 if (atm_vcc)
35773- atomic_inc(&atm_vcc->stats->rx_drop);
35774+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35775 break;
35776 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35777 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35778diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35779index 204814e..cede831 100644
35780--- a/drivers/atm/fore200e.c
35781+++ b/drivers/atm/fore200e.c
35782@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35783 #endif
35784 /* check error condition */
35785 if (*entry->status & STATUS_ERROR)
35786- atomic_inc(&vcc->stats->tx_err);
35787+ atomic_inc_unchecked(&vcc->stats->tx_err);
35788 else
35789- atomic_inc(&vcc->stats->tx);
35790+ atomic_inc_unchecked(&vcc->stats->tx);
35791 }
35792 }
35793
35794@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35795 if (skb == NULL) {
35796 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35797
35798- atomic_inc(&vcc->stats->rx_drop);
35799+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35800 return -ENOMEM;
35801 }
35802
35803@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35804
35805 dev_kfree_skb_any(skb);
35806
35807- atomic_inc(&vcc->stats->rx_drop);
35808+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35809 return -ENOMEM;
35810 }
35811
35812 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35813
35814 vcc->push(vcc, skb);
35815- atomic_inc(&vcc->stats->rx);
35816+ atomic_inc_unchecked(&vcc->stats->rx);
35817
35818 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35819
35820@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35821 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35822 fore200e->atm_dev->number,
35823 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35824- atomic_inc(&vcc->stats->rx_err);
35825+ atomic_inc_unchecked(&vcc->stats->rx_err);
35826 }
35827 }
35828
35829@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35830 goto retry_here;
35831 }
35832
35833- atomic_inc(&vcc->stats->tx_err);
35834+ atomic_inc_unchecked(&vcc->stats->tx_err);
35835
35836 fore200e->tx_sat++;
35837 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35838diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35839index 8557adc..3fb5d55 100644
35840--- a/drivers/atm/he.c
35841+++ b/drivers/atm/he.c
35842@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35843
35844 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35845 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35846- atomic_inc(&vcc->stats->rx_drop);
35847+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35848 goto return_host_buffers;
35849 }
35850
35851@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35852 RBRQ_LEN_ERR(he_dev->rbrq_head)
35853 ? "LEN_ERR" : "",
35854 vcc->vpi, vcc->vci);
35855- atomic_inc(&vcc->stats->rx_err);
35856+ atomic_inc_unchecked(&vcc->stats->rx_err);
35857 goto return_host_buffers;
35858 }
35859
35860@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35861 vcc->push(vcc, skb);
35862 spin_lock(&he_dev->global_lock);
35863
35864- atomic_inc(&vcc->stats->rx);
35865+ atomic_inc_unchecked(&vcc->stats->rx);
35866
35867 return_host_buffers:
35868 ++pdus_assembled;
35869@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35870 tpd->vcc->pop(tpd->vcc, tpd->skb);
35871 else
35872 dev_kfree_skb_any(tpd->skb);
35873- atomic_inc(&tpd->vcc->stats->tx_err);
35874+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35875 }
35876 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35877 return;
35878@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35879 vcc->pop(vcc, skb);
35880 else
35881 dev_kfree_skb_any(skb);
35882- atomic_inc(&vcc->stats->tx_err);
35883+ atomic_inc_unchecked(&vcc->stats->tx_err);
35884 return -EINVAL;
35885 }
35886
35887@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35888 vcc->pop(vcc, skb);
35889 else
35890 dev_kfree_skb_any(skb);
35891- atomic_inc(&vcc->stats->tx_err);
35892+ atomic_inc_unchecked(&vcc->stats->tx_err);
35893 return -EINVAL;
35894 }
35895 #endif
35896@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35897 vcc->pop(vcc, skb);
35898 else
35899 dev_kfree_skb_any(skb);
35900- atomic_inc(&vcc->stats->tx_err);
35901+ atomic_inc_unchecked(&vcc->stats->tx_err);
35902 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35903 return -ENOMEM;
35904 }
35905@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35906 vcc->pop(vcc, skb);
35907 else
35908 dev_kfree_skb_any(skb);
35909- atomic_inc(&vcc->stats->tx_err);
35910+ atomic_inc_unchecked(&vcc->stats->tx_err);
35911 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35912 return -ENOMEM;
35913 }
35914@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35915 __enqueue_tpd(he_dev, tpd, cid);
35916 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35917
35918- atomic_inc(&vcc->stats->tx);
35919+ atomic_inc_unchecked(&vcc->stats->tx);
35920
35921 return 0;
35922 }
35923diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35924index 1dc0519..1aadaf7 100644
35925--- a/drivers/atm/horizon.c
35926+++ b/drivers/atm/horizon.c
35927@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35928 {
35929 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35930 // VC layer stats
35931- atomic_inc(&vcc->stats->rx);
35932+ atomic_inc_unchecked(&vcc->stats->rx);
35933 __net_timestamp(skb);
35934 // end of our responsibility
35935 vcc->push (vcc, skb);
35936@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35937 dev->tx_iovec = NULL;
35938
35939 // VC layer stats
35940- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35941+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35942
35943 // free the skb
35944 hrz_kfree_skb (skb);
35945diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35946index 1bdf104..9dc44b1 100644
35947--- a/drivers/atm/idt77252.c
35948+++ b/drivers/atm/idt77252.c
35949@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35950 else
35951 dev_kfree_skb(skb);
35952
35953- atomic_inc(&vcc->stats->tx);
35954+ atomic_inc_unchecked(&vcc->stats->tx);
35955 }
35956
35957 atomic_dec(&scq->used);
35958@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35959 if ((sb = dev_alloc_skb(64)) == NULL) {
35960 printk("%s: Can't allocate buffers for aal0.\n",
35961 card->name);
35962- atomic_add(i, &vcc->stats->rx_drop);
35963+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35964 break;
35965 }
35966 if (!atm_charge(vcc, sb->truesize)) {
35967 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35968 card->name);
35969- atomic_add(i - 1, &vcc->stats->rx_drop);
35970+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35971 dev_kfree_skb(sb);
35972 break;
35973 }
35974@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35975 ATM_SKB(sb)->vcc = vcc;
35976 __net_timestamp(sb);
35977 vcc->push(vcc, sb);
35978- atomic_inc(&vcc->stats->rx);
35979+ atomic_inc_unchecked(&vcc->stats->rx);
35980
35981 cell += ATM_CELL_PAYLOAD;
35982 }
35983@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35984 "(CDC: %08x)\n",
35985 card->name, len, rpp->len, readl(SAR_REG_CDC));
35986 recycle_rx_pool_skb(card, rpp);
35987- atomic_inc(&vcc->stats->rx_err);
35988+ atomic_inc_unchecked(&vcc->stats->rx_err);
35989 return;
35990 }
35991 if (stat & SAR_RSQE_CRC) {
35992 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35993 recycle_rx_pool_skb(card, rpp);
35994- atomic_inc(&vcc->stats->rx_err);
35995+ atomic_inc_unchecked(&vcc->stats->rx_err);
35996 return;
35997 }
35998 if (skb_queue_len(&rpp->queue) > 1) {
35999@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36000 RXPRINTK("%s: Can't alloc RX skb.\n",
36001 card->name);
36002 recycle_rx_pool_skb(card, rpp);
36003- atomic_inc(&vcc->stats->rx_err);
36004+ atomic_inc_unchecked(&vcc->stats->rx_err);
36005 return;
36006 }
36007 if (!atm_charge(vcc, skb->truesize)) {
36008@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36009 __net_timestamp(skb);
36010
36011 vcc->push(vcc, skb);
36012- atomic_inc(&vcc->stats->rx);
36013+ atomic_inc_unchecked(&vcc->stats->rx);
36014
36015 return;
36016 }
36017@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36018 __net_timestamp(skb);
36019
36020 vcc->push(vcc, skb);
36021- atomic_inc(&vcc->stats->rx);
36022+ atomic_inc_unchecked(&vcc->stats->rx);
36023
36024 if (skb->truesize > SAR_FB_SIZE_3)
36025 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36026@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36027 if (vcc->qos.aal != ATM_AAL0) {
36028 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36029 card->name, vpi, vci);
36030- atomic_inc(&vcc->stats->rx_drop);
36031+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36032 goto drop;
36033 }
36034
36035 if ((sb = dev_alloc_skb(64)) == NULL) {
36036 printk("%s: Can't allocate buffers for AAL0.\n",
36037 card->name);
36038- atomic_inc(&vcc->stats->rx_err);
36039+ atomic_inc_unchecked(&vcc->stats->rx_err);
36040 goto drop;
36041 }
36042
36043@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36044 ATM_SKB(sb)->vcc = vcc;
36045 __net_timestamp(sb);
36046 vcc->push(vcc, sb);
36047- atomic_inc(&vcc->stats->rx);
36048+ atomic_inc_unchecked(&vcc->stats->rx);
36049
36050 drop:
36051 skb_pull(queue, 64);
36052@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36053
36054 if (vc == NULL) {
36055 printk("%s: NULL connection in send().\n", card->name);
36056- atomic_inc(&vcc->stats->tx_err);
36057+ atomic_inc_unchecked(&vcc->stats->tx_err);
36058 dev_kfree_skb(skb);
36059 return -EINVAL;
36060 }
36061 if (!test_bit(VCF_TX, &vc->flags)) {
36062 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36063- atomic_inc(&vcc->stats->tx_err);
36064+ atomic_inc_unchecked(&vcc->stats->tx_err);
36065 dev_kfree_skb(skb);
36066 return -EINVAL;
36067 }
36068@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36069 break;
36070 default:
36071 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36072- atomic_inc(&vcc->stats->tx_err);
36073+ atomic_inc_unchecked(&vcc->stats->tx_err);
36074 dev_kfree_skb(skb);
36075 return -EINVAL;
36076 }
36077
36078 if (skb_shinfo(skb)->nr_frags != 0) {
36079 printk("%s: No scatter-gather yet.\n", card->name);
36080- atomic_inc(&vcc->stats->tx_err);
36081+ atomic_inc_unchecked(&vcc->stats->tx_err);
36082 dev_kfree_skb(skb);
36083 return -EINVAL;
36084 }
36085@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36086
36087 err = queue_skb(card, vc, skb, oam);
36088 if (err) {
36089- atomic_inc(&vcc->stats->tx_err);
36090+ atomic_inc_unchecked(&vcc->stats->tx_err);
36091 dev_kfree_skb(skb);
36092 return err;
36093 }
36094@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36095 skb = dev_alloc_skb(64);
36096 if (!skb) {
36097 printk("%s: Out of memory in send_oam().\n", card->name);
36098- atomic_inc(&vcc->stats->tx_err);
36099+ atomic_inc_unchecked(&vcc->stats->tx_err);
36100 return -ENOMEM;
36101 }
36102 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36103diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36104index 4217f29..88f547a 100644
36105--- a/drivers/atm/iphase.c
36106+++ b/drivers/atm/iphase.c
36107@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36108 status = (u_short) (buf_desc_ptr->desc_mode);
36109 if (status & (RX_CER | RX_PTE | RX_OFL))
36110 {
36111- atomic_inc(&vcc->stats->rx_err);
36112+ atomic_inc_unchecked(&vcc->stats->rx_err);
36113 IF_ERR(printk("IA: bad packet, dropping it");)
36114 if (status & RX_CER) {
36115 IF_ERR(printk(" cause: packet CRC error\n");)
36116@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36117 len = dma_addr - buf_addr;
36118 if (len > iadev->rx_buf_sz) {
36119 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36120- atomic_inc(&vcc->stats->rx_err);
36121+ atomic_inc_unchecked(&vcc->stats->rx_err);
36122 goto out_free_desc;
36123 }
36124
36125@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36126 ia_vcc = INPH_IA_VCC(vcc);
36127 if (ia_vcc == NULL)
36128 {
36129- atomic_inc(&vcc->stats->rx_err);
36130+ atomic_inc_unchecked(&vcc->stats->rx_err);
36131 atm_return(vcc, skb->truesize);
36132 dev_kfree_skb_any(skb);
36133 goto INCR_DLE;
36134@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36135 if ((length > iadev->rx_buf_sz) || (length >
36136 (skb->len - sizeof(struct cpcs_trailer))))
36137 {
36138- atomic_inc(&vcc->stats->rx_err);
36139+ atomic_inc_unchecked(&vcc->stats->rx_err);
36140 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36141 length, skb->len);)
36142 atm_return(vcc, skb->truesize);
36143@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36144
36145 IF_RX(printk("rx_dle_intr: skb push");)
36146 vcc->push(vcc,skb);
36147- atomic_inc(&vcc->stats->rx);
36148+ atomic_inc_unchecked(&vcc->stats->rx);
36149 iadev->rx_pkt_cnt++;
36150 }
36151 INCR_DLE:
36152@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36153 {
36154 struct k_sonet_stats *stats;
36155 stats = &PRIV(_ia_dev[board])->sonet_stats;
36156- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36157- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36158- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36159- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36160- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36161- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36162- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36163- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36164- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36165+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36166+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36167+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36168+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36169+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36170+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36171+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36172+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36173+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36174 }
36175 ia_cmds.status = 0;
36176 break;
36177@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36178 if ((desc == 0) || (desc > iadev->num_tx_desc))
36179 {
36180 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36181- atomic_inc(&vcc->stats->tx);
36182+ atomic_inc_unchecked(&vcc->stats->tx);
36183 if (vcc->pop)
36184 vcc->pop(vcc, skb);
36185 else
36186@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36187 ATM_DESC(skb) = vcc->vci;
36188 skb_queue_tail(&iadev->tx_dma_q, skb);
36189
36190- atomic_inc(&vcc->stats->tx);
36191+ atomic_inc_unchecked(&vcc->stats->tx);
36192 iadev->tx_pkt_cnt++;
36193 /* Increment transaction counter */
36194 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36195
36196 #if 0
36197 /* add flow control logic */
36198- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36199+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36200 if (iavcc->vc_desc_cnt > 10) {
36201 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36202 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36203diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36204index fa7d701..1e404c7 100644
36205--- a/drivers/atm/lanai.c
36206+++ b/drivers/atm/lanai.c
36207@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36208 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36209 lanai_endtx(lanai, lvcc);
36210 lanai_free_skb(lvcc->tx.atmvcc, skb);
36211- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36212+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36213 }
36214
36215 /* Try to fill the buffer - don't call unless there is backlog */
36216@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36217 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36218 __net_timestamp(skb);
36219 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36220- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36221+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36222 out:
36223 lvcc->rx.buf.ptr = end;
36224 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36225@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36226 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36227 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36228 lanai->stats.service_rxnotaal5++;
36229- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36230+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36231 return 0;
36232 }
36233 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36234@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36235 int bytes;
36236 read_unlock(&vcc_sklist_lock);
36237 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36238- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36239+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36240 lvcc->stats.x.aal5.service_trash++;
36241 bytes = (SERVICE_GET_END(s) * 16) -
36242 (((unsigned long) lvcc->rx.buf.ptr) -
36243@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36244 }
36245 if (s & SERVICE_STREAM) {
36246 read_unlock(&vcc_sklist_lock);
36247- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36248+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36249 lvcc->stats.x.aal5.service_stream++;
36250 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36251 "PDU on VCI %d!\n", lanai->number, vci);
36252@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36253 return 0;
36254 }
36255 DPRINTK("got rx crc error on vci %d\n", vci);
36256- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36257+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36258 lvcc->stats.x.aal5.service_rxcrc++;
36259 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36260 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36261diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36262index 5aca5f4..ce3a6b0 100644
36263--- a/drivers/atm/nicstar.c
36264+++ b/drivers/atm/nicstar.c
36265@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36266 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36267 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36268 card->index);
36269- atomic_inc(&vcc->stats->tx_err);
36270+ atomic_inc_unchecked(&vcc->stats->tx_err);
36271 dev_kfree_skb_any(skb);
36272 return -EINVAL;
36273 }
36274@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36275 if (!vc->tx) {
36276 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36277 card->index);
36278- atomic_inc(&vcc->stats->tx_err);
36279+ atomic_inc_unchecked(&vcc->stats->tx_err);
36280 dev_kfree_skb_any(skb);
36281 return -EINVAL;
36282 }
36283@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36284 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36285 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36286 card->index);
36287- atomic_inc(&vcc->stats->tx_err);
36288+ atomic_inc_unchecked(&vcc->stats->tx_err);
36289 dev_kfree_skb_any(skb);
36290 return -EINVAL;
36291 }
36292
36293 if (skb_shinfo(skb)->nr_frags != 0) {
36294 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36295- atomic_inc(&vcc->stats->tx_err);
36296+ atomic_inc_unchecked(&vcc->stats->tx_err);
36297 dev_kfree_skb_any(skb);
36298 return -EINVAL;
36299 }
36300@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36301 }
36302
36303 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36304- atomic_inc(&vcc->stats->tx_err);
36305+ atomic_inc_unchecked(&vcc->stats->tx_err);
36306 dev_kfree_skb_any(skb);
36307 return -EIO;
36308 }
36309- atomic_inc(&vcc->stats->tx);
36310+ atomic_inc_unchecked(&vcc->stats->tx);
36311
36312 return 0;
36313 }
36314@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36315 printk
36316 ("nicstar%d: Can't allocate buffers for aal0.\n",
36317 card->index);
36318- atomic_add(i, &vcc->stats->rx_drop);
36319+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36320 break;
36321 }
36322 if (!atm_charge(vcc, sb->truesize)) {
36323 RXPRINTK
36324 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36325 card->index);
36326- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36327+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36328 dev_kfree_skb_any(sb);
36329 break;
36330 }
36331@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36332 ATM_SKB(sb)->vcc = vcc;
36333 __net_timestamp(sb);
36334 vcc->push(vcc, sb);
36335- atomic_inc(&vcc->stats->rx);
36336+ atomic_inc_unchecked(&vcc->stats->rx);
36337 cell += ATM_CELL_PAYLOAD;
36338 }
36339
36340@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36341 if (iovb == NULL) {
36342 printk("nicstar%d: Out of iovec buffers.\n",
36343 card->index);
36344- atomic_inc(&vcc->stats->rx_drop);
36345+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36346 recycle_rx_buf(card, skb);
36347 return;
36348 }
36349@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36350 small or large buffer itself. */
36351 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36352 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36353- atomic_inc(&vcc->stats->rx_err);
36354+ atomic_inc_unchecked(&vcc->stats->rx_err);
36355 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36356 NS_MAX_IOVECS);
36357 NS_PRV_IOVCNT(iovb) = 0;
36358@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36359 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36360 card->index);
36361 which_list(card, skb);
36362- atomic_inc(&vcc->stats->rx_err);
36363+ atomic_inc_unchecked(&vcc->stats->rx_err);
36364 recycle_rx_buf(card, skb);
36365 vc->rx_iov = NULL;
36366 recycle_iov_buf(card, iovb);
36367@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36368 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36369 card->index);
36370 which_list(card, skb);
36371- atomic_inc(&vcc->stats->rx_err);
36372+ atomic_inc_unchecked(&vcc->stats->rx_err);
36373 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36374 NS_PRV_IOVCNT(iovb));
36375 vc->rx_iov = NULL;
36376@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36377 printk(" - PDU size mismatch.\n");
36378 else
36379 printk(".\n");
36380- atomic_inc(&vcc->stats->rx_err);
36381+ atomic_inc_unchecked(&vcc->stats->rx_err);
36382 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36383 NS_PRV_IOVCNT(iovb));
36384 vc->rx_iov = NULL;
36385@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36386 /* skb points to a small buffer */
36387 if (!atm_charge(vcc, skb->truesize)) {
36388 push_rxbufs(card, skb);
36389- atomic_inc(&vcc->stats->rx_drop);
36390+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36391 } else {
36392 skb_put(skb, len);
36393 dequeue_sm_buf(card, skb);
36394@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36395 ATM_SKB(skb)->vcc = vcc;
36396 __net_timestamp(skb);
36397 vcc->push(vcc, skb);
36398- atomic_inc(&vcc->stats->rx);
36399+ atomic_inc_unchecked(&vcc->stats->rx);
36400 }
36401 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36402 struct sk_buff *sb;
36403@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36404 if (len <= NS_SMBUFSIZE) {
36405 if (!atm_charge(vcc, sb->truesize)) {
36406 push_rxbufs(card, sb);
36407- atomic_inc(&vcc->stats->rx_drop);
36408+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36409 } else {
36410 skb_put(sb, len);
36411 dequeue_sm_buf(card, sb);
36412@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36413 ATM_SKB(sb)->vcc = vcc;
36414 __net_timestamp(sb);
36415 vcc->push(vcc, sb);
36416- atomic_inc(&vcc->stats->rx);
36417+ atomic_inc_unchecked(&vcc->stats->rx);
36418 }
36419
36420 push_rxbufs(card, skb);
36421@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36422
36423 if (!atm_charge(vcc, skb->truesize)) {
36424 push_rxbufs(card, skb);
36425- atomic_inc(&vcc->stats->rx_drop);
36426+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36427 } else {
36428 dequeue_lg_buf(card, skb);
36429 #ifdef NS_USE_DESTRUCTORS
36430@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36431 ATM_SKB(skb)->vcc = vcc;
36432 __net_timestamp(skb);
36433 vcc->push(vcc, skb);
36434- atomic_inc(&vcc->stats->rx);
36435+ atomic_inc_unchecked(&vcc->stats->rx);
36436 }
36437
36438 push_rxbufs(card, sb);
36439@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36440 printk
36441 ("nicstar%d: Out of huge buffers.\n",
36442 card->index);
36443- atomic_inc(&vcc->stats->rx_drop);
36444+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36445 recycle_iovec_rx_bufs(card,
36446 (struct iovec *)
36447 iovb->data,
36448@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36449 card->hbpool.count++;
36450 } else
36451 dev_kfree_skb_any(hb);
36452- atomic_inc(&vcc->stats->rx_drop);
36453+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36454 } else {
36455 /* Copy the small buffer to the huge buffer */
36456 sb = (struct sk_buff *)iov->iov_base;
36457@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36458 #endif /* NS_USE_DESTRUCTORS */
36459 __net_timestamp(hb);
36460 vcc->push(vcc, hb);
36461- atomic_inc(&vcc->stats->rx);
36462+ atomic_inc_unchecked(&vcc->stats->rx);
36463 }
36464 }
36465
36466diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36467index 32784d1..4a8434a 100644
36468--- a/drivers/atm/solos-pci.c
36469+++ b/drivers/atm/solos-pci.c
36470@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36471 }
36472 atm_charge(vcc, skb->truesize);
36473 vcc->push(vcc, skb);
36474- atomic_inc(&vcc->stats->rx);
36475+ atomic_inc_unchecked(&vcc->stats->rx);
36476 break;
36477
36478 case PKT_STATUS:
36479@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36480 vcc = SKB_CB(oldskb)->vcc;
36481
36482 if (vcc) {
36483- atomic_inc(&vcc->stats->tx);
36484+ atomic_inc_unchecked(&vcc->stats->tx);
36485 solos_pop(vcc, oldskb);
36486 } else {
36487 dev_kfree_skb_irq(oldskb);
36488diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36489index 0215934..ce9f5b1 100644
36490--- a/drivers/atm/suni.c
36491+++ b/drivers/atm/suni.c
36492@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36493
36494
36495 #define ADD_LIMITED(s,v) \
36496- atomic_add((v),&stats->s); \
36497- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36498+ atomic_add_unchecked((v),&stats->s); \
36499+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36500
36501
36502 static void suni_hz(unsigned long from_timer)
36503diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36504index 5120a96..e2572bd 100644
36505--- a/drivers/atm/uPD98402.c
36506+++ b/drivers/atm/uPD98402.c
36507@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36508 struct sonet_stats tmp;
36509 int error = 0;
36510
36511- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36512+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36513 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36514 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36515 if (zero && !error) {
36516@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36517
36518
36519 #define ADD_LIMITED(s,v) \
36520- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36521- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36522- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36523+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36524+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36525+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36526
36527
36528 static void stat_event(struct atm_dev *dev)
36529@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36530 if (reason & uPD98402_INT_PFM) stat_event(dev);
36531 if (reason & uPD98402_INT_PCO) {
36532 (void) GET(PCOCR); /* clear interrupt cause */
36533- atomic_add(GET(HECCT),
36534+ atomic_add_unchecked(GET(HECCT),
36535 &PRIV(dev)->sonet_stats.uncorr_hcs);
36536 }
36537 if ((reason & uPD98402_INT_RFO) &&
36538@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36539 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36540 uPD98402_INT_LOS),PIMR); /* enable them */
36541 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36542- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36543- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36544- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36545+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36546+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36547+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36548 return 0;
36549 }
36550
36551diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36552index 969c3c2..9b72956 100644
36553--- a/drivers/atm/zatm.c
36554+++ b/drivers/atm/zatm.c
36555@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36556 }
36557 if (!size) {
36558 dev_kfree_skb_irq(skb);
36559- if (vcc) atomic_inc(&vcc->stats->rx_err);
36560+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36561 continue;
36562 }
36563 if (!atm_charge(vcc,skb->truesize)) {
36564@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36565 skb->len = size;
36566 ATM_SKB(skb)->vcc = vcc;
36567 vcc->push(vcc,skb);
36568- atomic_inc(&vcc->stats->rx);
36569+ atomic_inc_unchecked(&vcc->stats->rx);
36570 }
36571 zout(pos & 0xffff,MTA(mbx));
36572 #if 0 /* probably a stupid idea */
36573@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36574 skb_queue_head(&zatm_vcc->backlog,skb);
36575 break;
36576 }
36577- atomic_inc(&vcc->stats->tx);
36578+ atomic_inc_unchecked(&vcc->stats->tx);
36579 wake_up(&zatm_vcc->tx_wait);
36580 }
36581
36582diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36583index 4c289ab..de1c333 100644
36584--- a/drivers/base/bus.c
36585+++ b/drivers/base/bus.c
36586@@ -1193,7 +1193,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36587 return -EINVAL;
36588
36589 mutex_lock(&subsys->p->mutex);
36590- list_add_tail(&sif->node, &subsys->p->interfaces);
36591+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36592 if (sif->add_dev) {
36593 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36594 while ((dev = subsys_dev_iter_next(&iter)))
36595@@ -1218,7 +1218,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36596 subsys = sif->subsys;
36597
36598 mutex_lock(&subsys->p->mutex);
36599- list_del_init(&sif->node);
36600+ pax_list_del_init((struct list_head *)&sif->node);
36601 if (sif->remove_dev) {
36602 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36603 while ((dev = subsys_dev_iter_next(&iter)))
36604diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36605index 7413d06..79155fa 100644
36606--- a/drivers/base/devtmpfs.c
36607+++ b/drivers/base/devtmpfs.c
36608@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36609 if (!thread)
36610 return 0;
36611
36612- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36613+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36614 if (err)
36615 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36616 else
36617@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36618 *err = sys_unshare(CLONE_NEWNS);
36619 if (*err)
36620 goto out;
36621- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36622+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36623 if (*err)
36624 goto out;
36625- sys_chdir("/.."); /* will traverse into overmounted root */
36626- sys_chroot(".");
36627+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36628+ sys_chroot((char __force_user *)".");
36629 complete(&setup_done);
36630 while (1) {
36631 spin_lock(&req_lock);
36632diff --git a/drivers/base/node.c b/drivers/base/node.c
36633index bc9f43b..29703b8 100644
36634--- a/drivers/base/node.c
36635+++ b/drivers/base/node.c
36636@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36637 struct node_attr {
36638 struct device_attribute attr;
36639 enum node_states state;
36640-};
36641+} __do_const;
36642
36643 static ssize_t show_node_state(struct device *dev,
36644 struct device_attribute *attr, char *buf)
36645diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36646index bfb8955..42c9b9a 100644
36647--- a/drivers/base/power/domain.c
36648+++ b/drivers/base/power/domain.c
36649@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36650 {
36651 struct cpuidle_driver *cpuidle_drv;
36652 struct gpd_cpu_data *cpu_data;
36653- struct cpuidle_state *idle_state;
36654+ cpuidle_state_no_const *idle_state;
36655 int ret = 0;
36656
36657 if (IS_ERR_OR_NULL(genpd) || state < 0)
36658@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36659 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36660 {
36661 struct gpd_cpu_data *cpu_data;
36662- struct cpuidle_state *idle_state;
36663+ cpuidle_state_no_const *idle_state;
36664 int ret = 0;
36665
36666 if (IS_ERR_OR_NULL(genpd))
36667diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36668index 03e089a..0e9560c 100644
36669--- a/drivers/base/power/sysfs.c
36670+++ b/drivers/base/power/sysfs.c
36671@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36672 return -EIO;
36673 }
36674 }
36675- return sprintf(buf, p);
36676+ return sprintf(buf, "%s", p);
36677 }
36678
36679 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36680diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36681index 2d56f41..8830f19 100644
36682--- a/drivers/base/power/wakeup.c
36683+++ b/drivers/base/power/wakeup.c
36684@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36685 * They need to be modified together atomically, so it's better to use one
36686 * atomic variable to hold them both.
36687 */
36688-static atomic_t combined_event_count = ATOMIC_INIT(0);
36689+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36690
36691 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36692 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36693
36694 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36695 {
36696- unsigned int comb = atomic_read(&combined_event_count);
36697+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36698
36699 *cnt = (comb >> IN_PROGRESS_BITS);
36700 *inpr = comb & MAX_IN_PROGRESS;
36701@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36702 ws->start_prevent_time = ws->last_time;
36703
36704 /* Increment the counter of events in progress. */
36705- cec = atomic_inc_return(&combined_event_count);
36706+ cec = atomic_inc_return_unchecked(&combined_event_count);
36707
36708 trace_wakeup_source_activate(ws->name, cec);
36709 }
36710@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36711 * Increment the counter of registered wakeup events and decrement the
36712 * couter of wakeup events in progress simultaneously.
36713 */
36714- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36715+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36716 trace_wakeup_source_deactivate(ws->name, cec);
36717
36718 split_counters(&cnt, &inpr);
36719diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36720index e8d11b6..7b1b36f 100644
36721--- a/drivers/base/syscore.c
36722+++ b/drivers/base/syscore.c
36723@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36724 void register_syscore_ops(struct syscore_ops *ops)
36725 {
36726 mutex_lock(&syscore_ops_lock);
36727- list_add_tail(&ops->node, &syscore_ops_list);
36728+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36729 mutex_unlock(&syscore_ops_lock);
36730 }
36731 EXPORT_SYMBOL_GPL(register_syscore_ops);
36732@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36733 void unregister_syscore_ops(struct syscore_ops *ops)
36734 {
36735 mutex_lock(&syscore_ops_lock);
36736- list_del(&ops->node);
36737+ pax_list_del((struct list_head *)&ops->node);
36738 mutex_unlock(&syscore_ops_lock);
36739 }
36740 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36741diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36742index edfa251..1734d4d 100644
36743--- a/drivers/block/cciss.c
36744+++ b/drivers/block/cciss.c
36745@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36746 while (!list_empty(&h->reqQ)) {
36747 c = list_entry(h->reqQ.next, CommandList_struct, list);
36748 /* can't do anything if fifo is full */
36749- if ((h->access.fifo_full(h))) {
36750+ if ((h->access->fifo_full(h))) {
36751 dev_warn(&h->pdev->dev, "fifo full\n");
36752 break;
36753 }
36754@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36755 h->Qdepth--;
36756
36757 /* Tell the controller execute command */
36758- h->access.submit_command(h, c);
36759+ h->access->submit_command(h, c);
36760
36761 /* Put job onto the completed Q */
36762 addQ(&h->cmpQ, c);
36763@@ -3447,17 +3447,17 @@ startio:
36764
36765 static inline unsigned long get_next_completion(ctlr_info_t *h)
36766 {
36767- return h->access.command_completed(h);
36768+ return h->access->command_completed(h);
36769 }
36770
36771 static inline int interrupt_pending(ctlr_info_t *h)
36772 {
36773- return h->access.intr_pending(h);
36774+ return h->access->intr_pending(h);
36775 }
36776
36777 static inline long interrupt_not_for_us(ctlr_info_t *h)
36778 {
36779- return ((h->access.intr_pending(h) == 0) ||
36780+ return ((h->access->intr_pending(h) == 0) ||
36781 (h->interrupts_enabled == 0));
36782 }
36783
36784@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36785 u32 a;
36786
36787 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36788- return h->access.command_completed(h);
36789+ return h->access->command_completed(h);
36790
36791 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36792 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36793@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36794 trans_support & CFGTBL_Trans_use_short_tags);
36795
36796 /* Change the access methods to the performant access methods */
36797- h->access = SA5_performant_access;
36798+ h->access = &SA5_performant_access;
36799 h->transMethod = CFGTBL_Trans_Performant;
36800
36801 return;
36802@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36803 if (prod_index < 0)
36804 return -ENODEV;
36805 h->product_name = products[prod_index].product_name;
36806- h->access = *(products[prod_index].access);
36807+ h->access = products[prod_index].access;
36808
36809 if (cciss_board_disabled(h)) {
36810 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36811@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36812 }
36813
36814 /* make sure the board interrupts are off */
36815- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36816+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36817 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36818 if (rc)
36819 goto clean2;
36820@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36821 * fake ones to scoop up any residual completions.
36822 */
36823 spin_lock_irqsave(&h->lock, flags);
36824- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36825+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36826 spin_unlock_irqrestore(&h->lock, flags);
36827 free_irq(h->intr[h->intr_mode], h);
36828 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36829@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36830 dev_info(&h->pdev->dev, "Board READY.\n");
36831 dev_info(&h->pdev->dev,
36832 "Waiting for stale completions to drain.\n");
36833- h->access.set_intr_mask(h, CCISS_INTR_ON);
36834+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36835 msleep(10000);
36836- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36837+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36838
36839 rc = controller_reset_failed(h->cfgtable);
36840 if (rc)
36841@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36842 cciss_scsi_setup(h);
36843
36844 /* Turn the interrupts on so we can service requests */
36845- h->access.set_intr_mask(h, CCISS_INTR_ON);
36846+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36847
36848 /* Get the firmware version */
36849 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36850@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36851 kfree(flush_buf);
36852 if (return_code != IO_OK)
36853 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36854- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36855+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36856 free_irq(h->intr[h->intr_mode], h);
36857 }
36858
36859diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36860index 7fda30e..eb5dfe0 100644
36861--- a/drivers/block/cciss.h
36862+++ b/drivers/block/cciss.h
36863@@ -101,7 +101,7 @@ struct ctlr_info
36864 /* information about each logical volume */
36865 drive_info_struct *drv[CISS_MAX_LUN];
36866
36867- struct access_method access;
36868+ struct access_method *access;
36869
36870 /* queue and queue Info */
36871 struct list_head reqQ;
36872diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36873index 2b94403..fd6ad1f 100644
36874--- a/drivers/block/cpqarray.c
36875+++ b/drivers/block/cpqarray.c
36876@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36877 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36878 goto Enomem4;
36879 }
36880- hba[i]->access.set_intr_mask(hba[i], 0);
36881+ hba[i]->access->set_intr_mask(hba[i], 0);
36882 if (request_irq(hba[i]->intr, do_ida_intr,
36883 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36884 {
36885@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36886 add_timer(&hba[i]->timer);
36887
36888 /* Enable IRQ now that spinlock and rate limit timer are set up */
36889- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36890+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36891
36892 for(j=0; j<NWD; j++) {
36893 struct gendisk *disk = ida_gendisk[i][j];
36894@@ -694,7 +694,7 @@ DBGINFO(
36895 for(i=0; i<NR_PRODUCTS; i++) {
36896 if (board_id == products[i].board_id) {
36897 c->product_name = products[i].product_name;
36898- c->access = *(products[i].access);
36899+ c->access = products[i].access;
36900 break;
36901 }
36902 }
36903@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36904 hba[ctlr]->intr = intr;
36905 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36906 hba[ctlr]->product_name = products[j].product_name;
36907- hba[ctlr]->access = *(products[j].access);
36908+ hba[ctlr]->access = products[j].access;
36909 hba[ctlr]->ctlr = ctlr;
36910 hba[ctlr]->board_id = board_id;
36911 hba[ctlr]->pci_dev = NULL; /* not PCI */
36912@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36913
36914 while((c = h->reqQ) != NULL) {
36915 /* Can't do anything if we're busy */
36916- if (h->access.fifo_full(h) == 0)
36917+ if (h->access->fifo_full(h) == 0)
36918 return;
36919
36920 /* Get the first entry from the request Q */
36921@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36922 h->Qdepth--;
36923
36924 /* Tell the controller to do our bidding */
36925- h->access.submit_command(h, c);
36926+ h->access->submit_command(h, c);
36927
36928 /* Get onto the completion Q */
36929 addQ(&h->cmpQ, c);
36930@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36931 unsigned long flags;
36932 __u32 a,a1;
36933
36934- istat = h->access.intr_pending(h);
36935+ istat = h->access->intr_pending(h);
36936 /* Is this interrupt for us? */
36937 if (istat == 0)
36938 return IRQ_NONE;
36939@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36940 */
36941 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36942 if (istat & FIFO_NOT_EMPTY) {
36943- while((a = h->access.command_completed(h))) {
36944+ while((a = h->access->command_completed(h))) {
36945 a1 = a; a &= ~3;
36946 if ((c = h->cmpQ) == NULL)
36947 {
36948@@ -1448,11 +1448,11 @@ static int sendcmd(
36949 /*
36950 * Disable interrupt
36951 */
36952- info_p->access.set_intr_mask(info_p, 0);
36953+ info_p->access->set_intr_mask(info_p, 0);
36954 /* Make sure there is room in the command FIFO */
36955 /* Actually it should be completely empty at this time. */
36956 for (i = 200000; i > 0; i--) {
36957- temp = info_p->access.fifo_full(info_p);
36958+ temp = info_p->access->fifo_full(info_p);
36959 if (temp != 0) {
36960 break;
36961 }
36962@@ -1465,7 +1465,7 @@ DBG(
36963 /*
36964 * Send the cmd
36965 */
36966- info_p->access.submit_command(info_p, c);
36967+ info_p->access->submit_command(info_p, c);
36968 complete = pollcomplete(ctlr);
36969
36970 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36971@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36972 * we check the new geometry. Then turn interrupts back on when
36973 * we're done.
36974 */
36975- host->access.set_intr_mask(host, 0);
36976+ host->access->set_intr_mask(host, 0);
36977 getgeometry(ctlr);
36978- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36979+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36980
36981 for(i=0; i<NWD; i++) {
36982 struct gendisk *disk = ida_gendisk[ctlr][i];
36983@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36984 /* Wait (up to 2 seconds) for a command to complete */
36985
36986 for (i = 200000; i > 0; i--) {
36987- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36988+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36989 if (done == 0) {
36990 udelay(10); /* a short fixed delay */
36991 } else
36992diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36993index be73e9d..7fbf140 100644
36994--- a/drivers/block/cpqarray.h
36995+++ b/drivers/block/cpqarray.h
36996@@ -99,7 +99,7 @@ struct ctlr_info {
36997 drv_info_t drv[NWD];
36998 struct proc_dir_entry *proc;
36999
37000- struct access_method access;
37001+ struct access_method *access;
37002
37003 cmdlist_t *reqQ;
37004 cmdlist_t *cmpQ;
37005diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37006index 2d7f608..11245fe 100644
37007--- a/drivers/block/drbd/drbd_int.h
37008+++ b/drivers/block/drbd/drbd_int.h
37009@@ -582,7 +582,7 @@ struct drbd_epoch {
37010 struct drbd_tconn *tconn;
37011 struct list_head list;
37012 unsigned int barrier_nr;
37013- atomic_t epoch_size; /* increased on every request added. */
37014+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37015 atomic_t active; /* increased on every req. added, and dec on every finished. */
37016 unsigned long flags;
37017 };
37018@@ -1022,7 +1022,7 @@ struct drbd_conf {
37019 unsigned int al_tr_number;
37020 int al_tr_cycle;
37021 wait_queue_head_t seq_wait;
37022- atomic_t packet_seq;
37023+ atomic_unchecked_t packet_seq;
37024 unsigned int peer_seq;
37025 spinlock_t peer_seq_lock;
37026 unsigned int minor;
37027@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37028 char __user *uoptval;
37029 int err;
37030
37031- uoptval = (char __user __force *)optval;
37032+ uoptval = (char __force_user *)optval;
37033
37034 set_fs(KERNEL_DS);
37035 if (level == SOL_SOCKET)
37036diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37037index 55635ed..40e837c 100644
37038--- a/drivers/block/drbd/drbd_main.c
37039+++ b/drivers/block/drbd/drbd_main.c
37040@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37041 p->sector = sector;
37042 p->block_id = block_id;
37043 p->blksize = blksize;
37044- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37045+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37046 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37047 }
37048
37049@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37050 return -EIO;
37051 p->sector = cpu_to_be64(req->i.sector);
37052 p->block_id = (unsigned long)req;
37053- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37054+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37055 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37056 if (mdev->state.conn >= C_SYNC_SOURCE &&
37057 mdev->state.conn <= C_PAUSED_SYNC_T)
37058@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37059 {
37060 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37061
37062- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37063- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37064+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37065+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37066 kfree(tconn->current_epoch);
37067
37068 idr_destroy(&tconn->volumes);
37069diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37070index 8cc1e64..ba7ffa9 100644
37071--- a/drivers/block/drbd/drbd_nl.c
37072+++ b/drivers/block/drbd/drbd_nl.c
37073@@ -3440,7 +3440,7 @@ out:
37074
37075 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37076 {
37077- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37078+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37079 struct sk_buff *msg;
37080 struct drbd_genlmsghdr *d_out;
37081 unsigned seq;
37082@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37083 return;
37084 }
37085
37086- seq = atomic_inc_return(&drbd_genl_seq);
37087+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37088 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37089 if (!msg)
37090 goto failed;
37091diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37092index cc29cd3..d4b058b 100644
37093--- a/drivers/block/drbd/drbd_receiver.c
37094+++ b/drivers/block/drbd/drbd_receiver.c
37095@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37096 {
37097 int err;
37098
37099- atomic_set(&mdev->packet_seq, 0);
37100+ atomic_set_unchecked(&mdev->packet_seq, 0);
37101 mdev->peer_seq = 0;
37102
37103 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37104@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37105 do {
37106 next_epoch = NULL;
37107
37108- epoch_size = atomic_read(&epoch->epoch_size);
37109+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37110
37111 switch (ev & ~EV_CLEANUP) {
37112 case EV_PUT:
37113@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37114 rv = FE_DESTROYED;
37115 } else {
37116 epoch->flags = 0;
37117- atomic_set(&epoch->epoch_size, 0);
37118+ atomic_set_unchecked(&epoch->epoch_size, 0);
37119 /* atomic_set(&epoch->active, 0); is already zero */
37120 if (rv == FE_STILL_LIVE)
37121 rv = FE_RECYCLED;
37122@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37123 conn_wait_active_ee_empty(tconn);
37124 drbd_flush(tconn);
37125
37126- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37127+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37128 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37129 if (epoch)
37130 break;
37131@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37132 }
37133
37134 epoch->flags = 0;
37135- atomic_set(&epoch->epoch_size, 0);
37136+ atomic_set_unchecked(&epoch->epoch_size, 0);
37137 atomic_set(&epoch->active, 0);
37138
37139 spin_lock(&tconn->epoch_lock);
37140- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37141+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37142 list_add(&epoch->list, &tconn->current_epoch->list);
37143 tconn->current_epoch = epoch;
37144 tconn->epochs++;
37145@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37146
37147 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37148 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37149- atomic_inc(&tconn->current_epoch->epoch_size);
37150+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37151 err2 = drbd_drain_block(mdev, pi->size);
37152 if (!err)
37153 err = err2;
37154@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37155
37156 spin_lock(&tconn->epoch_lock);
37157 peer_req->epoch = tconn->current_epoch;
37158- atomic_inc(&peer_req->epoch->epoch_size);
37159+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37160 atomic_inc(&peer_req->epoch->active);
37161 spin_unlock(&tconn->epoch_lock);
37162
37163@@ -4347,7 +4347,7 @@ struct data_cmd {
37164 int expect_payload;
37165 size_t pkt_size;
37166 int (*fn)(struct drbd_tconn *, struct packet_info *);
37167-};
37168+} __do_const;
37169
37170 static struct data_cmd drbd_cmd_handler[] = {
37171 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37172@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37173 if (!list_empty(&tconn->current_epoch->list))
37174 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37175 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37176- atomic_set(&tconn->current_epoch->epoch_size, 0);
37177+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37178 tconn->send.seen_any_write_yet = false;
37179
37180 conn_info(tconn, "Connection closed\n");
37181@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37182 struct asender_cmd {
37183 size_t pkt_size;
37184 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37185-};
37186+} __do_const;
37187
37188 static struct asender_cmd asender_tbl[] = {
37189 [P_PING] = { 0, got_Ping },
37190diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37191index c8dac73..1800093 100644
37192--- a/drivers/block/loop.c
37193+++ b/drivers/block/loop.c
37194@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37195
37196 file_start_write(file);
37197 set_fs(get_ds());
37198- bw = file->f_op->write(file, buf, len, &pos);
37199+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37200 set_fs(old_fs);
37201 file_end_write(file);
37202 if (likely(bw == len))
37203diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37204index 5618847..5a46f3b 100644
37205--- a/drivers/block/pktcdvd.c
37206+++ b/drivers/block/pktcdvd.c
37207@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37208
37209 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37210 {
37211- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37212+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37213 }
37214
37215 /*
37216@@ -1897,7 +1897,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37217 return -EROFS;
37218 }
37219 pd->settings.fp = ti.fp;
37220- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37221+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37222
37223 if (ti.nwa_v) {
37224 pd->nwa = be32_to_cpu(ti.next_writable);
37225diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37226index 60abf59..80789e1 100644
37227--- a/drivers/bluetooth/btwilink.c
37228+++ b/drivers/bluetooth/btwilink.c
37229@@ -293,7 +293,7 @@ static int ti_st_send_frame(struct sk_buff *skb)
37230
37231 static int bt_ti_probe(struct platform_device *pdev)
37232 {
37233- static struct ti_st *hst;
37234+ struct ti_st *hst;
37235 struct hci_dev *hdev;
37236 int err;
37237
37238diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37239index 2009266..7be9ca2 100644
37240--- a/drivers/bus/arm-cci.c
37241+++ b/drivers/bus/arm-cci.c
37242@@ -405,7 +405,7 @@ static int __init cci_probe(void)
37243
37244 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37245
37246- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37247+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37248 if (!ports)
37249 return -ENOMEM;
37250
37251diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37252index 8a3aff7..d7538c2 100644
37253--- a/drivers/cdrom/cdrom.c
37254+++ b/drivers/cdrom/cdrom.c
37255@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37256 ENSURE(reset, CDC_RESET);
37257 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37258 cdi->mc_flags = 0;
37259- cdo->n_minors = 0;
37260 cdi->options = CDO_USE_FFLAGS;
37261
37262 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37263@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37264 else
37265 cdi->cdda_method = CDDA_OLD;
37266
37267- if (!cdo->generic_packet)
37268- cdo->generic_packet = cdrom_dummy_generic_packet;
37269+ if (!cdo->generic_packet) {
37270+ pax_open_kernel();
37271+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37272+ pax_close_kernel();
37273+ }
37274
37275 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37276 mutex_lock(&cdrom_mutex);
37277@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37278 if (cdi->exit)
37279 cdi->exit(cdi);
37280
37281- cdi->ops->n_minors--;
37282 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37283 }
37284
37285@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37286 */
37287 nr = nframes;
37288 do {
37289- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37290+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37291 if (cgc.buffer)
37292 break;
37293
37294@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37295 struct cdrom_device_info *cdi;
37296 int ret;
37297
37298- ret = scnprintf(info + *pos, max_size - *pos, header);
37299+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37300 if (!ret)
37301 return 1;
37302
37303diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37304index 5980cb9..6d7bd7e 100644
37305--- a/drivers/cdrom/gdrom.c
37306+++ b/drivers/cdrom/gdrom.c
37307@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37308 .audio_ioctl = gdrom_audio_ioctl,
37309 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37310 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37311- .n_minors = 1,
37312 };
37313
37314 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37315diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37316index 1421997..33f5d6d 100644
37317--- a/drivers/char/Kconfig
37318+++ b/drivers/char/Kconfig
37319@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37320
37321 config DEVKMEM
37322 bool "/dev/kmem virtual device support"
37323- default y
37324+ default n
37325+ depends on !GRKERNSEC_KMEM
37326 help
37327 Say Y here if you want to support the /dev/kmem device. The
37328 /dev/kmem device is rarely used, but can be used for certain
37329@@ -570,6 +571,7 @@ config DEVPORT
37330 bool
37331 depends on !M68K
37332 depends on ISA || PCI
37333+ depends on !GRKERNSEC_KMEM
37334 default y
37335
37336 source "drivers/s390/char/Kconfig"
37337diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37338index a48e05b..6bac831 100644
37339--- a/drivers/char/agp/compat_ioctl.c
37340+++ b/drivers/char/agp/compat_ioctl.c
37341@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37342 return -ENOMEM;
37343 }
37344
37345- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37346+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37347 sizeof(*usegment) * ureserve.seg_count)) {
37348 kfree(usegment);
37349 kfree(ksegment);
37350diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37351index 1b19239..b87b143 100644
37352--- a/drivers/char/agp/frontend.c
37353+++ b/drivers/char/agp/frontend.c
37354@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37355 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37356 return -EFAULT;
37357
37358- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37359+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37360 return -EFAULT;
37361
37362 client = agp_find_client_by_pid(reserve.pid);
37363@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37364 if (segment == NULL)
37365 return -ENOMEM;
37366
37367- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37368+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37369 sizeof(struct agp_segment) * reserve.seg_count)) {
37370 kfree(segment);
37371 return -EFAULT;
37372diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37373index 4f94375..413694e 100644
37374--- a/drivers/char/genrtc.c
37375+++ b/drivers/char/genrtc.c
37376@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37377 switch (cmd) {
37378
37379 case RTC_PLL_GET:
37380+ memset(&pll, 0, sizeof(pll));
37381 if (get_rtc_pll(&pll))
37382 return -EINVAL;
37383 else
37384diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37385index 448ce5e..3a76625 100644
37386--- a/drivers/char/hpet.c
37387+++ b/drivers/char/hpet.c
37388@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37389 }
37390
37391 static int
37392-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37393+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37394 struct hpet_info *info)
37395 {
37396 struct hpet_timer __iomem *timer;
37397diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37398index 86fe45c..c0ea948 100644
37399--- a/drivers/char/hw_random/intel-rng.c
37400+++ b/drivers/char/hw_random/intel-rng.c
37401@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37402
37403 if (no_fwh_detect)
37404 return -ENODEV;
37405- printk(warning);
37406+ printk("%s", warning);
37407 return -EBUSY;
37408 }
37409
37410diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37411index ec4e10f..f2a763b 100644
37412--- a/drivers/char/ipmi/ipmi_msghandler.c
37413+++ b/drivers/char/ipmi/ipmi_msghandler.c
37414@@ -420,7 +420,7 @@ struct ipmi_smi {
37415 struct proc_dir_entry *proc_dir;
37416 char proc_dir_name[10];
37417
37418- atomic_t stats[IPMI_NUM_STATS];
37419+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37420
37421 /*
37422 * run_to_completion duplicate of smb_info, smi_info
37423@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37424
37425
37426 #define ipmi_inc_stat(intf, stat) \
37427- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37428+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37429 #define ipmi_get_stat(intf, stat) \
37430- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37431+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37432
37433 static int is_lan_addr(struct ipmi_addr *addr)
37434 {
37435@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37436 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37437 init_waitqueue_head(&intf->waitq);
37438 for (i = 0; i < IPMI_NUM_STATS; i++)
37439- atomic_set(&intf->stats[i], 0);
37440+ atomic_set_unchecked(&intf->stats[i], 0);
37441
37442 intf->proc_dir = NULL;
37443
37444diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37445index 15e4a60..b046093 100644
37446--- a/drivers/char/ipmi/ipmi_si_intf.c
37447+++ b/drivers/char/ipmi/ipmi_si_intf.c
37448@@ -280,7 +280,7 @@ struct smi_info {
37449 unsigned char slave_addr;
37450
37451 /* Counters and things for the proc filesystem. */
37452- atomic_t stats[SI_NUM_STATS];
37453+ atomic_unchecked_t stats[SI_NUM_STATS];
37454
37455 struct task_struct *thread;
37456
37457@@ -289,9 +289,9 @@ struct smi_info {
37458 };
37459
37460 #define smi_inc_stat(smi, stat) \
37461- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37462+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37463 #define smi_get_stat(smi, stat) \
37464- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37465+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37466
37467 #define SI_MAX_PARMS 4
37468
37469@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37470 atomic_set(&new_smi->req_events, 0);
37471 new_smi->run_to_completion = 0;
37472 for (i = 0; i < SI_NUM_STATS; i++)
37473- atomic_set(&new_smi->stats[i], 0);
37474+ atomic_set_unchecked(&new_smi->stats[i], 0);
37475
37476 new_smi->interrupt_disabled = 1;
37477 atomic_set(&new_smi->stop_operation, 0);
37478diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37479index f895a8c..2bc9147 100644
37480--- a/drivers/char/mem.c
37481+++ b/drivers/char/mem.c
37482@@ -18,6 +18,7 @@
37483 #include <linux/raw.h>
37484 #include <linux/tty.h>
37485 #include <linux/capability.h>
37486+#include <linux/security.h>
37487 #include <linux/ptrace.h>
37488 #include <linux/device.h>
37489 #include <linux/highmem.h>
37490@@ -37,6 +38,10 @@
37491
37492 #define DEVPORT_MINOR 4
37493
37494+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37495+extern const struct file_operations grsec_fops;
37496+#endif
37497+
37498 static inline unsigned long size_inside_page(unsigned long start,
37499 unsigned long size)
37500 {
37501@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37502
37503 while (cursor < to) {
37504 if (!devmem_is_allowed(pfn)) {
37505+#ifdef CONFIG_GRKERNSEC_KMEM
37506+ gr_handle_mem_readwrite(from, to);
37507+#else
37508 printk(KERN_INFO
37509 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37510 current->comm, from, to);
37511+#endif
37512 return 0;
37513 }
37514 cursor += PAGE_SIZE;
37515@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37516 }
37517 return 1;
37518 }
37519+#elif defined(CONFIG_GRKERNSEC_KMEM)
37520+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37521+{
37522+ return 0;
37523+}
37524 #else
37525 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37526 {
37527@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37528
37529 while (count > 0) {
37530 unsigned long remaining;
37531+ char *temp;
37532
37533 sz = size_inside_page(p, count);
37534
37535@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37536 if (!ptr)
37537 return -EFAULT;
37538
37539- remaining = copy_to_user(buf, ptr, sz);
37540+#ifdef CONFIG_PAX_USERCOPY
37541+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37542+ if (!temp) {
37543+ unxlate_dev_mem_ptr(p, ptr);
37544+ return -ENOMEM;
37545+ }
37546+ memcpy(temp, ptr, sz);
37547+#else
37548+ temp = ptr;
37549+#endif
37550+
37551+ remaining = copy_to_user(buf, temp, sz);
37552+
37553+#ifdef CONFIG_PAX_USERCOPY
37554+ kfree(temp);
37555+#endif
37556+
37557 unxlate_dev_mem_ptr(p, ptr);
37558 if (remaining)
37559 return -EFAULT;
37560@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37561 size_t count, loff_t *ppos)
37562 {
37563 unsigned long p = *ppos;
37564- ssize_t low_count, read, sz;
37565+ ssize_t low_count, read, sz, err = 0;
37566 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37567- int err = 0;
37568
37569 read = 0;
37570 if (p < (unsigned long) high_memory) {
37571@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37572 }
37573 #endif
37574 while (low_count > 0) {
37575+ char *temp;
37576+
37577 sz = size_inside_page(p, low_count);
37578
37579 /*
37580@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37581 */
37582 kbuf = xlate_dev_kmem_ptr((char *)p);
37583
37584- if (copy_to_user(buf, kbuf, sz))
37585+#ifdef CONFIG_PAX_USERCOPY
37586+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37587+ if (!temp)
37588+ return -ENOMEM;
37589+ memcpy(temp, kbuf, sz);
37590+#else
37591+ temp = kbuf;
37592+#endif
37593+
37594+ err = copy_to_user(buf, temp, sz);
37595+
37596+#ifdef CONFIG_PAX_USERCOPY
37597+ kfree(temp);
37598+#endif
37599+
37600+ if (err)
37601 return -EFAULT;
37602 buf += sz;
37603 p += sz;
37604@@ -822,6 +869,9 @@ static const struct memdev {
37605 #ifdef CONFIG_PRINTK
37606 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37607 #endif
37608+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37609+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37610+#endif
37611 };
37612
37613 static int memory_open(struct inode *inode, struct file *filp)
37614@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37615 continue;
37616
37617 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37618- NULL, devlist[minor].name);
37619+ NULL, "%s", devlist[minor].name);
37620 }
37621
37622 return tty_init();
37623diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37624index 9df78e2..01ba9ae 100644
37625--- a/drivers/char/nvram.c
37626+++ b/drivers/char/nvram.c
37627@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37628
37629 spin_unlock_irq(&rtc_lock);
37630
37631- if (copy_to_user(buf, contents, tmp - contents))
37632+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37633 return -EFAULT;
37634
37635 *ppos = i;
37636diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37637index d39cca6..8c1e269 100644
37638--- a/drivers/char/pcmcia/synclink_cs.c
37639+++ b/drivers/char/pcmcia/synclink_cs.c
37640@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37641
37642 if (debug_level >= DEBUG_LEVEL_INFO)
37643 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37644- __FILE__, __LINE__, info->device_name, port->count);
37645+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37646
37647- WARN_ON(!port->count);
37648+ WARN_ON(!atomic_read(&port->count));
37649
37650 if (tty_port_close_start(port, tty, filp) == 0)
37651 goto cleanup;
37652@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37653 cleanup:
37654 if (debug_level >= DEBUG_LEVEL_INFO)
37655 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37656- tty->driver->name, port->count);
37657+ tty->driver->name, atomic_read(&port->count));
37658 }
37659
37660 /* Wait until the transmitter is empty.
37661@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37662
37663 if (debug_level >= DEBUG_LEVEL_INFO)
37664 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37665- __FILE__, __LINE__, tty->driver->name, port->count);
37666+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37667
37668 /* If port is closing, signal caller to try again */
37669 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37670@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37671 goto cleanup;
37672 }
37673 spin_lock(&port->lock);
37674- port->count++;
37675+ atomic_inc(&port->count);
37676 spin_unlock(&port->lock);
37677 spin_unlock_irqrestore(&info->netlock, flags);
37678
37679- if (port->count == 1) {
37680+ if (atomic_read(&port->count) == 1) {
37681 /* 1st open on this device, init hardware */
37682 retval = startup(info, tty);
37683 if (retval < 0)
37684@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37685 unsigned short new_crctype;
37686
37687 /* return error if TTY interface open */
37688- if (info->port.count)
37689+ if (atomic_read(&info->port.count))
37690 return -EBUSY;
37691
37692 switch (encoding)
37693@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37694
37695 /* arbitrate between network and tty opens */
37696 spin_lock_irqsave(&info->netlock, flags);
37697- if (info->port.count != 0 || info->netcount != 0) {
37698+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37699 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37700 spin_unlock_irqrestore(&info->netlock, flags);
37701 return -EBUSY;
37702@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37703 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37704
37705 /* return error if TTY interface open */
37706- if (info->port.count)
37707+ if (atomic_read(&info->port.count))
37708 return -EBUSY;
37709
37710 if (cmd != SIOCWANDEV)
37711diff --git a/drivers/char/random.c b/drivers/char/random.c
37712index 7a744d3..35a177ee 100644
37713--- a/drivers/char/random.c
37714+++ b/drivers/char/random.c
37715@@ -269,8 +269,13 @@
37716 /*
37717 * Configuration information
37718 */
37719+#ifdef CONFIG_GRKERNSEC_RANDNET
37720+#define INPUT_POOL_WORDS 512
37721+#define OUTPUT_POOL_WORDS 128
37722+#else
37723 #define INPUT_POOL_WORDS 128
37724 #define OUTPUT_POOL_WORDS 32
37725+#endif
37726 #define SEC_XFER_SIZE 512
37727 #define EXTRACT_SIZE 10
37728
37729@@ -310,10 +315,17 @@ static struct poolinfo {
37730 int poolwords;
37731 int tap1, tap2, tap3, tap4, tap5;
37732 } poolinfo_table[] = {
37733+#ifdef CONFIG_GRKERNSEC_RANDNET
37734+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37735+ { 512, 411, 308, 208, 104, 1 },
37736+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37737+ { 128, 103, 76, 51, 25, 1 },
37738+#else
37739 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
37740 { 128, 103, 76, 51, 25, 1 },
37741 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
37742 { 32, 26, 20, 14, 7, 1 },
37743+#endif
37744 #if 0
37745 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37746 { 2048, 1638, 1231, 819, 411, 1 },
37747@@ -521,8 +533,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37748 input_rotate += i ? 7 : 14;
37749 }
37750
37751- ACCESS_ONCE(r->input_rotate) = input_rotate;
37752- ACCESS_ONCE(r->add_ptr) = i;
37753+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37754+ ACCESS_ONCE_RW(r->add_ptr) = i;
37755 smp_wmb();
37756
37757 if (out)
37758@@ -1029,7 +1041,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37759
37760 extract_buf(r, tmp);
37761 i = min_t(int, nbytes, EXTRACT_SIZE);
37762- if (copy_to_user(buf, tmp, i)) {
37763+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37764 ret = -EFAULT;
37765 break;
37766 }
37767@@ -1365,7 +1377,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37768 #include <linux/sysctl.h>
37769
37770 static int min_read_thresh = 8, min_write_thresh;
37771-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37772+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37773 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37774 static char sysctl_bootid[16];
37775
37776@@ -1381,7 +1393,7 @@ static char sysctl_bootid[16];
37777 static int proc_do_uuid(struct ctl_table *table, int write,
37778 void __user *buffer, size_t *lenp, loff_t *ppos)
37779 {
37780- struct ctl_table fake_table;
37781+ ctl_table_no_const fake_table;
37782 unsigned char buf[64], tmp_uuid[16], *uuid;
37783
37784 uuid = table->data;
37785diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37786index 7cc1fe22..b602d6b 100644
37787--- a/drivers/char/sonypi.c
37788+++ b/drivers/char/sonypi.c
37789@@ -54,6 +54,7 @@
37790
37791 #include <asm/uaccess.h>
37792 #include <asm/io.h>
37793+#include <asm/local.h>
37794
37795 #include <linux/sonypi.h>
37796
37797@@ -490,7 +491,7 @@ static struct sonypi_device {
37798 spinlock_t fifo_lock;
37799 wait_queue_head_t fifo_proc_list;
37800 struct fasync_struct *fifo_async;
37801- int open_count;
37802+ local_t open_count;
37803 int model;
37804 struct input_dev *input_jog_dev;
37805 struct input_dev *input_key_dev;
37806@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37807 static int sonypi_misc_release(struct inode *inode, struct file *file)
37808 {
37809 mutex_lock(&sonypi_device.lock);
37810- sonypi_device.open_count--;
37811+ local_dec(&sonypi_device.open_count);
37812 mutex_unlock(&sonypi_device.lock);
37813 return 0;
37814 }
37815@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37816 {
37817 mutex_lock(&sonypi_device.lock);
37818 /* Flush input queue on first open */
37819- if (!sonypi_device.open_count)
37820+ if (!local_read(&sonypi_device.open_count))
37821 kfifo_reset(&sonypi_device.fifo);
37822- sonypi_device.open_count++;
37823+ local_inc(&sonypi_device.open_count);
37824 mutex_unlock(&sonypi_device.lock);
37825
37826 return 0;
37827diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37828index 64420b3..5c40b56 100644
37829--- a/drivers/char/tpm/tpm_acpi.c
37830+++ b/drivers/char/tpm/tpm_acpi.c
37831@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37832 virt = acpi_os_map_memory(start, len);
37833 if (!virt) {
37834 kfree(log->bios_event_log);
37835+ log->bios_event_log = NULL;
37836 printk("%s: ERROR - Unable to map memory\n", __func__);
37837 return -EIO;
37838 }
37839
37840- memcpy_fromio(log->bios_event_log, virt, len);
37841+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37842
37843 acpi_os_unmap_memory(virt, len);
37844 return 0;
37845diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37846index 84ddc55..1d32f1e 100644
37847--- a/drivers/char/tpm/tpm_eventlog.c
37848+++ b/drivers/char/tpm/tpm_eventlog.c
37849@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37850 event = addr;
37851
37852 if ((event->event_type == 0 && event->event_size == 0) ||
37853- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37854+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37855 return NULL;
37856
37857 return addr;
37858@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37859 return NULL;
37860
37861 if ((event->event_type == 0 && event->event_size == 0) ||
37862- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37863+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37864 return NULL;
37865
37866 (*pos)++;
37867@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37868 int i;
37869
37870 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37871- seq_putc(m, data[i]);
37872+ if (!seq_putc(m, data[i]))
37873+ return -EFAULT;
37874
37875 return 0;
37876 }
37877diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37878index b79cf3e..de172d64f 100644
37879--- a/drivers/char/virtio_console.c
37880+++ b/drivers/char/virtio_console.c
37881@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37882 if (to_user) {
37883 ssize_t ret;
37884
37885- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37886+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37887 if (ret)
37888 return -EFAULT;
37889 } else {
37890@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37891 if (!port_has_data(port) && !port->host_connected)
37892 return 0;
37893
37894- return fill_readbuf(port, ubuf, count, true);
37895+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37896 }
37897
37898 static int wait_port_writable(struct port *port, bool nonblock)
37899diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37900index a33f46f..a720eed 100644
37901--- a/drivers/clk/clk-composite.c
37902+++ b/drivers/clk/clk-composite.c
37903@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37904 struct clk *clk;
37905 struct clk_init_data init;
37906 struct clk_composite *composite;
37907- struct clk_ops *clk_composite_ops;
37908+ clk_ops_no_const *clk_composite_ops;
37909
37910 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37911 if (!composite) {
37912diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37913index 81dd31a..ef5c542 100644
37914--- a/drivers/clk/socfpga/clk.c
37915+++ b/drivers/clk/socfpga/clk.c
37916@@ -22,6 +22,7 @@
37917 #include <linux/clk-provider.h>
37918 #include <linux/io.h>
37919 #include <linux/of.h>
37920+#include <asm/pgtable.h>
37921
37922 /* Clock Manager offsets */
37923 #define CLKMGR_CTRL 0x0
37924@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37925 streq(clk_name, "periph_pll") ||
37926 streq(clk_name, "sdram_pll")) {
37927 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37928- clk_pll_ops.enable = clk_gate_ops.enable;
37929- clk_pll_ops.disable = clk_gate_ops.disable;
37930+ pax_open_kernel();
37931+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37932+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37933+ pax_close_kernel();
37934 }
37935
37936 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37937@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37938 return parent_rate / div;
37939 }
37940
37941-static struct clk_ops gateclk_ops = {
37942+static clk_ops_no_const gateclk_ops __read_only = {
37943 .recalc_rate = socfpga_clk_recalc_rate,
37944 .get_parent = socfpga_clk_get_parent,
37945 .set_parent = socfpga_clk_set_parent,
37946diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37947index 506fd23..01a593f 100644
37948--- a/drivers/cpufreq/acpi-cpufreq.c
37949+++ b/drivers/cpufreq/acpi-cpufreq.c
37950@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37951 return sprintf(buf, "%u\n", boost_enabled);
37952 }
37953
37954-static struct global_attr global_boost = __ATTR(boost, 0644,
37955+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37956 show_global_boost,
37957 store_global_boost);
37958
37959@@ -721,8 +721,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37960 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37961 per_cpu(acfreq_data, cpu) = data;
37962
37963- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37964- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37965+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37966+ pax_open_kernel();
37967+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37968+ pax_close_kernel();
37969+ }
37970
37971 result = acpi_processor_register_performance(data->acpi_data, cpu);
37972 if (result)
37973@@ -850,7 +853,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37974 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37975 break;
37976 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37977- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37978+ pax_open_kernel();
37979+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37980+ pax_close_kernel();
37981 policy->cur = get_cur_freq_on_cpu(cpu);
37982 break;
37983 default:
37984diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37985index 04548f7..457a342 100644
37986--- a/drivers/cpufreq/cpufreq.c
37987+++ b/drivers/cpufreq/cpufreq.c
37988@@ -2069,7 +2069,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37989 return NOTIFY_OK;
37990 }
37991
37992-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37993+static struct notifier_block cpufreq_cpu_notifier = {
37994 .notifier_call = cpufreq_cpu_callback,
37995 };
37996
37997@@ -2101,8 +2101,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37998
37999 pr_debug("trying to register driver %s\n", driver_data->name);
38000
38001- if (driver_data->setpolicy)
38002- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38003+ if (driver_data->setpolicy) {
38004+ pax_open_kernel();
38005+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38006+ pax_close_kernel();
38007+ }
38008
38009 write_lock_irqsave(&cpufreq_driver_lock, flags);
38010 if (cpufreq_driver) {
38011diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38012index 0806c31..6a73276 100644
38013--- a/drivers/cpufreq/cpufreq_governor.c
38014+++ b/drivers/cpufreq/cpufreq_governor.c
38015@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38016 struct dbs_data *dbs_data;
38017 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38018 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38019- struct od_ops *od_ops = NULL;
38020+ const struct od_ops *od_ops = NULL;
38021 struct od_dbs_tuners *od_tuners = NULL;
38022 struct cs_dbs_tuners *cs_tuners = NULL;
38023 struct cpu_dbs_common_info *cpu_cdbs;
38024@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38025
38026 if ((cdata->governor == GOV_CONSERVATIVE) &&
38027 (!policy->governor->initialized)) {
38028- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38029+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38030
38031 cpufreq_register_notifier(cs_ops->notifier_block,
38032 CPUFREQ_TRANSITION_NOTIFIER);
38033@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38034
38035 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38036 (policy->governor->initialized == 1)) {
38037- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38038+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38039
38040 cpufreq_unregister_notifier(cs_ops->notifier_block,
38041 CPUFREQ_TRANSITION_NOTIFIER);
38042diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38043index 88cd39f..87f0393 100644
38044--- a/drivers/cpufreq/cpufreq_governor.h
38045+++ b/drivers/cpufreq/cpufreq_governor.h
38046@@ -202,7 +202,7 @@ struct common_dbs_data {
38047 void (*exit)(struct dbs_data *dbs_data);
38048
38049 /* Governor specific ops, see below */
38050- void *gov_ops;
38051+ const void *gov_ops;
38052 };
38053
38054 /* Governor Per policy data */
38055@@ -222,7 +222,7 @@ struct od_ops {
38056 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38057 unsigned int freq_next, unsigned int relation);
38058 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38059-};
38060+} __no_const;
38061
38062 struct cs_ops {
38063 struct notifier_block *notifier_block;
38064diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38065index 32f26f6..feb657b 100644
38066--- a/drivers/cpufreq/cpufreq_ondemand.c
38067+++ b/drivers/cpufreq/cpufreq_ondemand.c
38068@@ -522,7 +522,7 @@ static void od_exit(struct dbs_data *dbs_data)
38069
38070 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38071
38072-static struct od_ops od_ops = {
38073+static struct od_ops od_ops __read_only = {
38074 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38075 .powersave_bias_target = generic_powersave_bias_target,
38076 .freq_increase = dbs_freq_increase,
38077@@ -577,14 +577,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38078 (struct cpufreq_policy *, unsigned int, unsigned int),
38079 unsigned int powersave_bias)
38080 {
38081- od_ops.powersave_bias_target = f;
38082+ pax_open_kernel();
38083+ *(void **)&od_ops.powersave_bias_target = f;
38084+ pax_close_kernel();
38085 od_set_powersave_bias(powersave_bias);
38086 }
38087 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38088
38089 void od_unregister_powersave_bias_handler(void)
38090 {
38091- od_ops.powersave_bias_target = generic_powersave_bias_target;
38092+ pax_open_kernel();
38093+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38094+ pax_close_kernel();
38095 od_set_powersave_bias(0);
38096 }
38097 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38098diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38099index 4cf0d28..5830372 100644
38100--- a/drivers/cpufreq/cpufreq_stats.c
38101+++ b/drivers/cpufreq/cpufreq_stats.c
38102@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38103 }
38104
38105 /* priority=1 so this will get called before cpufreq_remove_dev */
38106-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38107+static struct notifier_block cpufreq_stat_cpu_notifier = {
38108 .notifier_call = cpufreq_stat_cpu_callback,
38109 .priority = 1,
38110 };
38111diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38112index 2f0a2a6..93d728e 100644
38113--- a/drivers/cpufreq/p4-clockmod.c
38114+++ b/drivers/cpufreq/p4-clockmod.c
38115@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38116 case 0x0F: /* Core Duo */
38117 case 0x16: /* Celeron Core */
38118 case 0x1C: /* Atom */
38119- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38120+ pax_open_kernel();
38121+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38122+ pax_close_kernel();
38123 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38124 case 0x0D: /* Pentium M (Dothan) */
38125- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38126+ pax_open_kernel();
38127+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38128+ pax_close_kernel();
38129 /* fall through */
38130 case 0x09: /* Pentium M (Banias) */
38131 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38132@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38133
38134 /* on P-4s, the TSC runs with constant frequency independent whether
38135 * throttling is active or not. */
38136- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38137+ pax_open_kernel();
38138+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38139+ pax_close_kernel();
38140
38141 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38142 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38143diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38144index ac76b48..2445bc6 100644
38145--- a/drivers/cpufreq/sparc-us3-cpufreq.c
38146+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38147@@ -18,14 +18,12 @@
38148 #include <asm/head.h>
38149 #include <asm/timer.h>
38150
38151-static struct cpufreq_driver *cpufreq_us3_driver;
38152-
38153 struct us3_freq_percpu_info {
38154 struct cpufreq_frequency_table table[4];
38155 };
38156
38157 /* Indexed by cpu number. */
38158-static struct us3_freq_percpu_info *us3_freq_table;
38159+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38160
38161 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38162 * in the Safari config register.
38163@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38164
38165 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38166 {
38167- if (cpufreq_us3_driver)
38168- us3_set_cpu_divider_index(policy, 0);
38169+ us3_set_cpu_divider_index(policy->cpu, 0);
38170
38171 return 0;
38172 }
38173
38174+static int __init us3_freq_init(void);
38175+static void __exit us3_freq_exit(void);
38176+
38177+static struct cpufreq_driver cpufreq_us3_driver = {
38178+ .init = us3_freq_cpu_init,
38179+ .verify = us3_freq_verify,
38180+ .target = us3_freq_target,
38181+ .get = us3_freq_get,
38182+ .exit = us3_freq_cpu_exit,
38183+ .owner = THIS_MODULE,
38184+ .name = "UltraSPARC-III",
38185+
38186+};
38187+
38188 static int __init us3_freq_init(void)
38189 {
38190 unsigned long manuf, impl, ver;
38191@@ -208,55 +219,15 @@ static int __init us3_freq_init(void)
38192 (impl == CHEETAH_IMPL ||
38193 impl == CHEETAH_PLUS_IMPL ||
38194 impl == JAGUAR_IMPL ||
38195- impl == PANTHER_IMPL)) {
38196- struct cpufreq_driver *driver;
38197-
38198- ret = -ENOMEM;
38199- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38200- if (!driver)
38201- goto err_out;
38202-
38203- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38204- GFP_KERNEL);
38205- if (!us3_freq_table)
38206- goto err_out;
38207-
38208- driver->init = us3_freq_cpu_init;
38209- driver->verify = us3_freq_verify;
38210- driver->target = us3_freq_target;
38211- driver->get = us3_freq_get;
38212- driver->exit = us3_freq_cpu_exit;
38213- strcpy(driver->name, "UltraSPARC-III");
38214-
38215- cpufreq_us3_driver = driver;
38216- ret = cpufreq_register_driver(driver);
38217- if (ret)
38218- goto err_out;
38219-
38220- return 0;
38221-
38222-err_out:
38223- if (driver) {
38224- kfree(driver);
38225- cpufreq_us3_driver = NULL;
38226- }
38227- kfree(us3_freq_table);
38228- us3_freq_table = NULL;
38229- return ret;
38230- }
38231+ impl == PANTHER_IMPL))
38232+ return cpufreq_register_driver(&cpufreq_us3_driver);
38233
38234 return -ENODEV;
38235 }
38236
38237 static void __exit us3_freq_exit(void)
38238 {
38239- if (cpufreq_us3_driver) {
38240- cpufreq_unregister_driver(cpufreq_us3_driver);
38241- kfree(cpufreq_us3_driver);
38242- cpufreq_us3_driver = NULL;
38243- kfree(us3_freq_table);
38244- us3_freq_table = NULL;
38245- }
38246+ cpufreq_unregister_driver(&cpufreq_us3_driver);
38247 }
38248
38249 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38250diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38251index f897d51..15da295 100644
38252--- a/drivers/cpufreq/speedstep-centrino.c
38253+++ b/drivers/cpufreq/speedstep-centrino.c
38254@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38255 !cpu_has(cpu, X86_FEATURE_EST))
38256 return -ENODEV;
38257
38258- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38259- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38260+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38261+ pax_open_kernel();
38262+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38263+ pax_close_kernel();
38264+ }
38265
38266 if (policy->cpu != 0)
38267 return -ENODEV;
38268diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
38269index 22c07fb..9dff5ac 100644
38270--- a/drivers/cpuidle/cpuidle.c
38271+++ b/drivers/cpuidle/cpuidle.c
38272@@ -252,7 +252,7 @@ static int poll_idle(struct cpuidle_device *dev,
38273
38274 static void poll_idle_init(struct cpuidle_driver *drv)
38275 {
38276- struct cpuidle_state *state = &drv->states[0];
38277+ cpuidle_state_no_const *state = &drv->states[0];
38278
38279 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38280 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38281diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38282index ea2f8e7..70ac501 100644
38283--- a/drivers/cpuidle/governor.c
38284+++ b/drivers/cpuidle/governor.c
38285@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38286 mutex_lock(&cpuidle_lock);
38287 if (__cpuidle_find_governor(gov->name) == NULL) {
38288 ret = 0;
38289- list_add_tail(&gov->governor_list, &cpuidle_governors);
38290+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38291 if (!cpuidle_curr_governor ||
38292 cpuidle_curr_governor->rating < gov->rating)
38293 cpuidle_switch_governor(gov);
38294@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
38295 new_gov = cpuidle_replace_governor(gov->rating);
38296 cpuidle_switch_governor(new_gov);
38297 }
38298- list_del(&gov->governor_list);
38299+ pax_list_del((struct list_head *)&gov->governor_list);
38300 mutex_unlock(&cpuidle_lock);
38301 }
38302
38303diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38304index 8739cc0..dc859d0 100644
38305--- a/drivers/cpuidle/sysfs.c
38306+++ b/drivers/cpuidle/sysfs.c
38307@@ -134,7 +134,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38308 NULL
38309 };
38310
38311-static struct attribute_group cpuidle_attr_group = {
38312+static attribute_group_no_const cpuidle_attr_group = {
38313 .attrs = cpuidle_default_attrs,
38314 .name = "cpuidle",
38315 };
38316diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38317index 12fea3e..1e28f47 100644
38318--- a/drivers/crypto/hifn_795x.c
38319+++ b/drivers/crypto/hifn_795x.c
38320@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38321 MODULE_PARM_DESC(hifn_pll_ref,
38322 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38323
38324-static atomic_t hifn_dev_number;
38325+static atomic_unchecked_t hifn_dev_number;
38326
38327 #define ACRYPTO_OP_DECRYPT 0
38328 #define ACRYPTO_OP_ENCRYPT 1
38329@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38330 goto err_out_disable_pci_device;
38331
38332 snprintf(name, sizeof(name), "hifn%d",
38333- atomic_inc_return(&hifn_dev_number)-1);
38334+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38335
38336 err = pci_request_regions(pdev, name);
38337 if (err)
38338diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38339index c99c00d..990a4b2 100644
38340--- a/drivers/devfreq/devfreq.c
38341+++ b/drivers/devfreq/devfreq.c
38342@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38343 goto err_out;
38344 }
38345
38346- list_add(&governor->node, &devfreq_governor_list);
38347+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38348
38349 list_for_each_entry(devfreq, &devfreq_list, node) {
38350 int ret = 0;
38351@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38352 }
38353 }
38354
38355- list_del(&governor->node);
38356+ pax_list_del((struct list_head *)&governor->node);
38357 err_out:
38358 mutex_unlock(&devfreq_list_lock);
38359
38360diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38361index 1069e88..dfcd642 100644
38362--- a/drivers/dma/sh/shdmac.c
38363+++ b/drivers/dma/sh/shdmac.c
38364@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38365 return ret;
38366 }
38367
38368-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38369+static struct notifier_block sh_dmae_nmi_notifier = {
38370 .notifier_call = sh_dmae_nmi_handler,
38371
38372 /* Run before NMI debug handler and KGDB */
38373diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38374index 211021d..201d47f 100644
38375--- a/drivers/edac/edac_device.c
38376+++ b/drivers/edac/edac_device.c
38377@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38378 */
38379 int edac_device_alloc_index(void)
38380 {
38381- static atomic_t device_indexes = ATOMIC_INIT(0);
38382+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38383
38384- return atomic_inc_return(&device_indexes) - 1;
38385+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38386 }
38387 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38388
38389diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38390index 9f7e0e60..348c875 100644
38391--- a/drivers/edac/edac_mc_sysfs.c
38392+++ b/drivers/edac/edac_mc_sysfs.c
38393@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38394 struct dev_ch_attribute {
38395 struct device_attribute attr;
38396 int channel;
38397-};
38398+} __do_const;
38399
38400 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38401 struct dev_ch_attribute dev_attr_legacy_##_name = \
38402@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38403 }
38404
38405 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38406+ pax_open_kernel();
38407 if (mci->get_sdram_scrub_rate) {
38408- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38409- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38410+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38411+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38412 }
38413 if (mci->set_sdram_scrub_rate) {
38414- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38415- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38416+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38417+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38418 }
38419+ pax_close_kernel();
38420 err = device_create_file(&mci->dev,
38421 &dev_attr_sdram_scrub_rate);
38422 if (err) {
38423diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38424index dd370f9..0281629 100644
38425--- a/drivers/edac/edac_pci.c
38426+++ b/drivers/edac/edac_pci.c
38427@@ -29,7 +29,7 @@
38428
38429 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38430 static LIST_HEAD(edac_pci_list);
38431-static atomic_t pci_indexes = ATOMIC_INIT(0);
38432+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38433
38434 /*
38435 * edac_pci_alloc_ctl_info
38436@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38437 */
38438 int edac_pci_alloc_index(void)
38439 {
38440- return atomic_inc_return(&pci_indexes) - 1;
38441+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38442 }
38443 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38444
38445diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38446index e8658e4..22746d6 100644
38447--- a/drivers/edac/edac_pci_sysfs.c
38448+++ b/drivers/edac/edac_pci_sysfs.c
38449@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38450 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38451 static int edac_pci_poll_msec = 1000; /* one second workq period */
38452
38453-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38454-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38455+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38456+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38457
38458 static struct kobject *edac_pci_top_main_kobj;
38459 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38460@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38461 void *value;
38462 ssize_t(*show) (void *, char *);
38463 ssize_t(*store) (void *, const char *, size_t);
38464-};
38465+} __do_const;
38466
38467 /* Set of show/store abstract level functions for PCI Parity object */
38468 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38469@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38470 edac_printk(KERN_CRIT, EDAC_PCI,
38471 "Signaled System Error on %s\n",
38472 pci_name(dev));
38473- atomic_inc(&pci_nonparity_count);
38474+ atomic_inc_unchecked(&pci_nonparity_count);
38475 }
38476
38477 if (status & (PCI_STATUS_PARITY)) {
38478@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38479 "Master Data Parity Error on %s\n",
38480 pci_name(dev));
38481
38482- atomic_inc(&pci_parity_count);
38483+ atomic_inc_unchecked(&pci_parity_count);
38484 }
38485
38486 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38487@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38488 "Detected Parity Error on %s\n",
38489 pci_name(dev));
38490
38491- atomic_inc(&pci_parity_count);
38492+ atomic_inc_unchecked(&pci_parity_count);
38493 }
38494 }
38495
38496@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38497 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38498 "Signaled System Error on %s\n",
38499 pci_name(dev));
38500- atomic_inc(&pci_nonparity_count);
38501+ atomic_inc_unchecked(&pci_nonparity_count);
38502 }
38503
38504 if (status & (PCI_STATUS_PARITY)) {
38505@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38506 "Master Data Parity Error on "
38507 "%s\n", pci_name(dev));
38508
38509- atomic_inc(&pci_parity_count);
38510+ atomic_inc_unchecked(&pci_parity_count);
38511 }
38512
38513 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38514@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38515 "Detected Parity Error on %s\n",
38516 pci_name(dev));
38517
38518- atomic_inc(&pci_parity_count);
38519+ atomic_inc_unchecked(&pci_parity_count);
38520 }
38521 }
38522 }
38523@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38524 if (!check_pci_errors)
38525 return;
38526
38527- before_count = atomic_read(&pci_parity_count);
38528+ before_count = atomic_read_unchecked(&pci_parity_count);
38529
38530 /* scan all PCI devices looking for a Parity Error on devices and
38531 * bridges.
38532@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38533 /* Only if operator has selected panic on PCI Error */
38534 if (edac_pci_get_panic_on_pe()) {
38535 /* If the count is different 'after' from 'before' */
38536- if (before_count != atomic_read(&pci_parity_count))
38537+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38538 panic("EDAC: PCI Parity Error");
38539 }
38540 }
38541diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38542index 51b7e3a..aa8a3e8 100644
38543--- a/drivers/edac/mce_amd.h
38544+++ b/drivers/edac/mce_amd.h
38545@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38546 bool (*mc0_mce)(u16, u8);
38547 bool (*mc1_mce)(u16, u8);
38548 bool (*mc2_mce)(u16, u8);
38549-};
38550+} __no_const;
38551
38552 void amd_report_gart_errors(bool);
38553 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38554diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38555index 57ea7f4..af06b76 100644
38556--- a/drivers/firewire/core-card.c
38557+++ b/drivers/firewire/core-card.c
38558@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38559 const struct fw_card_driver *driver,
38560 struct device *device)
38561 {
38562- static atomic_t index = ATOMIC_INIT(-1);
38563+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38564
38565- card->index = atomic_inc_return(&index);
38566+ card->index = atomic_inc_return_unchecked(&index);
38567 card->driver = driver;
38568 card->device = device;
38569 card->current_tlabel = 0;
38570@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38571
38572 void fw_core_remove_card(struct fw_card *card)
38573 {
38574- struct fw_card_driver dummy_driver = dummy_driver_template;
38575+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38576
38577 card->driver->update_phy_reg(card, 4,
38578 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38579diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38580index de4aa40..49ab1f2 100644
38581--- a/drivers/firewire/core-device.c
38582+++ b/drivers/firewire/core-device.c
38583@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38584 struct config_rom_attribute {
38585 struct device_attribute attr;
38586 u32 key;
38587-};
38588+} __do_const;
38589
38590 static ssize_t show_immediate(struct device *dev,
38591 struct device_attribute *dattr, char *buf)
38592diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38593index e5af0e3..d318058 100644
38594--- a/drivers/firewire/core-transaction.c
38595+++ b/drivers/firewire/core-transaction.c
38596@@ -38,6 +38,7 @@
38597 #include <linux/timer.h>
38598 #include <linux/types.h>
38599 #include <linux/workqueue.h>
38600+#include <linux/sched.h>
38601
38602 #include <asm/byteorder.h>
38603
38604diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38605index 515a42c..5ecf3ba 100644
38606--- a/drivers/firewire/core.h
38607+++ b/drivers/firewire/core.h
38608@@ -111,6 +111,7 @@ struct fw_card_driver {
38609
38610 int (*stop_iso)(struct fw_iso_context *ctx);
38611 };
38612+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38613
38614 void fw_card_initialize(struct fw_card *card,
38615 const struct fw_card_driver *driver, struct device *device);
38616diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38617index 94a58a0..f5eba42 100644
38618--- a/drivers/firmware/dmi-id.c
38619+++ b/drivers/firmware/dmi-id.c
38620@@ -16,7 +16,7 @@
38621 struct dmi_device_attribute{
38622 struct device_attribute dev_attr;
38623 int field;
38624-};
38625+} __do_const;
38626 #define to_dmi_dev_attr(_dev_attr) \
38627 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38628
38629diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38630index fa0affb..aa448eb 100644
38631--- a/drivers/firmware/dmi_scan.c
38632+++ b/drivers/firmware/dmi_scan.c
38633@@ -791,7 +791,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38634 if (buf == NULL)
38635 return -1;
38636
38637- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38638+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38639
38640 iounmap(buf);
38641 return 0;
38642diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38643index 5145fa3..0d3babd 100644
38644--- a/drivers/firmware/efi/efi.c
38645+++ b/drivers/firmware/efi/efi.c
38646@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38647 };
38648
38649 static struct efivars generic_efivars;
38650-static struct efivar_operations generic_ops;
38651+static efivar_operations_no_const generic_ops __read_only;
38652
38653 static int generic_ops_register(void)
38654 {
38655- generic_ops.get_variable = efi.get_variable;
38656- generic_ops.set_variable = efi.set_variable;
38657- generic_ops.get_next_variable = efi.get_next_variable;
38658- generic_ops.query_variable_store = efi_query_variable_store;
38659+ pax_open_kernel();
38660+ *(void **)&generic_ops.get_variable = efi.get_variable;
38661+ *(void **)&generic_ops.set_variable = efi.set_variable;
38662+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38663+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38664+ pax_close_kernel();
38665
38666 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38667 }
38668diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38669index 8c5a61a..cf07bd0 100644
38670--- a/drivers/firmware/efi/efivars.c
38671+++ b/drivers/firmware/efi/efivars.c
38672@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38673 static int
38674 create_efivars_bin_attributes(void)
38675 {
38676- struct bin_attribute *attr;
38677+ bin_attribute_no_const *attr;
38678 int error;
38679
38680 /* new_var */
38681diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38682index 2a90ba6..07f3733 100644
38683--- a/drivers/firmware/google/memconsole.c
38684+++ b/drivers/firmware/google/memconsole.c
38685@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38686 if (!found_memconsole())
38687 return -ENODEV;
38688
38689- memconsole_bin_attr.size = memconsole_length;
38690+ pax_open_kernel();
38691+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38692+ pax_close_kernel();
38693
38694 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38695
38696diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38697index 814addb..0937d7f 100644
38698--- a/drivers/gpio/gpio-ich.c
38699+++ b/drivers/gpio/gpio-ich.c
38700@@ -71,7 +71,7 @@ struct ichx_desc {
38701 /* Some chipsets have quirks, let these use their own request/get */
38702 int (*request)(struct gpio_chip *chip, unsigned offset);
38703 int (*get)(struct gpio_chip *chip, unsigned offset);
38704-};
38705+} __do_const;
38706
38707 static struct {
38708 spinlock_t lock;
38709diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38710index 9902732..64b62dd 100644
38711--- a/drivers/gpio/gpio-vr41xx.c
38712+++ b/drivers/gpio/gpio-vr41xx.c
38713@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38714 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38715 maskl, pendl, maskh, pendh);
38716
38717- atomic_inc(&irq_err_count);
38718+ atomic_inc_unchecked(&irq_err_count);
38719
38720 return -EINVAL;
38721 }
38722diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38723index c722c3b..2ec6040 100644
38724--- a/drivers/gpu/drm/drm_crtc_helper.c
38725+++ b/drivers/gpu/drm/drm_crtc_helper.c
38726@@ -328,7 +328,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38727 struct drm_crtc *tmp;
38728 int crtc_mask = 1;
38729
38730- WARN(!crtc, "checking null crtc?\n");
38731+ BUG_ON(!crtc);
38732
38733 dev = crtc->dev;
38734
38735diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38736index fe58d08..07bc38e 100644
38737--- a/drivers/gpu/drm/drm_drv.c
38738+++ b/drivers/gpu/drm/drm_drv.c
38739@@ -186,7 +186,7 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
38740 atomic_set(&dev->vma_count, 0);
38741
38742 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38743- atomic_set(&dev->counts[i], 0);
38744+ atomic_set_unchecked(&dev->counts[i], 0);
38745
38746 dev->sigdata.lock = NULL;
38747
38748@@ -302,7 +302,7 @@ module_exit(drm_core_exit);
38749 /**
38750 * Copy and IOCTL return string to user space
38751 */
38752-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38753+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38754 {
38755 int len;
38756
38757@@ -372,7 +372,7 @@ long drm_ioctl(struct file *filp,
38758 struct drm_file *file_priv = filp->private_data;
38759 struct drm_device *dev;
38760 const struct drm_ioctl_desc *ioctl = NULL;
38761- drm_ioctl_t *func;
38762+ drm_ioctl_no_const_t func;
38763 unsigned int nr = DRM_IOCTL_NR(cmd);
38764 int retcode = -EINVAL;
38765 char stack_kdata[128];
38766@@ -385,7 +385,7 @@ long drm_ioctl(struct file *filp,
38767 return -ENODEV;
38768
38769 atomic_inc(&dev->ioctl_count);
38770- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38771+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38772 ++file_priv->ioctl_count;
38773
38774 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38775diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38776index 3f84277..c627c54 100644
38777--- a/drivers/gpu/drm/drm_fops.c
38778+++ b/drivers/gpu/drm/drm_fops.c
38779@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
38780 if (drm_device_is_unplugged(dev))
38781 return -ENODEV;
38782
38783- if (!dev->open_count++)
38784+ if (local_inc_return(&dev->open_count) == 1)
38785 need_setup = 1;
38786 mutex_lock(&dev->struct_mutex);
38787 old_imapping = inode->i_mapping;
38788@@ -113,7 +113,7 @@ int drm_open(struct inode *inode, struct file *filp)
38789 retcode = drm_open_helper(inode, filp, dev);
38790 if (retcode)
38791 goto err_undo;
38792- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38793+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38794 if (need_setup) {
38795 retcode = drm_setup(dev);
38796 if (retcode)
38797@@ -128,7 +128,7 @@ err_undo:
38798 iput(container_of(dev->dev_mapping, struct inode, i_data));
38799 dev->dev_mapping = old_mapping;
38800 mutex_unlock(&dev->struct_mutex);
38801- dev->open_count--;
38802+ local_dec(&dev->open_count);
38803 return retcode;
38804 }
38805 EXPORT_SYMBOL(drm_open);
38806@@ -405,7 +405,7 @@ int drm_release(struct inode *inode, struct file *filp)
38807
38808 mutex_lock(&drm_global_mutex);
38809
38810- DRM_DEBUG("open_count = %d\n", dev->open_count);
38811+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38812
38813 if (dev->driver->preclose)
38814 dev->driver->preclose(dev, file_priv);
38815@@ -414,10 +414,10 @@ int drm_release(struct inode *inode, struct file *filp)
38816 * Begin inline drm_release
38817 */
38818
38819- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38820+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38821 task_pid_nr(current),
38822 (long)old_encode_dev(file_priv->minor->device),
38823- dev->open_count);
38824+ local_read(&dev->open_count));
38825
38826 /* Release any auth tokens that might point to this file_priv,
38827 (do that under the drm_global_mutex) */
38828@@ -516,8 +516,8 @@ int drm_release(struct inode *inode, struct file *filp)
38829 * End inline drm_release
38830 */
38831
38832- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38833- if (!--dev->open_count) {
38834+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38835+ if (local_dec_and_test(&dev->open_count)) {
38836 if (atomic_read(&dev->ioctl_count)) {
38837 DRM_ERROR("Device busy: %d\n",
38838 atomic_read(&dev->ioctl_count));
38839diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38840index f731116..629842c 100644
38841--- a/drivers/gpu/drm/drm_global.c
38842+++ b/drivers/gpu/drm/drm_global.c
38843@@ -36,7 +36,7 @@
38844 struct drm_global_item {
38845 struct mutex mutex;
38846 void *object;
38847- int refcount;
38848+ atomic_t refcount;
38849 };
38850
38851 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38852@@ -49,7 +49,7 @@ void drm_global_init(void)
38853 struct drm_global_item *item = &glob[i];
38854 mutex_init(&item->mutex);
38855 item->object = NULL;
38856- item->refcount = 0;
38857+ atomic_set(&item->refcount, 0);
38858 }
38859 }
38860
38861@@ -59,7 +59,7 @@ void drm_global_release(void)
38862 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38863 struct drm_global_item *item = &glob[i];
38864 BUG_ON(item->object != NULL);
38865- BUG_ON(item->refcount != 0);
38866+ BUG_ON(atomic_read(&item->refcount) != 0);
38867 }
38868 }
38869
38870@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38871 void *object;
38872
38873 mutex_lock(&item->mutex);
38874- if (item->refcount == 0) {
38875+ if (atomic_read(&item->refcount) == 0) {
38876 item->object = kzalloc(ref->size, GFP_KERNEL);
38877 if (unlikely(item->object == NULL)) {
38878 ret = -ENOMEM;
38879@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38880 goto out_err;
38881
38882 }
38883- ++item->refcount;
38884+ atomic_inc(&item->refcount);
38885 ref->object = item->object;
38886 object = item->object;
38887 mutex_unlock(&item->mutex);
38888@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38889 struct drm_global_item *item = &glob[ref->global_type];
38890
38891 mutex_lock(&item->mutex);
38892- BUG_ON(item->refcount == 0);
38893+ BUG_ON(atomic_read(&item->refcount) == 0);
38894 BUG_ON(ref->object != item->object);
38895- if (--item->refcount == 0) {
38896+ if (atomic_dec_and_test(&item->refcount)) {
38897 ref->release(ref);
38898 item->object = NULL;
38899 }
38900diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38901index 5329832..b503f49 100644
38902--- a/drivers/gpu/drm/drm_info.c
38903+++ b/drivers/gpu/drm/drm_info.c
38904@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38905 struct drm_local_map *map;
38906 struct drm_map_list *r_list;
38907
38908- /* Hardcoded from _DRM_FRAME_BUFFER,
38909- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38910- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38911- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38912+ static const char * const types[] = {
38913+ [_DRM_FRAME_BUFFER] = "FB",
38914+ [_DRM_REGISTERS] = "REG",
38915+ [_DRM_SHM] = "SHM",
38916+ [_DRM_AGP] = "AGP",
38917+ [_DRM_SCATTER_GATHER] = "SG",
38918+ [_DRM_CONSISTENT] = "PCI",
38919+ [_DRM_GEM] = "GEM" };
38920 const char *type;
38921 int i;
38922
38923@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38924 map = r_list->map;
38925 if (!map)
38926 continue;
38927- if (map->type < 0 || map->type > 5)
38928+ if (map->type >= ARRAY_SIZE(types))
38929 type = "??";
38930 else
38931 type = types[map->type];
38932@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38933 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38934 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38935 vma->vm_flags & VM_IO ? 'i' : '-',
38936+#ifdef CONFIG_GRKERNSEC_HIDESYM
38937+ 0);
38938+#else
38939 vma->vm_pgoff);
38940+#endif
38941
38942 #if defined(__i386__)
38943 pgprot = pgprot_val(vma->vm_page_prot);
38944diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38945index 2f4c434..dd12cd2 100644
38946--- a/drivers/gpu/drm/drm_ioc32.c
38947+++ b/drivers/gpu/drm/drm_ioc32.c
38948@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38949 request = compat_alloc_user_space(nbytes);
38950 if (!access_ok(VERIFY_WRITE, request, nbytes))
38951 return -EFAULT;
38952- list = (struct drm_buf_desc *) (request + 1);
38953+ list = (struct drm_buf_desc __user *) (request + 1);
38954
38955 if (__put_user(count, &request->count)
38956 || __put_user(list, &request->list))
38957@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38958 request = compat_alloc_user_space(nbytes);
38959 if (!access_ok(VERIFY_WRITE, request, nbytes))
38960 return -EFAULT;
38961- list = (struct drm_buf_pub *) (request + 1);
38962+ list = (struct drm_buf_pub __user *) (request + 1);
38963
38964 if (__put_user(count, &request->count)
38965 || __put_user(list, &request->list))
38966@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38967 return 0;
38968 }
38969
38970-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38971+drm_ioctl_compat_t drm_compat_ioctls[] = {
38972 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38973 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38974 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38975@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38976 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38977 {
38978 unsigned int nr = DRM_IOCTL_NR(cmd);
38979- drm_ioctl_compat_t *fn;
38980 int ret;
38981
38982 /* Assume that ioctls without an explicit compat routine will just
38983@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38984 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38985 return drm_ioctl(filp, cmd, arg);
38986
38987- fn = drm_compat_ioctls[nr];
38988-
38989- if (fn != NULL)
38990- ret = (*fn) (filp, cmd, arg);
38991+ if (drm_compat_ioctls[nr] != NULL)
38992+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38993 else
38994 ret = drm_ioctl(filp, cmd, arg);
38995
38996diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38997index d752c96..fe08455 100644
38998--- a/drivers/gpu/drm/drm_lock.c
38999+++ b/drivers/gpu/drm/drm_lock.c
39000@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
39001 if (drm_lock_take(&master->lock, lock->context)) {
39002 master->lock.file_priv = file_priv;
39003 master->lock.lock_time = jiffies;
39004- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
39005+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
39006 break; /* Got lock */
39007 }
39008
39009@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
39010 return -EINVAL;
39011 }
39012
39013- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
39014+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
39015
39016 if (drm_lock_free(&master->lock, lock->context)) {
39017 /* FIXME: Should really bail out here. */
39018diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39019index 39d8645..59e06fa 100644
39020--- a/drivers/gpu/drm/drm_stub.c
39021+++ b/drivers/gpu/drm/drm_stub.c
39022@@ -484,7 +484,7 @@ void drm_unplug_dev(struct drm_device *dev)
39023
39024 drm_device_set_unplugged(dev);
39025
39026- if (dev->open_count == 0) {
39027+ if (local_read(&dev->open_count) == 0) {
39028 drm_put_dev(dev);
39029 }
39030 mutex_unlock(&drm_global_mutex);
39031diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39032index 2290b3b..22056a1 100644
39033--- a/drivers/gpu/drm/drm_sysfs.c
39034+++ b/drivers/gpu/drm/drm_sysfs.c
39035@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
39036 int drm_sysfs_device_add(struct drm_minor *minor)
39037 {
39038 int err;
39039- char *minor_str;
39040+ const char *minor_str;
39041
39042 minor->kdev.parent = minor->dev->dev;
39043
39044diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
39045index ab1892eb..d7009ca 100644
39046--- a/drivers/gpu/drm/i810/i810_dma.c
39047+++ b/drivers/gpu/drm/i810/i810_dma.c
39048@@ -944,8 +944,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
39049 dma->buflist[vertex->idx],
39050 vertex->discard, vertex->used);
39051
39052- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
39053- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
39054+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
39055+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
39056 sarea_priv->last_enqueue = dev_priv->counter - 1;
39057 sarea_priv->last_dispatch = (int)hw_status[5];
39058
39059@@ -1105,8 +1105,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
39060 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
39061 mc->last_render);
39062
39063- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
39064- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
39065+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
39066+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
39067 sarea_priv->last_enqueue = dev_priv->counter - 1;
39068 sarea_priv->last_dispatch = (int)hw_status[5];
39069
39070diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39071index d4d16ed..8fb0b51 100644
39072--- a/drivers/gpu/drm/i810/i810_drv.h
39073+++ b/drivers/gpu/drm/i810/i810_drv.h
39074@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39075 int page_flipping;
39076
39077 wait_queue_head_t irq_queue;
39078- atomic_t irq_received;
39079- atomic_t irq_emitted;
39080+ atomic_unchecked_t irq_received;
39081+ atomic_unchecked_t irq_emitted;
39082
39083 int front_offset;
39084 } drm_i810_private_t;
39085diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39086index a6f4cb5..6b2beb2 100644
39087--- a/drivers/gpu/drm/i915/i915_debugfs.c
39088+++ b/drivers/gpu/drm/i915/i915_debugfs.c
39089@@ -624,7 +624,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39090 I915_READ(GTIMR));
39091 }
39092 seq_printf(m, "Interrupts received: %d\n",
39093- atomic_read(&dev_priv->irq_received));
39094+ atomic_read_unchecked(&dev_priv->irq_received));
39095 for_each_ring(ring, dev_priv, i) {
39096 if (IS_GEN6(dev) || IS_GEN7(dev)) {
39097 seq_printf(m,
39098diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39099index d5c784d..06e5c36 100644
39100--- a/drivers/gpu/drm/i915/i915_dma.c
39101+++ b/drivers/gpu/drm/i915/i915_dma.c
39102@@ -1263,7 +1263,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39103 bool can_switch;
39104
39105 spin_lock(&dev->count_lock);
39106- can_switch = (dev->open_count == 0);
39107+ can_switch = (local_read(&dev->open_count) == 0);
39108 spin_unlock(&dev->count_lock);
39109 return can_switch;
39110 }
39111diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39112index ab0f2c0..53c1bda 100644
39113--- a/drivers/gpu/drm/i915/i915_drv.h
39114+++ b/drivers/gpu/drm/i915/i915_drv.h
39115@@ -1181,7 +1181,7 @@ typedef struct drm_i915_private {
39116 drm_dma_handle_t *status_page_dmah;
39117 struct resource mch_res;
39118
39119- atomic_t irq_received;
39120+ atomic_unchecked_t irq_received;
39121
39122 /* protects the irq masks */
39123 spinlock_t irq_lock;
39124diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39125index bf34577..3fd2ffa 100644
39126--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39127+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39128@@ -768,9 +768,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39129
39130 static int
39131 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39132- int count)
39133+ unsigned int count)
39134 {
39135- int i;
39136+ unsigned int i;
39137 int relocs_total = 0;
39138 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39139
39140diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39141index 3c59584..500f2e9 100644
39142--- a/drivers/gpu/drm/i915/i915_ioc32.c
39143+++ b/drivers/gpu/drm/i915/i915_ioc32.c
39144@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39145 (unsigned long)request);
39146 }
39147
39148-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39149+static drm_ioctl_compat_t i915_compat_ioctls[] = {
39150 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39151 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39152 [DRM_I915_GETPARAM] = compat_i915_getparam,
39153@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39154 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39155 {
39156 unsigned int nr = DRM_IOCTL_NR(cmd);
39157- drm_ioctl_compat_t *fn = NULL;
39158 int ret;
39159
39160 if (nr < DRM_COMMAND_BASE)
39161 return drm_compat_ioctl(filp, cmd, arg);
39162
39163- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39164- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39165-
39166- if (fn != NULL)
39167+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39168+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39169 ret = (*fn) (filp, cmd, arg);
39170- else
39171+ } else
39172 ret = drm_ioctl(filp, cmd, arg);
39173
39174 return ret;
39175diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39176index 4b91228..590c643 100644
39177--- a/drivers/gpu/drm/i915/i915_irq.c
39178+++ b/drivers/gpu/drm/i915/i915_irq.c
39179@@ -1085,7 +1085,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39180 int pipe;
39181 u32 pipe_stats[I915_MAX_PIPES];
39182
39183- atomic_inc(&dev_priv->irq_received);
39184+ atomic_inc_unchecked(&dev_priv->irq_received);
39185
39186 while (true) {
39187 iir = I915_READ(VLV_IIR);
39188@@ -1390,7 +1390,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39189 irqreturn_t ret = IRQ_NONE;
39190 bool err_int_reenable = false;
39191
39192- atomic_inc(&dev_priv->irq_received);
39193+ atomic_inc_unchecked(&dev_priv->irq_received);
39194
39195 /* We get interrupts on unclaimed registers, so check for this before we
39196 * do any I915_{READ,WRITE}. */
39197@@ -2146,7 +2146,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39198 {
39199 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39200
39201- atomic_set(&dev_priv->irq_received, 0);
39202+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39203
39204 I915_WRITE(HWSTAM, 0xeffe);
39205
39206@@ -2164,7 +2164,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39207 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39208 int pipe;
39209
39210- atomic_set(&dev_priv->irq_received, 0);
39211+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39212
39213 /* VLV magic */
39214 I915_WRITE(VLV_IMR, 0);
39215@@ -2452,7 +2452,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39216 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39217 int pipe;
39218
39219- atomic_set(&dev_priv->irq_received, 0);
39220+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39221
39222 for_each_pipe(pipe)
39223 I915_WRITE(PIPESTAT(pipe), 0);
39224@@ -2530,7 +2530,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39225 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39226 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39227
39228- atomic_inc(&dev_priv->irq_received);
39229+ atomic_inc_unchecked(&dev_priv->irq_received);
39230
39231 iir = I915_READ16(IIR);
39232 if (iir == 0)
39233@@ -2604,7 +2604,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39234 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39235 int pipe;
39236
39237- atomic_set(&dev_priv->irq_received, 0);
39238+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39239
39240 if (I915_HAS_HOTPLUG(dev)) {
39241 I915_WRITE(PORT_HOTPLUG_EN, 0);
39242@@ -2703,7 +2703,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39243 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39244 int pipe, ret = IRQ_NONE;
39245
39246- atomic_inc(&dev_priv->irq_received);
39247+ atomic_inc_unchecked(&dev_priv->irq_received);
39248
39249 iir = I915_READ(IIR);
39250 do {
39251@@ -2827,7 +2827,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39252 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39253 int pipe;
39254
39255- atomic_set(&dev_priv->irq_received, 0);
39256+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39257
39258 I915_WRITE(PORT_HOTPLUG_EN, 0);
39259 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39260@@ -2941,7 +2941,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39261 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39262 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39263
39264- atomic_inc(&dev_priv->irq_received);
39265+ atomic_inc_unchecked(&dev_priv->irq_received);
39266
39267 iir = I915_READ(IIR);
39268
39269diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39270index 333aa1b..0183e38 100644
39271--- a/drivers/gpu/drm/i915/intel_display.c
39272+++ b/drivers/gpu/drm/i915/intel_display.c
39273@@ -9976,13 +9976,13 @@ struct intel_quirk {
39274 int subsystem_vendor;
39275 int subsystem_device;
39276 void (*hook)(struct drm_device *dev);
39277-};
39278+} __do_const;
39279
39280 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39281 struct intel_dmi_quirk {
39282 void (*hook)(struct drm_device *dev);
39283 const struct dmi_system_id (*dmi_id_list)[];
39284-};
39285+} __do_const;
39286
39287 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39288 {
39289@@ -9990,18 +9990,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39290 return 1;
39291 }
39292
39293-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39294+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39295 {
39296- .dmi_id_list = &(const struct dmi_system_id[]) {
39297- {
39298- .callback = intel_dmi_reverse_brightness,
39299- .ident = "NCR Corporation",
39300- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39301- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39302- },
39303- },
39304- { } /* terminating entry */
39305+ .callback = intel_dmi_reverse_brightness,
39306+ .ident = "NCR Corporation",
39307+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39308+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39309 },
39310+ },
39311+ { } /* terminating entry */
39312+};
39313+
39314+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39315+ {
39316+ .dmi_id_list = &intel_dmi_quirks_table,
39317 .hook = quirk_invert_brightness,
39318 },
39319 };
39320diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39321index ca4bc54..ee598a2 100644
39322--- a/drivers/gpu/drm/mga/mga_drv.h
39323+++ b/drivers/gpu/drm/mga/mga_drv.h
39324@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39325 u32 clear_cmd;
39326 u32 maccess;
39327
39328- atomic_t vbl_received; /**< Number of vblanks received. */
39329+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39330 wait_queue_head_t fence_queue;
39331- atomic_t last_fence_retired;
39332+ atomic_unchecked_t last_fence_retired;
39333 u32 next_fence_to_post;
39334
39335 unsigned int fb_cpp;
39336diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39337index 709e90d..89a1c0d 100644
39338--- a/drivers/gpu/drm/mga/mga_ioc32.c
39339+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39340@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39341 return 0;
39342 }
39343
39344-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39345+drm_ioctl_compat_t mga_compat_ioctls[] = {
39346 [DRM_MGA_INIT] = compat_mga_init,
39347 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39348 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39349@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39350 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39351 {
39352 unsigned int nr = DRM_IOCTL_NR(cmd);
39353- drm_ioctl_compat_t *fn = NULL;
39354 int ret;
39355
39356 if (nr < DRM_COMMAND_BASE)
39357 return drm_compat_ioctl(filp, cmd, arg);
39358
39359- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39360- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39361-
39362- if (fn != NULL)
39363+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39364+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39365 ret = (*fn) (filp, cmd, arg);
39366- else
39367+ } else
39368 ret = drm_ioctl(filp, cmd, arg);
39369
39370 return ret;
39371diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39372index 598c281..60d590e 100644
39373--- a/drivers/gpu/drm/mga/mga_irq.c
39374+++ b/drivers/gpu/drm/mga/mga_irq.c
39375@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39376 if (crtc != 0)
39377 return 0;
39378
39379- return atomic_read(&dev_priv->vbl_received);
39380+ return atomic_read_unchecked(&dev_priv->vbl_received);
39381 }
39382
39383
39384@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39385 /* VBLANK interrupt */
39386 if (status & MGA_VLINEPEN) {
39387 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39388- atomic_inc(&dev_priv->vbl_received);
39389+ atomic_inc_unchecked(&dev_priv->vbl_received);
39390 drm_handle_vblank(dev, 0);
39391 handled = 1;
39392 }
39393@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39394 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39395 MGA_WRITE(MGA_PRIMEND, prim_end);
39396
39397- atomic_inc(&dev_priv->last_fence_retired);
39398+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39399 DRM_WAKEUP(&dev_priv->fence_queue);
39400 handled = 1;
39401 }
39402@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39403 * using fences.
39404 */
39405 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39406- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39407+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39408 - *sequence) <= (1 << 23)));
39409
39410 *sequence = cur_fence;
39411diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39412index 3e72876..d1c15ad 100644
39413--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39414+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39415@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39416 struct bit_table {
39417 const char id;
39418 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39419-};
39420+} __no_const;
39421
39422 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39423
39424diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39425index 994fd6e..6e12565 100644
39426--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39427+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39428@@ -94,7 +94,6 @@ struct nouveau_drm {
39429 struct drm_global_reference mem_global_ref;
39430 struct ttm_bo_global_ref bo_global_ref;
39431 struct ttm_bo_device bdev;
39432- atomic_t validate_sequence;
39433 int (*move)(struct nouveau_channel *,
39434 struct ttm_buffer_object *,
39435 struct ttm_mem_reg *, struct ttm_mem_reg *);
39436diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39437index c1a7e5a..38b8539 100644
39438--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39439+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39440@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39441 unsigned long arg)
39442 {
39443 unsigned int nr = DRM_IOCTL_NR(cmd);
39444- drm_ioctl_compat_t *fn = NULL;
39445+ drm_ioctl_compat_t fn = NULL;
39446 int ret;
39447
39448 if (nr < DRM_COMMAND_BASE)
39449diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39450index 81638d7..2e45854 100644
39451--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39452+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39453@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39454 bool can_switch;
39455
39456 spin_lock(&dev->count_lock);
39457- can_switch = (dev->open_count == 0);
39458+ can_switch = (local_read(&dev->open_count) == 0);
39459 spin_unlock(&dev->count_lock);
39460 return can_switch;
39461 }
39462diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39463index eb89653..613cf71 100644
39464--- a/drivers/gpu/drm/qxl/qxl_cmd.c
39465+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39466@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39467 int ret;
39468
39469 mutex_lock(&qdev->async_io_mutex);
39470- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39471+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39472 if (qdev->last_sent_io_cmd > irq_num) {
39473 if (intr)
39474 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39475- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39476+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39477 else
39478 ret = wait_event_timeout(qdev->io_cmd_event,
39479- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39480+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39481 /* 0 is timeout, just bail the "hw" has gone away */
39482 if (ret <= 0)
39483 goto out;
39484- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39485+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39486 }
39487 outb(val, addr);
39488 qdev->last_sent_io_cmd = irq_num + 1;
39489 if (intr)
39490 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39491- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39492+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39493 else
39494 ret = wait_event_timeout(qdev->io_cmd_event,
39495- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39496+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39497 out:
39498 if (ret > 0)
39499 ret = 0;
39500diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39501index c3c2bbd..bc3c0fb 100644
39502--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39503+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39504@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39505 struct drm_info_node *node = (struct drm_info_node *) m->private;
39506 struct qxl_device *qdev = node->minor->dev->dev_private;
39507
39508- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39509- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39510- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39511- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39512+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39513+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39514+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39515+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39516 seq_printf(m, "%d\n", qdev->irq_received_error);
39517 return 0;
39518 }
39519diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39520index f7c9add..fb971d2 100644
39521--- a/drivers/gpu/drm/qxl/qxl_drv.h
39522+++ b/drivers/gpu/drm/qxl/qxl_drv.h
39523@@ -290,10 +290,10 @@ struct qxl_device {
39524 unsigned int last_sent_io_cmd;
39525
39526 /* interrupt handling */
39527- atomic_t irq_received;
39528- atomic_t irq_received_display;
39529- atomic_t irq_received_cursor;
39530- atomic_t irq_received_io_cmd;
39531+ atomic_unchecked_t irq_received;
39532+ atomic_unchecked_t irq_received_display;
39533+ atomic_unchecked_t irq_received_cursor;
39534+ atomic_unchecked_t irq_received_io_cmd;
39535 unsigned irq_received_error;
39536 wait_queue_head_t display_event;
39537 wait_queue_head_t cursor_event;
39538diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39539index 21393dc..329f3a9 100644
39540--- a/drivers/gpu/drm/qxl/qxl_irq.c
39541+++ b/drivers/gpu/drm/qxl/qxl_irq.c
39542@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39543
39544 pending = xchg(&qdev->ram_header->int_pending, 0);
39545
39546- atomic_inc(&qdev->irq_received);
39547+ atomic_inc_unchecked(&qdev->irq_received);
39548
39549 if (pending & QXL_INTERRUPT_DISPLAY) {
39550- atomic_inc(&qdev->irq_received_display);
39551+ atomic_inc_unchecked(&qdev->irq_received_display);
39552 wake_up_all(&qdev->display_event);
39553 qxl_queue_garbage_collect(qdev, false);
39554 }
39555 if (pending & QXL_INTERRUPT_CURSOR) {
39556- atomic_inc(&qdev->irq_received_cursor);
39557+ atomic_inc_unchecked(&qdev->irq_received_cursor);
39558 wake_up_all(&qdev->cursor_event);
39559 }
39560 if (pending & QXL_INTERRUPT_IO_CMD) {
39561- atomic_inc(&qdev->irq_received_io_cmd);
39562+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39563 wake_up_all(&qdev->io_cmd_event);
39564 }
39565 if (pending & QXL_INTERRUPT_ERROR) {
39566@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39567 init_waitqueue_head(&qdev->io_cmd_event);
39568 INIT_WORK(&qdev->client_monitors_config_work,
39569 qxl_client_monitors_config_work_func);
39570- atomic_set(&qdev->irq_received, 0);
39571- atomic_set(&qdev->irq_received_display, 0);
39572- atomic_set(&qdev->irq_received_cursor, 0);
39573- atomic_set(&qdev->irq_received_io_cmd, 0);
39574+ atomic_set_unchecked(&qdev->irq_received, 0);
39575+ atomic_set_unchecked(&qdev->irq_received_display, 0);
39576+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
39577+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
39578 qdev->irq_received_error = 0;
39579 ret = drm_irq_install(qdev->ddev);
39580 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
39581diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39582index 037786d..2a95e33 100644
39583--- a/drivers/gpu/drm/qxl/qxl_ttm.c
39584+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39585@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39586 }
39587 }
39588
39589-static struct vm_operations_struct qxl_ttm_vm_ops;
39590+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39591 static const struct vm_operations_struct *ttm_vm_ops;
39592
39593 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39594@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39595 return r;
39596 if (unlikely(ttm_vm_ops == NULL)) {
39597 ttm_vm_ops = vma->vm_ops;
39598+ pax_open_kernel();
39599 qxl_ttm_vm_ops = *ttm_vm_ops;
39600 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39601+ pax_close_kernel();
39602 }
39603 vma->vm_ops = &qxl_ttm_vm_ops;
39604 return 0;
39605@@ -558,25 +560,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39606 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39607 {
39608 #if defined(CONFIG_DEBUG_FS)
39609- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39610- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39611- unsigned i;
39612+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39613+ {
39614+ .name = "qxl_mem_mm",
39615+ .show = &qxl_mm_dump_table,
39616+ },
39617+ {
39618+ .name = "qxl_surf_mm",
39619+ .show = &qxl_mm_dump_table,
39620+ }
39621+ };
39622
39623- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39624- if (i == 0)
39625- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39626- else
39627- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39628- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39629- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39630- qxl_mem_types_list[i].driver_features = 0;
39631- if (i == 0)
39632- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39633- else
39634- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39635+ pax_open_kernel();
39636+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39637+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39638+ pax_close_kernel();
39639
39640- }
39641- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
39642+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
39643 #else
39644 return 0;
39645 #endif
39646diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
39647index c451257..0ad2134 100644
39648--- a/drivers/gpu/drm/r128/r128_cce.c
39649+++ b/drivers/gpu/drm/r128/r128_cce.c
39650@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
39651
39652 /* GH: Simple idle check.
39653 */
39654- atomic_set(&dev_priv->idle_count, 0);
39655+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39656
39657 /* We don't support anything other than bus-mastering ring mode,
39658 * but the ring can be in either AGP or PCI space for the ring
39659diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
39660index 56eb5e3..c4ec43d 100644
39661--- a/drivers/gpu/drm/r128/r128_drv.h
39662+++ b/drivers/gpu/drm/r128/r128_drv.h
39663@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
39664 int is_pci;
39665 unsigned long cce_buffers_offset;
39666
39667- atomic_t idle_count;
39668+ atomic_unchecked_t idle_count;
39669
39670 int page_flipping;
39671 int current_page;
39672 u32 crtc_offset;
39673 u32 crtc_offset_cntl;
39674
39675- atomic_t vbl_received;
39676+ atomic_unchecked_t vbl_received;
39677
39678 u32 color_fmt;
39679 unsigned int front_offset;
39680diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
39681index a954c54..9cc595c 100644
39682--- a/drivers/gpu/drm/r128/r128_ioc32.c
39683+++ b/drivers/gpu/drm/r128/r128_ioc32.c
39684@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
39685 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
39686 }
39687
39688-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39689+drm_ioctl_compat_t r128_compat_ioctls[] = {
39690 [DRM_R128_INIT] = compat_r128_init,
39691 [DRM_R128_DEPTH] = compat_r128_depth,
39692 [DRM_R128_STIPPLE] = compat_r128_stipple,
39693@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39694 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39695 {
39696 unsigned int nr = DRM_IOCTL_NR(cmd);
39697- drm_ioctl_compat_t *fn = NULL;
39698 int ret;
39699
39700 if (nr < DRM_COMMAND_BASE)
39701 return drm_compat_ioctl(filp, cmd, arg);
39702
39703- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39704- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39705-
39706- if (fn != NULL)
39707+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39708+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39709 ret = (*fn) (filp, cmd, arg);
39710- else
39711+ } else
39712 ret = drm_ioctl(filp, cmd, arg);
39713
39714 return ret;
39715diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39716index 2ea4f09..d391371 100644
39717--- a/drivers/gpu/drm/r128/r128_irq.c
39718+++ b/drivers/gpu/drm/r128/r128_irq.c
39719@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39720 if (crtc != 0)
39721 return 0;
39722
39723- return atomic_read(&dev_priv->vbl_received);
39724+ return atomic_read_unchecked(&dev_priv->vbl_received);
39725 }
39726
39727 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39728@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39729 /* VBLANK interrupt */
39730 if (status & R128_CRTC_VBLANK_INT) {
39731 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39732- atomic_inc(&dev_priv->vbl_received);
39733+ atomic_inc_unchecked(&dev_priv->vbl_received);
39734 drm_handle_vblank(dev, 0);
39735 return IRQ_HANDLED;
39736 }
39737diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39738index 01dd9ae..6352f04 100644
39739--- a/drivers/gpu/drm/r128/r128_state.c
39740+++ b/drivers/gpu/drm/r128/r128_state.c
39741@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39742
39743 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39744 {
39745- if (atomic_read(&dev_priv->idle_count) == 0)
39746+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39747 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39748 else
39749- atomic_set(&dev_priv->idle_count, 0);
39750+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39751 }
39752
39753 #endif
39754diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39755index af85299..ed9ac8d 100644
39756--- a/drivers/gpu/drm/radeon/mkregtable.c
39757+++ b/drivers/gpu/drm/radeon/mkregtable.c
39758@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39759 regex_t mask_rex;
39760 regmatch_t match[4];
39761 char buf[1024];
39762- size_t end;
39763+ long end;
39764 int len;
39765 int done = 0;
39766 int r;
39767 unsigned o;
39768 struct offset *offset;
39769 char last_reg_s[10];
39770- int last_reg;
39771+ unsigned long last_reg;
39772
39773 if (regcomp
39774 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39775diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39776index 841d0e0..9eaa268 100644
39777--- a/drivers/gpu/drm/radeon/radeon_device.c
39778+++ b/drivers/gpu/drm/radeon/radeon_device.c
39779@@ -1117,7 +1117,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39780 bool can_switch;
39781
39782 spin_lock(&dev->count_lock);
39783- can_switch = (dev->open_count == 0);
39784+ can_switch = (local_read(&dev->open_count) == 0);
39785 spin_unlock(&dev->count_lock);
39786 return can_switch;
39787 }
39788diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39789index b369d42..8dd04eb 100644
39790--- a/drivers/gpu/drm/radeon/radeon_drv.h
39791+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39792@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39793
39794 /* SW interrupt */
39795 wait_queue_head_t swi_queue;
39796- atomic_t swi_emitted;
39797+ atomic_unchecked_t swi_emitted;
39798 int vblank_crtc;
39799 uint32_t irq_enable_reg;
39800 uint32_t r500_disp_irq_reg;
39801diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39802index c180df8..5fd8186 100644
39803--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39804+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39805@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39806 request = compat_alloc_user_space(sizeof(*request));
39807 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39808 || __put_user(req32.param, &request->param)
39809- || __put_user((void __user *)(unsigned long)req32.value,
39810+ || __put_user((unsigned long)req32.value,
39811 &request->value))
39812 return -EFAULT;
39813
39814@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39815 #define compat_radeon_cp_setparam NULL
39816 #endif /* X86_64 || IA64 */
39817
39818-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39819+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39820 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39821 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39822 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39823@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39824 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39825 {
39826 unsigned int nr = DRM_IOCTL_NR(cmd);
39827- drm_ioctl_compat_t *fn = NULL;
39828 int ret;
39829
39830 if (nr < DRM_COMMAND_BASE)
39831 return drm_compat_ioctl(filp, cmd, arg);
39832
39833- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39834- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39835-
39836- if (fn != NULL)
39837+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39838+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39839 ret = (*fn) (filp, cmd, arg);
39840- else
39841+ } else
39842 ret = drm_ioctl(filp, cmd, arg);
39843
39844 return ret;
39845diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39846index 8d68e97..9dcfed8 100644
39847--- a/drivers/gpu/drm/radeon/radeon_irq.c
39848+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39849@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39850 unsigned int ret;
39851 RING_LOCALS;
39852
39853- atomic_inc(&dev_priv->swi_emitted);
39854- ret = atomic_read(&dev_priv->swi_emitted);
39855+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39856+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39857
39858 BEGIN_RING(4);
39859 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39860@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39861 drm_radeon_private_t *dev_priv =
39862 (drm_radeon_private_t *) dev->dev_private;
39863
39864- atomic_set(&dev_priv->swi_emitted, 0);
39865+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39866 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39867
39868 dev->max_vblank_count = 0x001fffff;
39869diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39870index 4d20910..6726b6d 100644
39871--- a/drivers/gpu/drm/radeon/radeon_state.c
39872+++ b/drivers/gpu/drm/radeon/radeon_state.c
39873@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39874 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39875 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39876
39877- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39878+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39879 sarea_priv->nbox * sizeof(depth_boxes[0])))
39880 return -EFAULT;
39881
39882@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39883 {
39884 drm_radeon_private_t *dev_priv = dev->dev_private;
39885 drm_radeon_getparam_t *param = data;
39886- int value;
39887+ int value = 0;
39888
39889 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39890
39891diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39892index 71245d6..94c556d 100644
39893--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39894+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39895@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39896 man->size = size >> PAGE_SHIFT;
39897 }
39898
39899-static struct vm_operations_struct radeon_ttm_vm_ops;
39900+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39901 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39902
39903 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39904@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39905 }
39906 if (unlikely(ttm_vm_ops == NULL)) {
39907 ttm_vm_ops = vma->vm_ops;
39908+ pax_open_kernel();
39909 radeon_ttm_vm_ops = *ttm_vm_ops;
39910 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39911+ pax_close_kernel();
39912 }
39913 vma->vm_ops = &radeon_ttm_vm_ops;
39914 return 0;
39915@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39916 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39917 {
39918 #if defined(CONFIG_DEBUG_FS)
39919- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39920- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39921- unsigned i;
39922+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39923+ {
39924+ .name = "radeon_vram_mm",
39925+ .show = &radeon_mm_dump_table,
39926+ },
39927+ {
39928+ .name = "radeon_gtt_mm",
39929+ .show = &radeon_mm_dump_table,
39930+ },
39931+ {
39932+ .name = "ttm_page_pool",
39933+ .show = &ttm_page_alloc_debugfs,
39934+ },
39935+ {
39936+ .name = "ttm_dma_page_pool",
39937+ .show = &ttm_dma_page_alloc_debugfs,
39938+ },
39939+ };
39940+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
39941
39942- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39943- if (i == 0)
39944- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39945- else
39946- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39947- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39948- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39949- radeon_mem_types_list[i].driver_features = 0;
39950- if (i == 0)
39951- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39952- else
39953- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39954-
39955- }
39956- /* Add ttm page pool to debugfs */
39957- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39958- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39959- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39960- radeon_mem_types_list[i].driver_features = 0;
39961- radeon_mem_types_list[i++].data = NULL;
39962+ pax_open_kernel();
39963+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39964+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39965+ pax_close_kernel();
39966 #ifdef CONFIG_SWIOTLB
39967- if (swiotlb_nr_tbl()) {
39968- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39969- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39970- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39971- radeon_mem_types_list[i].driver_features = 0;
39972- radeon_mem_types_list[i++].data = NULL;
39973- }
39974+ if (swiotlb_nr_tbl())
39975+ i++;
39976 #endif
39977 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39978
39979diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39980index 1447d79..40b2a5b 100644
39981--- a/drivers/gpu/drm/radeon/rs690.c
39982+++ b/drivers/gpu/drm/radeon/rs690.c
39983@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39984 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39985 rdev->pm.sideport_bandwidth.full)
39986 max_bandwidth = rdev->pm.sideport_bandwidth;
39987- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39988+ read_delay_latency.full = dfixed_const(800 * 1000);
39989 read_delay_latency.full = dfixed_div(read_delay_latency,
39990 rdev->pm.igp_sideport_mclk);
39991+ a.full = dfixed_const(370);
39992+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39993 } else {
39994 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39995 rdev->pm.k8_bandwidth.full)
39996diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39997index dbc2def..0a9f710 100644
39998--- a/drivers/gpu/drm/ttm/ttm_memory.c
39999+++ b/drivers/gpu/drm/ttm/ttm_memory.c
40000@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40001 zone->glob = glob;
40002 glob->zone_kernel = zone;
40003 ret = kobject_init_and_add(
40004- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40005+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40006 if (unlikely(ret != 0)) {
40007 kobject_put(&zone->kobj);
40008 return ret;
40009@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40010 zone->glob = glob;
40011 glob->zone_dma32 = zone;
40012 ret = kobject_init_and_add(
40013- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40014+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40015 if (unlikely(ret != 0)) {
40016 kobject_put(&zone->kobj);
40017 return ret;
40018diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40019index 863bef9..cba15cf 100644
40020--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40021+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40022@@ -391,9 +391,9 @@ out:
40023 static unsigned long
40024 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40025 {
40026- static atomic_t start_pool = ATOMIC_INIT(0);
40027+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40028 unsigned i;
40029- unsigned pool_offset = atomic_add_return(1, &start_pool);
40030+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40031 struct ttm_page_pool *pool;
40032 int shrink_pages = sc->nr_to_scan;
40033 unsigned long freed = 0;
40034diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40035index 97e9d61..bf23c461 100644
40036--- a/drivers/gpu/drm/udl/udl_fb.c
40037+++ b/drivers/gpu/drm/udl/udl_fb.c
40038@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40039 fb_deferred_io_cleanup(info);
40040 kfree(info->fbdefio);
40041 info->fbdefio = NULL;
40042- info->fbops->fb_mmap = udl_fb_mmap;
40043 }
40044
40045 pr_warn("released /dev/fb%d user=%d count=%d\n",
40046diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40047index a811ef2..ff99b05 100644
40048--- a/drivers/gpu/drm/via/via_drv.h
40049+++ b/drivers/gpu/drm/via/via_drv.h
40050@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40051 typedef uint32_t maskarray_t[5];
40052
40053 typedef struct drm_via_irq {
40054- atomic_t irq_received;
40055+ atomic_unchecked_t irq_received;
40056 uint32_t pending_mask;
40057 uint32_t enable_mask;
40058 wait_queue_head_t irq_queue;
40059@@ -75,7 +75,7 @@ typedef struct drm_via_private {
40060 struct timeval last_vblank;
40061 int last_vblank_valid;
40062 unsigned usec_per_vblank;
40063- atomic_t vbl_received;
40064+ atomic_unchecked_t vbl_received;
40065 drm_via_state_t hc_state;
40066 char pci_buf[VIA_PCI_BUF_SIZE];
40067 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40068diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40069index ac98964..5dbf512 100644
40070--- a/drivers/gpu/drm/via/via_irq.c
40071+++ b/drivers/gpu/drm/via/via_irq.c
40072@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40073 if (crtc != 0)
40074 return 0;
40075
40076- return atomic_read(&dev_priv->vbl_received);
40077+ return atomic_read_unchecked(&dev_priv->vbl_received);
40078 }
40079
40080 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40081@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40082
40083 status = VIA_READ(VIA_REG_INTERRUPT);
40084 if (status & VIA_IRQ_VBLANK_PENDING) {
40085- atomic_inc(&dev_priv->vbl_received);
40086- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40087+ atomic_inc_unchecked(&dev_priv->vbl_received);
40088+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40089 do_gettimeofday(&cur_vblank);
40090 if (dev_priv->last_vblank_valid) {
40091 dev_priv->usec_per_vblank =
40092@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40093 dev_priv->last_vblank = cur_vblank;
40094 dev_priv->last_vblank_valid = 1;
40095 }
40096- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40097+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40098 DRM_DEBUG("US per vblank is: %u\n",
40099 dev_priv->usec_per_vblank);
40100 }
40101@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40102
40103 for (i = 0; i < dev_priv->num_irqs; ++i) {
40104 if (status & cur_irq->pending_mask) {
40105- atomic_inc(&cur_irq->irq_received);
40106+ atomic_inc_unchecked(&cur_irq->irq_received);
40107 DRM_WAKEUP(&cur_irq->irq_queue);
40108 handled = 1;
40109 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40110@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40111 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40112 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40113 masks[irq][4]));
40114- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40115+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40116 } else {
40117 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40118 (((cur_irq_sequence =
40119- atomic_read(&cur_irq->irq_received)) -
40120+ atomic_read_unchecked(&cur_irq->irq_received)) -
40121 *sequence) <= (1 << 23)));
40122 }
40123 *sequence = cur_irq_sequence;
40124@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40125 }
40126
40127 for (i = 0; i < dev_priv->num_irqs; ++i) {
40128- atomic_set(&cur_irq->irq_received, 0);
40129+ atomic_set_unchecked(&cur_irq->irq_received, 0);
40130 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40131 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40132 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40133@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40134 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40135 case VIA_IRQ_RELATIVE:
40136 irqwait->request.sequence +=
40137- atomic_read(&cur_irq->irq_received);
40138+ atomic_read_unchecked(&cur_irq->irq_received);
40139 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40140 case VIA_IRQ_ABSOLUTE:
40141 break;
40142diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40143index 150ec64..f5165f2 100644
40144--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40145+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40146@@ -290,7 +290,7 @@ struct vmw_private {
40147 * Fencing and IRQs.
40148 */
40149
40150- atomic_t marker_seq;
40151+ atomic_unchecked_t marker_seq;
40152 wait_queue_head_t fence_queue;
40153 wait_queue_head_t fifo_queue;
40154 int fence_queue_waiters; /* Protected by hw_mutex */
40155diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40156index 3eb1486..0a47ee9 100644
40157--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40158+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40159@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40160 (unsigned int) min,
40161 (unsigned int) fifo->capabilities);
40162
40163- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40164+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40165 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40166 vmw_marker_queue_init(&fifo->marker_queue);
40167 return vmw_fifo_send_fence(dev_priv, &dummy);
40168@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40169 if (reserveable)
40170 iowrite32(bytes, fifo_mem +
40171 SVGA_FIFO_RESERVED);
40172- return fifo_mem + (next_cmd >> 2);
40173+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40174 } else {
40175 need_bounce = true;
40176 }
40177@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40178
40179 fm = vmw_fifo_reserve(dev_priv, bytes);
40180 if (unlikely(fm == NULL)) {
40181- *seqno = atomic_read(&dev_priv->marker_seq);
40182+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40183 ret = -ENOMEM;
40184 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40185 false, 3*HZ);
40186@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40187 }
40188
40189 do {
40190- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40191+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40192 } while (*seqno == 0);
40193
40194 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40195diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40196index c509d40..3b640c3 100644
40197--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40198+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40199@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40200 int ret;
40201
40202 num_clips = arg->num_clips;
40203- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40204+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40205
40206 if (unlikely(num_clips == 0))
40207 return 0;
40208@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40209 int ret;
40210
40211 num_clips = arg->num_clips;
40212- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40213+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40214
40215 if (unlikely(num_clips == 0))
40216 return 0;
40217diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40218index 4640adb..e1384ed 100644
40219--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40220+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40221@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40222 * emitted. Then the fence is stale and signaled.
40223 */
40224
40225- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40226+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40227 > VMW_FENCE_WRAP);
40228
40229 return ret;
40230@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40231
40232 if (fifo_idle)
40233 down_read(&fifo_state->rwsem);
40234- signal_seq = atomic_read(&dev_priv->marker_seq);
40235+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40236 ret = 0;
40237
40238 for (;;) {
40239diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40240index 8a8725c2..afed796 100644
40241--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40242+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40243@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40244 while (!vmw_lag_lt(queue, us)) {
40245 spin_lock(&queue->lock);
40246 if (list_empty(&queue->head))
40247- seqno = atomic_read(&dev_priv->marker_seq);
40248+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40249 else {
40250 marker = list_first_entry(&queue->head,
40251 struct vmw_marker, head);
40252diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
40253index b1a05ad..1c9d899 100644
40254--- a/drivers/gpu/host1x/drm/dc.c
40255+++ b/drivers/gpu/host1x/drm/dc.c
40256@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40257 }
40258
40259 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40260- dc->debugfs_files[i].data = dc;
40261+ *(void **)&dc->debugfs_files[i].data = dc;
40262
40263 err = drm_debugfs_create_files(dc->debugfs_files,
40264 ARRAY_SIZE(debugfs_files),
40265diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40266index ec0ae2d..dc0780b 100644
40267--- a/drivers/gpu/vga/vga_switcheroo.c
40268+++ b/drivers/gpu/vga/vga_switcheroo.c
40269@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40270
40271 /* this version is for the case where the power switch is separate
40272 to the device being powered down. */
40273-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40274+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40275 {
40276 /* copy over all the bus versions */
40277 if (dev->bus && dev->bus->pm) {
40278@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40279 return ret;
40280 }
40281
40282-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40283+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40284 {
40285 /* copy over all the bus versions */
40286 if (dev->bus && dev->bus->pm) {
40287diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40288index c08b5c1..6c3d50b 100644
40289--- a/drivers/hid/hid-core.c
40290+++ b/drivers/hid/hid-core.c
40291@@ -2415,7 +2415,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40292
40293 int hid_add_device(struct hid_device *hdev)
40294 {
40295- static atomic_t id = ATOMIC_INIT(0);
40296+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40297 int ret;
40298
40299 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40300@@ -2449,7 +2449,7 @@ int hid_add_device(struct hid_device *hdev)
40301 /* XXX hack, any other cleaner solution after the driver core
40302 * is converted to allow more than 20 bytes as the device name? */
40303 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40304- hdev->vendor, hdev->product, atomic_inc_return(&id));
40305+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40306
40307 hid_debug_register(hdev, dev_name(&hdev->dev));
40308 ret = device_add(&hdev->dev);
40309diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40310index c13fb5b..55a3802 100644
40311--- a/drivers/hid/hid-wiimote-debug.c
40312+++ b/drivers/hid/hid-wiimote-debug.c
40313@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40314 else if (size == 0)
40315 return -EIO;
40316
40317- if (copy_to_user(u, buf, size))
40318+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40319 return -EFAULT;
40320
40321 *off += size;
40322diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40323index cedc6da..2c3da2a 100644
40324--- a/drivers/hid/uhid.c
40325+++ b/drivers/hid/uhid.c
40326@@ -47,7 +47,7 @@ struct uhid_device {
40327 struct mutex report_lock;
40328 wait_queue_head_t report_wait;
40329 atomic_t report_done;
40330- atomic_t report_id;
40331+ atomic_unchecked_t report_id;
40332 struct uhid_event report_buf;
40333 };
40334
40335@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40336
40337 spin_lock_irqsave(&uhid->qlock, flags);
40338 ev->type = UHID_FEATURE;
40339- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40340+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40341 ev->u.feature.rnum = rnum;
40342 ev->u.feature.rtype = report_type;
40343
40344@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40345 spin_lock_irqsave(&uhid->qlock, flags);
40346
40347 /* id for old report; drop it silently */
40348- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40349+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40350 goto unlock;
40351 if (atomic_read(&uhid->report_done))
40352 goto unlock;
40353diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40354index 6de6c98..18319e9 100644
40355--- a/drivers/hv/channel.c
40356+++ b/drivers/hv/channel.c
40357@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40358 int ret = 0;
40359 int t;
40360
40361- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40362- atomic_inc(&vmbus_connection.next_gpadl_handle);
40363+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40364+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40365
40366 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40367 if (ret)
40368diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40369index 88f4096..e50452e 100644
40370--- a/drivers/hv/hv.c
40371+++ b/drivers/hv/hv.c
40372@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40373 u64 output_address = (output) ? virt_to_phys(output) : 0;
40374 u32 output_address_hi = output_address >> 32;
40375 u32 output_address_lo = output_address & 0xFFFFFFFF;
40376- void *hypercall_page = hv_context.hypercall_page;
40377+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40378
40379 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40380 "=a"(hv_status_lo) : "d" (control_hi),
40381diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40382index 7e17a54..a50a33d 100644
40383--- a/drivers/hv/hv_balloon.c
40384+++ b/drivers/hv/hv_balloon.c
40385@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40386
40387 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40388 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40389-static atomic_t trans_id = ATOMIC_INIT(0);
40390+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40391
40392 static int dm_ring_size = (5 * PAGE_SIZE);
40393
40394@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40395 pr_info("Memory hot add failed\n");
40396
40397 dm->state = DM_INITIALIZED;
40398- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40399+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40400 vmbus_sendpacket(dm->dev->channel, &resp,
40401 sizeof(struct dm_hot_add_response),
40402 (unsigned long)NULL,
40403@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40404 memset(&status, 0, sizeof(struct dm_status));
40405 status.hdr.type = DM_STATUS_REPORT;
40406 status.hdr.size = sizeof(struct dm_status);
40407- status.hdr.trans_id = atomic_inc_return(&trans_id);
40408+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40409
40410 /*
40411 * The host expects the guest to report free memory.
40412@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40413 * send the status. This can happen if we were interrupted
40414 * after we picked our transaction ID.
40415 */
40416- if (status.hdr.trans_id != atomic_read(&trans_id))
40417+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40418 return;
40419
40420 vmbus_sendpacket(dm->dev->channel, &status,
40421@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40422 */
40423
40424 do {
40425- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40426+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40427 ret = vmbus_sendpacket(dm_device.dev->channel,
40428 bl_resp,
40429 bl_resp->hdr.size,
40430@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40431
40432 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40433 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40434- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40435+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40436 resp.hdr.size = sizeof(struct dm_unballoon_response);
40437
40438 vmbus_sendpacket(dm_device.dev->channel, &resp,
40439@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40440 memset(&version_req, 0, sizeof(struct dm_version_request));
40441 version_req.hdr.type = DM_VERSION_REQUEST;
40442 version_req.hdr.size = sizeof(struct dm_version_request);
40443- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40444+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40445 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40446 version_req.is_last_attempt = 1;
40447
40448@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40449 memset(&version_req, 0, sizeof(struct dm_version_request));
40450 version_req.hdr.type = DM_VERSION_REQUEST;
40451 version_req.hdr.size = sizeof(struct dm_version_request);
40452- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40453+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40454 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40455 version_req.is_last_attempt = 0;
40456
40457@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40458 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40459 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40460 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40461- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40462+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40463
40464 cap_msg.caps.cap_bits.balloon = 1;
40465 cap_msg.caps.cap_bits.hot_add = 1;
40466diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40467index d84918f..7f38f9f 100644
40468--- a/drivers/hv/hyperv_vmbus.h
40469+++ b/drivers/hv/hyperv_vmbus.h
40470@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40471 struct vmbus_connection {
40472 enum vmbus_connect_state conn_state;
40473
40474- atomic_t next_gpadl_handle;
40475+ atomic_unchecked_t next_gpadl_handle;
40476
40477 /*
40478 * Represents channel interrupts. Each bit position represents a
40479diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40480index f9fe46f..356b119 100644
40481--- a/drivers/hv/vmbus_drv.c
40482+++ b/drivers/hv/vmbus_drv.c
40483@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40484 {
40485 int ret = 0;
40486
40487- static atomic_t device_num = ATOMIC_INIT(0);
40488+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40489
40490 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40491- atomic_inc_return(&device_num));
40492+ atomic_inc_return_unchecked(&device_num));
40493
40494 child_device_obj->device.bus = &hv_bus;
40495 child_device_obj->device.parent = &hv_acpi_dev->dev;
40496diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40497index a9e3d01..9dd246e 100644
40498--- a/drivers/hwmon/acpi_power_meter.c
40499+++ b/drivers/hwmon/acpi_power_meter.c
40500@@ -117,7 +117,7 @@ struct sensor_template {
40501 struct device_attribute *devattr,
40502 const char *buf, size_t count);
40503 int index;
40504-};
40505+} __do_const;
40506
40507 /* Averaging interval */
40508 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40509@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40510 struct sensor_template *attrs)
40511 {
40512 struct device *dev = &resource->acpi_dev->dev;
40513- struct sensor_device_attribute *sensors =
40514+ sensor_device_attribute_no_const *sensors =
40515 &resource->sensors[resource->num_sensors];
40516 int res = 0;
40517
40518diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40519index 3288f13..71cfb4e 100644
40520--- a/drivers/hwmon/applesmc.c
40521+++ b/drivers/hwmon/applesmc.c
40522@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40523 {
40524 struct applesmc_node_group *grp;
40525 struct applesmc_dev_attr *node;
40526- struct attribute *attr;
40527+ attribute_no_const *attr;
40528 int ret, i;
40529
40530 for (grp = groups; grp->format; grp++) {
40531diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40532index b25c643..a13460d 100644
40533--- a/drivers/hwmon/asus_atk0110.c
40534+++ b/drivers/hwmon/asus_atk0110.c
40535@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40536 struct atk_sensor_data {
40537 struct list_head list;
40538 struct atk_data *data;
40539- struct device_attribute label_attr;
40540- struct device_attribute input_attr;
40541- struct device_attribute limit1_attr;
40542- struct device_attribute limit2_attr;
40543+ device_attribute_no_const label_attr;
40544+ device_attribute_no_const input_attr;
40545+ device_attribute_no_const limit1_attr;
40546+ device_attribute_no_const limit2_attr;
40547 char label_attr_name[ATTR_NAME_SIZE];
40548 char input_attr_name[ATTR_NAME_SIZE];
40549 char limit1_attr_name[ATTR_NAME_SIZE];
40550@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40551 static struct device_attribute atk_name_attr =
40552 __ATTR(name, 0444, atk_name_show, NULL);
40553
40554-static void atk_init_attribute(struct device_attribute *attr, char *name,
40555+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40556 sysfs_show_func show)
40557 {
40558 sysfs_attr_init(&attr->attr);
40559diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40560index 78be661..4dd032f 100644
40561--- a/drivers/hwmon/coretemp.c
40562+++ b/drivers/hwmon/coretemp.c
40563@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40564 return NOTIFY_OK;
40565 }
40566
40567-static struct notifier_block coretemp_cpu_notifier __refdata = {
40568+static struct notifier_block coretemp_cpu_notifier = {
40569 .notifier_call = coretemp_cpu_callback,
40570 };
40571
40572diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40573index 632f1dc..57e6a58 100644
40574--- a/drivers/hwmon/ibmaem.c
40575+++ b/drivers/hwmon/ibmaem.c
40576@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40577 struct aem_rw_sensor_template *rw)
40578 {
40579 struct device *dev = &data->pdev->dev;
40580- struct sensor_device_attribute *sensors = data->sensors;
40581+ sensor_device_attribute_no_const *sensors = data->sensors;
40582 int err;
40583
40584 /* Set up read-only sensors */
40585diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40586index 708081b..fe2d4ab 100644
40587--- a/drivers/hwmon/iio_hwmon.c
40588+++ b/drivers/hwmon/iio_hwmon.c
40589@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40590 {
40591 struct device *dev = &pdev->dev;
40592 struct iio_hwmon_state *st;
40593- struct sensor_device_attribute *a;
40594+ sensor_device_attribute_no_const *a;
40595 int ret, i;
40596 int in_i = 1, temp_i = 1, curr_i = 1;
40597 enum iio_chan_type type;
40598diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
40599index 6eb03ce..bea7e3e 100644
40600--- a/drivers/hwmon/nct6775.c
40601+++ b/drivers/hwmon/nct6775.c
40602@@ -936,10 +936,10 @@ static struct attribute_group *
40603 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
40604 int repeat)
40605 {
40606- struct attribute_group *group;
40607+ attribute_group_no_const *group;
40608 struct sensor_device_attr_u *su;
40609- struct sensor_device_attribute *a;
40610- struct sensor_device_attribute_2 *a2;
40611+ sensor_device_attribute_no_const *a;
40612+ sensor_device_attribute_2_no_const *a2;
40613 struct attribute **attrs;
40614 struct sensor_device_template **t;
40615 int err, i, j, count;
40616diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40617index 9319fcf..189ff45 100644
40618--- a/drivers/hwmon/pmbus/pmbus_core.c
40619+++ b/drivers/hwmon/pmbus/pmbus_core.c
40620@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40621 return 0;
40622 }
40623
40624-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40625+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40626 const char *name,
40627 umode_t mode,
40628 ssize_t (*show)(struct device *dev,
40629@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40630 dev_attr->store = store;
40631 }
40632
40633-static void pmbus_attr_init(struct sensor_device_attribute *a,
40634+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40635 const char *name,
40636 umode_t mode,
40637 ssize_t (*show)(struct device *dev,
40638@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40639 u16 reg, u8 mask)
40640 {
40641 struct pmbus_boolean *boolean;
40642- struct sensor_device_attribute *a;
40643+ sensor_device_attribute_no_const *a;
40644
40645 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40646 if (!boolean)
40647@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40648 bool update, bool readonly)
40649 {
40650 struct pmbus_sensor *sensor;
40651- struct device_attribute *a;
40652+ device_attribute_no_const *a;
40653
40654 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40655 if (!sensor)
40656@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40657 const char *lstring, int index)
40658 {
40659 struct pmbus_label *label;
40660- struct device_attribute *a;
40661+ device_attribute_no_const *a;
40662
40663 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40664 if (!label)
40665diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40666index 97cd45a..ac54d8b 100644
40667--- a/drivers/hwmon/sht15.c
40668+++ b/drivers/hwmon/sht15.c
40669@@ -169,7 +169,7 @@ struct sht15_data {
40670 int supply_uv;
40671 bool supply_uv_valid;
40672 struct work_struct update_supply_work;
40673- atomic_t interrupt_handled;
40674+ atomic_unchecked_t interrupt_handled;
40675 };
40676
40677 /**
40678@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40679 ret = gpio_direction_input(data->pdata->gpio_data);
40680 if (ret)
40681 return ret;
40682- atomic_set(&data->interrupt_handled, 0);
40683+ atomic_set_unchecked(&data->interrupt_handled, 0);
40684
40685 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40686 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40687 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40688 /* Only relevant if the interrupt hasn't occurred. */
40689- if (!atomic_read(&data->interrupt_handled))
40690+ if (!atomic_read_unchecked(&data->interrupt_handled))
40691 schedule_work(&data->read_work);
40692 }
40693 ret = wait_event_timeout(data->wait_queue,
40694@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40695
40696 /* First disable the interrupt */
40697 disable_irq_nosync(irq);
40698- atomic_inc(&data->interrupt_handled);
40699+ atomic_inc_unchecked(&data->interrupt_handled);
40700 /* Then schedule a reading work struct */
40701 if (data->state != SHT15_READING_NOTHING)
40702 schedule_work(&data->read_work);
40703@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40704 * If not, then start the interrupt again - care here as could
40705 * have gone low in meantime so verify it hasn't!
40706 */
40707- atomic_set(&data->interrupt_handled, 0);
40708+ atomic_set_unchecked(&data->interrupt_handled, 0);
40709 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40710 /* If still not occurred or another handler was scheduled */
40711 if (gpio_get_value(data->pdata->gpio_data)
40712- || atomic_read(&data->interrupt_handled))
40713+ || atomic_read_unchecked(&data->interrupt_handled))
40714 return;
40715 }
40716
40717diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40718index 38944e9..ae9e5ed 100644
40719--- a/drivers/hwmon/via-cputemp.c
40720+++ b/drivers/hwmon/via-cputemp.c
40721@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40722 return NOTIFY_OK;
40723 }
40724
40725-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40726+static struct notifier_block via_cputemp_cpu_notifier = {
40727 .notifier_call = via_cputemp_cpu_callback,
40728 };
40729
40730diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40731index 07f01ac..d79ad3d 100644
40732--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40733+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40734@@ -43,7 +43,7 @@
40735 extern struct i2c_adapter amd756_smbus;
40736
40737 static struct i2c_adapter *s4882_adapter;
40738-static struct i2c_algorithm *s4882_algo;
40739+static i2c_algorithm_no_const *s4882_algo;
40740
40741 /* Wrapper access functions for multiplexed SMBus */
40742 static DEFINE_MUTEX(amd756_lock);
40743diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
40744index dae3ddf..26e21d1 100644
40745--- a/drivers/i2c/busses/i2c-diolan-u2c.c
40746+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
40747@@ -99,7 +99,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
40748 /* usb layer */
40749
40750 /* Send command to device, and get response. */
40751-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40752+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
40753 {
40754 int ret = 0;
40755 int actual;
40756diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40757index 2ca268d..c6acbdf 100644
40758--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40759+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40760@@ -41,7 +41,7 @@
40761 extern struct i2c_adapter *nforce2_smbus;
40762
40763 static struct i2c_adapter *s4985_adapter;
40764-static struct i2c_algorithm *s4985_algo;
40765+static i2c_algorithm_no_const *s4985_algo;
40766
40767 /* Wrapper access functions for multiplexed SMBus */
40768 static DEFINE_MUTEX(nforce2_lock);
40769diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40770index c3ccdea..5b3dc1a 100644
40771--- a/drivers/i2c/i2c-dev.c
40772+++ b/drivers/i2c/i2c-dev.c
40773@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40774 break;
40775 }
40776
40777- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40778+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40779 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40780 if (IS_ERR(rdwr_pa[i].buf)) {
40781 res = PTR_ERR(rdwr_pa[i].buf);
40782diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40783index 0b510ba..4fbb5085 100644
40784--- a/drivers/ide/ide-cd.c
40785+++ b/drivers/ide/ide-cd.c
40786@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40787 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40788 if ((unsigned long)buf & alignment
40789 || blk_rq_bytes(rq) & q->dma_pad_mask
40790- || object_is_on_stack(buf))
40791+ || object_starts_on_stack(buf))
40792 drive->dma = 0;
40793 }
40794 }
40795diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40796index f95c697..0a1b05c 100644
40797--- a/drivers/iio/industrialio-core.c
40798+++ b/drivers/iio/industrialio-core.c
40799@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40800 }
40801
40802 static
40803-int __iio_device_attr_init(struct device_attribute *dev_attr,
40804+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40805 const char *postfix,
40806 struct iio_chan_spec const *chan,
40807 ssize_t (*readfunc)(struct device *dev,
40808diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40809index 784b97c..c9ceadf 100644
40810--- a/drivers/infiniband/core/cm.c
40811+++ b/drivers/infiniband/core/cm.c
40812@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40813
40814 struct cm_counter_group {
40815 struct kobject obj;
40816- atomic_long_t counter[CM_ATTR_COUNT];
40817+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40818 };
40819
40820 struct cm_counter_attribute {
40821@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40822 struct ib_mad_send_buf *msg = NULL;
40823 int ret;
40824
40825- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40826+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40827 counter[CM_REQ_COUNTER]);
40828
40829 /* Quick state check to discard duplicate REQs. */
40830@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40831 if (!cm_id_priv)
40832 return;
40833
40834- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40835+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40836 counter[CM_REP_COUNTER]);
40837 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40838 if (ret)
40839@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40840 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40841 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40842 spin_unlock_irq(&cm_id_priv->lock);
40843- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40844+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40845 counter[CM_RTU_COUNTER]);
40846 goto out;
40847 }
40848@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40849 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40850 dreq_msg->local_comm_id);
40851 if (!cm_id_priv) {
40852- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40853+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40854 counter[CM_DREQ_COUNTER]);
40855 cm_issue_drep(work->port, work->mad_recv_wc);
40856 return -EINVAL;
40857@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40858 case IB_CM_MRA_REP_RCVD:
40859 break;
40860 case IB_CM_TIMEWAIT:
40861- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40862+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40863 counter[CM_DREQ_COUNTER]);
40864 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40865 goto unlock;
40866@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40867 cm_free_msg(msg);
40868 goto deref;
40869 case IB_CM_DREQ_RCVD:
40870- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40871+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40872 counter[CM_DREQ_COUNTER]);
40873 goto unlock;
40874 default:
40875@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40876 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40877 cm_id_priv->msg, timeout)) {
40878 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40879- atomic_long_inc(&work->port->
40880+ atomic_long_inc_unchecked(&work->port->
40881 counter_group[CM_RECV_DUPLICATES].
40882 counter[CM_MRA_COUNTER]);
40883 goto out;
40884@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40885 break;
40886 case IB_CM_MRA_REQ_RCVD:
40887 case IB_CM_MRA_REP_RCVD:
40888- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40889+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40890 counter[CM_MRA_COUNTER]);
40891 /* fall through */
40892 default:
40893@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40894 case IB_CM_LAP_IDLE:
40895 break;
40896 case IB_CM_MRA_LAP_SENT:
40897- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40898+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40899 counter[CM_LAP_COUNTER]);
40900 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40901 goto unlock;
40902@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40903 cm_free_msg(msg);
40904 goto deref;
40905 case IB_CM_LAP_RCVD:
40906- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40907+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40908 counter[CM_LAP_COUNTER]);
40909 goto unlock;
40910 default:
40911@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40912 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40913 if (cur_cm_id_priv) {
40914 spin_unlock_irq(&cm.lock);
40915- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40916+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40917 counter[CM_SIDR_REQ_COUNTER]);
40918 goto out; /* Duplicate message. */
40919 }
40920@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40921 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40922 msg->retries = 1;
40923
40924- atomic_long_add(1 + msg->retries,
40925+ atomic_long_add_unchecked(1 + msg->retries,
40926 &port->counter_group[CM_XMIT].counter[attr_index]);
40927 if (msg->retries)
40928- atomic_long_add(msg->retries,
40929+ atomic_long_add_unchecked(msg->retries,
40930 &port->counter_group[CM_XMIT_RETRIES].
40931 counter[attr_index]);
40932
40933@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40934 }
40935
40936 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40937- atomic_long_inc(&port->counter_group[CM_RECV].
40938+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40939 counter[attr_id - CM_ATTR_ID_OFFSET]);
40940
40941 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40942@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40943 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40944
40945 return sprintf(buf, "%ld\n",
40946- atomic_long_read(&group->counter[cm_attr->index]));
40947+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40948 }
40949
40950 static const struct sysfs_ops cm_counter_ops = {
40951diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40952index 9f5ad7c..588cd84 100644
40953--- a/drivers/infiniband/core/fmr_pool.c
40954+++ b/drivers/infiniband/core/fmr_pool.c
40955@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40956
40957 struct task_struct *thread;
40958
40959- atomic_t req_ser;
40960- atomic_t flush_ser;
40961+ atomic_unchecked_t req_ser;
40962+ atomic_unchecked_t flush_ser;
40963
40964 wait_queue_head_t force_wait;
40965 };
40966@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40967 struct ib_fmr_pool *pool = pool_ptr;
40968
40969 do {
40970- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40971+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40972 ib_fmr_batch_release(pool);
40973
40974- atomic_inc(&pool->flush_ser);
40975+ atomic_inc_unchecked(&pool->flush_ser);
40976 wake_up_interruptible(&pool->force_wait);
40977
40978 if (pool->flush_function)
40979@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40980 }
40981
40982 set_current_state(TASK_INTERRUPTIBLE);
40983- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40984+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40985 !kthread_should_stop())
40986 schedule();
40987 __set_current_state(TASK_RUNNING);
40988@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40989 pool->dirty_watermark = params->dirty_watermark;
40990 pool->dirty_len = 0;
40991 spin_lock_init(&pool->pool_lock);
40992- atomic_set(&pool->req_ser, 0);
40993- atomic_set(&pool->flush_ser, 0);
40994+ atomic_set_unchecked(&pool->req_ser, 0);
40995+ atomic_set_unchecked(&pool->flush_ser, 0);
40996 init_waitqueue_head(&pool->force_wait);
40997
40998 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40999@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41000 }
41001 spin_unlock_irq(&pool->pool_lock);
41002
41003- serial = atomic_inc_return(&pool->req_ser);
41004+ serial = atomic_inc_return_unchecked(&pool->req_ser);
41005 wake_up_process(pool->thread);
41006
41007 if (wait_event_interruptible(pool->force_wait,
41008- atomic_read(&pool->flush_ser) - serial >= 0))
41009+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41010 return -EINTR;
41011
41012 return 0;
41013@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41014 } else {
41015 list_add_tail(&fmr->list, &pool->dirty_list);
41016 if (++pool->dirty_len >= pool->dirty_watermark) {
41017- atomic_inc(&pool->req_ser);
41018+ atomic_inc_unchecked(&pool->req_ser);
41019 wake_up_process(pool->thread);
41020 }
41021 }
41022diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41023index 4cb8eb2..146bf60 100644
41024--- a/drivers/infiniband/hw/cxgb4/mem.c
41025+++ b/drivers/infiniband/hw/cxgb4/mem.c
41026@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41027 int err;
41028 struct fw_ri_tpte tpt;
41029 u32 stag_idx;
41030- static atomic_t key;
41031+ static atomic_unchecked_t key;
41032
41033 if (c4iw_fatal_error(rdev))
41034 return -EIO;
41035@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41036 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41037 rdev->stats.stag.max = rdev->stats.stag.cur;
41038 mutex_unlock(&rdev->stats.lock);
41039- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41040+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41041 }
41042 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41043 __func__, stag_state, type, pdid, stag_idx);
41044diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41045index 79b3dbc..96e5fcc 100644
41046--- a/drivers/infiniband/hw/ipath/ipath_rc.c
41047+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41048@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41049 struct ib_atomic_eth *ateth;
41050 struct ipath_ack_entry *e;
41051 u64 vaddr;
41052- atomic64_t *maddr;
41053+ atomic64_unchecked_t *maddr;
41054 u64 sdata;
41055 u32 rkey;
41056 u8 next;
41057@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41058 IB_ACCESS_REMOTE_ATOMIC)))
41059 goto nack_acc_unlck;
41060 /* Perform atomic OP and save result. */
41061- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41062+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41063 sdata = be64_to_cpu(ateth->swap_data);
41064 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41065 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41066- (u64) atomic64_add_return(sdata, maddr) - sdata :
41067+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41068 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41069 be64_to_cpu(ateth->compare_data),
41070 sdata);
41071diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41072index 1f95bba..9530f87 100644
41073--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41074+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41075@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41076 unsigned long flags;
41077 struct ib_wc wc;
41078 u64 sdata;
41079- atomic64_t *maddr;
41080+ atomic64_unchecked_t *maddr;
41081 enum ib_wc_status send_status;
41082
41083 /*
41084@@ -382,11 +382,11 @@ again:
41085 IB_ACCESS_REMOTE_ATOMIC)))
41086 goto acc_err;
41087 /* Perform atomic OP and save result. */
41088- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41089+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41090 sdata = wqe->wr.wr.atomic.compare_add;
41091 *(u64 *) sqp->s_sge.sge.vaddr =
41092 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41093- (u64) atomic64_add_return(sdata, maddr) - sdata :
41094+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41095 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41096 sdata, wqe->wr.wr.atomic.swap);
41097 goto send_comp;
41098diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41099index f2a3f48..673ec79 100644
41100--- a/drivers/infiniband/hw/mlx4/mad.c
41101+++ b/drivers/infiniband/hw/mlx4/mad.c
41102@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41103
41104 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41105 {
41106- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41107+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41108 cpu_to_be64(0xff00000000000000LL);
41109 }
41110
41111diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41112index 25b2cdf..099ff97 100644
41113--- a/drivers/infiniband/hw/mlx4/mcg.c
41114+++ b/drivers/infiniband/hw/mlx4/mcg.c
41115@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41116 {
41117 char name[20];
41118
41119- atomic_set(&ctx->tid, 0);
41120+ atomic_set_unchecked(&ctx->tid, 0);
41121 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41122 ctx->mcg_wq = create_singlethread_workqueue(name);
41123 if (!ctx->mcg_wq)
41124diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41125index 036b663..c9a8c73 100644
41126--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41127+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41128@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41129 struct list_head mcg_mgid0_list;
41130 struct workqueue_struct *mcg_wq;
41131 struct mlx4_ib_demux_pv_ctx **tun;
41132- atomic_t tid;
41133+ atomic_unchecked_t tid;
41134 int flushing; /* flushing the work queue */
41135 };
41136
41137diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41138index 9d3e5c1..6f166df 100644
41139--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41140+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41141@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41142 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41143 }
41144
41145-int mthca_QUERY_FW(struct mthca_dev *dev)
41146+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41147 {
41148 struct mthca_mailbox *mailbox;
41149 u32 *outbox;
41150@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41151 CMD_TIME_CLASS_B);
41152 }
41153
41154-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41155+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41156 int num_mtt)
41157 {
41158 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41159@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41160 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41161 }
41162
41163-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41164+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41165 int eq_num)
41166 {
41167 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41168@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41169 CMD_TIME_CLASS_B);
41170 }
41171
41172-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41173+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41174 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41175 void *in_mad, void *response_mad)
41176 {
41177diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41178index 87897b9..7e79542 100644
41179--- a/drivers/infiniband/hw/mthca/mthca_main.c
41180+++ b/drivers/infiniband/hw/mthca/mthca_main.c
41181@@ -692,7 +692,7 @@ err_close:
41182 return err;
41183 }
41184
41185-static int mthca_setup_hca(struct mthca_dev *dev)
41186+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41187 {
41188 int err;
41189
41190diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41191index ed9a989..6aa5dc2 100644
41192--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41193+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41194@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41195 * through the bitmaps)
41196 */
41197
41198-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41199+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41200 {
41201 int o;
41202 int m;
41203@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41204 return key;
41205 }
41206
41207-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41208+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41209 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41210 {
41211 struct mthca_mailbox *mailbox;
41212@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41213 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41214 }
41215
41216-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41217+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41218 u64 *buffer_list, int buffer_size_shift,
41219 int list_len, u64 iova, u64 total_size,
41220 u32 access, struct mthca_mr *mr)
41221diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41222index 5b71d43..35a9e14 100644
41223--- a/drivers/infiniband/hw/mthca/mthca_provider.c
41224+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41225@@ -763,7 +763,7 @@ unlock:
41226 return 0;
41227 }
41228
41229-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41230+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41231 {
41232 struct mthca_dev *dev = to_mdev(ibcq->device);
41233 struct mthca_cq *cq = to_mcq(ibcq);
41234diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41235index 4291410..d2ab1fb 100644
41236--- a/drivers/infiniband/hw/nes/nes.c
41237+++ b/drivers/infiniband/hw/nes/nes.c
41238@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41239 LIST_HEAD(nes_adapter_list);
41240 static LIST_HEAD(nes_dev_list);
41241
41242-atomic_t qps_destroyed;
41243+atomic_unchecked_t qps_destroyed;
41244
41245 static unsigned int ee_flsh_adapter;
41246 static unsigned int sysfs_nonidx_addr;
41247@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41248 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41249 struct nes_adapter *nesadapter = nesdev->nesadapter;
41250
41251- atomic_inc(&qps_destroyed);
41252+ atomic_inc_unchecked(&qps_destroyed);
41253
41254 /* Free the control structures */
41255
41256diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41257index 33cc589..3bd6538 100644
41258--- a/drivers/infiniband/hw/nes/nes.h
41259+++ b/drivers/infiniband/hw/nes/nes.h
41260@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41261 extern unsigned int wqm_quanta;
41262 extern struct list_head nes_adapter_list;
41263
41264-extern atomic_t cm_connects;
41265-extern atomic_t cm_accepts;
41266-extern atomic_t cm_disconnects;
41267-extern atomic_t cm_closes;
41268-extern atomic_t cm_connecteds;
41269-extern atomic_t cm_connect_reqs;
41270-extern atomic_t cm_rejects;
41271-extern atomic_t mod_qp_timouts;
41272-extern atomic_t qps_created;
41273-extern atomic_t qps_destroyed;
41274-extern atomic_t sw_qps_destroyed;
41275+extern atomic_unchecked_t cm_connects;
41276+extern atomic_unchecked_t cm_accepts;
41277+extern atomic_unchecked_t cm_disconnects;
41278+extern atomic_unchecked_t cm_closes;
41279+extern atomic_unchecked_t cm_connecteds;
41280+extern atomic_unchecked_t cm_connect_reqs;
41281+extern atomic_unchecked_t cm_rejects;
41282+extern atomic_unchecked_t mod_qp_timouts;
41283+extern atomic_unchecked_t qps_created;
41284+extern atomic_unchecked_t qps_destroyed;
41285+extern atomic_unchecked_t sw_qps_destroyed;
41286 extern u32 mh_detected;
41287 extern u32 mh_pauses_sent;
41288 extern u32 cm_packets_sent;
41289@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41290 extern u32 cm_packets_received;
41291 extern u32 cm_packets_dropped;
41292 extern u32 cm_packets_retrans;
41293-extern atomic_t cm_listens_created;
41294-extern atomic_t cm_listens_destroyed;
41295+extern atomic_unchecked_t cm_listens_created;
41296+extern atomic_unchecked_t cm_listens_destroyed;
41297 extern u32 cm_backlog_drops;
41298-extern atomic_t cm_loopbacks;
41299-extern atomic_t cm_nodes_created;
41300-extern atomic_t cm_nodes_destroyed;
41301-extern atomic_t cm_accel_dropped_pkts;
41302-extern atomic_t cm_resets_recvd;
41303-extern atomic_t pau_qps_created;
41304-extern atomic_t pau_qps_destroyed;
41305+extern atomic_unchecked_t cm_loopbacks;
41306+extern atomic_unchecked_t cm_nodes_created;
41307+extern atomic_unchecked_t cm_nodes_destroyed;
41308+extern atomic_unchecked_t cm_accel_dropped_pkts;
41309+extern atomic_unchecked_t cm_resets_recvd;
41310+extern atomic_unchecked_t pau_qps_created;
41311+extern atomic_unchecked_t pau_qps_destroyed;
41312
41313 extern u32 int_mod_timer_init;
41314 extern u32 int_mod_cq_depth_256;
41315diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41316index 6b29249..57081dd 100644
41317--- a/drivers/infiniband/hw/nes/nes_cm.c
41318+++ b/drivers/infiniband/hw/nes/nes_cm.c
41319@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41320 u32 cm_packets_retrans;
41321 u32 cm_packets_created;
41322 u32 cm_packets_received;
41323-atomic_t cm_listens_created;
41324-atomic_t cm_listens_destroyed;
41325+atomic_unchecked_t cm_listens_created;
41326+atomic_unchecked_t cm_listens_destroyed;
41327 u32 cm_backlog_drops;
41328-atomic_t cm_loopbacks;
41329-atomic_t cm_nodes_created;
41330-atomic_t cm_nodes_destroyed;
41331-atomic_t cm_accel_dropped_pkts;
41332-atomic_t cm_resets_recvd;
41333+atomic_unchecked_t cm_loopbacks;
41334+atomic_unchecked_t cm_nodes_created;
41335+atomic_unchecked_t cm_nodes_destroyed;
41336+atomic_unchecked_t cm_accel_dropped_pkts;
41337+atomic_unchecked_t cm_resets_recvd;
41338
41339 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41340 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41341@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
41342
41343 static struct nes_cm_core *g_cm_core;
41344
41345-atomic_t cm_connects;
41346-atomic_t cm_accepts;
41347-atomic_t cm_disconnects;
41348-atomic_t cm_closes;
41349-atomic_t cm_connecteds;
41350-atomic_t cm_connect_reqs;
41351-atomic_t cm_rejects;
41352+atomic_unchecked_t cm_connects;
41353+atomic_unchecked_t cm_accepts;
41354+atomic_unchecked_t cm_disconnects;
41355+atomic_unchecked_t cm_closes;
41356+atomic_unchecked_t cm_connecteds;
41357+atomic_unchecked_t cm_connect_reqs;
41358+atomic_unchecked_t cm_rejects;
41359
41360 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41361 {
41362@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41363 kfree(listener);
41364 listener = NULL;
41365 ret = 0;
41366- atomic_inc(&cm_listens_destroyed);
41367+ atomic_inc_unchecked(&cm_listens_destroyed);
41368 } else {
41369 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41370 }
41371@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41372 cm_node->rem_mac);
41373
41374 add_hte_node(cm_core, cm_node);
41375- atomic_inc(&cm_nodes_created);
41376+ atomic_inc_unchecked(&cm_nodes_created);
41377
41378 return cm_node;
41379 }
41380@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41381 }
41382
41383 atomic_dec(&cm_core->node_cnt);
41384- atomic_inc(&cm_nodes_destroyed);
41385+ atomic_inc_unchecked(&cm_nodes_destroyed);
41386 nesqp = cm_node->nesqp;
41387 if (nesqp) {
41388 nesqp->cm_node = NULL;
41389@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41390
41391 static void drop_packet(struct sk_buff *skb)
41392 {
41393- atomic_inc(&cm_accel_dropped_pkts);
41394+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41395 dev_kfree_skb_any(skb);
41396 }
41397
41398@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41399 {
41400
41401 int reset = 0; /* whether to send reset in case of err.. */
41402- atomic_inc(&cm_resets_recvd);
41403+ atomic_inc_unchecked(&cm_resets_recvd);
41404 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41405 " refcnt=%d\n", cm_node, cm_node->state,
41406 atomic_read(&cm_node->ref_count));
41407@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41408 rem_ref_cm_node(cm_node->cm_core, cm_node);
41409 return NULL;
41410 }
41411- atomic_inc(&cm_loopbacks);
41412+ atomic_inc_unchecked(&cm_loopbacks);
41413 loopbackremotenode->loopbackpartner = cm_node;
41414 loopbackremotenode->tcp_cntxt.rcv_wscale =
41415 NES_CM_DEFAULT_RCV_WND_SCALE;
41416@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41417 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41418 else {
41419 rem_ref_cm_node(cm_core, cm_node);
41420- atomic_inc(&cm_accel_dropped_pkts);
41421+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41422 dev_kfree_skb_any(skb);
41423 }
41424 break;
41425@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41426
41427 if ((cm_id) && (cm_id->event_handler)) {
41428 if (issue_disconn) {
41429- atomic_inc(&cm_disconnects);
41430+ atomic_inc_unchecked(&cm_disconnects);
41431 cm_event.event = IW_CM_EVENT_DISCONNECT;
41432 cm_event.status = disconn_status;
41433 cm_event.local_addr = cm_id->local_addr;
41434@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41435 }
41436
41437 if (issue_close) {
41438- atomic_inc(&cm_closes);
41439+ atomic_inc_unchecked(&cm_closes);
41440 nes_disconnect(nesqp, 1);
41441
41442 cm_id->provider_data = nesqp;
41443@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41444
41445 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41446 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41447- atomic_inc(&cm_accepts);
41448+ atomic_inc_unchecked(&cm_accepts);
41449
41450 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41451 netdev_refcnt_read(nesvnic->netdev));
41452@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41453 struct nes_cm_core *cm_core;
41454 u8 *start_buff;
41455
41456- atomic_inc(&cm_rejects);
41457+ atomic_inc_unchecked(&cm_rejects);
41458 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41459 loopback = cm_node->loopbackpartner;
41460 cm_core = cm_node->cm_core;
41461@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41462 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41463 ntohs(laddr->sin_port));
41464
41465- atomic_inc(&cm_connects);
41466+ atomic_inc_unchecked(&cm_connects);
41467 nesqp->active_conn = 1;
41468
41469 /* cache the cm_id in the qp */
41470@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41471 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41472 return err;
41473 }
41474- atomic_inc(&cm_listens_created);
41475+ atomic_inc_unchecked(&cm_listens_created);
41476 }
41477
41478 cm_id->add_ref(cm_id);
41479@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41480
41481 if (nesqp->destroyed)
41482 return;
41483- atomic_inc(&cm_connecteds);
41484+ atomic_inc_unchecked(&cm_connecteds);
41485 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41486 " local port 0x%04X. jiffies = %lu.\n",
41487 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
41488@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41489
41490 cm_id->add_ref(cm_id);
41491 ret = cm_id->event_handler(cm_id, &cm_event);
41492- atomic_inc(&cm_closes);
41493+ atomic_inc_unchecked(&cm_closes);
41494 cm_event.event = IW_CM_EVENT_CLOSE;
41495 cm_event.status = 0;
41496 cm_event.provider_data = cm_id->provider_data;
41497@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41498 return;
41499 cm_id = cm_node->cm_id;
41500
41501- atomic_inc(&cm_connect_reqs);
41502+ atomic_inc_unchecked(&cm_connect_reqs);
41503 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41504 cm_node, cm_id, jiffies);
41505
41506@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41507 return;
41508 cm_id = cm_node->cm_id;
41509
41510- atomic_inc(&cm_connect_reqs);
41511+ atomic_inc_unchecked(&cm_connect_reqs);
41512 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41513 cm_node, cm_id, jiffies);
41514
41515diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41516index 4166452..fc952c3 100644
41517--- a/drivers/infiniband/hw/nes/nes_mgt.c
41518+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41519@@ -40,8 +40,8 @@
41520 #include "nes.h"
41521 #include "nes_mgt.h"
41522
41523-atomic_t pau_qps_created;
41524-atomic_t pau_qps_destroyed;
41525+atomic_unchecked_t pau_qps_created;
41526+atomic_unchecked_t pau_qps_destroyed;
41527
41528 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41529 {
41530@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41531 {
41532 struct sk_buff *skb;
41533 unsigned long flags;
41534- atomic_inc(&pau_qps_destroyed);
41535+ atomic_inc_unchecked(&pau_qps_destroyed);
41536
41537 /* Free packets that have not yet been forwarded */
41538 /* Lock is acquired by skb_dequeue when removing the skb */
41539@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41540 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41541 skb_queue_head_init(&nesqp->pau_list);
41542 spin_lock_init(&nesqp->pau_lock);
41543- atomic_inc(&pau_qps_created);
41544+ atomic_inc_unchecked(&pau_qps_created);
41545 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41546 }
41547
41548diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41549index 49eb511..a774366 100644
41550--- a/drivers/infiniband/hw/nes/nes_nic.c
41551+++ b/drivers/infiniband/hw/nes/nes_nic.c
41552@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41553 target_stat_values[++index] = mh_detected;
41554 target_stat_values[++index] = mh_pauses_sent;
41555 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41556- target_stat_values[++index] = atomic_read(&cm_connects);
41557- target_stat_values[++index] = atomic_read(&cm_accepts);
41558- target_stat_values[++index] = atomic_read(&cm_disconnects);
41559- target_stat_values[++index] = atomic_read(&cm_connecteds);
41560- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41561- target_stat_values[++index] = atomic_read(&cm_rejects);
41562- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41563- target_stat_values[++index] = atomic_read(&qps_created);
41564- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41565- target_stat_values[++index] = atomic_read(&qps_destroyed);
41566- target_stat_values[++index] = atomic_read(&cm_closes);
41567+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41568+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41569+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41570+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41571+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41572+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41573+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41574+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41575+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41576+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41577+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41578 target_stat_values[++index] = cm_packets_sent;
41579 target_stat_values[++index] = cm_packets_bounced;
41580 target_stat_values[++index] = cm_packets_created;
41581 target_stat_values[++index] = cm_packets_received;
41582 target_stat_values[++index] = cm_packets_dropped;
41583 target_stat_values[++index] = cm_packets_retrans;
41584- target_stat_values[++index] = atomic_read(&cm_listens_created);
41585- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41586+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41587+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41588 target_stat_values[++index] = cm_backlog_drops;
41589- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41590- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41591- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41592- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41593- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41594+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41595+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41596+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41597+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41598+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41599 target_stat_values[++index] = nesadapter->free_4kpbl;
41600 target_stat_values[++index] = nesadapter->free_256pbl;
41601 target_stat_values[++index] = int_mod_timer_init;
41602 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41603 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41604 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41605- target_stat_values[++index] = atomic_read(&pau_qps_created);
41606- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41607+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41608+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41609 }
41610
41611 /**
41612diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41613index 5b53ca5..443da3c 100644
41614--- a/drivers/infiniband/hw/nes/nes_verbs.c
41615+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41616@@ -46,9 +46,9 @@
41617
41618 #include <rdma/ib_umem.h>
41619
41620-atomic_t mod_qp_timouts;
41621-atomic_t qps_created;
41622-atomic_t sw_qps_destroyed;
41623+atomic_unchecked_t mod_qp_timouts;
41624+atomic_unchecked_t qps_created;
41625+atomic_unchecked_t sw_qps_destroyed;
41626
41627 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41628
41629@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41630 if (init_attr->create_flags)
41631 return ERR_PTR(-EINVAL);
41632
41633- atomic_inc(&qps_created);
41634+ atomic_inc_unchecked(&qps_created);
41635 switch (init_attr->qp_type) {
41636 case IB_QPT_RC:
41637 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41638@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41639 struct iw_cm_event cm_event;
41640 int ret = 0;
41641
41642- atomic_inc(&sw_qps_destroyed);
41643+ atomic_inc_unchecked(&sw_qps_destroyed);
41644 nesqp->destroyed = 1;
41645
41646 /* Blow away the connection if it exists. */
41647diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41648index 1946101..09766d2 100644
41649--- a/drivers/infiniband/hw/qib/qib.h
41650+++ b/drivers/infiniband/hw/qib/qib.h
41651@@ -52,6 +52,7 @@
41652 #include <linux/kref.h>
41653 #include <linux/sched.h>
41654 #include <linux/kthread.h>
41655+#include <linux/slab.h>
41656
41657 #include "qib_common.h"
41658 #include "qib_verbs.h"
41659diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41660index 922a7fe..bb035db 100644
41661--- a/drivers/input/gameport/gameport.c
41662+++ b/drivers/input/gameport/gameport.c
41663@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41664 */
41665 static void gameport_init_port(struct gameport *gameport)
41666 {
41667- static atomic_t gameport_no = ATOMIC_INIT(0);
41668+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41669
41670 __module_get(THIS_MODULE);
41671
41672 mutex_init(&gameport->drv_mutex);
41673 device_initialize(&gameport->dev);
41674 dev_set_name(&gameport->dev, "gameport%lu",
41675- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41676+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41677 gameport->dev.bus = &gameport_bus;
41678 gameport->dev.release = gameport_release_port;
41679 if (gameport->parent)
41680diff --git a/drivers/input/input.c b/drivers/input/input.c
41681index e75d015..57d1c28 100644
41682--- a/drivers/input/input.c
41683+++ b/drivers/input/input.c
41684@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
41685 */
41686 struct input_dev *input_allocate_device(void)
41687 {
41688- static atomic_t input_no = ATOMIC_INIT(0);
41689+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41690 struct input_dev *dev;
41691
41692 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
41693@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
41694 INIT_LIST_HEAD(&dev->node);
41695
41696 dev_set_name(&dev->dev, "input%ld",
41697- (unsigned long) atomic_inc_return(&input_no) - 1);
41698+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41699
41700 __module_get(THIS_MODULE);
41701 }
41702diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41703index 04c69af..5f92d00 100644
41704--- a/drivers/input/joystick/sidewinder.c
41705+++ b/drivers/input/joystick/sidewinder.c
41706@@ -30,6 +30,7 @@
41707 #include <linux/kernel.h>
41708 #include <linux/module.h>
41709 #include <linux/slab.h>
41710+#include <linux/sched.h>
41711 #include <linux/init.h>
41712 #include <linux/input.h>
41713 #include <linux/gameport.h>
41714diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41715index 75e3b10..fb390fd 100644
41716--- a/drivers/input/joystick/xpad.c
41717+++ b/drivers/input/joystick/xpad.c
41718@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41719
41720 static int xpad_led_probe(struct usb_xpad *xpad)
41721 {
41722- static atomic_t led_seq = ATOMIC_INIT(0);
41723+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41724 long led_no;
41725 struct xpad_led *led;
41726 struct led_classdev *led_cdev;
41727@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41728 if (!led)
41729 return -ENOMEM;
41730
41731- led_no = (long)atomic_inc_return(&led_seq) - 1;
41732+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41733
41734 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41735 led->xpad = xpad;
41736diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41737index e204f26..8459f15 100644
41738--- a/drivers/input/misc/ims-pcu.c
41739+++ b/drivers/input/misc/ims-pcu.c
41740@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41741
41742 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41743 {
41744- static atomic_t device_no = ATOMIC_INIT(0);
41745+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41746
41747 const struct ims_pcu_device_info *info;
41748 u8 device_id;
41749@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41750 }
41751
41752 /* Device appears to be operable, complete initialization */
41753- pcu->device_no = atomic_inc_return(&device_no) - 1;
41754+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41755
41756 error = ims_pcu_setup_backlight(pcu);
41757 if (error)
41758diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41759index 2f0b39d..7370f13 100644
41760--- a/drivers/input/mouse/psmouse.h
41761+++ b/drivers/input/mouse/psmouse.h
41762@@ -116,7 +116,7 @@ struct psmouse_attribute {
41763 ssize_t (*set)(struct psmouse *psmouse, void *data,
41764 const char *buf, size_t count);
41765 bool protect;
41766-};
41767+} __do_const;
41768 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41769
41770 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41771diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41772index 4c842c3..590b0bf 100644
41773--- a/drivers/input/mousedev.c
41774+++ b/drivers/input/mousedev.c
41775@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41776
41777 spin_unlock_irq(&client->packet_lock);
41778
41779- if (copy_to_user(buffer, data, count))
41780+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41781 return -EFAULT;
41782
41783 return count;
41784diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41785index 2b56855..5a55837 100644
41786--- a/drivers/input/serio/serio.c
41787+++ b/drivers/input/serio/serio.c
41788@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41789 */
41790 static void serio_init_port(struct serio *serio)
41791 {
41792- static atomic_t serio_no = ATOMIC_INIT(0);
41793+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41794
41795 __module_get(THIS_MODULE);
41796
41797@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41798 mutex_init(&serio->drv_mutex);
41799 device_initialize(&serio->dev);
41800 dev_set_name(&serio->dev, "serio%ld",
41801- (long)atomic_inc_return(&serio_no) - 1);
41802+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41803 serio->dev.bus = &serio_bus;
41804 serio->dev.release = serio_release_port;
41805 serio->dev.groups = serio_device_attr_groups;
41806diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41807index 59df2e7..8f1cafb 100644
41808--- a/drivers/input/serio/serio_raw.c
41809+++ b/drivers/input/serio/serio_raw.c
41810@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41811
41812 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41813 {
41814- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41815+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41816 struct serio_raw *serio_raw;
41817 int err;
41818
41819@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41820 }
41821
41822 snprintf(serio_raw->name, sizeof(serio_raw->name),
41823- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41824+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41825 kref_init(&serio_raw->kref);
41826 INIT_LIST_HEAD(&serio_raw->client_list);
41827 init_waitqueue_head(&serio_raw->wait);
41828diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41829index fbe9ca7..dbee61d 100644
41830--- a/drivers/iommu/iommu.c
41831+++ b/drivers/iommu/iommu.c
41832@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41833 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41834 {
41835 bus_register_notifier(bus, &iommu_bus_nb);
41836- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41837+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41838 }
41839
41840 /**
41841diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41842index 39f81ae..2660096 100644
41843--- a/drivers/iommu/irq_remapping.c
41844+++ b/drivers/iommu/irq_remapping.c
41845@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41846 void panic_if_irq_remap(const char *msg)
41847 {
41848 if (irq_remapping_enabled)
41849- panic(msg);
41850+ panic("%s", msg);
41851 }
41852
41853 static void ir_ack_apic_edge(struct irq_data *data)
41854@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41855
41856 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41857 {
41858- chip->irq_print_chip = ir_print_prefix;
41859- chip->irq_ack = ir_ack_apic_edge;
41860- chip->irq_eoi = ir_ack_apic_level;
41861- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41862+ pax_open_kernel();
41863+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41864+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41865+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41866+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41867+ pax_close_kernel();
41868 }
41869
41870 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41871diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41872index d0e9480..d2b6340 100644
41873--- a/drivers/irqchip/irq-gic.c
41874+++ b/drivers/irqchip/irq-gic.c
41875@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41876 * Supported arch specific GIC irq extension.
41877 * Default make them NULL.
41878 */
41879-struct irq_chip gic_arch_extn = {
41880+irq_chip_no_const gic_arch_extn = {
41881 .irq_eoi = NULL,
41882 .irq_mask = NULL,
41883 .irq_unmask = NULL,
41884@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41885 chained_irq_exit(chip, desc);
41886 }
41887
41888-static struct irq_chip gic_chip = {
41889+static irq_chip_no_const gic_chip __read_only = {
41890 .name = "GIC",
41891 .irq_mask = gic_mask_irq,
41892 .irq_unmask = gic_unmask_irq,
41893diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41894index ac6f72b..81150f2 100644
41895--- a/drivers/isdn/capi/capi.c
41896+++ b/drivers/isdn/capi/capi.c
41897@@ -81,8 +81,8 @@ struct capiminor {
41898
41899 struct capi20_appl *ap;
41900 u32 ncci;
41901- atomic_t datahandle;
41902- atomic_t msgid;
41903+ atomic_unchecked_t datahandle;
41904+ atomic_unchecked_t msgid;
41905
41906 struct tty_port port;
41907 int ttyinstop;
41908@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41909 capimsg_setu16(s, 2, mp->ap->applid);
41910 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41911 capimsg_setu8 (s, 5, CAPI_RESP);
41912- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41913+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41914 capimsg_setu32(s, 8, mp->ncci);
41915 capimsg_setu16(s, 12, datahandle);
41916 }
41917@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41918 mp->outbytes -= len;
41919 spin_unlock_bh(&mp->outlock);
41920
41921- datahandle = atomic_inc_return(&mp->datahandle);
41922+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41923 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41924 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41925 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41926 capimsg_setu16(skb->data, 2, mp->ap->applid);
41927 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41928 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41929- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41930+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41931 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41932 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41933 capimsg_setu16(skb->data, 16, len); /* Data length */
41934diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41935index 600c79b..3752bab 100644
41936--- a/drivers/isdn/gigaset/interface.c
41937+++ b/drivers/isdn/gigaset/interface.c
41938@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41939 }
41940 tty->driver_data = cs;
41941
41942- ++cs->port.count;
41943+ atomic_inc(&cs->port.count);
41944
41945- if (cs->port.count == 1) {
41946+ if (atomic_read(&cs->port.count) == 1) {
41947 tty_port_tty_set(&cs->port, tty);
41948 cs->port.low_latency = 1;
41949 }
41950@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41951
41952 if (!cs->connected)
41953 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41954- else if (!cs->port.count)
41955+ else if (!atomic_read(&cs->port.count))
41956 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41957- else if (!--cs->port.count)
41958+ else if (!atomic_dec_return(&cs->port.count))
41959 tty_port_tty_set(&cs->port, NULL);
41960
41961 mutex_unlock(&cs->mutex);
41962diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41963index d0a41cb..f0cdb8c 100644
41964--- a/drivers/isdn/gigaset/usb-gigaset.c
41965+++ b/drivers/isdn/gigaset/usb-gigaset.c
41966@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41967 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41968 memcpy(cs->hw.usb->bchars, buf, 6);
41969 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41970- 0, 0, &buf, 6, 2000);
41971+ 0, 0, buf, 6, 2000);
41972 }
41973
41974 static void gigaset_freebcshw(struct bc_state *bcs)
41975diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41976index 4d9b195..455075c 100644
41977--- a/drivers/isdn/hardware/avm/b1.c
41978+++ b/drivers/isdn/hardware/avm/b1.c
41979@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41980 }
41981 if (left) {
41982 if (t4file->user) {
41983- if (copy_from_user(buf, dp, left))
41984+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41985 return -EFAULT;
41986 } else {
41987 memcpy(buf, dp, left);
41988@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41989 }
41990 if (left) {
41991 if (config->user) {
41992- if (copy_from_user(buf, dp, left))
41993+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41994 return -EFAULT;
41995 } else {
41996 memcpy(buf, dp, left);
41997diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41998index 9bb12ba..d4262f7 100644
41999--- a/drivers/isdn/i4l/isdn_common.c
42000+++ b/drivers/isdn/i4l/isdn_common.c
42001@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42002 } else
42003 return -EINVAL;
42004 case IIOCDBGVAR:
42005+ if (!capable(CAP_SYS_RAWIO))
42006+ return -EPERM;
42007 if (arg) {
42008 if (copy_to_user(argp, &dev, sizeof(ulong)))
42009 return -EFAULT;
42010diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42011index 3c5f249..5fac4d0 100644
42012--- a/drivers/isdn/i4l/isdn_tty.c
42013+++ b/drivers/isdn/i4l/isdn_tty.c
42014@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42015
42016 #ifdef ISDN_DEBUG_MODEM_OPEN
42017 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42018- port->count);
42019+ atomic_read(&port->count));
42020 #endif
42021- port->count++;
42022+ atomic_inc(&port->count);
42023 port->tty = tty;
42024 /*
42025 * Start up serial port
42026@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42027 #endif
42028 return;
42029 }
42030- if ((tty->count == 1) && (port->count != 1)) {
42031+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42032 /*
42033 * Uh, oh. tty->count is 1, which means that the tty
42034 * structure will be freed. Info->count should always
42035@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42036 * serial port won't be shutdown.
42037 */
42038 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42039- "info->count is %d\n", port->count);
42040- port->count = 1;
42041+ "info->count is %d\n", atomic_read(&port->count));
42042+ atomic_set(&port->count, 1);
42043 }
42044- if (--port->count < 0) {
42045+ if (atomic_dec_return(&port->count) < 0) {
42046 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42047- info->line, port->count);
42048- port->count = 0;
42049+ info->line, atomic_read(&port->count));
42050+ atomic_set(&port->count, 0);
42051 }
42052- if (port->count) {
42053+ if (atomic_read(&port->count)) {
42054 #ifdef ISDN_DEBUG_MODEM_OPEN
42055 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42056 #endif
42057@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42058 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42059 return;
42060 isdn_tty_shutdown(info);
42061- port->count = 0;
42062+ atomic_set(&port->count, 0);
42063 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42064 port->tty = NULL;
42065 wake_up_interruptible(&port->open_wait);
42066@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42067 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42068 modem_info *info = &dev->mdm.info[i];
42069
42070- if (info->port.count == 0)
42071+ if (atomic_read(&info->port.count) == 0)
42072 continue;
42073 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42074 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42075diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42076index e74df7c..03a03ba 100644
42077--- a/drivers/isdn/icn/icn.c
42078+++ b/drivers/isdn/icn/icn.c
42079@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42080 if (count > len)
42081 count = len;
42082 if (user) {
42083- if (copy_from_user(msg, buf, count))
42084+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42085 return -EFAULT;
42086 } else
42087 memcpy(msg, buf, count);
42088diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42089index a4f05c5..1433bc5 100644
42090--- a/drivers/isdn/mISDN/dsp_cmx.c
42091+++ b/drivers/isdn/mISDN/dsp_cmx.c
42092@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42093 static u16 dsp_count; /* last sample count */
42094 static int dsp_count_valid; /* if we have last sample count */
42095
42096-void
42097+void __intentional_overflow(-1)
42098 dsp_cmx_send(void *arg)
42099 {
42100 struct dsp_conf *conf;
42101diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42102index d93e245..e7ece6b 100644
42103--- a/drivers/leds/leds-clevo-mail.c
42104+++ b/drivers/leds/leds-clevo-mail.c
42105@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42106 * detected as working, but in reality it is not) as low as
42107 * possible.
42108 */
42109-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42110+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42111 {
42112 .callback = clevo_mail_led_dmi_callback,
42113 .ident = "Clevo D410J",
42114diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42115index 5b8f938..b73d657 100644
42116--- a/drivers/leds/leds-ss4200.c
42117+++ b/drivers/leds/leds-ss4200.c
42118@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42119 * detected as working, but in reality it is not) as low as
42120 * possible.
42121 */
42122-static struct dmi_system_id nas_led_whitelist[] __initdata = {
42123+static struct dmi_system_id nas_led_whitelist[] __initconst = {
42124 {
42125 .callback = ss4200_led_dmi_callback,
42126 .ident = "Intel SS4200-E",
42127diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42128index 0bf1e4e..b4bf44e 100644
42129--- a/drivers/lguest/core.c
42130+++ b/drivers/lguest/core.c
42131@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42132 * The end address needs +1 because __get_vm_area allocates an
42133 * extra guard page, so we need space for that.
42134 */
42135+
42136+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42137+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42138+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42139+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42140+#else
42141 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42142 VM_ALLOC, switcher_addr, switcher_addr
42143 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42144+#endif
42145+
42146 if (!switcher_vma) {
42147 err = -ENOMEM;
42148 printk("lguest: could not map switcher pages high\n");
42149@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42150 * Now the Switcher is mapped at the right address, we can't fail!
42151 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42152 */
42153- memcpy(switcher_vma->addr, start_switcher_text,
42154+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42155 end_switcher_text - start_switcher_text);
42156
42157 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42158diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42159index bfb39bb..08a603b 100644
42160--- a/drivers/lguest/page_tables.c
42161+++ b/drivers/lguest/page_tables.c
42162@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42163 /*:*/
42164
42165 #ifdef CONFIG_X86_PAE
42166-static void release_pmd(pmd_t *spmd)
42167+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42168 {
42169 /* If the entry's not present, there's nothing to release. */
42170 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42171diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42172index 5169239..47cb4db 100644
42173--- a/drivers/lguest/x86/core.c
42174+++ b/drivers/lguest/x86/core.c
42175@@ -59,7 +59,7 @@ static struct {
42176 /* Offset from where switcher.S was compiled to where we've copied it */
42177 static unsigned long switcher_offset(void)
42178 {
42179- return switcher_addr - (unsigned long)start_switcher_text;
42180+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42181 }
42182
42183 /* This cpu's struct lguest_pages (after the Switcher text page) */
42184@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42185 * These copies are pretty cheap, so we do them unconditionally: */
42186 /* Save the current Host top-level page directory.
42187 */
42188+
42189+#ifdef CONFIG_PAX_PER_CPU_PGD
42190+ pages->state.host_cr3 = read_cr3();
42191+#else
42192 pages->state.host_cr3 = __pa(current->mm->pgd);
42193+#endif
42194+
42195 /*
42196 * Set up the Guest's page tables to see this CPU's pages (and no
42197 * other CPU's pages).
42198@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42199 * compiled-in switcher code and the high-mapped copy we just made.
42200 */
42201 for (i = 0; i < IDT_ENTRIES; i++)
42202- default_idt_entries[i] += switcher_offset();
42203+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42204
42205 /*
42206 * Set up the Switcher's per-cpu areas.
42207@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42208 * it will be undisturbed when we switch. To change %cs and jump we
42209 * need this structure to feed to Intel's "lcall" instruction.
42210 */
42211- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42212+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42213 lguest_entry.segment = LGUEST_CS;
42214
42215 /*
42216diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42217index 40634b0..4f5855e 100644
42218--- a/drivers/lguest/x86/switcher_32.S
42219+++ b/drivers/lguest/x86/switcher_32.S
42220@@ -87,6 +87,7 @@
42221 #include <asm/page.h>
42222 #include <asm/segment.h>
42223 #include <asm/lguest.h>
42224+#include <asm/processor-flags.h>
42225
42226 // We mark the start of the code to copy
42227 // It's placed in .text tho it's never run here
42228@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42229 // Changes type when we load it: damn Intel!
42230 // For after we switch over our page tables
42231 // That entry will be read-only: we'd crash.
42232+
42233+#ifdef CONFIG_PAX_KERNEXEC
42234+ mov %cr0, %edx
42235+ xor $X86_CR0_WP, %edx
42236+ mov %edx, %cr0
42237+#endif
42238+
42239 movl $(GDT_ENTRY_TSS*8), %edx
42240 ltr %dx
42241
42242@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42243 // Let's clear it again for our return.
42244 // The GDT descriptor of the Host
42245 // Points to the table after two "size" bytes
42246- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42247+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42248 // Clear "used" from type field (byte 5, bit 2)
42249- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42250+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42251+
42252+#ifdef CONFIG_PAX_KERNEXEC
42253+ mov %cr0, %eax
42254+ xor $X86_CR0_WP, %eax
42255+ mov %eax, %cr0
42256+#endif
42257
42258 // Once our page table's switched, the Guest is live!
42259 // The Host fades as we run this final step.
42260@@ -295,13 +309,12 @@ deliver_to_host:
42261 // I consulted gcc, and it gave
42262 // These instructions, which I gladly credit:
42263 leal (%edx,%ebx,8), %eax
42264- movzwl (%eax),%edx
42265- movl 4(%eax), %eax
42266- xorw %ax, %ax
42267- orl %eax, %edx
42268+ movl 4(%eax), %edx
42269+ movw (%eax), %dx
42270 // Now the address of the handler's in %edx
42271 // We call it now: its "iret" drops us home.
42272- jmp *%edx
42273+ ljmp $__KERNEL_CS, $1f
42274+1: jmp *%edx
42275
42276 // Every interrupt can come to us here
42277 // But we must truly tell each apart.
42278diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42279index 0003992..854bbce 100644
42280--- a/drivers/md/bcache/closure.h
42281+++ b/drivers/md/bcache/closure.h
42282@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42283 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42284 struct workqueue_struct *wq)
42285 {
42286- BUG_ON(object_is_on_stack(cl));
42287+ BUG_ON(object_starts_on_stack(cl));
42288 closure_set_ip(cl);
42289 cl->fn = fn;
42290 cl->wq = wq;
42291diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42292index 547c4c5..5be1de4 100644
42293--- a/drivers/md/bcache/super.c
42294+++ b/drivers/md/bcache/super.c
42295@@ -1644,7 +1644,7 @@ err_unlock_gc:
42296 err:
42297 closure_sync(&op.cl);
42298 /* XXX: test this, it's broken */
42299- bch_cache_set_error(c, err);
42300+ bch_cache_set_error(c, "%s", err);
42301 }
42302
42303 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42304diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42305index a7fd821..9dcf6c3 100644
42306--- a/drivers/md/bitmap.c
42307+++ b/drivers/md/bitmap.c
42308@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42309 chunk_kb ? "KB" : "B");
42310 if (bitmap->storage.file) {
42311 seq_printf(seq, ", file: ");
42312- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42313+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42314 }
42315
42316 seq_printf(seq, "\n");
42317diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42318index afe0814..8cf3794 100644
42319--- a/drivers/md/dm-ioctl.c
42320+++ b/drivers/md/dm-ioctl.c
42321@@ -1745,7 +1745,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42322 cmd == DM_LIST_VERSIONS_CMD)
42323 return 0;
42324
42325- if ((cmd == DM_DEV_CREATE_CMD)) {
42326+ if (cmd == DM_DEV_CREATE_CMD) {
42327 if (!*param->name) {
42328 DMWARN("name not supplied when creating device");
42329 return -EINVAL;
42330diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42331index 9584443..9fc9ac9 100644
42332--- a/drivers/md/dm-raid1.c
42333+++ b/drivers/md/dm-raid1.c
42334@@ -40,7 +40,7 @@ enum dm_raid1_error {
42335
42336 struct mirror {
42337 struct mirror_set *ms;
42338- atomic_t error_count;
42339+ atomic_unchecked_t error_count;
42340 unsigned long error_type;
42341 struct dm_dev *dev;
42342 sector_t offset;
42343@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42344 struct mirror *m;
42345
42346 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42347- if (!atomic_read(&m->error_count))
42348+ if (!atomic_read_unchecked(&m->error_count))
42349 return m;
42350
42351 return NULL;
42352@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42353 * simple way to tell if a device has encountered
42354 * errors.
42355 */
42356- atomic_inc(&m->error_count);
42357+ atomic_inc_unchecked(&m->error_count);
42358
42359 if (test_and_set_bit(error_type, &m->error_type))
42360 return;
42361@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42362 struct mirror *m = get_default_mirror(ms);
42363
42364 do {
42365- if (likely(!atomic_read(&m->error_count)))
42366+ if (likely(!atomic_read_unchecked(&m->error_count)))
42367 return m;
42368
42369 if (m-- == ms->mirror)
42370@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42371 {
42372 struct mirror *default_mirror = get_default_mirror(m->ms);
42373
42374- return !atomic_read(&default_mirror->error_count);
42375+ return !atomic_read_unchecked(&default_mirror->error_count);
42376 }
42377
42378 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42379@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42380 */
42381 if (likely(region_in_sync(ms, region, 1)))
42382 m = choose_mirror(ms, bio->bi_sector);
42383- else if (m && atomic_read(&m->error_count))
42384+ else if (m && atomic_read_unchecked(&m->error_count))
42385 m = NULL;
42386
42387 if (likely(m))
42388@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42389 }
42390
42391 ms->mirror[mirror].ms = ms;
42392- atomic_set(&(ms->mirror[mirror].error_count), 0);
42393+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42394 ms->mirror[mirror].error_type = 0;
42395 ms->mirror[mirror].offset = offset;
42396
42397@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
42398 */
42399 static char device_status_char(struct mirror *m)
42400 {
42401- if (!atomic_read(&(m->error_count)))
42402+ if (!atomic_read_unchecked(&(m->error_count)))
42403 return 'A';
42404
42405 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42406diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
42407index 3d404c1..b62af0e 100644
42408--- a/drivers/md/dm-stats.c
42409+++ b/drivers/md/dm-stats.c
42410@@ -382,7 +382,7 @@ do_sync_free:
42411 synchronize_rcu_expedited();
42412 dm_stat_free(&s->rcu_head);
42413 } else {
42414- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
42415+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
42416 call_rcu(&s->rcu_head, dm_stat_free);
42417 }
42418 return 0;
42419@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
42420 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
42421 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
42422 ));
42423- ACCESS_ONCE(last->last_sector) = end_sector;
42424- ACCESS_ONCE(last->last_rw) = bi_rw;
42425+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
42426+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
42427 }
42428
42429 rcu_read_lock();
42430diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42431index 73c1712..7347292 100644
42432--- a/drivers/md/dm-stripe.c
42433+++ b/drivers/md/dm-stripe.c
42434@@ -21,7 +21,7 @@ struct stripe {
42435 struct dm_dev *dev;
42436 sector_t physical_start;
42437
42438- atomic_t error_count;
42439+ atomic_unchecked_t error_count;
42440 };
42441
42442 struct stripe_c {
42443@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42444 kfree(sc);
42445 return r;
42446 }
42447- atomic_set(&(sc->stripe[i].error_count), 0);
42448+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42449 }
42450
42451 ti->private = sc;
42452@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42453 DMEMIT("%d ", sc->stripes);
42454 for (i = 0; i < sc->stripes; i++) {
42455 DMEMIT("%s ", sc->stripe[i].dev->name);
42456- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42457+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42458 'D' : 'A';
42459 }
42460 buffer[i] = '\0';
42461@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42462 */
42463 for (i = 0; i < sc->stripes; i++)
42464 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42465- atomic_inc(&(sc->stripe[i].error_count));
42466- if (atomic_read(&(sc->stripe[i].error_count)) <
42467+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42468+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42469 DM_IO_ERROR_THRESHOLD)
42470 schedule_work(&sc->trigger_event);
42471 }
42472diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42473index 41d907b..34b87ee 100644
42474--- a/drivers/md/dm-table.c
42475+++ b/drivers/md/dm-table.c
42476@@ -286,7 +286,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
42477 static int open_dev(struct dm_dev_internal *d, dev_t dev,
42478 struct mapped_device *md)
42479 {
42480- static char *_claim_ptr = "I belong to device-mapper";
42481+ static char _claim_ptr[] = "I belong to device-mapper";
42482 struct block_device *bdev;
42483
42484 int r;
42485@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42486 if (!dev_size)
42487 return 0;
42488
42489- if ((start >= dev_size) || (start + len > dev_size)) {
42490+ if ((start >= dev_size) || (len > dev_size - start)) {
42491 DMWARN("%s: %s too small for target: "
42492 "start=%llu, len=%llu, dev_size=%llu",
42493 dm_device_name(ti->table->md), bdevname(bdev, b),
42494diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42495index 60bce43..9b997d0 100644
42496--- a/drivers/md/dm-thin-metadata.c
42497+++ b/drivers/md/dm-thin-metadata.c
42498@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42499 {
42500 pmd->info.tm = pmd->tm;
42501 pmd->info.levels = 2;
42502- pmd->info.value_type.context = pmd->data_sm;
42503+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42504 pmd->info.value_type.size = sizeof(__le64);
42505 pmd->info.value_type.inc = data_block_inc;
42506 pmd->info.value_type.dec = data_block_dec;
42507@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42508
42509 pmd->bl_info.tm = pmd->tm;
42510 pmd->bl_info.levels = 1;
42511- pmd->bl_info.value_type.context = pmd->data_sm;
42512+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42513 pmd->bl_info.value_type.size = sizeof(__le64);
42514 pmd->bl_info.value_type.inc = data_block_inc;
42515 pmd->bl_info.value_type.dec = data_block_dec;
42516diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42517index b3e26c7..1efca94 100644
42518--- a/drivers/md/dm.c
42519+++ b/drivers/md/dm.c
42520@@ -179,9 +179,9 @@ struct mapped_device {
42521 /*
42522 * Event handling.
42523 */
42524- atomic_t event_nr;
42525+ atomic_unchecked_t event_nr;
42526 wait_queue_head_t eventq;
42527- atomic_t uevent_seq;
42528+ atomic_unchecked_t uevent_seq;
42529 struct list_head uevent_list;
42530 spinlock_t uevent_lock; /* Protect access to uevent_list */
42531
42532@@ -1985,8 +1985,8 @@ static struct mapped_device *alloc_dev(int minor)
42533 spin_lock_init(&md->deferred_lock);
42534 atomic_set(&md->holders, 1);
42535 atomic_set(&md->open_count, 0);
42536- atomic_set(&md->event_nr, 0);
42537- atomic_set(&md->uevent_seq, 0);
42538+ atomic_set_unchecked(&md->event_nr, 0);
42539+ atomic_set_unchecked(&md->uevent_seq, 0);
42540 INIT_LIST_HEAD(&md->uevent_list);
42541 spin_lock_init(&md->uevent_lock);
42542
42543@@ -2139,7 +2139,7 @@ static void event_callback(void *context)
42544
42545 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42546
42547- atomic_inc(&md->event_nr);
42548+ atomic_inc_unchecked(&md->event_nr);
42549 wake_up(&md->eventq);
42550 }
42551
42552@@ -2832,18 +2832,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42553
42554 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42555 {
42556- return atomic_add_return(1, &md->uevent_seq);
42557+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42558 }
42559
42560 uint32_t dm_get_event_nr(struct mapped_device *md)
42561 {
42562- return atomic_read(&md->event_nr);
42563+ return atomic_read_unchecked(&md->event_nr);
42564 }
42565
42566 int dm_wait_event(struct mapped_device *md, int event_nr)
42567 {
42568 return wait_event_interruptible(md->eventq,
42569- (event_nr != atomic_read(&md->event_nr)));
42570+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42571 }
42572
42573 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42574diff --git a/drivers/md/md.c b/drivers/md/md.c
42575index ba46d97..f8f5019 100644
42576--- a/drivers/md/md.c
42577+++ b/drivers/md/md.c
42578@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42579 * start build, activate spare
42580 */
42581 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42582-static atomic_t md_event_count;
42583+static atomic_unchecked_t md_event_count;
42584 void md_new_event(struct mddev *mddev)
42585 {
42586- atomic_inc(&md_event_count);
42587+ atomic_inc_unchecked(&md_event_count);
42588 wake_up(&md_event_waiters);
42589 }
42590 EXPORT_SYMBOL_GPL(md_new_event);
42591@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42592 */
42593 static void md_new_event_inintr(struct mddev *mddev)
42594 {
42595- atomic_inc(&md_event_count);
42596+ atomic_inc_unchecked(&md_event_count);
42597 wake_up(&md_event_waiters);
42598 }
42599
42600@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42601 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42602 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42603 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42604- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42605+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42606
42607 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42608 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42609@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42610 else
42611 sb->resync_offset = cpu_to_le64(0);
42612
42613- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42614+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42615
42616 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42617 sb->size = cpu_to_le64(mddev->dev_sectors);
42618@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42619 static ssize_t
42620 errors_show(struct md_rdev *rdev, char *page)
42621 {
42622- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42623+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42624 }
42625
42626 static ssize_t
42627@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42628 char *e;
42629 unsigned long n = simple_strtoul(buf, &e, 10);
42630 if (*buf && (*e == 0 || *e == '\n')) {
42631- atomic_set(&rdev->corrected_errors, n);
42632+ atomic_set_unchecked(&rdev->corrected_errors, n);
42633 return len;
42634 }
42635 return -EINVAL;
42636@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42637 rdev->sb_loaded = 0;
42638 rdev->bb_page = NULL;
42639 atomic_set(&rdev->nr_pending, 0);
42640- atomic_set(&rdev->read_errors, 0);
42641- atomic_set(&rdev->corrected_errors, 0);
42642+ atomic_set_unchecked(&rdev->read_errors, 0);
42643+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42644
42645 INIT_LIST_HEAD(&rdev->same_set);
42646 init_waitqueue_head(&rdev->blocked_wait);
42647@@ -7043,7 +7043,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42648
42649 spin_unlock(&pers_lock);
42650 seq_printf(seq, "\n");
42651- seq->poll_event = atomic_read(&md_event_count);
42652+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42653 return 0;
42654 }
42655 if (v == (void*)2) {
42656@@ -7146,7 +7146,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42657 return error;
42658
42659 seq = file->private_data;
42660- seq->poll_event = atomic_read(&md_event_count);
42661+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42662 return error;
42663 }
42664
42665@@ -7160,7 +7160,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42666 /* always allow read */
42667 mask = POLLIN | POLLRDNORM;
42668
42669- if (seq->poll_event != atomic_read(&md_event_count))
42670+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42671 mask |= POLLERR | POLLPRI;
42672 return mask;
42673 }
42674@@ -7204,7 +7204,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42675 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42676 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42677 (int)part_stat_read(&disk->part0, sectors[1]) -
42678- atomic_read(&disk->sync_io);
42679+ atomic_read_unchecked(&disk->sync_io);
42680 /* sync IO will cause sync_io to increase before the disk_stats
42681 * as sync_io is counted when a request starts, and
42682 * disk_stats is counted when it completes.
42683diff --git a/drivers/md/md.h b/drivers/md/md.h
42684index 608050c..6e77db5d 100644
42685--- a/drivers/md/md.h
42686+++ b/drivers/md/md.h
42687@@ -94,13 +94,13 @@ struct md_rdev {
42688 * only maintained for arrays that
42689 * support hot removal
42690 */
42691- atomic_t read_errors; /* number of consecutive read errors that
42692+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42693 * we have tried to ignore.
42694 */
42695 struct timespec last_read_error; /* monotonic time since our
42696 * last read error
42697 */
42698- atomic_t corrected_errors; /* number of corrected read errors,
42699+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42700 * for reporting to userspace and storing
42701 * in superblock.
42702 */
42703@@ -446,7 +446,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42704
42705 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42706 {
42707- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42708+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42709 }
42710
42711 struct md_personality
42712diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42713index 3e6d115..ffecdeb 100644
42714--- a/drivers/md/persistent-data/dm-space-map.h
42715+++ b/drivers/md/persistent-data/dm-space-map.h
42716@@ -71,6 +71,7 @@ struct dm_space_map {
42717 dm_sm_threshold_fn fn,
42718 void *context);
42719 };
42720+typedef struct dm_space_map __no_const dm_space_map_no_const;
42721
42722 /*----------------------------------------------------------------*/
42723
42724diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42725index aacf6bf..67d63f2 100644
42726--- a/drivers/md/raid1.c
42727+++ b/drivers/md/raid1.c
42728@@ -1824,7 +1824,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42729 if (r1_sync_page_io(rdev, sect, s,
42730 bio->bi_io_vec[idx].bv_page,
42731 READ) != 0)
42732- atomic_add(s, &rdev->corrected_errors);
42733+ atomic_add_unchecked(s, &rdev->corrected_errors);
42734 }
42735 sectors -= s;
42736 sect += s;
42737@@ -2051,7 +2051,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42738 test_bit(In_sync, &rdev->flags)) {
42739 if (r1_sync_page_io(rdev, sect, s,
42740 conf->tmppage, READ)) {
42741- atomic_add(s, &rdev->corrected_errors);
42742+ atomic_add_unchecked(s, &rdev->corrected_errors);
42743 printk(KERN_INFO
42744 "md/raid1:%s: read error corrected "
42745 "(%d sectors at %llu on %s)\n",
42746diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42747index 73dc8a3..bdd515a 100644
42748--- a/drivers/md/raid10.c
42749+++ b/drivers/md/raid10.c
42750@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
42751 /* The write handler will notice the lack of
42752 * R10BIO_Uptodate and record any errors etc
42753 */
42754- atomic_add(r10_bio->sectors,
42755+ atomic_add_unchecked(r10_bio->sectors,
42756 &conf->mirrors[d].rdev->corrected_errors);
42757
42758 /* for reconstruct, we always reschedule after a read.
42759@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42760 {
42761 struct timespec cur_time_mon;
42762 unsigned long hours_since_last;
42763- unsigned int read_errors = atomic_read(&rdev->read_errors);
42764+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42765
42766 ktime_get_ts(&cur_time_mon);
42767
42768@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42769 * overflowing the shift of read_errors by hours_since_last.
42770 */
42771 if (hours_since_last >= 8 * sizeof(read_errors))
42772- atomic_set(&rdev->read_errors, 0);
42773+ atomic_set_unchecked(&rdev->read_errors, 0);
42774 else
42775- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42776+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42777 }
42778
42779 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42780@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42781 return;
42782
42783 check_decay_read_errors(mddev, rdev);
42784- atomic_inc(&rdev->read_errors);
42785- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42786+ atomic_inc_unchecked(&rdev->read_errors);
42787+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42788 char b[BDEVNAME_SIZE];
42789 bdevname(rdev->bdev, b);
42790
42791@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42792 "md/raid10:%s: %s: Raid device exceeded "
42793 "read_error threshold [cur %d:max %d]\n",
42794 mdname(mddev), b,
42795- atomic_read(&rdev->read_errors), max_read_errors);
42796+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42797 printk(KERN_NOTICE
42798 "md/raid10:%s: %s: Failing raid device\n",
42799 mdname(mddev), b);
42800@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42801 sect +
42802 choose_data_offset(r10_bio, rdev)),
42803 bdevname(rdev->bdev, b));
42804- atomic_add(s, &rdev->corrected_errors);
42805+ atomic_add_unchecked(s, &rdev->corrected_errors);
42806 }
42807
42808 rdev_dec_pending(rdev, mddev);
42809diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42810index 8a0665d..984c46d 100644
42811--- a/drivers/md/raid5.c
42812+++ b/drivers/md/raid5.c
42813@@ -1887,21 +1887,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42814 mdname(conf->mddev), STRIPE_SECTORS,
42815 (unsigned long long)s,
42816 bdevname(rdev->bdev, b));
42817- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42818+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42819 clear_bit(R5_ReadError, &sh->dev[i].flags);
42820 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42821 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42822 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42823
42824- if (atomic_read(&rdev->read_errors))
42825- atomic_set(&rdev->read_errors, 0);
42826+ if (atomic_read_unchecked(&rdev->read_errors))
42827+ atomic_set_unchecked(&rdev->read_errors, 0);
42828 } else {
42829 const char *bdn = bdevname(rdev->bdev, b);
42830 int retry = 0;
42831 int set_bad = 0;
42832
42833 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42834- atomic_inc(&rdev->read_errors);
42835+ atomic_inc_unchecked(&rdev->read_errors);
42836 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42837 printk_ratelimited(
42838 KERN_WARNING
42839@@ -1929,7 +1929,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42840 mdname(conf->mddev),
42841 (unsigned long long)s,
42842 bdn);
42843- } else if (atomic_read(&rdev->read_errors)
42844+ } else if (atomic_read_unchecked(&rdev->read_errors)
42845 > conf->max_nr_stripes)
42846 printk(KERN_WARNING
42847 "md/raid:%s: Too many read errors, failing device %s.\n",
42848diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42849index 401ef64..836e563 100644
42850--- a/drivers/media/dvb-core/dvbdev.c
42851+++ b/drivers/media/dvb-core/dvbdev.c
42852@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42853 const struct dvb_device *template, void *priv, int type)
42854 {
42855 struct dvb_device *dvbdev;
42856- struct file_operations *dvbdevfops;
42857+ file_operations_no_const *dvbdevfops;
42858 struct device *clsdev;
42859 int minor;
42860 int id;
42861diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42862index 9b6c3bb..baeb5c7 100644
42863--- a/drivers/media/dvb-frontends/dib3000.h
42864+++ b/drivers/media/dvb-frontends/dib3000.h
42865@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42866 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42867 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42868 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42869-};
42870+} __no_const;
42871
42872 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42873 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42874diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42875index ecf21d9..b992428d 100644
42876--- a/drivers/media/pci/cx88/cx88-video.c
42877+++ b/drivers/media/pci/cx88/cx88-video.c
42878@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42879
42880 /* ------------------------------------------------------------------ */
42881
42882-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42883-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42884-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42885+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42886+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42887+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42888
42889 module_param_array(video_nr, int, NULL, 0444);
42890 module_param_array(vbi_nr, int, NULL, 0444);
42891diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42892index c08ae3e..eb59af1 100644
42893--- a/drivers/media/pci/ivtv/ivtv-driver.c
42894+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42895@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42896 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42897
42898 /* ivtv instance counter */
42899-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42900+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42901
42902 /* Parameter declarations */
42903 static int cardtype[IVTV_MAX_CARDS];
42904diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42905index dfd0a21..6bbb465 100644
42906--- a/drivers/media/platform/omap/omap_vout.c
42907+++ b/drivers/media/platform/omap/omap_vout.c
42908@@ -63,7 +63,6 @@ enum omap_vout_channels {
42909 OMAP_VIDEO2,
42910 };
42911
42912-static struct videobuf_queue_ops video_vbq_ops;
42913 /* Variables configurable through module params*/
42914 static u32 video1_numbuffers = 3;
42915 static u32 video2_numbuffers = 3;
42916@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42917 {
42918 struct videobuf_queue *q;
42919 struct omap_vout_device *vout = NULL;
42920+ static struct videobuf_queue_ops video_vbq_ops = {
42921+ .buf_setup = omap_vout_buffer_setup,
42922+ .buf_prepare = omap_vout_buffer_prepare,
42923+ .buf_release = omap_vout_buffer_release,
42924+ .buf_queue = omap_vout_buffer_queue,
42925+ };
42926
42927 vout = video_drvdata(file);
42928 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42929@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42930 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42931
42932 q = &vout->vbq;
42933- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42934- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42935- video_vbq_ops.buf_release = omap_vout_buffer_release;
42936- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42937 spin_lock_init(&vout->vbq_lock);
42938
42939 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42940diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42941index 04e6490..2df65bf 100644
42942--- a/drivers/media/platform/s5p-tv/mixer.h
42943+++ b/drivers/media/platform/s5p-tv/mixer.h
42944@@ -156,7 +156,7 @@ struct mxr_layer {
42945 /** layer index (unique identifier) */
42946 int idx;
42947 /** callbacks for layer methods */
42948- struct mxr_layer_ops ops;
42949+ struct mxr_layer_ops *ops;
42950 /** format array */
42951 const struct mxr_format **fmt_array;
42952 /** size of format array */
42953diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42954index b93a21f..2535195 100644
42955--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42956+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42957@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42958 {
42959 struct mxr_layer *layer;
42960 int ret;
42961- struct mxr_layer_ops ops = {
42962+ static struct mxr_layer_ops ops = {
42963 .release = mxr_graph_layer_release,
42964 .buffer_set = mxr_graph_buffer_set,
42965 .stream_set = mxr_graph_stream_set,
42966diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42967index b713403..53cb5ad 100644
42968--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42969+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42970@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42971 layer->update_buf = next;
42972 }
42973
42974- layer->ops.buffer_set(layer, layer->update_buf);
42975+ layer->ops->buffer_set(layer, layer->update_buf);
42976
42977 if (done && done != layer->shadow_buf)
42978 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42979diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42980index 641b1f0..49cff30 100644
42981--- a/drivers/media/platform/s5p-tv/mixer_video.c
42982+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42983@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42984 layer->geo.src.height = layer->geo.src.full_height;
42985
42986 mxr_geometry_dump(mdev, &layer->geo);
42987- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42988+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42989 mxr_geometry_dump(mdev, &layer->geo);
42990 }
42991
42992@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42993 layer->geo.dst.full_width = mbus_fmt.width;
42994 layer->geo.dst.full_height = mbus_fmt.height;
42995 layer->geo.dst.field = mbus_fmt.field;
42996- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42997+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42998
42999 mxr_geometry_dump(mdev, &layer->geo);
43000 }
43001@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43002 /* set source size to highest accepted value */
43003 geo->src.full_width = max(geo->dst.full_width, pix->width);
43004 geo->src.full_height = max(geo->dst.full_height, pix->height);
43005- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43006+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43007 mxr_geometry_dump(mdev, &layer->geo);
43008 /* set cropping to total visible screen */
43009 geo->src.width = pix->width;
43010@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43011 geo->src.x_offset = 0;
43012 geo->src.y_offset = 0;
43013 /* assure consistency of geometry */
43014- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43015+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43016 mxr_geometry_dump(mdev, &layer->geo);
43017 /* set full size to lowest possible value */
43018 geo->src.full_width = 0;
43019 geo->src.full_height = 0;
43020- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43021+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43022 mxr_geometry_dump(mdev, &layer->geo);
43023
43024 /* returning results */
43025@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43026 target->width = s->r.width;
43027 target->height = s->r.height;
43028
43029- layer->ops.fix_geometry(layer, stage, s->flags);
43030+ layer->ops->fix_geometry(layer, stage, s->flags);
43031
43032 /* retrieve update selection rectangle */
43033 res.left = target->x_offset;
43034@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43035 mxr_output_get(mdev);
43036
43037 mxr_layer_update_output(layer);
43038- layer->ops.format_set(layer);
43039+ layer->ops->format_set(layer);
43040 /* enabling layer in hardware */
43041 spin_lock_irqsave(&layer->enq_slock, flags);
43042 layer->state = MXR_LAYER_STREAMING;
43043 spin_unlock_irqrestore(&layer->enq_slock, flags);
43044
43045- layer->ops.stream_set(layer, MXR_ENABLE);
43046+ layer->ops->stream_set(layer, MXR_ENABLE);
43047 mxr_streamer_get(mdev);
43048
43049 return 0;
43050@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43051 spin_unlock_irqrestore(&layer->enq_slock, flags);
43052
43053 /* disabling layer in hardware */
43054- layer->ops.stream_set(layer, MXR_DISABLE);
43055+ layer->ops->stream_set(layer, MXR_DISABLE);
43056 /* remove one streamer */
43057 mxr_streamer_put(mdev);
43058 /* allow changes in output configuration */
43059@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43060
43061 void mxr_layer_release(struct mxr_layer *layer)
43062 {
43063- if (layer->ops.release)
43064- layer->ops.release(layer);
43065+ if (layer->ops->release)
43066+ layer->ops->release(layer);
43067 }
43068
43069 void mxr_base_layer_release(struct mxr_layer *layer)
43070@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43071
43072 layer->mdev = mdev;
43073 layer->idx = idx;
43074- layer->ops = *ops;
43075+ layer->ops = ops;
43076
43077 spin_lock_init(&layer->enq_slock);
43078 INIT_LIST_HEAD(&layer->enq_list);
43079diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43080index 3d13a63..da31bf1 100644
43081--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43082+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43083@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43084 {
43085 struct mxr_layer *layer;
43086 int ret;
43087- struct mxr_layer_ops ops = {
43088+ static struct mxr_layer_ops ops = {
43089 .release = mxr_vp_layer_release,
43090 .buffer_set = mxr_vp_buffer_set,
43091 .stream_set = mxr_vp_stream_set,
43092diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43093index 545c04c..a14bded 100644
43094--- a/drivers/media/radio/radio-cadet.c
43095+++ b/drivers/media/radio/radio-cadet.c
43096@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43097 unsigned char readbuf[RDS_BUFFER];
43098 int i = 0;
43099
43100+ if (count > RDS_BUFFER)
43101+ return -EFAULT;
43102 mutex_lock(&dev->lock);
43103 if (dev->rdsstat == 0)
43104 cadet_start_rds(dev);
43105@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43106 while (i < count && dev->rdsin != dev->rdsout)
43107 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43108
43109- if (i && copy_to_user(data, readbuf, i))
43110+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43111 i = -EFAULT;
43112 unlock:
43113 mutex_unlock(&dev->lock);
43114diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43115index 5236035..c622c74 100644
43116--- a/drivers/media/radio/radio-maxiradio.c
43117+++ b/drivers/media/radio/radio-maxiradio.c
43118@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43119 /* TEA5757 pin mappings */
43120 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43121
43122-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43123+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43124
43125 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43126 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43127diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43128index b914772..7ddbf9b 100644
43129--- a/drivers/media/radio/radio-shark.c
43130+++ b/drivers/media/radio/radio-shark.c
43131@@ -79,7 +79,7 @@ struct shark_device {
43132 u32 last_val;
43133 };
43134
43135-static atomic_t shark_instance = ATOMIC_INIT(0);
43136+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43137
43138 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43139 {
43140diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43141index 9fb6697..f167415 100644
43142--- a/drivers/media/radio/radio-shark2.c
43143+++ b/drivers/media/radio/radio-shark2.c
43144@@ -74,7 +74,7 @@ struct shark_device {
43145 u8 *transfer_buffer;
43146 };
43147
43148-static atomic_t shark_instance = ATOMIC_INIT(0);
43149+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43150
43151 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43152 {
43153diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43154index 9c9084c..a9e8dfb 100644
43155--- a/drivers/media/radio/radio-si476x.c
43156+++ b/drivers/media/radio/radio-si476x.c
43157@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43158 struct si476x_radio *radio;
43159 struct v4l2_ctrl *ctrl;
43160
43161- static atomic_t instance = ATOMIC_INIT(0);
43162+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43163
43164 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43165 if (!radio)
43166diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43167index 46da365..3ba4206 100644
43168--- a/drivers/media/rc/rc-main.c
43169+++ b/drivers/media/rc/rc-main.c
43170@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43171 int rc_register_device(struct rc_dev *dev)
43172 {
43173 static bool raw_init = false; /* raw decoders loaded? */
43174- static atomic_t devno = ATOMIC_INIT(0);
43175+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43176 struct rc_map *rc_map;
43177 const char *path;
43178 int rc;
43179@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43180 */
43181 mutex_lock(&dev->lock);
43182
43183- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43184+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43185 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43186 dev_set_drvdata(&dev->dev, dev);
43187 rc = device_add(&dev->dev);
43188diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43189index 20e345d..da56fe4 100644
43190--- a/drivers/media/usb/dvb-usb/cxusb.c
43191+++ b/drivers/media/usb/dvb-usb/cxusb.c
43192@@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43193
43194 struct dib0700_adapter_state {
43195 int (*set_param_save) (struct dvb_frontend *);
43196-};
43197+} __no_const;
43198
43199 static int dib7070_set_param_override(struct dvb_frontend *fe)
43200 {
43201diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43202index 71b22f5..a63b33f 100644
43203--- a/drivers/media/usb/dvb-usb/dw2102.c
43204+++ b/drivers/media/usb/dvb-usb/dw2102.c
43205@@ -121,7 +121,7 @@ struct su3000_state {
43206
43207 struct s6x0_state {
43208 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43209-};
43210+} __no_const;
43211
43212 /* debug */
43213 static int dvb_usb_dw2102_debug;
43214diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43215index 8f7a6a4..59502dd 100644
43216--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43217+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43218@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43219 __u32 reserved;
43220 };
43221
43222-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43223+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43224 enum v4l2_memory memory)
43225 {
43226 void __user *up_pln;
43227@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43228 return 0;
43229 }
43230
43231-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43232+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43233 enum v4l2_memory memory)
43234 {
43235 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43236@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43237 put_user(kp->start_block, &up->start_block) ||
43238 put_user(kp->blocks, &up->blocks) ||
43239 put_user(tmp, &up->edid) ||
43240- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43241+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43242 return -EFAULT;
43243 return 0;
43244 }
43245diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43246index 02d1b63..5fd6b16 100644
43247--- a/drivers/media/v4l2-core/v4l2-device.c
43248+++ b/drivers/media/v4l2-core/v4l2-device.c
43249@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43250 EXPORT_SYMBOL_GPL(v4l2_device_put);
43251
43252 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43253- atomic_t *instance)
43254+ atomic_unchecked_t *instance)
43255 {
43256- int num = atomic_inc_return(instance) - 1;
43257+ int num = atomic_inc_return_unchecked(instance) - 1;
43258 int len = strlen(basename);
43259
43260 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43261diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43262index 68e6b5e..d8b923e 100644
43263--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43264+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43265@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43266 struct file *file, void *fh, void *p);
43267 } u;
43268 void (*debug)(const void *arg, bool write_only);
43269-};
43270+} __do_const;
43271+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43272
43273 /* This control needs a priority check */
43274 #define INFO_FL_PRIO (1 << 0)
43275@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43276 struct video_device *vfd = video_devdata(file);
43277 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43278 bool write_only = false;
43279- struct v4l2_ioctl_info default_info;
43280+ v4l2_ioctl_info_no_const default_info;
43281 const struct v4l2_ioctl_info *info;
43282 void *fh = file->private_data;
43283 struct v4l2_fh *vfh = NULL;
43284@@ -2194,7 +2195,7 @@ done:
43285 }
43286
43287 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43288- void * __user *user_ptr, void ***kernel_ptr)
43289+ void __user **user_ptr, void ***kernel_ptr)
43290 {
43291 int ret = 0;
43292
43293@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43294 ret = -EINVAL;
43295 break;
43296 }
43297- *user_ptr = (void __user *)buf->m.planes;
43298+ *user_ptr = (void __force_user *)buf->m.planes;
43299 *kernel_ptr = (void *)&buf->m.planes;
43300 *array_size = sizeof(struct v4l2_plane) * buf->length;
43301 ret = 1;
43302@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43303 ret = -EINVAL;
43304 break;
43305 }
43306- *user_ptr = (void __user *)ctrls->controls;
43307+ *user_ptr = (void __force_user *)ctrls->controls;
43308 *kernel_ptr = (void *)&ctrls->controls;
43309 *array_size = sizeof(struct v4l2_ext_control)
43310 * ctrls->count;
43311diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43312index 767ff4d..c69d259 100644
43313--- a/drivers/message/fusion/mptbase.c
43314+++ b/drivers/message/fusion/mptbase.c
43315@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43316 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43317 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43318
43319+#ifdef CONFIG_GRKERNSEC_HIDESYM
43320+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43321+#else
43322 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43323 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43324+#endif
43325+
43326 /*
43327 * Rounding UP to nearest 4-kB boundary here...
43328 */
43329@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43330 ioc->facts.GlobalCredits);
43331
43332 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43333+#ifdef CONFIG_GRKERNSEC_HIDESYM
43334+ NULL, NULL);
43335+#else
43336 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43337+#endif
43338 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43339 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43340 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43341diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43342index dd239bd..689c4f7 100644
43343--- a/drivers/message/fusion/mptsas.c
43344+++ b/drivers/message/fusion/mptsas.c
43345@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43346 return 0;
43347 }
43348
43349+static inline void
43350+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43351+{
43352+ if (phy_info->port_details) {
43353+ phy_info->port_details->rphy = rphy;
43354+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43355+ ioc->name, rphy));
43356+ }
43357+
43358+ if (rphy) {
43359+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43360+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43361+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43362+ ioc->name, rphy, rphy->dev.release));
43363+ }
43364+}
43365+
43366 /* no mutex */
43367 static void
43368 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43369@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43370 return NULL;
43371 }
43372
43373-static inline void
43374-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43375-{
43376- if (phy_info->port_details) {
43377- phy_info->port_details->rphy = rphy;
43378- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43379- ioc->name, rphy));
43380- }
43381-
43382- if (rphy) {
43383- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43384- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43385- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43386- ioc->name, rphy, rphy->dev.release));
43387- }
43388-}
43389-
43390 static inline struct sas_port *
43391 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43392 {
43393diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43394index 727819c..ad74694 100644
43395--- a/drivers/message/fusion/mptscsih.c
43396+++ b/drivers/message/fusion/mptscsih.c
43397@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43398
43399 h = shost_priv(SChost);
43400
43401- if (h) {
43402- if (h->info_kbuf == NULL)
43403- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43404- return h->info_kbuf;
43405- h->info_kbuf[0] = '\0';
43406+ if (!h)
43407+ return NULL;
43408
43409- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43410- h->info_kbuf[size-1] = '\0';
43411- }
43412+ if (h->info_kbuf == NULL)
43413+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43414+ return h->info_kbuf;
43415+ h->info_kbuf[0] = '\0';
43416+
43417+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43418+ h->info_kbuf[size-1] = '\0';
43419
43420 return h->info_kbuf;
43421 }
43422diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43423index b7d87cd..3fb36da 100644
43424--- a/drivers/message/i2o/i2o_proc.c
43425+++ b/drivers/message/i2o/i2o_proc.c
43426@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43427 "Array Controller Device"
43428 };
43429
43430-static char *chtostr(char *tmp, u8 *chars, int n)
43431-{
43432- tmp[0] = 0;
43433- return strncat(tmp, (char *)chars, n);
43434-}
43435-
43436 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43437 char *group)
43438 {
43439@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
43440 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
43441 {
43442 struct i2o_controller *c = (struct i2o_controller *)seq->private;
43443- static u32 work32[5];
43444- static u8 *work8 = (u8 *) work32;
43445- static u16 *work16 = (u16 *) work32;
43446+ u32 work32[5];
43447+ u8 *work8 = (u8 *) work32;
43448+ u16 *work16 = (u16 *) work32;
43449 int token;
43450 u32 hwcap;
43451
43452@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43453 } *result;
43454
43455 i2o_exec_execute_ddm_table ddm_table;
43456- char tmp[28 + 1];
43457
43458 result = kmalloc(sizeof(*result), GFP_KERNEL);
43459 if (!result)
43460@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43461
43462 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43463 seq_printf(seq, "%-#8x", ddm_table.module_id);
43464- seq_printf(seq, "%-29s",
43465- chtostr(tmp, ddm_table.module_name_version, 28));
43466+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43467 seq_printf(seq, "%9d ", ddm_table.data_size);
43468 seq_printf(seq, "%8d", ddm_table.code_size);
43469
43470@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43471
43472 i2o_driver_result_table *result;
43473 i2o_driver_store_table *dst;
43474- char tmp[28 + 1];
43475
43476 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43477 if (result == NULL)
43478@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43479
43480 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43481 seq_printf(seq, "%-#8x", dst->module_id);
43482- seq_printf(seq, "%-29s",
43483- chtostr(tmp, dst->module_name_version, 28));
43484- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43485+ seq_printf(seq, "%-.28s", dst->module_name_version);
43486+ seq_printf(seq, "%-.8s", dst->date);
43487 seq_printf(seq, "%8d ", dst->module_size);
43488 seq_printf(seq, "%8d ", dst->mpb_size);
43489 seq_printf(seq, "0x%04x", dst->module_flags);
43490@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
43491 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43492 {
43493 struct i2o_device *d = (struct i2o_device *)seq->private;
43494- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
43495+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
43496 // == (allow) 512d bytes (max)
43497- static u16 *work16 = (u16 *) work32;
43498+ u16 *work16 = (u16 *) work32;
43499 int token;
43500- char tmp[16 + 1];
43501
43502 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43503
43504@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43505 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43506 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43507 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43508- seq_printf(seq, "Vendor info : %s\n",
43509- chtostr(tmp, (u8 *) (work32 + 2), 16));
43510- seq_printf(seq, "Product info : %s\n",
43511- chtostr(tmp, (u8 *) (work32 + 6), 16));
43512- seq_printf(seq, "Description : %s\n",
43513- chtostr(tmp, (u8 *) (work32 + 10), 16));
43514- seq_printf(seq, "Product rev. : %s\n",
43515- chtostr(tmp, (u8 *) (work32 + 14), 8));
43516+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43517+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43518+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43519+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43520
43521 seq_printf(seq, "Serial number : ");
43522 print_serial_number(seq, (u8 *) (work32 + 16),
43523@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43524 u8 pad[256]; // allow up to 256 byte (max) serial number
43525 } result;
43526
43527- char tmp[24 + 1];
43528-
43529 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43530
43531 if (token < 0) {
43532@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43533 }
43534
43535 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43536- seq_printf(seq, "Module name : %s\n",
43537- chtostr(tmp, result.module_name, 24));
43538- seq_printf(seq, "Module revision : %s\n",
43539- chtostr(tmp, result.module_rev, 8));
43540+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43541+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43542
43543 seq_printf(seq, "Serial number : ");
43544 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43545@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43546 u8 instance_number[4];
43547 } result;
43548
43549- char tmp[64 + 1];
43550-
43551 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43552
43553 if (token < 0) {
43554@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43555 return 0;
43556 }
43557
43558- seq_printf(seq, "Device name : %s\n",
43559- chtostr(tmp, result.device_name, 64));
43560- seq_printf(seq, "Service name : %s\n",
43561- chtostr(tmp, result.service_name, 64));
43562- seq_printf(seq, "Physical name : %s\n",
43563- chtostr(tmp, result.physical_location, 64));
43564- seq_printf(seq, "Instance number : %s\n",
43565- chtostr(tmp, result.instance_number, 4));
43566+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43567+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43568+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43569+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43570
43571 return 0;
43572 }
43573@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43574 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
43575 {
43576 struct i2o_device *d = (struct i2o_device *)seq->private;
43577- static u32 work32[12];
43578- static u16 *work16 = (u16 *) work32;
43579- static u8 *work8 = (u8 *) work32;
43580+ u32 work32[12];
43581+ u16 *work16 = (u16 *) work32;
43582+ u8 *work8 = (u8 *) work32;
43583 int token;
43584
43585 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
43586diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43587index a8c08f3..155fe3d 100644
43588--- a/drivers/message/i2o/iop.c
43589+++ b/drivers/message/i2o/iop.c
43590@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43591
43592 spin_lock_irqsave(&c->context_list_lock, flags);
43593
43594- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43595- atomic_inc(&c->context_list_counter);
43596+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43597+ atomic_inc_unchecked(&c->context_list_counter);
43598
43599- entry->context = atomic_read(&c->context_list_counter);
43600+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43601
43602 list_add(&entry->list, &c->context_list);
43603
43604@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43605
43606 #if BITS_PER_LONG == 64
43607 spin_lock_init(&c->context_list_lock);
43608- atomic_set(&c->context_list_counter, 0);
43609+ atomic_set_unchecked(&c->context_list_counter, 0);
43610 INIT_LIST_HEAD(&c->context_list);
43611 #endif
43612
43613diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43614index fcbb2e9..2635e11 100644
43615--- a/drivers/mfd/janz-cmodio.c
43616+++ b/drivers/mfd/janz-cmodio.c
43617@@ -13,6 +13,7 @@
43618
43619 #include <linux/kernel.h>
43620 #include <linux/module.h>
43621+#include <linux/slab.h>
43622 #include <linux/init.h>
43623 #include <linux/pci.h>
43624 #include <linux/interrupt.h>
43625diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
43626index de7fb80..7c1b931 100644
43627--- a/drivers/mfd/max8925-i2c.c
43628+++ b/drivers/mfd/max8925-i2c.c
43629@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
43630 const struct i2c_device_id *id)
43631 {
43632 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
43633- static struct max8925_chip *chip;
43634+ struct max8925_chip *chip;
43635 struct device_node *node = client->dev.of_node;
43636
43637 if (node && !pdata) {
43638diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
43639index d792772..cd73ba3 100644
43640--- a/drivers/mfd/tps65910.c
43641+++ b/drivers/mfd/tps65910.c
43642@@ -229,7 +229,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
43643 struct tps65910_platform_data *pdata)
43644 {
43645 int ret = 0;
43646- static struct regmap_irq_chip *tps6591x_irqs_chip;
43647+ struct regmap_irq_chip *tps6591x_irqs_chip;
43648
43649 if (!irq) {
43650 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
43651diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43652index 9aa6d1e..1631bfc 100644
43653--- a/drivers/mfd/twl4030-irq.c
43654+++ b/drivers/mfd/twl4030-irq.c
43655@@ -35,6 +35,7 @@
43656 #include <linux/of.h>
43657 #include <linux/irqdomain.h>
43658 #include <linux/i2c/twl.h>
43659+#include <asm/pgtable.h>
43660
43661 #include "twl-core.h"
43662
43663@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43664 * Install an irq handler for each of the SIH modules;
43665 * clone dummy irq_chip since PIH can't *do* anything
43666 */
43667- twl4030_irq_chip = dummy_irq_chip;
43668- twl4030_irq_chip.name = "twl4030";
43669+ pax_open_kernel();
43670+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43671+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43672
43673- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43674+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43675+ pax_close_kernel();
43676
43677 for (i = irq_base; i < irq_end; i++) {
43678 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43679diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43680index 464419b..64bae8d 100644
43681--- a/drivers/misc/c2port/core.c
43682+++ b/drivers/misc/c2port/core.c
43683@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
43684 goto error_idr_alloc;
43685 c2dev->id = ret;
43686
43687- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
43688+ pax_open_kernel();
43689+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
43690+ pax_close_kernel();
43691
43692 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
43693 "c2port%d", c2dev->id);
43694diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43695index 36f5d52..32311c3 100644
43696--- a/drivers/misc/kgdbts.c
43697+++ b/drivers/misc/kgdbts.c
43698@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43699 char before[BREAK_INSTR_SIZE];
43700 char after[BREAK_INSTR_SIZE];
43701
43702- probe_kernel_read(before, (char *)kgdbts_break_test,
43703+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43704 BREAK_INSTR_SIZE);
43705 init_simple_test();
43706 ts.tst = plant_and_detach_test;
43707@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43708 /* Activate test with initial breakpoint */
43709 if (!is_early)
43710 kgdb_breakpoint();
43711- probe_kernel_read(after, (char *)kgdbts_break_test,
43712+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43713 BREAK_INSTR_SIZE);
43714 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43715 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43716diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43717index 036effe..b3a6336 100644
43718--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43719+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43720@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43721 * the lid is closed. This leads to interrupts as soon as a little move
43722 * is done.
43723 */
43724- atomic_inc(&lis3->count);
43725+ atomic_inc_unchecked(&lis3->count);
43726
43727 wake_up_interruptible(&lis3->misc_wait);
43728 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43729@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43730 if (lis3->pm_dev)
43731 pm_runtime_get_sync(lis3->pm_dev);
43732
43733- atomic_set(&lis3->count, 0);
43734+ atomic_set_unchecked(&lis3->count, 0);
43735 return 0;
43736 }
43737
43738@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43739 add_wait_queue(&lis3->misc_wait, &wait);
43740 while (true) {
43741 set_current_state(TASK_INTERRUPTIBLE);
43742- data = atomic_xchg(&lis3->count, 0);
43743+ data = atomic_xchg_unchecked(&lis3->count, 0);
43744 if (data)
43745 break;
43746
43747@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43748 struct lis3lv02d, miscdev);
43749
43750 poll_wait(file, &lis3->misc_wait, wait);
43751- if (atomic_read(&lis3->count))
43752+ if (atomic_read_unchecked(&lis3->count))
43753 return POLLIN | POLLRDNORM;
43754 return 0;
43755 }
43756diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43757index c439c82..1f20f57 100644
43758--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43759+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43760@@ -297,7 +297,7 @@ struct lis3lv02d {
43761 struct input_polled_dev *idev; /* input device */
43762 struct platform_device *pdev; /* platform device */
43763 struct regulator_bulk_data regulators[2];
43764- atomic_t count; /* interrupt count after last read */
43765+ atomic_unchecked_t count; /* interrupt count after last read */
43766 union axis_conversion ac; /* hw -> logical axis */
43767 int mapped_btns[3];
43768
43769diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43770index 2f30bad..c4c13d0 100644
43771--- a/drivers/misc/sgi-gru/gruhandles.c
43772+++ b/drivers/misc/sgi-gru/gruhandles.c
43773@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43774 unsigned long nsec;
43775
43776 nsec = CLKS2NSEC(clks);
43777- atomic_long_inc(&mcs_op_statistics[op].count);
43778- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43779+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43780+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43781 if (mcs_op_statistics[op].max < nsec)
43782 mcs_op_statistics[op].max = nsec;
43783 }
43784diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43785index 4f76359..cdfcb2e 100644
43786--- a/drivers/misc/sgi-gru/gruprocfs.c
43787+++ b/drivers/misc/sgi-gru/gruprocfs.c
43788@@ -32,9 +32,9 @@
43789
43790 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43791
43792-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43793+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43794 {
43795- unsigned long val = atomic_long_read(v);
43796+ unsigned long val = atomic_long_read_unchecked(v);
43797
43798 seq_printf(s, "%16lu %s\n", val, id);
43799 }
43800@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43801
43802 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43803 for (op = 0; op < mcsop_last; op++) {
43804- count = atomic_long_read(&mcs_op_statistics[op].count);
43805- total = atomic_long_read(&mcs_op_statistics[op].total);
43806+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43807+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43808 max = mcs_op_statistics[op].max;
43809 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43810 count ? total / count : 0, max);
43811diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43812index 5c3ce24..4915ccb 100644
43813--- a/drivers/misc/sgi-gru/grutables.h
43814+++ b/drivers/misc/sgi-gru/grutables.h
43815@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43816 * GRU statistics.
43817 */
43818 struct gru_stats_s {
43819- atomic_long_t vdata_alloc;
43820- atomic_long_t vdata_free;
43821- atomic_long_t gts_alloc;
43822- atomic_long_t gts_free;
43823- atomic_long_t gms_alloc;
43824- atomic_long_t gms_free;
43825- atomic_long_t gts_double_allocate;
43826- atomic_long_t assign_context;
43827- atomic_long_t assign_context_failed;
43828- atomic_long_t free_context;
43829- atomic_long_t load_user_context;
43830- atomic_long_t load_kernel_context;
43831- atomic_long_t lock_kernel_context;
43832- atomic_long_t unlock_kernel_context;
43833- atomic_long_t steal_user_context;
43834- atomic_long_t steal_kernel_context;
43835- atomic_long_t steal_context_failed;
43836- atomic_long_t nopfn;
43837- atomic_long_t asid_new;
43838- atomic_long_t asid_next;
43839- atomic_long_t asid_wrap;
43840- atomic_long_t asid_reuse;
43841- atomic_long_t intr;
43842- atomic_long_t intr_cbr;
43843- atomic_long_t intr_tfh;
43844- atomic_long_t intr_spurious;
43845- atomic_long_t intr_mm_lock_failed;
43846- atomic_long_t call_os;
43847- atomic_long_t call_os_wait_queue;
43848- atomic_long_t user_flush_tlb;
43849- atomic_long_t user_unload_context;
43850- atomic_long_t user_exception;
43851- atomic_long_t set_context_option;
43852- atomic_long_t check_context_retarget_intr;
43853- atomic_long_t check_context_unload;
43854- atomic_long_t tlb_dropin;
43855- atomic_long_t tlb_preload_page;
43856- atomic_long_t tlb_dropin_fail_no_asid;
43857- atomic_long_t tlb_dropin_fail_upm;
43858- atomic_long_t tlb_dropin_fail_invalid;
43859- atomic_long_t tlb_dropin_fail_range_active;
43860- atomic_long_t tlb_dropin_fail_idle;
43861- atomic_long_t tlb_dropin_fail_fmm;
43862- atomic_long_t tlb_dropin_fail_no_exception;
43863- atomic_long_t tfh_stale_on_fault;
43864- atomic_long_t mmu_invalidate_range;
43865- atomic_long_t mmu_invalidate_page;
43866- atomic_long_t flush_tlb;
43867- atomic_long_t flush_tlb_gru;
43868- atomic_long_t flush_tlb_gru_tgh;
43869- atomic_long_t flush_tlb_gru_zero_asid;
43870+ atomic_long_unchecked_t vdata_alloc;
43871+ atomic_long_unchecked_t vdata_free;
43872+ atomic_long_unchecked_t gts_alloc;
43873+ atomic_long_unchecked_t gts_free;
43874+ atomic_long_unchecked_t gms_alloc;
43875+ atomic_long_unchecked_t gms_free;
43876+ atomic_long_unchecked_t gts_double_allocate;
43877+ atomic_long_unchecked_t assign_context;
43878+ atomic_long_unchecked_t assign_context_failed;
43879+ atomic_long_unchecked_t free_context;
43880+ atomic_long_unchecked_t load_user_context;
43881+ atomic_long_unchecked_t load_kernel_context;
43882+ atomic_long_unchecked_t lock_kernel_context;
43883+ atomic_long_unchecked_t unlock_kernel_context;
43884+ atomic_long_unchecked_t steal_user_context;
43885+ atomic_long_unchecked_t steal_kernel_context;
43886+ atomic_long_unchecked_t steal_context_failed;
43887+ atomic_long_unchecked_t nopfn;
43888+ atomic_long_unchecked_t asid_new;
43889+ atomic_long_unchecked_t asid_next;
43890+ atomic_long_unchecked_t asid_wrap;
43891+ atomic_long_unchecked_t asid_reuse;
43892+ atomic_long_unchecked_t intr;
43893+ atomic_long_unchecked_t intr_cbr;
43894+ atomic_long_unchecked_t intr_tfh;
43895+ atomic_long_unchecked_t intr_spurious;
43896+ atomic_long_unchecked_t intr_mm_lock_failed;
43897+ atomic_long_unchecked_t call_os;
43898+ atomic_long_unchecked_t call_os_wait_queue;
43899+ atomic_long_unchecked_t user_flush_tlb;
43900+ atomic_long_unchecked_t user_unload_context;
43901+ atomic_long_unchecked_t user_exception;
43902+ atomic_long_unchecked_t set_context_option;
43903+ atomic_long_unchecked_t check_context_retarget_intr;
43904+ atomic_long_unchecked_t check_context_unload;
43905+ atomic_long_unchecked_t tlb_dropin;
43906+ atomic_long_unchecked_t tlb_preload_page;
43907+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43908+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43909+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43910+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43911+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43912+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43913+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43914+ atomic_long_unchecked_t tfh_stale_on_fault;
43915+ atomic_long_unchecked_t mmu_invalidate_range;
43916+ atomic_long_unchecked_t mmu_invalidate_page;
43917+ atomic_long_unchecked_t flush_tlb;
43918+ atomic_long_unchecked_t flush_tlb_gru;
43919+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43920+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43921
43922- atomic_long_t copy_gpa;
43923- atomic_long_t read_gpa;
43924+ atomic_long_unchecked_t copy_gpa;
43925+ atomic_long_unchecked_t read_gpa;
43926
43927- atomic_long_t mesq_receive;
43928- atomic_long_t mesq_receive_none;
43929- atomic_long_t mesq_send;
43930- atomic_long_t mesq_send_failed;
43931- atomic_long_t mesq_noop;
43932- atomic_long_t mesq_send_unexpected_error;
43933- atomic_long_t mesq_send_lb_overflow;
43934- atomic_long_t mesq_send_qlimit_reached;
43935- atomic_long_t mesq_send_amo_nacked;
43936- atomic_long_t mesq_send_put_nacked;
43937- atomic_long_t mesq_page_overflow;
43938- atomic_long_t mesq_qf_locked;
43939- atomic_long_t mesq_qf_noop_not_full;
43940- atomic_long_t mesq_qf_switch_head_failed;
43941- atomic_long_t mesq_qf_unexpected_error;
43942- atomic_long_t mesq_noop_unexpected_error;
43943- atomic_long_t mesq_noop_lb_overflow;
43944- atomic_long_t mesq_noop_qlimit_reached;
43945- atomic_long_t mesq_noop_amo_nacked;
43946- atomic_long_t mesq_noop_put_nacked;
43947- atomic_long_t mesq_noop_page_overflow;
43948+ atomic_long_unchecked_t mesq_receive;
43949+ atomic_long_unchecked_t mesq_receive_none;
43950+ atomic_long_unchecked_t mesq_send;
43951+ atomic_long_unchecked_t mesq_send_failed;
43952+ atomic_long_unchecked_t mesq_noop;
43953+ atomic_long_unchecked_t mesq_send_unexpected_error;
43954+ atomic_long_unchecked_t mesq_send_lb_overflow;
43955+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43956+ atomic_long_unchecked_t mesq_send_amo_nacked;
43957+ atomic_long_unchecked_t mesq_send_put_nacked;
43958+ atomic_long_unchecked_t mesq_page_overflow;
43959+ atomic_long_unchecked_t mesq_qf_locked;
43960+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43961+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43962+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43963+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43964+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43965+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43966+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43967+ atomic_long_unchecked_t mesq_noop_put_nacked;
43968+ atomic_long_unchecked_t mesq_noop_page_overflow;
43969
43970 };
43971
43972@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43973 tghop_invalidate, mcsop_last};
43974
43975 struct mcs_op_statistic {
43976- atomic_long_t count;
43977- atomic_long_t total;
43978+ atomic_long_unchecked_t count;
43979+ atomic_long_unchecked_t total;
43980 unsigned long max;
43981 };
43982
43983@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43984
43985 #define STAT(id) do { \
43986 if (gru_options & OPT_STATS) \
43987- atomic_long_inc(&gru_stats.id); \
43988+ atomic_long_inc_unchecked(&gru_stats.id); \
43989 } while (0)
43990
43991 #ifdef CONFIG_SGI_GRU_DEBUG
43992diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43993index c862cd4..0d176fe 100644
43994--- a/drivers/misc/sgi-xp/xp.h
43995+++ b/drivers/misc/sgi-xp/xp.h
43996@@ -288,7 +288,7 @@ struct xpc_interface {
43997 xpc_notify_func, void *);
43998 void (*received) (short, int, void *);
43999 enum xp_retval (*partid_to_nasids) (short, void *);
44000-};
44001+} __no_const;
44002
44003 extern struct xpc_interface xpc_interface;
44004
44005diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44006index b94d5f7..7f494c5 100644
44007--- a/drivers/misc/sgi-xp/xpc.h
44008+++ b/drivers/misc/sgi-xp/xpc.h
44009@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44010 void (*received_payload) (struct xpc_channel *, void *);
44011 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44012 };
44013+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44014
44015 /* struct xpc_partition act_state values (for XPC HB) */
44016
44017@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44018 /* found in xpc_main.c */
44019 extern struct device *xpc_part;
44020 extern struct device *xpc_chan;
44021-extern struct xpc_arch_operations xpc_arch_ops;
44022+extern xpc_arch_operations_no_const xpc_arch_ops;
44023 extern int xpc_disengage_timelimit;
44024 extern int xpc_disengage_timedout;
44025 extern int xpc_activate_IRQ_rcvd;
44026diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44027index 82dc574..8539ab2 100644
44028--- a/drivers/misc/sgi-xp/xpc_main.c
44029+++ b/drivers/misc/sgi-xp/xpc_main.c
44030@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44031 .notifier_call = xpc_system_die,
44032 };
44033
44034-struct xpc_arch_operations xpc_arch_ops;
44035+xpc_arch_operations_no_const xpc_arch_ops;
44036
44037 /*
44038 * Timer function to enforce the timelimit on the partition disengage.
44039@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44040
44041 if (((die_args->trapnr == X86_TRAP_MF) ||
44042 (die_args->trapnr == X86_TRAP_XF)) &&
44043- !user_mode_vm(die_args->regs))
44044+ !user_mode(die_args->regs))
44045 xpc_die_deactivate();
44046
44047 break;
44048diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44049index ef18348..1b53cf0 100644
44050--- a/drivers/mmc/core/mmc_ops.c
44051+++ b/drivers/mmc/core/mmc_ops.c
44052@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44053 void *data_buf;
44054 int is_on_stack;
44055
44056- is_on_stack = object_is_on_stack(buf);
44057+ is_on_stack = object_starts_on_stack(buf);
44058 if (is_on_stack) {
44059 /*
44060 * dma onto stack is unsafe/nonportable, but callers to this
44061diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44062index 81b2994..dce857e 100644
44063--- a/drivers/mmc/host/dw_mmc.h
44064+++ b/drivers/mmc/host/dw_mmc.h
44065@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44066 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44067 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44068 int (*parse_dt)(struct dw_mci *host);
44069-};
44070+} __do_const;
44071 #endif /* _DW_MMC_H_ */
44072diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44073index c3785ed..1984c44 100644
44074--- a/drivers/mmc/host/mmci.c
44075+++ b/drivers/mmc/host/mmci.c
44076@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
44077 }
44078
44079 if (variant->busy_detect) {
44080- mmci_ops.card_busy = mmci_card_busy;
44081+ pax_open_kernel();
44082+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44083+ pax_close_kernel();
44084 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44085 }
44086
44087diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44088index 6debda9..2ba7427 100644
44089--- a/drivers/mmc/host/sdhci-s3c.c
44090+++ b/drivers/mmc/host/sdhci-s3c.c
44091@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44092 * we can use overriding functions instead of default.
44093 */
44094 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44095- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44096- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44097- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44098+ pax_open_kernel();
44099+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44100+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44101+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44102+ pax_close_kernel();
44103 }
44104
44105 /* It supports additional host capabilities if needed */
44106diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44107index 096993f..f02c23b 100644
44108--- a/drivers/mtd/chips/cfi_cmdset_0020.c
44109+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44110@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44111 size_t totlen = 0, thislen;
44112 int ret = 0;
44113 size_t buflen = 0;
44114- static char *buffer;
44115+ char *buffer;
44116
44117 if (!ECCBUF_SIZE) {
44118 /* We should fall back to a general writev implementation.
44119diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44120index 2ed2bb3..2d0b82e 100644
44121--- a/drivers/mtd/nand/denali.c
44122+++ b/drivers/mtd/nand/denali.c
44123@@ -24,6 +24,7 @@
44124 #include <linux/slab.h>
44125 #include <linux/mtd/mtd.h>
44126 #include <linux/module.h>
44127+#include <linux/slab.h>
44128
44129 #include "denali.h"
44130
44131diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44132index 51b9d6a..52af9a7 100644
44133--- a/drivers/mtd/nftlmount.c
44134+++ b/drivers/mtd/nftlmount.c
44135@@ -24,6 +24,7 @@
44136 #include <asm/errno.h>
44137 #include <linux/delay.h>
44138 #include <linux/slab.h>
44139+#include <linux/sched.h>
44140 #include <linux/mtd/mtd.h>
44141 #include <linux/mtd/nand.h>
44142 #include <linux/mtd/nftl.h>
44143diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44144index 4b8e895..6b3c498 100644
44145--- a/drivers/mtd/sm_ftl.c
44146+++ b/drivers/mtd/sm_ftl.c
44147@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44148 #define SM_CIS_VENDOR_OFFSET 0x59
44149 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44150 {
44151- struct attribute_group *attr_group;
44152+ attribute_group_no_const *attr_group;
44153 struct attribute **attributes;
44154 struct sm_sysfs_attribute *vendor_attribute;
44155
44156diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44157index dd8057d..22aaf36 100644
44158--- a/drivers/net/bonding/bond_main.c
44159+++ b/drivers/net/bonding/bond_main.c
44160@@ -4511,7 +4511,7 @@ static unsigned int bond_get_num_tx_queues(void)
44161 return tx_queues;
44162 }
44163
44164-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44165+static struct rtnl_link_ops bond_link_ops = {
44166 .kind = "bond",
44167 .priv_size = sizeof(struct bonding),
44168 .setup = bond_setup,
44169@@ -4636,8 +4636,8 @@ static void __exit bonding_exit(void)
44170
44171 bond_destroy_debugfs();
44172
44173- rtnl_link_unregister(&bond_link_ops);
44174 unregister_pernet_subsys(&bond_net_ops);
44175+ rtnl_link_unregister(&bond_link_ops);
44176
44177 #ifdef CONFIG_NET_POLL_CONTROLLER
44178 /*
44179diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44180index f92f001..0b2f9bf 100644
44181--- a/drivers/net/ethernet/8390/ax88796.c
44182+++ b/drivers/net/ethernet/8390/ax88796.c
44183@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44184 if (ax->plat->reg_offsets)
44185 ei_local->reg_offset = ax->plat->reg_offsets;
44186 else {
44187+ resource_size_t _mem_size = mem_size;
44188+ do_div(_mem_size, 0x18);
44189 ei_local->reg_offset = ax->reg_offsets;
44190 for (ret = 0; ret < 0x18; ret++)
44191- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44192+ ax->reg_offsets[ret] = _mem_size * ret;
44193 }
44194
44195 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44196diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44197index da8fcaa..f4b5d3b 100644
44198--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44199+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44200@@ -1138,7 +1138,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44201 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44202 {
44203 /* RX_MODE controlling object */
44204- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44205+ bnx2x_init_rx_mode_obj(bp);
44206
44207 /* multicast configuration controlling object */
44208 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44209diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44210index 9fbeee5..5e3e37a 100644
44211--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44212+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44213@@ -2590,15 +2590,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44214 return rc;
44215 }
44216
44217-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44218- struct bnx2x_rx_mode_obj *o)
44219+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44220 {
44221 if (CHIP_IS_E1x(bp)) {
44222- o->wait_comp = bnx2x_empty_rx_mode_wait;
44223- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44224+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44225+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44226 } else {
44227- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44228- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44229+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44230+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44231 }
44232 }
44233
44234diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44235index 658f4e3..15074a6 100644
44236--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44237+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44238@@ -1325,8 +1325,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44239
44240 /********************* RX MODE ****************/
44241
44242-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44243- struct bnx2x_rx_mode_obj *o);
44244+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44245
44246 /**
44247 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44248diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44249index 7025780..e55a71c 100644
44250--- a/drivers/net/ethernet/broadcom/tg3.h
44251+++ b/drivers/net/ethernet/broadcom/tg3.h
44252@@ -147,6 +147,7 @@
44253 #define CHIPREV_ID_5750_A0 0x4000
44254 #define CHIPREV_ID_5750_A1 0x4001
44255 #define CHIPREV_ID_5750_A3 0x4003
44256+#define CHIPREV_ID_5750_C1 0x4201
44257 #define CHIPREV_ID_5750_C2 0x4202
44258 #define CHIPREV_ID_5752_A0_HW 0x5000
44259 #define CHIPREV_ID_5752_A0 0x6000
44260diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44261index 8cffcdf..aadf043 100644
44262--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44263+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44264@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44265 */
44266 struct l2t_skb_cb {
44267 arp_failure_handler_func arp_failure_handler;
44268-};
44269+} __no_const;
44270
44271 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44272
44273diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44274index c73cabd..cd278b1 100644
44275--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44276+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
44277@@ -2186,7 +2186,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
44278
44279 int i;
44280 struct adapter *ap = netdev2adap(dev);
44281- static const unsigned int *reg_ranges;
44282+ const unsigned int *reg_ranges;
44283 int arr_size = 0, buf_size = 0;
44284
44285 if (is_t4(ap->chip)) {
44286diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44287index 263b92c..f05134b 100644
44288--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44289+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44290@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44291 for (i=0; i<ETH_ALEN; i++) {
44292 tmp.addr[i] = dev->dev_addr[i];
44293 }
44294- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44295+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44296 break;
44297
44298 case DE4X5_SET_HWADDR: /* Set the hardware address */
44299@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44300 spin_lock_irqsave(&lp->lock, flags);
44301 memcpy(&statbuf, &lp->pktStats, ioc->len);
44302 spin_unlock_irqrestore(&lp->lock, flags);
44303- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44304+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44305 return -EFAULT;
44306 break;
44307 }
44308diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44309index 2c38cc4..0323f6e 100644
44310--- a/drivers/net/ethernet/emulex/benet/be_main.c
44311+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44312@@ -470,7 +470,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44313
44314 if (wrapped)
44315 newacc += 65536;
44316- ACCESS_ONCE(*acc) = newacc;
44317+ ACCESS_ONCE_RW(*acc) = newacc;
44318 }
44319
44320 static void populate_erx_stats(struct be_adapter *adapter,
44321diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44322index 212f44b..fb69959 100644
44323--- a/drivers/net/ethernet/faraday/ftgmac100.c
44324+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44325@@ -31,6 +31,8 @@
44326 #include <linux/netdevice.h>
44327 #include <linux/phy.h>
44328 #include <linux/platform_device.h>
44329+#include <linux/interrupt.h>
44330+#include <linux/irqreturn.h>
44331 #include <net/ip.h>
44332
44333 #include "ftgmac100.h"
44334diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44335index 8be5b40..081bc1b 100644
44336--- a/drivers/net/ethernet/faraday/ftmac100.c
44337+++ b/drivers/net/ethernet/faraday/ftmac100.c
44338@@ -31,6 +31,8 @@
44339 #include <linux/module.h>
44340 #include <linux/netdevice.h>
44341 #include <linux/platform_device.h>
44342+#include <linux/interrupt.h>
44343+#include <linux/irqreturn.h>
44344
44345 #include "ftmac100.h"
44346
44347diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44348index 5184e2a..acb28c3 100644
44349--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44350+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44351@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44352 }
44353
44354 /* update the base incval used to calculate frequency adjustment */
44355- ACCESS_ONCE(adapter->base_incval) = incval;
44356+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44357 smp_mb();
44358
44359 /* need lock to prevent incorrect read while modifying cyclecounter */
44360diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44361index fbe5363..266b4e3 100644
44362--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44363+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44364@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44365 struct __vxge_hw_fifo *fifo;
44366 struct vxge_hw_fifo_config *config;
44367 u32 txdl_size, txdl_per_memblock;
44368- struct vxge_hw_mempool_cbs fifo_mp_callback;
44369+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44370+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44371+ };
44372+
44373 struct __vxge_hw_virtualpath *vpath;
44374
44375 if ((vp == NULL) || (attr == NULL)) {
44376@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44377 goto exit;
44378 }
44379
44380- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44381-
44382 fifo->mempool =
44383 __vxge_hw_mempool_create(vpath->hldev,
44384 fifo->config->memblock_size,
44385diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44386index f09e787..f3916a8 100644
44387--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44388+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44389@@ -2055,7 +2055,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
44390
44391 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
44392 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
44393- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44394+ pax_open_kernel();
44395+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44396+ pax_close_kernel();
44397 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44398 } else {
44399 return -EIO;
44400diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44401index 0248a4c..9648d96 100644
44402--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44403+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44404@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44405 case QLCNIC_NON_PRIV_FUNC:
44406 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44407 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44408- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44409+ pax_open_kernel();
44410+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44411+ pax_close_kernel();
44412 break;
44413 case QLCNIC_PRIV_FUNC:
44414 ahw->op_mode = QLCNIC_PRIV_FUNC;
44415 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44416- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44417+ pax_open_kernel();
44418+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44419+ pax_close_kernel();
44420 break;
44421 case QLCNIC_MGMT_FUNC:
44422 ahw->op_mode = QLCNIC_MGMT_FUNC;
44423 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44424- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44425+ pax_open_kernel();
44426+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44427+ pax_close_kernel();
44428 break;
44429 default:
44430 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44431diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44432index 1551360..ed6510f 100644
44433--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44434+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
44435@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
44436 struct qlcnic_dump_entry *entry;
44437 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
44438 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
44439- static const struct qlcnic_dump_operations *fw_dump_ops;
44440+ const struct qlcnic_dump_operations *fw_dump_ops;
44441 struct device *dev = &adapter->pdev->dev;
44442 struct qlcnic_hardware_context *ahw;
44443 void *temp_buffer;
44444diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44445index fb3f8dc..9d2ff38 100644
44446--- a/drivers/net/ethernet/realtek/r8169.c
44447+++ b/drivers/net/ethernet/realtek/r8169.c
44448@@ -759,22 +759,22 @@ struct rtl8169_private {
44449 struct mdio_ops {
44450 void (*write)(struct rtl8169_private *, int, int);
44451 int (*read)(struct rtl8169_private *, int);
44452- } mdio_ops;
44453+ } __no_const mdio_ops;
44454
44455 struct pll_power_ops {
44456 void (*down)(struct rtl8169_private *);
44457 void (*up)(struct rtl8169_private *);
44458- } pll_power_ops;
44459+ } __no_const pll_power_ops;
44460
44461 struct jumbo_ops {
44462 void (*enable)(struct rtl8169_private *);
44463 void (*disable)(struct rtl8169_private *);
44464- } jumbo_ops;
44465+ } __no_const jumbo_ops;
44466
44467 struct csi_ops {
44468 void (*write)(struct rtl8169_private *, int, int);
44469 u32 (*read)(struct rtl8169_private *, int);
44470- } csi_ops;
44471+ } __no_const csi_ops;
44472
44473 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44474 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44475diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44476index 03acf57..e1251ff 100644
44477--- a/drivers/net/ethernet/sfc/ptp.c
44478+++ b/drivers/net/ethernet/sfc/ptp.c
44479@@ -539,7 +539,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44480 ptp->start.dma_addr);
44481
44482 /* Clear flag that signals MC ready */
44483- ACCESS_ONCE(*start) = 0;
44484+ ACCESS_ONCE_RW(*start) = 0;
44485 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44486 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44487 EFX_BUG_ON_PARANOID(rc);
44488diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44489index 50617c5..b13724c 100644
44490--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44491+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44492@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44493
44494 writel(value, ioaddr + MMC_CNTRL);
44495
44496- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44497- MMC_CNTRL, value);
44498+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44499+// MMC_CNTRL, value);
44500 }
44501
44502 /* To mask all all interrupts.*/
44503diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44504index e6fe0d8..2b7d752 100644
44505--- a/drivers/net/hyperv/hyperv_net.h
44506+++ b/drivers/net/hyperv/hyperv_net.h
44507@@ -101,7 +101,7 @@ struct rndis_device {
44508
44509 enum rndis_device_state state;
44510 bool link_state;
44511- atomic_t new_req_id;
44512+ atomic_unchecked_t new_req_id;
44513
44514 spinlock_t request_lock;
44515 struct list_head req_list;
44516diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44517index 0775f0a..d4fb316 100644
44518--- a/drivers/net/hyperv/rndis_filter.c
44519+++ b/drivers/net/hyperv/rndis_filter.c
44520@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44521 * template
44522 */
44523 set = &rndis_msg->msg.set_req;
44524- set->req_id = atomic_inc_return(&dev->new_req_id);
44525+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44526
44527 /* Add to the request list */
44528 spin_lock_irqsave(&dev->request_lock, flags);
44529@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44530
44531 /* Setup the rndis set */
44532 halt = &request->request_msg.msg.halt_req;
44533- halt->req_id = atomic_inc_return(&dev->new_req_id);
44534+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44535
44536 /* Ignore return since this msg is optional. */
44537 rndis_filter_send_request(dev, request);
44538diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44539index bf0d55e..82bcfbd1 100644
44540--- a/drivers/net/ieee802154/fakehard.c
44541+++ b/drivers/net/ieee802154/fakehard.c
44542@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44543 phy->transmit_power = 0xbf;
44544
44545 dev->netdev_ops = &fake_ops;
44546- dev->ml_priv = &fake_mlme;
44547+ dev->ml_priv = (void *)&fake_mlme;
44548
44549 priv = netdev_priv(dev);
44550 priv->phy = phy;
44551diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44552index 9bf46bd..bfdaa84 100644
44553--- a/drivers/net/macvlan.c
44554+++ b/drivers/net/macvlan.c
44555@@ -939,13 +939,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44556 int macvlan_link_register(struct rtnl_link_ops *ops)
44557 {
44558 /* common fields */
44559- ops->priv_size = sizeof(struct macvlan_dev);
44560- ops->validate = macvlan_validate;
44561- ops->maxtype = IFLA_MACVLAN_MAX;
44562- ops->policy = macvlan_policy;
44563- ops->changelink = macvlan_changelink;
44564- ops->get_size = macvlan_get_size;
44565- ops->fill_info = macvlan_fill_info;
44566+ pax_open_kernel();
44567+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44568+ *(void **)&ops->validate = macvlan_validate;
44569+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44570+ *(const void **)&ops->policy = macvlan_policy;
44571+ *(void **)&ops->changelink = macvlan_changelink;
44572+ *(void **)&ops->get_size = macvlan_get_size;
44573+ *(void **)&ops->fill_info = macvlan_fill_info;
44574+ pax_close_kernel();
44575
44576 return rtnl_link_register(ops);
44577 };
44578@@ -1001,7 +1003,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44579 return NOTIFY_DONE;
44580 }
44581
44582-static struct notifier_block macvlan_notifier_block __read_mostly = {
44583+static struct notifier_block macvlan_notifier_block = {
44584 .notifier_call = macvlan_device_event,
44585 };
44586
44587diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44588index dc76670..e18f39c 100644
44589--- a/drivers/net/macvtap.c
44590+++ b/drivers/net/macvtap.c
44591@@ -1189,7 +1189,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44592 return NOTIFY_DONE;
44593 }
44594
44595-static struct notifier_block macvtap_notifier_block __read_mostly = {
44596+static struct notifier_block macvtap_notifier_block = {
44597 .notifier_call = macvtap_device_event,
44598 };
44599
44600diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44601index daec9b0..6428fcb 100644
44602--- a/drivers/net/phy/mdio-bitbang.c
44603+++ b/drivers/net/phy/mdio-bitbang.c
44604@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44605 struct mdiobb_ctrl *ctrl = bus->priv;
44606
44607 module_put(ctrl->ops->owner);
44608+ mdiobus_unregister(bus);
44609 mdiobus_free(bus);
44610 }
44611 EXPORT_SYMBOL(free_mdio_bitbang);
44612diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44613index 72ff14b..11d442d 100644
44614--- a/drivers/net/ppp/ppp_generic.c
44615+++ b/drivers/net/ppp/ppp_generic.c
44616@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44617 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44618 struct ppp_stats stats;
44619 struct ppp_comp_stats cstats;
44620- char *vers;
44621
44622 switch (cmd) {
44623 case SIOCGPPPSTATS:
44624@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44625 break;
44626
44627 case SIOCGPPPVER:
44628- vers = PPP_VERSION;
44629- if (copy_to_user(addr, vers, strlen(vers) + 1))
44630+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44631 break;
44632 err = 0;
44633 break;
44634diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44635index 1252d9c..80e660b 100644
44636--- a/drivers/net/slip/slhc.c
44637+++ b/drivers/net/slip/slhc.c
44638@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44639 register struct tcphdr *thp;
44640 register struct iphdr *ip;
44641 register struct cstate *cs;
44642- int len, hdrlen;
44643+ long len, hdrlen;
44644 unsigned char *cp = icp;
44645
44646 /* We've got a compressed packet; read the change byte */
44647diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44648index 6327df2..e6e1ebe 100644
44649--- a/drivers/net/team/team.c
44650+++ b/drivers/net/team/team.c
44651@@ -2873,7 +2873,7 @@ static int team_device_event(struct notifier_block *unused,
44652 return NOTIFY_DONE;
44653 }
44654
44655-static struct notifier_block team_notifier_block __read_mostly = {
44656+static struct notifier_block team_notifier_block = {
44657 .notifier_call = team_device_event,
44658 };
44659
44660diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44661index 782e38b..d076fdc 100644
44662--- a/drivers/net/tun.c
44663+++ b/drivers/net/tun.c
44664@@ -1834,7 +1834,7 @@ unlock:
44665 }
44666
44667 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44668- unsigned long arg, int ifreq_len)
44669+ unsigned long arg, size_t ifreq_len)
44670 {
44671 struct tun_file *tfile = file->private_data;
44672 struct tun_struct *tun;
44673@@ -1847,6 +1847,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44674 unsigned int ifindex;
44675 int ret;
44676
44677+ if (ifreq_len > sizeof ifr)
44678+ return -EFAULT;
44679+
44680 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44681 if (copy_from_user(&ifr, argp, ifreq_len))
44682 return -EFAULT;
44683diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44684index 86292e6..8d34433 100644
44685--- a/drivers/net/usb/hso.c
44686+++ b/drivers/net/usb/hso.c
44687@@ -71,7 +71,7 @@
44688 #include <asm/byteorder.h>
44689 #include <linux/serial_core.h>
44690 #include <linux/serial.h>
44691-
44692+#include <asm/local.h>
44693
44694 #define MOD_AUTHOR "Option Wireless"
44695 #define MOD_DESCRIPTION "USB High Speed Option driver"
44696@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44697 struct urb *urb;
44698
44699 urb = serial->rx_urb[0];
44700- if (serial->port.count > 0) {
44701+ if (atomic_read(&serial->port.count) > 0) {
44702 count = put_rxbuf_data(urb, serial);
44703 if (count == -1)
44704 return;
44705@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44706 DUMP1(urb->transfer_buffer, urb->actual_length);
44707
44708 /* Anyone listening? */
44709- if (serial->port.count == 0)
44710+ if (atomic_read(&serial->port.count) == 0)
44711 return;
44712
44713 if (status == 0) {
44714@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44715 tty_port_tty_set(&serial->port, tty);
44716
44717 /* check for port already opened, if not set the termios */
44718- serial->port.count++;
44719- if (serial->port.count == 1) {
44720+ if (atomic_inc_return(&serial->port.count) == 1) {
44721 serial->rx_state = RX_IDLE;
44722 /* Force default termio settings */
44723 _hso_serial_set_termios(tty, NULL);
44724@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44725 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44726 if (result) {
44727 hso_stop_serial_device(serial->parent);
44728- serial->port.count--;
44729+ atomic_dec(&serial->port.count);
44730 kref_put(&serial->parent->ref, hso_serial_ref_free);
44731 }
44732 } else {
44733@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44734
44735 /* reset the rts and dtr */
44736 /* do the actual close */
44737- serial->port.count--;
44738+ atomic_dec(&serial->port.count);
44739
44740- if (serial->port.count <= 0) {
44741- serial->port.count = 0;
44742+ if (atomic_read(&serial->port.count) <= 0) {
44743+ atomic_set(&serial->port.count, 0);
44744 tty_port_tty_set(&serial->port, NULL);
44745 if (!usb_gone)
44746 hso_stop_serial_device(serial->parent);
44747@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44748
44749 /* the actual setup */
44750 spin_lock_irqsave(&serial->serial_lock, flags);
44751- if (serial->port.count)
44752+ if (atomic_read(&serial->port.count))
44753 _hso_serial_set_termios(tty, old);
44754 else
44755 tty->termios = *old;
44756@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44757 D1("Pending read interrupt on port %d\n", i);
44758 spin_lock(&serial->serial_lock);
44759 if (serial->rx_state == RX_IDLE &&
44760- serial->port.count > 0) {
44761+ atomic_read(&serial->port.count) > 0) {
44762 /* Setup and send a ctrl req read on
44763 * port i */
44764 if (!serial->rx_urb_filled[0]) {
44765@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44766 /* Start all serial ports */
44767 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44768 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44769- if (dev2ser(serial_table[i])->port.count) {
44770+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44771 result =
44772 hso_start_serial_device(serial_table[i], GFP_NOIO);
44773 hso_kick_transmit(dev2ser(serial_table[i]));
44774diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44775index a79e9d3..78cd4fa 100644
44776--- a/drivers/net/usb/sierra_net.c
44777+++ b/drivers/net/usb/sierra_net.c
44778@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44779 /* atomic counter partially included in MAC address to make sure 2 devices
44780 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44781 */
44782-static atomic_t iface_counter = ATOMIC_INIT(0);
44783+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44784
44785 /*
44786 * SYNC Timer Delay definition used to set the expiry time
44787@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44788 dev->net->netdev_ops = &sierra_net_device_ops;
44789
44790 /* change MAC addr to include, ifacenum, and to be unique */
44791- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44792+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44793 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44794
44795 /* we will have to manufacture ethernet headers, prepare template */
44796diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44797index 2ef5b62..6fa0ec3 100644
44798--- a/drivers/net/vxlan.c
44799+++ b/drivers/net/vxlan.c
44800@@ -2615,7 +2615,7 @@ nla_put_failure:
44801 return -EMSGSIZE;
44802 }
44803
44804-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44805+static struct rtnl_link_ops vxlan_link_ops = {
44806 .kind = "vxlan",
44807 .maxtype = IFLA_VXLAN_MAX,
44808 .policy = vxlan_policy,
44809diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44810index 0b60295..b8bfa5b 100644
44811--- a/drivers/net/wimax/i2400m/rx.c
44812+++ b/drivers/net/wimax/i2400m/rx.c
44813@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44814 if (i2400m->rx_roq == NULL)
44815 goto error_roq_alloc;
44816
44817- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44818+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44819 GFP_KERNEL);
44820 if (rd == NULL) {
44821 result = -ENOMEM;
44822diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
44823index 7fe1964..7016de0 100644
44824--- a/drivers/net/wireless/airo.c
44825+++ b/drivers/net/wireless/airo.c
44826@@ -7844,7 +7844,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
44827 struct airo_info *ai = dev->ml_priv;
44828 int ridcode;
44829 int enabled;
44830- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44831+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44832 unsigned char *iobuf;
44833
44834 /* Only super-user can write RIDs */
44835diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44836index 34c8a33..3261fdc 100644
44837--- a/drivers/net/wireless/at76c50x-usb.c
44838+++ b/drivers/net/wireless/at76c50x-usb.c
44839@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44840 }
44841
44842 /* Convert timeout from the DFU status to jiffies */
44843-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44844+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44845 {
44846 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44847 | (s->poll_timeout[1] << 8)
44848diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44849index ef3329e..c28ff5d 100644
44850--- a/drivers/net/wireless/ath/ath10k/htc.c
44851+++ b/drivers/net/wireless/ath/ath10k/htc.c
44852@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44853 /* registered target arrival callback from the HIF layer */
44854 int ath10k_htc_init(struct ath10k *ar)
44855 {
44856- struct ath10k_hif_cb htc_callbacks;
44857+ static struct ath10k_hif_cb htc_callbacks = {
44858+ .rx_completion = ath10k_htc_rx_completion_handler,
44859+ .tx_completion = ath10k_htc_tx_completion_handler,
44860+ };
44861 struct ath10k_htc_ep *ep = NULL;
44862 struct ath10k_htc *htc = &ar->htc;
44863
44864@@ -973,8 +976,6 @@ int ath10k_htc_init(struct ath10k *ar)
44865 ath10k_htc_reset_endpoint_states(htc);
44866
44867 /* setup HIF layer callbacks */
44868- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44869- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44870 htc->ar = ar;
44871
44872 /* Get HIF default pipe for HTC message exchange */
44873diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
44874index e1dd8c7..9f91b3f 100644
44875--- a/drivers/net/wireless/ath/ath10k/htc.h
44876+++ b/drivers/net/wireless/ath/ath10k/htc.h
44877@@ -271,12 +271,12 @@ enum ath10k_htc_ep_id {
44878
44879 struct ath10k_htc_ops {
44880 void (*target_send_suspend_complete)(struct ath10k *ar);
44881-};
44882+} __no_const;
44883
44884 struct ath10k_htc_ep_ops {
44885 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
44886 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
44887-};
44888+} __no_const;
44889
44890 /* service connection information */
44891 struct ath10k_htc_svc_conn_req {
44892diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44893index 8d78253..bebbb68 100644
44894--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44895+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44896@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44897 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44898 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44899
44900- ACCESS_ONCE(ads->ds_link) = i->link;
44901- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44902+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44903+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44904
44905 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44906 ctl6 = SM(i->keytype, AR_EncrType);
44907@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44908
44909 if ((i->is_first || i->is_last) &&
44910 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44911- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44912+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44913 | set11nTries(i->rates, 1)
44914 | set11nTries(i->rates, 2)
44915 | set11nTries(i->rates, 3)
44916 | (i->dur_update ? AR_DurUpdateEna : 0)
44917 | SM(0, AR_BurstDur);
44918
44919- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44920+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44921 | set11nRate(i->rates, 1)
44922 | set11nRate(i->rates, 2)
44923 | set11nRate(i->rates, 3);
44924 } else {
44925- ACCESS_ONCE(ads->ds_ctl2) = 0;
44926- ACCESS_ONCE(ads->ds_ctl3) = 0;
44927+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44928+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44929 }
44930
44931 if (!i->is_first) {
44932- ACCESS_ONCE(ads->ds_ctl0) = 0;
44933- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44934- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44935+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44936+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44937+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44938 return;
44939 }
44940
44941@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44942 break;
44943 }
44944
44945- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44946+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44947 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44948 | SM(i->txpower, AR_XmitPower)
44949 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44950@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44951 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44952 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44953
44954- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44955- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44956+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44957+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44958
44959 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44960 return;
44961
44962- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44963+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44964 | set11nPktDurRTSCTS(i->rates, 1);
44965
44966- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44967+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44968 | set11nPktDurRTSCTS(i->rates, 3);
44969
44970- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44971+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44972 | set11nRateFlags(i->rates, 1)
44973 | set11nRateFlags(i->rates, 2)
44974 | set11nRateFlags(i->rates, 3)
44975diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44976index f6c5c1b..6058354 100644
44977--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44978+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44979@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44980 (i->qcu << AR_TxQcuNum_S) | desc_len;
44981
44982 checksum += val;
44983- ACCESS_ONCE(ads->info) = val;
44984+ ACCESS_ONCE_RW(ads->info) = val;
44985
44986 checksum += i->link;
44987- ACCESS_ONCE(ads->link) = i->link;
44988+ ACCESS_ONCE_RW(ads->link) = i->link;
44989
44990 checksum += i->buf_addr[0];
44991- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44992+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44993 checksum += i->buf_addr[1];
44994- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44995+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44996 checksum += i->buf_addr[2];
44997- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44998+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44999 checksum += i->buf_addr[3];
45000- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45001+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45002
45003 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45004- ACCESS_ONCE(ads->ctl3) = val;
45005+ ACCESS_ONCE_RW(ads->ctl3) = val;
45006 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45007- ACCESS_ONCE(ads->ctl5) = val;
45008+ ACCESS_ONCE_RW(ads->ctl5) = val;
45009 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45010- ACCESS_ONCE(ads->ctl7) = val;
45011+ ACCESS_ONCE_RW(ads->ctl7) = val;
45012 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45013- ACCESS_ONCE(ads->ctl9) = val;
45014+ ACCESS_ONCE_RW(ads->ctl9) = val;
45015
45016 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45017- ACCESS_ONCE(ads->ctl10) = checksum;
45018+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
45019
45020 if (i->is_first || i->is_last) {
45021- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45022+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45023 | set11nTries(i->rates, 1)
45024 | set11nTries(i->rates, 2)
45025 | set11nTries(i->rates, 3)
45026 | (i->dur_update ? AR_DurUpdateEna : 0)
45027 | SM(0, AR_BurstDur);
45028
45029- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45030+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45031 | set11nRate(i->rates, 1)
45032 | set11nRate(i->rates, 2)
45033 | set11nRate(i->rates, 3);
45034 } else {
45035- ACCESS_ONCE(ads->ctl13) = 0;
45036- ACCESS_ONCE(ads->ctl14) = 0;
45037+ ACCESS_ONCE_RW(ads->ctl13) = 0;
45038+ ACCESS_ONCE_RW(ads->ctl14) = 0;
45039 }
45040
45041 ads->ctl20 = 0;
45042@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45043
45044 ctl17 = SM(i->keytype, AR_EncrType);
45045 if (!i->is_first) {
45046- ACCESS_ONCE(ads->ctl11) = 0;
45047- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45048- ACCESS_ONCE(ads->ctl15) = 0;
45049- ACCESS_ONCE(ads->ctl16) = 0;
45050- ACCESS_ONCE(ads->ctl17) = ctl17;
45051- ACCESS_ONCE(ads->ctl18) = 0;
45052- ACCESS_ONCE(ads->ctl19) = 0;
45053+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45054+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45055+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45056+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45057+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45058+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45059+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45060 return;
45061 }
45062
45063- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45064+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45065 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45066 | SM(i->txpower, AR_XmitPower)
45067 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45068@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45069 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45070 ctl12 |= SM(val, AR_PAPRDChainMask);
45071
45072- ACCESS_ONCE(ads->ctl12) = ctl12;
45073- ACCESS_ONCE(ads->ctl17) = ctl17;
45074+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45075+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45076
45077- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45078+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45079 | set11nPktDurRTSCTS(i->rates, 1);
45080
45081- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45082+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45083 | set11nPktDurRTSCTS(i->rates, 3);
45084
45085- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45086+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45087 | set11nRateFlags(i->rates, 1)
45088 | set11nRateFlags(i->rates, 2)
45089 | set11nRateFlags(i->rates, 3)
45090 | SM(i->rtscts_rate, AR_RTSCTSRate);
45091
45092- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45093+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45094 }
45095
45096 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45097diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45098index 69a907b..91e071c 100644
45099--- a/drivers/net/wireless/ath/ath9k/hw.h
45100+++ b/drivers/net/wireless/ath/ath9k/hw.h
45101@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
45102
45103 /* ANI */
45104 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45105-};
45106+} __no_const;
45107
45108 /**
45109 * struct ath_spec_scan - parameters for Atheros spectral scan
45110@@ -729,7 +729,7 @@ struct ath_hw_ops {
45111 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
45112 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
45113 #endif
45114-};
45115+} __no_const;
45116
45117 struct ath_nf_limits {
45118 s16 max;
45119diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
45120index 92190da..f3a4c4c 100644
45121--- a/drivers/net/wireless/b43/phy_lp.c
45122+++ b/drivers/net/wireless/b43/phy_lp.c
45123@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
45124 {
45125 struct ssb_bus *bus = dev->dev->sdev->bus;
45126
45127- static const struct b206x_channel *chandata = NULL;
45128+ const struct b206x_channel *chandata = NULL;
45129 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
45130 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
45131 u16 old_comm15, scale;
45132diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45133index 9581d07..84f6a76 100644
45134--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45135+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45136@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45137 */
45138 if (il3945_mod_params.disable_hw_scan) {
45139 D_INFO("Disabling hw_scan\n");
45140- il3945_mac_ops.hw_scan = NULL;
45141+ pax_open_kernel();
45142+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45143+ pax_close_kernel();
45144 }
45145
45146 D_INFO("*** LOAD DRIVER ***\n");
45147diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45148index d94f8ab..5b568c8 100644
45149--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45150+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45151@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45152 {
45153 struct iwl_priv *priv = file->private_data;
45154 char buf[64];
45155- int buf_size;
45156+ size_t buf_size;
45157 u32 offset, len;
45158
45159 memset(buf, 0, sizeof(buf));
45160@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45161 struct iwl_priv *priv = file->private_data;
45162
45163 char buf[8];
45164- int buf_size;
45165+ size_t buf_size;
45166 u32 reset_flag;
45167
45168 memset(buf, 0, sizeof(buf));
45169@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45170 {
45171 struct iwl_priv *priv = file->private_data;
45172 char buf[8];
45173- int buf_size;
45174+ size_t buf_size;
45175 int ht40;
45176
45177 memset(buf, 0, sizeof(buf));
45178@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45179 {
45180 struct iwl_priv *priv = file->private_data;
45181 char buf[8];
45182- int buf_size;
45183+ size_t buf_size;
45184 int value;
45185
45186 memset(buf, 0, sizeof(buf));
45187@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45188 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45189 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45190
45191-static const char *fmt_value = " %-30s %10u\n";
45192-static const char *fmt_hex = " %-30s 0x%02X\n";
45193-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45194-static const char *fmt_header =
45195+static const char fmt_value[] = " %-30s %10u\n";
45196+static const char fmt_hex[] = " %-30s 0x%02X\n";
45197+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45198+static const char fmt_header[] =
45199 "%-32s current cumulative delta max\n";
45200
45201 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45202@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45203 {
45204 struct iwl_priv *priv = file->private_data;
45205 char buf[8];
45206- int buf_size;
45207+ size_t buf_size;
45208 int clear;
45209
45210 memset(buf, 0, sizeof(buf));
45211@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45212 {
45213 struct iwl_priv *priv = file->private_data;
45214 char buf[8];
45215- int buf_size;
45216+ size_t buf_size;
45217 int trace;
45218
45219 memset(buf, 0, sizeof(buf));
45220@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45221 {
45222 struct iwl_priv *priv = file->private_data;
45223 char buf[8];
45224- int buf_size;
45225+ size_t buf_size;
45226 int missed;
45227
45228 memset(buf, 0, sizeof(buf));
45229@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45230
45231 struct iwl_priv *priv = file->private_data;
45232 char buf[8];
45233- int buf_size;
45234+ size_t buf_size;
45235 int plcp;
45236
45237 memset(buf, 0, sizeof(buf));
45238@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45239
45240 struct iwl_priv *priv = file->private_data;
45241 char buf[8];
45242- int buf_size;
45243+ size_t buf_size;
45244 int flush;
45245
45246 memset(buf, 0, sizeof(buf));
45247@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45248
45249 struct iwl_priv *priv = file->private_data;
45250 char buf[8];
45251- int buf_size;
45252+ size_t buf_size;
45253 int rts;
45254
45255 if (!priv->cfg->ht_params)
45256@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45257 {
45258 struct iwl_priv *priv = file->private_data;
45259 char buf[8];
45260- int buf_size;
45261+ size_t buf_size;
45262
45263 memset(buf, 0, sizeof(buf));
45264 buf_size = min(count, sizeof(buf) - 1);
45265@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45266 struct iwl_priv *priv = file->private_data;
45267 u32 event_log_flag;
45268 char buf[8];
45269- int buf_size;
45270+ size_t buf_size;
45271
45272 /* check that the interface is up */
45273 if (!iwl_is_ready(priv))
45274@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45275 struct iwl_priv *priv = file->private_data;
45276 char buf[8];
45277 u32 calib_disabled;
45278- int buf_size;
45279+ size_t buf_size;
45280
45281 memset(buf, 0, sizeof(buf));
45282 buf_size = min(count, sizeof(buf) - 1);
45283diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45284index 7aad766..06addb4 100644
45285--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45286+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45287@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45288 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45289 {
45290 struct iwl_nvm_data *data = priv->nvm_data;
45291- char *debug_msg;
45292+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45293
45294 if (data->sku_cap_11n_enable &&
45295 !priv->cfg->ht_params) {
45296@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45297 return -EINVAL;
45298 }
45299
45300- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45301 IWL_DEBUG_INFO(priv, debug_msg,
45302 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45303 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45304diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45305index c3f904d..4cadf83 100644
45306--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45307+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45308@@ -1252,7 +1252,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45309 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45310
45311 char buf[8];
45312- int buf_size;
45313+ size_t buf_size;
45314 u32 reset_flag;
45315
45316 memset(buf, 0, sizeof(buf));
45317@@ -1273,7 +1273,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45318 {
45319 struct iwl_trans *trans = file->private_data;
45320 char buf[8];
45321- int buf_size;
45322+ size_t buf_size;
45323 int csr;
45324
45325 memset(buf, 0, sizeof(buf));
45326diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45327index 2cd3f54..e936f90 100644
45328--- a/drivers/net/wireless/mac80211_hwsim.c
45329+++ b/drivers/net/wireless/mac80211_hwsim.c
45330@@ -2196,25 +2196,19 @@ static int __init init_mac80211_hwsim(void)
45331
45332 if (channels > 1) {
45333 hwsim_if_comb.num_different_channels = channels;
45334- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45335- mac80211_hwsim_ops.cancel_hw_scan =
45336- mac80211_hwsim_cancel_hw_scan;
45337- mac80211_hwsim_ops.sw_scan_start = NULL;
45338- mac80211_hwsim_ops.sw_scan_complete = NULL;
45339- mac80211_hwsim_ops.remain_on_channel =
45340- mac80211_hwsim_roc;
45341- mac80211_hwsim_ops.cancel_remain_on_channel =
45342- mac80211_hwsim_croc;
45343- mac80211_hwsim_ops.add_chanctx =
45344- mac80211_hwsim_add_chanctx;
45345- mac80211_hwsim_ops.remove_chanctx =
45346- mac80211_hwsim_remove_chanctx;
45347- mac80211_hwsim_ops.change_chanctx =
45348- mac80211_hwsim_change_chanctx;
45349- mac80211_hwsim_ops.assign_vif_chanctx =
45350- mac80211_hwsim_assign_vif_chanctx;
45351- mac80211_hwsim_ops.unassign_vif_chanctx =
45352- mac80211_hwsim_unassign_vif_chanctx;
45353+ pax_open_kernel();
45354+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45355+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45356+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45357+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45358+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45359+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45360+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45361+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45362+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45363+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45364+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45365+ pax_close_kernel();
45366 }
45367
45368 spin_lock_init(&hwsim_radio_lock);
45369diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45370index 8169a85..7fa3b47 100644
45371--- a/drivers/net/wireless/rndis_wlan.c
45372+++ b/drivers/net/wireless/rndis_wlan.c
45373@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45374
45375 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45376
45377- if (rts_threshold < 0 || rts_threshold > 2347)
45378+ if (rts_threshold > 2347)
45379 rts_threshold = 2347;
45380
45381 tmp = cpu_to_le32(rts_threshold);
45382diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45383index fe4c572..99dedfa 100644
45384--- a/drivers/net/wireless/rt2x00/rt2x00.h
45385+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45386@@ -387,7 +387,7 @@ struct rt2x00_intf {
45387 * for hardware which doesn't support hardware
45388 * sequence counting.
45389 */
45390- atomic_t seqno;
45391+ atomic_unchecked_t seqno;
45392 };
45393
45394 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45395diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45396index 66a2db8..70cad04 100644
45397--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45398+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45399@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45400 * sequence counter given by mac80211.
45401 */
45402 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45403- seqno = atomic_add_return(0x10, &intf->seqno);
45404+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45405 else
45406- seqno = atomic_read(&intf->seqno);
45407+ seqno = atomic_read_unchecked(&intf->seqno);
45408
45409 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45410 hdr->seq_ctrl |= cpu_to_le16(seqno);
45411diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45412index e2b3d9c..67a5184 100644
45413--- a/drivers/net/wireless/ti/wl1251/sdio.c
45414+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45415@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45416
45417 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45418
45419- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45420- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45421+ pax_open_kernel();
45422+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45423+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45424+ pax_close_kernel();
45425
45426 wl1251_info("using dedicated interrupt line");
45427 } else {
45428- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45429- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45430+ pax_open_kernel();
45431+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45432+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45433+ pax_close_kernel();
45434
45435 wl1251_info("using SDIO interrupt");
45436 }
45437diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45438index 1c627da..69f7d17 100644
45439--- a/drivers/net/wireless/ti/wl12xx/main.c
45440+++ b/drivers/net/wireless/ti/wl12xx/main.c
45441@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45442 sizeof(wl->conf.mem));
45443
45444 /* read data preparation is only needed by wl127x */
45445- wl->ops->prepare_read = wl127x_prepare_read;
45446+ pax_open_kernel();
45447+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45448+ pax_close_kernel();
45449
45450 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45451 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45452@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45453 sizeof(wl->conf.mem));
45454
45455 /* read data preparation is only needed by wl127x */
45456- wl->ops->prepare_read = wl127x_prepare_read;
45457+ pax_open_kernel();
45458+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45459+ pax_close_kernel();
45460
45461 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45462 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45463diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45464index 7aa0eb8..5a9ef38 100644
45465--- a/drivers/net/wireless/ti/wl18xx/main.c
45466+++ b/drivers/net/wireless/ti/wl18xx/main.c
45467@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45468 }
45469
45470 if (!checksum_param) {
45471- wl18xx_ops.set_rx_csum = NULL;
45472- wl18xx_ops.init_vif = NULL;
45473+ pax_open_kernel();
45474+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45475+ *(void **)&wl18xx_ops.init_vif = NULL;
45476+ pax_close_kernel();
45477 }
45478
45479 /* Enable 11a Band only if we have 5G antennas */
45480diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45481index 7ef0b4a..ff65c28 100644
45482--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45483+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45484@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45485 {
45486 struct zd_usb *usb = urb->context;
45487 struct zd_usb_interrupt *intr = &usb->intr;
45488- int len;
45489+ unsigned int len;
45490 u16 int_num;
45491
45492 ZD_ASSERT(in_interrupt());
45493diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
45494index 59f95d8..53e0e7f 100644
45495--- a/drivers/nfc/nfcwilink.c
45496+++ b/drivers/nfc/nfcwilink.c
45497@@ -513,7 +513,7 @@ static struct nci_ops nfcwilink_ops = {
45498
45499 static int nfcwilink_probe(struct platform_device *pdev)
45500 {
45501- static struct nfcwilink *drv;
45502+ struct nfcwilink *drv;
45503 int rc;
45504 __u32 protocols;
45505
45506diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45507index d93b2b6..ae50401 100644
45508--- a/drivers/oprofile/buffer_sync.c
45509+++ b/drivers/oprofile/buffer_sync.c
45510@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45511 if (cookie == NO_COOKIE)
45512 offset = pc;
45513 if (cookie == INVALID_COOKIE) {
45514- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45515+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45516 offset = pc;
45517 }
45518 if (cookie != last_cookie) {
45519@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45520 /* add userspace sample */
45521
45522 if (!mm) {
45523- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45524+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45525 return 0;
45526 }
45527
45528 cookie = lookup_dcookie(mm, s->eip, &offset);
45529
45530 if (cookie == INVALID_COOKIE) {
45531- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45532+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45533 return 0;
45534 }
45535
45536@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45537 /* ignore backtraces if failed to add a sample */
45538 if (state == sb_bt_start) {
45539 state = sb_bt_ignore;
45540- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45541+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45542 }
45543 }
45544 release_mm(mm);
45545diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45546index c0cc4e7..44d4e54 100644
45547--- a/drivers/oprofile/event_buffer.c
45548+++ b/drivers/oprofile/event_buffer.c
45549@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45550 }
45551
45552 if (buffer_pos == buffer_size) {
45553- atomic_inc(&oprofile_stats.event_lost_overflow);
45554+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45555 return;
45556 }
45557
45558diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45559index ed2c3ec..deda85a 100644
45560--- a/drivers/oprofile/oprof.c
45561+++ b/drivers/oprofile/oprof.c
45562@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45563 if (oprofile_ops.switch_events())
45564 return;
45565
45566- atomic_inc(&oprofile_stats.multiplex_counter);
45567+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45568 start_switch_worker();
45569 }
45570
45571diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45572index ee2cfce..7f8f699 100644
45573--- a/drivers/oprofile/oprofile_files.c
45574+++ b/drivers/oprofile/oprofile_files.c
45575@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45576
45577 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45578
45579-static ssize_t timeout_read(struct file *file, char __user *buf,
45580+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45581 size_t count, loff_t *offset)
45582 {
45583 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45584diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45585index 59659ce..6c860a0 100644
45586--- a/drivers/oprofile/oprofile_stats.c
45587+++ b/drivers/oprofile/oprofile_stats.c
45588@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45589 cpu_buf->sample_invalid_eip = 0;
45590 }
45591
45592- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45593- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45594- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45595- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45596- atomic_set(&oprofile_stats.multiplex_counter, 0);
45597+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45598+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45599+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45600+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45601+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45602 }
45603
45604
45605diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45606index 1fc622b..8c48fc3 100644
45607--- a/drivers/oprofile/oprofile_stats.h
45608+++ b/drivers/oprofile/oprofile_stats.h
45609@@ -13,11 +13,11 @@
45610 #include <linux/atomic.h>
45611
45612 struct oprofile_stat_struct {
45613- atomic_t sample_lost_no_mm;
45614- atomic_t sample_lost_no_mapping;
45615- atomic_t bt_lost_no_mapping;
45616- atomic_t event_lost_overflow;
45617- atomic_t multiplex_counter;
45618+ atomic_unchecked_t sample_lost_no_mm;
45619+ atomic_unchecked_t sample_lost_no_mapping;
45620+ atomic_unchecked_t bt_lost_no_mapping;
45621+ atomic_unchecked_t event_lost_overflow;
45622+ atomic_unchecked_t multiplex_counter;
45623 };
45624
45625 extern struct oprofile_stat_struct oprofile_stats;
45626diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45627index 3f49345..c750d0b 100644
45628--- a/drivers/oprofile/oprofilefs.c
45629+++ b/drivers/oprofile/oprofilefs.c
45630@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
45631
45632 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
45633 {
45634- atomic_t *val = file->private_data;
45635- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
45636+ atomic_unchecked_t *val = file->private_data;
45637+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
45638 }
45639
45640
45641@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
45642
45643
45644 int oprofilefs_create_ro_atomic(struct dentry *root,
45645- char const *name, atomic_t *val)
45646+ char const *name, atomic_unchecked_t *val)
45647 {
45648 return __oprofilefs_create_file(root, name,
45649 &atomic_ro_fops, 0444, val);
45650diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45651index 61be1d9..dec05d7 100644
45652--- a/drivers/oprofile/timer_int.c
45653+++ b/drivers/oprofile/timer_int.c
45654@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45655 return NOTIFY_OK;
45656 }
45657
45658-static struct notifier_block __refdata oprofile_cpu_notifier = {
45659+static struct notifier_block oprofile_cpu_notifier = {
45660 .notifier_call = oprofile_cpu_notify,
45661 };
45662
45663diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45664index 92ed045..62d39bd7 100644
45665--- a/drivers/parport/procfs.c
45666+++ b/drivers/parport/procfs.c
45667@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45668
45669 *ppos += len;
45670
45671- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45672+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45673 }
45674
45675 #ifdef CONFIG_PARPORT_1284
45676@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45677
45678 *ppos += len;
45679
45680- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45681+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45682 }
45683 #endif /* IEEE1284.3 support. */
45684
45685diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45686index 2f5786c..61ab4d1 100644
45687--- a/drivers/pci/hotplug/acpiphp_ibm.c
45688+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45689@@ -463,7 +463,9 @@ static int __init ibm_acpiphp_init(void)
45690 goto init_cleanup;
45691 }
45692
45693- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45694+ pax_open_kernel();
45695+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45696+ pax_close_kernel();
45697 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45698
45699 return retval;
45700diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45701index a6a71c4..c91097b 100644
45702--- a/drivers/pci/hotplug/cpcihp_generic.c
45703+++ b/drivers/pci/hotplug/cpcihp_generic.c
45704@@ -73,7 +73,6 @@ static u16 port;
45705 static unsigned int enum_bit;
45706 static u8 enum_mask;
45707
45708-static struct cpci_hp_controller_ops generic_hpc_ops;
45709 static struct cpci_hp_controller generic_hpc;
45710
45711 static int __init validate_parameters(void)
45712@@ -139,6 +138,10 @@ static int query_enum(void)
45713 return ((value & enum_mask) == enum_mask);
45714 }
45715
45716+static struct cpci_hp_controller_ops generic_hpc_ops = {
45717+ .query_enum = query_enum,
45718+};
45719+
45720 static int __init cpcihp_generic_init(void)
45721 {
45722 int status;
45723@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45724 pci_dev_put(dev);
45725
45726 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45727- generic_hpc_ops.query_enum = query_enum;
45728 generic_hpc.ops = &generic_hpc_ops;
45729
45730 status = cpci_hp_register_controller(&generic_hpc);
45731diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45732index 449b4bb..257e2e8 100644
45733--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45734+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45735@@ -59,7 +59,6 @@
45736 /* local variables */
45737 static bool debug;
45738 static bool poll;
45739-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45740 static struct cpci_hp_controller zt5550_hpc;
45741
45742 /* Primary cPCI bus bridge device */
45743@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45744 return 0;
45745 }
45746
45747+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45748+ .query_enum = zt5550_hc_query_enum,
45749+};
45750+
45751 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45752 {
45753 int status;
45754@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45755 dbg("returned from zt5550_hc_config");
45756
45757 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45758- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45759 zt5550_hpc.ops = &zt5550_hpc_ops;
45760 if(!poll) {
45761 zt5550_hpc.irq = hc_dev->irq;
45762 zt5550_hpc.irq_flags = IRQF_SHARED;
45763 zt5550_hpc.dev_id = hc_dev;
45764
45765- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45766- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45767- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45768+ pax_open_kernel();
45769+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45770+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45771+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45772+ pax_open_kernel();
45773 } else {
45774 info("using ENUM# polling mode");
45775 }
45776diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45777index 76ba8a1..20ca857 100644
45778--- a/drivers/pci/hotplug/cpqphp_nvram.c
45779+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45780@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45781
45782 void compaq_nvram_init (void __iomem *rom_start)
45783 {
45784+
45785+#ifndef CONFIG_PAX_KERNEXEC
45786 if (rom_start) {
45787 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45788 }
45789+#endif
45790+
45791 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45792
45793 /* initialize our int15 lock */
45794diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45795index ec20f74..c1d961e 100644
45796--- a/drivers/pci/hotplug/pci_hotplug_core.c
45797+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45798@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45799 return -EINVAL;
45800 }
45801
45802- slot->ops->owner = owner;
45803- slot->ops->mod_name = mod_name;
45804+ pax_open_kernel();
45805+ *(struct module **)&slot->ops->owner = owner;
45806+ *(const char **)&slot->ops->mod_name = mod_name;
45807+ pax_close_kernel();
45808
45809 mutex_lock(&pci_hp_mutex);
45810 /*
45811diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45812index f4a18f5..ff2463c 100644
45813--- a/drivers/pci/hotplug/pciehp_core.c
45814+++ b/drivers/pci/hotplug/pciehp_core.c
45815@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
45816 struct slot *slot = ctrl->slot;
45817 struct hotplug_slot *hotplug = NULL;
45818 struct hotplug_slot_info *info = NULL;
45819- struct hotplug_slot_ops *ops = NULL;
45820+ hotplug_slot_ops_no_const *ops = NULL;
45821 char name[SLOT_NAME_SIZE];
45822 int retval = -ENOMEM;
45823
45824diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45825index 7128cfd..a0640d6 100644
45826--- a/drivers/pci/pci-sysfs.c
45827+++ b/drivers/pci/pci-sysfs.c
45828@@ -1083,7 +1083,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45829 {
45830 /* allocate attribute structure, piggyback attribute name */
45831 int name_len = write_combine ? 13 : 10;
45832- struct bin_attribute *res_attr;
45833+ bin_attribute_no_const *res_attr;
45834 int retval;
45835
45836 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45837@@ -1268,7 +1268,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45838 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45839 {
45840 int retval;
45841- struct bin_attribute *attr;
45842+ bin_attribute_no_const *attr;
45843
45844 /* If the device has VPD, try to expose it in sysfs. */
45845 if (dev->vpd) {
45846@@ -1315,7 +1315,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45847 {
45848 int retval;
45849 int rom_size = 0;
45850- struct bin_attribute *attr;
45851+ bin_attribute_no_const *attr;
45852
45853 if (!sysfs_initialized)
45854 return -EACCES;
45855diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45856index 8a00c06..18a9715 100644
45857--- a/drivers/pci/pci.h
45858+++ b/drivers/pci/pci.h
45859@@ -95,7 +95,7 @@ struct pci_vpd_ops {
45860 struct pci_vpd {
45861 unsigned int len;
45862 const struct pci_vpd_ops *ops;
45863- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45864+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45865 };
45866
45867 int pci_vpd_pci22_init(struct pci_dev *dev);
45868diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45869index 403a443..034e050 100644
45870--- a/drivers/pci/pcie/aspm.c
45871+++ b/drivers/pci/pcie/aspm.c
45872@@ -27,9 +27,9 @@
45873 #define MODULE_PARAM_PREFIX "pcie_aspm."
45874
45875 /* Note: those are not register definitions */
45876-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45877-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45878-#define ASPM_STATE_L1 (4) /* L1 state */
45879+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45880+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45881+#define ASPM_STATE_L1 (4U) /* L1 state */
45882 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45883 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45884
45885diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45886index 7ef0f86..17b710f 100644
45887--- a/drivers/pci/probe.c
45888+++ b/drivers/pci/probe.c
45889@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45890 struct pci_bus_region region, inverted_region;
45891 bool bar_too_big = false, bar_disabled = false;
45892
45893- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45894+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45895
45896 /* No printks while decoding is disabled! */
45897 if (!dev->mmio_always_on) {
45898diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45899index cdc7836..528635c 100644
45900--- a/drivers/pci/proc.c
45901+++ b/drivers/pci/proc.c
45902@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45903 static int __init pci_proc_init(void)
45904 {
45905 struct pci_dev *dev = NULL;
45906+
45907+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45908+#ifdef CONFIG_GRKERNSEC_PROC_USER
45909+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45910+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45911+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45912+#endif
45913+#else
45914 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45915+#endif
45916 proc_create("devices", 0, proc_bus_pci_dir,
45917 &proc_bus_pci_dev_operations);
45918 proc_initialized = 1;
45919diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45920index 3e5b4497..dcdfb70 100644
45921--- a/drivers/platform/x86/chromeos_laptop.c
45922+++ b/drivers/platform/x86/chromeos_laptop.c
45923@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45924 return 0;
45925 }
45926
45927-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45928+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45929 {
45930 .ident = "Samsung Series 5 550 - Touchpad",
45931 .matches = {
45932diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45933index 62f8030..c7f2a45 100644
45934--- a/drivers/platform/x86/msi-laptop.c
45935+++ b/drivers/platform/x86/msi-laptop.c
45936@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45937
45938 if (!quirks->ec_read_only) {
45939 /* allow userland write sysfs file */
45940- dev_attr_bluetooth.store = store_bluetooth;
45941- dev_attr_wlan.store = store_wlan;
45942- dev_attr_threeg.store = store_threeg;
45943- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45944- dev_attr_wlan.attr.mode |= S_IWUSR;
45945- dev_attr_threeg.attr.mode |= S_IWUSR;
45946+ pax_open_kernel();
45947+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45948+ *(void **)&dev_attr_wlan.store = store_wlan;
45949+ *(void **)&dev_attr_threeg.store = store_threeg;
45950+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45951+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45952+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45953+ pax_close_kernel();
45954 }
45955
45956 /* disable hardware control by fn key */
45957diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
45958index 70222f2..8c8ce66 100644
45959--- a/drivers/platform/x86/msi-wmi.c
45960+++ b/drivers/platform/x86/msi-wmi.c
45961@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
45962 static void msi_wmi_notify(u32 value, void *context)
45963 {
45964 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
45965- static struct key_entry *key;
45966+ struct key_entry *key;
45967 union acpi_object *obj;
45968 acpi_status status;
45969
45970diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45971index 3484dd2..13ee730 100644
45972--- a/drivers/platform/x86/sony-laptop.c
45973+++ b/drivers/platform/x86/sony-laptop.c
45974@@ -2448,7 +2448,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45975 }
45976
45977 /* High speed charging function */
45978-static struct device_attribute *hsc_handle;
45979+static device_attribute_no_const *hsc_handle;
45980
45981 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45982 struct device_attribute *attr,
45983diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45984index 4e86e97..04d50d1 100644
45985--- a/drivers/platform/x86/thinkpad_acpi.c
45986+++ b/drivers/platform/x86/thinkpad_acpi.c
45987@@ -2091,7 +2091,7 @@ static int hotkey_mask_get(void)
45988 return 0;
45989 }
45990
45991-void static hotkey_mask_warn_incomplete_mask(void)
45992+static void hotkey_mask_warn_incomplete_mask(void)
45993 {
45994 /* log only what the user can fix... */
45995 const u32 wantedmask = hotkey_driver_mask &
45996@@ -2318,11 +2318,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45997 }
45998 }
45999
46000-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46001- struct tp_nvram_state *newn,
46002- const u32 event_mask)
46003-{
46004-
46005 #define TPACPI_COMPARE_KEY(__scancode, __member) \
46006 do { \
46007 if ((event_mask & (1 << __scancode)) && \
46008@@ -2336,36 +2331,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46009 tpacpi_hotkey_send_key(__scancode); \
46010 } while (0)
46011
46012- void issue_volchange(const unsigned int oldvol,
46013- const unsigned int newvol)
46014- {
46015- unsigned int i = oldvol;
46016+static void issue_volchange(const unsigned int oldvol,
46017+ const unsigned int newvol,
46018+ const u32 event_mask)
46019+{
46020+ unsigned int i = oldvol;
46021
46022- while (i > newvol) {
46023- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46024- i--;
46025- }
46026- while (i < newvol) {
46027- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46028- i++;
46029- }
46030+ while (i > newvol) {
46031+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46032+ i--;
46033 }
46034+ while (i < newvol) {
46035+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46036+ i++;
46037+ }
46038+}
46039
46040- void issue_brightnesschange(const unsigned int oldbrt,
46041- const unsigned int newbrt)
46042- {
46043- unsigned int i = oldbrt;
46044+static void issue_brightnesschange(const unsigned int oldbrt,
46045+ const unsigned int newbrt,
46046+ const u32 event_mask)
46047+{
46048+ unsigned int i = oldbrt;
46049
46050- while (i > newbrt) {
46051- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46052- i--;
46053- }
46054- while (i < newbrt) {
46055- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46056- i++;
46057- }
46058+ while (i > newbrt) {
46059+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46060+ i--;
46061+ }
46062+ while (i < newbrt) {
46063+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46064+ i++;
46065 }
46066+}
46067
46068+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46069+ struct tp_nvram_state *newn,
46070+ const u32 event_mask)
46071+{
46072 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
46073 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
46074 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
46075@@ -2399,7 +2400,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46076 oldn->volume_level != newn->volume_level) {
46077 /* recently muted, or repeated mute keypress, or
46078 * multiple presses ending in mute */
46079- issue_volchange(oldn->volume_level, newn->volume_level);
46080+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46081 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46082 }
46083 } else {
46084@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46085 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46086 }
46087 if (oldn->volume_level != newn->volume_level) {
46088- issue_volchange(oldn->volume_level, newn->volume_level);
46089+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46090 } else if (oldn->volume_toggle != newn->volume_toggle) {
46091 /* repeated vol up/down keypress at end of scale ? */
46092 if (newn->volume_level == 0)
46093@@ -2422,7 +2423,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46094 /* handle brightness */
46095 if (oldn->brightness_level != newn->brightness_level) {
46096 issue_brightnesschange(oldn->brightness_level,
46097- newn->brightness_level);
46098+ newn->brightness_level,
46099+ event_mask);
46100 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46101 /* repeated key presses that didn't change state */
46102 if (newn->brightness_level == 0)
46103@@ -2431,10 +2433,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46104 && !tp_features.bright_unkfw)
46105 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46106 }
46107+}
46108
46109 #undef TPACPI_COMPARE_KEY
46110 #undef TPACPI_MAY_SEND_KEY
46111-}
46112
46113 /*
46114 * Polling driver
46115diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46116index 769d265..a3a05ca 100644
46117--- a/drivers/pnp/pnpbios/bioscalls.c
46118+++ b/drivers/pnp/pnpbios/bioscalls.c
46119@@ -58,7 +58,7 @@ do { \
46120 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46121 } while(0)
46122
46123-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46124+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46125 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46126
46127 /*
46128@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46129
46130 cpu = get_cpu();
46131 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46132+
46133+ pax_open_kernel();
46134 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46135+ pax_close_kernel();
46136
46137 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46138 spin_lock_irqsave(&pnp_bios_lock, flags);
46139@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46140 :"memory");
46141 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46142
46143+ pax_open_kernel();
46144 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46145+ pax_close_kernel();
46146+
46147 put_cpu();
46148
46149 /* If we get here and this is set then the PnP BIOS faulted on us. */
46150@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46151 return status;
46152 }
46153
46154-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46155+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46156 {
46157 int i;
46158
46159@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46160 pnp_bios_callpoint.offset = header->fields.pm16offset;
46161 pnp_bios_callpoint.segment = PNP_CS16;
46162
46163+ pax_open_kernel();
46164+
46165 for_each_possible_cpu(i) {
46166 struct desc_struct *gdt = get_cpu_gdt_table(i);
46167 if (!gdt)
46168@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46169 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46170 (unsigned long)__va(header->fields.pm16dseg));
46171 }
46172+
46173+ pax_close_kernel();
46174 }
46175diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46176index d95e101..67f0c3f 100644
46177--- a/drivers/pnp/resource.c
46178+++ b/drivers/pnp/resource.c
46179@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46180 return 1;
46181
46182 /* check if the resource is valid */
46183- if (*irq < 0 || *irq > 15)
46184+ if (*irq > 15)
46185 return 0;
46186
46187 /* check if the resource is reserved */
46188@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46189 return 1;
46190
46191 /* check if the resource is valid */
46192- if (*dma < 0 || *dma == 4 || *dma > 7)
46193+ if (*dma == 4 || *dma > 7)
46194 return 0;
46195
46196 /* check if the resource is reserved */
46197diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46198index 0c52e2a..3421ab7 100644
46199--- a/drivers/power/pda_power.c
46200+++ b/drivers/power/pda_power.c
46201@@ -37,7 +37,11 @@ static int polling;
46202
46203 #if IS_ENABLED(CONFIG_USB_PHY)
46204 static struct usb_phy *transceiver;
46205-static struct notifier_block otg_nb;
46206+static int otg_handle_notification(struct notifier_block *nb,
46207+ unsigned long event, void *unused);
46208+static struct notifier_block otg_nb = {
46209+ .notifier_call = otg_handle_notification
46210+};
46211 #endif
46212
46213 static struct regulator *ac_draw;
46214@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46215
46216 #if IS_ENABLED(CONFIG_USB_PHY)
46217 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46218- otg_nb.notifier_call = otg_handle_notification;
46219 ret = usb_register_notifier(transceiver, &otg_nb);
46220 if (ret) {
46221 dev_err(dev, "failure to register otg notifier\n");
46222diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46223index cc439fd..8fa30df 100644
46224--- a/drivers/power/power_supply.h
46225+++ b/drivers/power/power_supply.h
46226@@ -16,12 +16,12 @@ struct power_supply;
46227
46228 #ifdef CONFIG_SYSFS
46229
46230-extern void power_supply_init_attrs(struct device_type *dev_type);
46231+extern void power_supply_init_attrs(void);
46232 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46233
46234 #else
46235
46236-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46237+static inline void power_supply_init_attrs(void) {}
46238 #define power_supply_uevent NULL
46239
46240 #endif /* CONFIG_SYSFS */
46241diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46242index 00e6672..2642c08 100644
46243--- a/drivers/power/power_supply_core.c
46244+++ b/drivers/power/power_supply_core.c
46245@@ -24,7 +24,10 @@
46246 struct class *power_supply_class;
46247 EXPORT_SYMBOL_GPL(power_supply_class);
46248
46249-static struct device_type power_supply_dev_type;
46250+extern const struct attribute_group *power_supply_attr_groups[];
46251+static struct device_type power_supply_dev_type = {
46252+ .groups = power_supply_attr_groups,
46253+};
46254
46255 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46256 struct power_supply *supply)
46257@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
46258 return PTR_ERR(power_supply_class);
46259
46260 power_supply_class->dev_uevent = power_supply_uevent;
46261- power_supply_init_attrs(&power_supply_dev_type);
46262+ power_supply_init_attrs();
46263
46264 return 0;
46265 }
46266diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46267index 44420d1..967126e 100644
46268--- a/drivers/power/power_supply_sysfs.c
46269+++ b/drivers/power/power_supply_sysfs.c
46270@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46271 .is_visible = power_supply_attr_is_visible,
46272 };
46273
46274-static const struct attribute_group *power_supply_attr_groups[] = {
46275+const struct attribute_group *power_supply_attr_groups[] = {
46276 &power_supply_attr_group,
46277 NULL,
46278 };
46279
46280-void power_supply_init_attrs(struct device_type *dev_type)
46281+void power_supply_init_attrs(void)
46282 {
46283 int i;
46284
46285- dev_type->groups = power_supply_attr_groups;
46286-
46287 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46288 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46289 }
46290diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46291index a01b8b3..37c2afe 100644
46292--- a/drivers/regulator/core.c
46293+++ b/drivers/regulator/core.c
46294@@ -3307,7 +3307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46295 {
46296 const struct regulation_constraints *constraints = NULL;
46297 const struct regulator_init_data *init_data;
46298- static atomic_t regulator_no = ATOMIC_INIT(0);
46299+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46300 struct regulator_dev *rdev;
46301 struct device *dev;
46302 int ret, i;
46303@@ -3377,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46304 rdev->dev.of_node = config->of_node;
46305 rdev->dev.parent = dev;
46306 dev_set_name(&rdev->dev, "regulator.%d",
46307- atomic_inc_return(&regulator_no) - 1);
46308+ atomic_inc_return_unchecked(&regulator_no) - 1);
46309 ret = device_register(&rdev->dev);
46310 if (ret != 0) {
46311 put_device(&rdev->dev);
46312diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46313index 144bcac..d20e7db 100644
46314--- a/drivers/regulator/max8660.c
46315+++ b/drivers/regulator/max8660.c
46316@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
46317 max8660->shadow_regs[MAX8660_OVER1] = 5;
46318 } else {
46319 /* Otherwise devices can be toggled via software */
46320- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46321- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46322+ pax_open_kernel();
46323+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46324+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46325+ pax_close_kernel();
46326 }
46327
46328 /*
46329diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46330index 5b77ab7..a62f061 100644
46331--- a/drivers/regulator/max8973-regulator.c
46332+++ b/drivers/regulator/max8973-regulator.c
46333@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46334 if (!pdata || !pdata->enable_ext_control) {
46335 max->desc.enable_reg = MAX8973_VOUT;
46336 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46337- max->ops.enable = regulator_enable_regmap;
46338- max->ops.disable = regulator_disable_regmap;
46339- max->ops.is_enabled = regulator_is_enabled_regmap;
46340+ pax_open_kernel();
46341+ *(void **)&max->ops.enable = regulator_enable_regmap;
46342+ *(void **)&max->ops.disable = regulator_disable_regmap;
46343+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46344+ pax_close_kernel();
46345 }
46346
46347 if (pdata) {
46348diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46349index 1037e07..e64dea1 100644
46350--- a/drivers/regulator/mc13892-regulator.c
46351+++ b/drivers/regulator/mc13892-regulator.c
46352@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46353 }
46354 mc13xxx_unlock(mc13892);
46355
46356- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46357+ pax_open_kernel();
46358+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46359 = mc13892_vcam_set_mode;
46360- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46361+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46362 = mc13892_vcam_get_mode;
46363+ pax_close_kernel();
46364
46365 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46366 ARRAY_SIZE(mc13892_regulators));
46367diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46368index 24e733c..bfbaa3e 100644
46369--- a/drivers/rtc/rtc-cmos.c
46370+++ b/drivers/rtc/rtc-cmos.c
46371@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46372 hpet_rtc_timer_init();
46373
46374 /* export at least the first block of NVRAM */
46375- nvram.size = address_space - NVRAM_OFFSET;
46376+ pax_open_kernel();
46377+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46378+ pax_close_kernel();
46379 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46380 if (retval < 0) {
46381 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46382diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46383index d049393..bb20be0 100644
46384--- a/drivers/rtc/rtc-dev.c
46385+++ b/drivers/rtc/rtc-dev.c
46386@@ -16,6 +16,7 @@
46387 #include <linux/module.h>
46388 #include <linux/rtc.h>
46389 #include <linux/sched.h>
46390+#include <linux/grsecurity.h>
46391 #include "rtc-core.h"
46392
46393 static dev_t rtc_devt;
46394@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46395 if (copy_from_user(&tm, uarg, sizeof(tm)))
46396 return -EFAULT;
46397
46398+ gr_log_timechange();
46399+
46400 return rtc_set_time(rtc, &tm);
46401
46402 case RTC_PIE_ON:
46403diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46404index ca18fd1..055e42d 100644
46405--- a/drivers/rtc/rtc-ds1307.c
46406+++ b/drivers/rtc/rtc-ds1307.c
46407@@ -107,7 +107,7 @@ struct ds1307 {
46408 u8 offset; /* register's offset */
46409 u8 regs[11];
46410 u16 nvram_offset;
46411- struct bin_attribute *nvram;
46412+ bin_attribute_no_const *nvram;
46413 enum ds_type type;
46414 unsigned long flags;
46415 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46416diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46417index fcb0329..d77b7f2 100644
46418--- a/drivers/rtc/rtc-m48t59.c
46419+++ b/drivers/rtc/rtc-m48t59.c
46420@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46421 if (IS_ERR(m48t59->rtc))
46422 return PTR_ERR(m48t59->rtc);
46423
46424- m48t59_nvram_attr.size = pdata->offset;
46425+ pax_open_kernel();
46426+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46427+ pax_close_kernel();
46428
46429 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46430 if (ret)
46431diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
46432index 14b5f8d..cc9bd26 100644
46433--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
46434+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
46435@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
46436 for (bit = 0; bit < 8; bit++) {
46437
46438 if ((pci_status[i] & (0x1 << bit)) != 0) {
46439- static const char *s;
46440+ const char *s;
46441
46442 s = pci_status_strings[bit];
46443 if (i == 7/*TARG*/ && bit == 3)
46444@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
46445
46446 for (bit = 0; bit < 8; bit++) {
46447
46448- if ((split_status[i] & (0x1 << bit)) != 0) {
46449- static const char *s;
46450-
46451- s = split_status_strings[bit];
46452- printk(s, ahd_name(ahd),
46453+ if ((split_status[i] & (0x1 << bit)) != 0)
46454+ printk(split_status_strings[bit], ahd_name(ahd),
46455 split_status_source[i]);
46456- }
46457
46458 if (i > 1)
46459 continue;
46460
46461- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
46462- static const char *s;
46463-
46464- s = split_status_strings[bit];
46465- printk(s, ahd_name(ahd), "SG");
46466- }
46467+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
46468+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
46469 }
46470 }
46471 /*
46472diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46473index e693af6..2e525b6 100644
46474--- a/drivers/scsi/bfa/bfa_fcpim.h
46475+++ b/drivers/scsi/bfa/bfa_fcpim.h
46476@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46477
46478 struct bfa_itn_s {
46479 bfa_isr_func_t isr;
46480-};
46481+} __no_const;
46482
46483 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46484 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46485diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46486index 90814fe..4384138 100644
46487--- a/drivers/scsi/bfa/bfa_ioc.h
46488+++ b/drivers/scsi/bfa/bfa_ioc.h
46489@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46490 bfa_ioc_disable_cbfn_t disable_cbfn;
46491 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46492 bfa_ioc_reset_cbfn_t reset_cbfn;
46493-};
46494+} __no_const;
46495
46496 /*
46497 * IOC event notification mechanism.
46498@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46499 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46500 enum bfi_ioc_state fwstate);
46501 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46502-};
46503+} __no_const;
46504
46505 /*
46506 * Queue element to wait for room in request queue. FIFO order is
46507diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46508index c9382d6..6619864 100644
46509--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46510+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46511@@ -33,8 +33,8 @@
46512 */
46513 #include "libfcoe.h"
46514
46515-static atomic_t ctlr_num;
46516-static atomic_t fcf_num;
46517+static atomic_unchecked_t ctlr_num;
46518+static atomic_unchecked_t fcf_num;
46519
46520 /*
46521 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46522@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46523 if (!ctlr)
46524 goto out;
46525
46526- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46527+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46528 ctlr->f = f;
46529 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46530 INIT_LIST_HEAD(&ctlr->fcfs);
46531@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46532 fcf->dev.parent = &ctlr->dev;
46533 fcf->dev.bus = &fcoe_bus_type;
46534 fcf->dev.type = &fcoe_fcf_device_type;
46535- fcf->id = atomic_inc_return(&fcf_num) - 1;
46536+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46537 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46538
46539 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46540@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46541 {
46542 int error;
46543
46544- atomic_set(&ctlr_num, 0);
46545- atomic_set(&fcf_num, 0);
46546+ atomic_set_unchecked(&ctlr_num, 0);
46547+ atomic_set_unchecked(&fcf_num, 0);
46548
46549 error = bus_register(&fcoe_bus_type);
46550 if (error)
46551diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46552index 3cafe0d..f1e87f8 100644
46553--- a/drivers/scsi/hosts.c
46554+++ b/drivers/scsi/hosts.c
46555@@ -42,7 +42,7 @@
46556 #include "scsi_logging.h"
46557
46558
46559-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46560+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46561
46562
46563 static void scsi_host_cls_release(struct device *dev)
46564@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46565 * subtract one because we increment first then return, but we need to
46566 * know what the next host number was before increment
46567 */
46568- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46569+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46570 shost->dma_channel = 0xff;
46571
46572 /* These three are default values which can be overridden */
46573diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46574index 0eb0940..3ca9b79 100644
46575--- a/drivers/scsi/hpsa.c
46576+++ b/drivers/scsi/hpsa.c
46577@@ -579,7 +579,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46578 unsigned long flags;
46579
46580 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46581- return h->access.command_completed(h, q);
46582+ return h->access->command_completed(h, q);
46583
46584 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46585 a = rq->head[rq->current_entry];
46586@@ -3445,7 +3445,7 @@ static void start_io(struct ctlr_info *h)
46587 while (!list_empty(&h->reqQ)) {
46588 c = list_entry(h->reqQ.next, struct CommandList, list);
46589 /* can't do anything if fifo is full */
46590- if ((h->access.fifo_full(h))) {
46591+ if ((h->access->fifo_full(h))) {
46592 dev_warn(&h->pdev->dev, "fifo full\n");
46593 break;
46594 }
46595@@ -3467,7 +3467,7 @@ static void start_io(struct ctlr_info *h)
46596
46597 /* Tell the controller execute command */
46598 spin_unlock_irqrestore(&h->lock, flags);
46599- h->access.submit_command(h, c);
46600+ h->access->submit_command(h, c);
46601 spin_lock_irqsave(&h->lock, flags);
46602 }
46603 spin_unlock_irqrestore(&h->lock, flags);
46604@@ -3475,17 +3475,17 @@ static void start_io(struct ctlr_info *h)
46605
46606 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46607 {
46608- return h->access.command_completed(h, q);
46609+ return h->access->command_completed(h, q);
46610 }
46611
46612 static inline bool interrupt_pending(struct ctlr_info *h)
46613 {
46614- return h->access.intr_pending(h);
46615+ return h->access->intr_pending(h);
46616 }
46617
46618 static inline long interrupt_not_for_us(struct ctlr_info *h)
46619 {
46620- return (h->access.intr_pending(h) == 0) ||
46621+ return (h->access->intr_pending(h) == 0) ||
46622 (h->interrupts_enabled == 0);
46623 }
46624
46625@@ -4387,7 +4387,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46626 if (prod_index < 0)
46627 return -ENODEV;
46628 h->product_name = products[prod_index].product_name;
46629- h->access = *(products[prod_index].access);
46630+ h->access = products[prod_index].access;
46631
46632 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46633 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46634@@ -4669,7 +4669,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46635
46636 assert_spin_locked(&lockup_detector_lock);
46637 remove_ctlr_from_lockup_detector_list(h);
46638- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46639+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46640 spin_lock_irqsave(&h->lock, flags);
46641 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46642 spin_unlock_irqrestore(&h->lock, flags);
46643@@ -4846,7 +4846,7 @@ reinit_after_soft_reset:
46644 }
46645
46646 /* make sure the board interrupts are off */
46647- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46648+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46649
46650 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46651 goto clean2;
46652@@ -4880,7 +4880,7 @@ reinit_after_soft_reset:
46653 * fake ones to scoop up any residual completions.
46654 */
46655 spin_lock_irqsave(&h->lock, flags);
46656- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46657+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46658 spin_unlock_irqrestore(&h->lock, flags);
46659 free_irqs(h);
46660 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46661@@ -4899,9 +4899,9 @@ reinit_after_soft_reset:
46662 dev_info(&h->pdev->dev, "Board READY.\n");
46663 dev_info(&h->pdev->dev,
46664 "Waiting for stale completions to drain.\n");
46665- h->access.set_intr_mask(h, HPSA_INTR_ON);
46666+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46667 msleep(10000);
46668- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46669+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46670
46671 rc = controller_reset_failed(h->cfgtable);
46672 if (rc)
46673@@ -4922,7 +4922,7 @@ reinit_after_soft_reset:
46674 }
46675
46676 /* Turn the interrupts on so we can service requests */
46677- h->access.set_intr_mask(h, HPSA_INTR_ON);
46678+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46679
46680 hpsa_hba_inquiry(h);
46681 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46682@@ -4977,7 +4977,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46683 * To write all data in the battery backed cache to disks
46684 */
46685 hpsa_flush_cache(h);
46686- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46687+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46688 hpsa_free_irqs_and_disable_msix(h);
46689 }
46690
46691@@ -5145,7 +5145,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46692 return;
46693 }
46694 /* Change the access methods to the performant access methods */
46695- h->access = SA5_performant_access;
46696+ h->access = &SA5_performant_access;
46697 h->transMethod = CFGTBL_Trans_Performant;
46698 }
46699
46700diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46701index bc85e72..ae04a39 100644
46702--- a/drivers/scsi/hpsa.h
46703+++ b/drivers/scsi/hpsa.h
46704@@ -79,7 +79,7 @@ struct ctlr_info {
46705 unsigned int msix_vector;
46706 unsigned int msi_vector;
46707 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46708- struct access_method access;
46709+ struct access_method *access;
46710
46711 /* queue and queue Info */
46712 struct list_head reqQ;
46713diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46714index 5879929..32b241d 100644
46715--- a/drivers/scsi/libfc/fc_exch.c
46716+++ b/drivers/scsi/libfc/fc_exch.c
46717@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46718 u16 pool_max_index;
46719
46720 struct {
46721- atomic_t no_free_exch;
46722- atomic_t no_free_exch_xid;
46723- atomic_t xid_not_found;
46724- atomic_t xid_busy;
46725- atomic_t seq_not_found;
46726- atomic_t non_bls_resp;
46727+ atomic_unchecked_t no_free_exch;
46728+ atomic_unchecked_t no_free_exch_xid;
46729+ atomic_unchecked_t xid_not_found;
46730+ atomic_unchecked_t xid_busy;
46731+ atomic_unchecked_t seq_not_found;
46732+ atomic_unchecked_t non_bls_resp;
46733 } stats;
46734 };
46735
46736@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46737 /* allocate memory for exchange */
46738 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46739 if (!ep) {
46740- atomic_inc(&mp->stats.no_free_exch);
46741+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46742 goto out;
46743 }
46744 memset(ep, 0, sizeof(*ep));
46745@@ -797,7 +797,7 @@ out:
46746 return ep;
46747 err:
46748 spin_unlock_bh(&pool->lock);
46749- atomic_inc(&mp->stats.no_free_exch_xid);
46750+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46751 mempool_free(ep, mp->ep_pool);
46752 return NULL;
46753 }
46754@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46755 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46756 ep = fc_exch_find(mp, xid);
46757 if (!ep) {
46758- atomic_inc(&mp->stats.xid_not_found);
46759+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46760 reject = FC_RJT_OX_ID;
46761 goto out;
46762 }
46763@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46764 ep = fc_exch_find(mp, xid);
46765 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46766 if (ep) {
46767- atomic_inc(&mp->stats.xid_busy);
46768+ atomic_inc_unchecked(&mp->stats.xid_busy);
46769 reject = FC_RJT_RX_ID;
46770 goto rel;
46771 }
46772@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46773 }
46774 xid = ep->xid; /* get our XID */
46775 } else if (!ep) {
46776- atomic_inc(&mp->stats.xid_not_found);
46777+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46778 reject = FC_RJT_RX_ID; /* XID not found */
46779 goto out;
46780 }
46781@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46782 } else {
46783 sp = &ep->seq;
46784 if (sp->id != fh->fh_seq_id) {
46785- atomic_inc(&mp->stats.seq_not_found);
46786+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46787 if (f_ctl & FC_FC_END_SEQ) {
46788 /*
46789 * Update sequence_id based on incoming last
46790@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46791
46792 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46793 if (!ep) {
46794- atomic_inc(&mp->stats.xid_not_found);
46795+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46796 goto out;
46797 }
46798 if (ep->esb_stat & ESB_ST_COMPLETE) {
46799- atomic_inc(&mp->stats.xid_not_found);
46800+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46801 goto rel;
46802 }
46803 if (ep->rxid == FC_XID_UNKNOWN)
46804 ep->rxid = ntohs(fh->fh_rx_id);
46805 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46806- atomic_inc(&mp->stats.xid_not_found);
46807+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46808 goto rel;
46809 }
46810 if (ep->did != ntoh24(fh->fh_s_id) &&
46811 ep->did != FC_FID_FLOGI) {
46812- atomic_inc(&mp->stats.xid_not_found);
46813+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46814 goto rel;
46815 }
46816 sof = fr_sof(fp);
46817@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46818 sp->ssb_stat |= SSB_ST_RESP;
46819 sp->id = fh->fh_seq_id;
46820 } else if (sp->id != fh->fh_seq_id) {
46821- atomic_inc(&mp->stats.seq_not_found);
46822+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46823 goto rel;
46824 }
46825
46826@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46827 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46828
46829 if (!sp)
46830- atomic_inc(&mp->stats.xid_not_found);
46831+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46832 else
46833- atomic_inc(&mp->stats.non_bls_resp);
46834+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46835
46836 fc_frame_free(fp);
46837 }
46838@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46839
46840 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46841 mp = ema->mp;
46842- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46843+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46844 st->fc_no_free_exch_xid +=
46845- atomic_read(&mp->stats.no_free_exch_xid);
46846- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46847- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46848- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46849- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46850+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46851+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46852+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46853+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46854+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46855 }
46856 }
46857 EXPORT_SYMBOL(fc_exch_update_stats);
46858diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46859index d289583..b745eec 100644
46860--- a/drivers/scsi/libsas/sas_ata.c
46861+++ b/drivers/scsi/libsas/sas_ata.c
46862@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46863 .postreset = ata_std_postreset,
46864 .error_handler = ata_std_error_handler,
46865 .post_internal_cmd = sas_ata_post_internal,
46866- .qc_defer = ata_std_qc_defer,
46867+ .qc_defer = ata_std_qc_defer,
46868 .qc_prep = ata_noop_qc_prep,
46869 .qc_issue = sas_ata_qc_issue,
46870 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46871diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46872index 4e1b75c..0bbdfa9 100644
46873--- a/drivers/scsi/lpfc/lpfc.h
46874+++ b/drivers/scsi/lpfc/lpfc.h
46875@@ -432,7 +432,7 @@ struct lpfc_vport {
46876 struct dentry *debug_nodelist;
46877 struct dentry *vport_debugfs_root;
46878 struct lpfc_debugfs_trc *disc_trc;
46879- atomic_t disc_trc_cnt;
46880+ atomic_unchecked_t disc_trc_cnt;
46881 #endif
46882 uint8_t stat_data_enabled;
46883 uint8_t stat_data_blocked;
46884@@ -865,8 +865,8 @@ struct lpfc_hba {
46885 struct timer_list fabric_block_timer;
46886 unsigned long bit_flags;
46887 #define FABRIC_COMANDS_BLOCKED 0
46888- atomic_t num_rsrc_err;
46889- atomic_t num_cmd_success;
46890+ atomic_unchecked_t num_rsrc_err;
46891+ atomic_unchecked_t num_cmd_success;
46892 unsigned long last_rsrc_error_time;
46893 unsigned long last_ramp_down_time;
46894 unsigned long last_ramp_up_time;
46895@@ -902,7 +902,7 @@ struct lpfc_hba {
46896
46897 struct dentry *debug_slow_ring_trc;
46898 struct lpfc_debugfs_trc *slow_ring_trc;
46899- atomic_t slow_ring_trc_cnt;
46900+ atomic_unchecked_t slow_ring_trc_cnt;
46901 /* iDiag debugfs sub-directory */
46902 struct dentry *idiag_root;
46903 struct dentry *idiag_pci_cfg;
46904diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46905index 60084e6..0e2e700 100644
46906--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46907+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46908@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46909
46910 #include <linux/debugfs.h>
46911
46912-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46913+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46914 static unsigned long lpfc_debugfs_start_time = 0L;
46915
46916 /* iDiag */
46917@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46918 lpfc_debugfs_enable = 0;
46919
46920 len = 0;
46921- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46922+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46923 (lpfc_debugfs_max_disc_trc - 1);
46924 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46925 dtp = vport->disc_trc + i;
46926@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46927 lpfc_debugfs_enable = 0;
46928
46929 len = 0;
46930- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46931+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46932 (lpfc_debugfs_max_slow_ring_trc - 1);
46933 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46934 dtp = phba->slow_ring_trc + i;
46935@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46936 !vport || !vport->disc_trc)
46937 return;
46938
46939- index = atomic_inc_return(&vport->disc_trc_cnt) &
46940+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46941 (lpfc_debugfs_max_disc_trc - 1);
46942 dtp = vport->disc_trc + index;
46943 dtp->fmt = fmt;
46944 dtp->data1 = data1;
46945 dtp->data2 = data2;
46946 dtp->data3 = data3;
46947- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46948+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46949 dtp->jif = jiffies;
46950 #endif
46951 return;
46952@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46953 !phba || !phba->slow_ring_trc)
46954 return;
46955
46956- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46957+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46958 (lpfc_debugfs_max_slow_ring_trc - 1);
46959 dtp = phba->slow_ring_trc + index;
46960 dtp->fmt = fmt;
46961 dtp->data1 = data1;
46962 dtp->data2 = data2;
46963 dtp->data3 = data3;
46964- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46965+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46966 dtp->jif = jiffies;
46967 #endif
46968 return;
46969@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46970 "slow_ring buffer\n");
46971 goto debug_failed;
46972 }
46973- atomic_set(&phba->slow_ring_trc_cnt, 0);
46974+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46975 memset(phba->slow_ring_trc, 0,
46976 (sizeof(struct lpfc_debugfs_trc) *
46977 lpfc_debugfs_max_slow_ring_trc));
46978@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46979 "buffer\n");
46980 goto debug_failed;
46981 }
46982- atomic_set(&vport->disc_trc_cnt, 0);
46983+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46984
46985 snprintf(name, sizeof(name), "discovery_trace");
46986 vport->debug_disc_trc =
46987diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46988index 647f5bf..d0068b9 100644
46989--- a/drivers/scsi/lpfc/lpfc_init.c
46990+++ b/drivers/scsi/lpfc/lpfc_init.c
46991@@ -10952,8 +10952,10 @@ lpfc_init(void)
46992 "misc_register returned with status %d", error);
46993
46994 if (lpfc_enable_npiv) {
46995- lpfc_transport_functions.vport_create = lpfc_vport_create;
46996- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46997+ pax_open_kernel();
46998+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46999+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
47000+ pax_close_kernel();
47001 }
47002 lpfc_transport_template =
47003 fc_attach_transport(&lpfc_transport_functions);
47004diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
47005index c913e8c..d34a119 100644
47006--- a/drivers/scsi/lpfc/lpfc_scsi.c
47007+++ b/drivers/scsi/lpfc/lpfc_scsi.c
47008@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
47009 uint32_t evt_posted;
47010
47011 spin_lock_irqsave(&phba->hbalock, flags);
47012- atomic_inc(&phba->num_rsrc_err);
47013+ atomic_inc_unchecked(&phba->num_rsrc_err);
47014 phba->last_rsrc_error_time = jiffies;
47015
47016 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
47017@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
47018 unsigned long flags;
47019 struct lpfc_hba *phba = vport->phba;
47020 uint32_t evt_posted;
47021- atomic_inc(&phba->num_cmd_success);
47022+ atomic_inc_unchecked(&phba->num_cmd_success);
47023
47024 if (vport->cfg_lun_queue_depth <= queue_depth)
47025 return;
47026@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
47027 unsigned long num_rsrc_err, num_cmd_success;
47028 int i;
47029
47030- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
47031- num_cmd_success = atomic_read(&phba->num_cmd_success);
47032+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
47033+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
47034
47035 /*
47036 * The error and success command counters are global per
47037@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
47038 }
47039 }
47040 lpfc_destroy_vport_work_array(phba, vports);
47041- atomic_set(&phba->num_rsrc_err, 0);
47042- atomic_set(&phba->num_cmd_success, 0);
47043+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
47044+ atomic_set_unchecked(&phba->num_cmd_success, 0);
47045 }
47046
47047 /**
47048@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
47049 }
47050 }
47051 lpfc_destroy_vport_work_array(phba, vports);
47052- atomic_set(&phba->num_rsrc_err, 0);
47053- atomic_set(&phba->num_cmd_success, 0);
47054+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
47055+ atomic_set_unchecked(&phba->num_cmd_success, 0);
47056 }
47057
47058 /**
47059diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
47060index 7f0af4f..193ac3e 100644
47061--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
47062+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
47063@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
47064 {
47065 struct scsi_device *sdev = to_scsi_device(dev);
47066 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
47067- static struct _raid_device *raid_device;
47068+ struct _raid_device *raid_device;
47069 unsigned long flags;
47070 Mpi2RaidVolPage0_t vol_pg0;
47071 Mpi2ConfigReply_t mpi_reply;
47072@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
47073 {
47074 struct scsi_device *sdev = to_scsi_device(dev);
47075 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
47076- static struct _raid_device *raid_device;
47077+ struct _raid_device *raid_device;
47078 unsigned long flags;
47079 Mpi2RaidVolPage0_t vol_pg0;
47080 Mpi2ConfigReply_t mpi_reply;
47081@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
47082 struct fw_event_work *fw_event)
47083 {
47084 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
47085- static struct _raid_device *raid_device;
47086+ struct _raid_device *raid_device;
47087 unsigned long flags;
47088 u16 handle;
47089
47090@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
47091 u64 sas_address;
47092 struct _sas_device *sas_device;
47093 struct _sas_node *expander_device;
47094- static struct _raid_device *raid_device;
47095+ struct _raid_device *raid_device;
47096 u8 retry_count;
47097 unsigned long flags;
47098
47099diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
47100index a38f71b..f3bc572 100644
47101--- a/drivers/scsi/pmcraid.c
47102+++ b/drivers/scsi/pmcraid.c
47103@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
47104 res->scsi_dev = scsi_dev;
47105 scsi_dev->hostdata = res;
47106 res->change_detected = 0;
47107- atomic_set(&res->read_failures, 0);
47108- atomic_set(&res->write_failures, 0);
47109+ atomic_set_unchecked(&res->read_failures, 0);
47110+ atomic_set_unchecked(&res->write_failures, 0);
47111 rc = 0;
47112 }
47113 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
47114@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
47115
47116 /* If this was a SCSI read/write command keep count of errors */
47117 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
47118- atomic_inc(&res->read_failures);
47119+ atomic_inc_unchecked(&res->read_failures);
47120 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
47121- atomic_inc(&res->write_failures);
47122+ atomic_inc_unchecked(&res->write_failures);
47123
47124 if (!RES_IS_GSCSI(res->cfg_entry) &&
47125 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
47126@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
47127 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47128 * hrrq_id assigned here in queuecommand
47129 */
47130- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47131+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47132 pinstance->num_hrrq;
47133 cmd->cmd_done = pmcraid_io_done;
47134
47135@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
47136 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47137 * hrrq_id assigned here in queuecommand
47138 */
47139- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47140+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47141 pinstance->num_hrrq;
47142
47143 if (request_size) {
47144@@ -4484,7 +4484,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
47145
47146 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
47147 /* add resources only after host is added into system */
47148- if (!atomic_read(&pinstance->expose_resources))
47149+ if (!atomic_read_unchecked(&pinstance->expose_resources))
47150 return;
47151
47152 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
47153@@ -5311,8 +5311,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
47154 init_waitqueue_head(&pinstance->reset_wait_q);
47155
47156 atomic_set(&pinstance->outstanding_cmds, 0);
47157- atomic_set(&pinstance->last_message_id, 0);
47158- atomic_set(&pinstance->expose_resources, 0);
47159+ atomic_set_unchecked(&pinstance->last_message_id, 0);
47160+ atomic_set_unchecked(&pinstance->expose_resources, 0);
47161
47162 INIT_LIST_HEAD(&pinstance->free_res_q);
47163 INIT_LIST_HEAD(&pinstance->used_res_q);
47164@@ -6025,7 +6025,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47165 /* Schedule worker thread to handle CCN and take care of adding and
47166 * removing devices to OS
47167 */
47168- atomic_set(&pinstance->expose_resources, 1);
47169+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47170 schedule_work(&pinstance->worker_q);
47171 return rc;
47172
47173diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47174index e1d150f..6c6df44 100644
47175--- a/drivers/scsi/pmcraid.h
47176+++ b/drivers/scsi/pmcraid.h
47177@@ -748,7 +748,7 @@ struct pmcraid_instance {
47178 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47179
47180 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47181- atomic_t last_message_id;
47182+ atomic_unchecked_t last_message_id;
47183
47184 /* configuration table */
47185 struct pmcraid_config_table *cfg_table;
47186@@ -777,7 +777,7 @@ struct pmcraid_instance {
47187 atomic_t outstanding_cmds;
47188
47189 /* should add/delete resources to mid-layer now ?*/
47190- atomic_t expose_resources;
47191+ atomic_unchecked_t expose_resources;
47192
47193
47194
47195@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47196 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47197 };
47198 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47199- atomic_t read_failures; /* count of failed READ commands */
47200- atomic_t write_failures; /* count of failed WRITE commands */
47201+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47202+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47203
47204 /* To indicate add/delete/modify during CCN */
47205 u8 change_detected;
47206diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47207index 5f174b8..98d32b0 100644
47208--- a/drivers/scsi/qla2xxx/qla_attr.c
47209+++ b/drivers/scsi/qla2xxx/qla_attr.c
47210@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47211 return 0;
47212 }
47213
47214-struct fc_function_template qla2xxx_transport_functions = {
47215+fc_function_template_no_const qla2xxx_transport_functions = {
47216
47217 .show_host_node_name = 1,
47218 .show_host_port_name = 1,
47219@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47220 .bsg_timeout = qla24xx_bsg_timeout,
47221 };
47222
47223-struct fc_function_template qla2xxx_transport_vport_functions = {
47224+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47225
47226 .show_host_node_name = 1,
47227 .show_host_port_name = 1,
47228diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47229index 4446bf5..9a3574d 100644
47230--- a/drivers/scsi/qla2xxx/qla_gbl.h
47231+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47232@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47233 struct device_attribute;
47234 extern struct device_attribute *qla2x00_host_attrs[];
47235 struct fc_function_template;
47236-extern struct fc_function_template qla2xxx_transport_functions;
47237-extern struct fc_function_template qla2xxx_transport_vport_functions;
47238+extern fc_function_template_no_const qla2xxx_transport_functions;
47239+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47240 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47241 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47242 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47243diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47244index 9f01bbb..5e1dcee 100644
47245--- a/drivers/scsi/qla2xxx/qla_os.c
47246+++ b/drivers/scsi/qla2xxx/qla_os.c
47247@@ -1572,8 +1572,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47248 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47249 /* Ok, a 64bit DMA mask is applicable. */
47250 ha->flags.enable_64bit_addressing = 1;
47251- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47252- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47253+ pax_open_kernel();
47254+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47255+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47256+ pax_close_kernel();
47257 return;
47258 }
47259 }
47260diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47261index 41327d4..feb03d479 100644
47262--- a/drivers/scsi/qla4xxx/ql4_def.h
47263+++ b/drivers/scsi/qla4xxx/ql4_def.h
47264@@ -296,7 +296,7 @@ struct ddb_entry {
47265 * (4000 only) */
47266 atomic_t relogin_timer; /* Max Time to wait for
47267 * relogin to complete */
47268- atomic_t relogin_retry_count; /* Num of times relogin has been
47269+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47270 * retried */
47271 uint32_t default_time2wait; /* Default Min time between
47272 * relogins (+aens) */
47273diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47274index f8a0a26..ec03cee 100644
47275--- a/drivers/scsi/qla4xxx/ql4_os.c
47276+++ b/drivers/scsi/qla4xxx/ql4_os.c
47277@@ -3066,12 +3066,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47278 */
47279 if (!iscsi_is_session_online(cls_sess)) {
47280 /* Reset retry relogin timer */
47281- atomic_inc(&ddb_entry->relogin_retry_count);
47282+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47283 DEBUG2(ql4_printk(KERN_INFO, ha,
47284 "%s: index[%d] relogin timed out-retrying"
47285 " relogin (%d), retry (%d)\n", __func__,
47286 ddb_entry->fw_ddb_index,
47287- atomic_read(&ddb_entry->relogin_retry_count),
47288+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47289 ddb_entry->default_time2wait + 4));
47290 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47291 atomic_set(&ddb_entry->retry_relogin_timer,
47292@@ -5209,7 +5209,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47293
47294 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47295 atomic_set(&ddb_entry->relogin_timer, 0);
47296- atomic_set(&ddb_entry->relogin_retry_count, 0);
47297+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47298 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47299 ddb_entry->default_relogin_timeout =
47300 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47301diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47302index eaa808e..95f8841 100644
47303--- a/drivers/scsi/scsi.c
47304+++ b/drivers/scsi/scsi.c
47305@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47306 unsigned long timeout;
47307 int rtn = 0;
47308
47309- atomic_inc(&cmd->device->iorequest_cnt);
47310+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47311
47312 /* check if the device is still usable */
47313 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47314diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47315index d1549b7..2f60767 100644
47316--- a/drivers/scsi/scsi_lib.c
47317+++ b/drivers/scsi/scsi_lib.c
47318@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47319 shost = sdev->host;
47320 scsi_init_cmd_errh(cmd);
47321 cmd->result = DID_NO_CONNECT << 16;
47322- atomic_inc(&cmd->device->iorequest_cnt);
47323+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47324
47325 /*
47326 * SCSI request completion path will do scsi_device_unbusy(),
47327@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47328
47329 INIT_LIST_HEAD(&cmd->eh_entry);
47330
47331- atomic_inc(&cmd->device->iodone_cnt);
47332+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47333 if (cmd->result)
47334- atomic_inc(&cmd->device->ioerr_cnt);
47335+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47336
47337 disposition = scsi_decide_disposition(cmd);
47338 if (disposition != SUCCESS &&
47339diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47340index 40c6394..62356c2 100644
47341--- a/drivers/scsi/scsi_sysfs.c
47342+++ b/drivers/scsi/scsi_sysfs.c
47343@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47344 char *buf) \
47345 { \
47346 struct scsi_device *sdev = to_scsi_device(dev); \
47347- unsigned long long count = atomic_read(&sdev->field); \
47348+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47349 return snprintf(buf, 20, "0x%llx\n", count); \
47350 } \
47351 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47352diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47353index 84a1fdf..693b0d6 100644
47354--- a/drivers/scsi/scsi_tgt_lib.c
47355+++ b/drivers/scsi/scsi_tgt_lib.c
47356@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47357 int err;
47358
47359 dprintk("%lx %u\n", uaddr, len);
47360- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47361+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47362 if (err) {
47363 /*
47364 * TODO: need to fixup sg_tablesize, max_segment_size,
47365diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47366index 4628fd5..a94a1c2 100644
47367--- a/drivers/scsi/scsi_transport_fc.c
47368+++ b/drivers/scsi/scsi_transport_fc.c
47369@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47370 * Netlink Infrastructure
47371 */
47372
47373-static atomic_t fc_event_seq;
47374+static atomic_unchecked_t fc_event_seq;
47375
47376 /**
47377 * fc_get_event_number - Obtain the next sequential FC event number
47378@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47379 u32
47380 fc_get_event_number(void)
47381 {
47382- return atomic_add_return(1, &fc_event_seq);
47383+ return atomic_add_return_unchecked(1, &fc_event_seq);
47384 }
47385 EXPORT_SYMBOL(fc_get_event_number);
47386
47387@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47388 {
47389 int error;
47390
47391- atomic_set(&fc_event_seq, 0);
47392+ atomic_set_unchecked(&fc_event_seq, 0);
47393
47394 error = transport_class_register(&fc_host_class);
47395 if (error)
47396@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47397 char *cp;
47398
47399 *val = simple_strtoul(buf, &cp, 0);
47400- if ((*cp && (*cp != '\n')) || (*val < 0))
47401+ if (*cp && (*cp != '\n'))
47402 return -EINVAL;
47403 /*
47404 * Check for overflow; dev_loss_tmo is u32
47405diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47406index e4a989f..293090c 100644
47407--- a/drivers/scsi/scsi_transport_iscsi.c
47408+++ b/drivers/scsi/scsi_transport_iscsi.c
47409@@ -79,7 +79,7 @@ struct iscsi_internal {
47410 struct transport_container session_cont;
47411 };
47412
47413-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47414+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47415 static struct workqueue_struct *iscsi_eh_timer_workq;
47416
47417 static DEFINE_IDA(iscsi_sess_ida);
47418@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47419 int err;
47420
47421 ihost = shost->shost_data;
47422- session->sid = atomic_add_return(1, &iscsi_session_nr);
47423+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47424
47425 if (target_id == ISCSI_MAX_TARGET) {
47426 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47427@@ -4077,7 +4077,7 @@ static __init int iscsi_transport_init(void)
47428 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47429 ISCSI_TRANSPORT_VERSION);
47430
47431- atomic_set(&iscsi_session_nr, 0);
47432+ atomic_set_unchecked(&iscsi_session_nr, 0);
47433
47434 err = class_register(&iscsi_transport_class);
47435 if (err)
47436diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47437index f379c7f..e8fc69c 100644
47438--- a/drivers/scsi/scsi_transport_srp.c
47439+++ b/drivers/scsi/scsi_transport_srp.c
47440@@ -33,7 +33,7 @@
47441 #include "scsi_transport_srp_internal.h"
47442
47443 struct srp_host_attrs {
47444- atomic_t next_port_id;
47445+ atomic_unchecked_t next_port_id;
47446 };
47447 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47448
47449@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47450 struct Scsi_Host *shost = dev_to_shost(dev);
47451 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47452
47453- atomic_set(&srp_host->next_port_id, 0);
47454+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47455 return 0;
47456 }
47457
47458@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47459 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47460 rport->roles = ids->roles;
47461
47462- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47463+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47464 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47465
47466 transport_setup_device(&rport->dev);
47467diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47468index 2634d69..fcf7a81 100644
47469--- a/drivers/scsi/sd.c
47470+++ b/drivers/scsi/sd.c
47471@@ -2940,7 +2940,7 @@ static int sd_probe(struct device *dev)
47472 sdkp->disk = gd;
47473 sdkp->index = index;
47474 atomic_set(&sdkp->openers, 0);
47475- atomic_set(&sdkp->device->ioerr_cnt, 0);
47476+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47477
47478 if (!sdp->request_queue->rq_timeout) {
47479 if (sdp->type != TYPE_MOD)
47480diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47481index df5e961..df6b97f 100644
47482--- a/drivers/scsi/sg.c
47483+++ b/drivers/scsi/sg.c
47484@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47485 sdp->disk->disk_name,
47486 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47487 NULL,
47488- (char *)arg);
47489+ (char __user *)arg);
47490 case BLKTRACESTART:
47491 return blk_trace_startstop(sdp->device->request_queue, 1);
47492 case BLKTRACESTOP:
47493diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47494index 9e039c6..ae9e800 100644
47495--- a/drivers/spi/spi.c
47496+++ b/drivers/spi/spi.c
47497@@ -1762,7 +1762,7 @@ int spi_bus_unlock(struct spi_master *master)
47498 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47499
47500 /* portable code must never pass more than 32 bytes */
47501-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47502+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47503
47504 static u8 *buf;
47505
47506diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47507index 2c61783..4d49e4e 100644
47508--- a/drivers/staging/android/timed_output.c
47509+++ b/drivers/staging/android/timed_output.c
47510@@ -25,7 +25,7 @@
47511 #include "timed_output.h"
47512
47513 static struct class *timed_output_class;
47514-static atomic_t device_count;
47515+static atomic_unchecked_t device_count;
47516
47517 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47518 char *buf)
47519@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
47520 timed_output_class = class_create(THIS_MODULE, "timed_output");
47521 if (IS_ERR(timed_output_class))
47522 return PTR_ERR(timed_output_class);
47523- atomic_set(&device_count, 0);
47524+ atomic_set_unchecked(&device_count, 0);
47525 timed_output_class->dev_groups = timed_output_groups;
47526 }
47527
47528@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47529 if (ret < 0)
47530 return ret;
47531
47532- tdev->index = atomic_inc_return(&device_count);
47533+ tdev->index = atomic_inc_return_unchecked(&device_count);
47534 tdev->dev = device_create(timed_output_class, NULL,
47535 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47536 if (IS_ERR(tdev->dev))
47537diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
47538index 0247a20..cb9595c 100644
47539--- a/drivers/staging/gdm724x/gdm_tty.c
47540+++ b/drivers/staging/gdm724x/gdm_tty.c
47541@@ -45,7 +45,7 @@
47542 #define gdm_tty_send_control(n, r, v, d, l) (\
47543 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
47544
47545-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
47546+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
47547
47548 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
47549 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
47550diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
47551index ef5064e..fce01db 100644
47552--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
47553+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
47554@@ -478,13 +478,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
47555 return 0;
47556 }
47557
47558-sfw_test_client_ops_t brw_test_client;
47559-void brw_init_test_client(void)
47560-{
47561- brw_test_client.tso_init = brw_client_init;
47562- brw_test_client.tso_fini = brw_client_fini;
47563- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
47564- brw_test_client.tso_done_rpc = brw_client_done_rpc;
47565+sfw_test_client_ops_t brw_test_client = {
47566+ .tso_init = brw_client_init,
47567+ .tso_fini = brw_client_fini,
47568+ .tso_prep_rpc = brw_client_prep_rpc,
47569+ .tso_done_rpc = brw_client_done_rpc,
47570 };
47571
47572 srpc_service_t brw_test_service;
47573diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
47574index 483c785..e1a2a7b 100644
47575--- a/drivers/staging/lustre/lnet/selftest/framework.c
47576+++ b/drivers/staging/lustre/lnet/selftest/framework.c
47577@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
47578
47579 extern sfw_test_client_ops_t ping_test_client;
47580 extern srpc_service_t ping_test_service;
47581-extern void ping_init_test_client(void);
47582 extern void ping_init_test_service(void);
47583
47584 extern sfw_test_client_ops_t brw_test_client;
47585 extern srpc_service_t brw_test_service;
47586-extern void brw_init_test_client(void);
47587 extern void brw_init_test_service(void);
47588
47589
47590@@ -1684,12 +1682,10 @@ sfw_startup (void)
47591 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
47592 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
47593
47594- brw_init_test_client();
47595 brw_init_test_service();
47596 rc = sfw_register_test(&brw_test_service, &brw_test_client);
47597 LASSERT (rc == 0);
47598
47599- ping_init_test_client();
47600 ping_init_test_service();
47601 rc = sfw_register_test(&ping_test_service, &ping_test_client);
47602 LASSERT (rc == 0);
47603diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
47604index f0f9194..b589047 100644
47605--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
47606+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
47607@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
47608 return 0;
47609 }
47610
47611-sfw_test_client_ops_t ping_test_client;
47612-void ping_init_test_client(void)
47613-{
47614- ping_test_client.tso_init = ping_client_init;
47615- ping_test_client.tso_fini = ping_client_fini;
47616- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
47617- ping_test_client.tso_done_rpc = ping_client_done_rpc;
47618-}
47619+sfw_test_client_ops_t ping_test_client = {
47620+ .tso_init = ping_client_init,
47621+ .tso_fini = ping_client_fini,
47622+ .tso_prep_rpc = ping_client_prep_rpc,
47623+ .tso_done_rpc = ping_client_done_rpc,
47624+};
47625
47626 srpc_service_t ping_test_service;
47627 void ping_init_test_service(void)
47628diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
47629index 7020d9c..0d3b580 100644
47630--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
47631+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
47632@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
47633 ldlm_completion_callback lcs_completion;
47634 ldlm_blocking_callback lcs_blocking;
47635 ldlm_glimpse_callback lcs_glimpse;
47636-};
47637+} __no_const;
47638
47639 /* ldlm_lockd.c */
47640 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
47641diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
47642index a612255..9a9e2dd 100644
47643--- a/drivers/staging/lustre/lustre/include/obd.h
47644+++ b/drivers/staging/lustre/lustre/include/obd.h
47645@@ -1417,7 +1417,7 @@ struct md_ops {
47646 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
47647 * wrapper function in include/linux/obd_class.h.
47648 */
47649-};
47650+} __no_const;
47651
47652 struct lsm_operations {
47653 void (*lsm_free)(struct lov_stripe_md *);
47654diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47655index fc6c977..df1f956 100644
47656--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47657+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
47658@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
47659 int LL_PROC_PROTO(proc_console_max_delay_cs)
47660 {
47661 int rc, max_delay_cs;
47662- ctl_table_t dummy = *table;
47663+ ctl_table_no_const dummy = *table;
47664 cfs_duration_t d;
47665
47666 dummy.data = &max_delay_cs;
47667@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
47668 int LL_PROC_PROTO(proc_console_min_delay_cs)
47669 {
47670 int rc, min_delay_cs;
47671- ctl_table_t dummy = *table;
47672+ ctl_table_no_const dummy = *table;
47673 cfs_duration_t d;
47674
47675 dummy.data = &min_delay_cs;
47676@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
47677 int LL_PROC_PROTO(proc_console_backoff)
47678 {
47679 int rc, backoff;
47680- ctl_table_t dummy = *table;
47681+ ctl_table_no_const dummy = *table;
47682
47683 dummy.data = &backoff;
47684 dummy.proc_handler = &proc_dointvec;
47685diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47686index 3675020..e80d92c 100644
47687--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47688+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47689@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47690
47691 static int solo_sysfs_init(struct solo_dev *solo_dev)
47692 {
47693- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47694+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47695 struct device *dev = &solo_dev->dev;
47696 const char *driver;
47697 int i;
47698diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47699index 3335941..2b26186 100644
47700--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47701+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47702@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47703
47704 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47705 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47706- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47707+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47708 if (p2m_id < 0)
47709 p2m_id = -p2m_id;
47710 }
47711diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47712index 6f91d2e..3f011d2 100644
47713--- a/drivers/staging/media/solo6x10/solo6x10.h
47714+++ b/drivers/staging/media/solo6x10/solo6x10.h
47715@@ -238,7 +238,7 @@ struct solo_dev {
47716
47717 /* P2M DMA Engine */
47718 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47719- atomic_t p2m_count;
47720+ atomic_unchecked_t p2m_count;
47721 int p2m_jiffies;
47722 unsigned int p2m_timeouts;
47723
47724diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47725index e14a1bb..9cb9bbe 100644
47726--- a/drivers/staging/octeon/ethernet-rx.c
47727+++ b/drivers/staging/octeon/ethernet-rx.c
47728@@ -419,11 +419,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47729 /* Increment RX stats for virtual ports */
47730 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47731 #ifdef CONFIG_64BIT
47732- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47733- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47734+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47735+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47736 #else
47737- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47738- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47739+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47740+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47741 #endif
47742 }
47743 netif_receive_skb(skb);
47744@@ -434,9 +434,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47745 dev->name);
47746 */
47747 #ifdef CONFIG_64BIT
47748- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47749+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47750 #else
47751- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47752+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47753 #endif
47754 dev_kfree_skb_irq(skb);
47755 }
47756diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47757index c3a90e7..023619a 100644
47758--- a/drivers/staging/octeon/ethernet.c
47759+++ b/drivers/staging/octeon/ethernet.c
47760@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47761 * since the RX tasklet also increments it.
47762 */
47763 #ifdef CONFIG_64BIT
47764- atomic64_add(rx_status.dropped_packets,
47765- (atomic64_t *)&priv->stats.rx_dropped);
47766+ atomic64_add_unchecked(rx_status.dropped_packets,
47767+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47768 #else
47769- atomic_add(rx_status.dropped_packets,
47770- (atomic_t *)&priv->stats.rx_dropped);
47771+ atomic_add_unchecked(rx_status.dropped_packets,
47772+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47773 #endif
47774 }
47775
47776diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
47777index 439c3c9..2d74293 100644
47778--- a/drivers/staging/rtl8188eu/include/hal_intf.h
47779+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
47780@@ -271,7 +271,7 @@ struct hal_ops {
47781 s32 (*c2h_handler)(struct adapter *padapter,
47782 struct c2h_evt_hdr *c2h_evt);
47783 c2h_id_filter c2h_id_filter_ccx;
47784-};
47785+} __no_const;
47786
47787 enum rt_eeprom_type {
47788 EEPROM_93C46,
47789diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
47790index eb6f0e5..e6a0958 100644
47791--- a/drivers/staging/rtl8188eu/include/rtw_io.h
47792+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
47793@@ -126,7 +126,7 @@ struct _io_ops {
47794 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
47795 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
47796 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
47797-};
47798+} __no_const;
47799
47800 struct io_req {
47801 struct list_head list;
47802diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47803index dc23395..cf7e9b1 100644
47804--- a/drivers/staging/rtl8712/rtl871x_io.h
47805+++ b/drivers/staging/rtl8712/rtl871x_io.h
47806@@ -108,7 +108,7 @@ struct _io_ops {
47807 u8 *pmem);
47808 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47809 u8 *pmem);
47810-};
47811+} __no_const;
47812
47813 struct io_req {
47814 struct list_head list;
47815diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47816index 1f5088b..0e59820 100644
47817--- a/drivers/staging/sbe-2t3e3/netdev.c
47818+++ b/drivers/staging/sbe-2t3e3/netdev.c
47819@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47820 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47821
47822 if (rlen)
47823- if (copy_to_user(data, &resp, rlen))
47824+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47825 return -EFAULT;
47826
47827 return 0;
47828diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47829index a863a98..d272795 100644
47830--- a/drivers/staging/usbip/vhci.h
47831+++ b/drivers/staging/usbip/vhci.h
47832@@ -83,7 +83,7 @@ struct vhci_hcd {
47833 unsigned resuming:1;
47834 unsigned long re_timeout;
47835
47836- atomic_t seqnum;
47837+ atomic_unchecked_t seqnum;
47838
47839 /*
47840 * NOTE:
47841diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47842index d7974cb..d78076b 100644
47843--- a/drivers/staging/usbip/vhci_hcd.c
47844+++ b/drivers/staging/usbip/vhci_hcd.c
47845@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47846
47847 spin_lock(&vdev->priv_lock);
47848
47849- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47850+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47851 if (priv->seqnum == 0xffff)
47852 dev_info(&urb->dev->dev, "seqnum max\n");
47853
47854@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47855 return -ENOMEM;
47856 }
47857
47858- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47859+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47860 if (unlink->seqnum == 0xffff)
47861 pr_info("seqnum max\n");
47862
47863@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47864 vdev->rhport = rhport;
47865 }
47866
47867- atomic_set(&vhci->seqnum, 0);
47868+ atomic_set_unchecked(&vhci->seqnum, 0);
47869 spin_lock_init(&vhci->lock);
47870
47871 hcd->power_budget = 0; /* no limit */
47872diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47873index d07fcb5..358e1e1 100644
47874--- a/drivers/staging/usbip/vhci_rx.c
47875+++ b/drivers/staging/usbip/vhci_rx.c
47876@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47877 if (!urb) {
47878 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47879 pr_info("max seqnum %d\n",
47880- atomic_read(&the_controller->seqnum));
47881+ atomic_read_unchecked(&the_controller->seqnum));
47882 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47883 return;
47884 }
47885diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47886index 8acff44..bdb2fca 100644
47887--- a/drivers/staging/vt6655/hostap.c
47888+++ b/drivers/staging/vt6655/hostap.c
47889@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47890 *
47891 */
47892
47893+static net_device_ops_no_const apdev_netdev_ops;
47894+
47895 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47896 {
47897 PSDevice apdev_priv;
47898 struct net_device *dev = pDevice->dev;
47899 int ret;
47900- const struct net_device_ops apdev_netdev_ops = {
47901- .ndo_start_xmit = pDevice->tx_80211,
47902- };
47903
47904 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47905
47906@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47907 *apdev_priv = *pDevice;
47908 eth_hw_addr_inherit(pDevice->apdev, dev);
47909
47910+ /* only half broken now */
47911+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47912 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47913
47914 pDevice->apdev->type = ARPHRD_IEEE80211;
47915diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47916index c699a30..b90a5fd 100644
47917--- a/drivers/staging/vt6656/hostap.c
47918+++ b/drivers/staging/vt6656/hostap.c
47919@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47920 *
47921 */
47922
47923+static net_device_ops_no_const apdev_netdev_ops;
47924+
47925 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47926 {
47927 struct vnt_private *apdev_priv;
47928 struct net_device *dev = pDevice->dev;
47929 int ret;
47930- const struct net_device_ops apdev_netdev_ops = {
47931- .ndo_start_xmit = pDevice->tx_80211,
47932- };
47933
47934 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47935
47936@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47937 *apdev_priv = *pDevice;
47938 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47939
47940+ /* only half broken now */
47941+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47942 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47943
47944 pDevice->apdev->type = ARPHRD_IEEE80211;
47945diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47946index e51b09a..5ebac31 100644
47947--- a/drivers/target/sbp/sbp_target.c
47948+++ b/drivers/target/sbp/sbp_target.c
47949@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47950
47951 #define SESSION_MAINTENANCE_INTERVAL HZ
47952
47953-static atomic_t login_id = ATOMIC_INIT(0);
47954+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47955
47956 static void session_maintenance_work(struct work_struct *);
47957 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47958@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47959 login->lun = se_lun;
47960 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47961 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47962- login->login_id = atomic_inc_return(&login_id);
47963+ login->login_id = atomic_inc_return_unchecked(&login_id);
47964
47965 login->tgt_agt = sbp_target_agent_register(login);
47966 if (IS_ERR(login->tgt_agt)) {
47967diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47968index d90dbb0..6cbe585 100644
47969--- a/drivers/target/target_core_device.c
47970+++ b/drivers/target/target_core_device.c
47971@@ -1431,7 +1431,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47972 spin_lock_init(&dev->se_tmr_lock);
47973 spin_lock_init(&dev->qf_cmd_lock);
47974 sema_init(&dev->caw_sem, 1);
47975- atomic_set(&dev->dev_ordered_id, 0);
47976+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47977 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47978 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47979 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47980diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47981index 0b0009b..215e88e 100644
47982--- a/drivers/target/target_core_transport.c
47983+++ b/drivers/target/target_core_transport.c
47984@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47985 * Used to determine when ORDERED commands should go from
47986 * Dormant to Active status.
47987 */
47988- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47989+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47990 smp_mb__after_atomic_inc();
47991 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47992 cmd->se_ordered_id, cmd->sam_task_attr,
47993diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47994index 33f83fe..d80f8e1 100644
47995--- a/drivers/tty/cyclades.c
47996+++ b/drivers/tty/cyclades.c
47997@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47998 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47999 info->port.count);
48000 #endif
48001- info->port.count++;
48002+ atomic_inc(&info->port.count);
48003 #ifdef CY_DEBUG_COUNT
48004 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
48005- current->pid, info->port.count);
48006+ current->pid, atomic_read(&info->port.count));
48007 #endif
48008
48009 /*
48010@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
48011 for (j = 0; j < cy_card[i].nports; j++) {
48012 info = &cy_card[i].ports[j];
48013
48014- if (info->port.count) {
48015+ if (atomic_read(&info->port.count)) {
48016 /* XXX is the ldisc num worth this? */
48017 struct tty_struct *tty;
48018 struct tty_ldisc *ld;
48019diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
48020index 9eba119..5070303 100644
48021--- a/drivers/tty/hvc/hvc_console.c
48022+++ b/drivers/tty/hvc/hvc_console.c
48023@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
48024
48025 spin_lock_irqsave(&hp->port.lock, flags);
48026 /* Check and then increment for fast path open. */
48027- if (hp->port.count++ > 0) {
48028+ if (atomic_inc_return(&hp->port.count) > 1) {
48029 spin_unlock_irqrestore(&hp->port.lock, flags);
48030 hvc_kick();
48031 return 0;
48032@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
48033
48034 spin_lock_irqsave(&hp->port.lock, flags);
48035
48036- if (--hp->port.count == 0) {
48037+ if (atomic_dec_return(&hp->port.count) == 0) {
48038 spin_unlock_irqrestore(&hp->port.lock, flags);
48039 /* We are done with the tty pointer now. */
48040 tty_port_tty_set(&hp->port, NULL);
48041@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
48042 */
48043 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
48044 } else {
48045- if (hp->port.count < 0)
48046+ if (atomic_read(&hp->port.count) < 0)
48047 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
48048- hp->vtermno, hp->port.count);
48049+ hp->vtermno, atomic_read(&hp->port.count));
48050 spin_unlock_irqrestore(&hp->port.lock, flags);
48051 }
48052 }
48053@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
48054 * open->hangup case this can be called after the final close so prevent
48055 * that from happening for now.
48056 */
48057- if (hp->port.count <= 0) {
48058+ if (atomic_read(&hp->port.count) <= 0) {
48059 spin_unlock_irqrestore(&hp->port.lock, flags);
48060 return;
48061 }
48062
48063- hp->port.count = 0;
48064+ atomic_set(&hp->port.count, 0);
48065 spin_unlock_irqrestore(&hp->port.lock, flags);
48066 tty_port_tty_set(&hp->port, NULL);
48067
48068@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
48069 return -EPIPE;
48070
48071 /* FIXME what's this (unprotected) check for? */
48072- if (hp->port.count <= 0)
48073+ if (atomic_read(&hp->port.count) <= 0)
48074 return -EIO;
48075
48076 spin_lock_irqsave(&hp->lock, flags);
48077diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
48078index 81e939e..95ead10 100644
48079--- a/drivers/tty/hvc/hvcs.c
48080+++ b/drivers/tty/hvc/hvcs.c
48081@@ -83,6 +83,7 @@
48082 #include <asm/hvcserver.h>
48083 #include <asm/uaccess.h>
48084 #include <asm/vio.h>
48085+#include <asm/local.h>
48086
48087 /*
48088 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
48089@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
48090
48091 spin_lock_irqsave(&hvcsd->lock, flags);
48092
48093- if (hvcsd->port.count > 0) {
48094+ if (atomic_read(&hvcsd->port.count) > 0) {
48095 spin_unlock_irqrestore(&hvcsd->lock, flags);
48096 printk(KERN_INFO "HVCS: vterm state unchanged. "
48097 "The hvcs device node is still in use.\n");
48098@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
48099 }
48100 }
48101
48102- hvcsd->port.count = 0;
48103+ atomic_set(&hvcsd->port.count, 0);
48104 hvcsd->port.tty = tty;
48105 tty->driver_data = hvcsd;
48106
48107@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
48108 unsigned long flags;
48109
48110 spin_lock_irqsave(&hvcsd->lock, flags);
48111- hvcsd->port.count++;
48112+ atomic_inc(&hvcsd->port.count);
48113 hvcsd->todo_mask |= HVCS_SCHED_READ;
48114 spin_unlock_irqrestore(&hvcsd->lock, flags);
48115
48116@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
48117 hvcsd = tty->driver_data;
48118
48119 spin_lock_irqsave(&hvcsd->lock, flags);
48120- if (--hvcsd->port.count == 0) {
48121+ if (atomic_dec_and_test(&hvcsd->port.count)) {
48122
48123 vio_disable_interrupts(hvcsd->vdev);
48124
48125@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
48126
48127 free_irq(irq, hvcsd);
48128 return;
48129- } else if (hvcsd->port.count < 0) {
48130+ } else if (atomic_read(&hvcsd->port.count) < 0) {
48131 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
48132 " is missmanaged.\n",
48133- hvcsd->vdev->unit_address, hvcsd->port.count);
48134+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
48135 }
48136
48137 spin_unlock_irqrestore(&hvcsd->lock, flags);
48138@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
48139
48140 spin_lock_irqsave(&hvcsd->lock, flags);
48141 /* Preserve this so that we know how many kref refs to put */
48142- temp_open_count = hvcsd->port.count;
48143+ temp_open_count = atomic_read(&hvcsd->port.count);
48144
48145 /*
48146 * Don't kref put inside the spinlock because the destruction
48147@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
48148 tty->driver_data = NULL;
48149 hvcsd->port.tty = NULL;
48150
48151- hvcsd->port.count = 0;
48152+ atomic_set(&hvcsd->port.count, 0);
48153
48154 /* This will drop any buffered data on the floor which is OK in a hangup
48155 * scenario. */
48156@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
48157 * the middle of a write operation? This is a crummy place to do this
48158 * but we want to keep it all in the spinlock.
48159 */
48160- if (hvcsd->port.count <= 0) {
48161+ if (atomic_read(&hvcsd->port.count) <= 0) {
48162 spin_unlock_irqrestore(&hvcsd->lock, flags);
48163 return -ENODEV;
48164 }
48165@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
48166 {
48167 struct hvcs_struct *hvcsd = tty->driver_data;
48168
48169- if (!hvcsd || hvcsd->port.count <= 0)
48170+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
48171 return 0;
48172
48173 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
48174diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
48175index 4190199..48f2920 100644
48176--- a/drivers/tty/hvc/hvsi.c
48177+++ b/drivers/tty/hvc/hvsi.c
48178@@ -85,7 +85,7 @@ struct hvsi_struct {
48179 int n_outbuf;
48180 uint32_t vtermno;
48181 uint32_t virq;
48182- atomic_t seqno; /* HVSI packet sequence number */
48183+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
48184 uint16_t mctrl;
48185 uint8_t state; /* HVSI protocol state */
48186 uint8_t flags;
48187@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
48188
48189 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
48190 packet.hdr.len = sizeof(struct hvsi_query_response);
48191- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48192+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48193 packet.verb = VSV_SEND_VERSION_NUMBER;
48194 packet.u.version = HVSI_VERSION;
48195 packet.query_seqno = query_seqno+1;
48196@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
48197
48198 packet.hdr.type = VS_QUERY_PACKET_HEADER;
48199 packet.hdr.len = sizeof(struct hvsi_query);
48200- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48201+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48202 packet.verb = verb;
48203
48204 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
48205@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
48206 int wrote;
48207
48208 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
48209- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48210+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48211 packet.hdr.len = sizeof(struct hvsi_control);
48212 packet.verb = VSV_SET_MODEM_CTL;
48213 packet.mask = HVSI_TSDTR;
48214@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
48215 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
48216
48217 packet.hdr.type = VS_DATA_PACKET_HEADER;
48218- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48219+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48220 packet.hdr.len = count + sizeof(struct hvsi_header);
48221 memcpy(&packet.data, buf, count);
48222
48223@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
48224 struct hvsi_control packet __ALIGNED__;
48225
48226 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
48227- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
48228+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
48229 packet.hdr.len = 6;
48230 packet.verb = VSV_CLOSE_PROTOCOL;
48231
48232diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
48233index ac27671..0f627ee 100644
48234--- a/drivers/tty/hvc/hvsi_lib.c
48235+++ b/drivers/tty/hvc/hvsi_lib.c
48236@@ -9,7 +9,7 @@
48237
48238 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
48239 {
48240- packet->seqno = atomic_inc_return(&pv->seqno);
48241+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
48242
48243 /* Assumes that always succeeds, works in practice */
48244 return pv->put_chars(pv->termno, (char *)packet, packet->len);
48245@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
48246
48247 /* Reset state */
48248 pv->established = 0;
48249- atomic_set(&pv->seqno, 0);
48250+ atomic_set_unchecked(&pv->seqno, 0);
48251
48252 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
48253
48254@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
48255 pv->mctrl_update = 0;
48256 q.hdr.type = VS_QUERY_PACKET_HEADER;
48257 q.hdr.len = sizeof(struct hvsi_query);
48258- q.hdr.seqno = atomic_inc_return(&pv->seqno);
48259+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
48260 q.verb = VSV_SEND_MODEM_CTL_STATUS;
48261 rc = hvsi_send_packet(pv, &q.hdr);
48262 if (rc <= 0) {
48263diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
48264index 8fd72ff..34a0bed 100644
48265--- a/drivers/tty/ipwireless/tty.c
48266+++ b/drivers/tty/ipwireless/tty.c
48267@@ -29,6 +29,7 @@
48268 #include <linux/tty_driver.h>
48269 #include <linux/tty_flip.h>
48270 #include <linux/uaccess.h>
48271+#include <asm/local.h>
48272
48273 #include "tty.h"
48274 #include "network.h"
48275@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48276 mutex_unlock(&tty->ipw_tty_mutex);
48277 return -ENODEV;
48278 }
48279- if (tty->port.count == 0)
48280+ if (atomic_read(&tty->port.count) == 0)
48281 tty->tx_bytes_queued = 0;
48282
48283- tty->port.count++;
48284+ atomic_inc(&tty->port.count);
48285
48286 tty->port.tty = linux_tty;
48287 linux_tty->driver_data = tty;
48288@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48289
48290 static void do_ipw_close(struct ipw_tty *tty)
48291 {
48292- tty->port.count--;
48293-
48294- if (tty->port.count == 0) {
48295+ if (atomic_dec_return(&tty->port.count) == 0) {
48296 struct tty_struct *linux_tty = tty->port.tty;
48297
48298 if (linux_tty != NULL) {
48299@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
48300 return;
48301
48302 mutex_lock(&tty->ipw_tty_mutex);
48303- if (tty->port.count == 0) {
48304+ if (atomic_read(&tty->port.count) == 0) {
48305 mutex_unlock(&tty->ipw_tty_mutex);
48306 return;
48307 }
48308@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48309
48310 mutex_lock(&tty->ipw_tty_mutex);
48311
48312- if (!tty->port.count) {
48313+ if (!atomic_read(&tty->port.count)) {
48314 mutex_unlock(&tty->ipw_tty_mutex);
48315 return;
48316 }
48317@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48318 return -ENODEV;
48319
48320 mutex_lock(&tty->ipw_tty_mutex);
48321- if (!tty->port.count) {
48322+ if (!atomic_read(&tty->port.count)) {
48323 mutex_unlock(&tty->ipw_tty_mutex);
48324 return -EINVAL;
48325 }
48326@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48327 if (!tty)
48328 return -ENODEV;
48329
48330- if (!tty->port.count)
48331+ if (!atomic_read(&tty->port.count))
48332 return -EINVAL;
48333
48334 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48335@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48336 if (!tty)
48337 return 0;
48338
48339- if (!tty->port.count)
48340+ if (!atomic_read(&tty->port.count))
48341 return 0;
48342
48343 return tty->tx_bytes_queued;
48344@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48345 if (!tty)
48346 return -ENODEV;
48347
48348- if (!tty->port.count)
48349+ if (!atomic_read(&tty->port.count))
48350 return -EINVAL;
48351
48352 return get_control_lines(tty);
48353@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48354 if (!tty)
48355 return -ENODEV;
48356
48357- if (!tty->port.count)
48358+ if (!atomic_read(&tty->port.count))
48359 return -EINVAL;
48360
48361 return set_control_lines(tty, set, clear);
48362@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48363 if (!tty)
48364 return -ENODEV;
48365
48366- if (!tty->port.count)
48367+ if (!atomic_read(&tty->port.count))
48368 return -EINVAL;
48369
48370 /* FIXME: Exactly how is the tty object locked here .. */
48371@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48372 * are gone */
48373 mutex_lock(&ttyj->ipw_tty_mutex);
48374 }
48375- while (ttyj->port.count)
48376+ while (atomic_read(&ttyj->port.count))
48377 do_ipw_close(ttyj);
48378 ipwireless_disassociate_network_ttys(network,
48379 ttyj->channel_idx);
48380diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48381index 1deaca4..c8582d4 100644
48382--- a/drivers/tty/moxa.c
48383+++ b/drivers/tty/moxa.c
48384@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48385 }
48386
48387 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48388- ch->port.count++;
48389+ atomic_inc(&ch->port.count);
48390 tty->driver_data = ch;
48391 tty_port_tty_set(&ch->port, tty);
48392 mutex_lock(&ch->port.mutex);
48393diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48394index c0f76da..d974c32 100644
48395--- a/drivers/tty/n_gsm.c
48396+++ b/drivers/tty/n_gsm.c
48397@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48398 spin_lock_init(&dlci->lock);
48399 mutex_init(&dlci->mutex);
48400 dlci->fifo = &dlci->_fifo;
48401- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48402+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48403 kfree(dlci);
48404 return NULL;
48405 }
48406@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48407 struct gsm_dlci *dlci = tty->driver_data;
48408 struct tty_port *port = &dlci->port;
48409
48410- port->count++;
48411+ atomic_inc(&port->count);
48412 dlci_get(dlci);
48413 dlci_get(dlci->gsm->dlci[0]);
48414 mux_get(dlci->gsm);
48415diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48416index 4d6f430..0810fa9 100644
48417--- a/drivers/tty/n_tty.c
48418+++ b/drivers/tty/n_tty.c
48419@@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48420 {
48421 *ops = tty_ldisc_N_TTY;
48422 ops->owner = NULL;
48423- ops->refcount = ops->flags = 0;
48424+ atomic_set(&ops->refcount, 0);
48425+ ops->flags = 0;
48426 }
48427 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48428diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48429index 25c9bc7..24077b7 100644
48430--- a/drivers/tty/pty.c
48431+++ b/drivers/tty/pty.c
48432@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
48433 panic("Couldn't register Unix98 pts driver");
48434
48435 /* Now create the /dev/ptmx special device */
48436+ pax_open_kernel();
48437 tty_default_fops(&ptmx_fops);
48438- ptmx_fops.open = ptmx_open;
48439+ *(void **)&ptmx_fops.open = ptmx_open;
48440+ pax_close_kernel();
48441
48442 cdev_init(&ptmx_cdev, &ptmx_fops);
48443 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48444diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48445index 354564e..fe50d9a 100644
48446--- a/drivers/tty/rocket.c
48447+++ b/drivers/tty/rocket.c
48448@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48449 tty->driver_data = info;
48450 tty_port_tty_set(port, tty);
48451
48452- if (port->count++ == 0) {
48453+ if (atomic_inc_return(&port->count) == 1) {
48454 atomic_inc(&rp_num_ports_open);
48455
48456 #ifdef ROCKET_DEBUG_OPEN
48457@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48458 #endif
48459 }
48460 #ifdef ROCKET_DEBUG_OPEN
48461- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48462+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48463 #endif
48464
48465 /*
48466@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48467 spin_unlock_irqrestore(&info->port.lock, flags);
48468 return;
48469 }
48470- if (info->port.count)
48471+ if (atomic_read(&info->port.count))
48472 atomic_dec(&rp_num_ports_open);
48473 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48474 spin_unlock_irqrestore(&info->port.lock, flags);
48475diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48476index 1274499..f541382 100644
48477--- a/drivers/tty/serial/ioc4_serial.c
48478+++ b/drivers/tty/serial/ioc4_serial.c
48479@@ -437,7 +437,7 @@ struct ioc4_soft {
48480 } is_intr_info[MAX_IOC4_INTR_ENTS];
48481
48482 /* Number of entries active in the above array */
48483- atomic_t is_num_intrs;
48484+ atomic_unchecked_t is_num_intrs;
48485 } is_intr_type[IOC4_NUM_INTR_TYPES];
48486
48487 /* is_ir_lock must be held while
48488@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48489 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48490 || (type == IOC4_OTHER_INTR_TYPE)));
48491
48492- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48493+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48494 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48495
48496 /* Save off the lower level interrupt handler */
48497@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48498
48499 soft = arg;
48500 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48501- num_intrs = (int)atomic_read(
48502+ num_intrs = (int)atomic_read_unchecked(
48503 &soft->is_intr_type[intr_type].is_num_intrs);
48504
48505 this_mir = this_ir = pending_intrs(soft, intr_type);
48506diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48507index a260cde..6b2b5ce 100644
48508--- a/drivers/tty/serial/kgdboc.c
48509+++ b/drivers/tty/serial/kgdboc.c
48510@@ -24,8 +24,9 @@
48511 #define MAX_CONFIG_LEN 40
48512
48513 static struct kgdb_io kgdboc_io_ops;
48514+static struct kgdb_io kgdboc_io_ops_console;
48515
48516-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48517+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48518 static int configured = -1;
48519
48520 static char config[MAX_CONFIG_LEN];
48521@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48522 kgdboc_unregister_kbd();
48523 if (configured == 1)
48524 kgdb_unregister_io_module(&kgdboc_io_ops);
48525+ else if (configured == 2)
48526+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48527 }
48528
48529 static int configure_kgdboc(void)
48530@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48531 int err;
48532 char *cptr = config;
48533 struct console *cons;
48534+ int is_console = 0;
48535
48536 err = kgdboc_option_setup(config);
48537 if (err || !strlen(config) || isspace(config[0]))
48538 goto noconfig;
48539
48540 err = -ENODEV;
48541- kgdboc_io_ops.is_console = 0;
48542 kgdb_tty_driver = NULL;
48543
48544 kgdboc_use_kms = 0;
48545@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48546 int idx;
48547 if (cons->device && cons->device(cons, &idx) == p &&
48548 idx == tty_line) {
48549- kgdboc_io_ops.is_console = 1;
48550+ is_console = 1;
48551 break;
48552 }
48553 cons = cons->next;
48554@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48555 kgdb_tty_line = tty_line;
48556
48557 do_register:
48558- err = kgdb_register_io_module(&kgdboc_io_ops);
48559+ if (is_console) {
48560+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48561+ configured = 2;
48562+ } else {
48563+ err = kgdb_register_io_module(&kgdboc_io_ops);
48564+ configured = 1;
48565+ }
48566 if (err)
48567 goto noconfig;
48568
48569@@ -205,8 +214,6 @@ do_register:
48570 if (err)
48571 goto nmi_con_failed;
48572
48573- configured = 1;
48574-
48575 return 0;
48576
48577 nmi_con_failed:
48578@@ -223,7 +230,7 @@ noconfig:
48579 static int __init init_kgdboc(void)
48580 {
48581 /* Already configured? */
48582- if (configured == 1)
48583+ if (configured >= 1)
48584 return 0;
48585
48586 return configure_kgdboc();
48587@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48588 if (config[len - 1] == '\n')
48589 config[len - 1] = '\0';
48590
48591- if (configured == 1)
48592+ if (configured >= 1)
48593 cleanup_kgdboc();
48594
48595 /* Go and configure with the new params. */
48596@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48597 .post_exception = kgdboc_post_exp_handler,
48598 };
48599
48600+static struct kgdb_io kgdboc_io_ops_console = {
48601+ .name = "kgdboc",
48602+ .read_char = kgdboc_get_char,
48603+ .write_char = kgdboc_put_char,
48604+ .pre_exception = kgdboc_pre_exp_handler,
48605+ .post_exception = kgdboc_post_exp_handler,
48606+ .is_console = 1
48607+};
48608+
48609 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48610 /* This is only available if kgdboc is a built in for early debugging */
48611 static int __init kgdboc_early_init(char *opt)
48612diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48613index b5d779c..3622cfe 100644
48614--- a/drivers/tty/serial/msm_serial.c
48615+++ b/drivers/tty/serial/msm_serial.c
48616@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
48617 .cons = MSM_CONSOLE,
48618 };
48619
48620-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48621+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48622
48623 static const struct of_device_id msm_uartdm_table[] = {
48624 { .compatible = "qcom,msm-uartdm" },
48625@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48626 int irq;
48627
48628 if (pdev->id == -1)
48629- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48630+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48631
48632 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48633 return -ENXIO;
48634diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48635index f3dfa19..342f2ff 100644
48636--- a/drivers/tty/serial/samsung.c
48637+++ b/drivers/tty/serial/samsung.c
48638@@ -456,11 +456,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48639 }
48640 }
48641
48642+static int s3c64xx_serial_startup(struct uart_port *port);
48643 static int s3c24xx_serial_startup(struct uart_port *port)
48644 {
48645 struct s3c24xx_uart_port *ourport = to_ourport(port);
48646 int ret;
48647
48648+ /* Startup sequence is different for s3c64xx and higher SoC's */
48649+ if (s3c24xx_serial_has_interrupt_mask(port))
48650+ return s3c64xx_serial_startup(port);
48651+
48652 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48653 port->mapbase, port->membase);
48654
48655@@ -1127,10 +1132,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48656 /* setup info for port */
48657 port->dev = &platdev->dev;
48658
48659- /* Startup sequence is different for s3c64xx and higher SoC's */
48660- if (s3c24xx_serial_has_interrupt_mask(port))
48661- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48662-
48663 port->uartclk = 1;
48664
48665 if (cfg->uart_flags & UPF_CONS_FLOW) {
48666diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48667index 0f02351..07c59c5 100644
48668--- a/drivers/tty/serial/serial_core.c
48669+++ b/drivers/tty/serial/serial_core.c
48670@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48671 uart_flush_buffer(tty);
48672 uart_shutdown(tty, state);
48673 spin_lock_irqsave(&port->lock, flags);
48674- port->count = 0;
48675+ atomic_set(&port->count, 0);
48676 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48677 spin_unlock_irqrestore(&port->lock, flags);
48678 tty_port_tty_set(port, NULL);
48679@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48680 goto end;
48681 }
48682
48683- port->count++;
48684+ atomic_inc(&port->count);
48685 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48686 retval = -ENXIO;
48687 goto err_dec_count;
48688@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48689 /*
48690 * Make sure the device is in D0 state.
48691 */
48692- if (port->count == 1)
48693+ if (atomic_read(&port->count) == 1)
48694 uart_change_pm(state, UART_PM_STATE_ON);
48695
48696 /*
48697@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48698 end:
48699 return retval;
48700 err_dec_count:
48701- port->count--;
48702+ atomic_inc(&port->count);
48703 mutex_unlock(&port->mutex);
48704 goto end;
48705 }
48706diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48707index e1ce141..6d4ed80 100644
48708--- a/drivers/tty/synclink.c
48709+++ b/drivers/tty/synclink.c
48710@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48711
48712 if (debug_level >= DEBUG_LEVEL_INFO)
48713 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48714- __FILE__,__LINE__, info->device_name, info->port.count);
48715+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48716
48717 if (tty_port_close_start(&info->port, tty, filp) == 0)
48718 goto cleanup;
48719@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48720 cleanup:
48721 if (debug_level >= DEBUG_LEVEL_INFO)
48722 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48723- tty->driver->name, info->port.count);
48724+ tty->driver->name, atomic_read(&info->port.count));
48725
48726 } /* end of mgsl_close() */
48727
48728@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48729
48730 mgsl_flush_buffer(tty);
48731 shutdown(info);
48732-
48733- info->port.count = 0;
48734+
48735+ atomic_set(&info->port.count, 0);
48736 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48737 info->port.tty = NULL;
48738
48739@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48740
48741 if (debug_level >= DEBUG_LEVEL_INFO)
48742 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48743- __FILE__,__LINE__, tty->driver->name, port->count );
48744+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48745
48746 spin_lock_irqsave(&info->irq_spinlock, flags);
48747 if (!tty_hung_up_p(filp)) {
48748 extra_count = true;
48749- port->count--;
48750+ atomic_dec(&port->count);
48751 }
48752 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48753 port->blocked_open++;
48754@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48755
48756 if (debug_level >= DEBUG_LEVEL_INFO)
48757 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48758- __FILE__,__LINE__, tty->driver->name, port->count );
48759+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48760
48761 tty_unlock(tty);
48762 schedule();
48763@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48764
48765 /* FIXME: Racy on hangup during close wait */
48766 if (extra_count)
48767- port->count++;
48768+ atomic_inc(&port->count);
48769 port->blocked_open--;
48770
48771 if (debug_level >= DEBUG_LEVEL_INFO)
48772 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48773- __FILE__,__LINE__, tty->driver->name, port->count );
48774+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48775
48776 if (!retval)
48777 port->flags |= ASYNC_NORMAL_ACTIVE;
48778@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48779
48780 if (debug_level >= DEBUG_LEVEL_INFO)
48781 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48782- __FILE__,__LINE__,tty->driver->name, info->port.count);
48783+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48784
48785 /* If port is closing, signal caller to try again */
48786 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48787@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48788 spin_unlock_irqrestore(&info->netlock, flags);
48789 goto cleanup;
48790 }
48791- info->port.count++;
48792+ atomic_inc(&info->port.count);
48793 spin_unlock_irqrestore(&info->netlock, flags);
48794
48795- if (info->port.count == 1) {
48796+ if (atomic_read(&info->port.count) == 1) {
48797 /* 1st open on this device, init hardware */
48798 retval = startup(info);
48799 if (retval < 0)
48800@@ -3446,8 +3446,8 @@ cleanup:
48801 if (retval) {
48802 if (tty->count == 1)
48803 info->port.tty = NULL; /* tty layer will release tty struct */
48804- if(info->port.count)
48805- info->port.count--;
48806+ if (atomic_read(&info->port.count))
48807+ atomic_dec(&info->port.count);
48808 }
48809
48810 return retval;
48811@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48812 unsigned short new_crctype;
48813
48814 /* return error if TTY interface open */
48815- if (info->port.count)
48816+ if (atomic_read(&info->port.count))
48817 return -EBUSY;
48818
48819 switch (encoding)
48820@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48821
48822 /* arbitrate between network and tty opens */
48823 spin_lock_irqsave(&info->netlock, flags);
48824- if (info->port.count != 0 || info->netcount != 0) {
48825+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48826 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48827 spin_unlock_irqrestore(&info->netlock, flags);
48828 return -EBUSY;
48829@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48830 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48831
48832 /* return error if TTY interface open */
48833- if (info->port.count)
48834+ if (atomic_read(&info->port.count))
48835 return -EBUSY;
48836
48837 if (cmd != SIOCWANDEV)
48838diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48839index 1abf946..1ee34fc 100644
48840--- a/drivers/tty/synclink_gt.c
48841+++ b/drivers/tty/synclink_gt.c
48842@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48843 tty->driver_data = info;
48844 info->port.tty = tty;
48845
48846- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48847+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48848
48849 /* If port is closing, signal caller to try again */
48850 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48851@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48852 mutex_unlock(&info->port.mutex);
48853 goto cleanup;
48854 }
48855- info->port.count++;
48856+ atomic_inc(&info->port.count);
48857 spin_unlock_irqrestore(&info->netlock, flags);
48858
48859- if (info->port.count == 1) {
48860+ if (atomic_read(&info->port.count) == 1) {
48861 /* 1st open on this device, init hardware */
48862 retval = startup(info);
48863 if (retval < 0) {
48864@@ -715,8 +715,8 @@ cleanup:
48865 if (retval) {
48866 if (tty->count == 1)
48867 info->port.tty = NULL; /* tty layer will release tty struct */
48868- if(info->port.count)
48869- info->port.count--;
48870+ if(atomic_read(&info->port.count))
48871+ atomic_dec(&info->port.count);
48872 }
48873
48874 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48875@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48876
48877 if (sanity_check(info, tty->name, "close"))
48878 return;
48879- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48880+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48881
48882 if (tty_port_close_start(&info->port, tty, filp) == 0)
48883 goto cleanup;
48884@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48885 tty_port_close_end(&info->port, tty);
48886 info->port.tty = NULL;
48887 cleanup:
48888- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48889+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48890 }
48891
48892 static void hangup(struct tty_struct *tty)
48893@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48894 shutdown(info);
48895
48896 spin_lock_irqsave(&info->port.lock, flags);
48897- info->port.count = 0;
48898+ atomic_set(&info->port.count, 0);
48899 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48900 info->port.tty = NULL;
48901 spin_unlock_irqrestore(&info->port.lock, flags);
48902@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48903 unsigned short new_crctype;
48904
48905 /* return error if TTY interface open */
48906- if (info->port.count)
48907+ if (atomic_read(&info->port.count))
48908 return -EBUSY;
48909
48910 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48911@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48912
48913 /* arbitrate between network and tty opens */
48914 spin_lock_irqsave(&info->netlock, flags);
48915- if (info->port.count != 0 || info->netcount != 0) {
48916+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48917 DBGINFO(("%s hdlc_open busy\n", dev->name));
48918 spin_unlock_irqrestore(&info->netlock, flags);
48919 return -EBUSY;
48920@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48921 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48922
48923 /* return error if TTY interface open */
48924- if (info->port.count)
48925+ if (atomic_read(&info->port.count))
48926 return -EBUSY;
48927
48928 if (cmd != SIOCWANDEV)
48929@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48930 if (port == NULL)
48931 continue;
48932 spin_lock(&port->lock);
48933- if ((port->port.count || port->netcount) &&
48934+ if ((atomic_read(&port->port.count) || port->netcount) &&
48935 port->pending_bh && !port->bh_running &&
48936 !port->bh_requested) {
48937 DBGISR(("%s bh queued\n", port->device_name));
48938@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48939 spin_lock_irqsave(&info->lock, flags);
48940 if (!tty_hung_up_p(filp)) {
48941 extra_count = true;
48942- port->count--;
48943+ atomic_dec(&port->count);
48944 }
48945 spin_unlock_irqrestore(&info->lock, flags);
48946 port->blocked_open++;
48947@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48948 remove_wait_queue(&port->open_wait, &wait);
48949
48950 if (extra_count)
48951- port->count++;
48952+ atomic_inc(&port->count);
48953 port->blocked_open--;
48954
48955 if (!retval)
48956diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48957index dc6e969..5dc8786 100644
48958--- a/drivers/tty/synclinkmp.c
48959+++ b/drivers/tty/synclinkmp.c
48960@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48961
48962 if (debug_level >= DEBUG_LEVEL_INFO)
48963 printk("%s(%d):%s open(), old ref count = %d\n",
48964- __FILE__,__LINE__,tty->driver->name, info->port.count);
48965+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48966
48967 /* If port is closing, signal caller to try again */
48968 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48969@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48970 spin_unlock_irqrestore(&info->netlock, flags);
48971 goto cleanup;
48972 }
48973- info->port.count++;
48974+ atomic_inc(&info->port.count);
48975 spin_unlock_irqrestore(&info->netlock, flags);
48976
48977- if (info->port.count == 1) {
48978+ if (atomic_read(&info->port.count) == 1) {
48979 /* 1st open on this device, init hardware */
48980 retval = startup(info);
48981 if (retval < 0)
48982@@ -796,8 +796,8 @@ cleanup:
48983 if (retval) {
48984 if (tty->count == 1)
48985 info->port.tty = NULL; /* tty layer will release tty struct */
48986- if(info->port.count)
48987- info->port.count--;
48988+ if(atomic_read(&info->port.count))
48989+ atomic_dec(&info->port.count);
48990 }
48991
48992 return retval;
48993@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48994
48995 if (debug_level >= DEBUG_LEVEL_INFO)
48996 printk("%s(%d):%s close() entry, count=%d\n",
48997- __FILE__,__LINE__, info->device_name, info->port.count);
48998+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48999
49000 if (tty_port_close_start(&info->port, tty, filp) == 0)
49001 goto cleanup;
49002@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
49003 cleanup:
49004 if (debug_level >= DEBUG_LEVEL_INFO)
49005 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
49006- tty->driver->name, info->port.count);
49007+ tty->driver->name, atomic_read(&info->port.count));
49008 }
49009
49010 /* Called by tty_hangup() when a hangup is signaled.
49011@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
49012 shutdown(info);
49013
49014 spin_lock_irqsave(&info->port.lock, flags);
49015- info->port.count = 0;
49016+ atomic_set(&info->port.count, 0);
49017 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
49018 info->port.tty = NULL;
49019 spin_unlock_irqrestore(&info->port.lock, flags);
49020@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
49021 unsigned short new_crctype;
49022
49023 /* return error if TTY interface open */
49024- if (info->port.count)
49025+ if (atomic_read(&info->port.count))
49026 return -EBUSY;
49027
49028 switch (encoding)
49029@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
49030
49031 /* arbitrate between network and tty opens */
49032 spin_lock_irqsave(&info->netlock, flags);
49033- if (info->port.count != 0 || info->netcount != 0) {
49034+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
49035 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
49036 spin_unlock_irqrestore(&info->netlock, flags);
49037 return -EBUSY;
49038@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49039 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
49040
49041 /* return error if TTY interface open */
49042- if (info->port.count)
49043+ if (atomic_read(&info->port.count))
49044 return -EBUSY;
49045
49046 if (cmd != SIOCWANDEV)
49047@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
49048 * do not request bottom half processing if the
49049 * device is not open in a normal mode.
49050 */
49051- if ( port && (port->port.count || port->netcount) &&
49052+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
49053 port->pending_bh && !port->bh_running &&
49054 !port->bh_requested ) {
49055 if ( debug_level >= DEBUG_LEVEL_ISR )
49056@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49057
49058 if (debug_level >= DEBUG_LEVEL_INFO)
49059 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
49060- __FILE__,__LINE__, tty->driver->name, port->count );
49061+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49062
49063 spin_lock_irqsave(&info->lock, flags);
49064 if (!tty_hung_up_p(filp)) {
49065 extra_count = true;
49066- port->count--;
49067+ atomic_dec(&port->count);
49068 }
49069 spin_unlock_irqrestore(&info->lock, flags);
49070 port->blocked_open++;
49071@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49072
49073 if (debug_level >= DEBUG_LEVEL_INFO)
49074 printk("%s(%d):%s block_til_ready() count=%d\n",
49075- __FILE__,__LINE__, tty->driver->name, port->count );
49076+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49077
49078 tty_unlock(tty);
49079 schedule();
49080@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
49081 remove_wait_queue(&port->open_wait, &wait);
49082
49083 if (extra_count)
49084- port->count++;
49085+ atomic_inc(&port->count);
49086 port->blocked_open--;
49087
49088 if (debug_level >= DEBUG_LEVEL_INFO)
49089 printk("%s(%d):%s block_til_ready() after, count=%d\n",
49090- __FILE__,__LINE__, tty->driver->name, port->count );
49091+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
49092
49093 if (!retval)
49094 port->flags |= ASYNC_NORMAL_ACTIVE;
49095diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
49096index 40a9fe9..a3f10cc 100644
49097--- a/drivers/tty/sysrq.c
49098+++ b/drivers/tty/sysrq.c
49099@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
49100 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
49101 size_t count, loff_t *ppos)
49102 {
49103- if (count) {
49104+ if (count && capable(CAP_SYS_ADMIN)) {
49105 char c;
49106
49107 if (get_user(c, buf))
49108diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
49109index c74a00a..02cf211a 100644
49110--- a/drivers/tty/tty_io.c
49111+++ b/drivers/tty/tty_io.c
49112@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
49113
49114 void tty_default_fops(struct file_operations *fops)
49115 {
49116- *fops = tty_fops;
49117+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
49118 }
49119
49120 /*
49121diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
49122index 6458e11..6cfc218 100644
49123--- a/drivers/tty/tty_ldisc.c
49124+++ b/drivers/tty/tty_ldisc.c
49125@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
49126 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49127 tty_ldiscs[disc] = new_ldisc;
49128 new_ldisc->num = disc;
49129- new_ldisc->refcount = 0;
49130+ atomic_set(&new_ldisc->refcount, 0);
49131 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
49132
49133 return ret;
49134@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
49135 return -EINVAL;
49136
49137 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49138- if (tty_ldiscs[disc]->refcount)
49139+ if (atomic_read(&tty_ldiscs[disc]->refcount))
49140 ret = -EBUSY;
49141 else
49142 tty_ldiscs[disc] = NULL;
49143@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
49144 if (ldops) {
49145 ret = ERR_PTR(-EAGAIN);
49146 if (try_module_get(ldops->owner)) {
49147- ldops->refcount++;
49148+ atomic_inc(&ldops->refcount);
49149 ret = ldops;
49150 }
49151 }
49152@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
49153 unsigned long flags;
49154
49155 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
49156- ldops->refcount--;
49157+ atomic_dec(&ldops->refcount);
49158 module_put(ldops->owner);
49159 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
49160 }
49161diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
49162index f597e88..b7f68ed 100644
49163--- a/drivers/tty/tty_port.c
49164+++ b/drivers/tty/tty_port.c
49165@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
49166 unsigned long flags;
49167
49168 spin_lock_irqsave(&port->lock, flags);
49169- port->count = 0;
49170+ atomic_set(&port->count, 0);
49171 port->flags &= ~ASYNC_NORMAL_ACTIVE;
49172 tty = port->tty;
49173 if (tty)
49174@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
49175 /* The port lock protects the port counts */
49176 spin_lock_irqsave(&port->lock, flags);
49177 if (!tty_hung_up_p(filp))
49178- port->count--;
49179+ atomic_dec(&port->count);
49180 port->blocked_open++;
49181 spin_unlock_irqrestore(&port->lock, flags);
49182
49183@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
49184 we must not mess that up further */
49185 spin_lock_irqsave(&port->lock, flags);
49186 if (!tty_hung_up_p(filp))
49187- port->count++;
49188+ atomic_inc(&port->count);
49189 port->blocked_open--;
49190 if (retval == 0)
49191 port->flags |= ASYNC_NORMAL_ACTIVE;
49192@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
49193 return 0;
49194 }
49195
49196- if (tty->count == 1 && port->count != 1) {
49197+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
49198 printk(KERN_WARNING
49199 "tty_port_close_start: tty->count = 1 port count = %d.\n",
49200- port->count);
49201- port->count = 1;
49202+ atomic_read(&port->count));
49203+ atomic_set(&port->count, 1);
49204 }
49205- if (--port->count < 0) {
49206+ if (atomic_dec_return(&port->count) < 0) {
49207 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
49208- port->count);
49209- port->count = 0;
49210+ atomic_read(&port->count));
49211+ atomic_set(&port->count, 0);
49212 }
49213
49214- if (port->count) {
49215+ if (atomic_read(&port->count)) {
49216 spin_unlock_irqrestore(&port->lock, flags);
49217 if (port->ops->drop)
49218 port->ops->drop(port);
49219@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
49220 {
49221 spin_lock_irq(&port->lock);
49222 if (!tty_hung_up_p(filp))
49223- ++port->count;
49224+ atomic_inc(&port->count);
49225 spin_unlock_irq(&port->lock);
49226 tty_port_tty_set(port, tty);
49227
49228diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
49229index d0e3a44..5f8b754 100644
49230--- a/drivers/tty/vt/keyboard.c
49231+++ b/drivers/tty/vt/keyboard.c
49232@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
49233 kbd->kbdmode == VC_OFF) &&
49234 value != KVAL(K_SAK))
49235 return; /* SAK is allowed even in raw mode */
49236+
49237+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49238+ {
49239+ void *func = fn_handler[value];
49240+ if (func == fn_show_state || func == fn_show_ptregs ||
49241+ func == fn_show_mem)
49242+ return;
49243+ }
49244+#endif
49245+
49246 fn_handler[value](vc);
49247 }
49248
49249@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49250 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
49251 return -EFAULT;
49252
49253- if (!capable(CAP_SYS_TTY_CONFIG))
49254- perm = 0;
49255-
49256 switch (cmd) {
49257 case KDGKBENT:
49258 /* Ensure another thread doesn't free it under us */
49259@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49260 spin_unlock_irqrestore(&kbd_event_lock, flags);
49261 return put_user(val, &user_kbe->kb_value);
49262 case KDSKBENT:
49263+ if (!capable(CAP_SYS_TTY_CONFIG))
49264+ perm = 0;
49265+
49266 if (!perm)
49267 return -EPERM;
49268 if (!i && v == K_NOSUCHMAP) {
49269@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49270 int i, j, k;
49271 int ret;
49272
49273- if (!capable(CAP_SYS_TTY_CONFIG))
49274- perm = 0;
49275-
49276 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
49277 if (!kbs) {
49278 ret = -ENOMEM;
49279@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49280 kfree(kbs);
49281 return ((p && *p) ? -EOVERFLOW : 0);
49282 case KDSKBSENT:
49283+ if (!capable(CAP_SYS_TTY_CONFIG))
49284+ perm = 0;
49285+
49286 if (!perm) {
49287 ret = -EPERM;
49288 goto reterr;
49289diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
49290index 0e808cf..d7d274b 100644
49291--- a/drivers/uio/uio.c
49292+++ b/drivers/uio/uio.c
49293@@ -25,6 +25,7 @@
49294 #include <linux/kobject.h>
49295 #include <linux/cdev.h>
49296 #include <linux/uio_driver.h>
49297+#include <asm/local.h>
49298
49299 #define UIO_MAX_DEVICES (1U << MINORBITS)
49300
49301@@ -32,7 +33,7 @@ struct uio_device {
49302 struct module *owner;
49303 struct device *dev;
49304 int minor;
49305- atomic_t event;
49306+ atomic_unchecked_t event;
49307 struct fasync_struct *async_queue;
49308 wait_queue_head_t wait;
49309 struct uio_info *info;
49310@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
49311 struct device_attribute *attr, char *buf)
49312 {
49313 struct uio_device *idev = dev_get_drvdata(dev);
49314- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49315+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49316 }
49317 static DEVICE_ATTR_RO(event);
49318
49319@@ -401,7 +402,7 @@ void uio_event_notify(struct uio_info *info)
49320 {
49321 struct uio_device *idev = info->uio_dev;
49322
49323- atomic_inc(&idev->event);
49324+ atomic_inc_unchecked(&idev->event);
49325 wake_up_interruptible(&idev->wait);
49326 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49327 }
49328@@ -454,7 +455,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49329 }
49330
49331 listener->dev = idev;
49332- listener->event_count = atomic_read(&idev->event);
49333+ listener->event_count = atomic_read_unchecked(&idev->event);
49334 filep->private_data = listener;
49335
49336 if (idev->info->open) {
49337@@ -505,7 +506,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49338 return -EIO;
49339
49340 poll_wait(filep, &idev->wait, wait);
49341- if (listener->event_count != atomic_read(&idev->event))
49342+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49343 return POLLIN | POLLRDNORM;
49344 return 0;
49345 }
49346@@ -530,7 +531,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49347 do {
49348 set_current_state(TASK_INTERRUPTIBLE);
49349
49350- event_count = atomic_read(&idev->event);
49351+ event_count = atomic_read_unchecked(&idev->event);
49352 if (event_count != listener->event_count) {
49353 if (copy_to_user(buf, &event_count, count))
49354 retval = -EFAULT;
49355@@ -587,9 +588,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
49356 static int uio_find_mem_index(struct vm_area_struct *vma)
49357 {
49358 struct uio_device *idev = vma->vm_private_data;
49359+ unsigned long size;
49360
49361 if (vma->vm_pgoff < MAX_UIO_MAPS) {
49362- if (idev->info->mem[vma->vm_pgoff].size == 0)
49363+ size = idev->info->mem[vma->vm_pgoff].size;
49364+ if (size == 0)
49365+ return -1;
49366+ if (vma->vm_end - vma->vm_start > size)
49367 return -1;
49368 return (int)vma->vm_pgoff;
49369 }
49370@@ -647,6 +652,8 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
49371 return -EINVAL;
49372 mem = idev->info->mem + mi;
49373
49374+ if (mem->addr & ~PAGE_MASK)
49375+ return -ENODEV;
49376 if (vma->vm_end - vma->vm_start > mem->size)
49377 return -EINVAL;
49378
49379@@ -818,7 +825,7 @@ int __uio_register_device(struct module *owner,
49380 idev->owner = owner;
49381 idev->info = info;
49382 init_waitqueue_head(&idev->wait);
49383- atomic_set(&idev->event, 0);
49384+ atomic_set_unchecked(&idev->event, 0);
49385
49386 ret = uio_get_minor(idev);
49387 if (ret)
49388diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49389index 8a7eb77..c00402f 100644
49390--- a/drivers/usb/atm/cxacru.c
49391+++ b/drivers/usb/atm/cxacru.c
49392@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49393 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49394 if (ret < 2)
49395 return -EINVAL;
49396- if (index < 0 || index > 0x7f)
49397+ if (index > 0x7f)
49398 return -EINVAL;
49399 pos += tmp;
49400
49401diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49402index 25a7bfc..57f3cf5 100644
49403--- a/drivers/usb/atm/usbatm.c
49404+++ b/drivers/usb/atm/usbatm.c
49405@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49406 if (printk_ratelimit())
49407 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49408 __func__, vpi, vci);
49409- atomic_inc(&vcc->stats->rx_err);
49410+ atomic_inc_unchecked(&vcc->stats->rx_err);
49411 return;
49412 }
49413
49414@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49415 if (length > ATM_MAX_AAL5_PDU) {
49416 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49417 __func__, length, vcc);
49418- atomic_inc(&vcc->stats->rx_err);
49419+ atomic_inc_unchecked(&vcc->stats->rx_err);
49420 goto out;
49421 }
49422
49423@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49424 if (sarb->len < pdu_length) {
49425 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49426 __func__, pdu_length, sarb->len, vcc);
49427- atomic_inc(&vcc->stats->rx_err);
49428+ atomic_inc_unchecked(&vcc->stats->rx_err);
49429 goto out;
49430 }
49431
49432 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49433 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49434 __func__, vcc);
49435- atomic_inc(&vcc->stats->rx_err);
49436+ atomic_inc_unchecked(&vcc->stats->rx_err);
49437 goto out;
49438 }
49439
49440@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49441 if (printk_ratelimit())
49442 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49443 __func__, length);
49444- atomic_inc(&vcc->stats->rx_drop);
49445+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49446 goto out;
49447 }
49448
49449@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49450
49451 vcc->push(vcc, skb);
49452
49453- atomic_inc(&vcc->stats->rx);
49454+ atomic_inc_unchecked(&vcc->stats->rx);
49455 out:
49456 skb_trim(sarb, 0);
49457 }
49458@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
49459 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49460
49461 usbatm_pop(vcc, skb);
49462- atomic_inc(&vcc->stats->tx);
49463+ atomic_inc_unchecked(&vcc->stats->tx);
49464
49465 skb = skb_dequeue(&instance->sndqueue);
49466 }
49467@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49468 if (!left--)
49469 return sprintf(page,
49470 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49471- atomic_read(&atm_dev->stats.aal5.tx),
49472- atomic_read(&atm_dev->stats.aal5.tx_err),
49473- atomic_read(&atm_dev->stats.aal5.rx),
49474- atomic_read(&atm_dev->stats.aal5.rx_err),
49475- atomic_read(&atm_dev->stats.aal5.rx_drop));
49476+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49477+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49478+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49479+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49480+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49481
49482 if (!left--) {
49483 if (instance->disconnected)
49484diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49485index 2a3bbdf..91d72cf 100644
49486--- a/drivers/usb/core/devices.c
49487+++ b/drivers/usb/core/devices.c
49488@@ -126,7 +126,7 @@ static const char format_endpt[] =
49489 * time it gets called.
49490 */
49491 static struct device_connect_event {
49492- atomic_t count;
49493+ atomic_unchecked_t count;
49494 wait_queue_head_t wait;
49495 } device_event = {
49496 .count = ATOMIC_INIT(1),
49497@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49498
49499 void usbfs_conn_disc_event(void)
49500 {
49501- atomic_add(2, &device_event.count);
49502+ atomic_add_unchecked(2, &device_event.count);
49503 wake_up(&device_event.wait);
49504 }
49505
49506@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49507
49508 poll_wait(file, &device_event.wait, wait);
49509
49510- event_count = atomic_read(&device_event.count);
49511+ event_count = atomic_read_unchecked(&device_event.count);
49512 if (file->f_version != event_count) {
49513 file->f_version = event_count;
49514 return POLLIN | POLLRDNORM;
49515diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
49516index 71dc5d7..6135ff2 100644
49517--- a/drivers/usb/core/devio.c
49518+++ b/drivers/usb/core/devio.c
49519@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
49520 struct dev_state *ps = file->private_data;
49521 struct usb_device *dev = ps->dev;
49522 ssize_t ret = 0;
49523- unsigned len;
49524+ size_t len;
49525 loff_t pos;
49526 int i;
49527
49528@@ -229,13 +229,13 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
49529 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
49530 struct usb_config_descriptor *config =
49531 (struct usb_config_descriptor *)dev->rawdescriptors[i];
49532- unsigned int length = le16_to_cpu(config->wTotalLength);
49533+ size_t length = le16_to_cpu(config->wTotalLength);
49534
49535 if (*ppos < pos + length) {
49536
49537 /* The descriptor may claim to be longer than it
49538 * really is. Here is the actual allocated length. */
49539- unsigned alloclen =
49540+ size_t alloclen =
49541 le16_to_cpu(dev->config[i].desc.wTotalLength);
49542
49543 len = length - (*ppos - pos);
49544diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49545index f20a044..d1059aa 100644
49546--- a/drivers/usb/core/hcd.c
49547+++ b/drivers/usb/core/hcd.c
49548@@ -1552,7 +1552,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49549 */
49550 usb_get_urb(urb);
49551 atomic_inc(&urb->use_count);
49552- atomic_inc(&urb->dev->urbnum);
49553+ atomic_inc_unchecked(&urb->dev->urbnum);
49554 usbmon_urb_submit(&hcd->self, urb);
49555
49556 /* NOTE requirements on root-hub callers (usbfs and the hub
49557@@ -1579,7 +1579,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49558 urb->hcpriv = NULL;
49559 INIT_LIST_HEAD(&urb->urb_list);
49560 atomic_dec(&urb->use_count);
49561- atomic_dec(&urb->dev->urbnum);
49562+ atomic_dec_unchecked(&urb->dev->urbnum);
49563 if (atomic_read(&urb->reject))
49564 wake_up(&usb_kill_urb_queue);
49565 usb_put_urb(urb);
49566diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49567index 243c672..8b66fbb 100644
49568--- a/drivers/usb/core/hub.c
49569+++ b/drivers/usb/core/hub.c
49570@@ -27,6 +27,7 @@
49571 #include <linux/freezer.h>
49572 #include <linux/random.h>
49573 #include <linux/pm_qos.h>
49574+#include <linux/grsecurity.h>
49575
49576 #include <asm/uaccess.h>
49577 #include <asm/byteorder.h>
49578@@ -4467,6 +4468,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49579 goto done;
49580 return;
49581 }
49582+
49583+ if (gr_handle_new_usb())
49584+ goto done;
49585+
49586 if (hub_is_superspeed(hub->hdev))
49587 unit_load = 150;
49588 else
49589diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49590index 82927e1..4993dbf 100644
49591--- a/drivers/usb/core/message.c
49592+++ b/drivers/usb/core/message.c
49593@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49594 * Return: If successful, the number of bytes transferred. Otherwise, a negative
49595 * error number.
49596 */
49597-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49598+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49599 __u8 requesttype, __u16 value, __u16 index, void *data,
49600 __u16 size, int timeout)
49601 {
49602@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
49603 * If successful, 0. Otherwise a negative error number. The number of actual
49604 * bytes transferred will be stored in the @actual_length paramater.
49605 */
49606-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
49607+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
49608 void *data, int len, int *actual_length, int timeout)
49609 {
49610 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
49611@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
49612 * bytes transferred will be stored in the @actual_length paramater.
49613 *
49614 */
49615-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
49616+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
49617 void *data, int len, int *actual_length, int timeout)
49618 {
49619 struct urb *urb;
49620diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49621index ca516ac..6c36ee4 100644
49622--- a/drivers/usb/core/sysfs.c
49623+++ b/drivers/usb/core/sysfs.c
49624@@ -236,7 +236,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
49625 struct usb_device *udev;
49626
49627 udev = to_usb_device(dev);
49628- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49629+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49630 }
49631 static DEVICE_ATTR_RO(urbnum);
49632
49633diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49634index 0a6ee2e..6f8d7e8 100644
49635--- a/drivers/usb/core/usb.c
49636+++ b/drivers/usb/core/usb.c
49637@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49638 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49639 dev->state = USB_STATE_ATTACHED;
49640 dev->lpm_disable_count = 1;
49641- atomic_set(&dev->urbnum, 0);
49642+ atomic_set_unchecked(&dev->urbnum, 0);
49643
49644 INIT_LIST_HEAD(&dev->ep0.urb_list);
49645 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49646diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49647index 5452c0f..34c9145 100644
49648--- a/drivers/usb/dwc3/gadget.c
49649+++ b/drivers/usb/dwc3/gadget.c
49650@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49651 if (!usb_endpoint_xfer_isoc(desc))
49652 return 0;
49653
49654- memset(&trb_link, 0, sizeof(trb_link));
49655-
49656 /* Link TRB for ISOC. The HWO bit is never reset */
49657 trb_st_hw = &dep->trb_pool[0];
49658
49659diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49660index 5e29dde..eca992f 100644
49661--- a/drivers/usb/early/ehci-dbgp.c
49662+++ b/drivers/usb/early/ehci-dbgp.c
49663@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49664
49665 #ifdef CONFIG_KGDB
49666 static struct kgdb_io kgdbdbgp_io_ops;
49667-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49668+static struct kgdb_io kgdbdbgp_io_ops_console;
49669+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49670 #else
49671 #define dbgp_kgdb_mode (0)
49672 #endif
49673@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49674 .write_char = kgdbdbgp_write_char,
49675 };
49676
49677+static struct kgdb_io kgdbdbgp_io_ops_console = {
49678+ .name = "kgdbdbgp",
49679+ .read_char = kgdbdbgp_read_char,
49680+ .write_char = kgdbdbgp_write_char,
49681+ .is_console = 1
49682+};
49683+
49684 static int kgdbdbgp_wait_time;
49685
49686 static int __init kgdbdbgp_parse_config(char *str)
49687@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49688 ptr++;
49689 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49690 }
49691- kgdb_register_io_module(&kgdbdbgp_io_ops);
49692- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49693+ if (early_dbgp_console.index != -1)
49694+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49695+ else
49696+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49697
49698 return 0;
49699 }
49700diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49701index b369292..9f3ba40 100644
49702--- a/drivers/usb/gadget/u_serial.c
49703+++ b/drivers/usb/gadget/u_serial.c
49704@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49705 spin_lock_irq(&port->port_lock);
49706
49707 /* already open? Great. */
49708- if (port->port.count) {
49709+ if (atomic_read(&port->port.count)) {
49710 status = 0;
49711- port->port.count++;
49712+ atomic_inc(&port->port.count);
49713
49714 /* currently opening/closing? wait ... */
49715 } else if (port->openclose) {
49716@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49717 tty->driver_data = port;
49718 port->port.tty = tty;
49719
49720- port->port.count = 1;
49721+ atomic_set(&port->port.count, 1);
49722 port->openclose = false;
49723
49724 /* if connected, start the I/O stream */
49725@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49726
49727 spin_lock_irq(&port->port_lock);
49728
49729- if (port->port.count != 1) {
49730- if (port->port.count == 0)
49731+ if (atomic_read(&port->port.count) != 1) {
49732+ if (atomic_read(&port->port.count) == 0)
49733 WARN_ON(1);
49734 else
49735- --port->port.count;
49736+ atomic_dec(&port->port.count);
49737 goto exit;
49738 }
49739
49740@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49741 * and sleep if necessary
49742 */
49743 port->openclose = true;
49744- port->port.count = 0;
49745+ atomic_set(&port->port.count, 0);
49746
49747 gser = port->port_usb;
49748 if (gser && gser->disconnect)
49749@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49750 int cond;
49751
49752 spin_lock_irq(&port->port_lock);
49753- cond = (port->port.count == 0) && !port->openclose;
49754+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49755 spin_unlock_irq(&port->port_lock);
49756 return cond;
49757 }
49758@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49759 /* if it's already open, start I/O ... and notify the serial
49760 * protocol about open/close status (connect/disconnect).
49761 */
49762- if (port->port.count) {
49763+ if (atomic_read(&port->port.count)) {
49764 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49765 gs_start_io(port);
49766 if (gser->connect)
49767@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49768
49769 port->port_usb = NULL;
49770 gser->ioport = NULL;
49771- if (port->port.count > 0 || port->openclose) {
49772+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49773 wake_up_interruptible(&port->drain_wait);
49774 if (port->port.tty)
49775 tty_hangup(port->port.tty);
49776@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49777
49778 /* finally, free any unused/unusable I/O buffers */
49779 spin_lock_irqsave(&port->port_lock, flags);
49780- if (port->port.count == 0 && !port->openclose)
49781+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49782 gs_buf_free(&port->port_write_buf);
49783 gs_free_requests(gser->out, &port->read_pool, NULL);
49784 gs_free_requests(gser->out, &port->read_queue, NULL);
49785diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
49786index 835fc08..f8b22bf 100644
49787--- a/drivers/usb/host/ehci-hub.c
49788+++ b/drivers/usb/host/ehci-hub.c
49789@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
49790 urb->transfer_flags = URB_DIR_IN;
49791 usb_get_urb(urb);
49792 atomic_inc(&urb->use_count);
49793- atomic_inc(&urb->dev->urbnum);
49794+ atomic_inc_unchecked(&urb->dev->urbnum);
49795 urb->setup_dma = dma_map_single(
49796 hcd->self.controller,
49797 urb->setup_packet,
49798@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
49799 urb->status = -EINPROGRESS;
49800 usb_get_urb(urb);
49801 atomic_inc(&urb->use_count);
49802- atomic_inc(&urb->dev->urbnum);
49803+ atomic_inc_unchecked(&urb->dev->urbnum);
49804 retval = submit_single_step_set_feature(hcd, urb, 0);
49805 if (!retval && !wait_for_completion_timeout(&done,
49806 msecs_to_jiffies(2000))) {
49807diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49808index ba6a5d6..f88f7f3 100644
49809--- a/drivers/usb/misc/appledisplay.c
49810+++ b/drivers/usb/misc/appledisplay.c
49811@@ -83,7 +83,7 @@ struct appledisplay {
49812 spinlock_t lock;
49813 };
49814
49815-static atomic_t count_displays = ATOMIC_INIT(0);
49816+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49817 static struct workqueue_struct *wq;
49818
49819 static void appledisplay_complete(struct urb *urb)
49820@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49821
49822 /* Register backlight device */
49823 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49824- atomic_inc_return(&count_displays) - 1);
49825+ atomic_inc_return_unchecked(&count_displays) - 1);
49826 memset(&props, 0, sizeof(struct backlight_properties));
49827 props.type = BACKLIGHT_RAW;
49828 props.max_brightness = 0xff;
49829diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49830index c69bb50..215ef37 100644
49831--- a/drivers/usb/serial/console.c
49832+++ b/drivers/usb/serial/console.c
49833@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49834
49835 info->port = port;
49836
49837- ++port->port.count;
49838+ atomic_inc(&port->port.count);
49839 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49840 if (serial->type->set_termios) {
49841 /*
49842@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
49843 }
49844 /* Now that any required fake tty operations are completed restore
49845 * the tty port count */
49846- --port->port.count;
49847+ atomic_dec(&port->port.count);
49848 /* The console is special in terms of closing the device so
49849 * indicate this port is now acting as a system console. */
49850 port->port.console = 1;
49851@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
49852 free_tty:
49853 kfree(tty);
49854 reset_open_count:
49855- port->port.count = 0;
49856+ atomic_set(&port->port.count, 0);
49857 usb_autopm_put_interface(serial->interface);
49858 error_get_interface:
49859 usb_serial_put(serial);
49860@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
49861 static void usb_console_write(struct console *co,
49862 const char *buf, unsigned count)
49863 {
49864- static struct usbcons_info *info = &usbcons_info;
49865+ struct usbcons_info *info = &usbcons_info;
49866 struct usb_serial_port *port = info->port;
49867 struct usb_serial *serial;
49868 int retval = -ENODEV;
49869diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49870index 75f70f0..d467e1a 100644
49871--- a/drivers/usb/storage/usb.h
49872+++ b/drivers/usb/storage/usb.h
49873@@ -63,7 +63,7 @@ struct us_unusual_dev {
49874 __u8 useProtocol;
49875 __u8 useTransport;
49876 int (*initFunction)(struct us_data *);
49877-};
49878+} __do_const;
49879
49880
49881 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49882diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49883index cf250c2..ad9d904 100644
49884--- a/drivers/usb/wusbcore/wa-hc.h
49885+++ b/drivers/usb/wusbcore/wa-hc.h
49886@@ -199,7 +199,7 @@ struct wahc {
49887 spinlock_t xfer_list_lock;
49888 struct work_struct xfer_enqueue_work;
49889 struct work_struct xfer_error_work;
49890- atomic_t xfer_id_count;
49891+ atomic_unchecked_t xfer_id_count;
49892 };
49893
49894
49895@@ -255,7 +255,7 @@ static inline void wa_init(struct wahc *wa)
49896 spin_lock_init(&wa->xfer_list_lock);
49897 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
49898 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
49899- atomic_set(&wa->xfer_id_count, 1);
49900+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49901 }
49902
49903 /**
49904diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49905index 3dcf66f..8faaf6e 100644
49906--- a/drivers/usb/wusbcore/wa-xfer.c
49907+++ b/drivers/usb/wusbcore/wa-xfer.c
49908@@ -300,7 +300,7 @@ out:
49909 */
49910 static void wa_xfer_id_init(struct wa_xfer *xfer)
49911 {
49912- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49913+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49914 }
49915
49916 /*
49917diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49918index 1eab4ac..e21efc9 100644
49919--- a/drivers/vfio/vfio.c
49920+++ b/drivers/vfio/vfio.c
49921@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49922 return 0;
49923
49924 /* TODO Prevent device auto probing */
49925- WARN("Device %s added to live group %d!\n", dev_name(dev),
49926+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49927 iommu_group_id(group->iommu_group));
49928
49929 return 0;
49930diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49931index 5174eba..86e764a 100644
49932--- a/drivers/vhost/vringh.c
49933+++ b/drivers/vhost/vringh.c
49934@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49935
49936 static inline int putu16_kern(u16 *p, u16 val)
49937 {
49938- ACCESS_ONCE(*p) = val;
49939+ ACCESS_ONCE_RW(*p) = val;
49940 return 0;
49941 }
49942
49943diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
49944index e43401a..dd49b3f 100644
49945--- a/drivers/video/arcfb.c
49946+++ b/drivers/video/arcfb.c
49947@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
49948 return -ENOSPC;
49949
49950 err = 0;
49951- if ((count + p) > fbmemlength) {
49952+ if (count > (fbmemlength - p)) {
49953 count = fbmemlength - p;
49954 err = -ENOSPC;
49955 }
49956diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49957index a4dfe8c..297ddd9 100644
49958--- a/drivers/video/aty/aty128fb.c
49959+++ b/drivers/video/aty/aty128fb.c
49960@@ -149,7 +149,7 @@ enum {
49961 };
49962
49963 /* Must match above enum */
49964-static char * const r128_family[] = {
49965+static const char * const r128_family[] = {
49966 "AGP",
49967 "PCI",
49968 "PRO AGP",
49969diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49970index 9b0f12c..024673d 100644
49971--- a/drivers/video/aty/atyfb_base.c
49972+++ b/drivers/video/aty/atyfb_base.c
49973@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49974 par->accel_flags = var->accel_flags; /* hack */
49975
49976 if (var->accel_flags) {
49977- info->fbops->fb_sync = atyfb_sync;
49978+ pax_open_kernel();
49979+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49980+ pax_close_kernel();
49981 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49982 } else {
49983- info->fbops->fb_sync = NULL;
49984+ pax_open_kernel();
49985+ *(void **)&info->fbops->fb_sync = NULL;
49986+ pax_close_kernel();
49987 info->flags |= FBINFO_HWACCEL_DISABLED;
49988 }
49989
49990diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49991index 95ec042..e6affdd 100644
49992--- a/drivers/video/aty/mach64_cursor.c
49993+++ b/drivers/video/aty/mach64_cursor.c
49994@@ -7,6 +7,7 @@
49995 #include <linux/string.h>
49996
49997 #include <asm/io.h>
49998+#include <asm/pgtable.h>
49999
50000 #ifdef __sparc__
50001 #include <asm/fbio.h>
50002@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
50003 info->sprite.buf_align = 16; /* and 64 lines tall. */
50004 info->sprite.flags = FB_PIXMAP_IO;
50005
50006- info->fbops->fb_cursor = atyfb_cursor;
50007+ pax_open_kernel();
50008+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
50009+ pax_close_kernel();
50010
50011 return 0;
50012 }
50013diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
50014index bca6ccc..252107e 100644
50015--- a/drivers/video/backlight/kb3886_bl.c
50016+++ b/drivers/video/backlight/kb3886_bl.c
50017@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
50018 static unsigned long kb3886bl_flags;
50019 #define KB3886BL_SUSPENDED 0x01
50020
50021-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
50022+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
50023 {
50024 .ident = "Sahara Touch-iT",
50025 .matches = {
50026diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
50027index 900aa4e..6d49418 100644
50028--- a/drivers/video/fb_defio.c
50029+++ b/drivers/video/fb_defio.c
50030@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
50031
50032 BUG_ON(!fbdefio);
50033 mutex_init(&fbdefio->lock);
50034- info->fbops->fb_mmap = fb_deferred_io_mmap;
50035+ pax_open_kernel();
50036+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
50037+ pax_close_kernel();
50038 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
50039 INIT_LIST_HEAD(&fbdefio->pagelist);
50040 if (fbdefio->delay == 0) /* set a default of 1 s */
50041@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
50042 page->mapping = NULL;
50043 }
50044
50045- info->fbops->fb_mmap = NULL;
50046+ *(void **)&info->fbops->fb_mmap = NULL;
50047 mutex_destroy(&fbdefio->lock);
50048 }
50049 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
50050diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
50051index dacaf74..8478a46 100644
50052--- a/drivers/video/fbmem.c
50053+++ b/drivers/video/fbmem.c
50054@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
50055 image->dx += image->width + 8;
50056 }
50057 } else if (rotate == FB_ROTATE_UD) {
50058- for (x = 0; x < num && image->dx >= 0; x++) {
50059+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
50060 info->fbops->fb_imageblit(info, image);
50061 image->dx -= image->width + 8;
50062 }
50063@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
50064 image->dy += image->height + 8;
50065 }
50066 } else if (rotate == FB_ROTATE_CCW) {
50067- for (x = 0; x < num && image->dy >= 0; x++) {
50068+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
50069 info->fbops->fb_imageblit(info, image);
50070 image->dy -= image->height + 8;
50071 }
50072@@ -1175,7 +1175,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
50073 return -EFAULT;
50074 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
50075 return -EINVAL;
50076- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
50077+ if (con2fb.framebuffer >= FB_MAX)
50078 return -EINVAL;
50079 if (!registered_fb[con2fb.framebuffer])
50080 request_module("fb%d", con2fb.framebuffer);
50081diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
50082index 8d456dc..b4fa44b 100644
50083--- a/drivers/video/hyperv_fb.c
50084+++ b/drivers/video/hyperv_fb.c
50085@@ -233,7 +233,7 @@ static uint screen_fb_size;
50086 static inline int synthvid_send(struct hv_device *hdev,
50087 struct synthvid_msg *msg)
50088 {
50089- static atomic64_t request_id = ATOMIC64_INIT(0);
50090+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
50091 int ret;
50092
50093 msg->pipe_hdr.type = PIPE_MSG_DATA;
50094@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
50095
50096 ret = vmbus_sendpacket(hdev->channel, msg,
50097 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
50098- atomic64_inc_return(&request_id),
50099+ atomic64_inc_return_unchecked(&request_id),
50100 VM_PKT_DATA_INBAND, 0);
50101
50102 if (ret)
50103diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
50104index 7672d2e..b56437f 100644
50105--- a/drivers/video/i810/i810_accel.c
50106+++ b/drivers/video/i810/i810_accel.c
50107@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
50108 }
50109 }
50110 printk("ringbuffer lockup!!!\n");
50111+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
50112 i810_report_error(mmio);
50113 par->dev_flags |= LOCKUP;
50114 info->pixmap.scan_align = 1;
50115diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
50116index 3c14e43..2630570 100644
50117--- a/drivers/video/logo/logo_linux_clut224.ppm
50118+++ b/drivers/video/logo/logo_linux_clut224.ppm
50119@@ -2,1603 +2,1123 @@ P3
50120 # Standard 224-color Linux logo
50121 80 80
50122 255
50123- 0 0 0 0 0 0 0 0 0 0 0 0
50124- 0 0 0 0 0 0 0 0 0 0 0 0
50125- 0 0 0 0 0 0 0 0 0 0 0 0
50126- 0 0 0 0 0 0 0 0 0 0 0 0
50127- 0 0 0 0 0 0 0 0 0 0 0 0
50128- 0 0 0 0 0 0 0 0 0 0 0 0
50129- 0 0 0 0 0 0 0 0 0 0 0 0
50130- 0 0 0 0 0 0 0 0 0 0 0 0
50131- 0 0 0 0 0 0 0 0 0 0 0 0
50132- 6 6 6 6 6 6 10 10 10 10 10 10
50133- 10 10 10 6 6 6 6 6 6 6 6 6
50134- 0 0 0 0 0 0 0 0 0 0 0 0
50135- 0 0 0 0 0 0 0 0 0 0 0 0
50136- 0 0 0 0 0 0 0 0 0 0 0 0
50137- 0 0 0 0 0 0 0 0 0 0 0 0
50138- 0 0 0 0 0 0 0 0 0 0 0 0
50139- 0 0 0 0 0 0 0 0 0 0 0 0
50140- 0 0 0 0 0 0 0 0 0 0 0 0
50141- 0 0 0 0 0 0 0 0 0 0 0 0
50142- 0 0 0 0 0 0 0 0 0 0 0 0
50143- 0 0 0 0 0 0 0 0 0 0 0 0
50144- 0 0 0 0 0 0 0 0 0 0 0 0
50145- 0 0 0 0 0 0 0 0 0 0 0 0
50146- 0 0 0 0 0 0 0 0 0 0 0 0
50147- 0 0 0 0 0 0 0 0 0 0 0 0
50148- 0 0 0 0 0 0 0 0 0 0 0 0
50149- 0 0 0 0 0 0 0 0 0 0 0 0
50150- 0 0 0 0 0 0 0 0 0 0 0 0
50151- 0 0 0 6 6 6 10 10 10 14 14 14
50152- 22 22 22 26 26 26 30 30 30 34 34 34
50153- 30 30 30 30 30 30 26 26 26 18 18 18
50154- 14 14 14 10 10 10 6 6 6 0 0 0
50155- 0 0 0 0 0 0 0 0 0 0 0 0
50156- 0 0 0 0 0 0 0 0 0 0 0 0
50157- 0 0 0 0 0 0 0 0 0 0 0 0
50158- 0 0 0 0 0 0 0 0 0 0 0 0
50159- 0 0 0 0 0 0 0 0 0 0 0 0
50160- 0 0 0 0 0 0 0 0 0 0 0 0
50161- 0 0 0 0 0 0 0 0 0 0 0 0
50162- 0 0 0 0 0 0 0 0 0 0 0 0
50163- 0 0 0 0 0 0 0 0 0 0 0 0
50164- 0 0 0 0 0 1 0 0 1 0 0 0
50165- 0 0 0 0 0 0 0 0 0 0 0 0
50166- 0 0 0 0 0 0 0 0 0 0 0 0
50167- 0 0 0 0 0 0 0 0 0 0 0 0
50168- 0 0 0 0 0 0 0 0 0 0 0 0
50169- 0 0 0 0 0 0 0 0 0 0 0 0
50170- 0 0 0 0 0 0 0 0 0 0 0 0
50171- 6 6 6 14 14 14 26 26 26 42 42 42
50172- 54 54 54 66 66 66 78 78 78 78 78 78
50173- 78 78 78 74 74 74 66 66 66 54 54 54
50174- 42 42 42 26 26 26 18 18 18 10 10 10
50175- 6 6 6 0 0 0 0 0 0 0 0 0
50176- 0 0 0 0 0 0 0 0 0 0 0 0
50177- 0 0 0 0 0 0 0 0 0 0 0 0
50178- 0 0 0 0 0 0 0 0 0 0 0 0
50179- 0 0 0 0 0 0 0 0 0 0 0 0
50180- 0 0 0 0 0 0 0 0 0 0 0 0
50181- 0 0 0 0 0 0 0 0 0 0 0 0
50182- 0 0 0 0 0 0 0 0 0 0 0 0
50183- 0 0 0 0 0 0 0 0 0 0 0 0
50184- 0 0 1 0 0 0 0 0 0 0 0 0
50185- 0 0 0 0 0 0 0 0 0 0 0 0
50186- 0 0 0 0 0 0 0 0 0 0 0 0
50187- 0 0 0 0 0 0 0 0 0 0 0 0
50188- 0 0 0 0 0 0 0 0 0 0 0 0
50189- 0 0 0 0 0 0 0 0 0 0 0 0
50190- 0 0 0 0 0 0 0 0 0 10 10 10
50191- 22 22 22 42 42 42 66 66 66 86 86 86
50192- 66 66 66 38 38 38 38 38 38 22 22 22
50193- 26 26 26 34 34 34 54 54 54 66 66 66
50194- 86 86 86 70 70 70 46 46 46 26 26 26
50195- 14 14 14 6 6 6 0 0 0 0 0 0
50196- 0 0 0 0 0 0 0 0 0 0 0 0
50197- 0 0 0 0 0 0 0 0 0 0 0 0
50198- 0 0 0 0 0 0 0 0 0 0 0 0
50199- 0 0 0 0 0 0 0 0 0 0 0 0
50200- 0 0 0 0 0 0 0 0 0 0 0 0
50201- 0 0 0 0 0 0 0 0 0 0 0 0
50202- 0 0 0 0 0 0 0 0 0 0 0 0
50203- 0 0 0 0 0 0 0 0 0 0 0 0
50204- 0 0 1 0 0 1 0 0 1 0 0 0
50205- 0 0 0 0 0 0 0 0 0 0 0 0
50206- 0 0 0 0 0 0 0 0 0 0 0 0
50207- 0 0 0 0 0 0 0 0 0 0 0 0
50208- 0 0 0 0 0 0 0 0 0 0 0 0
50209- 0 0 0 0 0 0 0 0 0 0 0 0
50210- 0 0 0 0 0 0 10 10 10 26 26 26
50211- 50 50 50 82 82 82 58 58 58 6 6 6
50212- 2 2 6 2 2 6 2 2 6 2 2 6
50213- 2 2 6 2 2 6 2 2 6 2 2 6
50214- 6 6 6 54 54 54 86 86 86 66 66 66
50215- 38 38 38 18 18 18 6 6 6 0 0 0
50216- 0 0 0 0 0 0 0 0 0 0 0 0
50217- 0 0 0 0 0 0 0 0 0 0 0 0
50218- 0 0 0 0 0 0 0 0 0 0 0 0
50219- 0 0 0 0 0 0 0 0 0 0 0 0
50220- 0 0 0 0 0 0 0 0 0 0 0 0
50221- 0 0 0 0 0 0 0 0 0 0 0 0
50222- 0 0 0 0 0 0 0 0 0 0 0 0
50223- 0 0 0 0 0 0 0 0 0 0 0 0
50224- 0 0 0 0 0 0 0 0 0 0 0 0
50225- 0 0 0 0 0 0 0 0 0 0 0 0
50226- 0 0 0 0 0 0 0 0 0 0 0 0
50227- 0 0 0 0 0 0 0 0 0 0 0 0
50228- 0 0 0 0 0 0 0 0 0 0 0 0
50229- 0 0 0 0 0 0 0 0 0 0 0 0
50230- 0 0 0 6 6 6 22 22 22 50 50 50
50231- 78 78 78 34 34 34 2 2 6 2 2 6
50232- 2 2 6 2 2 6 2 2 6 2 2 6
50233- 2 2 6 2 2 6 2 2 6 2 2 6
50234- 2 2 6 2 2 6 6 6 6 70 70 70
50235- 78 78 78 46 46 46 22 22 22 6 6 6
50236- 0 0 0 0 0 0 0 0 0 0 0 0
50237- 0 0 0 0 0 0 0 0 0 0 0 0
50238- 0 0 0 0 0 0 0 0 0 0 0 0
50239- 0 0 0 0 0 0 0 0 0 0 0 0
50240- 0 0 0 0 0 0 0 0 0 0 0 0
50241- 0 0 0 0 0 0 0 0 0 0 0 0
50242- 0 0 0 0 0 0 0 0 0 0 0 0
50243- 0 0 0 0 0 0 0 0 0 0 0 0
50244- 0 0 1 0 0 1 0 0 1 0 0 0
50245- 0 0 0 0 0 0 0 0 0 0 0 0
50246- 0 0 0 0 0 0 0 0 0 0 0 0
50247- 0 0 0 0 0 0 0 0 0 0 0 0
50248- 0 0 0 0 0 0 0 0 0 0 0 0
50249- 0 0 0 0 0 0 0 0 0 0 0 0
50250- 6 6 6 18 18 18 42 42 42 82 82 82
50251- 26 26 26 2 2 6 2 2 6 2 2 6
50252- 2 2 6 2 2 6 2 2 6 2 2 6
50253- 2 2 6 2 2 6 2 2 6 14 14 14
50254- 46 46 46 34 34 34 6 6 6 2 2 6
50255- 42 42 42 78 78 78 42 42 42 18 18 18
50256- 6 6 6 0 0 0 0 0 0 0 0 0
50257- 0 0 0 0 0 0 0 0 0 0 0 0
50258- 0 0 0 0 0 0 0 0 0 0 0 0
50259- 0 0 0 0 0 0 0 0 0 0 0 0
50260- 0 0 0 0 0 0 0 0 0 0 0 0
50261- 0 0 0 0 0 0 0 0 0 0 0 0
50262- 0 0 0 0 0 0 0 0 0 0 0 0
50263- 0 0 0 0 0 0 0 0 0 0 0 0
50264- 0 0 1 0 0 0 0 0 1 0 0 0
50265- 0 0 0 0 0 0 0 0 0 0 0 0
50266- 0 0 0 0 0 0 0 0 0 0 0 0
50267- 0 0 0 0 0 0 0 0 0 0 0 0
50268- 0 0 0 0 0 0 0 0 0 0 0 0
50269- 0 0 0 0 0 0 0 0 0 0 0 0
50270- 10 10 10 30 30 30 66 66 66 58 58 58
50271- 2 2 6 2 2 6 2 2 6 2 2 6
50272- 2 2 6 2 2 6 2 2 6 2 2 6
50273- 2 2 6 2 2 6 2 2 6 26 26 26
50274- 86 86 86 101 101 101 46 46 46 10 10 10
50275- 2 2 6 58 58 58 70 70 70 34 34 34
50276- 10 10 10 0 0 0 0 0 0 0 0 0
50277- 0 0 0 0 0 0 0 0 0 0 0 0
50278- 0 0 0 0 0 0 0 0 0 0 0 0
50279- 0 0 0 0 0 0 0 0 0 0 0 0
50280- 0 0 0 0 0 0 0 0 0 0 0 0
50281- 0 0 0 0 0 0 0 0 0 0 0 0
50282- 0 0 0 0 0 0 0 0 0 0 0 0
50283- 0 0 0 0 0 0 0 0 0 0 0 0
50284- 0 0 1 0 0 1 0 0 1 0 0 0
50285- 0 0 0 0 0 0 0 0 0 0 0 0
50286- 0 0 0 0 0 0 0 0 0 0 0 0
50287- 0 0 0 0 0 0 0 0 0 0 0 0
50288- 0 0 0 0 0 0 0 0 0 0 0 0
50289- 0 0 0 0 0 0 0 0 0 0 0 0
50290- 14 14 14 42 42 42 86 86 86 10 10 10
50291- 2 2 6 2 2 6 2 2 6 2 2 6
50292- 2 2 6 2 2 6 2 2 6 2 2 6
50293- 2 2 6 2 2 6 2 2 6 30 30 30
50294- 94 94 94 94 94 94 58 58 58 26 26 26
50295- 2 2 6 6 6 6 78 78 78 54 54 54
50296- 22 22 22 6 6 6 0 0 0 0 0 0
50297- 0 0 0 0 0 0 0 0 0 0 0 0
50298- 0 0 0 0 0 0 0 0 0 0 0 0
50299- 0 0 0 0 0 0 0 0 0 0 0 0
50300- 0 0 0 0 0 0 0 0 0 0 0 0
50301- 0 0 0 0 0 0 0 0 0 0 0 0
50302- 0 0 0 0 0 0 0 0 0 0 0 0
50303- 0 0 0 0 0 0 0 0 0 0 0 0
50304- 0 0 0 0 0 0 0 0 0 0 0 0
50305- 0 0 0 0 0 0 0 0 0 0 0 0
50306- 0 0 0 0 0 0 0 0 0 0 0 0
50307- 0 0 0 0 0 0 0 0 0 0 0 0
50308- 0 0 0 0 0 0 0 0 0 0 0 0
50309- 0 0 0 0 0 0 0 0 0 6 6 6
50310- 22 22 22 62 62 62 62 62 62 2 2 6
50311- 2 2 6 2 2 6 2 2 6 2 2 6
50312- 2 2 6 2 2 6 2 2 6 2 2 6
50313- 2 2 6 2 2 6 2 2 6 26 26 26
50314- 54 54 54 38 38 38 18 18 18 10 10 10
50315- 2 2 6 2 2 6 34 34 34 82 82 82
50316- 38 38 38 14 14 14 0 0 0 0 0 0
50317- 0 0 0 0 0 0 0 0 0 0 0 0
50318- 0 0 0 0 0 0 0 0 0 0 0 0
50319- 0 0 0 0 0 0 0 0 0 0 0 0
50320- 0 0 0 0 0 0 0 0 0 0 0 0
50321- 0 0 0 0 0 0 0 0 0 0 0 0
50322- 0 0 0 0 0 0 0 0 0 0 0 0
50323- 0 0 0 0 0 0 0 0 0 0 0 0
50324- 0 0 0 0 0 1 0 0 1 0 0 0
50325- 0 0 0 0 0 0 0 0 0 0 0 0
50326- 0 0 0 0 0 0 0 0 0 0 0 0
50327- 0 0 0 0 0 0 0 0 0 0 0 0
50328- 0 0 0 0 0 0 0 0 0 0 0 0
50329- 0 0 0 0 0 0 0 0 0 6 6 6
50330- 30 30 30 78 78 78 30 30 30 2 2 6
50331- 2 2 6 2 2 6 2 2 6 2 2 6
50332- 2 2 6 2 2 6 2 2 6 2 2 6
50333- 2 2 6 2 2 6 2 2 6 10 10 10
50334- 10 10 10 2 2 6 2 2 6 2 2 6
50335- 2 2 6 2 2 6 2 2 6 78 78 78
50336- 50 50 50 18 18 18 6 6 6 0 0 0
50337- 0 0 0 0 0 0 0 0 0 0 0 0
50338- 0 0 0 0 0 0 0 0 0 0 0 0
50339- 0 0 0 0 0 0 0 0 0 0 0 0
50340- 0 0 0 0 0 0 0 0 0 0 0 0
50341- 0 0 0 0 0 0 0 0 0 0 0 0
50342- 0 0 0 0 0 0 0 0 0 0 0 0
50343- 0 0 0 0 0 0 0 0 0 0 0 0
50344- 0 0 1 0 0 0 0 0 0 0 0 0
50345- 0 0 0 0 0 0 0 0 0 0 0 0
50346- 0 0 0 0 0 0 0 0 0 0 0 0
50347- 0 0 0 0 0 0 0 0 0 0 0 0
50348- 0 0 0 0 0 0 0 0 0 0 0 0
50349- 0 0 0 0 0 0 0 0 0 10 10 10
50350- 38 38 38 86 86 86 14 14 14 2 2 6
50351- 2 2 6 2 2 6 2 2 6 2 2 6
50352- 2 2 6 2 2 6 2 2 6 2 2 6
50353- 2 2 6 2 2 6 2 2 6 2 2 6
50354- 2 2 6 2 2 6 2 2 6 2 2 6
50355- 2 2 6 2 2 6 2 2 6 54 54 54
50356- 66 66 66 26 26 26 6 6 6 0 0 0
50357- 0 0 0 0 0 0 0 0 0 0 0 0
50358- 0 0 0 0 0 0 0 0 0 0 0 0
50359- 0 0 0 0 0 0 0 0 0 0 0 0
50360- 0 0 0 0 0 0 0 0 0 0 0 0
50361- 0 0 0 0 0 0 0 0 0 0 0 0
50362- 0 0 0 0 0 0 0 0 0 0 0 0
50363- 0 0 0 0 0 0 0 0 0 0 0 0
50364- 0 0 0 0 0 1 0 0 1 0 0 0
50365- 0 0 0 0 0 0 0 0 0 0 0 0
50366- 0 0 0 0 0 0 0 0 0 0 0 0
50367- 0 0 0 0 0 0 0 0 0 0 0 0
50368- 0 0 0 0 0 0 0 0 0 0 0 0
50369- 0 0 0 0 0 0 0 0 0 14 14 14
50370- 42 42 42 82 82 82 2 2 6 2 2 6
50371- 2 2 6 6 6 6 10 10 10 2 2 6
50372- 2 2 6 2 2 6 2 2 6 2 2 6
50373- 2 2 6 2 2 6 2 2 6 6 6 6
50374- 14 14 14 10 10 10 2 2 6 2 2 6
50375- 2 2 6 2 2 6 2 2 6 18 18 18
50376- 82 82 82 34 34 34 10 10 10 0 0 0
50377- 0 0 0 0 0 0 0 0 0 0 0 0
50378- 0 0 0 0 0 0 0 0 0 0 0 0
50379- 0 0 0 0 0 0 0 0 0 0 0 0
50380- 0 0 0 0 0 0 0 0 0 0 0 0
50381- 0 0 0 0 0 0 0 0 0 0 0 0
50382- 0 0 0 0 0 0 0 0 0 0 0 0
50383- 0 0 0 0 0 0 0 0 0 0 0 0
50384- 0 0 1 0 0 0 0 0 0 0 0 0
50385- 0 0 0 0 0 0 0 0 0 0 0 0
50386- 0 0 0 0 0 0 0 0 0 0 0 0
50387- 0 0 0 0 0 0 0 0 0 0 0 0
50388- 0 0 0 0 0 0 0 0 0 0 0 0
50389- 0 0 0 0 0 0 0 0 0 14 14 14
50390- 46 46 46 86 86 86 2 2 6 2 2 6
50391- 6 6 6 6 6 6 22 22 22 34 34 34
50392- 6 6 6 2 2 6 2 2 6 2 2 6
50393- 2 2 6 2 2 6 18 18 18 34 34 34
50394- 10 10 10 50 50 50 22 22 22 2 2 6
50395- 2 2 6 2 2 6 2 2 6 10 10 10
50396- 86 86 86 42 42 42 14 14 14 0 0 0
50397- 0 0 0 0 0 0 0 0 0 0 0 0
50398- 0 0 0 0 0 0 0 0 0 0 0 0
50399- 0 0 0 0 0 0 0 0 0 0 0 0
50400- 0 0 0 0 0 0 0 0 0 0 0 0
50401- 0 0 0 0 0 0 0 0 0 0 0 0
50402- 0 0 0 0 0 0 0 0 0 0 0 0
50403- 0 0 0 0 0 0 0 0 0 0 0 0
50404- 0 0 1 0 0 1 0 0 1 0 0 0
50405- 0 0 0 0 0 0 0 0 0 0 0 0
50406- 0 0 0 0 0 0 0 0 0 0 0 0
50407- 0 0 0 0 0 0 0 0 0 0 0 0
50408- 0 0 0 0 0 0 0 0 0 0 0 0
50409- 0 0 0 0 0 0 0 0 0 14 14 14
50410- 46 46 46 86 86 86 2 2 6 2 2 6
50411- 38 38 38 116 116 116 94 94 94 22 22 22
50412- 22 22 22 2 2 6 2 2 6 2 2 6
50413- 14 14 14 86 86 86 138 138 138 162 162 162
50414-154 154 154 38 38 38 26 26 26 6 6 6
50415- 2 2 6 2 2 6 2 2 6 2 2 6
50416- 86 86 86 46 46 46 14 14 14 0 0 0
50417- 0 0 0 0 0 0 0 0 0 0 0 0
50418- 0 0 0 0 0 0 0 0 0 0 0 0
50419- 0 0 0 0 0 0 0 0 0 0 0 0
50420- 0 0 0 0 0 0 0 0 0 0 0 0
50421- 0 0 0 0 0 0 0 0 0 0 0 0
50422- 0 0 0 0 0 0 0 0 0 0 0 0
50423- 0 0 0 0 0 0 0 0 0 0 0 0
50424- 0 0 0 0 0 0 0 0 0 0 0 0
50425- 0 0 0 0 0 0 0 0 0 0 0 0
50426- 0 0 0 0 0 0 0 0 0 0 0 0
50427- 0 0 0 0 0 0 0 0 0 0 0 0
50428- 0 0 0 0 0 0 0 0 0 0 0 0
50429- 0 0 0 0 0 0 0 0 0 14 14 14
50430- 46 46 46 86 86 86 2 2 6 14 14 14
50431-134 134 134 198 198 198 195 195 195 116 116 116
50432- 10 10 10 2 2 6 2 2 6 6 6 6
50433-101 98 89 187 187 187 210 210 210 218 218 218
50434-214 214 214 134 134 134 14 14 14 6 6 6
50435- 2 2 6 2 2 6 2 2 6 2 2 6
50436- 86 86 86 50 50 50 18 18 18 6 6 6
50437- 0 0 0 0 0 0 0 0 0 0 0 0
50438- 0 0 0 0 0 0 0 0 0 0 0 0
50439- 0 0 0 0 0 0 0 0 0 0 0 0
50440- 0 0 0 0 0 0 0 0 0 0 0 0
50441- 0 0 0 0 0 0 0 0 0 0 0 0
50442- 0 0 0 0 0 0 0 0 0 0 0 0
50443- 0 0 0 0 0 0 0 0 1 0 0 0
50444- 0 0 1 0 0 1 0 0 1 0 0 0
50445- 0 0 0 0 0 0 0 0 0 0 0 0
50446- 0 0 0 0 0 0 0 0 0 0 0 0
50447- 0 0 0 0 0 0 0 0 0 0 0 0
50448- 0 0 0 0 0 0 0 0 0 0 0 0
50449- 0 0 0 0 0 0 0 0 0 14 14 14
50450- 46 46 46 86 86 86 2 2 6 54 54 54
50451-218 218 218 195 195 195 226 226 226 246 246 246
50452- 58 58 58 2 2 6 2 2 6 30 30 30
50453-210 210 210 253 253 253 174 174 174 123 123 123
50454-221 221 221 234 234 234 74 74 74 2 2 6
50455- 2 2 6 2 2 6 2 2 6 2 2 6
50456- 70 70 70 58 58 58 22 22 22 6 6 6
50457- 0 0 0 0 0 0 0 0 0 0 0 0
50458- 0 0 0 0 0 0 0 0 0 0 0 0
50459- 0 0 0 0 0 0 0 0 0 0 0 0
50460- 0 0 0 0 0 0 0 0 0 0 0 0
50461- 0 0 0 0 0 0 0 0 0 0 0 0
50462- 0 0 0 0 0 0 0 0 0 0 0 0
50463- 0 0 0 0 0 0 0 0 0 0 0 0
50464- 0 0 0 0 0 0 0 0 0 0 0 0
50465- 0 0 0 0 0 0 0 0 0 0 0 0
50466- 0 0 0 0 0 0 0 0 0 0 0 0
50467- 0 0 0 0 0 0 0 0 0 0 0 0
50468- 0 0 0 0 0 0 0 0 0 0 0 0
50469- 0 0 0 0 0 0 0 0 0 14 14 14
50470- 46 46 46 82 82 82 2 2 6 106 106 106
50471-170 170 170 26 26 26 86 86 86 226 226 226
50472-123 123 123 10 10 10 14 14 14 46 46 46
50473-231 231 231 190 190 190 6 6 6 70 70 70
50474- 90 90 90 238 238 238 158 158 158 2 2 6
50475- 2 2 6 2 2 6 2 2 6 2 2 6
50476- 70 70 70 58 58 58 22 22 22 6 6 6
50477- 0 0 0 0 0 0 0 0 0 0 0 0
50478- 0 0 0 0 0 0 0 0 0 0 0 0
50479- 0 0 0 0 0 0 0 0 0 0 0 0
50480- 0 0 0 0 0 0 0 0 0 0 0 0
50481- 0 0 0 0 0 0 0 0 0 0 0 0
50482- 0 0 0 0 0 0 0 0 0 0 0 0
50483- 0 0 0 0 0 0 0 0 1 0 0 0
50484- 0 0 1 0 0 1 0 0 1 0 0 0
50485- 0 0 0 0 0 0 0 0 0 0 0 0
50486- 0 0 0 0 0 0 0 0 0 0 0 0
50487- 0 0 0 0 0 0 0 0 0 0 0 0
50488- 0 0 0 0 0 0 0 0 0 0 0 0
50489- 0 0 0 0 0 0 0 0 0 14 14 14
50490- 42 42 42 86 86 86 6 6 6 116 116 116
50491-106 106 106 6 6 6 70 70 70 149 149 149
50492-128 128 128 18 18 18 38 38 38 54 54 54
50493-221 221 221 106 106 106 2 2 6 14 14 14
50494- 46 46 46 190 190 190 198 198 198 2 2 6
50495- 2 2 6 2 2 6 2 2 6 2 2 6
50496- 74 74 74 62 62 62 22 22 22 6 6 6
50497- 0 0 0 0 0 0 0 0 0 0 0 0
50498- 0 0 0 0 0 0 0 0 0 0 0 0
50499- 0 0 0 0 0 0 0 0 0 0 0 0
50500- 0 0 0 0 0 0 0 0 0 0 0 0
50501- 0 0 0 0 0 0 0 0 0 0 0 0
50502- 0 0 0 0 0 0 0 0 0 0 0 0
50503- 0 0 0 0 0 0 0 0 1 0 0 0
50504- 0 0 1 0 0 0 0 0 1 0 0 0
50505- 0 0 0 0 0 0 0 0 0 0 0 0
50506- 0 0 0 0 0 0 0 0 0 0 0 0
50507- 0 0 0 0 0 0 0 0 0 0 0 0
50508- 0 0 0 0 0 0 0 0 0 0 0 0
50509- 0 0 0 0 0 0 0 0 0 14 14 14
50510- 42 42 42 94 94 94 14 14 14 101 101 101
50511-128 128 128 2 2 6 18 18 18 116 116 116
50512-118 98 46 121 92 8 121 92 8 98 78 10
50513-162 162 162 106 106 106 2 2 6 2 2 6
50514- 2 2 6 195 195 195 195 195 195 6 6 6
50515- 2 2 6 2 2 6 2 2 6 2 2 6
50516- 74 74 74 62 62 62 22 22 22 6 6 6
50517- 0 0 0 0 0 0 0 0 0 0 0 0
50518- 0 0 0 0 0 0 0 0 0 0 0 0
50519- 0 0 0 0 0 0 0 0 0 0 0 0
50520- 0 0 0 0 0 0 0 0 0 0 0 0
50521- 0 0 0 0 0 0 0 0 0 0 0 0
50522- 0 0 0 0 0 0 0 0 0 0 0 0
50523- 0 0 0 0 0 0 0 0 1 0 0 1
50524- 0 0 1 0 0 0 0 0 1 0 0 0
50525- 0 0 0 0 0 0 0 0 0 0 0 0
50526- 0 0 0 0 0 0 0 0 0 0 0 0
50527- 0 0 0 0 0 0 0 0 0 0 0 0
50528- 0 0 0 0 0 0 0 0 0 0 0 0
50529- 0 0 0 0 0 0 0 0 0 10 10 10
50530- 38 38 38 90 90 90 14 14 14 58 58 58
50531-210 210 210 26 26 26 54 38 6 154 114 10
50532-226 170 11 236 186 11 225 175 15 184 144 12
50533-215 174 15 175 146 61 37 26 9 2 2 6
50534- 70 70 70 246 246 246 138 138 138 2 2 6
50535- 2 2 6 2 2 6 2 2 6 2 2 6
50536- 70 70 70 66 66 66 26 26 26 6 6 6
50537- 0 0 0 0 0 0 0 0 0 0 0 0
50538- 0 0 0 0 0 0 0 0 0 0 0 0
50539- 0 0 0 0 0 0 0 0 0 0 0 0
50540- 0 0 0 0 0 0 0 0 0 0 0 0
50541- 0 0 0 0 0 0 0 0 0 0 0 0
50542- 0 0 0 0 0 0 0 0 0 0 0 0
50543- 0 0 0 0 0 0 0 0 0 0 0 0
50544- 0 0 0 0 0 0 0 0 0 0 0 0
50545- 0 0 0 0 0 0 0 0 0 0 0 0
50546- 0 0 0 0 0 0 0 0 0 0 0 0
50547- 0 0 0 0 0 0 0 0 0 0 0 0
50548- 0 0 0 0 0 0 0 0 0 0 0 0
50549- 0 0 0 0 0 0 0 0 0 10 10 10
50550- 38 38 38 86 86 86 14 14 14 10 10 10
50551-195 195 195 188 164 115 192 133 9 225 175 15
50552-239 182 13 234 190 10 232 195 16 232 200 30
50553-245 207 45 241 208 19 232 195 16 184 144 12
50554-218 194 134 211 206 186 42 42 42 2 2 6
50555- 2 2 6 2 2 6 2 2 6 2 2 6
50556- 50 50 50 74 74 74 30 30 30 6 6 6
50557- 0 0 0 0 0 0 0 0 0 0 0 0
50558- 0 0 0 0 0 0 0 0 0 0 0 0
50559- 0 0 0 0 0 0 0 0 0 0 0 0
50560- 0 0 0 0 0 0 0 0 0 0 0 0
50561- 0 0 0 0 0 0 0 0 0 0 0 0
50562- 0 0 0 0 0 0 0 0 0 0 0 0
50563- 0 0 0 0 0 0 0 0 0 0 0 0
50564- 0 0 0 0 0 0 0 0 0 0 0 0
50565- 0 0 0 0 0 0 0 0 0 0 0 0
50566- 0 0 0 0 0 0 0 0 0 0 0 0
50567- 0 0 0 0 0 0 0 0 0 0 0 0
50568- 0 0 0 0 0 0 0 0 0 0 0 0
50569- 0 0 0 0 0 0 0 0 0 10 10 10
50570- 34 34 34 86 86 86 14 14 14 2 2 6
50571-121 87 25 192 133 9 219 162 10 239 182 13
50572-236 186 11 232 195 16 241 208 19 244 214 54
50573-246 218 60 246 218 38 246 215 20 241 208 19
50574-241 208 19 226 184 13 121 87 25 2 2 6
50575- 2 2 6 2 2 6 2 2 6 2 2 6
50576- 50 50 50 82 82 82 34 34 34 10 10 10
50577- 0 0 0 0 0 0 0 0 0 0 0 0
50578- 0 0 0 0 0 0 0 0 0 0 0 0
50579- 0 0 0 0 0 0 0 0 0 0 0 0
50580- 0 0 0 0 0 0 0 0 0 0 0 0
50581- 0 0 0 0 0 0 0 0 0 0 0 0
50582- 0 0 0 0 0 0 0 0 0 0 0 0
50583- 0 0 0 0 0 0 0 0 0 0 0 0
50584- 0 0 0 0 0 0 0 0 0 0 0 0
50585- 0 0 0 0 0 0 0 0 0 0 0 0
50586- 0 0 0 0 0 0 0 0 0 0 0 0
50587- 0 0 0 0 0 0 0 0 0 0 0 0
50588- 0 0 0 0 0 0 0 0 0 0 0 0
50589- 0 0 0 0 0 0 0 0 0 10 10 10
50590- 34 34 34 82 82 82 30 30 30 61 42 6
50591-180 123 7 206 145 10 230 174 11 239 182 13
50592-234 190 10 238 202 15 241 208 19 246 218 74
50593-246 218 38 246 215 20 246 215 20 246 215 20
50594-226 184 13 215 174 15 184 144 12 6 6 6
50595- 2 2 6 2 2 6 2 2 6 2 2 6
50596- 26 26 26 94 94 94 42 42 42 14 14 14
50597- 0 0 0 0 0 0 0 0 0 0 0 0
50598- 0 0 0 0 0 0 0 0 0 0 0 0
50599- 0 0 0 0 0 0 0 0 0 0 0 0
50600- 0 0 0 0 0 0 0 0 0 0 0 0
50601- 0 0 0 0 0 0 0 0 0 0 0 0
50602- 0 0 0 0 0 0 0 0 0 0 0 0
50603- 0 0 0 0 0 0 0 0 0 0 0 0
50604- 0 0 0 0 0 0 0 0 0 0 0 0
50605- 0 0 0 0 0 0 0 0 0 0 0 0
50606- 0 0 0 0 0 0 0 0 0 0 0 0
50607- 0 0 0 0 0 0 0 0 0 0 0 0
50608- 0 0 0 0 0 0 0 0 0 0 0 0
50609- 0 0 0 0 0 0 0 0 0 10 10 10
50610- 30 30 30 78 78 78 50 50 50 104 69 6
50611-192 133 9 216 158 10 236 178 12 236 186 11
50612-232 195 16 241 208 19 244 214 54 245 215 43
50613-246 215 20 246 215 20 241 208 19 198 155 10
50614-200 144 11 216 158 10 156 118 10 2 2 6
50615- 2 2 6 2 2 6 2 2 6 2 2 6
50616- 6 6 6 90 90 90 54 54 54 18 18 18
50617- 6 6 6 0 0 0 0 0 0 0 0 0
50618- 0 0 0 0 0 0 0 0 0 0 0 0
50619- 0 0 0 0 0 0 0 0 0 0 0 0
50620- 0 0 0 0 0 0 0 0 0 0 0 0
50621- 0 0 0 0 0 0 0 0 0 0 0 0
50622- 0 0 0 0 0 0 0 0 0 0 0 0
50623- 0 0 0 0 0 0 0 0 0 0 0 0
50624- 0 0 0 0 0 0 0 0 0 0 0 0
50625- 0 0 0 0 0 0 0 0 0 0 0 0
50626- 0 0 0 0 0 0 0 0 0 0 0 0
50627- 0 0 0 0 0 0 0 0 0 0 0 0
50628- 0 0 0 0 0 0 0 0 0 0 0 0
50629- 0 0 0 0 0 0 0 0 0 10 10 10
50630- 30 30 30 78 78 78 46 46 46 22 22 22
50631-137 92 6 210 162 10 239 182 13 238 190 10
50632-238 202 15 241 208 19 246 215 20 246 215 20
50633-241 208 19 203 166 17 185 133 11 210 150 10
50634-216 158 10 210 150 10 102 78 10 2 2 6
50635- 6 6 6 54 54 54 14 14 14 2 2 6
50636- 2 2 6 62 62 62 74 74 74 30 30 30
50637- 10 10 10 0 0 0 0 0 0 0 0 0
50638- 0 0 0 0 0 0 0 0 0 0 0 0
50639- 0 0 0 0 0 0 0 0 0 0 0 0
50640- 0 0 0 0 0 0 0 0 0 0 0 0
50641- 0 0 0 0 0 0 0 0 0 0 0 0
50642- 0 0 0 0 0 0 0 0 0 0 0 0
50643- 0 0 0 0 0 0 0 0 0 0 0 0
50644- 0 0 0 0 0 0 0 0 0 0 0 0
50645- 0 0 0 0 0 0 0 0 0 0 0 0
50646- 0 0 0 0 0 0 0 0 0 0 0 0
50647- 0 0 0 0 0 0 0 0 0 0 0 0
50648- 0 0 0 0 0 0 0 0 0 0 0 0
50649- 0 0 0 0 0 0 0 0 0 10 10 10
50650- 34 34 34 78 78 78 50 50 50 6 6 6
50651- 94 70 30 139 102 15 190 146 13 226 184 13
50652-232 200 30 232 195 16 215 174 15 190 146 13
50653-168 122 10 192 133 9 210 150 10 213 154 11
50654-202 150 34 182 157 106 101 98 89 2 2 6
50655- 2 2 6 78 78 78 116 116 116 58 58 58
50656- 2 2 6 22 22 22 90 90 90 46 46 46
50657- 18 18 18 6 6 6 0 0 0 0 0 0
50658- 0 0 0 0 0 0 0 0 0 0 0 0
50659- 0 0 0 0 0 0 0 0 0 0 0 0
50660- 0 0 0 0 0 0 0 0 0 0 0 0
50661- 0 0 0 0 0 0 0 0 0 0 0 0
50662- 0 0 0 0 0 0 0 0 0 0 0 0
50663- 0 0 0 0 0 0 0 0 0 0 0 0
50664- 0 0 0 0 0 0 0 0 0 0 0 0
50665- 0 0 0 0 0 0 0 0 0 0 0 0
50666- 0 0 0 0 0 0 0 0 0 0 0 0
50667- 0 0 0 0 0 0 0 0 0 0 0 0
50668- 0 0 0 0 0 0 0 0 0 0 0 0
50669- 0 0 0 0 0 0 0 0 0 10 10 10
50670- 38 38 38 86 86 86 50 50 50 6 6 6
50671-128 128 128 174 154 114 156 107 11 168 122 10
50672-198 155 10 184 144 12 197 138 11 200 144 11
50673-206 145 10 206 145 10 197 138 11 188 164 115
50674-195 195 195 198 198 198 174 174 174 14 14 14
50675- 2 2 6 22 22 22 116 116 116 116 116 116
50676- 22 22 22 2 2 6 74 74 74 70 70 70
50677- 30 30 30 10 10 10 0 0 0 0 0 0
50678- 0 0 0 0 0 0 0 0 0 0 0 0
50679- 0 0 0 0 0 0 0 0 0 0 0 0
50680- 0 0 0 0 0 0 0 0 0 0 0 0
50681- 0 0 0 0 0 0 0 0 0 0 0 0
50682- 0 0 0 0 0 0 0 0 0 0 0 0
50683- 0 0 0 0 0 0 0 0 0 0 0 0
50684- 0 0 0 0 0 0 0 0 0 0 0 0
50685- 0 0 0 0 0 0 0 0 0 0 0 0
50686- 0 0 0 0 0 0 0 0 0 0 0 0
50687- 0 0 0 0 0 0 0 0 0 0 0 0
50688- 0 0 0 0 0 0 0 0 0 0 0 0
50689- 0 0 0 0 0 0 6 6 6 18 18 18
50690- 50 50 50 101 101 101 26 26 26 10 10 10
50691-138 138 138 190 190 190 174 154 114 156 107 11
50692-197 138 11 200 144 11 197 138 11 192 133 9
50693-180 123 7 190 142 34 190 178 144 187 187 187
50694-202 202 202 221 221 221 214 214 214 66 66 66
50695- 2 2 6 2 2 6 50 50 50 62 62 62
50696- 6 6 6 2 2 6 10 10 10 90 90 90
50697- 50 50 50 18 18 18 6 6 6 0 0 0
50698- 0 0 0 0 0 0 0 0 0 0 0 0
50699- 0 0 0 0 0 0 0 0 0 0 0 0
50700- 0 0 0 0 0 0 0 0 0 0 0 0
50701- 0 0 0 0 0 0 0 0 0 0 0 0
50702- 0 0 0 0 0 0 0 0 0 0 0 0
50703- 0 0 0 0 0 0 0 0 0 0 0 0
50704- 0 0 0 0 0 0 0 0 0 0 0 0
50705- 0 0 0 0 0 0 0 0 0 0 0 0
50706- 0 0 0 0 0 0 0 0 0 0 0 0
50707- 0 0 0 0 0 0 0 0 0 0 0 0
50708- 0 0 0 0 0 0 0 0 0 0 0 0
50709- 0 0 0 0 0 0 10 10 10 34 34 34
50710- 74 74 74 74 74 74 2 2 6 6 6 6
50711-144 144 144 198 198 198 190 190 190 178 166 146
50712-154 121 60 156 107 11 156 107 11 168 124 44
50713-174 154 114 187 187 187 190 190 190 210 210 210
50714-246 246 246 253 253 253 253 253 253 182 182 182
50715- 6 6 6 2 2 6 2 2 6 2 2 6
50716- 2 2 6 2 2 6 2 2 6 62 62 62
50717- 74 74 74 34 34 34 14 14 14 0 0 0
50718- 0 0 0 0 0 0 0 0 0 0 0 0
50719- 0 0 0 0 0 0 0 0 0 0 0 0
50720- 0 0 0 0 0 0 0 0 0 0 0 0
50721- 0 0 0 0 0 0 0 0 0 0 0 0
50722- 0 0 0 0 0 0 0 0 0 0 0 0
50723- 0 0 0 0 0 0 0 0 0 0 0 0
50724- 0 0 0 0 0 0 0 0 0 0 0 0
50725- 0 0 0 0 0 0 0 0 0 0 0 0
50726- 0 0 0 0 0 0 0 0 0 0 0 0
50727- 0 0 0 0 0 0 0 0 0 0 0 0
50728- 0 0 0 0 0 0 0 0 0 0 0 0
50729- 0 0 0 10 10 10 22 22 22 54 54 54
50730- 94 94 94 18 18 18 2 2 6 46 46 46
50731-234 234 234 221 221 221 190 190 190 190 190 190
50732-190 190 190 187 187 187 187 187 187 190 190 190
50733-190 190 190 195 195 195 214 214 214 242 242 242
50734-253 253 253 253 253 253 253 253 253 253 253 253
50735- 82 82 82 2 2 6 2 2 6 2 2 6
50736- 2 2 6 2 2 6 2 2 6 14 14 14
50737- 86 86 86 54 54 54 22 22 22 6 6 6
50738- 0 0 0 0 0 0 0 0 0 0 0 0
50739- 0 0 0 0 0 0 0 0 0 0 0 0
50740- 0 0 0 0 0 0 0 0 0 0 0 0
50741- 0 0 0 0 0 0 0 0 0 0 0 0
50742- 0 0 0 0 0 0 0 0 0 0 0 0
50743- 0 0 0 0 0 0 0 0 0 0 0 0
50744- 0 0 0 0 0 0 0 0 0 0 0 0
50745- 0 0 0 0 0 0 0 0 0 0 0 0
50746- 0 0 0 0 0 0 0 0 0 0 0 0
50747- 0 0 0 0 0 0 0 0 0 0 0 0
50748- 0 0 0 0 0 0 0 0 0 0 0 0
50749- 6 6 6 18 18 18 46 46 46 90 90 90
50750- 46 46 46 18 18 18 6 6 6 182 182 182
50751-253 253 253 246 246 246 206 206 206 190 190 190
50752-190 190 190 190 190 190 190 190 190 190 190 190
50753-206 206 206 231 231 231 250 250 250 253 253 253
50754-253 253 253 253 253 253 253 253 253 253 253 253
50755-202 202 202 14 14 14 2 2 6 2 2 6
50756- 2 2 6 2 2 6 2 2 6 2 2 6
50757- 42 42 42 86 86 86 42 42 42 18 18 18
50758- 6 6 6 0 0 0 0 0 0 0 0 0
50759- 0 0 0 0 0 0 0 0 0 0 0 0
50760- 0 0 0 0 0 0 0 0 0 0 0 0
50761- 0 0 0 0 0 0 0 0 0 0 0 0
50762- 0 0 0 0 0 0 0 0 0 0 0 0
50763- 0 0 0 0 0 0 0 0 0 0 0 0
50764- 0 0 0 0 0 0 0 0 0 0 0 0
50765- 0 0 0 0 0 0 0 0 0 0 0 0
50766- 0 0 0 0 0 0 0 0 0 0 0 0
50767- 0 0 0 0 0 0 0 0 0 0 0 0
50768- 0 0 0 0 0 0 0 0 0 6 6 6
50769- 14 14 14 38 38 38 74 74 74 66 66 66
50770- 2 2 6 6 6 6 90 90 90 250 250 250
50771-253 253 253 253 253 253 238 238 238 198 198 198
50772-190 190 190 190 190 190 195 195 195 221 221 221
50773-246 246 246 253 253 253 253 253 253 253 253 253
50774-253 253 253 253 253 253 253 253 253 253 253 253
50775-253 253 253 82 82 82 2 2 6 2 2 6
50776- 2 2 6 2 2 6 2 2 6 2 2 6
50777- 2 2 6 78 78 78 70 70 70 34 34 34
50778- 14 14 14 6 6 6 0 0 0 0 0 0
50779- 0 0 0 0 0 0 0 0 0 0 0 0
50780- 0 0 0 0 0 0 0 0 0 0 0 0
50781- 0 0 0 0 0 0 0 0 0 0 0 0
50782- 0 0 0 0 0 0 0 0 0 0 0 0
50783- 0 0 0 0 0 0 0 0 0 0 0 0
50784- 0 0 0 0 0 0 0 0 0 0 0 0
50785- 0 0 0 0 0 0 0 0 0 0 0 0
50786- 0 0 0 0 0 0 0 0 0 0 0 0
50787- 0 0 0 0 0 0 0 0 0 0 0 0
50788- 0 0 0 0 0 0 0 0 0 14 14 14
50789- 34 34 34 66 66 66 78 78 78 6 6 6
50790- 2 2 6 18 18 18 218 218 218 253 253 253
50791-253 253 253 253 253 253 253 253 253 246 246 246
50792-226 226 226 231 231 231 246 246 246 253 253 253
50793-253 253 253 253 253 253 253 253 253 253 253 253
50794-253 253 253 253 253 253 253 253 253 253 253 253
50795-253 253 253 178 178 178 2 2 6 2 2 6
50796- 2 2 6 2 2 6 2 2 6 2 2 6
50797- 2 2 6 18 18 18 90 90 90 62 62 62
50798- 30 30 30 10 10 10 0 0 0 0 0 0
50799- 0 0 0 0 0 0 0 0 0 0 0 0
50800- 0 0 0 0 0 0 0 0 0 0 0 0
50801- 0 0 0 0 0 0 0 0 0 0 0 0
50802- 0 0 0 0 0 0 0 0 0 0 0 0
50803- 0 0 0 0 0 0 0 0 0 0 0 0
50804- 0 0 0 0 0 0 0 0 0 0 0 0
50805- 0 0 0 0 0 0 0 0 0 0 0 0
50806- 0 0 0 0 0 0 0 0 0 0 0 0
50807- 0 0 0 0 0 0 0 0 0 0 0 0
50808- 0 0 0 0 0 0 10 10 10 26 26 26
50809- 58 58 58 90 90 90 18 18 18 2 2 6
50810- 2 2 6 110 110 110 253 253 253 253 253 253
50811-253 253 253 253 253 253 253 253 253 253 253 253
50812-250 250 250 253 253 253 253 253 253 253 253 253
50813-253 253 253 253 253 253 253 253 253 253 253 253
50814-253 253 253 253 253 253 253 253 253 253 253 253
50815-253 253 253 231 231 231 18 18 18 2 2 6
50816- 2 2 6 2 2 6 2 2 6 2 2 6
50817- 2 2 6 2 2 6 18 18 18 94 94 94
50818- 54 54 54 26 26 26 10 10 10 0 0 0
50819- 0 0 0 0 0 0 0 0 0 0 0 0
50820- 0 0 0 0 0 0 0 0 0 0 0 0
50821- 0 0 0 0 0 0 0 0 0 0 0 0
50822- 0 0 0 0 0 0 0 0 0 0 0 0
50823- 0 0 0 0 0 0 0 0 0 0 0 0
50824- 0 0 0 0 0 0 0 0 0 0 0 0
50825- 0 0 0 0 0 0 0 0 0 0 0 0
50826- 0 0 0 0 0 0 0 0 0 0 0 0
50827- 0 0 0 0 0 0 0 0 0 0 0 0
50828- 0 0 0 6 6 6 22 22 22 50 50 50
50829- 90 90 90 26 26 26 2 2 6 2 2 6
50830- 14 14 14 195 195 195 250 250 250 253 253 253
50831-253 253 253 253 253 253 253 253 253 253 253 253
50832-253 253 253 253 253 253 253 253 253 253 253 253
50833-253 253 253 253 253 253 253 253 253 253 253 253
50834-253 253 253 253 253 253 253 253 253 253 253 253
50835-250 250 250 242 242 242 54 54 54 2 2 6
50836- 2 2 6 2 2 6 2 2 6 2 2 6
50837- 2 2 6 2 2 6 2 2 6 38 38 38
50838- 86 86 86 50 50 50 22 22 22 6 6 6
50839- 0 0 0 0 0 0 0 0 0 0 0 0
50840- 0 0 0 0 0 0 0 0 0 0 0 0
50841- 0 0 0 0 0 0 0 0 0 0 0 0
50842- 0 0 0 0 0 0 0 0 0 0 0 0
50843- 0 0 0 0 0 0 0 0 0 0 0 0
50844- 0 0 0 0 0 0 0 0 0 0 0 0
50845- 0 0 0 0 0 0 0 0 0 0 0 0
50846- 0 0 0 0 0 0 0 0 0 0 0 0
50847- 0 0 0 0 0 0 0 0 0 0 0 0
50848- 6 6 6 14 14 14 38 38 38 82 82 82
50849- 34 34 34 2 2 6 2 2 6 2 2 6
50850- 42 42 42 195 195 195 246 246 246 253 253 253
50851-253 253 253 253 253 253 253 253 253 250 250 250
50852-242 242 242 242 242 242 250 250 250 253 253 253
50853-253 253 253 253 253 253 253 253 253 253 253 253
50854-253 253 253 250 250 250 246 246 246 238 238 238
50855-226 226 226 231 231 231 101 101 101 6 6 6
50856- 2 2 6 2 2 6 2 2 6 2 2 6
50857- 2 2 6 2 2 6 2 2 6 2 2 6
50858- 38 38 38 82 82 82 42 42 42 14 14 14
50859- 6 6 6 0 0 0 0 0 0 0 0 0
50860- 0 0 0 0 0 0 0 0 0 0 0 0
50861- 0 0 0 0 0 0 0 0 0 0 0 0
50862- 0 0 0 0 0 0 0 0 0 0 0 0
50863- 0 0 0 0 0 0 0 0 0 0 0 0
50864- 0 0 0 0 0 0 0 0 0 0 0 0
50865- 0 0 0 0 0 0 0 0 0 0 0 0
50866- 0 0 0 0 0 0 0 0 0 0 0 0
50867- 0 0 0 0 0 0 0 0 0 0 0 0
50868- 10 10 10 26 26 26 62 62 62 66 66 66
50869- 2 2 6 2 2 6 2 2 6 6 6 6
50870- 70 70 70 170 170 170 206 206 206 234 234 234
50871-246 246 246 250 250 250 250 250 250 238 238 238
50872-226 226 226 231 231 231 238 238 238 250 250 250
50873-250 250 250 250 250 250 246 246 246 231 231 231
50874-214 214 214 206 206 206 202 202 202 202 202 202
50875-198 198 198 202 202 202 182 182 182 18 18 18
50876- 2 2 6 2 2 6 2 2 6 2 2 6
50877- 2 2 6 2 2 6 2 2 6 2 2 6
50878- 2 2 6 62 62 62 66 66 66 30 30 30
50879- 10 10 10 0 0 0 0 0 0 0 0 0
50880- 0 0 0 0 0 0 0 0 0 0 0 0
50881- 0 0 0 0 0 0 0 0 0 0 0 0
50882- 0 0 0 0 0 0 0 0 0 0 0 0
50883- 0 0 0 0 0 0 0 0 0 0 0 0
50884- 0 0 0 0 0 0 0 0 0 0 0 0
50885- 0 0 0 0 0 0 0 0 0 0 0 0
50886- 0 0 0 0 0 0 0 0 0 0 0 0
50887- 0 0 0 0 0 0 0 0 0 0 0 0
50888- 14 14 14 42 42 42 82 82 82 18 18 18
50889- 2 2 6 2 2 6 2 2 6 10 10 10
50890- 94 94 94 182 182 182 218 218 218 242 242 242
50891-250 250 250 253 253 253 253 253 253 250 250 250
50892-234 234 234 253 253 253 253 253 253 253 253 253
50893-253 253 253 253 253 253 253 253 253 246 246 246
50894-238 238 238 226 226 226 210 210 210 202 202 202
50895-195 195 195 195 195 195 210 210 210 158 158 158
50896- 6 6 6 14 14 14 50 50 50 14 14 14
50897- 2 2 6 2 2 6 2 2 6 2 2 6
50898- 2 2 6 6 6 6 86 86 86 46 46 46
50899- 18 18 18 6 6 6 0 0 0 0 0 0
50900- 0 0 0 0 0 0 0 0 0 0 0 0
50901- 0 0 0 0 0 0 0 0 0 0 0 0
50902- 0 0 0 0 0 0 0 0 0 0 0 0
50903- 0 0 0 0 0 0 0 0 0 0 0 0
50904- 0 0 0 0 0 0 0 0 0 0 0 0
50905- 0 0 0 0 0 0 0 0 0 0 0 0
50906- 0 0 0 0 0 0 0 0 0 0 0 0
50907- 0 0 0 0 0 0 0 0 0 6 6 6
50908- 22 22 22 54 54 54 70 70 70 2 2 6
50909- 2 2 6 10 10 10 2 2 6 22 22 22
50910-166 166 166 231 231 231 250 250 250 253 253 253
50911-253 253 253 253 253 253 253 253 253 250 250 250
50912-242 242 242 253 253 253 253 253 253 253 253 253
50913-253 253 253 253 253 253 253 253 253 253 253 253
50914-253 253 253 253 253 253 253 253 253 246 246 246
50915-231 231 231 206 206 206 198 198 198 226 226 226
50916- 94 94 94 2 2 6 6 6 6 38 38 38
50917- 30 30 30 2 2 6 2 2 6 2 2 6
50918- 2 2 6 2 2 6 62 62 62 66 66 66
50919- 26 26 26 10 10 10 0 0 0 0 0 0
50920- 0 0 0 0 0 0 0 0 0 0 0 0
50921- 0 0 0 0 0 0 0 0 0 0 0 0
50922- 0 0 0 0 0 0 0 0 0 0 0 0
50923- 0 0 0 0 0 0 0 0 0 0 0 0
50924- 0 0 0 0 0 0 0 0 0 0 0 0
50925- 0 0 0 0 0 0 0 0 0 0 0 0
50926- 0 0 0 0 0 0 0 0 0 0 0 0
50927- 0 0 0 0 0 0 0 0 0 10 10 10
50928- 30 30 30 74 74 74 50 50 50 2 2 6
50929- 26 26 26 26 26 26 2 2 6 106 106 106
50930-238 238 238 253 253 253 253 253 253 253 253 253
50931-253 253 253 253 253 253 253 253 253 253 253 253
50932-253 253 253 253 253 253 253 253 253 253 253 253
50933-253 253 253 253 253 253 253 253 253 253 253 253
50934-253 253 253 253 253 253 253 253 253 253 253 253
50935-253 253 253 246 246 246 218 218 218 202 202 202
50936-210 210 210 14 14 14 2 2 6 2 2 6
50937- 30 30 30 22 22 22 2 2 6 2 2 6
50938- 2 2 6 2 2 6 18 18 18 86 86 86
50939- 42 42 42 14 14 14 0 0 0 0 0 0
50940- 0 0 0 0 0 0 0 0 0 0 0 0
50941- 0 0 0 0 0 0 0 0 0 0 0 0
50942- 0 0 0 0 0 0 0 0 0 0 0 0
50943- 0 0 0 0 0 0 0 0 0 0 0 0
50944- 0 0 0 0 0 0 0 0 0 0 0 0
50945- 0 0 0 0 0 0 0 0 0 0 0 0
50946- 0 0 0 0 0 0 0 0 0 0 0 0
50947- 0 0 0 0 0 0 0 0 0 14 14 14
50948- 42 42 42 90 90 90 22 22 22 2 2 6
50949- 42 42 42 2 2 6 18 18 18 218 218 218
50950-253 253 253 253 253 253 253 253 253 253 253 253
50951-253 253 253 253 253 253 253 253 253 253 253 253
50952-253 253 253 253 253 253 253 253 253 253 253 253
50953-253 253 253 253 253 253 253 253 253 253 253 253
50954-253 253 253 253 253 253 253 253 253 253 253 253
50955-253 253 253 253 253 253 250 250 250 221 221 221
50956-218 218 218 101 101 101 2 2 6 14 14 14
50957- 18 18 18 38 38 38 10 10 10 2 2 6
50958- 2 2 6 2 2 6 2 2 6 78 78 78
50959- 58 58 58 22 22 22 6 6 6 0 0 0
50960- 0 0 0 0 0 0 0 0 0 0 0 0
50961- 0 0 0 0 0 0 0 0 0 0 0 0
50962- 0 0 0 0 0 0 0 0 0 0 0 0
50963- 0 0 0 0 0 0 0 0 0 0 0 0
50964- 0 0 0 0 0 0 0 0 0 0 0 0
50965- 0 0 0 0 0 0 0 0 0 0 0 0
50966- 0 0 0 0 0 0 0 0 0 0 0 0
50967- 0 0 0 0 0 0 6 6 6 18 18 18
50968- 54 54 54 82 82 82 2 2 6 26 26 26
50969- 22 22 22 2 2 6 123 123 123 253 253 253
50970-253 253 253 253 253 253 253 253 253 253 253 253
50971-253 253 253 253 253 253 253 253 253 253 253 253
50972-253 253 253 253 253 253 253 253 253 253 253 253
50973-253 253 253 253 253 253 253 253 253 253 253 253
50974-253 253 253 253 253 253 253 253 253 253 253 253
50975-253 253 253 253 253 253 253 253 253 250 250 250
50976-238 238 238 198 198 198 6 6 6 38 38 38
50977- 58 58 58 26 26 26 38 38 38 2 2 6
50978- 2 2 6 2 2 6 2 2 6 46 46 46
50979- 78 78 78 30 30 30 10 10 10 0 0 0
50980- 0 0 0 0 0 0 0 0 0 0 0 0
50981- 0 0 0 0 0 0 0 0 0 0 0 0
50982- 0 0 0 0 0 0 0 0 0 0 0 0
50983- 0 0 0 0 0 0 0 0 0 0 0 0
50984- 0 0 0 0 0 0 0 0 0 0 0 0
50985- 0 0 0 0 0 0 0 0 0 0 0 0
50986- 0 0 0 0 0 0 0 0 0 0 0 0
50987- 0 0 0 0 0 0 10 10 10 30 30 30
50988- 74 74 74 58 58 58 2 2 6 42 42 42
50989- 2 2 6 22 22 22 231 231 231 253 253 253
50990-253 253 253 253 253 253 253 253 253 253 253 253
50991-253 253 253 253 253 253 253 253 253 250 250 250
50992-253 253 253 253 253 253 253 253 253 253 253 253
50993-253 253 253 253 253 253 253 253 253 253 253 253
50994-253 253 253 253 253 253 253 253 253 253 253 253
50995-253 253 253 253 253 253 253 253 253 253 253 253
50996-253 253 253 246 246 246 46 46 46 38 38 38
50997- 42 42 42 14 14 14 38 38 38 14 14 14
50998- 2 2 6 2 2 6 2 2 6 6 6 6
50999- 86 86 86 46 46 46 14 14 14 0 0 0
51000- 0 0 0 0 0 0 0 0 0 0 0 0
51001- 0 0 0 0 0 0 0 0 0 0 0 0
51002- 0 0 0 0 0 0 0 0 0 0 0 0
51003- 0 0 0 0 0 0 0 0 0 0 0 0
51004- 0 0 0 0 0 0 0 0 0 0 0 0
51005- 0 0 0 0 0 0 0 0 0 0 0 0
51006- 0 0 0 0 0 0 0 0 0 0 0 0
51007- 0 0 0 6 6 6 14 14 14 42 42 42
51008- 90 90 90 18 18 18 18 18 18 26 26 26
51009- 2 2 6 116 116 116 253 253 253 253 253 253
51010-253 253 253 253 253 253 253 253 253 253 253 253
51011-253 253 253 253 253 253 250 250 250 238 238 238
51012-253 253 253 253 253 253 253 253 253 253 253 253
51013-253 253 253 253 253 253 253 253 253 253 253 253
51014-253 253 253 253 253 253 253 253 253 253 253 253
51015-253 253 253 253 253 253 253 253 253 253 253 253
51016-253 253 253 253 253 253 94 94 94 6 6 6
51017- 2 2 6 2 2 6 10 10 10 34 34 34
51018- 2 2 6 2 2 6 2 2 6 2 2 6
51019- 74 74 74 58 58 58 22 22 22 6 6 6
51020- 0 0 0 0 0 0 0 0 0 0 0 0
51021- 0 0 0 0 0 0 0 0 0 0 0 0
51022- 0 0 0 0 0 0 0 0 0 0 0 0
51023- 0 0 0 0 0 0 0 0 0 0 0 0
51024- 0 0 0 0 0 0 0 0 0 0 0 0
51025- 0 0 0 0 0 0 0 0 0 0 0 0
51026- 0 0 0 0 0 0 0 0 0 0 0 0
51027- 0 0 0 10 10 10 26 26 26 66 66 66
51028- 82 82 82 2 2 6 38 38 38 6 6 6
51029- 14 14 14 210 210 210 253 253 253 253 253 253
51030-253 253 253 253 253 253 253 253 253 253 253 253
51031-253 253 253 253 253 253 246 246 246 242 242 242
51032-253 253 253 253 253 253 253 253 253 253 253 253
51033-253 253 253 253 253 253 253 253 253 253 253 253
51034-253 253 253 253 253 253 253 253 253 253 253 253
51035-253 253 253 253 253 253 253 253 253 253 253 253
51036-253 253 253 253 253 253 144 144 144 2 2 6
51037- 2 2 6 2 2 6 2 2 6 46 46 46
51038- 2 2 6 2 2 6 2 2 6 2 2 6
51039- 42 42 42 74 74 74 30 30 30 10 10 10
51040- 0 0 0 0 0 0 0 0 0 0 0 0
51041- 0 0 0 0 0 0 0 0 0 0 0 0
51042- 0 0 0 0 0 0 0 0 0 0 0 0
51043- 0 0 0 0 0 0 0 0 0 0 0 0
51044- 0 0 0 0 0 0 0 0 0 0 0 0
51045- 0 0 0 0 0 0 0 0 0 0 0 0
51046- 0 0 0 0 0 0 0 0 0 0 0 0
51047- 6 6 6 14 14 14 42 42 42 90 90 90
51048- 26 26 26 6 6 6 42 42 42 2 2 6
51049- 74 74 74 250 250 250 253 253 253 253 253 253
51050-253 253 253 253 253 253 253 253 253 253 253 253
51051-253 253 253 253 253 253 242 242 242 242 242 242
51052-253 253 253 253 253 253 253 253 253 253 253 253
51053-253 253 253 253 253 253 253 253 253 253 253 253
51054-253 253 253 253 253 253 253 253 253 253 253 253
51055-253 253 253 253 253 253 253 253 253 253 253 253
51056-253 253 253 253 253 253 182 182 182 2 2 6
51057- 2 2 6 2 2 6 2 2 6 46 46 46
51058- 2 2 6 2 2 6 2 2 6 2 2 6
51059- 10 10 10 86 86 86 38 38 38 10 10 10
51060- 0 0 0 0 0 0 0 0 0 0 0 0
51061- 0 0 0 0 0 0 0 0 0 0 0 0
51062- 0 0 0 0 0 0 0 0 0 0 0 0
51063- 0 0 0 0 0 0 0 0 0 0 0 0
51064- 0 0 0 0 0 0 0 0 0 0 0 0
51065- 0 0 0 0 0 0 0 0 0 0 0 0
51066- 0 0 0 0 0 0 0 0 0 0 0 0
51067- 10 10 10 26 26 26 66 66 66 82 82 82
51068- 2 2 6 22 22 22 18 18 18 2 2 6
51069-149 149 149 253 253 253 253 253 253 253 253 253
51070-253 253 253 253 253 253 253 253 253 253 253 253
51071-253 253 253 253 253 253 234 234 234 242 242 242
51072-253 253 253 253 253 253 253 253 253 253 253 253
51073-253 253 253 253 253 253 253 253 253 253 253 253
51074-253 253 253 253 253 253 253 253 253 253 253 253
51075-253 253 253 253 253 253 253 253 253 253 253 253
51076-253 253 253 253 253 253 206 206 206 2 2 6
51077- 2 2 6 2 2 6 2 2 6 38 38 38
51078- 2 2 6 2 2 6 2 2 6 2 2 6
51079- 6 6 6 86 86 86 46 46 46 14 14 14
51080- 0 0 0 0 0 0 0 0 0 0 0 0
51081- 0 0 0 0 0 0 0 0 0 0 0 0
51082- 0 0 0 0 0 0 0 0 0 0 0 0
51083- 0 0 0 0 0 0 0 0 0 0 0 0
51084- 0 0 0 0 0 0 0 0 0 0 0 0
51085- 0 0 0 0 0 0 0 0 0 0 0 0
51086- 0 0 0 0 0 0 0 0 0 6 6 6
51087- 18 18 18 46 46 46 86 86 86 18 18 18
51088- 2 2 6 34 34 34 10 10 10 6 6 6
51089-210 210 210 253 253 253 253 253 253 253 253 253
51090-253 253 253 253 253 253 253 253 253 253 253 253
51091-253 253 253 253 253 253 234 234 234 242 242 242
51092-253 253 253 253 253 253 253 253 253 253 253 253
51093-253 253 253 253 253 253 253 253 253 253 253 253
51094-253 253 253 253 253 253 253 253 253 253 253 253
51095-253 253 253 253 253 253 253 253 253 253 253 253
51096-253 253 253 253 253 253 221 221 221 6 6 6
51097- 2 2 6 2 2 6 6 6 6 30 30 30
51098- 2 2 6 2 2 6 2 2 6 2 2 6
51099- 2 2 6 82 82 82 54 54 54 18 18 18
51100- 6 6 6 0 0 0 0 0 0 0 0 0
51101- 0 0 0 0 0 0 0 0 0 0 0 0
51102- 0 0 0 0 0 0 0 0 0 0 0 0
51103- 0 0 0 0 0 0 0 0 0 0 0 0
51104- 0 0 0 0 0 0 0 0 0 0 0 0
51105- 0 0 0 0 0 0 0 0 0 0 0 0
51106- 0 0 0 0 0 0 0 0 0 10 10 10
51107- 26 26 26 66 66 66 62 62 62 2 2 6
51108- 2 2 6 38 38 38 10 10 10 26 26 26
51109-238 238 238 253 253 253 253 253 253 253 253 253
51110-253 253 253 253 253 253 253 253 253 253 253 253
51111-253 253 253 253 253 253 231 231 231 238 238 238
51112-253 253 253 253 253 253 253 253 253 253 253 253
51113-253 253 253 253 253 253 253 253 253 253 253 253
51114-253 253 253 253 253 253 253 253 253 253 253 253
51115-253 253 253 253 253 253 253 253 253 253 253 253
51116-253 253 253 253 253 253 231 231 231 6 6 6
51117- 2 2 6 2 2 6 10 10 10 30 30 30
51118- 2 2 6 2 2 6 2 2 6 2 2 6
51119- 2 2 6 66 66 66 58 58 58 22 22 22
51120- 6 6 6 0 0 0 0 0 0 0 0 0
51121- 0 0 0 0 0 0 0 0 0 0 0 0
51122- 0 0 0 0 0 0 0 0 0 0 0 0
51123- 0 0 0 0 0 0 0 0 0 0 0 0
51124- 0 0 0 0 0 0 0 0 0 0 0 0
51125- 0 0 0 0 0 0 0 0 0 0 0 0
51126- 0 0 0 0 0 0 0 0 0 10 10 10
51127- 38 38 38 78 78 78 6 6 6 2 2 6
51128- 2 2 6 46 46 46 14 14 14 42 42 42
51129-246 246 246 253 253 253 253 253 253 253 253 253
51130-253 253 253 253 253 253 253 253 253 253 253 253
51131-253 253 253 253 253 253 231 231 231 242 242 242
51132-253 253 253 253 253 253 253 253 253 253 253 253
51133-253 253 253 253 253 253 253 253 253 253 253 253
51134-253 253 253 253 253 253 253 253 253 253 253 253
51135-253 253 253 253 253 253 253 253 253 253 253 253
51136-253 253 253 253 253 253 234 234 234 10 10 10
51137- 2 2 6 2 2 6 22 22 22 14 14 14
51138- 2 2 6 2 2 6 2 2 6 2 2 6
51139- 2 2 6 66 66 66 62 62 62 22 22 22
51140- 6 6 6 0 0 0 0 0 0 0 0 0
51141- 0 0 0 0 0 0 0 0 0 0 0 0
51142- 0 0 0 0 0 0 0 0 0 0 0 0
51143- 0 0 0 0 0 0 0 0 0 0 0 0
51144- 0 0 0 0 0 0 0 0 0 0 0 0
51145- 0 0 0 0 0 0 0 0 0 0 0 0
51146- 0 0 0 0 0 0 6 6 6 18 18 18
51147- 50 50 50 74 74 74 2 2 6 2 2 6
51148- 14 14 14 70 70 70 34 34 34 62 62 62
51149-250 250 250 253 253 253 253 253 253 253 253 253
51150-253 253 253 253 253 253 253 253 253 253 253 253
51151-253 253 253 253 253 253 231 231 231 246 246 246
51152-253 253 253 253 253 253 253 253 253 253 253 253
51153-253 253 253 253 253 253 253 253 253 253 253 253
51154-253 253 253 253 253 253 253 253 253 253 253 253
51155-253 253 253 253 253 253 253 253 253 253 253 253
51156-253 253 253 253 253 253 234 234 234 14 14 14
51157- 2 2 6 2 2 6 30 30 30 2 2 6
51158- 2 2 6 2 2 6 2 2 6 2 2 6
51159- 2 2 6 66 66 66 62 62 62 22 22 22
51160- 6 6 6 0 0 0 0 0 0 0 0 0
51161- 0 0 0 0 0 0 0 0 0 0 0 0
51162- 0 0 0 0 0 0 0 0 0 0 0 0
51163- 0 0 0 0 0 0 0 0 0 0 0 0
51164- 0 0 0 0 0 0 0 0 0 0 0 0
51165- 0 0 0 0 0 0 0 0 0 0 0 0
51166- 0 0 0 0 0 0 6 6 6 18 18 18
51167- 54 54 54 62 62 62 2 2 6 2 2 6
51168- 2 2 6 30 30 30 46 46 46 70 70 70
51169-250 250 250 253 253 253 253 253 253 253 253 253
51170-253 253 253 253 253 253 253 253 253 253 253 253
51171-253 253 253 253 253 253 231 231 231 246 246 246
51172-253 253 253 253 253 253 253 253 253 253 253 253
51173-253 253 253 253 253 253 253 253 253 253 253 253
51174-253 253 253 253 253 253 253 253 253 253 253 253
51175-253 253 253 253 253 253 253 253 253 253 253 253
51176-253 253 253 253 253 253 226 226 226 10 10 10
51177- 2 2 6 6 6 6 30 30 30 2 2 6
51178- 2 2 6 2 2 6 2 2 6 2 2 6
51179- 2 2 6 66 66 66 58 58 58 22 22 22
51180- 6 6 6 0 0 0 0 0 0 0 0 0
51181- 0 0 0 0 0 0 0 0 0 0 0 0
51182- 0 0 0 0 0 0 0 0 0 0 0 0
51183- 0 0 0 0 0 0 0 0 0 0 0 0
51184- 0 0 0 0 0 0 0 0 0 0 0 0
51185- 0 0 0 0 0 0 0 0 0 0 0 0
51186- 0 0 0 0 0 0 6 6 6 22 22 22
51187- 58 58 58 62 62 62 2 2 6 2 2 6
51188- 2 2 6 2 2 6 30 30 30 78 78 78
51189-250 250 250 253 253 253 253 253 253 253 253 253
51190-253 253 253 253 253 253 253 253 253 253 253 253
51191-253 253 253 253 253 253 231 231 231 246 246 246
51192-253 253 253 253 253 253 253 253 253 253 253 253
51193-253 253 253 253 253 253 253 253 253 253 253 253
51194-253 253 253 253 253 253 253 253 253 253 253 253
51195-253 253 253 253 253 253 253 253 253 253 253 253
51196-253 253 253 253 253 253 206 206 206 2 2 6
51197- 22 22 22 34 34 34 18 14 6 22 22 22
51198- 26 26 26 18 18 18 6 6 6 2 2 6
51199- 2 2 6 82 82 82 54 54 54 18 18 18
51200- 6 6 6 0 0 0 0 0 0 0 0 0
51201- 0 0 0 0 0 0 0 0 0 0 0 0
51202- 0 0 0 0 0 0 0 0 0 0 0 0
51203- 0 0 0 0 0 0 0 0 0 0 0 0
51204- 0 0 0 0 0 0 0 0 0 0 0 0
51205- 0 0 0 0 0 0 0 0 0 0 0 0
51206- 0 0 0 0 0 0 6 6 6 26 26 26
51207- 62 62 62 106 106 106 74 54 14 185 133 11
51208-210 162 10 121 92 8 6 6 6 62 62 62
51209-238 238 238 253 253 253 253 253 253 253 253 253
51210-253 253 253 253 253 253 253 253 253 253 253 253
51211-253 253 253 253 253 253 231 231 231 246 246 246
51212-253 253 253 253 253 253 253 253 253 253 253 253
51213-253 253 253 253 253 253 253 253 253 253 253 253
51214-253 253 253 253 253 253 253 253 253 253 253 253
51215-253 253 253 253 253 253 253 253 253 253 253 253
51216-253 253 253 253 253 253 158 158 158 18 18 18
51217- 14 14 14 2 2 6 2 2 6 2 2 6
51218- 6 6 6 18 18 18 66 66 66 38 38 38
51219- 6 6 6 94 94 94 50 50 50 18 18 18
51220- 6 6 6 0 0 0 0 0 0 0 0 0
51221- 0 0 0 0 0 0 0 0 0 0 0 0
51222- 0 0 0 0 0 0 0 0 0 0 0 0
51223- 0 0 0 0 0 0 0 0 0 0 0 0
51224- 0 0 0 0 0 0 0 0 0 0 0 0
51225- 0 0 0 0 0 0 0 0 0 6 6 6
51226- 10 10 10 10 10 10 18 18 18 38 38 38
51227- 78 78 78 142 134 106 216 158 10 242 186 14
51228-246 190 14 246 190 14 156 118 10 10 10 10
51229- 90 90 90 238 238 238 253 253 253 253 253 253
51230-253 253 253 253 253 253 253 253 253 253 253 253
51231-253 253 253 253 253 253 231 231 231 250 250 250
51232-253 253 253 253 253 253 253 253 253 253 253 253
51233-253 253 253 253 253 253 253 253 253 253 253 253
51234-253 253 253 253 253 253 253 253 253 253 253 253
51235-253 253 253 253 253 253 253 253 253 246 230 190
51236-238 204 91 238 204 91 181 142 44 37 26 9
51237- 2 2 6 2 2 6 2 2 6 2 2 6
51238- 2 2 6 2 2 6 38 38 38 46 46 46
51239- 26 26 26 106 106 106 54 54 54 18 18 18
51240- 6 6 6 0 0 0 0 0 0 0 0 0
51241- 0 0 0 0 0 0 0 0 0 0 0 0
51242- 0 0 0 0 0 0 0 0 0 0 0 0
51243- 0 0 0 0 0 0 0 0 0 0 0 0
51244- 0 0 0 0 0 0 0 0 0 0 0 0
51245- 0 0 0 6 6 6 14 14 14 22 22 22
51246- 30 30 30 38 38 38 50 50 50 70 70 70
51247-106 106 106 190 142 34 226 170 11 242 186 14
51248-246 190 14 246 190 14 246 190 14 154 114 10
51249- 6 6 6 74 74 74 226 226 226 253 253 253
51250-253 253 253 253 253 253 253 253 253 253 253 253
51251-253 253 253 253 253 253 231 231 231 250 250 250
51252-253 253 253 253 253 253 253 253 253 253 253 253
51253-253 253 253 253 253 253 253 253 253 253 253 253
51254-253 253 253 253 253 253 253 253 253 253 253 253
51255-253 253 253 253 253 253 253 253 253 228 184 62
51256-241 196 14 241 208 19 232 195 16 38 30 10
51257- 2 2 6 2 2 6 2 2 6 2 2 6
51258- 2 2 6 6 6 6 30 30 30 26 26 26
51259-203 166 17 154 142 90 66 66 66 26 26 26
51260- 6 6 6 0 0 0 0 0 0 0 0 0
51261- 0 0 0 0 0 0 0 0 0 0 0 0
51262- 0 0 0 0 0 0 0 0 0 0 0 0
51263- 0 0 0 0 0 0 0 0 0 0 0 0
51264- 0 0 0 0 0 0 0 0 0 0 0 0
51265- 6 6 6 18 18 18 38 38 38 58 58 58
51266- 78 78 78 86 86 86 101 101 101 123 123 123
51267-175 146 61 210 150 10 234 174 13 246 186 14
51268-246 190 14 246 190 14 246 190 14 238 190 10
51269-102 78 10 2 2 6 46 46 46 198 198 198
51270-253 253 253 253 253 253 253 253 253 253 253 253
51271-253 253 253 253 253 253 234 234 234 242 242 242
51272-253 253 253 253 253 253 253 253 253 253 253 253
51273-253 253 253 253 253 253 253 253 253 253 253 253
51274-253 253 253 253 253 253 253 253 253 253 253 253
51275-253 253 253 253 253 253 253 253 253 224 178 62
51276-242 186 14 241 196 14 210 166 10 22 18 6
51277- 2 2 6 2 2 6 2 2 6 2 2 6
51278- 2 2 6 2 2 6 6 6 6 121 92 8
51279-238 202 15 232 195 16 82 82 82 34 34 34
51280- 10 10 10 0 0 0 0 0 0 0 0 0
51281- 0 0 0 0 0 0 0 0 0 0 0 0
51282- 0 0 0 0 0 0 0 0 0 0 0 0
51283- 0 0 0 0 0 0 0 0 0 0 0 0
51284- 0 0 0 0 0 0 0 0 0 0 0 0
51285- 14 14 14 38 38 38 70 70 70 154 122 46
51286-190 142 34 200 144 11 197 138 11 197 138 11
51287-213 154 11 226 170 11 242 186 14 246 190 14
51288-246 190 14 246 190 14 246 190 14 246 190 14
51289-225 175 15 46 32 6 2 2 6 22 22 22
51290-158 158 158 250 250 250 253 253 253 253 253 253
51291-253 253 253 253 253 253 253 253 253 253 253 253
51292-253 253 253 253 253 253 253 253 253 253 253 253
51293-253 253 253 253 253 253 253 253 253 253 253 253
51294-253 253 253 253 253 253 253 253 253 253 253 253
51295-253 253 253 250 250 250 242 242 242 224 178 62
51296-239 182 13 236 186 11 213 154 11 46 32 6
51297- 2 2 6 2 2 6 2 2 6 2 2 6
51298- 2 2 6 2 2 6 61 42 6 225 175 15
51299-238 190 10 236 186 11 112 100 78 42 42 42
51300- 14 14 14 0 0 0 0 0 0 0 0 0
51301- 0 0 0 0 0 0 0 0 0 0 0 0
51302- 0 0 0 0 0 0 0 0 0 0 0 0
51303- 0 0 0 0 0 0 0 0 0 0 0 0
51304- 0 0 0 0 0 0 0 0 0 6 6 6
51305- 22 22 22 54 54 54 154 122 46 213 154 11
51306-226 170 11 230 174 11 226 170 11 226 170 11
51307-236 178 12 242 186 14 246 190 14 246 190 14
51308-246 190 14 246 190 14 246 190 14 246 190 14
51309-241 196 14 184 144 12 10 10 10 2 2 6
51310- 6 6 6 116 116 116 242 242 242 253 253 253
51311-253 253 253 253 253 253 253 253 253 253 253 253
51312-253 253 253 253 253 253 253 253 253 253 253 253
51313-253 253 253 253 253 253 253 253 253 253 253 253
51314-253 253 253 253 253 253 253 253 253 253 253 253
51315-253 253 253 231 231 231 198 198 198 214 170 54
51316-236 178 12 236 178 12 210 150 10 137 92 6
51317- 18 14 6 2 2 6 2 2 6 2 2 6
51318- 6 6 6 70 47 6 200 144 11 236 178 12
51319-239 182 13 239 182 13 124 112 88 58 58 58
51320- 22 22 22 6 6 6 0 0 0 0 0 0
51321- 0 0 0 0 0 0 0 0 0 0 0 0
51322- 0 0 0 0 0 0 0 0 0 0 0 0
51323- 0 0 0 0 0 0 0 0 0 0 0 0
51324- 0 0 0 0 0 0 0 0 0 10 10 10
51325- 30 30 30 70 70 70 180 133 36 226 170 11
51326-239 182 13 242 186 14 242 186 14 246 186 14
51327-246 190 14 246 190 14 246 190 14 246 190 14
51328-246 190 14 246 190 14 246 190 14 246 190 14
51329-246 190 14 232 195 16 98 70 6 2 2 6
51330- 2 2 6 2 2 6 66 66 66 221 221 221
51331-253 253 253 253 253 253 253 253 253 253 253 253
51332-253 253 253 253 253 253 253 253 253 253 253 253
51333-253 253 253 253 253 253 253 253 253 253 253 253
51334-253 253 253 253 253 253 253 253 253 253 253 253
51335-253 253 253 206 206 206 198 198 198 214 166 58
51336-230 174 11 230 174 11 216 158 10 192 133 9
51337-163 110 8 116 81 8 102 78 10 116 81 8
51338-167 114 7 197 138 11 226 170 11 239 182 13
51339-242 186 14 242 186 14 162 146 94 78 78 78
51340- 34 34 34 14 14 14 6 6 6 0 0 0
51341- 0 0 0 0 0 0 0 0 0 0 0 0
51342- 0 0 0 0 0 0 0 0 0 0 0 0
51343- 0 0 0 0 0 0 0 0 0 0 0 0
51344- 0 0 0 0 0 0 0 0 0 6 6 6
51345- 30 30 30 78 78 78 190 142 34 226 170 11
51346-239 182 13 246 190 14 246 190 14 246 190 14
51347-246 190 14 246 190 14 246 190 14 246 190 14
51348-246 190 14 246 190 14 246 190 14 246 190 14
51349-246 190 14 241 196 14 203 166 17 22 18 6
51350- 2 2 6 2 2 6 2 2 6 38 38 38
51351-218 218 218 253 253 253 253 253 253 253 253 253
51352-253 253 253 253 253 253 253 253 253 253 253 253
51353-253 253 253 253 253 253 253 253 253 253 253 253
51354-253 253 253 253 253 253 253 253 253 253 253 253
51355-250 250 250 206 206 206 198 198 198 202 162 69
51356-226 170 11 236 178 12 224 166 10 210 150 10
51357-200 144 11 197 138 11 192 133 9 197 138 11
51358-210 150 10 226 170 11 242 186 14 246 190 14
51359-246 190 14 246 186 14 225 175 15 124 112 88
51360- 62 62 62 30 30 30 14 14 14 6 6 6
51361- 0 0 0 0 0 0 0 0 0 0 0 0
51362- 0 0 0 0 0 0 0 0 0 0 0 0
51363- 0 0 0 0 0 0 0 0 0 0 0 0
51364- 0 0 0 0 0 0 0 0 0 10 10 10
51365- 30 30 30 78 78 78 174 135 50 224 166 10
51366-239 182 13 246 190 14 246 190 14 246 190 14
51367-246 190 14 246 190 14 246 190 14 246 190 14
51368-246 190 14 246 190 14 246 190 14 246 190 14
51369-246 190 14 246 190 14 241 196 14 139 102 15
51370- 2 2 6 2 2 6 2 2 6 2 2 6
51371- 78 78 78 250 250 250 253 253 253 253 253 253
51372-253 253 253 253 253 253 253 253 253 253 253 253
51373-253 253 253 253 253 253 253 253 253 253 253 253
51374-253 253 253 253 253 253 253 253 253 253 253 253
51375-250 250 250 214 214 214 198 198 198 190 150 46
51376-219 162 10 236 178 12 234 174 13 224 166 10
51377-216 158 10 213 154 11 213 154 11 216 158 10
51378-226 170 11 239 182 13 246 190 14 246 190 14
51379-246 190 14 246 190 14 242 186 14 206 162 42
51380-101 101 101 58 58 58 30 30 30 14 14 14
51381- 6 6 6 0 0 0 0 0 0 0 0 0
51382- 0 0 0 0 0 0 0 0 0 0 0 0
51383- 0 0 0 0 0 0 0 0 0 0 0 0
51384- 0 0 0 0 0 0 0 0 0 10 10 10
51385- 30 30 30 74 74 74 174 135 50 216 158 10
51386-236 178 12 246 190 14 246 190 14 246 190 14
51387-246 190 14 246 190 14 246 190 14 246 190 14
51388-246 190 14 246 190 14 246 190 14 246 190 14
51389-246 190 14 246 190 14 241 196 14 226 184 13
51390- 61 42 6 2 2 6 2 2 6 2 2 6
51391- 22 22 22 238 238 238 253 253 253 253 253 253
51392-253 253 253 253 253 253 253 253 253 253 253 253
51393-253 253 253 253 253 253 253 253 253 253 253 253
51394-253 253 253 253 253 253 253 253 253 253 253 253
51395-253 253 253 226 226 226 187 187 187 180 133 36
51396-216 158 10 236 178 12 239 182 13 236 178 12
51397-230 174 11 226 170 11 226 170 11 230 174 11
51398-236 178 12 242 186 14 246 190 14 246 190 14
51399-246 190 14 246 190 14 246 186 14 239 182 13
51400-206 162 42 106 106 106 66 66 66 34 34 34
51401- 14 14 14 6 6 6 0 0 0 0 0 0
51402- 0 0 0 0 0 0 0 0 0 0 0 0
51403- 0 0 0 0 0 0 0 0 0 0 0 0
51404- 0 0 0 0 0 0 0 0 0 6 6 6
51405- 26 26 26 70 70 70 163 133 67 213 154 11
51406-236 178 12 246 190 14 246 190 14 246 190 14
51407-246 190 14 246 190 14 246 190 14 246 190 14
51408-246 190 14 246 190 14 246 190 14 246 190 14
51409-246 190 14 246 190 14 246 190 14 241 196 14
51410-190 146 13 18 14 6 2 2 6 2 2 6
51411- 46 46 46 246 246 246 253 253 253 253 253 253
51412-253 253 253 253 253 253 253 253 253 253 253 253
51413-253 253 253 253 253 253 253 253 253 253 253 253
51414-253 253 253 253 253 253 253 253 253 253 253 253
51415-253 253 253 221 221 221 86 86 86 156 107 11
51416-216 158 10 236 178 12 242 186 14 246 186 14
51417-242 186 14 239 182 13 239 182 13 242 186 14
51418-242 186 14 246 186 14 246 190 14 246 190 14
51419-246 190 14 246 190 14 246 190 14 246 190 14
51420-242 186 14 225 175 15 142 122 72 66 66 66
51421- 30 30 30 10 10 10 0 0 0 0 0 0
51422- 0 0 0 0 0 0 0 0 0 0 0 0
51423- 0 0 0 0 0 0 0 0 0 0 0 0
51424- 0 0 0 0 0 0 0 0 0 6 6 6
51425- 26 26 26 70 70 70 163 133 67 210 150 10
51426-236 178 12 246 190 14 246 190 14 246 190 14
51427-246 190 14 246 190 14 246 190 14 246 190 14
51428-246 190 14 246 190 14 246 190 14 246 190 14
51429-246 190 14 246 190 14 246 190 14 246 190 14
51430-232 195 16 121 92 8 34 34 34 106 106 106
51431-221 221 221 253 253 253 253 253 253 253 253 253
51432-253 253 253 253 253 253 253 253 253 253 253 253
51433-253 253 253 253 253 253 253 253 253 253 253 253
51434-253 253 253 253 253 253 253 253 253 253 253 253
51435-242 242 242 82 82 82 18 14 6 163 110 8
51436-216 158 10 236 178 12 242 186 14 246 190 14
51437-246 190 14 246 190 14 246 190 14 246 190 14
51438-246 190 14 246 190 14 246 190 14 246 190 14
51439-246 190 14 246 190 14 246 190 14 246 190 14
51440-246 190 14 246 190 14 242 186 14 163 133 67
51441- 46 46 46 18 18 18 6 6 6 0 0 0
51442- 0 0 0 0 0 0 0 0 0 0 0 0
51443- 0 0 0 0 0 0 0 0 0 0 0 0
51444- 0 0 0 0 0 0 0 0 0 10 10 10
51445- 30 30 30 78 78 78 163 133 67 210 150 10
51446-236 178 12 246 186 14 246 190 14 246 190 14
51447-246 190 14 246 190 14 246 190 14 246 190 14
51448-246 190 14 246 190 14 246 190 14 246 190 14
51449-246 190 14 246 190 14 246 190 14 246 190 14
51450-241 196 14 215 174 15 190 178 144 253 253 253
51451-253 253 253 253 253 253 253 253 253 253 253 253
51452-253 253 253 253 253 253 253 253 253 253 253 253
51453-253 253 253 253 253 253 253 253 253 253 253 253
51454-253 253 253 253 253 253 253 253 253 218 218 218
51455- 58 58 58 2 2 6 22 18 6 167 114 7
51456-216 158 10 236 178 12 246 186 14 246 190 14
51457-246 190 14 246 190 14 246 190 14 246 190 14
51458-246 190 14 246 190 14 246 190 14 246 190 14
51459-246 190 14 246 190 14 246 190 14 246 190 14
51460-246 190 14 246 186 14 242 186 14 190 150 46
51461- 54 54 54 22 22 22 6 6 6 0 0 0
51462- 0 0 0 0 0 0 0 0 0 0 0 0
51463- 0 0 0 0 0 0 0 0 0 0 0 0
51464- 0 0 0 0 0 0 0 0 0 14 14 14
51465- 38 38 38 86 86 86 180 133 36 213 154 11
51466-236 178 12 246 186 14 246 190 14 246 190 14
51467-246 190 14 246 190 14 246 190 14 246 190 14
51468-246 190 14 246 190 14 246 190 14 246 190 14
51469-246 190 14 246 190 14 246 190 14 246 190 14
51470-246 190 14 232 195 16 190 146 13 214 214 214
51471-253 253 253 253 253 253 253 253 253 253 253 253
51472-253 253 253 253 253 253 253 253 253 253 253 253
51473-253 253 253 253 253 253 253 253 253 253 253 253
51474-253 253 253 250 250 250 170 170 170 26 26 26
51475- 2 2 6 2 2 6 37 26 9 163 110 8
51476-219 162 10 239 182 13 246 186 14 246 190 14
51477-246 190 14 246 190 14 246 190 14 246 190 14
51478-246 190 14 246 190 14 246 190 14 246 190 14
51479-246 190 14 246 190 14 246 190 14 246 190 14
51480-246 186 14 236 178 12 224 166 10 142 122 72
51481- 46 46 46 18 18 18 6 6 6 0 0 0
51482- 0 0 0 0 0 0 0 0 0 0 0 0
51483- 0 0 0 0 0 0 0 0 0 0 0 0
51484- 0 0 0 0 0 0 6 6 6 18 18 18
51485- 50 50 50 109 106 95 192 133 9 224 166 10
51486-242 186 14 246 190 14 246 190 14 246 190 14
51487-246 190 14 246 190 14 246 190 14 246 190 14
51488-246 190 14 246 190 14 246 190 14 246 190 14
51489-246 190 14 246 190 14 246 190 14 246 190 14
51490-242 186 14 226 184 13 210 162 10 142 110 46
51491-226 226 226 253 253 253 253 253 253 253 253 253
51492-253 253 253 253 253 253 253 253 253 253 253 253
51493-253 253 253 253 253 253 253 253 253 253 253 253
51494-198 198 198 66 66 66 2 2 6 2 2 6
51495- 2 2 6 2 2 6 50 34 6 156 107 11
51496-219 162 10 239 182 13 246 186 14 246 190 14
51497-246 190 14 246 190 14 246 190 14 246 190 14
51498-246 190 14 246 190 14 246 190 14 246 190 14
51499-246 190 14 246 190 14 246 190 14 242 186 14
51500-234 174 13 213 154 11 154 122 46 66 66 66
51501- 30 30 30 10 10 10 0 0 0 0 0 0
51502- 0 0 0 0 0 0 0 0 0 0 0 0
51503- 0 0 0 0 0 0 0 0 0 0 0 0
51504- 0 0 0 0 0 0 6 6 6 22 22 22
51505- 58 58 58 154 121 60 206 145 10 234 174 13
51506-242 186 14 246 186 14 246 190 14 246 190 14
51507-246 190 14 246 190 14 246 190 14 246 190 14
51508-246 190 14 246 190 14 246 190 14 246 190 14
51509-246 190 14 246 190 14 246 190 14 246 190 14
51510-246 186 14 236 178 12 210 162 10 163 110 8
51511- 61 42 6 138 138 138 218 218 218 250 250 250
51512-253 253 253 253 253 253 253 253 253 250 250 250
51513-242 242 242 210 210 210 144 144 144 66 66 66
51514- 6 6 6 2 2 6 2 2 6 2 2 6
51515- 2 2 6 2 2 6 61 42 6 163 110 8
51516-216 158 10 236 178 12 246 190 14 246 190 14
51517-246 190 14 246 190 14 246 190 14 246 190 14
51518-246 190 14 246 190 14 246 190 14 246 190 14
51519-246 190 14 239 182 13 230 174 11 216 158 10
51520-190 142 34 124 112 88 70 70 70 38 38 38
51521- 18 18 18 6 6 6 0 0 0 0 0 0
51522- 0 0 0 0 0 0 0 0 0 0 0 0
51523- 0 0 0 0 0 0 0 0 0 0 0 0
51524- 0 0 0 0 0 0 6 6 6 22 22 22
51525- 62 62 62 168 124 44 206 145 10 224 166 10
51526-236 178 12 239 182 13 242 186 14 242 186 14
51527-246 186 14 246 190 14 246 190 14 246 190 14
51528-246 190 14 246 190 14 246 190 14 246 190 14
51529-246 190 14 246 190 14 246 190 14 246 190 14
51530-246 190 14 236 178 12 216 158 10 175 118 6
51531- 80 54 7 2 2 6 6 6 6 30 30 30
51532- 54 54 54 62 62 62 50 50 50 38 38 38
51533- 14 14 14 2 2 6 2 2 6 2 2 6
51534- 2 2 6 2 2 6 2 2 6 2 2 6
51535- 2 2 6 6 6 6 80 54 7 167 114 7
51536-213 154 11 236 178 12 246 190 14 246 190 14
51537-246 190 14 246 190 14 246 190 14 246 190 14
51538-246 190 14 242 186 14 239 182 13 239 182 13
51539-230 174 11 210 150 10 174 135 50 124 112 88
51540- 82 82 82 54 54 54 34 34 34 18 18 18
51541- 6 6 6 0 0 0 0 0 0 0 0 0
51542- 0 0 0 0 0 0 0 0 0 0 0 0
51543- 0 0 0 0 0 0 0 0 0 0 0 0
51544- 0 0 0 0 0 0 6 6 6 18 18 18
51545- 50 50 50 158 118 36 192 133 9 200 144 11
51546-216 158 10 219 162 10 224 166 10 226 170 11
51547-230 174 11 236 178 12 239 182 13 239 182 13
51548-242 186 14 246 186 14 246 190 14 246 190 14
51549-246 190 14 246 190 14 246 190 14 246 190 14
51550-246 186 14 230 174 11 210 150 10 163 110 8
51551-104 69 6 10 10 10 2 2 6 2 2 6
51552- 2 2 6 2 2 6 2 2 6 2 2 6
51553- 2 2 6 2 2 6 2 2 6 2 2 6
51554- 2 2 6 2 2 6 2 2 6 2 2 6
51555- 2 2 6 6 6 6 91 60 6 167 114 7
51556-206 145 10 230 174 11 242 186 14 246 190 14
51557-246 190 14 246 190 14 246 186 14 242 186 14
51558-239 182 13 230 174 11 224 166 10 213 154 11
51559-180 133 36 124 112 88 86 86 86 58 58 58
51560- 38 38 38 22 22 22 10 10 10 6 6 6
51561- 0 0 0 0 0 0 0 0 0 0 0 0
51562- 0 0 0 0 0 0 0 0 0 0 0 0
51563- 0 0 0 0 0 0 0 0 0 0 0 0
51564- 0 0 0 0 0 0 0 0 0 14 14 14
51565- 34 34 34 70 70 70 138 110 50 158 118 36
51566-167 114 7 180 123 7 192 133 9 197 138 11
51567-200 144 11 206 145 10 213 154 11 219 162 10
51568-224 166 10 230 174 11 239 182 13 242 186 14
51569-246 186 14 246 186 14 246 186 14 246 186 14
51570-239 182 13 216 158 10 185 133 11 152 99 6
51571-104 69 6 18 14 6 2 2 6 2 2 6
51572- 2 2 6 2 2 6 2 2 6 2 2 6
51573- 2 2 6 2 2 6 2 2 6 2 2 6
51574- 2 2 6 2 2 6 2 2 6 2 2 6
51575- 2 2 6 6 6 6 80 54 7 152 99 6
51576-192 133 9 219 162 10 236 178 12 239 182 13
51577-246 186 14 242 186 14 239 182 13 236 178 12
51578-224 166 10 206 145 10 192 133 9 154 121 60
51579- 94 94 94 62 62 62 42 42 42 22 22 22
51580- 14 14 14 6 6 6 0 0 0 0 0 0
51581- 0 0 0 0 0 0 0 0 0 0 0 0
51582- 0 0 0 0 0 0 0 0 0 0 0 0
51583- 0 0 0 0 0 0 0 0 0 0 0 0
51584- 0 0 0 0 0 0 0 0 0 6 6 6
51585- 18 18 18 34 34 34 58 58 58 78 78 78
51586-101 98 89 124 112 88 142 110 46 156 107 11
51587-163 110 8 167 114 7 175 118 6 180 123 7
51588-185 133 11 197 138 11 210 150 10 219 162 10
51589-226 170 11 236 178 12 236 178 12 234 174 13
51590-219 162 10 197 138 11 163 110 8 130 83 6
51591- 91 60 6 10 10 10 2 2 6 2 2 6
51592- 18 18 18 38 38 38 38 38 38 38 38 38
51593- 38 38 38 38 38 38 38 38 38 38 38 38
51594- 38 38 38 38 38 38 26 26 26 2 2 6
51595- 2 2 6 6 6 6 70 47 6 137 92 6
51596-175 118 6 200 144 11 219 162 10 230 174 11
51597-234 174 13 230 174 11 219 162 10 210 150 10
51598-192 133 9 163 110 8 124 112 88 82 82 82
51599- 50 50 50 30 30 30 14 14 14 6 6 6
51600- 0 0 0 0 0 0 0 0 0 0 0 0
51601- 0 0 0 0 0 0 0 0 0 0 0 0
51602- 0 0 0 0 0 0 0 0 0 0 0 0
51603- 0 0 0 0 0 0 0 0 0 0 0 0
51604- 0 0 0 0 0 0 0 0 0 0 0 0
51605- 6 6 6 14 14 14 22 22 22 34 34 34
51606- 42 42 42 58 58 58 74 74 74 86 86 86
51607-101 98 89 122 102 70 130 98 46 121 87 25
51608-137 92 6 152 99 6 163 110 8 180 123 7
51609-185 133 11 197 138 11 206 145 10 200 144 11
51610-180 123 7 156 107 11 130 83 6 104 69 6
51611- 50 34 6 54 54 54 110 110 110 101 98 89
51612- 86 86 86 82 82 82 78 78 78 78 78 78
51613- 78 78 78 78 78 78 78 78 78 78 78 78
51614- 78 78 78 82 82 82 86 86 86 94 94 94
51615-106 106 106 101 101 101 86 66 34 124 80 6
51616-156 107 11 180 123 7 192 133 9 200 144 11
51617-206 145 10 200 144 11 192 133 9 175 118 6
51618-139 102 15 109 106 95 70 70 70 42 42 42
51619- 22 22 22 10 10 10 0 0 0 0 0 0
51620- 0 0 0 0 0 0 0 0 0 0 0 0
51621- 0 0 0 0 0 0 0 0 0 0 0 0
51622- 0 0 0 0 0 0 0 0 0 0 0 0
51623- 0 0 0 0 0 0 0 0 0 0 0 0
51624- 0 0 0 0 0 0 0 0 0 0 0 0
51625- 0 0 0 0 0 0 6 6 6 10 10 10
51626- 14 14 14 22 22 22 30 30 30 38 38 38
51627- 50 50 50 62 62 62 74 74 74 90 90 90
51628-101 98 89 112 100 78 121 87 25 124 80 6
51629-137 92 6 152 99 6 152 99 6 152 99 6
51630-138 86 6 124 80 6 98 70 6 86 66 30
51631-101 98 89 82 82 82 58 58 58 46 46 46
51632- 38 38 38 34 34 34 34 34 34 34 34 34
51633- 34 34 34 34 34 34 34 34 34 34 34 34
51634- 34 34 34 34 34 34 38 38 38 42 42 42
51635- 54 54 54 82 82 82 94 86 76 91 60 6
51636-134 86 6 156 107 11 167 114 7 175 118 6
51637-175 118 6 167 114 7 152 99 6 121 87 25
51638-101 98 89 62 62 62 34 34 34 18 18 18
51639- 6 6 6 0 0 0 0 0 0 0 0 0
51640- 0 0 0 0 0 0 0 0 0 0 0 0
51641- 0 0 0 0 0 0 0 0 0 0 0 0
51642- 0 0 0 0 0 0 0 0 0 0 0 0
51643- 0 0 0 0 0 0 0 0 0 0 0 0
51644- 0 0 0 0 0 0 0 0 0 0 0 0
51645- 0 0 0 0 0 0 0 0 0 0 0 0
51646- 0 0 0 6 6 6 6 6 6 10 10 10
51647- 18 18 18 22 22 22 30 30 30 42 42 42
51648- 50 50 50 66 66 66 86 86 86 101 98 89
51649-106 86 58 98 70 6 104 69 6 104 69 6
51650-104 69 6 91 60 6 82 62 34 90 90 90
51651- 62 62 62 38 38 38 22 22 22 14 14 14
51652- 10 10 10 10 10 10 10 10 10 10 10 10
51653- 10 10 10 10 10 10 6 6 6 10 10 10
51654- 10 10 10 10 10 10 10 10 10 14 14 14
51655- 22 22 22 42 42 42 70 70 70 89 81 66
51656- 80 54 7 104 69 6 124 80 6 137 92 6
51657-134 86 6 116 81 8 100 82 52 86 86 86
51658- 58 58 58 30 30 30 14 14 14 6 6 6
51659- 0 0 0 0 0 0 0 0 0 0 0 0
51660- 0 0 0 0 0 0 0 0 0 0 0 0
51661- 0 0 0 0 0 0 0 0 0 0 0 0
51662- 0 0 0 0 0 0 0 0 0 0 0 0
51663- 0 0 0 0 0 0 0 0 0 0 0 0
51664- 0 0 0 0 0 0 0 0 0 0 0 0
51665- 0 0 0 0 0 0 0 0 0 0 0 0
51666- 0 0 0 0 0 0 0 0 0 0 0 0
51667- 0 0 0 6 6 6 10 10 10 14 14 14
51668- 18 18 18 26 26 26 38 38 38 54 54 54
51669- 70 70 70 86 86 86 94 86 76 89 81 66
51670- 89 81 66 86 86 86 74 74 74 50 50 50
51671- 30 30 30 14 14 14 6 6 6 0 0 0
51672- 0 0 0 0 0 0 0 0 0 0 0 0
51673- 0 0 0 0 0 0 0 0 0 0 0 0
51674- 0 0 0 0 0 0 0 0 0 0 0 0
51675- 6 6 6 18 18 18 34 34 34 58 58 58
51676- 82 82 82 89 81 66 89 81 66 89 81 66
51677- 94 86 66 94 86 76 74 74 74 50 50 50
51678- 26 26 26 14 14 14 6 6 6 0 0 0
51679- 0 0 0 0 0 0 0 0 0 0 0 0
51680- 0 0 0 0 0 0 0 0 0 0 0 0
51681- 0 0 0 0 0 0 0 0 0 0 0 0
51682- 0 0 0 0 0 0 0 0 0 0 0 0
51683- 0 0 0 0 0 0 0 0 0 0 0 0
51684- 0 0 0 0 0 0 0 0 0 0 0 0
51685- 0 0 0 0 0 0 0 0 0 0 0 0
51686- 0 0 0 0 0 0 0 0 0 0 0 0
51687- 0 0 0 0 0 0 0 0 0 0 0 0
51688- 6 6 6 6 6 6 14 14 14 18 18 18
51689- 30 30 30 38 38 38 46 46 46 54 54 54
51690- 50 50 50 42 42 42 30 30 30 18 18 18
51691- 10 10 10 0 0 0 0 0 0 0 0 0
51692- 0 0 0 0 0 0 0 0 0 0 0 0
51693- 0 0 0 0 0 0 0 0 0 0 0 0
51694- 0 0 0 0 0 0 0 0 0 0 0 0
51695- 0 0 0 6 6 6 14 14 14 26 26 26
51696- 38 38 38 50 50 50 58 58 58 58 58 58
51697- 54 54 54 42 42 42 30 30 30 18 18 18
51698- 10 10 10 0 0 0 0 0 0 0 0 0
51699- 0 0 0 0 0 0 0 0 0 0 0 0
51700- 0 0 0 0 0 0 0 0 0 0 0 0
51701- 0 0 0 0 0 0 0 0 0 0 0 0
51702- 0 0 0 0 0 0 0 0 0 0 0 0
51703- 0 0 0 0 0 0 0 0 0 0 0 0
51704- 0 0 0 0 0 0 0 0 0 0 0 0
51705- 0 0 0 0 0 0 0 0 0 0 0 0
51706- 0 0 0 0 0 0 0 0 0 0 0 0
51707- 0 0 0 0 0 0 0 0 0 0 0 0
51708- 0 0 0 0 0 0 0 0 0 6 6 6
51709- 6 6 6 10 10 10 14 14 14 18 18 18
51710- 18 18 18 14 14 14 10 10 10 6 6 6
51711- 0 0 0 0 0 0 0 0 0 0 0 0
51712- 0 0 0 0 0 0 0 0 0 0 0 0
51713- 0 0 0 0 0 0 0 0 0 0 0 0
51714- 0 0 0 0 0 0 0 0 0 0 0 0
51715- 0 0 0 0 0 0 0 0 0 6 6 6
51716- 14 14 14 18 18 18 22 22 22 22 22 22
51717- 18 18 18 14 14 14 10 10 10 6 6 6
51718- 0 0 0 0 0 0 0 0 0 0 0 0
51719- 0 0 0 0 0 0 0 0 0 0 0 0
51720- 0 0 0 0 0 0 0 0 0 0 0 0
51721- 0 0 0 0 0 0 0 0 0 0 0 0
51722- 0 0 0 0 0 0 0 0 0 0 0 0
51723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51736+4 4 4 4 4 4
51737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51750+4 4 4 4 4 4
51751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51764+4 4 4 4 4 4
51765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51778+4 4 4 4 4 4
51779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51792+4 4 4 4 4 4
51793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51806+4 4 4 4 4 4
51807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51811+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
51812+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
51813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51816+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
51817+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51818+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
51819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51820+4 4 4 4 4 4
51821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51825+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
51826+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51827+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51830+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51831+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51832+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51833+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51834+4 4 4 4 4 4
51835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51839+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51840+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51841+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51844+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51845+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51846+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51847+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51848+4 4 4 4 4 4
51849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51852+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
51853+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51854+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51855+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51857+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51858+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51859+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51860+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51861+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51862+4 4 4 4 4 4
51863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51866+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51867+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51868+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51869+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51870+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51871+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51872+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51873+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51874+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51875+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51876+4 4 4 4 4 4
51877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51880+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51881+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51882+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51883+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51884+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51885+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51886+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51887+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51888+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51889+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51890+4 4 4 4 4 4
51891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51893+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51894+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51895+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51896+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51897+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51898+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51899+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51900+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51901+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51902+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51903+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51904+4 4 4 4 4 4
51905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51907+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51908+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51909+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51910+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51911+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51912+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51913+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51914+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51915+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51916+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51917+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51918+4 4 4 4 4 4
51919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51921+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51922+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51923+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51924+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51925+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51926+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51927+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51928+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51929+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51930+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51931+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51932+4 4 4 4 4 4
51933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51935+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51936+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51937+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51938+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51939+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51940+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51941+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51942+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51943+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51944+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51945+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51946+4 4 4 4 4 4
51947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51948+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
51949+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51950+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51951+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51952+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51953+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51954+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51955+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51956+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51957+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51958+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51959+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51960+4 4 4 4 4 4
51961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51962+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51963+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51964+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51965+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51966+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51967+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51968+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51969+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51970+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51971+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51972+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51973+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51974+0 0 0 4 4 4
51975+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51976+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51977+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51978+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51979+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51980+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51981+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51982+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51983+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51984+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51985+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51986+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51987+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51988+2 0 0 0 0 0
51989+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51990+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51991+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51992+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51993+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51994+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51995+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51996+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51997+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51998+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51999+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
52000+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
52001+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
52002+37 38 37 0 0 0
52003+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
52004+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
52005+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
52006+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
52007+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
52008+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
52009+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
52010+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
52011+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
52012+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
52013+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
52014+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
52015+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
52016+85 115 134 4 0 0
52017+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
52018+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
52019+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
52020+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
52021+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
52022+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
52023+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
52024+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
52025+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
52026+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
52027+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
52028+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
52029+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
52030+60 73 81 4 0 0
52031+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
52032+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
52033+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
52034+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
52035+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
52036+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
52037+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
52038+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
52039+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
52040+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
52041+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
52042+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
52043+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
52044+16 19 21 4 0 0
52045+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
52046+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
52047+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
52048+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
52049+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
52050+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
52051+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
52052+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
52053+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
52054+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
52055+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
52056+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
52057+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
52058+4 0 0 4 3 3
52059+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
52060+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
52061+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
52062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
52063+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
52064+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
52065+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
52066+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
52067+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
52068+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
52069+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
52070+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
52071+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
52072+3 2 2 4 4 4
52073+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
52074+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
52075+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
52076+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
52077+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
52078+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
52079+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
52080+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
52081+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
52082+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
52083+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
52084+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
52085+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
52086+4 4 4 4 4 4
52087+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
52088+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
52089+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
52090+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
52091+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
52092+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
52093+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
52094+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
52095+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
52096+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
52097+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
52098+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
52099+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
52100+4 4 4 4 4 4
52101+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
52102+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
52103+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
52104+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
52105+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
52106+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
52107+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
52108+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
52109+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
52110+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
52111+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
52112+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
52113+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
52114+5 5 5 5 5 5
52115+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
52116+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
52117+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
52118+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
52119+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
52120+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52121+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
52122+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
52123+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
52124+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
52125+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
52126+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
52127+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
52128+5 5 5 4 4 4
52129+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
52130+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
52131+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
52132+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
52133+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52134+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
52135+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
52136+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
52137+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
52138+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
52139+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
52140+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52142+4 4 4 4 4 4
52143+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
52144+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
52145+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
52146+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
52147+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
52148+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52149+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52150+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
52151+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
52152+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
52153+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
52154+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
52155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52156+4 4 4 4 4 4
52157+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
52158+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
52159+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
52160+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
52161+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52162+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
52163+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
52164+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
52165+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
52166+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
52167+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
52168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52170+4 4 4 4 4 4
52171+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
52172+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
52173+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
52174+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
52175+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52176+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52177+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
52178+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
52179+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
52180+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
52181+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
52182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52184+4 4 4 4 4 4
52185+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
52186+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
52187+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
52188+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
52189+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52190+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
52191+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
52192+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
52193+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
52194+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
52195+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52198+4 4 4 4 4 4
52199+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
52200+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
52201+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
52202+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
52203+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
52204+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
52205+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
52206+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
52207+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
52208+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
52209+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
52210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52212+4 4 4 4 4 4
52213+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
52214+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
52215+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
52216+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
52217+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
52218+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
52219+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
52220+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
52221+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
52222+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
52223+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
52224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52226+4 4 4 4 4 4
52227+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
52228+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
52229+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
52230+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
52231+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
52232+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
52233+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
52234+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
52235+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
52236+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
52237+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52240+4 4 4 4 4 4
52241+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
52242+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
52243+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
52244+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
52245+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52246+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
52247+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
52248+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
52249+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
52250+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
52251+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52254+4 4 4 4 4 4
52255+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
52256+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
52257+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
52258+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
52259+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52260+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
52261+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
52262+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
52263+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
52264+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
52265+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52268+4 4 4 4 4 4
52269+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
52270+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
52271+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
52272+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
52273+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52274+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
52275+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
52276+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
52277+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
52278+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52279+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52282+4 4 4 4 4 4
52283+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
52284+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
52285+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
52286+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
52287+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
52288+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
52289+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
52290+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
52291+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52292+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52293+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52296+4 4 4 4 4 4
52297+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
52298+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
52299+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
52300+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
52301+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52302+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
52303+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
52304+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
52305+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52306+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52307+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52310+4 4 4 4 4 4
52311+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
52312+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
52313+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52314+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
52315+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
52316+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
52317+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
52318+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
52319+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52320+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52321+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52324+4 4 4 4 4 4
52325+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
52326+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
52327+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52328+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
52329+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
52330+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
52331+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
52332+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
52333+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
52334+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52335+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52338+4 4 4 4 4 4
52339+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52340+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
52341+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52342+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
52343+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
52344+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
52345+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
52346+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
52347+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52348+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52349+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52352+4 4 4 4 4 4
52353+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
52354+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
52355+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52356+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
52357+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
52358+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
52359+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
52360+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
52361+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
52362+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52363+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52366+4 4 4 4 4 4
52367+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52368+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
52369+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
52370+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
52371+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
52372+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
52373+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
52374+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
52375+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52376+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52377+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52380+4 4 4 4 4 4
52381+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52382+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
52383+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52384+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
52385+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
52386+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
52387+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
52388+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
52389+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52390+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52391+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52394+4 4 4 4 4 4
52395+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52396+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
52397+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
52398+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
52399+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
52400+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
52401+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52402+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
52403+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52404+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52405+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52408+4 4 4 4 4 4
52409+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52410+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
52411+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
52412+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52413+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
52414+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
52415+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52416+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
52417+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52418+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52419+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52422+4 4 4 4 4 4
52423+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52424+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
52425+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
52426+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
52427+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
52428+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
52429+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
52430+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
52431+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
52432+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52433+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52436+4 4 4 4 4 4
52437+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52438+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
52439+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
52440+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
52441+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
52442+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
52443+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
52444+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
52445+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
52446+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52447+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52450+4 4 4 4 4 4
52451+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
52452+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
52453+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
52454+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
52455+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52456+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
52457+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
52458+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
52459+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
52460+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52461+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52464+4 4 4 4 4 4
52465+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52466+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
52467+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
52468+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
52469+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
52470+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
52471+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
52472+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
52473+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
52474+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52475+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52478+4 4 4 4 4 4
52479+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
52480+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
52481+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
52482+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
52483+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
52484+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
52485+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
52486+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
52487+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
52488+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
52489+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52492+4 4 4 4 4 4
52493+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
52494+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52495+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
52496+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
52497+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
52498+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
52499+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
52500+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
52501+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
52502+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
52503+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52506+4 4 4 4 4 4
52507+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
52508+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52509+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
52510+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
52511+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
52512+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
52513+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52514+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
52515+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
52516+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
52517+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52520+4 4 4 4 4 4
52521+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
52522+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
52523+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
52524+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
52525+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
52526+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
52527+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
52528+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
52529+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
52530+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
52531+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52534+4 4 4 4 4 4
52535+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
52536+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
52537+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52538+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
52539+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
52540+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
52541+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
52542+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
52543+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
52544+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
52545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52548+4 4 4 4 4 4
52549+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52550+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
52551+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
52552+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
52553+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
52554+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
52555+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
52556+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
52557+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
52558+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52562+4 4 4 4 4 4
52563+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
52564+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
52565+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
52566+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
52567+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
52568+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
52569+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
52570+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
52571+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
52572+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52576+4 4 4 4 4 4
52577+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
52578+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
52579+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
52580+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
52581+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
52582+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
52583+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
52584+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
52585+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
52586+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52590+4 4 4 4 4 4
52591+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
52592+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52593+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
52594+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52595+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
52596+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
52597+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
52598+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
52599+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
52600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52604+4 4 4 4 4 4
52605+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
52606+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
52607+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
52608+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
52609+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
52610+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
52611+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
52612+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
52613+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
52614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52618+4 4 4 4 4 4
52619+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52620+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
52621+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
52622+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
52623+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
52624+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
52625+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
52626+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
52627+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52632+4 4 4 4 4 4
52633+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
52634+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
52635+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52636+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
52637+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
52638+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
52639+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
52640+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
52641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52646+4 4 4 4 4 4
52647+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52648+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
52649+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
52650+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
52651+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
52652+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
52653+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
52654+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52660+4 4 4 4 4 4
52661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52662+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
52663+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52664+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
52665+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
52666+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
52667+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
52668+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
52669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52674+4 4 4 4 4 4
52675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52676+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
52677+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
52678+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
52679+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
52680+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
52681+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
52682+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
52683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52688+4 4 4 4 4 4
52689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52690+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
52691+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
52692+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52693+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
52694+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
52695+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
52696+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52702+4 4 4 4 4 4
52703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52705+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52706+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
52707+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
52708+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
52709+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
52710+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52716+4 4 4 4 4 4
52717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52720+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52721+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
52722+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
52723+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
52724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52730+4 4 4 4 4 4
52731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52734+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52735+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52736+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
52737+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
52738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52744+4 4 4 4 4 4
52745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52748+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52749+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52750+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52751+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
52752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52758+4 4 4 4 4 4
52759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52762+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
52763+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
52764+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
52765+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
52766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52772+4 4 4 4 4 4
52773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52777+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
52778+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52779+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52786+4 4 4 4 4 4
52787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52791+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
52792+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
52793+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52800+4 4 4 4 4 4
52801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52805+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52806+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52807+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52814+4 4 4 4 4 4
52815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52819+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
52820+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52828+4 4 4 4 4 4
52829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52833+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52834+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52842+4 4 4 4 4 4
52843diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52844index fe92eed..106e085 100644
52845--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52846+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52847@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52848 struct mb862xxfb_par *par = info->par;
52849
52850 if (info->var.bits_per_pixel == 32) {
52851- info->fbops->fb_fillrect = cfb_fillrect;
52852- info->fbops->fb_copyarea = cfb_copyarea;
52853- info->fbops->fb_imageblit = cfb_imageblit;
52854+ pax_open_kernel();
52855+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52856+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52857+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52858+ pax_close_kernel();
52859 } else {
52860 outreg(disp, GC_L0EM, 3);
52861- info->fbops->fb_fillrect = mb86290fb_fillrect;
52862- info->fbops->fb_copyarea = mb86290fb_copyarea;
52863- info->fbops->fb_imageblit = mb86290fb_imageblit;
52864+ pax_open_kernel();
52865+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52866+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52867+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52868+ pax_close_kernel();
52869 }
52870 outreg(draw, GDC_REG_DRAW_BASE, 0);
52871 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52872diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52873index ff22871..b129bed 100644
52874--- a/drivers/video/nvidia/nvidia.c
52875+++ b/drivers/video/nvidia/nvidia.c
52876@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52877 info->fix.line_length = (info->var.xres_virtual *
52878 info->var.bits_per_pixel) >> 3;
52879 if (info->var.accel_flags) {
52880- info->fbops->fb_imageblit = nvidiafb_imageblit;
52881- info->fbops->fb_fillrect = nvidiafb_fillrect;
52882- info->fbops->fb_copyarea = nvidiafb_copyarea;
52883- info->fbops->fb_sync = nvidiafb_sync;
52884+ pax_open_kernel();
52885+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52886+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52887+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52888+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52889+ pax_close_kernel();
52890 info->pixmap.scan_align = 4;
52891 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52892 info->flags |= FBINFO_READS_FAST;
52893 NVResetGraphics(info);
52894 } else {
52895- info->fbops->fb_imageblit = cfb_imageblit;
52896- info->fbops->fb_fillrect = cfb_fillrect;
52897- info->fbops->fb_copyarea = cfb_copyarea;
52898- info->fbops->fb_sync = NULL;
52899+ pax_open_kernel();
52900+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52901+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52902+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52903+ *(void **)&info->fbops->fb_sync = NULL;
52904+ pax_close_kernel();
52905 info->pixmap.scan_align = 1;
52906 info->flags |= FBINFO_HWACCEL_DISABLED;
52907 info->flags &= ~FBINFO_READS_FAST;
52908@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52909 info->pixmap.size = 8 * 1024;
52910 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52911
52912- if (!hwcur)
52913- info->fbops->fb_cursor = NULL;
52914+ if (!hwcur) {
52915+ pax_open_kernel();
52916+ *(void **)&info->fbops->fb_cursor = NULL;
52917+ pax_close_kernel();
52918+ }
52919
52920 info->var.accel_flags = (!noaccel);
52921
52922diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
52923index fafe7c9..93197b9 100644
52924--- a/drivers/video/omap2/dss/display.c
52925+++ b/drivers/video/omap2/dss/display.c
52926@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52927 snprintf(dssdev->alias, sizeof(dssdev->alias),
52928 "display%d", disp_num_counter++);
52929
52930+ pax_open_kernel();
52931 if (drv && drv->get_resolution == NULL)
52932- drv->get_resolution = omapdss_default_get_resolution;
52933+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52934 if (drv && drv->get_recommended_bpp == NULL)
52935- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52936+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52937 if (drv && drv->get_timings == NULL)
52938- drv->get_timings = omapdss_default_get_timings;
52939+ *(void **)&drv->get_timings = omapdss_default_get_timings;
52940+ pax_close_kernel();
52941
52942 mutex_lock(&panel_list_mutex);
52943 list_add_tail(&dssdev->panel_list, &panel_list);
52944diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52945index 05c2dc3..ea1f391 100644
52946--- a/drivers/video/s1d13xxxfb.c
52947+++ b/drivers/video/s1d13xxxfb.c
52948@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52949
52950 switch(prod_id) {
52951 case S1D13506_PROD_ID: /* activate acceleration */
52952- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52953- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52954+ pax_open_kernel();
52955+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52956+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52957+ pax_close_kernel();
52958 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52959 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52960 break;
52961diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52962index e188ada..aac63c8 100644
52963--- a/drivers/video/smscufx.c
52964+++ b/drivers/video/smscufx.c
52965@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52966 fb_deferred_io_cleanup(info);
52967 kfree(info->fbdefio);
52968 info->fbdefio = NULL;
52969- info->fbops->fb_mmap = ufx_ops_mmap;
52970+ pax_open_kernel();
52971+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52972+ pax_close_kernel();
52973 }
52974
52975 pr_debug("released /dev/fb%d user=%d count=%d",
52976diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52977index d2e5bc3..4cb05d1 100644
52978--- a/drivers/video/udlfb.c
52979+++ b/drivers/video/udlfb.c
52980@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52981 dlfb_urb_completion(urb);
52982
52983 error:
52984- atomic_add(bytes_sent, &dev->bytes_sent);
52985- atomic_add(bytes_identical, &dev->bytes_identical);
52986- atomic_add(width*height*2, &dev->bytes_rendered);
52987+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52988+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52989+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52990 end_cycles = get_cycles();
52991- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52992+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52993 >> 10)), /* Kcycles */
52994 &dev->cpu_kcycles_used);
52995
52996@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52997 dlfb_urb_completion(urb);
52998
52999 error:
53000- atomic_add(bytes_sent, &dev->bytes_sent);
53001- atomic_add(bytes_identical, &dev->bytes_identical);
53002- atomic_add(bytes_rendered, &dev->bytes_rendered);
53003+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53004+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53005+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53006 end_cycles = get_cycles();
53007- atomic_add(((unsigned int) ((end_cycles - start_cycles)
53008+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53009 >> 10)), /* Kcycles */
53010 &dev->cpu_kcycles_used);
53011 }
53012@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53013 fb_deferred_io_cleanup(info);
53014 kfree(info->fbdefio);
53015 info->fbdefio = NULL;
53016- info->fbops->fb_mmap = dlfb_ops_mmap;
53017+ pax_open_kernel();
53018+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53019+ pax_close_kernel();
53020 }
53021
53022 pr_warn("released /dev/fb%d user=%d count=%d\n",
53023@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53024 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53025 struct dlfb_data *dev = fb_info->par;
53026 return snprintf(buf, PAGE_SIZE, "%u\n",
53027- atomic_read(&dev->bytes_rendered));
53028+ atomic_read_unchecked(&dev->bytes_rendered));
53029 }
53030
53031 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53032@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53033 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53034 struct dlfb_data *dev = fb_info->par;
53035 return snprintf(buf, PAGE_SIZE, "%u\n",
53036- atomic_read(&dev->bytes_identical));
53037+ atomic_read_unchecked(&dev->bytes_identical));
53038 }
53039
53040 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53041@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53042 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53043 struct dlfb_data *dev = fb_info->par;
53044 return snprintf(buf, PAGE_SIZE, "%u\n",
53045- atomic_read(&dev->bytes_sent));
53046+ atomic_read_unchecked(&dev->bytes_sent));
53047 }
53048
53049 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53050@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53051 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53052 struct dlfb_data *dev = fb_info->par;
53053 return snprintf(buf, PAGE_SIZE, "%u\n",
53054- atomic_read(&dev->cpu_kcycles_used));
53055+ atomic_read_unchecked(&dev->cpu_kcycles_used));
53056 }
53057
53058 static ssize_t edid_show(
53059@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53060 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53061 struct dlfb_data *dev = fb_info->par;
53062
53063- atomic_set(&dev->bytes_rendered, 0);
53064- atomic_set(&dev->bytes_identical, 0);
53065- atomic_set(&dev->bytes_sent, 0);
53066- atomic_set(&dev->cpu_kcycles_used, 0);
53067+ atomic_set_unchecked(&dev->bytes_rendered, 0);
53068+ atomic_set_unchecked(&dev->bytes_identical, 0);
53069+ atomic_set_unchecked(&dev->bytes_sent, 0);
53070+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53071
53072 return count;
53073 }
53074diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
53075index 7aec6f3..e3b2d55 100644
53076--- a/drivers/video/uvesafb.c
53077+++ b/drivers/video/uvesafb.c
53078@@ -19,6 +19,7 @@
53079 #include <linux/io.h>
53080 #include <linux/mutex.h>
53081 #include <linux/slab.h>
53082+#include <linux/moduleloader.h>
53083 #include <video/edid.h>
53084 #include <video/uvesafb.h>
53085 #ifdef CONFIG_X86
53086@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53087 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53088 par->pmi_setpal = par->ypan = 0;
53089 } else {
53090+
53091+#ifdef CONFIG_PAX_KERNEXEC
53092+#ifdef CONFIG_MODULES
53093+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53094+#endif
53095+ if (!par->pmi_code) {
53096+ par->pmi_setpal = par->ypan = 0;
53097+ return 0;
53098+ }
53099+#endif
53100+
53101 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53102 + task->t.regs.edi);
53103+
53104+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53105+ pax_open_kernel();
53106+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53107+ pax_close_kernel();
53108+
53109+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53110+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53111+#else
53112 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53113 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53114+#endif
53115+
53116 printk(KERN_INFO "uvesafb: protected mode interface info at "
53117 "%04x:%04x\n",
53118 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53119@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53120 par->ypan = ypan;
53121
53122 if (par->pmi_setpal || par->ypan) {
53123+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53124 if (__supported_pte_mask & _PAGE_NX) {
53125 par->pmi_setpal = par->ypan = 0;
53126 printk(KERN_WARNING "uvesafb: NX protection is active, "
53127 "better not use the PMI.\n");
53128- } else {
53129+ } else
53130+#endif
53131 uvesafb_vbe_getpmi(task, par);
53132- }
53133 }
53134 #else
53135 /* The protected mode interface is not available on non-x86. */
53136@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53137 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53138
53139 /* Disable blanking if the user requested so. */
53140- if (!blank)
53141- info->fbops->fb_blank = NULL;
53142+ if (!blank) {
53143+ pax_open_kernel();
53144+ *(void **)&info->fbops->fb_blank = NULL;
53145+ pax_close_kernel();
53146+ }
53147
53148 /*
53149 * Find out how much IO memory is required for the mode with
53150@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53151 info->flags = FBINFO_FLAG_DEFAULT |
53152 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53153
53154- if (!par->ypan)
53155- info->fbops->fb_pan_display = NULL;
53156+ if (!par->ypan) {
53157+ pax_open_kernel();
53158+ *(void **)&info->fbops->fb_pan_display = NULL;
53159+ pax_close_kernel();
53160+ }
53161 }
53162
53163 static void uvesafb_init_mtrr(struct fb_info *info)
53164@@ -1796,6 +1826,11 @@ out:
53165 if (par->vbe_modes)
53166 kfree(par->vbe_modes);
53167
53168+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53169+ if (par->pmi_code)
53170+ module_free_exec(NULL, par->pmi_code);
53171+#endif
53172+
53173 framebuffer_release(info);
53174 return err;
53175 }
53176@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
53177 kfree(par->vbe_state_orig);
53178 if (par->vbe_state_saved)
53179 kfree(par->vbe_state_saved);
53180+
53181+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53182+ if (par->pmi_code)
53183+ module_free_exec(NULL, par->pmi_code);
53184+#endif
53185+
53186 }
53187
53188 framebuffer_release(info);
53189diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
53190index bd83233..7d8a5aa 100644
53191--- a/drivers/video/vesafb.c
53192+++ b/drivers/video/vesafb.c
53193@@ -9,6 +9,7 @@
53194 */
53195
53196 #include <linux/module.h>
53197+#include <linux/moduleloader.h>
53198 #include <linux/kernel.h>
53199 #include <linux/errno.h>
53200 #include <linux/string.h>
53201@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53202 static int vram_total; /* Set total amount of memory */
53203 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53204 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53205-static void (*pmi_start)(void) __read_mostly;
53206-static void (*pmi_pal) (void) __read_mostly;
53207+static void (*pmi_start)(void) __read_only;
53208+static void (*pmi_pal) (void) __read_only;
53209 static int depth __read_mostly;
53210 static int vga_compat __read_mostly;
53211 /* --------------------------------------------------------------------- */
53212@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
53213 unsigned int size_remap;
53214 unsigned int size_total;
53215 char *option = NULL;
53216+ void *pmi_code = NULL;
53217
53218 /* ignore error return of fb_get_options */
53219 fb_get_options("vesafb", &option);
53220@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
53221 size_remap = size_total;
53222 vesafb_fix.smem_len = size_remap;
53223
53224-#ifndef __i386__
53225- screen_info.vesapm_seg = 0;
53226-#endif
53227-
53228 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53229 printk(KERN_WARNING
53230 "vesafb: cannot reserve video memory at 0x%lx\n",
53231@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53232 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53233 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53234
53235+#ifdef __i386__
53236+
53237+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53238+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53239+ if (!pmi_code)
53240+#elif !defined(CONFIG_PAX_KERNEXEC)
53241+ if (0)
53242+#endif
53243+
53244+#endif
53245+ screen_info.vesapm_seg = 0;
53246+
53247 if (screen_info.vesapm_seg) {
53248- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53249- screen_info.vesapm_seg,screen_info.vesapm_off);
53250+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53251+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53252 }
53253
53254 if (screen_info.vesapm_seg < 0xc000)
53255@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53256
53257 if (ypan || pmi_setpal) {
53258 unsigned short *pmi_base;
53259+
53260 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53261- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53262- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53263+
53264+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53265+ pax_open_kernel();
53266+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53267+#else
53268+ pmi_code = pmi_base;
53269+#endif
53270+
53271+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53272+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53273+
53274+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53275+ pmi_start = ktva_ktla(pmi_start);
53276+ pmi_pal = ktva_ktla(pmi_pal);
53277+ pax_close_kernel();
53278+#endif
53279+
53280 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53281 if (pmi_base[3]) {
53282 printk(KERN_INFO "vesafb: pmi: ports = ");
53283@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53284 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53285 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53286
53287- if (!ypan)
53288- info->fbops->fb_pan_display = NULL;
53289+ if (!ypan) {
53290+ pax_open_kernel();
53291+ *(void **)&info->fbops->fb_pan_display = NULL;
53292+ pax_close_kernel();
53293+ }
53294
53295 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53296 err = -ENOMEM;
53297@@ -493,6 +522,11 @@ static int vesafb_probe(struct platform_device *dev)
53298 info->node, info->fix.id);
53299 return 0;
53300 err:
53301+
53302+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53303+ module_free_exec(NULL, pmi_code);
53304+#endif
53305+
53306 if (info->screen_base)
53307 iounmap(info->screen_base);
53308 framebuffer_release(info);
53309diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
53310index 88714ae..16c2e11 100644
53311--- a/drivers/video/via/via_clock.h
53312+++ b/drivers/video/via/via_clock.h
53313@@ -56,7 +56,7 @@ struct via_clock {
53314
53315 void (*set_engine_pll_state)(u8 state);
53316 void (*set_engine_pll)(struct via_pll_config config);
53317-};
53318+} __no_const;
53319
53320
53321 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53322diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
53323index fef20db..d28b1ab 100644
53324--- a/drivers/xen/xenfs/xenstored.c
53325+++ b/drivers/xen/xenfs/xenstored.c
53326@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
53327 static int xsd_kva_open(struct inode *inode, struct file *file)
53328 {
53329 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
53330+#ifdef CONFIG_GRKERNSEC_HIDESYM
53331+ NULL);
53332+#else
53333 xen_store_interface);
53334+#endif
53335+
53336 if (!file->private_data)
53337 return -ENOMEM;
53338 return 0;
53339diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
53340index 9ff073f..05cef23 100644
53341--- a/fs/9p/vfs_addr.c
53342+++ b/fs/9p/vfs_addr.c
53343@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
53344
53345 retval = v9fs_file_write_internal(inode,
53346 v9inode->writeback_fid,
53347- (__force const char __user *)buffer,
53348+ (const char __force_user *)buffer,
53349 len, &offset, 0);
53350 if (retval > 0)
53351 retval = 0;
53352diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
53353index 94de6d1..8d81256 100644
53354--- a/fs/9p/vfs_inode.c
53355+++ b/fs/9p/vfs_inode.c
53356@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53357 void
53358 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53359 {
53360- char *s = nd_get_link(nd);
53361+ const char *s = nd_get_link(nd);
53362
53363 p9_debug(P9_DEBUG_VFS, " %s %s\n",
53364 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
53365diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
53366index 370b24c..ff0be7b 100644
53367--- a/fs/Kconfig.binfmt
53368+++ b/fs/Kconfig.binfmt
53369@@ -103,7 +103,7 @@ config HAVE_AOUT
53370
53371 config BINFMT_AOUT
53372 tristate "Kernel support for a.out and ECOFF binaries"
53373- depends on HAVE_AOUT
53374+ depends on HAVE_AOUT && BROKEN
53375 ---help---
53376 A.out (Assembler.OUTput) is a set of formats for libraries and
53377 executables used in the earliest versions of UNIX. Linux used
53378diff --git a/fs/afs/inode.c b/fs/afs/inode.c
53379index 789bc25..fafaeea 100644
53380--- a/fs/afs/inode.c
53381+++ b/fs/afs/inode.c
53382@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53383 struct afs_vnode *vnode;
53384 struct super_block *sb;
53385 struct inode *inode;
53386- static atomic_t afs_autocell_ino;
53387+ static atomic_unchecked_t afs_autocell_ino;
53388
53389 _enter("{%x:%u},%*.*s,",
53390 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
53391@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53392 data.fid.unique = 0;
53393 data.fid.vnode = 0;
53394
53395- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
53396+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
53397 afs_iget5_autocell_test, afs_iget5_set,
53398 &data);
53399 if (!inode) {
53400diff --git a/fs/aio.c b/fs/aio.c
53401index 6efb7f6..37da952 100644
53402--- a/fs/aio.c
53403+++ b/fs/aio.c
53404@@ -338,7 +338,7 @@ static int aio_setup_ring(struct kioctx *ctx)
53405 size += sizeof(struct io_event) * nr_events;
53406
53407 nr_pages = PFN_UP(size);
53408- if (nr_pages < 0)
53409+ if (nr_pages <= 0)
53410 return -EINVAL;
53411
53412 file = aio_private_file(ctx, nr_pages);
53413diff --git a/fs/attr.c b/fs/attr.c
53414index 1449adb..a2038c2 100644
53415--- a/fs/attr.c
53416+++ b/fs/attr.c
53417@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
53418 unsigned long limit;
53419
53420 limit = rlimit(RLIMIT_FSIZE);
53421+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
53422 if (limit != RLIM_INFINITY && offset > limit)
53423 goto out_sig;
53424 if (offset > inode->i_sb->s_maxbytes)
53425diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
53426index 689e40d..515cac5 100644
53427--- a/fs/autofs4/waitq.c
53428+++ b/fs/autofs4/waitq.c
53429@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
53430 {
53431 unsigned long sigpipe, flags;
53432 mm_segment_t fs;
53433- const char *data = (const char *)addr;
53434+ const char __user *data = (const char __force_user *)addr;
53435 ssize_t wr = 0;
53436
53437 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
53438@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
53439 return 1;
53440 }
53441
53442+#ifdef CONFIG_GRKERNSEC_HIDESYM
53443+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
53444+#endif
53445+
53446 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53447 enum autofs_notify notify)
53448 {
53449@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53450
53451 /* If this is a direct mount request create a dummy name */
53452 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
53453+#ifdef CONFIG_GRKERNSEC_HIDESYM
53454+ /* this name does get written to userland via autofs4_write() */
53455+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
53456+#else
53457 qstr.len = sprintf(name, "%p", dentry);
53458+#endif
53459 else {
53460 qstr.len = autofs4_getpath(sbi, dentry, &name);
53461 if (!qstr.len) {
53462diff --git a/fs/befs/endian.h b/fs/befs/endian.h
53463index 2722387..56059b5 100644
53464--- a/fs/befs/endian.h
53465+++ b/fs/befs/endian.h
53466@@ -11,7 +11,7 @@
53467
53468 #include <asm/byteorder.h>
53469
53470-static inline u64
53471+static inline u64 __intentional_overflow(-1)
53472 fs64_to_cpu(const struct super_block *sb, fs64 n)
53473 {
53474 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53475@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
53476 return (__force fs64)cpu_to_be64(n);
53477 }
53478
53479-static inline u32
53480+static inline u32 __intentional_overflow(-1)
53481 fs32_to_cpu(const struct super_block *sb, fs32 n)
53482 {
53483 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53484@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
53485 return (__force fs32)cpu_to_be32(n);
53486 }
53487
53488-static inline u16
53489+static inline u16 __intentional_overflow(-1)
53490 fs16_to_cpu(const struct super_block *sb, fs16 n)
53491 {
53492 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53493diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
53494index e9c75e2..1baece1 100644
53495--- a/fs/befs/linuxvfs.c
53496+++ b/fs/befs/linuxvfs.c
53497@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53498 {
53499 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
53500 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
53501- char *link = nd_get_link(nd);
53502+ const char *link = nd_get_link(nd);
53503 if (!IS_ERR(link))
53504 kfree(link);
53505 }
53506diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
53507index 89dec7f..361b0d75 100644
53508--- a/fs/binfmt_aout.c
53509+++ b/fs/binfmt_aout.c
53510@@ -16,6 +16,7 @@
53511 #include <linux/string.h>
53512 #include <linux/fs.h>
53513 #include <linux/file.h>
53514+#include <linux/security.h>
53515 #include <linux/stat.h>
53516 #include <linux/fcntl.h>
53517 #include <linux/ptrace.h>
53518@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
53519 #endif
53520 # define START_STACK(u) ((void __user *)u.start_stack)
53521
53522+ memset(&dump, 0, sizeof(dump));
53523+
53524 fs = get_fs();
53525 set_fs(KERNEL_DS);
53526 has_dumped = 1;
53527@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
53528
53529 /* If the size of the dump file exceeds the rlimit, then see what would happen
53530 if we wrote the stack, but not the data area. */
53531+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
53532 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
53533 dump.u_dsize = 0;
53534
53535 /* Make sure we have enough room to write the stack and data areas. */
53536+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
53537 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
53538 dump.u_ssize = 0;
53539
53540@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
53541 rlim = rlimit(RLIMIT_DATA);
53542 if (rlim >= RLIM_INFINITY)
53543 rlim = ~0;
53544+
53545+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
53546 if (ex.a_data + ex.a_bss > rlim)
53547 return -ENOMEM;
53548
53549@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
53550
53551 install_exec_creds(bprm);
53552
53553+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53554+ current->mm->pax_flags = 0UL;
53555+#endif
53556+
53557+#ifdef CONFIG_PAX_PAGEEXEC
53558+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
53559+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
53560+
53561+#ifdef CONFIG_PAX_EMUTRAMP
53562+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
53563+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
53564+#endif
53565+
53566+#ifdef CONFIG_PAX_MPROTECT
53567+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
53568+ current->mm->pax_flags |= MF_PAX_MPROTECT;
53569+#endif
53570+
53571+ }
53572+#endif
53573+
53574 if (N_MAGIC(ex) == OMAGIC) {
53575 unsigned long text_addr, map_size;
53576 loff_t pos;
53577@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
53578 }
53579
53580 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
53581- PROT_READ | PROT_WRITE | PROT_EXEC,
53582+ PROT_READ | PROT_WRITE,
53583 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
53584 fd_offset + ex.a_text);
53585 if (error != N_DATADDR(ex)) {
53586diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
53587index 4c94a79..2610454 100644
53588--- a/fs/binfmt_elf.c
53589+++ b/fs/binfmt_elf.c
53590@@ -34,6 +34,7 @@
53591 #include <linux/utsname.h>
53592 #include <linux/coredump.h>
53593 #include <linux/sched.h>
53594+#include <linux/xattr.h>
53595 #include <asm/uaccess.h>
53596 #include <asm/param.h>
53597 #include <asm/page.h>
53598@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
53599 #define elf_core_dump NULL
53600 #endif
53601
53602+#ifdef CONFIG_PAX_MPROTECT
53603+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
53604+#endif
53605+
53606+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53607+static void elf_handle_mmap(struct file *file);
53608+#endif
53609+
53610 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
53611 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
53612 #else
53613@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
53614 .load_binary = load_elf_binary,
53615 .load_shlib = load_elf_library,
53616 .core_dump = elf_core_dump,
53617+
53618+#ifdef CONFIG_PAX_MPROTECT
53619+ .handle_mprotect= elf_handle_mprotect,
53620+#endif
53621+
53622+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53623+ .handle_mmap = elf_handle_mmap,
53624+#endif
53625+
53626 .min_coredump = ELF_EXEC_PAGESIZE,
53627 };
53628
53629@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
53630
53631 static int set_brk(unsigned long start, unsigned long end)
53632 {
53633+ unsigned long e = end;
53634+
53635 start = ELF_PAGEALIGN(start);
53636 end = ELF_PAGEALIGN(end);
53637 if (end > start) {
53638@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
53639 if (BAD_ADDR(addr))
53640 return addr;
53641 }
53642- current->mm->start_brk = current->mm->brk = end;
53643+ current->mm->start_brk = current->mm->brk = e;
53644 return 0;
53645 }
53646
53647@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53648 elf_addr_t __user *u_rand_bytes;
53649 const char *k_platform = ELF_PLATFORM;
53650 const char *k_base_platform = ELF_BASE_PLATFORM;
53651- unsigned char k_rand_bytes[16];
53652+ u32 k_rand_bytes[4];
53653 int items;
53654 elf_addr_t *elf_info;
53655 int ei_index = 0;
53656 const struct cred *cred = current_cred();
53657 struct vm_area_struct *vma;
53658+ unsigned long saved_auxv[AT_VECTOR_SIZE];
53659
53660 /*
53661 * In some cases (e.g. Hyper-Threading), we want to avoid L1
53662@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53663 * Generate 16 random bytes for userspace PRNG seeding.
53664 */
53665 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
53666- u_rand_bytes = (elf_addr_t __user *)
53667- STACK_ALLOC(p, sizeof(k_rand_bytes));
53668+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
53669+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
53670+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
53671+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
53672+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
53673+ u_rand_bytes = (elf_addr_t __user *) p;
53674 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
53675 return -EFAULT;
53676
53677@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53678 return -EFAULT;
53679 current->mm->env_end = p;
53680
53681+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
53682+
53683 /* Put the elf_info on the stack in the right place. */
53684 sp = (elf_addr_t __user *)envp + 1;
53685- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
53686+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
53687 return -EFAULT;
53688 return 0;
53689 }
53690@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
53691 an ELF header */
53692
53693 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53694- struct file *interpreter, unsigned long *interp_map_addr,
53695- unsigned long no_base)
53696+ struct file *interpreter, unsigned long no_base)
53697 {
53698 struct elf_phdr *elf_phdata;
53699 struct elf_phdr *eppnt;
53700- unsigned long load_addr = 0;
53701+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
53702 int load_addr_set = 0;
53703 unsigned long last_bss = 0, elf_bss = 0;
53704- unsigned long error = ~0UL;
53705+ unsigned long error = -EINVAL;
53706 unsigned long total_size;
53707 int retval, i, size;
53708
53709@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53710 goto out_close;
53711 }
53712
53713+#ifdef CONFIG_PAX_SEGMEXEC
53714+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
53715+ pax_task_size = SEGMEXEC_TASK_SIZE;
53716+#endif
53717+
53718 eppnt = elf_phdata;
53719 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
53720 if (eppnt->p_type == PT_LOAD) {
53721@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53722 map_addr = elf_map(interpreter, load_addr + vaddr,
53723 eppnt, elf_prot, elf_type, total_size);
53724 total_size = 0;
53725- if (!*interp_map_addr)
53726- *interp_map_addr = map_addr;
53727 error = map_addr;
53728 if (BAD_ADDR(map_addr))
53729 goto out_close;
53730@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53731 k = load_addr + eppnt->p_vaddr;
53732 if (BAD_ADDR(k) ||
53733 eppnt->p_filesz > eppnt->p_memsz ||
53734- eppnt->p_memsz > TASK_SIZE ||
53735- TASK_SIZE - eppnt->p_memsz < k) {
53736+ eppnt->p_memsz > pax_task_size ||
53737+ pax_task_size - eppnt->p_memsz < k) {
53738 error = -ENOMEM;
53739 goto out_close;
53740 }
53741@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53742 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
53743
53744 /* Map the last of the bss segment */
53745- error = vm_brk(elf_bss, last_bss - elf_bss);
53746- if (BAD_ADDR(error))
53747- goto out_close;
53748+ if (last_bss > elf_bss) {
53749+ error = vm_brk(elf_bss, last_bss - elf_bss);
53750+ if (BAD_ADDR(error))
53751+ goto out_close;
53752+ }
53753 }
53754
53755 error = load_addr;
53756@@ -538,6 +569,315 @@ out:
53757 return error;
53758 }
53759
53760+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53761+#ifdef CONFIG_PAX_SOFTMODE
53762+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
53763+{
53764+ unsigned long pax_flags = 0UL;
53765+
53766+#ifdef CONFIG_PAX_PAGEEXEC
53767+ if (elf_phdata->p_flags & PF_PAGEEXEC)
53768+ pax_flags |= MF_PAX_PAGEEXEC;
53769+#endif
53770+
53771+#ifdef CONFIG_PAX_SEGMEXEC
53772+ if (elf_phdata->p_flags & PF_SEGMEXEC)
53773+ pax_flags |= MF_PAX_SEGMEXEC;
53774+#endif
53775+
53776+#ifdef CONFIG_PAX_EMUTRAMP
53777+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53778+ pax_flags |= MF_PAX_EMUTRAMP;
53779+#endif
53780+
53781+#ifdef CONFIG_PAX_MPROTECT
53782+ if (elf_phdata->p_flags & PF_MPROTECT)
53783+ pax_flags |= MF_PAX_MPROTECT;
53784+#endif
53785+
53786+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53787+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
53788+ pax_flags |= MF_PAX_RANDMMAP;
53789+#endif
53790+
53791+ return pax_flags;
53792+}
53793+#endif
53794+
53795+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
53796+{
53797+ unsigned long pax_flags = 0UL;
53798+
53799+#ifdef CONFIG_PAX_PAGEEXEC
53800+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
53801+ pax_flags |= MF_PAX_PAGEEXEC;
53802+#endif
53803+
53804+#ifdef CONFIG_PAX_SEGMEXEC
53805+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
53806+ pax_flags |= MF_PAX_SEGMEXEC;
53807+#endif
53808+
53809+#ifdef CONFIG_PAX_EMUTRAMP
53810+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
53811+ pax_flags |= MF_PAX_EMUTRAMP;
53812+#endif
53813+
53814+#ifdef CONFIG_PAX_MPROTECT
53815+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53816+ pax_flags |= MF_PAX_MPROTECT;
53817+#endif
53818+
53819+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53820+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53821+ pax_flags |= MF_PAX_RANDMMAP;
53822+#endif
53823+
53824+ return pax_flags;
53825+}
53826+#endif
53827+
53828+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53829+#ifdef CONFIG_PAX_SOFTMODE
53830+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53831+{
53832+ unsigned long pax_flags = 0UL;
53833+
53834+#ifdef CONFIG_PAX_PAGEEXEC
53835+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53836+ pax_flags |= MF_PAX_PAGEEXEC;
53837+#endif
53838+
53839+#ifdef CONFIG_PAX_SEGMEXEC
53840+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53841+ pax_flags |= MF_PAX_SEGMEXEC;
53842+#endif
53843+
53844+#ifdef CONFIG_PAX_EMUTRAMP
53845+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53846+ pax_flags |= MF_PAX_EMUTRAMP;
53847+#endif
53848+
53849+#ifdef CONFIG_PAX_MPROTECT
53850+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53851+ pax_flags |= MF_PAX_MPROTECT;
53852+#endif
53853+
53854+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53855+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53856+ pax_flags |= MF_PAX_RANDMMAP;
53857+#endif
53858+
53859+ return pax_flags;
53860+}
53861+#endif
53862+
53863+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53864+{
53865+ unsigned long pax_flags = 0UL;
53866+
53867+#ifdef CONFIG_PAX_PAGEEXEC
53868+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53869+ pax_flags |= MF_PAX_PAGEEXEC;
53870+#endif
53871+
53872+#ifdef CONFIG_PAX_SEGMEXEC
53873+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53874+ pax_flags |= MF_PAX_SEGMEXEC;
53875+#endif
53876+
53877+#ifdef CONFIG_PAX_EMUTRAMP
53878+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53879+ pax_flags |= MF_PAX_EMUTRAMP;
53880+#endif
53881+
53882+#ifdef CONFIG_PAX_MPROTECT
53883+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53884+ pax_flags |= MF_PAX_MPROTECT;
53885+#endif
53886+
53887+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53888+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53889+ pax_flags |= MF_PAX_RANDMMAP;
53890+#endif
53891+
53892+ return pax_flags;
53893+}
53894+#endif
53895+
53896+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53897+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53898+{
53899+ unsigned long pax_flags = 0UL;
53900+
53901+#ifdef CONFIG_PAX_EI_PAX
53902+
53903+#ifdef CONFIG_PAX_PAGEEXEC
53904+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53905+ pax_flags |= MF_PAX_PAGEEXEC;
53906+#endif
53907+
53908+#ifdef CONFIG_PAX_SEGMEXEC
53909+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53910+ pax_flags |= MF_PAX_SEGMEXEC;
53911+#endif
53912+
53913+#ifdef CONFIG_PAX_EMUTRAMP
53914+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53915+ pax_flags |= MF_PAX_EMUTRAMP;
53916+#endif
53917+
53918+#ifdef CONFIG_PAX_MPROTECT
53919+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53920+ pax_flags |= MF_PAX_MPROTECT;
53921+#endif
53922+
53923+#ifdef CONFIG_PAX_ASLR
53924+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53925+ pax_flags |= MF_PAX_RANDMMAP;
53926+#endif
53927+
53928+#else
53929+
53930+#ifdef CONFIG_PAX_PAGEEXEC
53931+ pax_flags |= MF_PAX_PAGEEXEC;
53932+#endif
53933+
53934+#ifdef CONFIG_PAX_SEGMEXEC
53935+ pax_flags |= MF_PAX_SEGMEXEC;
53936+#endif
53937+
53938+#ifdef CONFIG_PAX_MPROTECT
53939+ pax_flags |= MF_PAX_MPROTECT;
53940+#endif
53941+
53942+#ifdef CONFIG_PAX_RANDMMAP
53943+ if (randomize_va_space)
53944+ pax_flags |= MF_PAX_RANDMMAP;
53945+#endif
53946+
53947+#endif
53948+
53949+ return pax_flags;
53950+}
53951+
53952+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53953+{
53954+
53955+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53956+ unsigned long i;
53957+
53958+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53959+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53960+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53961+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53962+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53963+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53964+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53965+ return ~0UL;
53966+
53967+#ifdef CONFIG_PAX_SOFTMODE
53968+ if (pax_softmode)
53969+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53970+ else
53971+#endif
53972+
53973+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53974+ break;
53975+ }
53976+#endif
53977+
53978+ return ~0UL;
53979+}
53980+
53981+static unsigned long pax_parse_xattr_pax(struct file * const file)
53982+{
53983+
53984+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53985+ ssize_t xattr_size, i;
53986+ unsigned char xattr_value[sizeof("pemrs") - 1];
53987+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53988+
53989+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53990+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53991+ return ~0UL;
53992+
53993+ for (i = 0; i < xattr_size; i++)
53994+ switch (xattr_value[i]) {
53995+ default:
53996+ return ~0UL;
53997+
53998+#define parse_flag(option1, option2, flag) \
53999+ case option1: \
54000+ if (pax_flags_hardmode & MF_PAX_##flag) \
54001+ return ~0UL; \
54002+ pax_flags_hardmode |= MF_PAX_##flag; \
54003+ break; \
54004+ case option2: \
54005+ if (pax_flags_softmode & MF_PAX_##flag) \
54006+ return ~0UL; \
54007+ pax_flags_softmode |= MF_PAX_##flag; \
54008+ break;
54009+
54010+ parse_flag('p', 'P', PAGEEXEC);
54011+ parse_flag('e', 'E', EMUTRAMP);
54012+ parse_flag('m', 'M', MPROTECT);
54013+ parse_flag('r', 'R', RANDMMAP);
54014+ parse_flag('s', 'S', SEGMEXEC);
54015+
54016+#undef parse_flag
54017+ }
54018+
54019+ if (pax_flags_hardmode & pax_flags_softmode)
54020+ return ~0UL;
54021+
54022+#ifdef CONFIG_PAX_SOFTMODE
54023+ if (pax_softmode)
54024+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
54025+ else
54026+#endif
54027+
54028+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
54029+#else
54030+ return ~0UL;
54031+#endif
54032+
54033+}
54034+
54035+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
54036+{
54037+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
54038+
54039+ pax_flags = pax_parse_ei_pax(elf_ex);
54040+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
54041+ xattr_pax_flags = pax_parse_xattr_pax(file);
54042+
54043+ if (pt_pax_flags == ~0UL)
54044+ pt_pax_flags = xattr_pax_flags;
54045+ else if (xattr_pax_flags == ~0UL)
54046+ xattr_pax_flags = pt_pax_flags;
54047+ if (pt_pax_flags != xattr_pax_flags)
54048+ return -EINVAL;
54049+ if (pt_pax_flags != ~0UL)
54050+ pax_flags = pt_pax_flags;
54051+
54052+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
54053+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54054+ if ((__supported_pte_mask & _PAGE_NX))
54055+ pax_flags &= ~MF_PAX_SEGMEXEC;
54056+ else
54057+ pax_flags &= ~MF_PAX_PAGEEXEC;
54058+ }
54059+#endif
54060+
54061+ if (0 > pax_check_flags(&pax_flags))
54062+ return -EINVAL;
54063+
54064+ current->mm->pax_flags = pax_flags;
54065+ return 0;
54066+}
54067+#endif
54068+
54069 /*
54070 * These are the functions used to load ELF style executables and shared
54071 * libraries. There is no binary dependent code anywhere else.
54072@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
54073 {
54074 unsigned int random_variable = 0;
54075
54076+#ifdef CONFIG_PAX_RANDUSTACK
54077+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
54078+ return stack_top - current->mm->delta_stack;
54079+#endif
54080+
54081 if ((current->flags & PF_RANDOMIZE) &&
54082 !(current->personality & ADDR_NO_RANDOMIZE)) {
54083 random_variable = get_random_int() & STACK_RND_MASK;
54084@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
54085 unsigned long load_addr = 0, load_bias = 0;
54086 int load_addr_set = 0;
54087 char * elf_interpreter = NULL;
54088- unsigned long error;
54089+ unsigned long error = 0;
54090 struct elf_phdr *elf_ppnt, *elf_phdata;
54091 unsigned long elf_bss, elf_brk;
54092 int retval, i;
54093@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
54094 unsigned long start_code, end_code, start_data, end_data;
54095 unsigned long reloc_func_desc __maybe_unused = 0;
54096 int executable_stack = EXSTACK_DEFAULT;
54097- unsigned long def_flags = 0;
54098 struct pt_regs *regs = current_pt_regs();
54099 struct {
54100 struct elfhdr elf_ex;
54101 struct elfhdr interp_elf_ex;
54102 } *loc;
54103+ unsigned long pax_task_size;
54104
54105 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
54106 if (!loc) {
54107@@ -723,11 +1068,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
54108 goto out_free_dentry;
54109
54110 /* OK, This is the point of no return */
54111- current->mm->def_flags = def_flags;
54112+ current->mm->def_flags = 0;
54113
54114 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
54115 may depend on the personality. */
54116 SET_PERSONALITY(loc->elf_ex);
54117+
54118+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54119+ current->mm->pax_flags = 0UL;
54120+#endif
54121+
54122+#ifdef CONFIG_PAX_DLRESOLVE
54123+ current->mm->call_dl_resolve = 0UL;
54124+#endif
54125+
54126+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
54127+ current->mm->call_syscall = 0UL;
54128+#endif
54129+
54130+#ifdef CONFIG_PAX_ASLR
54131+ current->mm->delta_mmap = 0UL;
54132+ current->mm->delta_stack = 0UL;
54133+#endif
54134+
54135+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54136+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
54137+ send_sig(SIGKILL, current, 0);
54138+ goto out_free_dentry;
54139+ }
54140+#endif
54141+
54142+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54143+ pax_set_initial_flags(bprm);
54144+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
54145+ if (pax_set_initial_flags_func)
54146+ (pax_set_initial_flags_func)(bprm);
54147+#endif
54148+
54149+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54150+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
54151+ current->mm->context.user_cs_limit = PAGE_SIZE;
54152+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
54153+ }
54154+#endif
54155+
54156+#ifdef CONFIG_PAX_SEGMEXEC
54157+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
54158+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
54159+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
54160+ pax_task_size = SEGMEXEC_TASK_SIZE;
54161+ current->mm->def_flags |= VM_NOHUGEPAGE;
54162+ } else
54163+#endif
54164+
54165+ pax_task_size = TASK_SIZE;
54166+
54167+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
54168+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54169+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
54170+ put_cpu();
54171+ }
54172+#endif
54173+
54174+#ifdef CONFIG_PAX_ASLR
54175+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
54176+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
54177+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
54178+ }
54179+#endif
54180+
54181+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54182+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54183+ executable_stack = EXSTACK_DISABLE_X;
54184+ current->personality &= ~READ_IMPLIES_EXEC;
54185+ } else
54186+#endif
54187+
54188 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
54189 current->personality |= READ_IMPLIES_EXEC;
54190
54191@@ -817,6 +1233,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
54192 #else
54193 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
54194 #endif
54195+
54196+#ifdef CONFIG_PAX_RANDMMAP
54197+ /* PaX: randomize base address at the default exe base if requested */
54198+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
54199+#ifdef CONFIG_SPARC64
54200+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
54201+#else
54202+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
54203+#endif
54204+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
54205+ elf_flags |= MAP_FIXED;
54206+ }
54207+#endif
54208+
54209 }
54210
54211 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
54212@@ -849,9 +1279,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
54213 * allowed task size. Note that p_filesz must always be
54214 * <= p_memsz so it is only necessary to check p_memsz.
54215 */
54216- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
54217- elf_ppnt->p_memsz > TASK_SIZE ||
54218- TASK_SIZE - elf_ppnt->p_memsz < k) {
54219+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
54220+ elf_ppnt->p_memsz > pax_task_size ||
54221+ pax_task_size - elf_ppnt->p_memsz < k) {
54222 /* set_brk can never work. Avoid overflows. */
54223 send_sig(SIGKILL, current, 0);
54224 retval = -EINVAL;
54225@@ -890,17 +1320,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
54226 goto out_free_dentry;
54227 }
54228 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
54229- send_sig(SIGSEGV, current, 0);
54230- retval = -EFAULT; /* Nobody gets to see this, but.. */
54231- goto out_free_dentry;
54232+ /*
54233+ * This bss-zeroing can fail if the ELF
54234+ * file specifies odd protections. So
54235+ * we don't check the return value
54236+ */
54237 }
54238
54239+#ifdef CONFIG_PAX_RANDMMAP
54240+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
54241+ unsigned long start, size, flags;
54242+ vm_flags_t vm_flags;
54243+
54244+ start = ELF_PAGEALIGN(elf_brk);
54245+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
54246+ flags = MAP_FIXED | MAP_PRIVATE;
54247+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
54248+
54249+ down_write(&current->mm->mmap_sem);
54250+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
54251+ retval = -ENOMEM;
54252+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
54253+// if (current->personality & ADDR_NO_RANDOMIZE)
54254+// vm_flags |= VM_READ | VM_MAYREAD;
54255+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
54256+ retval = IS_ERR_VALUE(start) ? start : 0;
54257+ }
54258+ up_write(&current->mm->mmap_sem);
54259+ if (retval == 0)
54260+ retval = set_brk(start + size, start + size + PAGE_SIZE);
54261+ if (retval < 0) {
54262+ send_sig(SIGKILL, current, 0);
54263+ goto out_free_dentry;
54264+ }
54265+ }
54266+#endif
54267+
54268 if (elf_interpreter) {
54269- unsigned long interp_map_addr = 0;
54270-
54271 elf_entry = load_elf_interp(&loc->interp_elf_ex,
54272 interpreter,
54273- &interp_map_addr,
54274 load_bias);
54275 if (!IS_ERR((void *)elf_entry)) {
54276 /*
54277@@ -1122,7 +1580,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
54278 * Decide what to dump of a segment, part, all or none.
54279 */
54280 static unsigned long vma_dump_size(struct vm_area_struct *vma,
54281- unsigned long mm_flags)
54282+ unsigned long mm_flags, long signr)
54283 {
54284 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
54285
54286@@ -1160,7 +1618,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
54287 if (vma->vm_file == NULL)
54288 return 0;
54289
54290- if (FILTER(MAPPED_PRIVATE))
54291+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
54292 goto whole;
54293
54294 /*
54295@@ -1385,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
54296 {
54297 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
54298 int i = 0;
54299- do
54300+ do {
54301 i += 2;
54302- while (auxv[i - 2] != AT_NULL);
54303+ } while (auxv[i - 2] != AT_NULL);
54304 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
54305 }
54306
54307@@ -1396,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
54308 {
54309 mm_segment_t old_fs = get_fs();
54310 set_fs(KERNEL_DS);
54311- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
54312+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
54313 set_fs(old_fs);
54314 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
54315 }
54316@@ -2023,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
54317 }
54318
54319 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
54320- unsigned long mm_flags)
54321+ struct coredump_params *cprm)
54322 {
54323 struct vm_area_struct *vma;
54324 size_t size = 0;
54325
54326 for (vma = first_vma(current, gate_vma); vma != NULL;
54327 vma = next_vma(vma, gate_vma))
54328- size += vma_dump_size(vma, mm_flags);
54329+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54330 return size;
54331 }
54332
54333@@ -2123,7 +2581,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54334
54335 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
54336
54337- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
54338+ offset += elf_core_vma_data_size(gate_vma, cprm);
54339 offset += elf_core_extra_data_size();
54340 e_shoff = offset;
54341
54342@@ -2137,10 +2595,12 @@ static int elf_core_dump(struct coredump_params *cprm)
54343 offset = dataoff;
54344
54345 size += sizeof(*elf);
54346+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54347 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
54348 goto end_coredump;
54349
54350 size += sizeof(*phdr4note);
54351+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54352 if (size > cprm->limit
54353 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
54354 goto end_coredump;
54355@@ -2154,7 +2614,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54356 phdr.p_offset = offset;
54357 phdr.p_vaddr = vma->vm_start;
54358 phdr.p_paddr = 0;
54359- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
54360+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54361 phdr.p_memsz = vma->vm_end - vma->vm_start;
54362 offset += phdr.p_filesz;
54363 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
54364@@ -2165,6 +2625,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54365 phdr.p_align = ELF_EXEC_PAGESIZE;
54366
54367 size += sizeof(phdr);
54368+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54369 if (size > cprm->limit
54370 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
54371 goto end_coredump;
54372@@ -2189,7 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54373 unsigned long addr;
54374 unsigned long end;
54375
54376- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
54377+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54378
54379 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
54380 struct page *page;
54381@@ -2198,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54382 page = get_dump_page(addr);
54383 if (page) {
54384 void *kaddr = kmap(page);
54385+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
54386 stop = ((size += PAGE_SIZE) > cprm->limit) ||
54387 !dump_write(cprm->file, kaddr,
54388 PAGE_SIZE);
54389@@ -2215,6 +2677,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54390
54391 if (e_phnum == PN_XNUM) {
54392 size += sizeof(*shdr4extnum);
54393+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54394 if (size > cprm->limit
54395 || !dump_write(cprm->file, shdr4extnum,
54396 sizeof(*shdr4extnum)))
54397@@ -2235,6 +2698,167 @@ out:
54398
54399 #endif /* CONFIG_ELF_CORE */
54400
54401+#ifdef CONFIG_PAX_MPROTECT
54402+/* PaX: non-PIC ELF libraries need relocations on their executable segments
54403+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
54404+ * we'll remove VM_MAYWRITE for good on RELRO segments.
54405+ *
54406+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
54407+ * basis because we want to allow the common case and not the special ones.
54408+ */
54409+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
54410+{
54411+ struct elfhdr elf_h;
54412+ struct elf_phdr elf_p;
54413+ unsigned long i;
54414+ unsigned long oldflags;
54415+ bool is_textrel_rw, is_textrel_rx, is_relro;
54416+
54417+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
54418+ return;
54419+
54420+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
54421+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
54422+
54423+#ifdef CONFIG_PAX_ELFRELOCS
54424+ /* possible TEXTREL */
54425+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
54426+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
54427+#else
54428+ is_textrel_rw = false;
54429+ is_textrel_rx = false;
54430+#endif
54431+
54432+ /* possible RELRO */
54433+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
54434+
54435+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
54436+ return;
54437+
54438+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54439+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54440+
54441+#ifdef CONFIG_PAX_ETEXECRELOCS
54442+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54443+#else
54444+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
54445+#endif
54446+
54447+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54448+ !elf_check_arch(&elf_h) ||
54449+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54450+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54451+ return;
54452+
54453+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54454+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54455+ return;
54456+ switch (elf_p.p_type) {
54457+ case PT_DYNAMIC:
54458+ if (!is_textrel_rw && !is_textrel_rx)
54459+ continue;
54460+ i = 0UL;
54461+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
54462+ elf_dyn dyn;
54463+
54464+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
54465+ break;
54466+ if (dyn.d_tag == DT_NULL)
54467+ break;
54468+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
54469+ gr_log_textrel(vma);
54470+ if (is_textrel_rw)
54471+ vma->vm_flags |= VM_MAYWRITE;
54472+ else
54473+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
54474+ vma->vm_flags &= ~VM_MAYWRITE;
54475+ break;
54476+ }
54477+ i++;
54478+ }
54479+ is_textrel_rw = false;
54480+ is_textrel_rx = false;
54481+ continue;
54482+
54483+ case PT_GNU_RELRO:
54484+ if (!is_relro)
54485+ continue;
54486+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
54487+ vma->vm_flags &= ~VM_MAYWRITE;
54488+ is_relro = false;
54489+ continue;
54490+
54491+#ifdef CONFIG_PAX_PT_PAX_FLAGS
54492+ case PT_PAX_FLAGS: {
54493+ const char *msg_mprotect = "", *msg_emutramp = "";
54494+ char *buffer_lib, *buffer_exe;
54495+
54496+ if (elf_p.p_flags & PF_NOMPROTECT)
54497+ msg_mprotect = "MPROTECT disabled";
54498+
54499+#ifdef CONFIG_PAX_EMUTRAMP
54500+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
54501+ msg_emutramp = "EMUTRAMP enabled";
54502+#endif
54503+
54504+ if (!msg_mprotect[0] && !msg_emutramp[0])
54505+ continue;
54506+
54507+ if (!printk_ratelimit())
54508+ continue;
54509+
54510+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
54511+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
54512+ if (buffer_lib && buffer_exe) {
54513+ char *path_lib, *path_exe;
54514+
54515+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
54516+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
54517+
54518+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
54519+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
54520+
54521+ }
54522+ free_page((unsigned long)buffer_exe);
54523+ free_page((unsigned long)buffer_lib);
54524+ continue;
54525+ }
54526+#endif
54527+
54528+ }
54529+ }
54530+}
54531+#endif
54532+
54533+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54534+
54535+extern int grsec_enable_log_rwxmaps;
54536+
54537+static void elf_handle_mmap(struct file *file)
54538+{
54539+ struct elfhdr elf_h;
54540+ struct elf_phdr elf_p;
54541+ unsigned long i;
54542+
54543+ if (!grsec_enable_log_rwxmaps)
54544+ return;
54545+
54546+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54547+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54548+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
54549+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54550+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54551+ return;
54552+
54553+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54554+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54555+ return;
54556+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
54557+ gr_log_ptgnustack(file);
54558+ }
54559+}
54560+#endif
54561+
54562 static int __init init_elf_binfmt(void)
54563 {
54564 register_binfmt(&elf_format);
54565diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
54566index d50bbe5..af3b649 100644
54567--- a/fs/binfmt_flat.c
54568+++ b/fs/binfmt_flat.c
54569@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
54570 realdatastart = (unsigned long) -ENOMEM;
54571 printk("Unable to allocate RAM for process data, errno %d\n",
54572 (int)-realdatastart);
54573+ down_write(&current->mm->mmap_sem);
54574 vm_munmap(textpos, text_len);
54575+ up_write(&current->mm->mmap_sem);
54576 ret = realdatastart;
54577 goto err;
54578 }
54579@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54580 }
54581 if (IS_ERR_VALUE(result)) {
54582 printk("Unable to read data+bss, errno %d\n", (int)-result);
54583+ down_write(&current->mm->mmap_sem);
54584 vm_munmap(textpos, text_len);
54585 vm_munmap(realdatastart, len);
54586+ up_write(&current->mm->mmap_sem);
54587 ret = result;
54588 goto err;
54589 }
54590@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54591 }
54592 if (IS_ERR_VALUE(result)) {
54593 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
54594+ down_write(&current->mm->mmap_sem);
54595 vm_munmap(textpos, text_len + data_len + extra +
54596 MAX_SHARED_LIBS * sizeof(unsigned long));
54597+ up_write(&current->mm->mmap_sem);
54598 ret = result;
54599 goto err;
54600 }
54601diff --git a/fs/bio.c b/fs/bio.c
54602index ea5035d..a2932eb 100644
54603--- a/fs/bio.c
54604+++ b/fs/bio.c
54605@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
54606 /*
54607 * Overflow, abort
54608 */
54609- if (end < start)
54610+ if (end < start || end - start > INT_MAX - nr_pages)
54611 return ERR_PTR(-EINVAL);
54612
54613 nr_pages += end - start;
54614@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
54615 /*
54616 * Overflow, abort
54617 */
54618- if (end < start)
54619+ if (end < start || end - start > INT_MAX - nr_pages)
54620 return ERR_PTR(-EINVAL);
54621
54622 nr_pages += end - start;
54623@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
54624 const int read = bio_data_dir(bio) == READ;
54625 struct bio_map_data *bmd = bio->bi_private;
54626 int i;
54627- char *p = bmd->sgvecs[0].iov_base;
54628+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
54629
54630 bio_for_each_segment_all(bvec, bio, i) {
54631 char *addr = page_address(bvec->bv_page);
54632diff --git a/fs/block_dev.c b/fs/block_dev.c
54633index 1e86823..8e34695 100644
54634--- a/fs/block_dev.c
54635+++ b/fs/block_dev.c
54636@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
54637 else if (bdev->bd_contains == bdev)
54638 return true; /* is a whole device which isn't held */
54639
54640- else if (whole->bd_holder == bd_may_claim)
54641+ else if (whole->bd_holder == (void *)bd_may_claim)
54642 return true; /* is a partition of a device that is being partitioned */
54643 else if (whole->bd_holder != NULL)
54644 return false; /* is a partition of a held device */
54645diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
54646index 61b5bcd..7eeede8 100644
54647--- a/fs/btrfs/ctree.c
54648+++ b/fs/btrfs/ctree.c
54649@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
54650 free_extent_buffer(buf);
54651 add_root_to_dirty_list(root);
54652 } else {
54653- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
54654- parent_start = parent->start;
54655- else
54656+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
54657+ if (parent)
54658+ parent_start = parent->start;
54659+ else
54660+ parent_start = 0;
54661+ } else
54662 parent_start = 0;
54663
54664 WARN_ON(trans->transid != btrfs_header_generation(parent));
54665diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
54666index cbd9523..5cca781 100644
54667--- a/fs/btrfs/delayed-inode.c
54668+++ b/fs/btrfs/delayed-inode.c
54669@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
54670
54671 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
54672 {
54673- int seq = atomic_inc_return(&delayed_root->items_seq);
54674+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
54675 if ((atomic_dec_return(&delayed_root->items) <
54676 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
54677 waitqueue_active(&delayed_root->wait))
54678@@ -1378,7 +1378,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
54679 static int refs_newer(struct btrfs_delayed_root *delayed_root,
54680 int seq, int count)
54681 {
54682- int val = atomic_read(&delayed_root->items_seq);
54683+ int val = atomic_read_unchecked(&delayed_root->items_seq);
54684
54685 if (val < seq || val >= seq + count)
54686 return 1;
54687@@ -1395,7 +1395,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
54688 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
54689 return;
54690
54691- seq = atomic_read(&delayed_root->items_seq);
54692+ seq = atomic_read_unchecked(&delayed_root->items_seq);
54693
54694 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
54695 int ret;
54696diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
54697index a4b38f9..f86a509 100644
54698--- a/fs/btrfs/delayed-inode.h
54699+++ b/fs/btrfs/delayed-inode.h
54700@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
54701 */
54702 struct list_head prepare_list;
54703 atomic_t items; /* for delayed items */
54704- atomic_t items_seq; /* for delayed items */
54705+ atomic_unchecked_t items_seq; /* for delayed items */
54706 int nodes; /* for delayed nodes */
54707 wait_queue_head_t wait;
54708 };
54709@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
54710 struct btrfs_delayed_root *delayed_root)
54711 {
54712 atomic_set(&delayed_root->items, 0);
54713- atomic_set(&delayed_root->items_seq, 0);
54714+ atomic_set_unchecked(&delayed_root->items_seq, 0);
54715 delayed_root->nodes = 0;
54716 spin_lock_init(&delayed_root->lock);
54717 init_waitqueue_head(&delayed_root->wait);
54718diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
54719index 9d46f60..a8f09eb 100644
54720--- a/fs/btrfs/ioctl.c
54721+++ b/fs/btrfs/ioctl.c
54722@@ -3464,9 +3464,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54723 for (i = 0; i < num_types; i++) {
54724 struct btrfs_space_info *tmp;
54725
54726+ /* Don't copy in more than we allocated */
54727 if (!slot_count)
54728 break;
54729
54730+ slot_count--;
54731+
54732 info = NULL;
54733 rcu_read_lock();
54734 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
54735@@ -3488,10 +3491,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54736 memcpy(dest, &space, sizeof(space));
54737 dest++;
54738 space_args.total_spaces++;
54739- slot_count--;
54740 }
54741- if (!slot_count)
54742- break;
54743 }
54744 up_read(&info->groups_sem);
54745 }
54746diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
54747index e913328..a34fb36 100644
54748--- a/fs/btrfs/super.c
54749+++ b/fs/btrfs/super.c
54750@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
54751 function, line, errstr);
54752 return;
54753 }
54754- ACCESS_ONCE(trans->transaction->aborted) = errno;
54755+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
54756 /* Wake up anybody who may be waiting on this transaction */
54757 wake_up(&root->fs_info->transaction_wait);
54758 wake_up(&root->fs_info->transaction_blocked_wait);
54759diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
54760index 79f057c..e14e1f7 100644
54761--- a/fs/btrfs/tree-log.c
54762+++ b/fs/btrfs/tree-log.c
54763@@ -3375,7 +3375,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
54764 btrfs_set_token_file_extent_type(leaf, fi,
54765 BTRFS_FILE_EXTENT_REG,
54766 &token);
54767- if (em->block_start == 0)
54768+ if (em->block_start == EXTENT_MAP_HOLE)
54769 skip_csum = true;
54770 }
54771
54772diff --git a/fs/buffer.c b/fs/buffer.c
54773index 6024877..7bd000a 100644
54774--- a/fs/buffer.c
54775+++ b/fs/buffer.c
54776@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
54777 bh_cachep = kmem_cache_create("buffer_head",
54778 sizeof(struct buffer_head), 0,
54779 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
54780- SLAB_MEM_SPREAD),
54781+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
54782 NULL);
54783
54784 /*
54785diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
54786index 622f469..e8d2d55 100644
54787--- a/fs/cachefiles/bind.c
54788+++ b/fs/cachefiles/bind.c
54789@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
54790 args);
54791
54792 /* start by checking things over */
54793- ASSERT(cache->fstop_percent >= 0 &&
54794- cache->fstop_percent < cache->fcull_percent &&
54795+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
54796 cache->fcull_percent < cache->frun_percent &&
54797 cache->frun_percent < 100);
54798
54799- ASSERT(cache->bstop_percent >= 0 &&
54800- cache->bstop_percent < cache->bcull_percent &&
54801+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
54802 cache->bcull_percent < cache->brun_percent &&
54803 cache->brun_percent < 100);
54804
54805diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
54806index 0a1467b..6a53245 100644
54807--- a/fs/cachefiles/daemon.c
54808+++ b/fs/cachefiles/daemon.c
54809@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
54810 if (n > buflen)
54811 return -EMSGSIZE;
54812
54813- if (copy_to_user(_buffer, buffer, n) != 0)
54814+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
54815 return -EFAULT;
54816
54817 return n;
54818@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
54819 if (test_bit(CACHEFILES_DEAD, &cache->flags))
54820 return -EIO;
54821
54822- if (datalen < 0 || datalen > PAGE_SIZE - 1)
54823+ if (datalen > PAGE_SIZE - 1)
54824 return -EOPNOTSUPP;
54825
54826 /* drag the command string into the kernel so we can parse it */
54827@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
54828 if (args[0] != '%' || args[1] != '\0')
54829 return -EINVAL;
54830
54831- if (fstop < 0 || fstop >= cache->fcull_percent)
54832+ if (fstop >= cache->fcull_percent)
54833 return cachefiles_daemon_range_error(cache, args);
54834
54835 cache->fstop_percent = fstop;
54836@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54837 if (args[0] != '%' || args[1] != '\0')
54838 return -EINVAL;
54839
54840- if (bstop < 0 || bstop >= cache->bcull_percent)
54841+ if (bstop >= cache->bcull_percent)
54842 return cachefiles_daemon_range_error(cache, args);
54843
54844 cache->bstop_percent = bstop;
54845diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54846index 5349473..d6c0b93 100644
54847--- a/fs/cachefiles/internal.h
54848+++ b/fs/cachefiles/internal.h
54849@@ -59,7 +59,7 @@ struct cachefiles_cache {
54850 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54851 struct rb_root active_nodes; /* active nodes (can't be culled) */
54852 rwlock_t active_lock; /* lock for active_nodes */
54853- atomic_t gravecounter; /* graveyard uniquifier */
54854+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54855 unsigned frun_percent; /* when to stop culling (% files) */
54856 unsigned fcull_percent; /* when to start culling (% files) */
54857 unsigned fstop_percent; /* when to stop allocating (% files) */
54858@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54859 * proc.c
54860 */
54861 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54862-extern atomic_t cachefiles_lookup_histogram[HZ];
54863-extern atomic_t cachefiles_mkdir_histogram[HZ];
54864-extern atomic_t cachefiles_create_histogram[HZ];
54865+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54866+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54867+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54868
54869 extern int __init cachefiles_proc_init(void);
54870 extern void cachefiles_proc_cleanup(void);
54871 static inline
54872-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54873+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54874 {
54875 unsigned long jif = jiffies - start_jif;
54876 if (jif >= HZ)
54877 jif = HZ - 1;
54878- atomic_inc(&histogram[jif]);
54879+ atomic_inc_unchecked(&histogram[jif]);
54880 }
54881
54882 #else
54883diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54884index f4a08d7..5aa4599 100644
54885--- a/fs/cachefiles/namei.c
54886+++ b/fs/cachefiles/namei.c
54887@@ -317,7 +317,7 @@ try_again:
54888 /* first step is to make up a grave dentry in the graveyard */
54889 sprintf(nbuffer, "%08x%08x",
54890 (uint32_t) get_seconds(),
54891- (uint32_t) atomic_inc_return(&cache->gravecounter));
54892+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54893
54894 /* do the multiway lock magic */
54895 trap = lock_rename(cache->graveyard, dir);
54896diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54897index eccd339..4c1d995 100644
54898--- a/fs/cachefiles/proc.c
54899+++ b/fs/cachefiles/proc.c
54900@@ -14,9 +14,9 @@
54901 #include <linux/seq_file.h>
54902 #include "internal.h"
54903
54904-atomic_t cachefiles_lookup_histogram[HZ];
54905-atomic_t cachefiles_mkdir_histogram[HZ];
54906-atomic_t cachefiles_create_histogram[HZ];
54907+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54908+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54909+atomic_unchecked_t cachefiles_create_histogram[HZ];
54910
54911 /*
54912 * display the latency histogram
54913@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54914 return 0;
54915 default:
54916 index = (unsigned long) v - 3;
54917- x = atomic_read(&cachefiles_lookup_histogram[index]);
54918- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54919- z = atomic_read(&cachefiles_create_histogram[index]);
54920+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54921+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54922+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54923 if (x == 0 && y == 0 && z == 0)
54924 return 0;
54925
54926diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54927index ebaff36..7e3ea26 100644
54928--- a/fs/cachefiles/rdwr.c
54929+++ b/fs/cachefiles/rdwr.c
54930@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54931 old_fs = get_fs();
54932 set_fs(KERNEL_DS);
54933 ret = file->f_op->write(
54934- file, (const void __user *) data, len, &pos);
54935+ file, (const void __force_user *) data, len, &pos);
54936 set_fs(old_fs);
54937 kunmap(page);
54938 file_end_write(file);
54939diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54940index 868b61d..58835a5 100644
54941--- a/fs/ceph/dir.c
54942+++ b/fs/ceph/dir.c
54943@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
54944 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54945 struct ceph_mds_client *mdsc = fsc->mdsc;
54946 unsigned frag = fpos_frag(ctx->pos);
54947- int off = fpos_off(ctx->pos);
54948+ unsigned int off = fpos_off(ctx->pos);
54949 int err;
54950 u32 ftype;
54951 struct ceph_mds_reply_info_parsed *rinfo;
54952diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54953index 6a0951e..03fac6d 100644
54954--- a/fs/ceph/super.c
54955+++ b/fs/ceph/super.c
54956@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54957 /*
54958 * construct our own bdi so we can control readahead, etc.
54959 */
54960-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54961+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54962
54963 static int ceph_register_bdi(struct super_block *sb,
54964 struct ceph_fs_client *fsc)
54965@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
54966 default_backing_dev_info.ra_pages;
54967
54968 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54969- atomic_long_inc_return(&bdi_seq));
54970+ atomic_long_inc_return_unchecked(&bdi_seq));
54971 if (!err)
54972 sb->s_bdi = &fsc->backing_dev_info;
54973 return err;
54974diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54975index f3ac415..3d2420c 100644
54976--- a/fs/cifs/cifs_debug.c
54977+++ b/fs/cifs/cifs_debug.c
54978@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54979
54980 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54981 #ifdef CONFIG_CIFS_STATS2
54982- atomic_set(&totBufAllocCount, 0);
54983- atomic_set(&totSmBufAllocCount, 0);
54984+ atomic_set_unchecked(&totBufAllocCount, 0);
54985+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54986 #endif /* CONFIG_CIFS_STATS2 */
54987 spin_lock(&cifs_tcp_ses_lock);
54988 list_for_each(tmp1, &cifs_tcp_ses_list) {
54989@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54990 tcon = list_entry(tmp3,
54991 struct cifs_tcon,
54992 tcon_list);
54993- atomic_set(&tcon->num_smbs_sent, 0);
54994+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54995 if (server->ops->clear_stats)
54996 server->ops->clear_stats(tcon);
54997 }
54998@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54999 smBufAllocCount.counter, cifs_min_small);
55000 #ifdef CONFIG_CIFS_STATS2
55001 seq_printf(m, "Total Large %d Small %d Allocations\n",
55002- atomic_read(&totBufAllocCount),
55003- atomic_read(&totSmBufAllocCount));
55004+ atomic_read_unchecked(&totBufAllocCount),
55005+ atomic_read_unchecked(&totSmBufAllocCount));
55006 #endif /* CONFIG_CIFS_STATS2 */
55007
55008 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
55009@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
55010 if (tcon->need_reconnect)
55011 seq_puts(m, "\tDISCONNECTED ");
55012 seq_printf(m, "\nSMBs: %d",
55013- atomic_read(&tcon->num_smbs_sent));
55014+ atomic_read_unchecked(&tcon->num_smbs_sent));
55015 if (server->ops->print_stats)
55016 server->ops->print_stats(m, tcon);
55017 }
55018diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
55019index 77fc5e1..e3d13e6 100644
55020--- a/fs/cifs/cifsfs.c
55021+++ b/fs/cifs/cifsfs.c
55022@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
55023 */
55024 cifs_req_cachep = kmem_cache_create("cifs_request",
55025 CIFSMaxBufSize + max_hdr_size, 0,
55026- SLAB_HWCACHE_ALIGN, NULL);
55027+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
55028 if (cifs_req_cachep == NULL)
55029 return -ENOMEM;
55030
55031@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
55032 efficient to alloc 1 per page off the slab compared to 17K (5page)
55033 alloc of large cifs buffers even when page debugging is on */
55034 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
55035- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
55036+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
55037 NULL);
55038 if (cifs_sm_req_cachep == NULL) {
55039 mempool_destroy(cifs_req_poolp);
55040@@ -1168,8 +1168,8 @@ init_cifs(void)
55041 atomic_set(&bufAllocCount, 0);
55042 atomic_set(&smBufAllocCount, 0);
55043 #ifdef CONFIG_CIFS_STATS2
55044- atomic_set(&totBufAllocCount, 0);
55045- atomic_set(&totSmBufAllocCount, 0);
55046+ atomic_set_unchecked(&totBufAllocCount, 0);
55047+ atomic_set_unchecked(&totSmBufAllocCount, 0);
55048 #endif /* CONFIG_CIFS_STATS2 */
55049
55050 atomic_set(&midCount, 0);
55051diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
55052index c8e03f8..75362f6 100644
55053--- a/fs/cifs/cifsglob.h
55054+++ b/fs/cifs/cifsglob.h
55055@@ -758,35 +758,35 @@ struct cifs_tcon {
55056 __u16 Flags; /* optional support bits */
55057 enum statusEnum tidStatus;
55058 #ifdef CONFIG_CIFS_STATS
55059- atomic_t num_smbs_sent;
55060+ atomic_unchecked_t num_smbs_sent;
55061 union {
55062 struct {
55063- atomic_t num_writes;
55064- atomic_t num_reads;
55065- atomic_t num_flushes;
55066- atomic_t num_oplock_brks;
55067- atomic_t num_opens;
55068- atomic_t num_closes;
55069- atomic_t num_deletes;
55070- atomic_t num_mkdirs;
55071- atomic_t num_posixopens;
55072- atomic_t num_posixmkdirs;
55073- atomic_t num_rmdirs;
55074- atomic_t num_renames;
55075- atomic_t num_t2renames;
55076- atomic_t num_ffirst;
55077- atomic_t num_fnext;
55078- atomic_t num_fclose;
55079- atomic_t num_hardlinks;
55080- atomic_t num_symlinks;
55081- atomic_t num_locks;
55082- atomic_t num_acl_get;
55083- atomic_t num_acl_set;
55084+ atomic_unchecked_t num_writes;
55085+ atomic_unchecked_t num_reads;
55086+ atomic_unchecked_t num_flushes;
55087+ atomic_unchecked_t num_oplock_brks;
55088+ atomic_unchecked_t num_opens;
55089+ atomic_unchecked_t num_closes;
55090+ atomic_unchecked_t num_deletes;
55091+ atomic_unchecked_t num_mkdirs;
55092+ atomic_unchecked_t num_posixopens;
55093+ atomic_unchecked_t num_posixmkdirs;
55094+ atomic_unchecked_t num_rmdirs;
55095+ atomic_unchecked_t num_renames;
55096+ atomic_unchecked_t num_t2renames;
55097+ atomic_unchecked_t num_ffirst;
55098+ atomic_unchecked_t num_fnext;
55099+ atomic_unchecked_t num_fclose;
55100+ atomic_unchecked_t num_hardlinks;
55101+ atomic_unchecked_t num_symlinks;
55102+ atomic_unchecked_t num_locks;
55103+ atomic_unchecked_t num_acl_get;
55104+ atomic_unchecked_t num_acl_set;
55105 } cifs_stats;
55106 #ifdef CONFIG_CIFS_SMB2
55107 struct {
55108- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
55109- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
55110+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
55111+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
55112 } smb2_stats;
55113 #endif /* CONFIG_CIFS_SMB2 */
55114 } stats;
55115@@ -1111,7 +1111,7 @@ convert_delimiter(char *path, char delim)
55116 }
55117
55118 #ifdef CONFIG_CIFS_STATS
55119-#define cifs_stats_inc atomic_inc
55120+#define cifs_stats_inc atomic_inc_unchecked
55121
55122 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
55123 unsigned int bytes)
55124@@ -1477,8 +1477,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
55125 /* Various Debug counters */
55126 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
55127 #ifdef CONFIG_CIFS_STATS2
55128-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
55129-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
55130+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
55131+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
55132 #endif
55133 GLOBAL_EXTERN atomic_t smBufAllocCount;
55134 GLOBAL_EXTERN atomic_t midCount;
55135diff --git a/fs/cifs/file.c b/fs/cifs/file.c
55136index 7ddddf2..2e12dbc 100644
55137--- a/fs/cifs/file.c
55138+++ b/fs/cifs/file.c
55139@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
55140 index = mapping->writeback_index; /* Start from prev offset */
55141 end = -1;
55142 } else {
55143- index = wbc->range_start >> PAGE_CACHE_SHIFT;
55144- end = wbc->range_end >> PAGE_CACHE_SHIFT;
55145- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
55146+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
55147 range_whole = true;
55148+ index = 0;
55149+ end = ULONG_MAX;
55150+ } else {
55151+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
55152+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
55153+ }
55154 scanned = true;
55155 }
55156 retry:
55157diff --git a/fs/cifs/link.c b/fs/cifs/link.c
55158index 7e36ceb..109252f 100644
55159--- a/fs/cifs/link.c
55160+++ b/fs/cifs/link.c
55161@@ -624,7 +624,7 @@ symlink_exit:
55162
55163 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
55164 {
55165- char *p = nd_get_link(nd);
55166+ const char *p = nd_get_link(nd);
55167 if (!IS_ERR(p))
55168 kfree(p);
55169 }
55170diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
55171index 138a011..cf9e13a 100644
55172--- a/fs/cifs/misc.c
55173+++ b/fs/cifs/misc.c
55174@@ -170,7 +170,7 @@ cifs_buf_get(void)
55175 memset(ret_buf, 0, buf_size + 3);
55176 atomic_inc(&bufAllocCount);
55177 #ifdef CONFIG_CIFS_STATS2
55178- atomic_inc(&totBufAllocCount);
55179+ atomic_inc_unchecked(&totBufAllocCount);
55180 #endif /* CONFIG_CIFS_STATS2 */
55181 }
55182
55183@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
55184 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
55185 atomic_inc(&smBufAllocCount);
55186 #ifdef CONFIG_CIFS_STATS2
55187- atomic_inc(&totSmBufAllocCount);
55188+ atomic_inc_unchecked(&totSmBufAllocCount);
55189 #endif /* CONFIG_CIFS_STATS2 */
55190
55191 }
55192diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
55193index e50554b..c011413 100644
55194--- a/fs/cifs/smb1ops.c
55195+++ b/fs/cifs/smb1ops.c
55196@@ -609,27 +609,27 @@ static void
55197 cifs_clear_stats(struct cifs_tcon *tcon)
55198 {
55199 #ifdef CONFIG_CIFS_STATS
55200- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
55201- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
55202- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
55203- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
55204- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
55205- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
55206- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
55207- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
55208- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
55209- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
55210- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
55211- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
55212- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
55213- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
55214- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
55215- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
55216- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
55217- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
55218- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
55219- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
55220- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
55221+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
55222+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
55223+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
55224+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
55225+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
55226+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
55227+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
55228+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
55229+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
55230+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
55231+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
55232+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
55233+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
55234+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
55235+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
55236+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
55237+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
55238+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
55239+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
55240+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
55241+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
55242 #endif
55243 }
55244
55245@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
55246 {
55247 #ifdef CONFIG_CIFS_STATS
55248 seq_printf(m, " Oplocks breaks: %d",
55249- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
55250+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
55251 seq_printf(m, "\nReads: %d Bytes: %llu",
55252- atomic_read(&tcon->stats.cifs_stats.num_reads),
55253+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
55254 (long long)(tcon->bytes_read));
55255 seq_printf(m, "\nWrites: %d Bytes: %llu",
55256- atomic_read(&tcon->stats.cifs_stats.num_writes),
55257+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
55258 (long long)(tcon->bytes_written));
55259 seq_printf(m, "\nFlushes: %d",
55260- atomic_read(&tcon->stats.cifs_stats.num_flushes));
55261+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
55262 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
55263- atomic_read(&tcon->stats.cifs_stats.num_locks),
55264- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
55265- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
55266+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
55267+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
55268+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
55269 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
55270- atomic_read(&tcon->stats.cifs_stats.num_opens),
55271- atomic_read(&tcon->stats.cifs_stats.num_closes),
55272- atomic_read(&tcon->stats.cifs_stats.num_deletes));
55273+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
55274+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
55275+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
55276 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
55277- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
55278- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
55279+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
55280+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
55281 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
55282- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
55283- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
55284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
55285+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
55286 seq_printf(m, "\nRenames: %d T2 Renames %d",
55287- atomic_read(&tcon->stats.cifs_stats.num_renames),
55288- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
55289+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
55290+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
55291 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
55292- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
55293- atomic_read(&tcon->stats.cifs_stats.num_fnext),
55294- atomic_read(&tcon->stats.cifs_stats.num_fclose));
55295+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
55296+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
55297+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
55298 #endif
55299 }
55300
55301diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
55302index 861b332..5506392 100644
55303--- a/fs/cifs/smb2ops.c
55304+++ b/fs/cifs/smb2ops.c
55305@@ -282,8 +282,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
55306 #ifdef CONFIG_CIFS_STATS
55307 int i;
55308 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
55309- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
55310- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
55311+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
55312+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
55313 }
55314 #endif
55315 }
55316@@ -311,65 +311,65 @@ static void
55317 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
55318 {
55319 #ifdef CONFIG_CIFS_STATS
55320- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
55321- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
55322+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
55323+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
55324 seq_printf(m, "\nNegotiates: %d sent %d failed",
55325- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
55326- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
55327+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
55328+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
55329 seq_printf(m, "\nSessionSetups: %d sent %d failed",
55330- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
55331- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
55332+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
55333+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
55334 seq_printf(m, "\nLogoffs: %d sent %d failed",
55335- atomic_read(&sent[SMB2_LOGOFF_HE]),
55336- atomic_read(&failed[SMB2_LOGOFF_HE]));
55337+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
55338+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
55339 seq_printf(m, "\nTreeConnects: %d sent %d failed",
55340- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
55341- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
55342+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
55343+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
55344 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
55345- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
55346- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
55347+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
55348+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
55349 seq_printf(m, "\nCreates: %d sent %d failed",
55350- atomic_read(&sent[SMB2_CREATE_HE]),
55351- atomic_read(&failed[SMB2_CREATE_HE]));
55352+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
55353+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
55354 seq_printf(m, "\nCloses: %d sent %d failed",
55355- atomic_read(&sent[SMB2_CLOSE_HE]),
55356- atomic_read(&failed[SMB2_CLOSE_HE]));
55357+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
55358+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
55359 seq_printf(m, "\nFlushes: %d sent %d failed",
55360- atomic_read(&sent[SMB2_FLUSH_HE]),
55361- atomic_read(&failed[SMB2_FLUSH_HE]));
55362+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
55363+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
55364 seq_printf(m, "\nReads: %d sent %d failed",
55365- atomic_read(&sent[SMB2_READ_HE]),
55366- atomic_read(&failed[SMB2_READ_HE]));
55367+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
55368+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
55369 seq_printf(m, "\nWrites: %d sent %d failed",
55370- atomic_read(&sent[SMB2_WRITE_HE]),
55371- atomic_read(&failed[SMB2_WRITE_HE]));
55372+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
55373+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
55374 seq_printf(m, "\nLocks: %d sent %d failed",
55375- atomic_read(&sent[SMB2_LOCK_HE]),
55376- atomic_read(&failed[SMB2_LOCK_HE]));
55377+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
55378+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
55379 seq_printf(m, "\nIOCTLs: %d sent %d failed",
55380- atomic_read(&sent[SMB2_IOCTL_HE]),
55381- atomic_read(&failed[SMB2_IOCTL_HE]));
55382+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
55383+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
55384 seq_printf(m, "\nCancels: %d sent %d failed",
55385- atomic_read(&sent[SMB2_CANCEL_HE]),
55386- atomic_read(&failed[SMB2_CANCEL_HE]));
55387+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
55388+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
55389 seq_printf(m, "\nEchos: %d sent %d failed",
55390- atomic_read(&sent[SMB2_ECHO_HE]),
55391- atomic_read(&failed[SMB2_ECHO_HE]));
55392+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
55393+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
55394 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
55395- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
55396- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
55397+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
55398+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
55399 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
55400- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
55401- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
55402+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
55403+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
55404 seq_printf(m, "\nQueryInfos: %d sent %d failed",
55405- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
55406- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
55407+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
55408+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
55409 seq_printf(m, "\nSetInfos: %d sent %d failed",
55410- atomic_read(&sent[SMB2_SET_INFO_HE]),
55411- atomic_read(&failed[SMB2_SET_INFO_HE]));
55412+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
55413+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
55414 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
55415- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
55416- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
55417+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
55418+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
55419 #endif
55420 }
55421
55422diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
55423index edccb52..16bc6db 100644
55424--- a/fs/cifs/smb2pdu.c
55425+++ b/fs/cifs/smb2pdu.c
55426@@ -1957,8 +1957,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
55427 default:
55428 cifs_dbg(VFS, "info level %u isn't supported\n",
55429 srch_inf->info_level);
55430- rc = -EINVAL;
55431- goto qdir_exit;
55432+ return -EINVAL;
55433 }
55434
55435 req->FileIndex = cpu_to_le32(index);
55436diff --git a/fs/coda/cache.c b/fs/coda/cache.c
55437index 1da168c..8bc7ff6 100644
55438--- a/fs/coda/cache.c
55439+++ b/fs/coda/cache.c
55440@@ -24,7 +24,7 @@
55441 #include "coda_linux.h"
55442 #include "coda_cache.h"
55443
55444-static atomic_t permission_epoch = ATOMIC_INIT(0);
55445+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
55446
55447 /* replace or extend an acl cache hit */
55448 void coda_cache_enter(struct inode *inode, int mask)
55449@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
55450 struct coda_inode_info *cii = ITOC(inode);
55451
55452 spin_lock(&cii->c_lock);
55453- cii->c_cached_epoch = atomic_read(&permission_epoch);
55454+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
55455 if (!uid_eq(cii->c_uid, current_fsuid())) {
55456 cii->c_uid = current_fsuid();
55457 cii->c_cached_perm = mask;
55458@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
55459 {
55460 struct coda_inode_info *cii = ITOC(inode);
55461 spin_lock(&cii->c_lock);
55462- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
55463+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
55464 spin_unlock(&cii->c_lock);
55465 }
55466
55467 /* remove all acl caches */
55468 void coda_cache_clear_all(struct super_block *sb)
55469 {
55470- atomic_inc(&permission_epoch);
55471+ atomic_inc_unchecked(&permission_epoch);
55472 }
55473
55474
55475@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
55476 spin_lock(&cii->c_lock);
55477 hit = (mask & cii->c_cached_perm) == mask &&
55478 uid_eq(cii->c_uid, current_fsuid()) &&
55479- cii->c_cached_epoch == atomic_read(&permission_epoch);
55480+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
55481 spin_unlock(&cii->c_lock);
55482
55483 return hit;
55484diff --git a/fs/compat.c b/fs/compat.c
55485index 6af20de..fec3fbb 100644
55486--- a/fs/compat.c
55487+++ b/fs/compat.c
55488@@ -54,7 +54,7 @@
55489 #include <asm/ioctls.h>
55490 #include "internal.h"
55491
55492-int compat_log = 1;
55493+int compat_log = 0;
55494
55495 int compat_printk(const char *fmt, ...)
55496 {
55497@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
55498
55499 set_fs(KERNEL_DS);
55500 /* The __user pointer cast is valid because of the set_fs() */
55501- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
55502+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
55503 set_fs(oldfs);
55504 /* truncating is ok because it's a user address */
55505 if (!ret)
55506@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
55507 goto out;
55508
55509 ret = -EINVAL;
55510- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
55511+ if (nr_segs > UIO_MAXIOV)
55512 goto out;
55513 if (nr_segs > fast_segs) {
55514 ret = -ENOMEM;
55515@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
55516 struct compat_readdir_callback {
55517 struct dir_context ctx;
55518 struct compat_old_linux_dirent __user *dirent;
55519+ struct file * file;
55520 int result;
55521 };
55522
55523@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
55524 buf->result = -EOVERFLOW;
55525 return -EOVERFLOW;
55526 }
55527+
55528+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55529+ return 0;
55530+
55531 buf->result++;
55532 dirent = buf->dirent;
55533 if (!access_ok(VERIFY_WRITE, dirent,
55534@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
55535 if (!f.file)
55536 return -EBADF;
55537
55538+ buf.file = f.file;
55539 error = iterate_dir(f.file, &buf.ctx);
55540 if (buf.result)
55541 error = buf.result;
55542@@ -901,6 +907,7 @@ struct compat_getdents_callback {
55543 struct dir_context ctx;
55544 struct compat_linux_dirent __user *current_dir;
55545 struct compat_linux_dirent __user *previous;
55546+ struct file * file;
55547 int count;
55548 int error;
55549 };
55550@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
55551 buf->error = -EOVERFLOW;
55552 return -EOVERFLOW;
55553 }
55554+
55555+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55556+ return 0;
55557+
55558 dirent = buf->previous;
55559 if (dirent) {
55560 if (__put_user(offset, &dirent->d_off))
55561@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55562 if (!f.file)
55563 return -EBADF;
55564
55565+ buf.file = f.file;
55566 error = iterate_dir(f.file, &buf.ctx);
55567 if (error >= 0)
55568 error = buf.error;
55569@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
55570 struct dir_context ctx;
55571 struct linux_dirent64 __user *current_dir;
55572 struct linux_dirent64 __user *previous;
55573+ struct file * file;
55574 int count;
55575 int error;
55576 };
55577@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
55578 buf->error = -EINVAL; /* only used if we fail.. */
55579 if (reclen > buf->count)
55580 return -EINVAL;
55581+
55582+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55583+ return 0;
55584+
55585 dirent = buf->previous;
55586
55587 if (dirent) {
55588@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
55589 if (!f.file)
55590 return -EBADF;
55591
55592+ buf.file = f.file;
55593 error = iterate_dir(f.file, &buf.ctx);
55594 if (error >= 0)
55595 error = buf.error;
55596diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
55597index a81147e..20bf2b5 100644
55598--- a/fs/compat_binfmt_elf.c
55599+++ b/fs/compat_binfmt_elf.c
55600@@ -30,11 +30,13 @@
55601 #undef elf_phdr
55602 #undef elf_shdr
55603 #undef elf_note
55604+#undef elf_dyn
55605 #undef elf_addr_t
55606 #define elfhdr elf32_hdr
55607 #define elf_phdr elf32_phdr
55608 #define elf_shdr elf32_shdr
55609 #define elf_note elf32_note
55610+#define elf_dyn Elf32_Dyn
55611 #define elf_addr_t Elf32_Addr
55612
55613 /*
55614diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
55615index 5d19acf..9ab093b 100644
55616--- a/fs/compat_ioctl.c
55617+++ b/fs/compat_ioctl.c
55618@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
55619 return -EFAULT;
55620 if (__get_user(udata, &ss32->iomem_base))
55621 return -EFAULT;
55622- ss.iomem_base = compat_ptr(udata);
55623+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
55624 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
55625 __get_user(ss.port_high, &ss32->port_high))
55626 return -EFAULT;
55627@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
55628 for (i = 0; i < nmsgs; i++) {
55629 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
55630 return -EFAULT;
55631- if (get_user(datap, &umsgs[i].buf) ||
55632- put_user(compat_ptr(datap), &tmsgs[i].buf))
55633+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
55634+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
55635 return -EFAULT;
55636 }
55637 return sys_ioctl(fd, cmd, (unsigned long)tdata);
55638@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
55639 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
55640 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
55641 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
55642- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55643+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55644 return -EFAULT;
55645
55646 return ioctl_preallocate(file, p);
55647@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
55648 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
55649 {
55650 unsigned int a, b;
55651- a = *(unsigned int *)p;
55652- b = *(unsigned int *)q;
55653+ a = *(const unsigned int *)p;
55654+ b = *(const unsigned int *)q;
55655 if (a > b)
55656 return 1;
55657 if (a < b)
55658diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
55659index 511d415..319d0e5 100644
55660--- a/fs/configfs/dir.c
55661+++ b/fs/configfs/dir.c
55662@@ -1558,7 +1558,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
55663 }
55664 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
55665 struct configfs_dirent *next;
55666- const char *name;
55667+ const unsigned char * name;
55668+ char d_name[sizeof(next->s_dentry->d_iname)];
55669 int len;
55670 struct inode *inode = NULL;
55671
55672@@ -1567,7 +1568,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
55673 continue;
55674
55675 name = configfs_get_name(next);
55676- len = strlen(name);
55677+ if (next->s_dentry && name == next->s_dentry->d_iname) {
55678+ len = next->s_dentry->d_name.len;
55679+ memcpy(d_name, name, len);
55680+ name = d_name;
55681+ } else
55682+ len = strlen(name);
55683
55684 /*
55685 * We'll have a dentry and an inode for
55686diff --git a/fs/coredump.c b/fs/coredump.c
55687index 9bdeca1..2a9b08d 100644
55688--- a/fs/coredump.c
55689+++ b/fs/coredump.c
55690@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
55691 struct pipe_inode_info *pipe = file->private_data;
55692
55693 pipe_lock(pipe);
55694- pipe->readers++;
55695- pipe->writers--;
55696+ atomic_inc(&pipe->readers);
55697+ atomic_dec(&pipe->writers);
55698 wake_up_interruptible_sync(&pipe->wait);
55699 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55700 pipe_unlock(pipe);
55701@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
55702 * We actually want wait_event_freezable() but then we need
55703 * to clear TIF_SIGPENDING and improve dump_interrupted().
55704 */
55705- wait_event_interruptible(pipe->wait, pipe->readers == 1);
55706+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
55707
55708 pipe_lock(pipe);
55709- pipe->readers--;
55710- pipe->writers++;
55711+ atomic_dec(&pipe->readers);
55712+ atomic_inc(&pipe->writers);
55713 pipe_unlock(pipe);
55714 }
55715
55716@@ -499,7 +499,9 @@ void do_coredump(siginfo_t *siginfo)
55717 struct files_struct *displaced;
55718 bool need_nonrelative = false;
55719 bool core_dumped = false;
55720- static atomic_t core_dump_count = ATOMIC_INIT(0);
55721+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
55722+ long signr = siginfo->si_signo;
55723+ int dumpable;
55724 struct coredump_params cprm = {
55725 .siginfo = siginfo,
55726 .regs = signal_pt_regs(),
55727@@ -512,12 +514,17 @@ void do_coredump(siginfo_t *siginfo)
55728 .mm_flags = mm->flags,
55729 };
55730
55731- audit_core_dumps(siginfo->si_signo);
55732+ audit_core_dumps(signr);
55733+
55734+ dumpable = __get_dumpable(cprm.mm_flags);
55735+
55736+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
55737+ gr_handle_brute_attach(dumpable);
55738
55739 binfmt = mm->binfmt;
55740 if (!binfmt || !binfmt->core_dump)
55741 goto fail;
55742- if (!__get_dumpable(cprm.mm_flags))
55743+ if (!dumpable)
55744 goto fail;
55745
55746 cred = prepare_creds();
55747@@ -536,7 +543,7 @@ void do_coredump(siginfo_t *siginfo)
55748 need_nonrelative = true;
55749 }
55750
55751- retval = coredump_wait(siginfo->si_signo, &core_state);
55752+ retval = coredump_wait(signr, &core_state);
55753 if (retval < 0)
55754 goto fail_creds;
55755
55756@@ -579,7 +586,7 @@ void do_coredump(siginfo_t *siginfo)
55757 }
55758 cprm.limit = RLIM_INFINITY;
55759
55760- dump_count = atomic_inc_return(&core_dump_count);
55761+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
55762 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
55763 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
55764 task_tgid_vnr(current), current->comm);
55765@@ -611,6 +618,8 @@ void do_coredump(siginfo_t *siginfo)
55766 } else {
55767 struct inode *inode;
55768
55769+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
55770+
55771 if (cprm.limit < binfmt->min_coredump)
55772 goto fail_unlock;
55773
55774@@ -669,7 +678,7 @@ close_fail:
55775 filp_close(cprm.file, NULL);
55776 fail_dropcount:
55777 if (ispipe)
55778- atomic_dec(&core_dump_count);
55779+ atomic_dec_unchecked(&core_dump_count);
55780 fail_unlock:
55781 kfree(cn.corename);
55782 coredump_finish(mm, core_dumped);
55783@@ -689,7 +698,7 @@ int dump_write(struct file *file, const void *addr, int nr)
55784 {
55785 return !dump_interrupted() &&
55786 access_ok(VERIFY_READ, addr, nr) &&
55787- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
55788+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
55789 }
55790 EXPORT_SYMBOL(dump_write);
55791
55792diff --git a/fs/dcache.c b/fs/dcache.c
55793index 89f9671..d2dce57 100644
55794--- a/fs/dcache.c
55795+++ b/fs/dcache.c
55796@@ -1570,7 +1570,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
55797 */
55798 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
55799 if (name->len > DNAME_INLINE_LEN-1) {
55800- dname = kmalloc(name->len + 1, GFP_KERNEL);
55801+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
55802 if (!dname) {
55803 kmem_cache_free(dentry_cache, dentry);
55804 return NULL;
55805@@ -2893,6 +2893,7 @@ static int prepend_path(const struct path *path,
55806 restart:
55807 bptr = *buffer;
55808 blen = *buflen;
55809+ error = 0;
55810 dentry = path->dentry;
55811 vfsmnt = path->mnt;
55812 mnt = real_mount(vfsmnt);
55813@@ -3432,7 +3433,8 @@ void __init vfs_caches_init(unsigned long mempages)
55814 mempages -= reserve;
55815
55816 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
55817- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
55818+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
55819+ SLAB_NO_SANITIZE, NULL);
55820
55821 dcache_init();
55822 inode_init();
55823diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
55824index c7c83ff..bda9461 100644
55825--- a/fs/debugfs/inode.c
55826+++ b/fs/debugfs/inode.c
55827@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
55828 */
55829 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
55830 {
55831+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55832+ return __create_file(name, S_IFDIR | S_IRWXU,
55833+#else
55834 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
55835+#endif
55836 parent, NULL, NULL);
55837 }
55838 EXPORT_SYMBOL_GPL(debugfs_create_dir);
55839diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
55840index 67e9b63..a9adb68 100644
55841--- a/fs/ecryptfs/inode.c
55842+++ b/fs/ecryptfs/inode.c
55843@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
55844 old_fs = get_fs();
55845 set_fs(get_ds());
55846 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
55847- (char __user *)lower_buf,
55848+ (char __force_user *)lower_buf,
55849 PATH_MAX);
55850 set_fs(old_fs);
55851 if (rc < 0)
55852@@ -706,7 +706,7 @@ out:
55853 static void
55854 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55855 {
55856- char *buf = nd_get_link(nd);
55857+ const char *buf = nd_get_link(nd);
55858 if (!IS_ERR(buf)) {
55859 /* Free the char* */
55860 kfree(buf);
55861diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55862index e4141f2..d8263e8 100644
55863--- a/fs/ecryptfs/miscdev.c
55864+++ b/fs/ecryptfs/miscdev.c
55865@@ -304,7 +304,7 @@ check_list:
55866 goto out_unlock_msg_ctx;
55867 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55868 if (msg_ctx->msg) {
55869- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55870+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55871 goto out_unlock_msg_ctx;
55872 i += packet_length_size;
55873 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55874diff --git a/fs/exec.c b/fs/exec.c
55875index bb8afc1..2f5087e 100644
55876--- a/fs/exec.c
55877+++ b/fs/exec.c
55878@@ -55,8 +55,20 @@
55879 #include <linux/pipe_fs_i.h>
55880 #include <linux/oom.h>
55881 #include <linux/compat.h>
55882+#include <linux/random.h>
55883+#include <linux/seq_file.h>
55884+#include <linux/coredump.h>
55885+#include <linux/mman.h>
55886+
55887+#ifdef CONFIG_PAX_REFCOUNT
55888+#include <linux/kallsyms.h>
55889+#include <linux/kdebug.h>
55890+#endif
55891+
55892+#include <trace/events/fs.h>
55893
55894 #include <asm/uaccess.h>
55895+#include <asm/sections.h>
55896 #include <asm/mmu_context.h>
55897 #include <asm/tlb.h>
55898
55899@@ -66,19 +78,34 @@
55900
55901 #include <trace/events/sched.h>
55902
55903+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55904+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55905+{
55906+ 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");
55907+}
55908+#endif
55909+
55910+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55911+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55912+EXPORT_SYMBOL(pax_set_initial_flags_func);
55913+#endif
55914+
55915 int suid_dumpable = 0;
55916
55917 static LIST_HEAD(formats);
55918 static DEFINE_RWLOCK(binfmt_lock);
55919
55920+extern int gr_process_kernel_exec_ban(void);
55921+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55922+
55923 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55924 {
55925 BUG_ON(!fmt);
55926 if (WARN_ON(!fmt->load_binary))
55927 return;
55928 write_lock(&binfmt_lock);
55929- insert ? list_add(&fmt->lh, &formats) :
55930- list_add_tail(&fmt->lh, &formats);
55931+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55932+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55933 write_unlock(&binfmt_lock);
55934 }
55935
55936@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
55937 void unregister_binfmt(struct linux_binfmt * fmt)
55938 {
55939 write_lock(&binfmt_lock);
55940- list_del(&fmt->lh);
55941+ pax_list_del((struct list_head *)&fmt->lh);
55942 write_unlock(&binfmt_lock);
55943 }
55944
55945@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55946 int write)
55947 {
55948 struct page *page;
55949- int ret;
55950
55951-#ifdef CONFIG_STACK_GROWSUP
55952- if (write) {
55953- ret = expand_downwards(bprm->vma, pos);
55954- if (ret < 0)
55955- return NULL;
55956- }
55957-#endif
55958- ret = get_user_pages(current, bprm->mm, pos,
55959- 1, write, 1, &page, NULL);
55960- if (ret <= 0)
55961+ if (0 > expand_downwards(bprm->vma, pos))
55962+ return NULL;
55963+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55964 return NULL;
55965
55966 if (write) {
55967@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55968 if (size <= ARG_MAX)
55969 return page;
55970
55971+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55972+ // only allow 512KB for argv+env on suid/sgid binaries
55973+ // to prevent easy ASLR exhaustion
55974+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55975+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55976+ (size > (512 * 1024))) {
55977+ put_page(page);
55978+ return NULL;
55979+ }
55980+#endif
55981+
55982 /*
55983 * Limit to 1/4-th the stack size for the argv+env strings.
55984 * This ensures that:
55985@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55986 vma->vm_end = STACK_TOP_MAX;
55987 vma->vm_start = vma->vm_end - PAGE_SIZE;
55988 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55989+
55990+#ifdef CONFIG_PAX_SEGMEXEC
55991+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55992+#endif
55993+
55994 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55995 INIT_LIST_HEAD(&vma->anon_vma_chain);
55996
55997@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55998 mm->stack_vm = mm->total_vm = 1;
55999 up_write(&mm->mmap_sem);
56000 bprm->p = vma->vm_end - sizeof(void *);
56001+
56002+#ifdef CONFIG_PAX_RANDUSTACK
56003+ if (randomize_va_space)
56004+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
56005+#endif
56006+
56007 return 0;
56008 err:
56009 up_write(&mm->mmap_sem);
56010@@ -399,7 +440,7 @@ struct user_arg_ptr {
56011 } ptr;
56012 };
56013
56014-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
56015+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
56016 {
56017 const char __user *native;
56018
56019@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
56020 compat_uptr_t compat;
56021
56022 if (get_user(compat, argv.ptr.compat + nr))
56023- return ERR_PTR(-EFAULT);
56024+ return (const char __force_user *)ERR_PTR(-EFAULT);
56025
56026 return compat_ptr(compat);
56027 }
56028 #endif
56029
56030 if (get_user(native, argv.ptr.native + nr))
56031- return ERR_PTR(-EFAULT);
56032+ return (const char __force_user *)ERR_PTR(-EFAULT);
56033
56034 return native;
56035 }
56036@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
56037 if (!p)
56038 break;
56039
56040- if (IS_ERR(p))
56041+ if (IS_ERR((const char __force_kernel *)p))
56042 return -EFAULT;
56043
56044 if (i >= max)
56045@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
56046
56047 ret = -EFAULT;
56048 str = get_user_arg_ptr(argv, argc);
56049- if (IS_ERR(str))
56050+ if (IS_ERR((const char __force_kernel *)str))
56051 goto out;
56052
56053 len = strnlen_user(str, MAX_ARG_STRLEN);
56054@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
56055 int r;
56056 mm_segment_t oldfs = get_fs();
56057 struct user_arg_ptr argv = {
56058- .ptr.native = (const char __user *const __user *)__argv,
56059+ .ptr.native = (const char __force_user * const __force_user *)__argv,
56060 };
56061
56062 set_fs(KERNEL_DS);
56063@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
56064 unsigned long new_end = old_end - shift;
56065 struct mmu_gather tlb;
56066
56067- BUG_ON(new_start > new_end);
56068+ if (new_start >= new_end || new_start < mmap_min_addr)
56069+ return -ENOMEM;
56070
56071 /*
56072 * ensure there are no vmas between where we want to go
56073@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
56074 if (vma != find_vma(mm, new_start))
56075 return -EFAULT;
56076
56077+#ifdef CONFIG_PAX_SEGMEXEC
56078+ BUG_ON(pax_find_mirror_vma(vma));
56079+#endif
56080+
56081 /*
56082 * cover the whole range: [new_start, old_end)
56083 */
56084@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
56085 stack_top = arch_align_stack(stack_top);
56086 stack_top = PAGE_ALIGN(stack_top);
56087
56088- if (unlikely(stack_top < mmap_min_addr) ||
56089- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
56090- return -ENOMEM;
56091-
56092 stack_shift = vma->vm_end - stack_top;
56093
56094 bprm->p -= stack_shift;
56095@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
56096 bprm->exec -= stack_shift;
56097
56098 down_write(&mm->mmap_sem);
56099+
56100+ /* Move stack pages down in memory. */
56101+ if (stack_shift) {
56102+ ret = shift_arg_pages(vma, stack_shift);
56103+ if (ret)
56104+ goto out_unlock;
56105+ }
56106+
56107 vm_flags = VM_STACK_FLAGS;
56108
56109+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56110+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56111+ vm_flags &= ~VM_EXEC;
56112+
56113+#ifdef CONFIG_PAX_MPROTECT
56114+ if (mm->pax_flags & MF_PAX_MPROTECT)
56115+ vm_flags &= ~VM_MAYEXEC;
56116+#endif
56117+
56118+ }
56119+#endif
56120+
56121 /*
56122 * Adjust stack execute permissions; explicitly enable for
56123 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
56124@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
56125 goto out_unlock;
56126 BUG_ON(prev != vma);
56127
56128- /* Move stack pages down in memory. */
56129- if (stack_shift) {
56130- ret = shift_arg_pages(vma, stack_shift);
56131- if (ret)
56132- goto out_unlock;
56133- }
56134-
56135 /* mprotect_fixup is overkill to remove the temporary stack flags */
56136 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
56137
56138@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
56139 #endif
56140 current->mm->start_stack = bprm->p;
56141 ret = expand_stack(vma, stack_base);
56142+
56143+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
56144+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
56145+ unsigned long size;
56146+ vm_flags_t vm_flags;
56147+
56148+ size = STACK_TOP - vma->vm_end;
56149+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
56150+
56151+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
56152+
56153+#ifdef CONFIG_X86
56154+ if (!ret) {
56155+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
56156+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
56157+ }
56158+#endif
56159+
56160+ }
56161+#endif
56162+
56163 if (ret)
56164 ret = -EFAULT;
56165
56166@@ -776,6 +852,8 @@ struct file *open_exec(const char *name)
56167
56168 fsnotify_open(file);
56169
56170+ trace_open_exec(name);
56171+
56172 err = deny_write_access(file);
56173 if (err)
56174 goto exit;
56175@@ -799,7 +877,7 @@ int kernel_read(struct file *file, loff_t offset,
56176 old_fs = get_fs();
56177 set_fs(get_ds());
56178 /* The cast to a user pointer is valid due to the set_fs() */
56179- result = vfs_read(file, (void __user *)addr, count, &pos);
56180+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
56181 set_fs(old_fs);
56182 return result;
56183 }
56184@@ -1255,7 +1333,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
56185 }
56186 rcu_read_unlock();
56187
56188- if (p->fs->users > n_fs) {
56189+ if (atomic_read(&p->fs->users) > n_fs) {
56190 bprm->unsafe |= LSM_UNSAFE_SHARE;
56191 } else {
56192 res = -EAGAIN;
56193@@ -1451,6 +1529,31 @@ static int exec_binprm(struct linux_binprm *bprm)
56194 return ret;
56195 }
56196
56197+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56198+static DEFINE_PER_CPU(u64, exec_counter);
56199+static int __init init_exec_counters(void)
56200+{
56201+ unsigned int cpu;
56202+
56203+ for_each_possible_cpu(cpu) {
56204+ per_cpu(exec_counter, cpu) = (u64)cpu;
56205+ }
56206+
56207+ return 0;
56208+}
56209+early_initcall(init_exec_counters);
56210+static inline void increment_exec_counter(void)
56211+{
56212+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
56213+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
56214+}
56215+#else
56216+static inline void increment_exec_counter(void) {}
56217+#endif
56218+
56219+extern void gr_handle_exec_args(struct linux_binprm *bprm,
56220+ struct user_arg_ptr argv);
56221+
56222 /*
56223 * sys_execve() executes a new program.
56224 */
56225@@ -1458,12 +1561,19 @@ static int do_execve_common(const char *filename,
56226 struct user_arg_ptr argv,
56227 struct user_arg_ptr envp)
56228 {
56229+#ifdef CONFIG_GRKERNSEC
56230+ struct file *old_exec_file;
56231+ struct acl_subject_label *old_acl;
56232+ struct rlimit old_rlim[RLIM_NLIMITS];
56233+#endif
56234 struct linux_binprm *bprm;
56235 struct file *file;
56236 struct files_struct *displaced;
56237 bool clear_in_exec;
56238 int retval;
56239
56240+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
56241+
56242 /*
56243 * We move the actual failure in case of RLIMIT_NPROC excess from
56244 * set*uid() to execve() because too many poorly written programs
56245@@ -1504,12 +1614,22 @@ static int do_execve_common(const char *filename,
56246 if (IS_ERR(file))
56247 goto out_unmark;
56248
56249+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
56250+ retval = -EPERM;
56251+ goto out_file;
56252+ }
56253+
56254 sched_exec();
56255
56256 bprm->file = file;
56257 bprm->filename = filename;
56258 bprm->interp = filename;
56259
56260+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
56261+ retval = -EACCES;
56262+ goto out_file;
56263+ }
56264+
56265 retval = bprm_mm_init(bprm);
56266 if (retval)
56267 goto out_file;
56268@@ -1526,24 +1646,70 @@ static int do_execve_common(const char *filename,
56269 if (retval < 0)
56270 goto out;
56271
56272+#ifdef CONFIG_GRKERNSEC
56273+ old_acl = current->acl;
56274+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
56275+ old_exec_file = current->exec_file;
56276+ get_file(file);
56277+ current->exec_file = file;
56278+#endif
56279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56280+ /* limit suid stack to 8MB
56281+ * we saved the old limits above and will restore them if this exec fails
56282+ */
56283+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
56284+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
56285+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
56286+#endif
56287+
56288+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
56289+ retval = -EPERM;
56290+ goto out_fail;
56291+ }
56292+
56293+ if (!gr_tpe_allow(file)) {
56294+ retval = -EACCES;
56295+ goto out_fail;
56296+ }
56297+
56298+ if (gr_check_crash_exec(file)) {
56299+ retval = -EACCES;
56300+ goto out_fail;
56301+ }
56302+
56303+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
56304+ bprm->unsafe);
56305+ if (retval < 0)
56306+ goto out_fail;
56307+
56308 retval = copy_strings_kernel(1, &bprm->filename, bprm);
56309 if (retval < 0)
56310- goto out;
56311+ goto out_fail;
56312
56313 bprm->exec = bprm->p;
56314 retval = copy_strings(bprm->envc, envp, bprm);
56315 if (retval < 0)
56316- goto out;
56317+ goto out_fail;
56318
56319 retval = copy_strings(bprm->argc, argv, bprm);
56320 if (retval < 0)
56321- goto out;
56322+ goto out_fail;
56323+
56324+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
56325+
56326+ gr_handle_exec_args(bprm, argv);
56327
56328 retval = exec_binprm(bprm);
56329 if (retval < 0)
56330- goto out;
56331+ goto out_fail;
56332+#ifdef CONFIG_GRKERNSEC
56333+ if (old_exec_file)
56334+ fput(old_exec_file);
56335+#endif
56336
56337 /* execve succeeded */
56338+
56339+ increment_exec_counter();
56340 current->fs->in_exec = 0;
56341 current->in_execve = 0;
56342 acct_update_integrals(current);
56343@@ -1552,6 +1718,14 @@ static int do_execve_common(const char *filename,
56344 put_files_struct(displaced);
56345 return retval;
56346
56347+out_fail:
56348+#ifdef CONFIG_GRKERNSEC
56349+ current->acl = old_acl;
56350+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
56351+ fput(current->exec_file);
56352+ current->exec_file = old_exec_file;
56353+#endif
56354+
56355 out:
56356 if (bprm->mm) {
56357 acct_arg_size(bprm, 0);
56358@@ -1706,3 +1880,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
56359 return error;
56360 }
56361 #endif
56362+
56363+int pax_check_flags(unsigned long *flags)
56364+{
56365+ int retval = 0;
56366+
56367+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
56368+ if (*flags & MF_PAX_SEGMEXEC)
56369+ {
56370+ *flags &= ~MF_PAX_SEGMEXEC;
56371+ retval = -EINVAL;
56372+ }
56373+#endif
56374+
56375+ if ((*flags & MF_PAX_PAGEEXEC)
56376+
56377+#ifdef CONFIG_PAX_PAGEEXEC
56378+ && (*flags & MF_PAX_SEGMEXEC)
56379+#endif
56380+
56381+ )
56382+ {
56383+ *flags &= ~MF_PAX_PAGEEXEC;
56384+ retval = -EINVAL;
56385+ }
56386+
56387+ if ((*flags & MF_PAX_MPROTECT)
56388+
56389+#ifdef CONFIG_PAX_MPROTECT
56390+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56391+#endif
56392+
56393+ )
56394+ {
56395+ *flags &= ~MF_PAX_MPROTECT;
56396+ retval = -EINVAL;
56397+ }
56398+
56399+ if ((*flags & MF_PAX_EMUTRAMP)
56400+
56401+#ifdef CONFIG_PAX_EMUTRAMP
56402+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56403+#endif
56404+
56405+ )
56406+ {
56407+ *flags &= ~MF_PAX_EMUTRAMP;
56408+ retval = -EINVAL;
56409+ }
56410+
56411+ return retval;
56412+}
56413+
56414+EXPORT_SYMBOL(pax_check_flags);
56415+
56416+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56417+char *pax_get_path(const struct path *path, char *buf, int buflen)
56418+{
56419+ char *pathname = d_path(path, buf, buflen);
56420+
56421+ if (IS_ERR(pathname))
56422+ goto toolong;
56423+
56424+ pathname = mangle_path(buf, pathname, "\t\n\\");
56425+ if (!pathname)
56426+ goto toolong;
56427+
56428+ *pathname = 0;
56429+ return buf;
56430+
56431+toolong:
56432+ return "<path too long>";
56433+}
56434+EXPORT_SYMBOL(pax_get_path);
56435+
56436+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
56437+{
56438+ struct task_struct *tsk = current;
56439+ struct mm_struct *mm = current->mm;
56440+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
56441+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
56442+ char *path_exec = NULL;
56443+ char *path_fault = NULL;
56444+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
56445+ siginfo_t info = { };
56446+
56447+ if (buffer_exec && buffer_fault) {
56448+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
56449+
56450+ down_read(&mm->mmap_sem);
56451+ vma = mm->mmap;
56452+ while (vma && (!vma_exec || !vma_fault)) {
56453+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
56454+ vma_exec = vma;
56455+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
56456+ vma_fault = vma;
56457+ vma = vma->vm_next;
56458+ }
56459+ if (vma_exec)
56460+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
56461+ if (vma_fault) {
56462+ start = vma_fault->vm_start;
56463+ end = vma_fault->vm_end;
56464+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
56465+ if (vma_fault->vm_file)
56466+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
56467+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
56468+ path_fault = "<heap>";
56469+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
56470+ path_fault = "<stack>";
56471+ else
56472+ path_fault = "<anonymous mapping>";
56473+ }
56474+ up_read(&mm->mmap_sem);
56475+ }
56476+ if (tsk->signal->curr_ip)
56477+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
56478+ else
56479+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
56480+ 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),
56481+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
56482+ free_page((unsigned long)buffer_exec);
56483+ free_page((unsigned long)buffer_fault);
56484+ pax_report_insns(regs, pc, sp);
56485+ info.si_signo = SIGKILL;
56486+ info.si_errno = 0;
56487+ info.si_code = SI_KERNEL;
56488+ info.si_pid = 0;
56489+ info.si_uid = 0;
56490+ do_coredump(&info);
56491+}
56492+#endif
56493+
56494+#ifdef CONFIG_PAX_REFCOUNT
56495+void pax_report_refcount_overflow(struct pt_regs *regs)
56496+{
56497+ if (current->signal->curr_ip)
56498+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
56499+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
56500+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56501+ else
56502+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
56503+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56504+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
56505+ preempt_disable();
56506+ show_regs(regs);
56507+ preempt_enable();
56508+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
56509+}
56510+#endif
56511+
56512+#ifdef CONFIG_PAX_USERCOPY
56513+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
56514+static noinline int check_stack_object(const void *obj, unsigned long len)
56515+{
56516+ const void * const stack = task_stack_page(current);
56517+ const void * const stackend = stack + THREAD_SIZE;
56518+
56519+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56520+ const void *frame = NULL;
56521+ const void *oldframe;
56522+#endif
56523+
56524+ if (obj + len < obj)
56525+ return -1;
56526+
56527+ if (obj + len <= stack || stackend <= obj)
56528+ return 0;
56529+
56530+ if (obj < stack || stackend < obj + len)
56531+ return -1;
56532+
56533+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56534+ oldframe = __builtin_frame_address(1);
56535+ if (oldframe)
56536+ frame = __builtin_frame_address(2);
56537+ /*
56538+ low ----------------------------------------------> high
56539+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
56540+ ^----------------^
56541+ allow copies only within here
56542+ */
56543+ while (stack <= frame && frame < stackend) {
56544+ /* if obj + len extends past the last frame, this
56545+ check won't pass and the next frame will be 0,
56546+ causing us to bail out and correctly report
56547+ the copy as invalid
56548+ */
56549+ if (obj + len <= frame)
56550+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
56551+ oldframe = frame;
56552+ frame = *(const void * const *)frame;
56553+ }
56554+ return -1;
56555+#else
56556+ return 1;
56557+#endif
56558+}
56559+
56560+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
56561+{
56562+ if (current->signal->curr_ip)
56563+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56564+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56565+ else
56566+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56567+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56568+ dump_stack();
56569+ gr_handle_kernel_exploit();
56570+ do_group_exit(SIGKILL);
56571+}
56572+#endif
56573+
56574+#ifdef CONFIG_PAX_USERCOPY
56575+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
56576+{
56577+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
56578+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
56579+#ifdef CONFIG_MODULES
56580+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
56581+#else
56582+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
56583+#endif
56584+
56585+#else
56586+ unsigned long textlow = (unsigned long)_stext;
56587+ unsigned long texthigh = (unsigned long)_etext;
56588+
56589+#ifdef CONFIG_X86_64
56590+ /* check against linear mapping as well */
56591+ if (high > (unsigned long)__va(__pa(textlow)) &&
56592+ low <= (unsigned long)__va(__pa(texthigh)))
56593+ return true;
56594+#endif
56595+
56596+#endif
56597+
56598+ if (high <= textlow || low > texthigh)
56599+ return false;
56600+ else
56601+ return true;
56602+}
56603+#endif
56604+
56605+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
56606+{
56607+
56608+#ifdef CONFIG_PAX_USERCOPY
56609+ const char *type;
56610+
56611+ if (!n)
56612+ return;
56613+
56614+ type = check_heap_object(ptr, n);
56615+ if (!type) {
56616+ int ret = check_stack_object(ptr, n);
56617+ if (ret == 1 || ret == 2)
56618+ return;
56619+ if (ret == 0) {
56620+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
56621+ type = "<kernel text>";
56622+ else
56623+ return;
56624+ } else
56625+ type = "<process stack>";
56626+ }
56627+
56628+ pax_report_usercopy(ptr, n, to_user, type);
56629+#endif
56630+
56631+}
56632+EXPORT_SYMBOL(__check_object_size);
56633+
56634+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56635+void pax_track_stack(void)
56636+{
56637+ unsigned long sp = (unsigned long)&sp;
56638+ if (sp < current_thread_info()->lowest_stack &&
56639+ sp > (unsigned long)task_stack_page(current))
56640+ current_thread_info()->lowest_stack = sp;
56641+}
56642+EXPORT_SYMBOL(pax_track_stack);
56643+#endif
56644+
56645+#ifdef CONFIG_PAX_SIZE_OVERFLOW
56646+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
56647+{
56648+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
56649+ dump_stack();
56650+ do_group_exit(SIGKILL);
56651+}
56652+EXPORT_SYMBOL(report_size_overflow);
56653+#endif
56654diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
56655index 9f9992b..8b59411 100644
56656--- a/fs/ext2/balloc.c
56657+++ b/fs/ext2/balloc.c
56658@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
56659
56660 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56661 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56662- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56663+ if (free_blocks < root_blocks + 1 &&
56664 !uid_eq(sbi->s_resuid, current_fsuid()) &&
56665 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56666- !in_group_p (sbi->s_resgid))) {
56667+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56668 return 0;
56669 }
56670 return 1;
56671diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
56672index 2d7557d..14e38f94 100644
56673--- a/fs/ext2/xattr.c
56674+++ b/fs/ext2/xattr.c
56675@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
56676 struct buffer_head *bh = NULL;
56677 struct ext2_xattr_entry *entry;
56678 char *end;
56679- size_t rest = buffer_size;
56680+ size_t rest = buffer_size, total_size = 0;
56681 int error;
56682
56683 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
56684@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
56685 buffer += size;
56686 }
56687 rest -= size;
56688+ total_size += size;
56689 }
56690 }
56691- error = buffer_size - rest; /* total size */
56692+ error = total_size;
56693
56694 cleanup:
56695 brelse(bh);
56696diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
56697index 22548f5..41521d8 100644
56698--- a/fs/ext3/balloc.c
56699+++ b/fs/ext3/balloc.c
56700@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
56701
56702 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56703 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56704- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56705+ if (free_blocks < root_blocks + 1 &&
56706 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
56707 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56708- !in_group_p (sbi->s_resgid))) {
56709+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56710 return 0;
56711 }
56712 return 1;
56713diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
56714index b1fc963..881228c 100644
56715--- a/fs/ext3/xattr.c
56716+++ b/fs/ext3/xattr.c
56717@@ -330,7 +330,7 @@ static int
56718 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
56719 char *buffer, size_t buffer_size)
56720 {
56721- size_t rest = buffer_size;
56722+ size_t rest = buffer_size, total_size = 0;
56723
56724 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
56725 const struct xattr_handler *handler =
56726@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
56727 buffer += size;
56728 }
56729 rest -= size;
56730+ total_size += size;
56731 }
56732 }
56733- return buffer_size - rest;
56734+ return total_size;
56735 }
56736
56737 static int
56738diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
56739index dc5d572..4c21f8e 100644
56740--- a/fs/ext4/balloc.c
56741+++ b/fs/ext4/balloc.c
56742@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
56743 /* Hm, nope. Are (enough) root reserved clusters available? */
56744 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
56745 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
56746- capable(CAP_SYS_RESOURCE) ||
56747- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
56748+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
56749+ capable_nolog(CAP_SYS_RESOURCE)) {
56750
56751 if (free_clusters >= (nclusters + dirty_clusters +
56752 resv_clusters))
56753diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
56754index af815ea..99294a6 100644
56755--- a/fs/ext4/ext4.h
56756+++ b/fs/ext4/ext4.h
56757@@ -1256,19 +1256,19 @@ struct ext4_sb_info {
56758 unsigned long s_mb_last_start;
56759
56760 /* stats for buddy allocator */
56761- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
56762- atomic_t s_bal_success; /* we found long enough chunks */
56763- atomic_t s_bal_allocated; /* in blocks */
56764- atomic_t s_bal_ex_scanned; /* total extents scanned */
56765- atomic_t s_bal_goals; /* goal hits */
56766- atomic_t s_bal_breaks; /* too long searches */
56767- atomic_t s_bal_2orders; /* 2^order hits */
56768+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
56769+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
56770+ atomic_unchecked_t s_bal_allocated; /* in blocks */
56771+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
56772+ atomic_unchecked_t s_bal_goals; /* goal hits */
56773+ atomic_unchecked_t s_bal_breaks; /* too long searches */
56774+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
56775 spinlock_t s_bal_lock;
56776 unsigned long s_mb_buddies_generated;
56777 unsigned long long s_mb_generation_time;
56778- atomic_t s_mb_lost_chunks;
56779- atomic_t s_mb_preallocated;
56780- atomic_t s_mb_discarded;
56781+ atomic_unchecked_t s_mb_lost_chunks;
56782+ atomic_unchecked_t s_mb_preallocated;
56783+ atomic_unchecked_t s_mb_discarded;
56784 atomic_t s_lock_busy;
56785
56786 /* locality groups */
56787diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
56788index a41e3ba..e574a00 100644
56789--- a/fs/ext4/mballoc.c
56790+++ b/fs/ext4/mballoc.c
56791@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
56792 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
56793
56794 if (EXT4_SB(sb)->s_mb_stats)
56795- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
56796+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
56797
56798 break;
56799 }
56800@@ -2189,7 +2189,7 @@ repeat:
56801 ac->ac_status = AC_STATUS_CONTINUE;
56802 ac->ac_flags |= EXT4_MB_HINT_FIRST;
56803 cr = 3;
56804- atomic_inc(&sbi->s_mb_lost_chunks);
56805+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
56806 goto repeat;
56807 }
56808 }
56809@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
56810 if (sbi->s_mb_stats) {
56811 ext4_msg(sb, KERN_INFO,
56812 "mballoc: %u blocks %u reqs (%u success)",
56813- atomic_read(&sbi->s_bal_allocated),
56814- atomic_read(&sbi->s_bal_reqs),
56815- atomic_read(&sbi->s_bal_success));
56816+ atomic_read_unchecked(&sbi->s_bal_allocated),
56817+ atomic_read_unchecked(&sbi->s_bal_reqs),
56818+ atomic_read_unchecked(&sbi->s_bal_success));
56819 ext4_msg(sb, KERN_INFO,
56820 "mballoc: %u extents scanned, %u goal hits, "
56821 "%u 2^N hits, %u breaks, %u lost",
56822- atomic_read(&sbi->s_bal_ex_scanned),
56823- atomic_read(&sbi->s_bal_goals),
56824- atomic_read(&sbi->s_bal_2orders),
56825- atomic_read(&sbi->s_bal_breaks),
56826- atomic_read(&sbi->s_mb_lost_chunks));
56827+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
56828+ atomic_read_unchecked(&sbi->s_bal_goals),
56829+ atomic_read_unchecked(&sbi->s_bal_2orders),
56830+ atomic_read_unchecked(&sbi->s_bal_breaks),
56831+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
56832 ext4_msg(sb, KERN_INFO,
56833 "mballoc: %lu generated and it took %Lu",
56834 sbi->s_mb_buddies_generated,
56835 sbi->s_mb_generation_time);
56836 ext4_msg(sb, KERN_INFO,
56837 "mballoc: %u preallocated, %u discarded",
56838- atomic_read(&sbi->s_mb_preallocated),
56839- atomic_read(&sbi->s_mb_discarded));
56840+ atomic_read_unchecked(&sbi->s_mb_preallocated),
56841+ atomic_read_unchecked(&sbi->s_mb_discarded));
56842 }
56843
56844 free_percpu(sbi->s_locality_groups);
56845@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
56846 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
56847
56848 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
56849- atomic_inc(&sbi->s_bal_reqs);
56850- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56851+ atomic_inc_unchecked(&sbi->s_bal_reqs);
56852+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56853 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56854- atomic_inc(&sbi->s_bal_success);
56855- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56856+ atomic_inc_unchecked(&sbi->s_bal_success);
56857+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56858 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56859 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56860- atomic_inc(&sbi->s_bal_goals);
56861+ atomic_inc_unchecked(&sbi->s_bal_goals);
56862 if (ac->ac_found > sbi->s_mb_max_to_scan)
56863- atomic_inc(&sbi->s_bal_breaks);
56864+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56865 }
56866
56867 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56868@@ -3578,7 +3578,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56869 trace_ext4_mb_new_inode_pa(ac, pa);
56870
56871 ext4_mb_use_inode_pa(ac, pa);
56872- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56873+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56874
56875 ei = EXT4_I(ac->ac_inode);
56876 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56877@@ -3638,7 +3638,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56878 trace_ext4_mb_new_group_pa(ac, pa);
56879
56880 ext4_mb_use_group_pa(ac, pa);
56881- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56882+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56883
56884 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56885 lg = ac->ac_lg;
56886@@ -3727,7 +3727,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56887 * from the bitmap and continue.
56888 */
56889 }
56890- atomic_add(free, &sbi->s_mb_discarded);
56891+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56892
56893 return err;
56894 }
56895@@ -3745,7 +3745,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56896 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56897 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56898 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56899- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56900+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56901 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56902
56903 return 0;
56904diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56905index 214461e..3614c89 100644
56906--- a/fs/ext4/mmp.c
56907+++ b/fs/ext4/mmp.c
56908@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56909 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56910 const char *function, unsigned int line, const char *msg)
56911 {
56912- __ext4_warning(sb, function, line, msg);
56913+ __ext4_warning(sb, function, line, "%s", msg);
56914 __ext4_warning(sb, function, line,
56915 "MMP failure info: last update time: %llu, last update "
56916 "node: %s, last update device: %s\n",
56917diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56918index 2c2e6cb..7c3ee62 100644
56919--- a/fs/ext4/super.c
56920+++ b/fs/ext4/super.c
56921@@ -1251,7 +1251,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56922 }
56923
56924 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56925-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56926+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56927 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56928
56929 #ifdef CONFIG_QUOTA
56930@@ -2431,7 +2431,7 @@ struct ext4_attr {
56931 int offset;
56932 int deprecated_val;
56933 } u;
56934-};
56935+} __do_const;
56936
56937 static int parse_strtoull(const char *buf,
56938 unsigned long long max, unsigned long long *value)
56939diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
56940index 1423c48..9c0c6dc 100644
56941--- a/fs/ext4/xattr.c
56942+++ b/fs/ext4/xattr.c
56943@@ -381,7 +381,7 @@ static int
56944 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56945 char *buffer, size_t buffer_size)
56946 {
56947- size_t rest = buffer_size;
56948+ size_t rest = buffer_size, total_size = 0;
56949
56950 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
56951 const struct xattr_handler *handler =
56952@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56953 buffer += size;
56954 }
56955 rest -= size;
56956+ total_size += size;
56957 }
56958 }
56959- return buffer_size - rest;
56960+ return total_size;
56961 }
56962
56963 static int
56964diff --git a/fs/fcntl.c b/fs/fcntl.c
56965index 65343c3..9969dcf 100644
56966--- a/fs/fcntl.c
56967+++ b/fs/fcntl.c
56968@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56969 if (err)
56970 return err;
56971
56972+ if (gr_handle_chroot_fowner(pid, type))
56973+ return -ENOENT;
56974+ if (gr_check_protected_task_fowner(pid, type))
56975+ return -EACCES;
56976+
56977 f_modown(filp, pid, type, force);
56978 return 0;
56979 }
56980diff --git a/fs/fhandle.c b/fs/fhandle.c
56981index 999ff5c..41f4109 100644
56982--- a/fs/fhandle.c
56983+++ b/fs/fhandle.c
56984@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56985 } else
56986 retval = 0;
56987 /* copy the mount id */
56988- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56989- sizeof(*mnt_id)) ||
56990+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56991 copy_to_user(ufh, handle,
56992 sizeof(struct file_handle) + handle_bytes))
56993 retval = -EFAULT;
56994diff --git a/fs/file.c b/fs/file.c
56995index 4a78f98..9447397 100644
56996--- a/fs/file.c
56997+++ b/fs/file.c
56998@@ -16,6 +16,7 @@
56999 #include <linux/slab.h>
57000 #include <linux/vmalloc.h>
57001 #include <linux/file.h>
57002+#include <linux/security.h>
57003 #include <linux/fdtable.h>
57004 #include <linux/bitops.h>
57005 #include <linux/interrupt.h>
57006@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
57007 if (!file)
57008 return __close_fd(files, fd);
57009
57010+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
57011 if (fd >= rlimit(RLIMIT_NOFILE))
57012 return -EBADF;
57013
57014@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
57015 if (unlikely(oldfd == newfd))
57016 return -EINVAL;
57017
57018+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
57019 if (newfd >= rlimit(RLIMIT_NOFILE))
57020 return -EBADF;
57021
57022@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
57023 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
57024 {
57025 int err;
57026+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
57027 if (from >= rlimit(RLIMIT_NOFILE))
57028 return -EINVAL;
57029 err = alloc_fd(from, flags);
57030diff --git a/fs/filesystems.c b/fs/filesystems.c
57031index 92567d9..fcd8cbf 100644
57032--- a/fs/filesystems.c
57033+++ b/fs/filesystems.c
57034@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
57035 int len = dot ? dot - name : strlen(name);
57036
57037 fs = __get_fs_type(name, len);
57038+#ifdef CONFIG_GRKERNSEC_MODHARDEN
57039+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
57040+#else
57041 if (!fs && (request_module("fs-%.*s", len, name) == 0))
57042+#endif
57043 fs = __get_fs_type(name, len);
57044
57045 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
57046diff --git a/fs/fs_struct.c b/fs/fs_struct.c
57047index d8ac61d..79a36f0 100644
57048--- a/fs/fs_struct.c
57049+++ b/fs/fs_struct.c
57050@@ -4,6 +4,7 @@
57051 #include <linux/path.h>
57052 #include <linux/slab.h>
57053 #include <linux/fs_struct.h>
57054+#include <linux/grsecurity.h>
57055 #include "internal.h"
57056
57057 /*
57058@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
57059 write_seqcount_begin(&fs->seq);
57060 old_root = fs->root;
57061 fs->root = *path;
57062+ gr_set_chroot_entries(current, path);
57063 write_seqcount_end(&fs->seq);
57064 spin_unlock(&fs->lock);
57065 if (old_root.dentry)
57066@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
57067 int hits = 0;
57068 spin_lock(&fs->lock);
57069 write_seqcount_begin(&fs->seq);
57070+ /* this root replacement is only done by pivot_root,
57071+ leave grsec's chroot tagging alone for this task
57072+ so that a pivoted root isn't treated as a chroot
57073+ */
57074 hits += replace_path(&fs->root, old_root, new_root);
57075 hits += replace_path(&fs->pwd, old_root, new_root);
57076 write_seqcount_end(&fs->seq);
57077@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
57078 task_lock(tsk);
57079 spin_lock(&fs->lock);
57080 tsk->fs = NULL;
57081- kill = !--fs->users;
57082+ gr_clear_chroot_entries(tsk);
57083+ kill = !atomic_dec_return(&fs->users);
57084 spin_unlock(&fs->lock);
57085 task_unlock(tsk);
57086 if (kill)
57087@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
57088 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
57089 /* We don't need to lock fs - think why ;-) */
57090 if (fs) {
57091- fs->users = 1;
57092+ atomic_set(&fs->users, 1);
57093 fs->in_exec = 0;
57094 spin_lock_init(&fs->lock);
57095 seqcount_init(&fs->seq);
57096@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
57097 spin_lock(&old->lock);
57098 fs->root = old->root;
57099 path_get(&fs->root);
57100+ /* instead of calling gr_set_chroot_entries here,
57101+ we call it from every caller of this function
57102+ */
57103 fs->pwd = old->pwd;
57104 path_get(&fs->pwd);
57105 spin_unlock(&old->lock);
57106@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
57107
57108 task_lock(current);
57109 spin_lock(&fs->lock);
57110- kill = !--fs->users;
57111+ kill = !atomic_dec_return(&fs->users);
57112 current->fs = new_fs;
57113+ gr_set_chroot_entries(current, &new_fs->root);
57114 spin_unlock(&fs->lock);
57115 task_unlock(current);
57116
57117@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
57118
57119 int current_umask(void)
57120 {
57121- return current->fs->umask;
57122+ return current->fs->umask | gr_acl_umask();
57123 }
57124 EXPORT_SYMBOL(current_umask);
57125
57126 /* to be mentioned only in INIT_TASK */
57127 struct fs_struct init_fs = {
57128- .users = 1,
57129+ .users = ATOMIC_INIT(1),
57130 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
57131 .seq = SEQCNT_ZERO,
57132 .umask = 0022,
57133diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
57134index b2a86e3..37f425a 100644
57135--- a/fs/fscache/cookie.c
57136+++ b/fs/fscache/cookie.c
57137@@ -19,7 +19,7 @@
57138
57139 struct kmem_cache *fscache_cookie_jar;
57140
57141-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
57142+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
57143
57144 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
57145 static int fscache_alloc_object(struct fscache_cache *cache,
57146@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
57147 parent ? (char *) parent->def->name : "<no-parent>",
57148 def->name, netfs_data);
57149
57150- fscache_stat(&fscache_n_acquires);
57151+ fscache_stat_unchecked(&fscache_n_acquires);
57152
57153 /* if there's no parent cookie, then we don't create one here either */
57154 if (!parent) {
57155- fscache_stat(&fscache_n_acquires_null);
57156+ fscache_stat_unchecked(&fscache_n_acquires_null);
57157 _leave(" [no parent]");
57158 return NULL;
57159 }
57160@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
57161 /* allocate and initialise a cookie */
57162 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
57163 if (!cookie) {
57164- fscache_stat(&fscache_n_acquires_oom);
57165+ fscache_stat_unchecked(&fscache_n_acquires_oom);
57166 _leave(" [ENOMEM]");
57167 return NULL;
57168 }
57169@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
57170
57171 switch (cookie->def->type) {
57172 case FSCACHE_COOKIE_TYPE_INDEX:
57173- fscache_stat(&fscache_n_cookie_index);
57174+ fscache_stat_unchecked(&fscache_n_cookie_index);
57175 break;
57176 case FSCACHE_COOKIE_TYPE_DATAFILE:
57177- fscache_stat(&fscache_n_cookie_data);
57178+ fscache_stat_unchecked(&fscache_n_cookie_data);
57179 break;
57180 default:
57181- fscache_stat(&fscache_n_cookie_special);
57182+ fscache_stat_unchecked(&fscache_n_cookie_special);
57183 break;
57184 }
57185
57186@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
57187 if (fscache_acquire_non_index_cookie(cookie) < 0) {
57188 atomic_dec(&parent->n_children);
57189 __fscache_cookie_put(cookie);
57190- fscache_stat(&fscache_n_acquires_nobufs);
57191+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
57192 _leave(" = NULL");
57193 return NULL;
57194 }
57195 }
57196
57197- fscache_stat(&fscache_n_acquires_ok);
57198+ fscache_stat_unchecked(&fscache_n_acquires_ok);
57199 _leave(" = %p", cookie);
57200 return cookie;
57201 }
57202@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
57203 cache = fscache_select_cache_for_object(cookie->parent);
57204 if (!cache) {
57205 up_read(&fscache_addremove_sem);
57206- fscache_stat(&fscache_n_acquires_no_cache);
57207+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
57208 _leave(" = -ENOMEDIUM [no cache]");
57209 return -ENOMEDIUM;
57210 }
57211@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
57212 object = cache->ops->alloc_object(cache, cookie);
57213 fscache_stat_d(&fscache_n_cop_alloc_object);
57214 if (IS_ERR(object)) {
57215- fscache_stat(&fscache_n_object_no_alloc);
57216+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
57217 ret = PTR_ERR(object);
57218 goto error;
57219 }
57220
57221- fscache_stat(&fscache_n_object_alloc);
57222+ fscache_stat_unchecked(&fscache_n_object_alloc);
57223
57224- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
57225+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
57226
57227 _debug("ALLOC OBJ%x: %s {%lx}",
57228 object->debug_id, cookie->def->name, object->events);
57229@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
57230
57231 _enter("{%s}", cookie->def->name);
57232
57233- fscache_stat(&fscache_n_invalidates);
57234+ fscache_stat_unchecked(&fscache_n_invalidates);
57235
57236 /* Only permit invalidation of data files. Invalidating an index will
57237 * require the caller to release all its attachments to the tree rooted
57238@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
57239 {
57240 struct fscache_object *object;
57241
57242- fscache_stat(&fscache_n_updates);
57243+ fscache_stat_unchecked(&fscache_n_updates);
57244
57245 if (!cookie) {
57246- fscache_stat(&fscache_n_updates_null);
57247+ fscache_stat_unchecked(&fscache_n_updates_null);
57248 _leave(" [no cookie]");
57249 return;
57250 }
57251@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
57252 {
57253 struct fscache_object *object;
57254
57255- fscache_stat(&fscache_n_relinquishes);
57256+ fscache_stat_unchecked(&fscache_n_relinquishes);
57257 if (retire)
57258- fscache_stat(&fscache_n_relinquishes_retire);
57259+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
57260
57261 if (!cookie) {
57262- fscache_stat(&fscache_n_relinquishes_null);
57263+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
57264 _leave(" [no cookie]");
57265 return;
57266 }
57267@@ -598,7 +598,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
57268 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
57269 goto inconsistent;
57270
57271- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
57272+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57273
57274 atomic_inc(&cookie->n_active);
57275 if (fscache_submit_op(object, op) < 0)
57276diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
57277index 4226f66..0fb3f45 100644
57278--- a/fs/fscache/internal.h
57279+++ b/fs/fscache/internal.h
57280@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
57281 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
57282 extern int fscache_wait_for_operation_activation(struct fscache_object *,
57283 struct fscache_operation *,
57284- atomic_t *,
57285- atomic_t *,
57286+ atomic_unchecked_t *,
57287+ atomic_unchecked_t *,
57288 void (*)(struct fscache_operation *));
57289 extern void fscache_invalidate_writes(struct fscache_cookie *);
57290
57291@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
57292 * stats.c
57293 */
57294 #ifdef CONFIG_FSCACHE_STATS
57295-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
57296-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
57297+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
57298+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
57299
57300-extern atomic_t fscache_n_op_pend;
57301-extern atomic_t fscache_n_op_run;
57302-extern atomic_t fscache_n_op_enqueue;
57303-extern atomic_t fscache_n_op_deferred_release;
57304-extern atomic_t fscache_n_op_release;
57305-extern atomic_t fscache_n_op_gc;
57306-extern atomic_t fscache_n_op_cancelled;
57307-extern atomic_t fscache_n_op_rejected;
57308+extern atomic_unchecked_t fscache_n_op_pend;
57309+extern atomic_unchecked_t fscache_n_op_run;
57310+extern atomic_unchecked_t fscache_n_op_enqueue;
57311+extern atomic_unchecked_t fscache_n_op_deferred_release;
57312+extern atomic_unchecked_t fscache_n_op_release;
57313+extern atomic_unchecked_t fscache_n_op_gc;
57314+extern atomic_unchecked_t fscache_n_op_cancelled;
57315+extern atomic_unchecked_t fscache_n_op_rejected;
57316
57317-extern atomic_t fscache_n_attr_changed;
57318-extern atomic_t fscache_n_attr_changed_ok;
57319-extern atomic_t fscache_n_attr_changed_nobufs;
57320-extern atomic_t fscache_n_attr_changed_nomem;
57321-extern atomic_t fscache_n_attr_changed_calls;
57322+extern atomic_unchecked_t fscache_n_attr_changed;
57323+extern atomic_unchecked_t fscache_n_attr_changed_ok;
57324+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
57325+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
57326+extern atomic_unchecked_t fscache_n_attr_changed_calls;
57327
57328-extern atomic_t fscache_n_allocs;
57329-extern atomic_t fscache_n_allocs_ok;
57330-extern atomic_t fscache_n_allocs_wait;
57331-extern atomic_t fscache_n_allocs_nobufs;
57332-extern atomic_t fscache_n_allocs_intr;
57333-extern atomic_t fscache_n_allocs_object_dead;
57334-extern atomic_t fscache_n_alloc_ops;
57335-extern atomic_t fscache_n_alloc_op_waits;
57336+extern atomic_unchecked_t fscache_n_allocs;
57337+extern atomic_unchecked_t fscache_n_allocs_ok;
57338+extern atomic_unchecked_t fscache_n_allocs_wait;
57339+extern atomic_unchecked_t fscache_n_allocs_nobufs;
57340+extern atomic_unchecked_t fscache_n_allocs_intr;
57341+extern atomic_unchecked_t fscache_n_allocs_object_dead;
57342+extern atomic_unchecked_t fscache_n_alloc_ops;
57343+extern atomic_unchecked_t fscache_n_alloc_op_waits;
57344
57345-extern atomic_t fscache_n_retrievals;
57346-extern atomic_t fscache_n_retrievals_ok;
57347-extern atomic_t fscache_n_retrievals_wait;
57348-extern atomic_t fscache_n_retrievals_nodata;
57349-extern atomic_t fscache_n_retrievals_nobufs;
57350-extern atomic_t fscache_n_retrievals_intr;
57351-extern atomic_t fscache_n_retrievals_nomem;
57352-extern atomic_t fscache_n_retrievals_object_dead;
57353-extern atomic_t fscache_n_retrieval_ops;
57354-extern atomic_t fscache_n_retrieval_op_waits;
57355+extern atomic_unchecked_t fscache_n_retrievals;
57356+extern atomic_unchecked_t fscache_n_retrievals_ok;
57357+extern atomic_unchecked_t fscache_n_retrievals_wait;
57358+extern atomic_unchecked_t fscache_n_retrievals_nodata;
57359+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
57360+extern atomic_unchecked_t fscache_n_retrievals_intr;
57361+extern atomic_unchecked_t fscache_n_retrievals_nomem;
57362+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
57363+extern atomic_unchecked_t fscache_n_retrieval_ops;
57364+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
57365
57366-extern atomic_t fscache_n_stores;
57367-extern atomic_t fscache_n_stores_ok;
57368-extern atomic_t fscache_n_stores_again;
57369-extern atomic_t fscache_n_stores_nobufs;
57370-extern atomic_t fscache_n_stores_oom;
57371-extern atomic_t fscache_n_store_ops;
57372-extern atomic_t fscache_n_store_calls;
57373-extern atomic_t fscache_n_store_pages;
57374-extern atomic_t fscache_n_store_radix_deletes;
57375-extern atomic_t fscache_n_store_pages_over_limit;
57376+extern atomic_unchecked_t fscache_n_stores;
57377+extern atomic_unchecked_t fscache_n_stores_ok;
57378+extern atomic_unchecked_t fscache_n_stores_again;
57379+extern atomic_unchecked_t fscache_n_stores_nobufs;
57380+extern atomic_unchecked_t fscache_n_stores_oom;
57381+extern atomic_unchecked_t fscache_n_store_ops;
57382+extern atomic_unchecked_t fscache_n_store_calls;
57383+extern atomic_unchecked_t fscache_n_store_pages;
57384+extern atomic_unchecked_t fscache_n_store_radix_deletes;
57385+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
57386
57387-extern atomic_t fscache_n_store_vmscan_not_storing;
57388-extern atomic_t fscache_n_store_vmscan_gone;
57389-extern atomic_t fscache_n_store_vmscan_busy;
57390-extern atomic_t fscache_n_store_vmscan_cancelled;
57391-extern atomic_t fscache_n_store_vmscan_wait;
57392+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57393+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
57394+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
57395+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57396+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
57397
57398-extern atomic_t fscache_n_marks;
57399-extern atomic_t fscache_n_uncaches;
57400+extern atomic_unchecked_t fscache_n_marks;
57401+extern atomic_unchecked_t fscache_n_uncaches;
57402
57403-extern atomic_t fscache_n_acquires;
57404-extern atomic_t fscache_n_acquires_null;
57405-extern atomic_t fscache_n_acquires_no_cache;
57406-extern atomic_t fscache_n_acquires_ok;
57407-extern atomic_t fscache_n_acquires_nobufs;
57408-extern atomic_t fscache_n_acquires_oom;
57409+extern atomic_unchecked_t fscache_n_acquires;
57410+extern atomic_unchecked_t fscache_n_acquires_null;
57411+extern atomic_unchecked_t fscache_n_acquires_no_cache;
57412+extern atomic_unchecked_t fscache_n_acquires_ok;
57413+extern atomic_unchecked_t fscache_n_acquires_nobufs;
57414+extern atomic_unchecked_t fscache_n_acquires_oom;
57415
57416-extern atomic_t fscache_n_invalidates;
57417-extern atomic_t fscache_n_invalidates_run;
57418+extern atomic_unchecked_t fscache_n_invalidates;
57419+extern atomic_unchecked_t fscache_n_invalidates_run;
57420
57421-extern atomic_t fscache_n_updates;
57422-extern atomic_t fscache_n_updates_null;
57423-extern atomic_t fscache_n_updates_run;
57424+extern atomic_unchecked_t fscache_n_updates;
57425+extern atomic_unchecked_t fscache_n_updates_null;
57426+extern atomic_unchecked_t fscache_n_updates_run;
57427
57428-extern atomic_t fscache_n_relinquishes;
57429-extern atomic_t fscache_n_relinquishes_null;
57430-extern atomic_t fscache_n_relinquishes_waitcrt;
57431-extern atomic_t fscache_n_relinquishes_retire;
57432+extern atomic_unchecked_t fscache_n_relinquishes;
57433+extern atomic_unchecked_t fscache_n_relinquishes_null;
57434+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57435+extern atomic_unchecked_t fscache_n_relinquishes_retire;
57436
57437-extern atomic_t fscache_n_cookie_index;
57438-extern atomic_t fscache_n_cookie_data;
57439-extern atomic_t fscache_n_cookie_special;
57440+extern atomic_unchecked_t fscache_n_cookie_index;
57441+extern atomic_unchecked_t fscache_n_cookie_data;
57442+extern atomic_unchecked_t fscache_n_cookie_special;
57443
57444-extern atomic_t fscache_n_object_alloc;
57445-extern atomic_t fscache_n_object_no_alloc;
57446-extern atomic_t fscache_n_object_lookups;
57447-extern atomic_t fscache_n_object_lookups_negative;
57448-extern atomic_t fscache_n_object_lookups_positive;
57449-extern atomic_t fscache_n_object_lookups_timed_out;
57450-extern atomic_t fscache_n_object_created;
57451-extern atomic_t fscache_n_object_avail;
57452-extern atomic_t fscache_n_object_dead;
57453+extern atomic_unchecked_t fscache_n_object_alloc;
57454+extern atomic_unchecked_t fscache_n_object_no_alloc;
57455+extern atomic_unchecked_t fscache_n_object_lookups;
57456+extern atomic_unchecked_t fscache_n_object_lookups_negative;
57457+extern atomic_unchecked_t fscache_n_object_lookups_positive;
57458+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
57459+extern atomic_unchecked_t fscache_n_object_created;
57460+extern atomic_unchecked_t fscache_n_object_avail;
57461+extern atomic_unchecked_t fscache_n_object_dead;
57462
57463-extern atomic_t fscache_n_checkaux_none;
57464-extern atomic_t fscache_n_checkaux_okay;
57465-extern atomic_t fscache_n_checkaux_update;
57466-extern atomic_t fscache_n_checkaux_obsolete;
57467+extern atomic_unchecked_t fscache_n_checkaux_none;
57468+extern atomic_unchecked_t fscache_n_checkaux_okay;
57469+extern atomic_unchecked_t fscache_n_checkaux_update;
57470+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
57471
57472 extern atomic_t fscache_n_cop_alloc_object;
57473 extern atomic_t fscache_n_cop_lookup_object;
57474@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
57475 atomic_inc(stat);
57476 }
57477
57478+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
57479+{
57480+ atomic_inc_unchecked(stat);
57481+}
57482+
57483 static inline void fscache_stat_d(atomic_t *stat)
57484 {
57485 atomic_dec(stat);
57486@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
57487
57488 #define __fscache_stat(stat) (NULL)
57489 #define fscache_stat(stat) do {} while (0)
57490+#define fscache_stat_unchecked(stat) do {} while (0)
57491 #define fscache_stat_d(stat) do {} while (0)
57492 #endif
57493
57494diff --git a/fs/fscache/object.c b/fs/fscache/object.c
57495index 86d75a6..5f3d7a0 100644
57496--- a/fs/fscache/object.c
57497+++ b/fs/fscache/object.c
57498@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
57499 _debug("LOOKUP \"%s\" in \"%s\"",
57500 cookie->def->name, object->cache->tag->name);
57501
57502- fscache_stat(&fscache_n_object_lookups);
57503+ fscache_stat_unchecked(&fscache_n_object_lookups);
57504 fscache_stat(&fscache_n_cop_lookup_object);
57505 ret = object->cache->ops->lookup_object(object);
57506 fscache_stat_d(&fscache_n_cop_lookup_object);
57507@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
57508 if (ret == -ETIMEDOUT) {
57509 /* probably stuck behind another object, so move this one to
57510 * the back of the queue */
57511- fscache_stat(&fscache_n_object_lookups_timed_out);
57512+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
57513 _leave(" [timeout]");
57514 return NO_TRANSIT;
57515 }
57516@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
57517 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
57518
57519 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
57520- fscache_stat(&fscache_n_object_lookups_negative);
57521+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
57522
57523 /* Allow write requests to begin stacking up and read requests to begin
57524 * returning ENODATA.
57525@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
57526 /* if we were still looking up, then we must have a positive lookup
57527 * result, in which case there may be data available */
57528 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
57529- fscache_stat(&fscache_n_object_lookups_positive);
57530+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
57531
57532 /* We do (presumably) have data */
57533 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
57534@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
57535 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
57536 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
57537 } else {
57538- fscache_stat(&fscache_n_object_created);
57539+ fscache_stat_unchecked(&fscache_n_object_created);
57540 }
57541
57542 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
57543@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
57544 fscache_stat_d(&fscache_n_cop_lookup_complete);
57545
57546 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
57547- fscache_stat(&fscache_n_object_avail);
57548+ fscache_stat_unchecked(&fscache_n_object_avail);
57549
57550 _leave("");
57551 return transit_to(JUMPSTART_DEPS);
57552@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
57553
57554 /* this just shifts the object release to the work processor */
57555 fscache_put_object(object);
57556- fscache_stat(&fscache_n_object_dead);
57557+ fscache_stat_unchecked(&fscache_n_object_dead);
57558
57559 _leave("");
57560 return transit_to(OBJECT_DEAD);
57561@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57562 enum fscache_checkaux result;
57563
57564 if (!object->cookie->def->check_aux) {
57565- fscache_stat(&fscache_n_checkaux_none);
57566+ fscache_stat_unchecked(&fscache_n_checkaux_none);
57567 return FSCACHE_CHECKAUX_OKAY;
57568 }
57569
57570@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57571 switch (result) {
57572 /* entry okay as is */
57573 case FSCACHE_CHECKAUX_OKAY:
57574- fscache_stat(&fscache_n_checkaux_okay);
57575+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
57576 break;
57577
57578 /* entry requires update */
57579 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
57580- fscache_stat(&fscache_n_checkaux_update);
57581+ fscache_stat_unchecked(&fscache_n_checkaux_update);
57582 break;
57583
57584 /* entry requires deletion */
57585 case FSCACHE_CHECKAUX_OBSOLETE:
57586- fscache_stat(&fscache_n_checkaux_obsolete);
57587+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
57588 break;
57589
57590 default:
57591@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
57592 {
57593 const struct fscache_state *s;
57594
57595- fscache_stat(&fscache_n_invalidates_run);
57596+ fscache_stat_unchecked(&fscache_n_invalidates_run);
57597 fscache_stat(&fscache_n_cop_invalidate_object);
57598 s = _fscache_invalidate_object(object, event);
57599 fscache_stat_d(&fscache_n_cop_invalidate_object);
57600@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
57601 {
57602 _enter("{OBJ%x},%d", object->debug_id, event);
57603
57604- fscache_stat(&fscache_n_updates_run);
57605+ fscache_stat_unchecked(&fscache_n_updates_run);
57606 fscache_stat(&fscache_n_cop_update_object);
57607 object->cache->ops->update_object(object);
57608 fscache_stat_d(&fscache_n_cop_update_object);
57609diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
57610index 318071a..379938b 100644
57611--- a/fs/fscache/operation.c
57612+++ b/fs/fscache/operation.c
57613@@ -17,7 +17,7 @@
57614 #include <linux/slab.h>
57615 #include "internal.h"
57616
57617-atomic_t fscache_op_debug_id;
57618+atomic_unchecked_t fscache_op_debug_id;
57619 EXPORT_SYMBOL(fscache_op_debug_id);
57620
57621 /**
57622@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
57623 ASSERTCMP(atomic_read(&op->usage), >, 0);
57624 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
57625
57626- fscache_stat(&fscache_n_op_enqueue);
57627+ fscache_stat_unchecked(&fscache_n_op_enqueue);
57628 switch (op->flags & FSCACHE_OP_TYPE) {
57629 case FSCACHE_OP_ASYNC:
57630 _debug("queue async");
57631@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
57632 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
57633 if (op->processor)
57634 fscache_enqueue_operation(op);
57635- fscache_stat(&fscache_n_op_run);
57636+ fscache_stat_unchecked(&fscache_n_op_run);
57637 }
57638
57639 /*
57640@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57641 if (object->n_in_progress > 0) {
57642 atomic_inc(&op->usage);
57643 list_add_tail(&op->pend_link, &object->pending_ops);
57644- fscache_stat(&fscache_n_op_pend);
57645+ fscache_stat_unchecked(&fscache_n_op_pend);
57646 } else if (!list_empty(&object->pending_ops)) {
57647 atomic_inc(&op->usage);
57648 list_add_tail(&op->pend_link, &object->pending_ops);
57649- fscache_stat(&fscache_n_op_pend);
57650+ fscache_stat_unchecked(&fscache_n_op_pend);
57651 fscache_start_operations(object);
57652 } else {
57653 ASSERTCMP(object->n_in_progress, ==, 0);
57654@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57655 object->n_exclusive++; /* reads and writes must wait */
57656 atomic_inc(&op->usage);
57657 list_add_tail(&op->pend_link, &object->pending_ops);
57658- fscache_stat(&fscache_n_op_pend);
57659+ fscache_stat_unchecked(&fscache_n_op_pend);
57660 ret = 0;
57661 } else {
57662 /* If we're in any other state, there must have been an I/O
57663@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
57664 if (object->n_exclusive > 0) {
57665 atomic_inc(&op->usage);
57666 list_add_tail(&op->pend_link, &object->pending_ops);
57667- fscache_stat(&fscache_n_op_pend);
57668+ fscache_stat_unchecked(&fscache_n_op_pend);
57669 } else if (!list_empty(&object->pending_ops)) {
57670 atomic_inc(&op->usage);
57671 list_add_tail(&op->pend_link, &object->pending_ops);
57672- fscache_stat(&fscache_n_op_pend);
57673+ fscache_stat_unchecked(&fscache_n_op_pend);
57674 fscache_start_operations(object);
57675 } else {
57676 ASSERTCMP(object->n_exclusive, ==, 0);
57677@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
57678 object->n_ops++;
57679 atomic_inc(&op->usage);
57680 list_add_tail(&op->pend_link, &object->pending_ops);
57681- fscache_stat(&fscache_n_op_pend);
57682+ fscache_stat_unchecked(&fscache_n_op_pend);
57683 ret = 0;
57684 } else if (fscache_object_is_dying(object)) {
57685- fscache_stat(&fscache_n_op_rejected);
57686+ fscache_stat_unchecked(&fscache_n_op_rejected);
57687 op->state = FSCACHE_OP_ST_CANCELLED;
57688 ret = -ENOBUFS;
57689 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
57690@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
57691 ret = -EBUSY;
57692 if (op->state == FSCACHE_OP_ST_PENDING) {
57693 ASSERT(!list_empty(&op->pend_link));
57694- fscache_stat(&fscache_n_op_cancelled);
57695+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57696 list_del_init(&op->pend_link);
57697 if (do_cancel)
57698 do_cancel(op);
57699@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
57700 while (!list_empty(&object->pending_ops)) {
57701 op = list_entry(object->pending_ops.next,
57702 struct fscache_operation, pend_link);
57703- fscache_stat(&fscache_n_op_cancelled);
57704+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57705 list_del_init(&op->pend_link);
57706
57707 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
57708@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
57709 op->state, ==, FSCACHE_OP_ST_CANCELLED);
57710 op->state = FSCACHE_OP_ST_DEAD;
57711
57712- fscache_stat(&fscache_n_op_release);
57713+ fscache_stat_unchecked(&fscache_n_op_release);
57714
57715 if (op->release) {
57716 op->release(op);
57717@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
57718 * lock, and defer it otherwise */
57719 if (!spin_trylock(&object->lock)) {
57720 _debug("defer put");
57721- fscache_stat(&fscache_n_op_deferred_release);
57722+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
57723
57724 cache = object->cache;
57725 spin_lock(&cache->op_gc_list_lock);
57726@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
57727
57728 _debug("GC DEFERRED REL OBJ%x OP%x",
57729 object->debug_id, op->debug_id);
57730- fscache_stat(&fscache_n_op_gc);
57731+ fscache_stat_unchecked(&fscache_n_op_gc);
57732
57733 ASSERTCMP(atomic_read(&op->usage), ==, 0);
57734 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
57735diff --git a/fs/fscache/page.c b/fs/fscache/page.c
57736index 73899c1..ae40c58 100644
57737--- a/fs/fscache/page.c
57738+++ b/fs/fscache/page.c
57739@@ -61,7 +61,7 @@ try_again:
57740 val = radix_tree_lookup(&cookie->stores, page->index);
57741 if (!val) {
57742 rcu_read_unlock();
57743- fscache_stat(&fscache_n_store_vmscan_not_storing);
57744+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
57745 __fscache_uncache_page(cookie, page);
57746 return true;
57747 }
57748@@ -91,11 +91,11 @@ try_again:
57749 spin_unlock(&cookie->stores_lock);
57750
57751 if (xpage) {
57752- fscache_stat(&fscache_n_store_vmscan_cancelled);
57753- fscache_stat(&fscache_n_store_radix_deletes);
57754+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
57755+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57756 ASSERTCMP(xpage, ==, page);
57757 } else {
57758- fscache_stat(&fscache_n_store_vmscan_gone);
57759+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
57760 }
57761
57762 wake_up_bit(&cookie->flags, 0);
57763@@ -110,11 +110,11 @@ page_busy:
57764 * sleeping on memory allocation, so we may need to impose a timeout
57765 * too. */
57766 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
57767- fscache_stat(&fscache_n_store_vmscan_busy);
57768+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
57769 return false;
57770 }
57771
57772- fscache_stat(&fscache_n_store_vmscan_wait);
57773+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
57774 __fscache_wait_on_page_write(cookie, page);
57775 gfp &= ~__GFP_WAIT;
57776 goto try_again;
57777@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
57778 FSCACHE_COOKIE_STORING_TAG);
57779 if (!radix_tree_tag_get(&cookie->stores, page->index,
57780 FSCACHE_COOKIE_PENDING_TAG)) {
57781- fscache_stat(&fscache_n_store_radix_deletes);
57782+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57783 xpage = radix_tree_delete(&cookie->stores, page->index);
57784 }
57785 spin_unlock(&cookie->stores_lock);
57786@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
57787
57788 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
57789
57790- fscache_stat(&fscache_n_attr_changed_calls);
57791+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
57792
57793 if (fscache_object_is_active(object) &&
57794 fscache_use_cookie(object)) {
57795@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57796
57797 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57798
57799- fscache_stat(&fscache_n_attr_changed);
57800+ fscache_stat_unchecked(&fscache_n_attr_changed);
57801
57802 op = kzalloc(sizeof(*op), GFP_KERNEL);
57803 if (!op) {
57804- fscache_stat(&fscache_n_attr_changed_nomem);
57805+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
57806 _leave(" = -ENOMEM");
57807 return -ENOMEM;
57808 }
57809@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57810 if (fscache_submit_exclusive_op(object, op) < 0)
57811 goto nobufs;
57812 spin_unlock(&cookie->lock);
57813- fscache_stat(&fscache_n_attr_changed_ok);
57814+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
57815 fscache_put_operation(op);
57816 _leave(" = 0");
57817 return 0;
57818@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57819 nobufs:
57820 spin_unlock(&cookie->lock);
57821 kfree(op);
57822- fscache_stat(&fscache_n_attr_changed_nobufs);
57823+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
57824 _leave(" = %d", -ENOBUFS);
57825 return -ENOBUFS;
57826 }
57827@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
57828 /* allocate a retrieval operation and attempt to submit it */
57829 op = kzalloc(sizeof(*op), GFP_NOIO);
57830 if (!op) {
57831- fscache_stat(&fscache_n_retrievals_nomem);
57832+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57833 return NULL;
57834 }
57835
57836@@ -289,13 +289,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
57837 return 0;
57838 }
57839
57840- fscache_stat(&fscache_n_retrievals_wait);
57841+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
57842
57843 jif = jiffies;
57844 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
57845 fscache_wait_bit_interruptible,
57846 TASK_INTERRUPTIBLE) != 0) {
57847- fscache_stat(&fscache_n_retrievals_intr);
57848+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57849 _leave(" = -ERESTARTSYS");
57850 return -ERESTARTSYS;
57851 }
57852@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
57853 */
57854 int fscache_wait_for_operation_activation(struct fscache_object *object,
57855 struct fscache_operation *op,
57856- atomic_t *stat_op_waits,
57857- atomic_t *stat_object_dead,
57858+ atomic_unchecked_t *stat_op_waits,
57859+ atomic_unchecked_t *stat_object_dead,
57860 void (*do_cancel)(struct fscache_operation *))
57861 {
57862 int ret;
57863@@ -335,7 +335,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57864
57865 _debug(">>> WT");
57866 if (stat_op_waits)
57867- fscache_stat(stat_op_waits);
57868+ fscache_stat_unchecked(stat_op_waits);
57869 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
57870 fscache_wait_bit_interruptible,
57871 TASK_INTERRUPTIBLE) != 0) {
57872@@ -353,7 +353,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57873 check_if_dead:
57874 if (op->state == FSCACHE_OP_ST_CANCELLED) {
57875 if (stat_object_dead)
57876- fscache_stat(stat_object_dead);
57877+ fscache_stat_unchecked(stat_object_dead);
57878 _leave(" = -ENOBUFS [cancelled]");
57879 return -ENOBUFS;
57880 }
57881@@ -361,7 +361,7 @@ check_if_dead:
57882 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
57883 fscache_cancel_op(op, do_cancel);
57884 if (stat_object_dead)
57885- fscache_stat(stat_object_dead);
57886+ fscache_stat_unchecked(stat_object_dead);
57887 return -ENOBUFS;
57888 }
57889 return 0;
57890@@ -388,7 +388,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57891
57892 _enter("%p,%p,,,", cookie, page);
57893
57894- fscache_stat(&fscache_n_retrievals);
57895+ fscache_stat_unchecked(&fscache_n_retrievals);
57896
57897 if (hlist_empty(&cookie->backing_objects))
57898 goto nobufs;
57899@@ -428,7 +428,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57900 goto nobufs_unlock_dec;
57901 spin_unlock(&cookie->lock);
57902
57903- fscache_stat(&fscache_n_retrieval_ops);
57904+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57905
57906 /* pin the netfs read context in case we need to do the actual netfs
57907 * read because we've encountered a cache read failure */
57908@@ -459,15 +459,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57909
57910 error:
57911 if (ret == -ENOMEM)
57912- fscache_stat(&fscache_n_retrievals_nomem);
57913+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57914 else if (ret == -ERESTARTSYS)
57915- fscache_stat(&fscache_n_retrievals_intr);
57916+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57917 else if (ret == -ENODATA)
57918- fscache_stat(&fscache_n_retrievals_nodata);
57919+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57920 else if (ret < 0)
57921- fscache_stat(&fscache_n_retrievals_nobufs);
57922+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57923 else
57924- fscache_stat(&fscache_n_retrievals_ok);
57925+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57926
57927 fscache_put_retrieval(op);
57928 _leave(" = %d", ret);
57929@@ -480,7 +480,7 @@ nobufs_unlock:
57930 atomic_dec(&cookie->n_active);
57931 kfree(op);
57932 nobufs:
57933- fscache_stat(&fscache_n_retrievals_nobufs);
57934+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57935 _leave(" = -ENOBUFS");
57936 return -ENOBUFS;
57937 }
57938@@ -518,7 +518,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57939
57940 _enter("%p,,%d,,,", cookie, *nr_pages);
57941
57942- fscache_stat(&fscache_n_retrievals);
57943+ fscache_stat_unchecked(&fscache_n_retrievals);
57944
57945 if (hlist_empty(&cookie->backing_objects))
57946 goto nobufs;
57947@@ -554,7 +554,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57948 goto nobufs_unlock_dec;
57949 spin_unlock(&cookie->lock);
57950
57951- fscache_stat(&fscache_n_retrieval_ops);
57952+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57953
57954 /* pin the netfs read context in case we need to do the actual netfs
57955 * read because we've encountered a cache read failure */
57956@@ -585,15 +585,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57957
57958 error:
57959 if (ret == -ENOMEM)
57960- fscache_stat(&fscache_n_retrievals_nomem);
57961+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57962 else if (ret == -ERESTARTSYS)
57963- fscache_stat(&fscache_n_retrievals_intr);
57964+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57965 else if (ret == -ENODATA)
57966- fscache_stat(&fscache_n_retrievals_nodata);
57967+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57968 else if (ret < 0)
57969- fscache_stat(&fscache_n_retrievals_nobufs);
57970+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57971 else
57972- fscache_stat(&fscache_n_retrievals_ok);
57973+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57974
57975 fscache_put_retrieval(op);
57976 _leave(" = %d", ret);
57977@@ -606,7 +606,7 @@ nobufs_unlock:
57978 atomic_dec(&cookie->n_active);
57979 kfree(op);
57980 nobufs:
57981- fscache_stat(&fscache_n_retrievals_nobufs);
57982+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57983 _leave(" = -ENOBUFS");
57984 return -ENOBUFS;
57985 }
57986@@ -630,7 +630,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57987
57988 _enter("%p,%p,,,", cookie, page);
57989
57990- fscache_stat(&fscache_n_allocs);
57991+ fscache_stat_unchecked(&fscache_n_allocs);
57992
57993 if (hlist_empty(&cookie->backing_objects))
57994 goto nobufs;
57995@@ -662,7 +662,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57996 goto nobufs_unlock;
57997 spin_unlock(&cookie->lock);
57998
57999- fscache_stat(&fscache_n_alloc_ops);
58000+ fscache_stat_unchecked(&fscache_n_alloc_ops);
58001
58002 ret = fscache_wait_for_operation_activation(
58003 object, &op->op,
58004@@ -679,11 +679,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
58005
58006 error:
58007 if (ret == -ERESTARTSYS)
58008- fscache_stat(&fscache_n_allocs_intr);
58009+ fscache_stat_unchecked(&fscache_n_allocs_intr);
58010 else if (ret < 0)
58011- fscache_stat(&fscache_n_allocs_nobufs);
58012+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
58013 else
58014- fscache_stat(&fscache_n_allocs_ok);
58015+ fscache_stat_unchecked(&fscache_n_allocs_ok);
58016
58017 fscache_put_retrieval(op);
58018 _leave(" = %d", ret);
58019@@ -694,7 +694,7 @@ nobufs_unlock:
58020 atomic_dec(&cookie->n_active);
58021 kfree(op);
58022 nobufs:
58023- fscache_stat(&fscache_n_allocs_nobufs);
58024+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
58025 _leave(" = -ENOBUFS");
58026 return -ENOBUFS;
58027 }
58028@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
58029
58030 spin_lock(&cookie->stores_lock);
58031
58032- fscache_stat(&fscache_n_store_calls);
58033+ fscache_stat_unchecked(&fscache_n_store_calls);
58034
58035 /* find a page to store */
58036 page = NULL;
58037@@ -781,7 +781,7 @@ static void fscache_write_op(struct fscache_operation *_op)
58038 page = results[0];
58039 _debug("gang %d [%lx]", n, page->index);
58040 if (page->index > op->store_limit) {
58041- fscache_stat(&fscache_n_store_pages_over_limit);
58042+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
58043 goto superseded;
58044 }
58045
58046@@ -793,7 +793,7 @@ static void fscache_write_op(struct fscache_operation *_op)
58047 spin_unlock(&cookie->stores_lock);
58048 spin_unlock(&object->lock);
58049
58050- fscache_stat(&fscache_n_store_pages);
58051+ fscache_stat_unchecked(&fscache_n_store_pages);
58052 fscache_stat(&fscache_n_cop_write_page);
58053 ret = object->cache->ops->write_page(op, page);
58054 fscache_stat_d(&fscache_n_cop_write_page);
58055@@ -896,7 +896,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58056 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
58057 ASSERT(PageFsCache(page));
58058
58059- fscache_stat(&fscache_n_stores);
58060+ fscache_stat_unchecked(&fscache_n_stores);
58061
58062 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
58063 _leave(" = -ENOBUFS [invalidating]");
58064@@ -954,7 +954,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58065 spin_unlock(&cookie->stores_lock);
58066 spin_unlock(&object->lock);
58067
58068- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
58069+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58070 op->store_limit = object->store_limit;
58071
58072 atomic_inc(&cookie->n_active);
58073@@ -963,8 +963,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58074
58075 spin_unlock(&cookie->lock);
58076 radix_tree_preload_end();
58077- fscache_stat(&fscache_n_store_ops);
58078- fscache_stat(&fscache_n_stores_ok);
58079+ fscache_stat_unchecked(&fscache_n_store_ops);
58080+ fscache_stat_unchecked(&fscache_n_stores_ok);
58081
58082 /* the work queue now carries its own ref on the object */
58083 fscache_put_operation(&op->op);
58084@@ -972,14 +972,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
58085 return 0;
58086
58087 already_queued:
58088- fscache_stat(&fscache_n_stores_again);
58089+ fscache_stat_unchecked(&fscache_n_stores_again);
58090 already_pending:
58091 spin_unlock(&cookie->stores_lock);
58092 spin_unlock(&object->lock);
58093 spin_unlock(&cookie->lock);
58094 radix_tree_preload_end();
58095 kfree(op);
58096- fscache_stat(&fscache_n_stores_ok);
58097+ fscache_stat_unchecked(&fscache_n_stores_ok);
58098 _leave(" = 0");
58099 return 0;
58100
58101@@ -999,14 +999,14 @@ nobufs:
58102 spin_unlock(&cookie->lock);
58103 radix_tree_preload_end();
58104 kfree(op);
58105- fscache_stat(&fscache_n_stores_nobufs);
58106+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
58107 _leave(" = -ENOBUFS");
58108 return -ENOBUFS;
58109
58110 nomem_free:
58111 kfree(op);
58112 nomem:
58113- fscache_stat(&fscache_n_stores_oom);
58114+ fscache_stat_unchecked(&fscache_n_stores_oom);
58115 _leave(" = -ENOMEM");
58116 return -ENOMEM;
58117 }
58118@@ -1024,7 +1024,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
58119 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
58120 ASSERTCMP(page, !=, NULL);
58121
58122- fscache_stat(&fscache_n_uncaches);
58123+ fscache_stat_unchecked(&fscache_n_uncaches);
58124
58125 /* cache withdrawal may beat us to it */
58126 if (!PageFsCache(page))
58127@@ -1075,7 +1075,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
58128 struct fscache_cookie *cookie = op->op.object->cookie;
58129
58130 #ifdef CONFIG_FSCACHE_STATS
58131- atomic_inc(&fscache_n_marks);
58132+ atomic_inc_unchecked(&fscache_n_marks);
58133 #endif
58134
58135 _debug("- mark %p{%lx}", page, page->index);
58136diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
58137index 40d13c7..ddf52b9 100644
58138--- a/fs/fscache/stats.c
58139+++ b/fs/fscache/stats.c
58140@@ -18,99 +18,99 @@
58141 /*
58142 * operation counters
58143 */
58144-atomic_t fscache_n_op_pend;
58145-atomic_t fscache_n_op_run;
58146-atomic_t fscache_n_op_enqueue;
58147-atomic_t fscache_n_op_requeue;
58148-atomic_t fscache_n_op_deferred_release;
58149-atomic_t fscache_n_op_release;
58150-atomic_t fscache_n_op_gc;
58151-atomic_t fscache_n_op_cancelled;
58152-atomic_t fscache_n_op_rejected;
58153+atomic_unchecked_t fscache_n_op_pend;
58154+atomic_unchecked_t fscache_n_op_run;
58155+atomic_unchecked_t fscache_n_op_enqueue;
58156+atomic_unchecked_t fscache_n_op_requeue;
58157+atomic_unchecked_t fscache_n_op_deferred_release;
58158+atomic_unchecked_t fscache_n_op_release;
58159+atomic_unchecked_t fscache_n_op_gc;
58160+atomic_unchecked_t fscache_n_op_cancelled;
58161+atomic_unchecked_t fscache_n_op_rejected;
58162
58163-atomic_t fscache_n_attr_changed;
58164-atomic_t fscache_n_attr_changed_ok;
58165-atomic_t fscache_n_attr_changed_nobufs;
58166-atomic_t fscache_n_attr_changed_nomem;
58167-atomic_t fscache_n_attr_changed_calls;
58168+atomic_unchecked_t fscache_n_attr_changed;
58169+atomic_unchecked_t fscache_n_attr_changed_ok;
58170+atomic_unchecked_t fscache_n_attr_changed_nobufs;
58171+atomic_unchecked_t fscache_n_attr_changed_nomem;
58172+atomic_unchecked_t fscache_n_attr_changed_calls;
58173
58174-atomic_t fscache_n_allocs;
58175-atomic_t fscache_n_allocs_ok;
58176-atomic_t fscache_n_allocs_wait;
58177-atomic_t fscache_n_allocs_nobufs;
58178-atomic_t fscache_n_allocs_intr;
58179-atomic_t fscache_n_allocs_object_dead;
58180-atomic_t fscache_n_alloc_ops;
58181-atomic_t fscache_n_alloc_op_waits;
58182+atomic_unchecked_t fscache_n_allocs;
58183+atomic_unchecked_t fscache_n_allocs_ok;
58184+atomic_unchecked_t fscache_n_allocs_wait;
58185+atomic_unchecked_t fscache_n_allocs_nobufs;
58186+atomic_unchecked_t fscache_n_allocs_intr;
58187+atomic_unchecked_t fscache_n_allocs_object_dead;
58188+atomic_unchecked_t fscache_n_alloc_ops;
58189+atomic_unchecked_t fscache_n_alloc_op_waits;
58190
58191-atomic_t fscache_n_retrievals;
58192-atomic_t fscache_n_retrievals_ok;
58193-atomic_t fscache_n_retrievals_wait;
58194-atomic_t fscache_n_retrievals_nodata;
58195-atomic_t fscache_n_retrievals_nobufs;
58196-atomic_t fscache_n_retrievals_intr;
58197-atomic_t fscache_n_retrievals_nomem;
58198-atomic_t fscache_n_retrievals_object_dead;
58199-atomic_t fscache_n_retrieval_ops;
58200-atomic_t fscache_n_retrieval_op_waits;
58201+atomic_unchecked_t fscache_n_retrievals;
58202+atomic_unchecked_t fscache_n_retrievals_ok;
58203+atomic_unchecked_t fscache_n_retrievals_wait;
58204+atomic_unchecked_t fscache_n_retrievals_nodata;
58205+atomic_unchecked_t fscache_n_retrievals_nobufs;
58206+atomic_unchecked_t fscache_n_retrievals_intr;
58207+atomic_unchecked_t fscache_n_retrievals_nomem;
58208+atomic_unchecked_t fscache_n_retrievals_object_dead;
58209+atomic_unchecked_t fscache_n_retrieval_ops;
58210+atomic_unchecked_t fscache_n_retrieval_op_waits;
58211
58212-atomic_t fscache_n_stores;
58213-atomic_t fscache_n_stores_ok;
58214-atomic_t fscache_n_stores_again;
58215-atomic_t fscache_n_stores_nobufs;
58216-atomic_t fscache_n_stores_oom;
58217-atomic_t fscache_n_store_ops;
58218-atomic_t fscache_n_store_calls;
58219-atomic_t fscache_n_store_pages;
58220-atomic_t fscache_n_store_radix_deletes;
58221-atomic_t fscache_n_store_pages_over_limit;
58222+atomic_unchecked_t fscache_n_stores;
58223+atomic_unchecked_t fscache_n_stores_ok;
58224+atomic_unchecked_t fscache_n_stores_again;
58225+atomic_unchecked_t fscache_n_stores_nobufs;
58226+atomic_unchecked_t fscache_n_stores_oom;
58227+atomic_unchecked_t fscache_n_store_ops;
58228+atomic_unchecked_t fscache_n_store_calls;
58229+atomic_unchecked_t fscache_n_store_pages;
58230+atomic_unchecked_t fscache_n_store_radix_deletes;
58231+atomic_unchecked_t fscache_n_store_pages_over_limit;
58232
58233-atomic_t fscache_n_store_vmscan_not_storing;
58234-atomic_t fscache_n_store_vmscan_gone;
58235-atomic_t fscache_n_store_vmscan_busy;
58236-atomic_t fscache_n_store_vmscan_cancelled;
58237-atomic_t fscache_n_store_vmscan_wait;
58238+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58239+atomic_unchecked_t fscache_n_store_vmscan_gone;
58240+atomic_unchecked_t fscache_n_store_vmscan_busy;
58241+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58242+atomic_unchecked_t fscache_n_store_vmscan_wait;
58243
58244-atomic_t fscache_n_marks;
58245-atomic_t fscache_n_uncaches;
58246+atomic_unchecked_t fscache_n_marks;
58247+atomic_unchecked_t fscache_n_uncaches;
58248
58249-atomic_t fscache_n_acquires;
58250-atomic_t fscache_n_acquires_null;
58251-atomic_t fscache_n_acquires_no_cache;
58252-atomic_t fscache_n_acquires_ok;
58253-atomic_t fscache_n_acquires_nobufs;
58254-atomic_t fscache_n_acquires_oom;
58255+atomic_unchecked_t fscache_n_acquires;
58256+atomic_unchecked_t fscache_n_acquires_null;
58257+atomic_unchecked_t fscache_n_acquires_no_cache;
58258+atomic_unchecked_t fscache_n_acquires_ok;
58259+atomic_unchecked_t fscache_n_acquires_nobufs;
58260+atomic_unchecked_t fscache_n_acquires_oom;
58261
58262-atomic_t fscache_n_invalidates;
58263-atomic_t fscache_n_invalidates_run;
58264+atomic_unchecked_t fscache_n_invalidates;
58265+atomic_unchecked_t fscache_n_invalidates_run;
58266
58267-atomic_t fscache_n_updates;
58268-atomic_t fscache_n_updates_null;
58269-atomic_t fscache_n_updates_run;
58270+atomic_unchecked_t fscache_n_updates;
58271+atomic_unchecked_t fscache_n_updates_null;
58272+atomic_unchecked_t fscache_n_updates_run;
58273
58274-atomic_t fscache_n_relinquishes;
58275-atomic_t fscache_n_relinquishes_null;
58276-atomic_t fscache_n_relinquishes_waitcrt;
58277-atomic_t fscache_n_relinquishes_retire;
58278+atomic_unchecked_t fscache_n_relinquishes;
58279+atomic_unchecked_t fscache_n_relinquishes_null;
58280+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58281+atomic_unchecked_t fscache_n_relinquishes_retire;
58282
58283-atomic_t fscache_n_cookie_index;
58284-atomic_t fscache_n_cookie_data;
58285-atomic_t fscache_n_cookie_special;
58286+atomic_unchecked_t fscache_n_cookie_index;
58287+atomic_unchecked_t fscache_n_cookie_data;
58288+atomic_unchecked_t fscache_n_cookie_special;
58289
58290-atomic_t fscache_n_object_alloc;
58291-atomic_t fscache_n_object_no_alloc;
58292-atomic_t fscache_n_object_lookups;
58293-atomic_t fscache_n_object_lookups_negative;
58294-atomic_t fscache_n_object_lookups_positive;
58295-atomic_t fscache_n_object_lookups_timed_out;
58296-atomic_t fscache_n_object_created;
58297-atomic_t fscache_n_object_avail;
58298-atomic_t fscache_n_object_dead;
58299+atomic_unchecked_t fscache_n_object_alloc;
58300+atomic_unchecked_t fscache_n_object_no_alloc;
58301+atomic_unchecked_t fscache_n_object_lookups;
58302+atomic_unchecked_t fscache_n_object_lookups_negative;
58303+atomic_unchecked_t fscache_n_object_lookups_positive;
58304+atomic_unchecked_t fscache_n_object_lookups_timed_out;
58305+atomic_unchecked_t fscache_n_object_created;
58306+atomic_unchecked_t fscache_n_object_avail;
58307+atomic_unchecked_t fscache_n_object_dead;
58308
58309-atomic_t fscache_n_checkaux_none;
58310-atomic_t fscache_n_checkaux_okay;
58311-atomic_t fscache_n_checkaux_update;
58312-atomic_t fscache_n_checkaux_obsolete;
58313+atomic_unchecked_t fscache_n_checkaux_none;
58314+atomic_unchecked_t fscache_n_checkaux_okay;
58315+atomic_unchecked_t fscache_n_checkaux_update;
58316+atomic_unchecked_t fscache_n_checkaux_obsolete;
58317
58318 atomic_t fscache_n_cop_alloc_object;
58319 atomic_t fscache_n_cop_lookup_object;
58320@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
58321 seq_puts(m, "FS-Cache statistics\n");
58322
58323 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
58324- atomic_read(&fscache_n_cookie_index),
58325- atomic_read(&fscache_n_cookie_data),
58326- atomic_read(&fscache_n_cookie_special));
58327+ atomic_read_unchecked(&fscache_n_cookie_index),
58328+ atomic_read_unchecked(&fscache_n_cookie_data),
58329+ atomic_read_unchecked(&fscache_n_cookie_special));
58330
58331 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
58332- atomic_read(&fscache_n_object_alloc),
58333- atomic_read(&fscache_n_object_no_alloc),
58334- atomic_read(&fscache_n_object_avail),
58335- atomic_read(&fscache_n_object_dead));
58336+ atomic_read_unchecked(&fscache_n_object_alloc),
58337+ atomic_read_unchecked(&fscache_n_object_no_alloc),
58338+ atomic_read_unchecked(&fscache_n_object_avail),
58339+ atomic_read_unchecked(&fscache_n_object_dead));
58340 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
58341- atomic_read(&fscache_n_checkaux_none),
58342- atomic_read(&fscache_n_checkaux_okay),
58343- atomic_read(&fscache_n_checkaux_update),
58344- atomic_read(&fscache_n_checkaux_obsolete));
58345+ atomic_read_unchecked(&fscache_n_checkaux_none),
58346+ atomic_read_unchecked(&fscache_n_checkaux_okay),
58347+ atomic_read_unchecked(&fscache_n_checkaux_update),
58348+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
58349
58350 seq_printf(m, "Pages : mrk=%u unc=%u\n",
58351- atomic_read(&fscache_n_marks),
58352- atomic_read(&fscache_n_uncaches));
58353+ atomic_read_unchecked(&fscache_n_marks),
58354+ atomic_read_unchecked(&fscache_n_uncaches));
58355
58356 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
58357 " oom=%u\n",
58358- atomic_read(&fscache_n_acquires),
58359- atomic_read(&fscache_n_acquires_null),
58360- atomic_read(&fscache_n_acquires_no_cache),
58361- atomic_read(&fscache_n_acquires_ok),
58362- atomic_read(&fscache_n_acquires_nobufs),
58363- atomic_read(&fscache_n_acquires_oom));
58364+ atomic_read_unchecked(&fscache_n_acquires),
58365+ atomic_read_unchecked(&fscache_n_acquires_null),
58366+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
58367+ atomic_read_unchecked(&fscache_n_acquires_ok),
58368+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
58369+ atomic_read_unchecked(&fscache_n_acquires_oom));
58370
58371 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
58372- atomic_read(&fscache_n_object_lookups),
58373- atomic_read(&fscache_n_object_lookups_negative),
58374- atomic_read(&fscache_n_object_lookups_positive),
58375- atomic_read(&fscache_n_object_created),
58376- atomic_read(&fscache_n_object_lookups_timed_out));
58377+ atomic_read_unchecked(&fscache_n_object_lookups),
58378+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
58379+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
58380+ atomic_read_unchecked(&fscache_n_object_created),
58381+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
58382
58383 seq_printf(m, "Invals : n=%u run=%u\n",
58384- atomic_read(&fscache_n_invalidates),
58385- atomic_read(&fscache_n_invalidates_run));
58386+ atomic_read_unchecked(&fscache_n_invalidates),
58387+ atomic_read_unchecked(&fscache_n_invalidates_run));
58388
58389 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
58390- atomic_read(&fscache_n_updates),
58391- atomic_read(&fscache_n_updates_null),
58392- atomic_read(&fscache_n_updates_run));
58393+ atomic_read_unchecked(&fscache_n_updates),
58394+ atomic_read_unchecked(&fscache_n_updates_null),
58395+ atomic_read_unchecked(&fscache_n_updates_run));
58396
58397 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
58398- atomic_read(&fscache_n_relinquishes),
58399- atomic_read(&fscache_n_relinquishes_null),
58400- atomic_read(&fscache_n_relinquishes_waitcrt),
58401- atomic_read(&fscache_n_relinquishes_retire));
58402+ atomic_read_unchecked(&fscache_n_relinquishes),
58403+ atomic_read_unchecked(&fscache_n_relinquishes_null),
58404+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
58405+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
58406
58407 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
58408- atomic_read(&fscache_n_attr_changed),
58409- atomic_read(&fscache_n_attr_changed_ok),
58410- atomic_read(&fscache_n_attr_changed_nobufs),
58411- atomic_read(&fscache_n_attr_changed_nomem),
58412- atomic_read(&fscache_n_attr_changed_calls));
58413+ atomic_read_unchecked(&fscache_n_attr_changed),
58414+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
58415+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
58416+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
58417+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
58418
58419 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
58420- atomic_read(&fscache_n_allocs),
58421- atomic_read(&fscache_n_allocs_ok),
58422- atomic_read(&fscache_n_allocs_wait),
58423- atomic_read(&fscache_n_allocs_nobufs),
58424- atomic_read(&fscache_n_allocs_intr));
58425+ atomic_read_unchecked(&fscache_n_allocs),
58426+ atomic_read_unchecked(&fscache_n_allocs_ok),
58427+ atomic_read_unchecked(&fscache_n_allocs_wait),
58428+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
58429+ atomic_read_unchecked(&fscache_n_allocs_intr));
58430 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
58431- atomic_read(&fscache_n_alloc_ops),
58432- atomic_read(&fscache_n_alloc_op_waits),
58433- atomic_read(&fscache_n_allocs_object_dead));
58434+ atomic_read_unchecked(&fscache_n_alloc_ops),
58435+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
58436+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
58437
58438 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
58439 " int=%u oom=%u\n",
58440- atomic_read(&fscache_n_retrievals),
58441- atomic_read(&fscache_n_retrievals_ok),
58442- atomic_read(&fscache_n_retrievals_wait),
58443- atomic_read(&fscache_n_retrievals_nodata),
58444- atomic_read(&fscache_n_retrievals_nobufs),
58445- atomic_read(&fscache_n_retrievals_intr),
58446- atomic_read(&fscache_n_retrievals_nomem));
58447+ atomic_read_unchecked(&fscache_n_retrievals),
58448+ atomic_read_unchecked(&fscache_n_retrievals_ok),
58449+ atomic_read_unchecked(&fscache_n_retrievals_wait),
58450+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
58451+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
58452+ atomic_read_unchecked(&fscache_n_retrievals_intr),
58453+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
58454 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
58455- atomic_read(&fscache_n_retrieval_ops),
58456- atomic_read(&fscache_n_retrieval_op_waits),
58457- atomic_read(&fscache_n_retrievals_object_dead));
58458+ atomic_read_unchecked(&fscache_n_retrieval_ops),
58459+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
58460+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
58461
58462 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
58463- atomic_read(&fscache_n_stores),
58464- atomic_read(&fscache_n_stores_ok),
58465- atomic_read(&fscache_n_stores_again),
58466- atomic_read(&fscache_n_stores_nobufs),
58467- atomic_read(&fscache_n_stores_oom));
58468+ atomic_read_unchecked(&fscache_n_stores),
58469+ atomic_read_unchecked(&fscache_n_stores_ok),
58470+ atomic_read_unchecked(&fscache_n_stores_again),
58471+ atomic_read_unchecked(&fscache_n_stores_nobufs),
58472+ atomic_read_unchecked(&fscache_n_stores_oom));
58473 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
58474- atomic_read(&fscache_n_store_ops),
58475- atomic_read(&fscache_n_store_calls),
58476- atomic_read(&fscache_n_store_pages),
58477- atomic_read(&fscache_n_store_radix_deletes),
58478- atomic_read(&fscache_n_store_pages_over_limit));
58479+ atomic_read_unchecked(&fscache_n_store_ops),
58480+ atomic_read_unchecked(&fscache_n_store_calls),
58481+ atomic_read_unchecked(&fscache_n_store_pages),
58482+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
58483+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
58484
58485 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
58486- atomic_read(&fscache_n_store_vmscan_not_storing),
58487- atomic_read(&fscache_n_store_vmscan_gone),
58488- atomic_read(&fscache_n_store_vmscan_busy),
58489- atomic_read(&fscache_n_store_vmscan_cancelled),
58490- atomic_read(&fscache_n_store_vmscan_wait));
58491+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
58492+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
58493+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
58494+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
58495+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
58496
58497 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
58498- atomic_read(&fscache_n_op_pend),
58499- atomic_read(&fscache_n_op_run),
58500- atomic_read(&fscache_n_op_enqueue),
58501- atomic_read(&fscache_n_op_cancelled),
58502- atomic_read(&fscache_n_op_rejected));
58503+ atomic_read_unchecked(&fscache_n_op_pend),
58504+ atomic_read_unchecked(&fscache_n_op_run),
58505+ atomic_read_unchecked(&fscache_n_op_enqueue),
58506+ atomic_read_unchecked(&fscache_n_op_cancelled),
58507+ atomic_read_unchecked(&fscache_n_op_rejected));
58508 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
58509- atomic_read(&fscache_n_op_deferred_release),
58510- atomic_read(&fscache_n_op_release),
58511- atomic_read(&fscache_n_op_gc));
58512+ atomic_read_unchecked(&fscache_n_op_deferred_release),
58513+ atomic_read_unchecked(&fscache_n_op_release),
58514+ atomic_read_unchecked(&fscache_n_op_gc));
58515
58516 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
58517 atomic_read(&fscache_n_cop_alloc_object),
58518diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
58519index adbfd66..4b25822 100644
58520--- a/fs/fuse/cuse.c
58521+++ b/fs/fuse/cuse.c
58522@@ -603,10 +603,12 @@ static int __init cuse_init(void)
58523 INIT_LIST_HEAD(&cuse_conntbl[i]);
58524
58525 /* inherit and extend fuse_dev_operations */
58526- cuse_channel_fops = fuse_dev_operations;
58527- cuse_channel_fops.owner = THIS_MODULE;
58528- cuse_channel_fops.open = cuse_channel_open;
58529- cuse_channel_fops.release = cuse_channel_release;
58530+ pax_open_kernel();
58531+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
58532+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
58533+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
58534+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
58535+ pax_close_kernel();
58536
58537 cuse_class = class_create(THIS_MODULE, "cuse");
58538 if (IS_ERR(cuse_class))
58539diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
58540index ef74ad5..c9ac759e 100644
58541--- a/fs/fuse/dev.c
58542+++ b/fs/fuse/dev.c
58543@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58544 ret = 0;
58545 pipe_lock(pipe);
58546
58547- if (!pipe->readers) {
58548+ if (!atomic_read(&pipe->readers)) {
58549 send_sig(SIGPIPE, current, 0);
58550 if (!ret)
58551 ret = -EPIPE;
58552@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58553 page_nr++;
58554 ret += buf->len;
58555
58556- if (pipe->files)
58557+ if (atomic_read(&pipe->files))
58558 do_wakeup = 1;
58559 }
58560
58561diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
58562index b7989f2..1f72ec4 100644
58563--- a/fs/fuse/dir.c
58564+++ b/fs/fuse/dir.c
58565@@ -1438,7 +1438,7 @@ static char *read_link(struct dentry *dentry)
58566 return link;
58567 }
58568
58569-static void free_link(char *link)
58570+static void free_link(const char *link)
58571 {
58572 if (!IS_ERR(link))
58573 free_page((unsigned long) link);
58574diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
58575index 1298766..c964c60 100644
58576--- a/fs/gfs2/inode.c
58577+++ b/fs/gfs2/inode.c
58578@@ -1515,7 +1515,7 @@ out:
58579
58580 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58581 {
58582- char *s = nd_get_link(nd);
58583+ const char *s = nd_get_link(nd);
58584 if (!IS_ERR(s))
58585 kfree(s);
58586 }
58587diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
58588index 2543728..14d7bd4 100644
58589--- a/fs/hostfs/hostfs_kern.c
58590+++ b/fs/hostfs/hostfs_kern.c
58591@@ -904,7 +904,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58592
58593 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
58594 {
58595- char *s = nd_get_link(nd);
58596+ const char *s = nd_get_link(nd);
58597 if (!IS_ERR(s))
58598 __putname(s);
58599 }
58600diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
58601index d19b30a..ef89c36 100644
58602--- a/fs/hugetlbfs/inode.c
58603+++ b/fs/hugetlbfs/inode.c
58604@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58605 struct mm_struct *mm = current->mm;
58606 struct vm_area_struct *vma;
58607 struct hstate *h = hstate_file(file);
58608+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
58609 struct vm_unmapped_area_info info;
58610
58611 if (len & ~huge_page_mask(h))
58612@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58613 return addr;
58614 }
58615
58616+#ifdef CONFIG_PAX_RANDMMAP
58617+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
58618+#endif
58619+
58620 if (addr) {
58621 addr = ALIGN(addr, huge_page_size(h));
58622 vma = find_vma(mm, addr);
58623- if (TASK_SIZE - len >= addr &&
58624- (!vma || addr + len <= vma->vm_start))
58625+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
58626 return addr;
58627 }
58628
58629 info.flags = 0;
58630 info.length = len;
58631 info.low_limit = TASK_UNMAPPED_BASE;
58632+
58633+#ifdef CONFIG_PAX_RANDMMAP
58634+ if (mm->pax_flags & MF_PAX_RANDMMAP)
58635+ info.low_limit += mm->delta_mmap;
58636+#endif
58637+
58638 info.high_limit = TASK_SIZE;
58639 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
58640 info.align_offset = 0;
58641@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
58642 };
58643 MODULE_ALIAS_FS("hugetlbfs");
58644
58645-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58646+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58647
58648 static int can_do_hugetlb_shm(void)
58649 {
58650diff --git a/fs/inode.c b/fs/inode.c
58651index b33ba8e..3c79a47 100644
58652--- a/fs/inode.c
58653+++ b/fs/inode.c
58654@@ -849,8 +849,8 @@ unsigned int get_next_ino(void)
58655
58656 #ifdef CONFIG_SMP
58657 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
58658- static atomic_t shared_last_ino;
58659- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
58660+ static atomic_unchecked_t shared_last_ino;
58661+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
58662
58663 res = next - LAST_INO_BATCH;
58664 }
58665diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
58666index 4a6cf28..d3a29d3 100644
58667--- a/fs/jffs2/erase.c
58668+++ b/fs/jffs2/erase.c
58669@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
58670 struct jffs2_unknown_node marker = {
58671 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
58672 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58673- .totlen = cpu_to_je32(c->cleanmarker_size)
58674+ .totlen = cpu_to_je32(c->cleanmarker_size),
58675+ .hdr_crc = cpu_to_je32(0)
58676 };
58677
58678 jffs2_prealloc_raw_node_refs(c, jeb, 1);
58679diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
58680index a6597d6..41b30ec 100644
58681--- a/fs/jffs2/wbuf.c
58682+++ b/fs/jffs2/wbuf.c
58683@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
58684 {
58685 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
58686 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58687- .totlen = constant_cpu_to_je32(8)
58688+ .totlen = constant_cpu_to_je32(8),
58689+ .hdr_crc = constant_cpu_to_je32(0)
58690 };
58691
58692 /*
58693diff --git a/fs/jfs/super.c b/fs/jfs/super.c
58694index 6669aa2..36b033d 100644
58695--- a/fs/jfs/super.c
58696+++ b/fs/jfs/super.c
58697@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
58698
58699 jfs_inode_cachep =
58700 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
58701- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
58702+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
58703 init_once);
58704 if (jfs_inode_cachep == NULL)
58705 return -ENOMEM;
58706diff --git a/fs/libfs.c b/fs/libfs.c
58707index 193e0c2..7404665 100644
58708--- a/fs/libfs.c
58709+++ b/fs/libfs.c
58710@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
58711
58712 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
58713 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
58714+ char d_name[sizeof(next->d_iname)];
58715+ const unsigned char *name;
58716+
58717 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
58718 if (!simple_positive(next)) {
58719 spin_unlock(&next->d_lock);
58720@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
58721
58722 spin_unlock(&next->d_lock);
58723 spin_unlock(&dentry->d_lock);
58724- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
58725+ name = next->d_name.name;
58726+ if (name == next->d_iname) {
58727+ memcpy(d_name, name, next->d_name.len);
58728+ name = d_name;
58729+ }
58730+ if (!dir_emit(ctx, name, next->d_name.len,
58731 next->d_inode->i_ino, dt_type(next->d_inode)))
58732 return 0;
58733 spin_lock(&dentry->d_lock);
58734diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
58735index acd3947..1f896e2 100644
58736--- a/fs/lockd/clntproc.c
58737+++ b/fs/lockd/clntproc.c
58738@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
58739 /*
58740 * Cookie counter for NLM requests
58741 */
58742-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
58743+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
58744
58745 void nlmclnt_next_cookie(struct nlm_cookie *c)
58746 {
58747- u32 cookie = atomic_inc_return(&nlm_cookie);
58748+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
58749
58750 memcpy(c->data, &cookie, 4);
58751 c->len=4;
58752diff --git a/fs/locks.c b/fs/locks.c
58753index b27a300..4156d0b 100644
58754--- a/fs/locks.c
58755+++ b/fs/locks.c
58756@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
58757 return;
58758
58759 if (filp->f_op && filp->f_op->flock) {
58760- struct file_lock fl = {
58761+ struct file_lock flock = {
58762 .fl_pid = current->tgid,
58763 .fl_file = filp,
58764 .fl_flags = FL_FLOCK,
58765 .fl_type = F_UNLCK,
58766 .fl_end = OFFSET_MAX,
58767 };
58768- filp->f_op->flock(filp, F_SETLKW, &fl);
58769- if (fl.fl_ops && fl.fl_ops->fl_release_private)
58770- fl.fl_ops->fl_release_private(&fl);
58771+ filp->f_op->flock(filp, F_SETLKW, &flock);
58772+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
58773+ flock.fl_ops->fl_release_private(&flock);
58774 }
58775
58776 spin_lock(&inode->i_lock);
58777diff --git a/fs/namei.c b/fs/namei.c
58778index 23ac50f..c6757a5 100644
58779--- a/fs/namei.c
58780+++ b/fs/namei.c
58781@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
58782 if (ret != -EACCES)
58783 return ret;
58784
58785+#ifdef CONFIG_GRKERNSEC
58786+ /* we'll block if we have to log due to a denied capability use */
58787+ if (mask & MAY_NOT_BLOCK)
58788+ return -ECHILD;
58789+#endif
58790+
58791 if (S_ISDIR(inode->i_mode)) {
58792 /* DACs are overridable for directories */
58793- if (inode_capable(inode, CAP_DAC_OVERRIDE))
58794- return 0;
58795 if (!(mask & MAY_WRITE))
58796- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58797+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58798+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58799 return 0;
58800+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
58801+ return 0;
58802 return -EACCES;
58803 }
58804 /*
58805+ * Searching includes executable on directories, else just read.
58806+ */
58807+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58808+ if (mask == MAY_READ)
58809+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58810+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58811+ return 0;
58812+
58813+ /*
58814 * Read/write DACs are always overridable.
58815 * Executable DACs are overridable when there is
58816 * at least one exec bit set.
58817@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
58818 if (inode_capable(inode, CAP_DAC_OVERRIDE))
58819 return 0;
58820
58821- /*
58822- * Searching includes executable on directories, else just read.
58823- */
58824- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58825- if (mask == MAY_READ)
58826- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58827- return 0;
58828-
58829 return -EACCES;
58830 }
58831
58832@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58833 {
58834 struct dentry *dentry = link->dentry;
58835 int error;
58836- char *s;
58837+ const char *s;
58838
58839 BUG_ON(nd->flags & LOOKUP_RCU);
58840
58841@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58842 if (error)
58843 goto out_put_nd_path;
58844
58845+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
58846+ dentry->d_inode, dentry, nd->path.mnt)) {
58847+ error = -EACCES;
58848+ goto out_put_nd_path;
58849+ }
58850+
58851 nd->last_type = LAST_BIND;
58852 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
58853 error = PTR_ERR(*p);
58854@@ -1602,6 +1616,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58855 if (res)
58856 break;
58857 res = walk_component(nd, path, LOOKUP_FOLLOW);
58858+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58859+ res = -EACCES;
58860 put_link(nd, &link, cookie);
58861 } while (res > 0);
58862
58863@@ -1700,7 +1716,7 @@ EXPORT_SYMBOL(full_name_hash);
58864 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58865 {
58866 unsigned long a, b, adata, bdata, mask, hash, len;
58867- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58868+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58869
58870 hash = a = 0;
58871 len = -sizeof(unsigned long);
58872@@ -1981,6 +1997,8 @@ static int path_lookupat(int dfd, const char *name,
58873 if (err)
58874 break;
58875 err = lookup_last(nd, &path);
58876+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58877+ err = -EACCES;
58878 put_link(nd, &link, cookie);
58879 }
58880 }
58881@@ -1988,6 +2006,13 @@ static int path_lookupat(int dfd, const char *name,
58882 if (!err)
58883 err = complete_walk(nd);
58884
58885+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58886+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58887+ path_put(&nd->path);
58888+ err = -ENOENT;
58889+ }
58890+ }
58891+
58892 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58893 if (!can_lookup(nd->inode)) {
58894 path_put(&nd->path);
58895@@ -2015,8 +2040,15 @@ static int filename_lookup(int dfd, struct filename *name,
58896 retval = path_lookupat(dfd, name->name,
58897 flags | LOOKUP_REVAL, nd);
58898
58899- if (likely(!retval))
58900+ if (likely(!retval)) {
58901 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58902+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58903+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58904+ path_put(&nd->path);
58905+ return -ENOENT;
58906+ }
58907+ }
58908+ }
58909 return retval;
58910 }
58911
58912@@ -2587,6 +2619,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58913 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58914 return -EPERM;
58915
58916+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58917+ return -EPERM;
58918+ if (gr_handle_rawio(inode))
58919+ return -EPERM;
58920+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58921+ return -EACCES;
58922+
58923 return 0;
58924 }
58925
58926@@ -2818,7 +2857,7 @@ looked_up:
58927 * cleared otherwise prior to returning.
58928 */
58929 static int lookup_open(struct nameidata *nd, struct path *path,
58930- struct file *file,
58931+ struct path *link, struct file *file,
58932 const struct open_flags *op,
58933 bool got_write, int *opened)
58934 {
58935@@ -2853,6 +2892,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58936 /* Negative dentry, just create the file */
58937 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58938 umode_t mode = op->mode;
58939+
58940+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58941+ error = -EACCES;
58942+ goto out_dput;
58943+ }
58944+
58945+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58946+ error = -EACCES;
58947+ goto out_dput;
58948+ }
58949+
58950 if (!IS_POSIXACL(dir->d_inode))
58951 mode &= ~current_umask();
58952 /*
58953@@ -2874,6 +2924,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58954 nd->flags & LOOKUP_EXCL);
58955 if (error)
58956 goto out_dput;
58957+ else
58958+ gr_handle_create(dentry, nd->path.mnt);
58959 }
58960 out_no_open:
58961 path->dentry = dentry;
58962@@ -2888,7 +2940,7 @@ out_dput:
58963 /*
58964 * Handle the last step of open()
58965 */
58966-static int do_last(struct nameidata *nd, struct path *path,
58967+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58968 struct file *file, const struct open_flags *op,
58969 int *opened, struct filename *name)
58970 {
58971@@ -2938,6 +2990,15 @@ static int do_last(struct nameidata *nd, struct path *path,
58972 if (error)
58973 return error;
58974
58975+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58976+ error = -ENOENT;
58977+ goto out;
58978+ }
58979+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58980+ error = -EACCES;
58981+ goto out;
58982+ }
58983+
58984 audit_inode(name, dir, LOOKUP_PARENT);
58985 error = -EISDIR;
58986 /* trailing slashes? */
58987@@ -2957,7 +3018,7 @@ retry_lookup:
58988 */
58989 }
58990 mutex_lock(&dir->d_inode->i_mutex);
58991- error = lookup_open(nd, path, file, op, got_write, opened);
58992+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58993 mutex_unlock(&dir->d_inode->i_mutex);
58994
58995 if (error <= 0) {
58996@@ -2981,11 +3042,28 @@ retry_lookup:
58997 goto finish_open_created;
58998 }
58999
59000+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
59001+ error = -ENOENT;
59002+ goto exit_dput;
59003+ }
59004+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
59005+ error = -EACCES;
59006+ goto exit_dput;
59007+ }
59008+
59009 /*
59010 * create/update audit record if it already exists.
59011 */
59012- if (path->dentry->d_inode)
59013+ if (path->dentry->d_inode) {
59014+ /* only check if O_CREAT is specified, all other checks need to go
59015+ into may_open */
59016+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
59017+ error = -EACCES;
59018+ goto exit_dput;
59019+ }
59020+
59021 audit_inode(name, path->dentry, 0);
59022+ }
59023
59024 /*
59025 * If atomic_open() acquired write access it is dropped now due to
59026@@ -3026,6 +3104,11 @@ finish_lookup:
59027 }
59028 }
59029 BUG_ON(inode != path->dentry->d_inode);
59030+ /* if we're resolving a symlink to another symlink */
59031+ if (link && gr_handle_symlink_owner(link, inode)) {
59032+ error = -EACCES;
59033+ goto out;
59034+ }
59035 return 1;
59036 }
59037
59038@@ -3035,7 +3118,6 @@ finish_lookup:
59039 save_parent.dentry = nd->path.dentry;
59040 save_parent.mnt = mntget(path->mnt);
59041 nd->path.dentry = path->dentry;
59042-
59043 }
59044 nd->inode = inode;
59045 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
59046@@ -3045,7 +3127,18 @@ finish_open:
59047 path_put(&save_parent);
59048 return error;
59049 }
59050+
59051+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
59052+ error = -ENOENT;
59053+ goto out;
59054+ }
59055+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
59056+ error = -EACCES;
59057+ goto out;
59058+ }
59059+
59060 audit_inode(name, nd->path.dentry, 0);
59061+
59062 error = -EISDIR;
59063 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
59064 goto out;
59065@@ -3208,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
59066 if (unlikely(error))
59067 goto out;
59068
59069- error = do_last(nd, &path, file, op, &opened, pathname);
59070+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
59071 while (unlikely(error > 0)) { /* trailing symlink */
59072 struct path link = path;
59073 void *cookie;
59074@@ -3226,7 +3319,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
59075 error = follow_link(&link, nd, &cookie);
59076 if (unlikely(error))
59077 break;
59078- error = do_last(nd, &path, file, op, &opened, pathname);
59079+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
59080 put_link(nd, &link, cookie);
59081 }
59082 out:
59083@@ -3326,8 +3419,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
59084 goto unlock;
59085
59086 error = -EEXIST;
59087- if (dentry->d_inode)
59088+ if (dentry->d_inode) {
59089+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
59090+ error = -ENOENT;
59091+ }
59092 goto fail;
59093+ }
59094 /*
59095 * Special case - lookup gave negative, but... we had foo/bar/
59096 * From the vfs_mknod() POV we just have a negative dentry -
59097@@ -3379,6 +3476,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
59098 }
59099 EXPORT_SYMBOL(user_path_create);
59100
59101+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
59102+{
59103+ struct filename *tmp = getname(pathname);
59104+ struct dentry *res;
59105+ if (IS_ERR(tmp))
59106+ return ERR_CAST(tmp);
59107+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
59108+ if (IS_ERR(res))
59109+ putname(tmp);
59110+ else
59111+ *to = tmp;
59112+ return res;
59113+}
59114+
59115 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
59116 {
59117 int error = may_create(dir, dentry);
59118@@ -3441,6 +3552,17 @@ retry:
59119
59120 if (!IS_POSIXACL(path.dentry->d_inode))
59121 mode &= ~current_umask();
59122+
59123+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
59124+ error = -EPERM;
59125+ goto out;
59126+ }
59127+
59128+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
59129+ error = -EACCES;
59130+ goto out;
59131+ }
59132+
59133 error = security_path_mknod(&path, dentry, mode, dev);
59134 if (error)
59135 goto out;
59136@@ -3457,6 +3579,8 @@ retry:
59137 break;
59138 }
59139 out:
59140+ if (!error)
59141+ gr_handle_create(dentry, path.mnt);
59142 done_path_create(&path, dentry);
59143 if (retry_estale(error, lookup_flags)) {
59144 lookup_flags |= LOOKUP_REVAL;
59145@@ -3509,9 +3633,16 @@ retry:
59146
59147 if (!IS_POSIXACL(path.dentry->d_inode))
59148 mode &= ~current_umask();
59149+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
59150+ error = -EACCES;
59151+ goto out;
59152+ }
59153 error = security_path_mkdir(&path, dentry, mode);
59154 if (!error)
59155 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
59156+ if (!error)
59157+ gr_handle_create(dentry, path.mnt);
59158+out:
59159 done_path_create(&path, dentry);
59160 if (retry_estale(error, lookup_flags)) {
59161 lookup_flags |= LOOKUP_REVAL;
59162@@ -3592,6 +3723,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
59163 struct filename *name;
59164 struct dentry *dentry;
59165 struct nameidata nd;
59166+ ino_t saved_ino = 0;
59167+ dev_t saved_dev = 0;
59168 unsigned int lookup_flags = 0;
59169 retry:
59170 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
59171@@ -3624,10 +3757,21 @@ retry:
59172 error = -ENOENT;
59173 goto exit3;
59174 }
59175+
59176+ saved_ino = dentry->d_inode->i_ino;
59177+ saved_dev = gr_get_dev_from_dentry(dentry);
59178+
59179+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
59180+ error = -EACCES;
59181+ goto exit3;
59182+ }
59183+
59184 error = security_path_rmdir(&nd.path, dentry);
59185 if (error)
59186 goto exit3;
59187 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
59188+ if (!error && (saved_dev || saved_ino))
59189+ gr_handle_delete(saved_ino, saved_dev);
59190 exit3:
59191 dput(dentry);
59192 exit2:
59193@@ -3693,6 +3837,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
59194 struct dentry *dentry;
59195 struct nameidata nd;
59196 struct inode *inode = NULL;
59197+ ino_t saved_ino = 0;
59198+ dev_t saved_dev = 0;
59199 unsigned int lookup_flags = 0;
59200 retry:
59201 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
59202@@ -3719,10 +3865,22 @@ retry:
59203 if (!inode)
59204 goto slashes;
59205 ihold(inode);
59206+
59207+ if (inode->i_nlink <= 1) {
59208+ saved_ino = inode->i_ino;
59209+ saved_dev = gr_get_dev_from_dentry(dentry);
59210+ }
59211+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
59212+ error = -EACCES;
59213+ goto exit2;
59214+ }
59215+
59216 error = security_path_unlink(&nd.path, dentry);
59217 if (error)
59218 goto exit2;
59219 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
59220+ if (!error && (saved_ino || saved_dev))
59221+ gr_handle_delete(saved_ino, saved_dev);
59222 exit2:
59223 dput(dentry);
59224 }
59225@@ -3800,9 +3958,17 @@ retry:
59226 if (IS_ERR(dentry))
59227 goto out_putname;
59228
59229+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
59230+ error = -EACCES;
59231+ goto out;
59232+ }
59233+
59234 error = security_path_symlink(&path, dentry, from->name);
59235 if (!error)
59236 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
59237+ if (!error)
59238+ gr_handle_create(dentry, path.mnt);
59239+out:
59240 done_path_create(&path, dentry);
59241 if (retry_estale(error, lookup_flags)) {
59242 lookup_flags |= LOOKUP_REVAL;
59243@@ -3882,6 +4048,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
59244 {
59245 struct dentry *new_dentry;
59246 struct path old_path, new_path;
59247+ struct filename *to = NULL;
59248 int how = 0;
59249 int error;
59250
59251@@ -3905,7 +4072,7 @@ retry:
59252 if (error)
59253 return error;
59254
59255- new_dentry = user_path_create(newdfd, newname, &new_path,
59256+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
59257 (how & LOOKUP_REVAL));
59258 error = PTR_ERR(new_dentry);
59259 if (IS_ERR(new_dentry))
59260@@ -3917,11 +4084,28 @@ retry:
59261 error = may_linkat(&old_path);
59262 if (unlikely(error))
59263 goto out_dput;
59264+
59265+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
59266+ old_path.dentry->d_inode,
59267+ old_path.dentry->d_inode->i_mode, to)) {
59268+ error = -EACCES;
59269+ goto out_dput;
59270+ }
59271+
59272+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
59273+ old_path.dentry, old_path.mnt, to)) {
59274+ error = -EACCES;
59275+ goto out_dput;
59276+ }
59277+
59278 error = security_path_link(old_path.dentry, &new_path, new_dentry);
59279 if (error)
59280 goto out_dput;
59281 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
59282+ if (!error)
59283+ gr_handle_create(new_dentry, new_path.mnt);
59284 out_dput:
59285+ putname(to);
59286 done_path_create(&new_path, new_dentry);
59287 if (retry_estale(error, how)) {
59288 how |= LOOKUP_REVAL;
59289@@ -4167,12 +4351,21 @@ retry:
59290 if (new_dentry == trap)
59291 goto exit5;
59292
59293+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
59294+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
59295+ to);
59296+ if (error)
59297+ goto exit5;
59298+
59299 error = security_path_rename(&oldnd.path, old_dentry,
59300 &newnd.path, new_dentry);
59301 if (error)
59302 goto exit5;
59303 error = vfs_rename(old_dir->d_inode, old_dentry,
59304 new_dir->d_inode, new_dentry);
59305+ if (!error)
59306+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
59307+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
59308 exit5:
59309 dput(new_dentry);
59310 exit4:
59311@@ -4204,6 +4397,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
59312
59313 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
59314 {
59315+ char tmpbuf[64];
59316+ const char *newlink;
59317 int len;
59318
59319 len = PTR_ERR(link);
59320@@ -4213,7 +4408,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
59321 len = strlen(link);
59322 if (len > (unsigned) buflen)
59323 len = buflen;
59324- if (copy_to_user(buffer, link, len))
59325+
59326+ if (len < sizeof(tmpbuf)) {
59327+ memcpy(tmpbuf, link, len);
59328+ newlink = tmpbuf;
59329+ } else
59330+ newlink = link;
59331+
59332+ if (copy_to_user(buffer, newlink, len))
59333 len = -EFAULT;
59334 out:
59335 return len;
59336diff --git a/fs/namespace.c b/fs/namespace.c
59337index da5c494..a755a54 100644
59338--- a/fs/namespace.c
59339+++ b/fs/namespace.c
59340@@ -1268,6 +1268,9 @@ static int do_umount(struct mount *mnt, int flags)
59341 if (!(sb->s_flags & MS_RDONLY))
59342 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
59343 up_write(&sb->s_umount);
59344+
59345+ gr_log_remount(mnt->mnt_devname, retval);
59346+
59347 return retval;
59348 }
59349
59350@@ -1286,6 +1289,9 @@ static int do_umount(struct mount *mnt, int flags)
59351 }
59352 br_write_unlock(&vfsmount_lock);
59353 namespace_unlock();
59354+
59355+ gr_log_unmount(mnt->mnt_devname, retval);
59356+
59357 return retval;
59358 }
59359
59360@@ -1305,7 +1311,7 @@ static inline bool may_mount(void)
59361 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
59362 */
59363
59364-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
59365+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
59366 {
59367 struct path path;
59368 struct mount *mnt;
59369@@ -1347,7 +1353,7 @@ out:
59370 /*
59371 * The 2.0 compatible umount. No flags.
59372 */
59373-SYSCALL_DEFINE1(oldumount, char __user *, name)
59374+SYSCALL_DEFINE1(oldumount, const char __user *, name)
59375 {
59376 return sys_umount(name, 0);
59377 }
59378@@ -2358,6 +2364,16 @@ long do_mount(const char *dev_name, const char *dir_name,
59379 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
59380 MS_STRICTATIME);
59381
59382+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
59383+ retval = -EPERM;
59384+ goto dput_out;
59385+ }
59386+
59387+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
59388+ retval = -EPERM;
59389+ goto dput_out;
59390+ }
59391+
59392 if (flags & MS_REMOUNT)
59393 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
59394 data_page);
59395@@ -2372,6 +2388,9 @@ long do_mount(const char *dev_name, const char *dir_name,
59396 dev_name, data_page);
59397 dput_out:
59398 path_put(&path);
59399+
59400+ gr_log_mount(dev_name, dir_name, retval);
59401+
59402 return retval;
59403 }
59404
59405@@ -2389,7 +2408,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
59406 * number incrementing at 10Ghz will take 12,427 years to wrap which
59407 * is effectively never, so we can ignore the possibility.
59408 */
59409-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
59410+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
59411
59412 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59413 {
59414@@ -2404,7 +2423,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59415 kfree(new_ns);
59416 return ERR_PTR(ret);
59417 }
59418- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
59419+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
59420 atomic_set(&new_ns->count, 1);
59421 new_ns->root = NULL;
59422 INIT_LIST_HEAD(&new_ns->list);
59423@@ -2418,7 +2437,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59424 * Allocate a new namespace structure and populate it with contents
59425 * copied from the namespace of the passed in task structure.
59426 */
59427-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
59428+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
59429 struct user_namespace *user_ns, struct fs_struct *fs)
59430 {
59431 struct mnt_namespace *new_ns;
59432@@ -2549,8 +2568,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
59433 }
59434 EXPORT_SYMBOL(mount_subtree);
59435
59436-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
59437- char __user *, type, unsigned long, flags, void __user *, data)
59438+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
59439+ const char __user *, type, unsigned long, flags, void __user *, data)
59440 {
59441 int ret;
59442 char *kernel_type;
59443@@ -2663,6 +2682,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
59444 if (error)
59445 goto out2;
59446
59447+ if (gr_handle_chroot_pivot()) {
59448+ error = -EPERM;
59449+ goto out2;
59450+ }
59451+
59452 get_fs_root(current->fs, &root);
59453 old_mp = lock_mount(&old);
59454 error = PTR_ERR(old_mp);
59455@@ -2932,7 +2956,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
59456 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
59457 return -EPERM;
59458
59459- if (fs->users != 1)
59460+ if (atomic_read(&fs->users) != 1)
59461 return -EINVAL;
59462
59463 get_mnt_ns(mnt_ns);
59464diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
59465index f4ccfe6..a5cf064 100644
59466--- a/fs/nfs/callback_xdr.c
59467+++ b/fs/nfs/callback_xdr.c
59468@@ -51,7 +51,7 @@ struct callback_op {
59469 callback_decode_arg_t decode_args;
59470 callback_encode_res_t encode_res;
59471 long res_maxsize;
59472-};
59473+} __do_const;
59474
59475 static struct callback_op callback_ops[];
59476
59477diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
59478index eda8879..bfc6837 100644
59479--- a/fs/nfs/inode.c
59480+++ b/fs/nfs/inode.c
59481@@ -1150,16 +1150,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
59482 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
59483 }
59484
59485-static atomic_long_t nfs_attr_generation_counter;
59486+static atomic_long_unchecked_t nfs_attr_generation_counter;
59487
59488 static unsigned long nfs_read_attr_generation_counter(void)
59489 {
59490- return atomic_long_read(&nfs_attr_generation_counter);
59491+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
59492 }
59493
59494 unsigned long nfs_inc_attr_generation_counter(void)
59495 {
59496- return atomic_long_inc_return(&nfs_attr_generation_counter);
59497+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
59498 }
59499
59500 void nfs_fattr_init(struct nfs_fattr *fattr)
59501diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
59502index 419572f..5414a23 100644
59503--- a/fs/nfsd/nfs4proc.c
59504+++ b/fs/nfsd/nfs4proc.c
59505@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
59506 nfsd4op_rsize op_rsize_bop;
59507 stateid_getter op_get_currentstateid;
59508 stateid_setter op_set_currentstateid;
59509-};
59510+} __do_const;
59511
59512 static struct nfsd4_operation nfsd4_ops[];
59513
59514diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
59515index ecc735e..79b2d31 100644
59516--- a/fs/nfsd/nfs4xdr.c
59517+++ b/fs/nfsd/nfs4xdr.c
59518@@ -1500,7 +1500,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
59519
59520 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
59521
59522-static nfsd4_dec nfsd4_dec_ops[] = {
59523+static const nfsd4_dec nfsd4_dec_ops[] = {
59524 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59525 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59526 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59527@@ -1540,7 +1540,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
59528 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
59529 };
59530
59531-static nfsd4_dec nfsd41_dec_ops[] = {
59532+static const nfsd4_dec nfsd41_dec_ops[] = {
59533 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59534 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59535 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59536@@ -1602,7 +1602,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
59537 };
59538
59539 struct nfsd4_minorversion_ops {
59540- nfsd4_dec *decoders;
59541+ const nfsd4_dec *decoders;
59542 int nops;
59543 };
59544
59545diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
59546index 9186c7c..3fdde3e 100644
59547--- a/fs/nfsd/nfscache.c
59548+++ b/fs/nfsd/nfscache.c
59549@@ -540,14 +540,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
59550 {
59551 struct svc_cacherep *rp = rqstp->rq_cacherep;
59552 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
59553- int len;
59554+ long len;
59555 size_t bufsize = 0;
59556
59557 if (!rp)
59558 return;
59559
59560- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
59561- len >>= 2;
59562+ if (statp) {
59563+ len = (char*)statp - (char*)resv->iov_base;
59564+ len = resv->iov_len - len;
59565+ len >>= 2;
59566+ }
59567
59568 /* Don't cache excessive amounts of data and XDR failures */
59569 if (!statp || len > (256 >> 2)) {
59570diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
59571index 72cb28e..5b5f87d 100644
59572--- a/fs/nfsd/vfs.c
59573+++ b/fs/nfsd/vfs.c
59574@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59575 } else {
59576 oldfs = get_fs();
59577 set_fs(KERNEL_DS);
59578- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
59579+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
59580 set_fs(oldfs);
59581 }
59582
59583@@ -1080,7 +1080,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59584
59585 /* Write the data. */
59586 oldfs = get_fs(); set_fs(KERNEL_DS);
59587- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
59588+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
59589 set_fs(oldfs);
59590 if (host_err < 0)
59591 goto out_nfserr;
59592@@ -1626,7 +1626,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
59593 */
59594
59595 oldfs = get_fs(); set_fs(KERNEL_DS);
59596- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
59597+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
59598 set_fs(oldfs);
59599
59600 if (host_err < 0)
59601diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
59602index fea6bd5..8ee9d81 100644
59603--- a/fs/nls/nls_base.c
59604+++ b/fs/nls/nls_base.c
59605@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
59606
59607 int register_nls(struct nls_table * nls)
59608 {
59609- struct nls_table ** tmp = &tables;
59610+ struct nls_table *tmp = tables;
59611
59612 if (nls->next)
59613 return -EBUSY;
59614
59615 spin_lock(&nls_lock);
59616- while (*tmp) {
59617- if (nls == *tmp) {
59618+ while (tmp) {
59619+ if (nls == tmp) {
59620 spin_unlock(&nls_lock);
59621 return -EBUSY;
59622 }
59623- tmp = &(*tmp)->next;
59624+ tmp = tmp->next;
59625 }
59626- nls->next = tables;
59627+ pax_open_kernel();
59628+ *(struct nls_table **)&nls->next = tables;
59629+ pax_close_kernel();
59630 tables = nls;
59631 spin_unlock(&nls_lock);
59632 return 0;
59633@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
59634
59635 int unregister_nls(struct nls_table * nls)
59636 {
59637- struct nls_table ** tmp = &tables;
59638+ struct nls_table * const * tmp = &tables;
59639
59640 spin_lock(&nls_lock);
59641 while (*tmp) {
59642 if (nls == *tmp) {
59643- *tmp = nls->next;
59644+ pax_open_kernel();
59645+ *(struct nls_table **)tmp = nls->next;
59646+ pax_close_kernel();
59647 spin_unlock(&nls_lock);
59648 return 0;
59649 }
59650diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
59651index 7424929..35f6be5 100644
59652--- a/fs/nls/nls_euc-jp.c
59653+++ b/fs/nls/nls_euc-jp.c
59654@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
59655 p_nls = load_nls("cp932");
59656
59657 if (p_nls) {
59658- table.charset2upper = p_nls->charset2upper;
59659- table.charset2lower = p_nls->charset2lower;
59660+ pax_open_kernel();
59661+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59662+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59663+ pax_close_kernel();
59664 return register_nls(&table);
59665 }
59666
59667diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
59668index e7bc1d7..06bd4bb 100644
59669--- a/fs/nls/nls_koi8-ru.c
59670+++ b/fs/nls/nls_koi8-ru.c
59671@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
59672 p_nls = load_nls("koi8-u");
59673
59674 if (p_nls) {
59675- table.charset2upper = p_nls->charset2upper;
59676- table.charset2lower = p_nls->charset2lower;
59677+ pax_open_kernel();
59678+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59679+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59680+ pax_close_kernel();
59681 return register_nls(&table);
59682 }
59683
59684diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
59685index e44cb64..4807084 100644
59686--- a/fs/notify/fanotify/fanotify_user.c
59687+++ b/fs/notify/fanotify/fanotify_user.c
59688@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
59689
59690 fd = fanotify_event_metadata.fd;
59691 ret = -EFAULT;
59692- if (copy_to_user(buf, &fanotify_event_metadata,
59693- fanotify_event_metadata.event_len))
59694+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
59695+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
59696 goto out_close_fd;
59697
59698 ret = prepare_for_access_response(group, event, fd);
59699diff --git a/fs/notify/notification.c b/fs/notify/notification.c
59700index 7b51b05..5ea5ef6 100644
59701--- a/fs/notify/notification.c
59702+++ b/fs/notify/notification.c
59703@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
59704 * get set to 0 so it will never get 'freed'
59705 */
59706 static struct fsnotify_event *q_overflow_event;
59707-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59708+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59709
59710 /**
59711 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
59712@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59713 */
59714 u32 fsnotify_get_cookie(void)
59715 {
59716- return atomic_inc_return(&fsnotify_sync_cookie);
59717+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
59718 }
59719 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
59720
59721diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
59722index 9e38daf..5727cae 100644
59723--- a/fs/ntfs/dir.c
59724+++ b/fs/ntfs/dir.c
59725@@ -1310,7 +1310,7 @@ find_next_index_buffer:
59726 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
59727 ~(s64)(ndir->itype.index.block_size - 1)));
59728 /* Bounds checks. */
59729- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59730+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59731 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
59732 "inode 0x%lx or driver bug.", vdir->i_ino);
59733 goto err_out;
59734diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
59735index ea4ba9d..1e13d34 100644
59736--- a/fs/ntfs/file.c
59737+++ b/fs/ntfs/file.c
59738@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
59739 char *addr;
59740 size_t total = 0;
59741 unsigned len;
59742- int left;
59743+ unsigned left;
59744
59745 do {
59746 len = PAGE_CACHE_SIZE - ofs;
59747diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
59748index 82650d5..db37dcf 100644
59749--- a/fs/ntfs/super.c
59750+++ b/fs/ntfs/super.c
59751@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59752 if (!silent)
59753 ntfs_error(sb, "Primary boot sector is invalid.");
59754 } else if (!silent)
59755- ntfs_error(sb, read_err_str, "primary");
59756+ ntfs_error(sb, read_err_str, "%s", "primary");
59757 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
59758 if (bh_primary)
59759 brelse(bh_primary);
59760@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59761 goto hotfix_primary_boot_sector;
59762 brelse(bh_backup);
59763 } else if (!silent)
59764- ntfs_error(sb, read_err_str, "backup");
59765+ ntfs_error(sb, read_err_str, "%s", "backup");
59766 /* Try to read NT3.51- backup boot sector. */
59767 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
59768 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
59769@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59770 "sector.");
59771 brelse(bh_backup);
59772 } else if (!silent)
59773- ntfs_error(sb, read_err_str, "backup");
59774+ ntfs_error(sb, read_err_str, "%s", "backup");
59775 /* We failed. Cleanup and return. */
59776 if (bh_primary)
59777 brelse(bh_primary);
59778diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
59779index cd5496b..26a1055 100644
59780--- a/fs/ocfs2/localalloc.c
59781+++ b/fs/ocfs2/localalloc.c
59782@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
59783 goto bail;
59784 }
59785
59786- atomic_inc(&osb->alloc_stats.moves);
59787+ atomic_inc_unchecked(&osb->alloc_stats.moves);
59788
59789 bail:
59790 if (handle)
59791diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
59792index 3a90347..c40bef8 100644
59793--- a/fs/ocfs2/ocfs2.h
59794+++ b/fs/ocfs2/ocfs2.h
59795@@ -235,11 +235,11 @@ enum ocfs2_vol_state
59796
59797 struct ocfs2_alloc_stats
59798 {
59799- atomic_t moves;
59800- atomic_t local_data;
59801- atomic_t bitmap_data;
59802- atomic_t bg_allocs;
59803- atomic_t bg_extends;
59804+ atomic_unchecked_t moves;
59805+ atomic_unchecked_t local_data;
59806+ atomic_unchecked_t bitmap_data;
59807+ atomic_unchecked_t bg_allocs;
59808+ atomic_unchecked_t bg_extends;
59809 };
59810
59811 enum ocfs2_local_alloc_state
59812diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
59813index 5397c07..54afc55 100644
59814--- a/fs/ocfs2/suballoc.c
59815+++ b/fs/ocfs2/suballoc.c
59816@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
59817 mlog_errno(status);
59818 goto bail;
59819 }
59820- atomic_inc(&osb->alloc_stats.bg_extends);
59821+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
59822
59823 /* You should never ask for this much metadata */
59824 BUG_ON(bits_wanted >
59825@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
59826 mlog_errno(status);
59827 goto bail;
59828 }
59829- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59830+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59831
59832 *suballoc_loc = res.sr_bg_blkno;
59833 *suballoc_bit_start = res.sr_bit_offset;
59834@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59835 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59836 res->sr_bits);
59837
59838- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59839+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59840
59841 BUG_ON(res->sr_bits != 1);
59842
59843@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59844 mlog_errno(status);
59845 goto bail;
59846 }
59847- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59848+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59849
59850 BUG_ON(res.sr_bits != 1);
59851
59852@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59853 cluster_start,
59854 num_clusters);
59855 if (!status)
59856- atomic_inc(&osb->alloc_stats.local_data);
59857+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59858 } else {
59859 if (min_clusters > (osb->bitmap_cpg - 1)) {
59860 /* The only paths asking for contiguousness
59861@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59862 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59863 res.sr_bg_blkno,
59864 res.sr_bit_offset);
59865- atomic_inc(&osb->alloc_stats.bitmap_data);
59866+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59867 *num_clusters = res.sr_bits;
59868 }
59869 }
59870diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59871index d4e81e4..ad89f5f 100644
59872--- a/fs/ocfs2/super.c
59873+++ b/fs/ocfs2/super.c
59874@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59875 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59876 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59877 "Stats",
59878- atomic_read(&osb->alloc_stats.bitmap_data),
59879- atomic_read(&osb->alloc_stats.local_data),
59880- atomic_read(&osb->alloc_stats.bg_allocs),
59881- atomic_read(&osb->alloc_stats.moves),
59882- atomic_read(&osb->alloc_stats.bg_extends));
59883+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59884+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59885+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59886+ atomic_read_unchecked(&osb->alloc_stats.moves),
59887+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59888
59889 out += snprintf(buf + out, len - out,
59890 "%10s => State: %u Descriptor: %llu Size: %u bits "
59891@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59892 spin_lock_init(&osb->osb_xattr_lock);
59893 ocfs2_init_steal_slots(osb);
59894
59895- atomic_set(&osb->alloc_stats.moves, 0);
59896- atomic_set(&osb->alloc_stats.local_data, 0);
59897- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59898- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59899- atomic_set(&osb->alloc_stats.bg_extends, 0);
59900+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59901+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59902+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59903+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59904+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59905
59906 /* Copy the blockcheck stats from the superblock probe */
59907 osb->osb_ecc_stats = *stats;
59908diff --git a/fs/open.c b/fs/open.c
59909index d420331..2dbb3fd 100644
59910--- a/fs/open.c
59911+++ b/fs/open.c
59912@@ -32,6 +32,8 @@
59913 #include <linux/dnotify.h>
59914 #include <linux/compat.h>
59915
59916+#define CREATE_TRACE_POINTS
59917+#include <trace/events/fs.h>
59918 #include "internal.h"
59919
59920 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59921@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59922 error = locks_verify_truncate(inode, NULL, length);
59923 if (!error)
59924 error = security_path_truncate(path);
59925+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59926+ error = -EACCES;
59927 if (!error)
59928 error = do_truncate(path->dentry, length, 0, NULL);
59929
59930@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59931 error = locks_verify_truncate(inode, f.file, length);
59932 if (!error)
59933 error = security_path_truncate(&f.file->f_path);
59934+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59935+ error = -EACCES;
59936 if (!error)
59937 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59938 sb_end_write(inode->i_sb);
59939@@ -360,6 +366,9 @@ retry:
59940 if (__mnt_is_readonly(path.mnt))
59941 res = -EROFS;
59942
59943+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59944+ res = -EACCES;
59945+
59946 out_path_release:
59947 path_put(&path);
59948 if (retry_estale(res, lookup_flags)) {
59949@@ -391,6 +400,8 @@ retry:
59950 if (error)
59951 goto dput_and_out;
59952
59953+ gr_log_chdir(path.dentry, path.mnt);
59954+
59955 set_fs_pwd(current->fs, &path);
59956
59957 dput_and_out:
59958@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59959 goto out_putf;
59960
59961 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59962+
59963+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59964+ error = -EPERM;
59965+
59966+ if (!error)
59967+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59968+
59969 if (!error)
59970 set_fs_pwd(current->fs, &f.file->f_path);
59971 out_putf:
59972@@ -449,7 +467,13 @@ retry:
59973 if (error)
59974 goto dput_and_out;
59975
59976+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59977+ goto dput_and_out;
59978+
59979 set_fs_root(current->fs, &path);
59980+
59981+ gr_handle_chroot_chdir(&path);
59982+
59983 error = 0;
59984 dput_and_out:
59985 path_put(&path);
59986@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59987 if (error)
59988 return error;
59989 mutex_lock(&inode->i_mutex);
59990+
59991+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59992+ error = -EACCES;
59993+ goto out_unlock;
59994+ }
59995+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59996+ error = -EACCES;
59997+ goto out_unlock;
59998+ }
59999+
60000 error = security_path_chmod(path, mode);
60001 if (error)
60002 goto out_unlock;
60003@@ -530,6 +564,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
60004 uid = make_kuid(current_user_ns(), user);
60005 gid = make_kgid(current_user_ns(), group);
60006
60007+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
60008+ return -EACCES;
60009+
60010 newattrs.ia_valid = ATTR_CTIME;
60011 if (user != (uid_t) -1) {
60012 if (!uid_valid(uid))
60013@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
60014 } else {
60015 fsnotify_open(f);
60016 fd_install(fd, f);
60017+ trace_do_sys_open(tmp->name, flags, mode);
60018 }
60019 }
60020 putname(tmp);
60021diff --git a/fs/pipe.c b/fs/pipe.c
60022index 0e0752e..7cfdd50 100644
60023--- a/fs/pipe.c
60024+++ b/fs/pipe.c
60025@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
60026
60027 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
60028 {
60029- if (pipe->files)
60030+ if (atomic_read(&pipe->files))
60031 mutex_lock_nested(&pipe->mutex, subclass);
60032 }
60033
60034@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
60035
60036 void pipe_unlock(struct pipe_inode_info *pipe)
60037 {
60038- if (pipe->files)
60039+ if (atomic_read(&pipe->files))
60040 mutex_unlock(&pipe->mutex);
60041 }
60042 EXPORT_SYMBOL(pipe_unlock);
60043@@ -449,9 +449,9 @@ redo:
60044 }
60045 if (bufs) /* More to do? */
60046 continue;
60047- if (!pipe->writers)
60048+ if (!atomic_read(&pipe->writers))
60049 break;
60050- if (!pipe->waiting_writers) {
60051+ if (!atomic_read(&pipe->waiting_writers)) {
60052 /* syscall merging: Usually we must not sleep
60053 * if O_NONBLOCK is set, or if we got some data.
60054 * But if a writer sleeps in kernel space, then
60055@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
60056 ret = 0;
60057 __pipe_lock(pipe);
60058
60059- if (!pipe->readers) {
60060+ if (!atomic_read(&pipe->readers)) {
60061 send_sig(SIGPIPE, current, 0);
60062 ret = -EPIPE;
60063 goto out;
60064@@ -562,7 +562,7 @@ redo1:
60065 for (;;) {
60066 int bufs;
60067
60068- if (!pipe->readers) {
60069+ if (!atomic_read(&pipe->readers)) {
60070 send_sig(SIGPIPE, current, 0);
60071 if (!ret)
60072 ret = -EPIPE;
60073@@ -653,9 +653,9 @@ redo2:
60074 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60075 do_wakeup = 0;
60076 }
60077- pipe->waiting_writers++;
60078+ atomic_inc(&pipe->waiting_writers);
60079 pipe_wait(pipe);
60080- pipe->waiting_writers--;
60081+ atomic_dec(&pipe->waiting_writers);
60082 }
60083 out:
60084 __pipe_unlock(pipe);
60085@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
60086 mask = 0;
60087 if (filp->f_mode & FMODE_READ) {
60088 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
60089- if (!pipe->writers && filp->f_version != pipe->w_counter)
60090+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
60091 mask |= POLLHUP;
60092 }
60093
60094@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
60095 * Most Unices do not set POLLERR for FIFOs but on Linux they
60096 * behave exactly like pipes for poll().
60097 */
60098- if (!pipe->readers)
60099+ if (!atomic_read(&pipe->readers))
60100 mask |= POLLERR;
60101 }
60102
60103@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
60104 int kill = 0;
60105
60106 spin_lock(&inode->i_lock);
60107- if (!--pipe->files) {
60108+ if (atomic_dec_and_test(&pipe->files)) {
60109 inode->i_pipe = NULL;
60110 kill = 1;
60111 }
60112@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
60113
60114 __pipe_lock(pipe);
60115 if (file->f_mode & FMODE_READ)
60116- pipe->readers--;
60117+ atomic_dec(&pipe->readers);
60118 if (file->f_mode & FMODE_WRITE)
60119- pipe->writers--;
60120+ atomic_dec(&pipe->writers);
60121
60122- if (pipe->readers || pipe->writers) {
60123+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
60124 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
60125 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60126 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
60127@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
60128 kfree(pipe);
60129 }
60130
60131-static struct vfsmount *pipe_mnt __read_mostly;
60132+struct vfsmount *pipe_mnt __read_mostly;
60133
60134 /*
60135 * pipefs_dname() is called from d_path().
60136@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
60137 goto fail_iput;
60138
60139 inode->i_pipe = pipe;
60140- pipe->files = 2;
60141- pipe->readers = pipe->writers = 1;
60142+ atomic_set(&pipe->files, 2);
60143+ atomic_set(&pipe->readers, 1);
60144+ atomic_set(&pipe->writers, 1);
60145 inode->i_fop = &pipefifo_fops;
60146
60147 /*
60148@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
60149 spin_lock(&inode->i_lock);
60150 if (inode->i_pipe) {
60151 pipe = inode->i_pipe;
60152- pipe->files++;
60153+ atomic_inc(&pipe->files);
60154 spin_unlock(&inode->i_lock);
60155 } else {
60156 spin_unlock(&inode->i_lock);
60157 pipe = alloc_pipe_info();
60158 if (!pipe)
60159 return -ENOMEM;
60160- pipe->files = 1;
60161+ atomic_set(&pipe->files, 1);
60162 spin_lock(&inode->i_lock);
60163 if (unlikely(inode->i_pipe)) {
60164- inode->i_pipe->files++;
60165+ atomic_inc(&inode->i_pipe->files);
60166 spin_unlock(&inode->i_lock);
60167 free_pipe_info(pipe);
60168 pipe = inode->i_pipe;
60169@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
60170 * opened, even when there is no process writing the FIFO.
60171 */
60172 pipe->r_counter++;
60173- if (pipe->readers++ == 0)
60174+ if (atomic_inc_return(&pipe->readers) == 1)
60175 wake_up_partner(pipe);
60176
60177- if (!is_pipe && !pipe->writers) {
60178+ if (!is_pipe && !atomic_read(&pipe->writers)) {
60179 if ((filp->f_flags & O_NONBLOCK)) {
60180 /* suppress POLLHUP until we have
60181 * seen a writer */
60182@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
60183 * errno=ENXIO when there is no process reading the FIFO.
60184 */
60185 ret = -ENXIO;
60186- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
60187+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
60188 goto err;
60189
60190 pipe->w_counter++;
60191- if (!pipe->writers++)
60192+ if (atomic_inc_return(&pipe->writers) == 1)
60193 wake_up_partner(pipe);
60194
60195- if (!is_pipe && !pipe->readers) {
60196+ if (!is_pipe && !atomic_read(&pipe->readers)) {
60197 if (wait_for_partner(pipe, &pipe->r_counter))
60198 goto err_wr;
60199 }
60200@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
60201 * the process can at least talk to itself.
60202 */
60203
60204- pipe->readers++;
60205- pipe->writers++;
60206+ atomic_inc(&pipe->readers);
60207+ atomic_inc(&pipe->writers);
60208 pipe->r_counter++;
60209 pipe->w_counter++;
60210- if (pipe->readers == 1 || pipe->writers == 1)
60211+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
60212 wake_up_partner(pipe);
60213 break;
60214
60215@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
60216 return 0;
60217
60218 err_rd:
60219- if (!--pipe->readers)
60220+ if (atomic_dec_and_test(&pipe->readers))
60221 wake_up_interruptible(&pipe->wait);
60222 ret = -ERESTARTSYS;
60223 goto err;
60224
60225 err_wr:
60226- if (!--pipe->writers)
60227+ if (atomic_dec_and_test(&pipe->writers))
60228 wake_up_interruptible(&pipe->wait);
60229 ret = -ERESTARTSYS;
60230 goto err;
60231diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
60232index 15af622..0e9f4467 100644
60233--- a/fs/proc/Kconfig
60234+++ b/fs/proc/Kconfig
60235@@ -30,12 +30,12 @@ config PROC_FS
60236
60237 config PROC_KCORE
60238 bool "/proc/kcore support" if !ARM
60239- depends on PROC_FS && MMU
60240+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
60241
60242 config PROC_VMCORE
60243 bool "/proc/vmcore support"
60244- depends on PROC_FS && CRASH_DUMP
60245- default y
60246+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
60247+ default n
60248 help
60249 Exports the dump image of crashed kernel in ELF format.
60250
60251@@ -59,8 +59,8 @@ config PROC_SYSCTL
60252 limited in memory.
60253
60254 config PROC_PAGE_MONITOR
60255- default y
60256- depends on PROC_FS && MMU
60257+ default n
60258+ depends on PROC_FS && MMU && !GRKERNSEC
60259 bool "Enable /proc page monitoring" if EXPERT
60260 help
60261 Various /proc files exist to monitor process memory utilization:
60262diff --git a/fs/proc/array.c b/fs/proc/array.c
60263index cbd0f1b..adec3f0 100644
60264--- a/fs/proc/array.c
60265+++ b/fs/proc/array.c
60266@@ -60,6 +60,7 @@
60267 #include <linux/tty.h>
60268 #include <linux/string.h>
60269 #include <linux/mman.h>
60270+#include <linux/grsecurity.h>
60271 #include <linux/proc_fs.h>
60272 #include <linux/ioport.h>
60273 #include <linux/uaccess.h>
60274@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
60275 seq_putc(m, '\n');
60276 }
60277
60278+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60279+static inline void task_pax(struct seq_file *m, struct task_struct *p)
60280+{
60281+ if (p->mm)
60282+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
60283+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
60284+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
60285+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
60286+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
60287+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
60288+ else
60289+ seq_printf(m, "PaX:\t-----\n");
60290+}
60291+#endif
60292+
60293 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60294 struct pid *pid, struct task_struct *task)
60295 {
60296@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60297 task_cpus_allowed(m, task);
60298 cpuset_task_status_allowed(m, task);
60299 task_context_switch_counts(m, task);
60300+
60301+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60302+ task_pax(m, task);
60303+#endif
60304+
60305+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
60306+ task_grsec_rbac(m, task);
60307+#endif
60308+
60309 return 0;
60310 }
60311
60312+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60313+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60314+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60315+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60316+#endif
60317+
60318 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60319 struct pid *pid, struct task_struct *task, int whole)
60320 {
60321@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60322 char tcomm[sizeof(task->comm)];
60323 unsigned long flags;
60324
60325+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60326+ if (current->exec_id != m->exec_id) {
60327+ gr_log_badprocpid("stat");
60328+ return 0;
60329+ }
60330+#endif
60331+
60332 state = *get_task_state(task);
60333 vsize = eip = esp = 0;
60334 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60335@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60336 gtime = task_gtime(task);
60337 }
60338
60339+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60340+ if (PAX_RAND_FLAGS(mm)) {
60341+ eip = 0;
60342+ esp = 0;
60343+ wchan = 0;
60344+ }
60345+#endif
60346+#ifdef CONFIG_GRKERNSEC_HIDESYM
60347+ wchan = 0;
60348+ eip =0;
60349+ esp =0;
60350+#endif
60351+
60352 /* scale priority and nice values from timeslices to -20..20 */
60353 /* to make it look like a "normal" Unix priority/nice value */
60354 priority = task_prio(task);
60355@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60356 seq_put_decimal_ull(m, ' ', vsize);
60357 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
60358 seq_put_decimal_ull(m, ' ', rsslim);
60359+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60360+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
60361+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
60362+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
60363+#else
60364 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
60365 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
60366 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
60367+#endif
60368 seq_put_decimal_ull(m, ' ', esp);
60369 seq_put_decimal_ull(m, ' ', eip);
60370 /* The signal information here is obsolete.
60371@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60372 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
60373 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
60374
60375- if (mm && permitted) {
60376+ if (mm && permitted
60377+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60378+ && !PAX_RAND_FLAGS(mm)
60379+#endif
60380+ ) {
60381 seq_put_decimal_ull(m, ' ', mm->start_data);
60382 seq_put_decimal_ull(m, ' ', mm->end_data);
60383 seq_put_decimal_ull(m, ' ', mm->start_brk);
60384@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60385 struct pid *pid, struct task_struct *task)
60386 {
60387 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
60388- struct mm_struct *mm = get_task_mm(task);
60389+ struct mm_struct *mm;
60390
60391+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60392+ if (current->exec_id != m->exec_id) {
60393+ gr_log_badprocpid("statm");
60394+ return 0;
60395+ }
60396+#endif
60397+ mm = get_task_mm(task);
60398 if (mm) {
60399 size = task_statm(mm, &shared, &text, &data, &resident);
60400 mmput(mm);
60401@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60402 return 0;
60403 }
60404
60405+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60406+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
60407+{
60408+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
60409+}
60410+#endif
60411+
60412 #ifdef CONFIG_CHECKPOINT_RESTORE
60413 static struct pid *
60414 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
60415diff --git a/fs/proc/base.c b/fs/proc/base.c
60416index 1485e38..8ad4236 100644
60417--- a/fs/proc/base.c
60418+++ b/fs/proc/base.c
60419@@ -113,6 +113,14 @@ struct pid_entry {
60420 union proc_op op;
60421 };
60422
60423+struct getdents_callback {
60424+ struct linux_dirent __user * current_dir;
60425+ struct linux_dirent __user * previous;
60426+ struct file * file;
60427+ int count;
60428+ int error;
60429+};
60430+
60431 #define NOD(NAME, MODE, IOP, FOP, OP) { \
60432 .name = (NAME), \
60433 .len = sizeof(NAME) - 1, \
60434@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
60435 if (!mm->arg_end)
60436 goto out_mm; /* Shh! No looking before we're done */
60437
60438+ if (gr_acl_handle_procpidmem(task))
60439+ goto out_mm;
60440+
60441 len = mm->arg_end - mm->arg_start;
60442
60443 if (len > PAGE_SIZE)
60444@@ -237,12 +248,28 @@ out:
60445 return res;
60446 }
60447
60448+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60449+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60450+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60451+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60452+#endif
60453+
60454 static int proc_pid_auxv(struct task_struct *task, char *buffer)
60455 {
60456 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
60457 int res = PTR_ERR(mm);
60458 if (mm && !IS_ERR(mm)) {
60459 unsigned int nwords = 0;
60460+
60461+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60462+ /* allow if we're currently ptracing this task */
60463+ if (PAX_RAND_FLAGS(mm) &&
60464+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
60465+ mmput(mm);
60466+ return 0;
60467+ }
60468+#endif
60469+
60470 do {
60471 nwords += 2;
60472 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
60473@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
60474 }
60475
60476
60477-#ifdef CONFIG_KALLSYMS
60478+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60479 /*
60480 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
60481 * Returns the resolved symbol. If that fails, simply return the address.
60482@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
60483 mutex_unlock(&task->signal->cred_guard_mutex);
60484 }
60485
60486-#ifdef CONFIG_STACKTRACE
60487+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60488
60489 #define MAX_STACK_TRACE_DEPTH 64
60490
60491@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
60492 return count;
60493 }
60494
60495-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60496+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60497 static int proc_pid_syscall(struct task_struct *task, char *buffer)
60498 {
60499 long nr;
60500@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
60501 /************************************************************************/
60502
60503 /* permission checks */
60504-static int proc_fd_access_allowed(struct inode *inode)
60505+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
60506 {
60507 struct task_struct *task;
60508 int allowed = 0;
60509@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
60510 */
60511 task = get_proc_task(inode);
60512 if (task) {
60513- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60514+ if (log)
60515+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60516+ else
60517+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60518 put_task_struct(task);
60519 }
60520 return allowed;
60521@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
60522 struct task_struct *task,
60523 int hide_pid_min)
60524 {
60525+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60526+ return false;
60527+
60528+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60529+ rcu_read_lock();
60530+ {
60531+ const struct cred *tmpcred = current_cred();
60532+ const struct cred *cred = __task_cred(task);
60533+
60534+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
60535+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60536+ || in_group_p(grsec_proc_gid)
60537+#endif
60538+ ) {
60539+ rcu_read_unlock();
60540+ return true;
60541+ }
60542+ }
60543+ rcu_read_unlock();
60544+
60545+ if (!pid->hide_pid)
60546+ return false;
60547+#endif
60548+
60549 if (pid->hide_pid < hide_pid_min)
60550 return true;
60551 if (in_group_p(pid->pid_gid))
60552 return true;
60553+
60554 return ptrace_may_access(task, PTRACE_MODE_READ);
60555 }
60556
60557@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
60558 put_task_struct(task);
60559
60560 if (!has_perms) {
60561+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60562+ {
60563+#else
60564 if (pid->hide_pid == 2) {
60565+#endif
60566 /*
60567 * Let's make getdents(), stat(), and open()
60568 * consistent with each other. If a process
60569@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60570 if (!task)
60571 return -ESRCH;
60572
60573+ if (gr_acl_handle_procpidmem(task)) {
60574+ put_task_struct(task);
60575+ return -EPERM;
60576+ }
60577+
60578 mm = mm_access(task, mode);
60579 put_task_struct(task);
60580
60581@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60582
60583 file->private_data = mm;
60584
60585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60586+ file->f_version = current->exec_id;
60587+#endif
60588+
60589 return 0;
60590 }
60591
60592@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60593 ssize_t copied;
60594 char *page;
60595
60596+#ifdef CONFIG_GRKERNSEC
60597+ if (write)
60598+ return -EPERM;
60599+#endif
60600+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60601+ if (file->f_version != current->exec_id) {
60602+ gr_log_badprocpid("mem");
60603+ return 0;
60604+ }
60605+#endif
60606+
60607 if (!mm)
60608 return 0;
60609
60610@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60611 goto free;
60612
60613 while (count > 0) {
60614- int this_len = min_t(int, count, PAGE_SIZE);
60615+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
60616
60617 if (write && copy_from_user(page, buf, this_len)) {
60618 copied = -EFAULT;
60619@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60620 if (!mm)
60621 return 0;
60622
60623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60624+ if (file->f_version != current->exec_id) {
60625+ gr_log_badprocpid("environ");
60626+ return 0;
60627+ }
60628+#endif
60629+
60630 page = (char *)__get_free_page(GFP_TEMPORARY);
60631 if (!page)
60632 return -ENOMEM;
60633@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60634 goto free;
60635 while (count > 0) {
60636 size_t this_len, max_len;
60637- int retval;
60638+ ssize_t retval;
60639
60640 if (src >= (mm->env_end - mm->env_start))
60641 break;
60642@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
60643 int error = -EACCES;
60644
60645 /* Are we allowed to snoop on the tasks file descriptors? */
60646- if (!proc_fd_access_allowed(inode))
60647+ if (!proc_fd_access_allowed(inode, 0))
60648 goto out;
60649
60650 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60651@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
60652 struct path path;
60653
60654 /* Are we allowed to snoop on the tasks file descriptors? */
60655- if (!proc_fd_access_allowed(inode))
60656- goto out;
60657+ /* logging this is needed for learning on chromium to work properly,
60658+ but we don't want to flood the logs from 'ps' which does a readlink
60659+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
60660+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
60661+ */
60662+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
60663+ if (!proc_fd_access_allowed(inode,0))
60664+ goto out;
60665+ } else {
60666+ if (!proc_fd_access_allowed(inode,1))
60667+ goto out;
60668+ }
60669
60670 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60671 if (error)
60672@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
60673 rcu_read_lock();
60674 cred = __task_cred(task);
60675 inode->i_uid = cred->euid;
60676+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60677+ inode->i_gid = grsec_proc_gid;
60678+#else
60679 inode->i_gid = cred->egid;
60680+#endif
60681 rcu_read_unlock();
60682 }
60683 security_task_to_inode(task, inode);
60684@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
60685 return -ENOENT;
60686 }
60687 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60688+#ifdef CONFIG_GRKERNSEC_PROC_USER
60689+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60690+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60691+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60692+#endif
60693 task_dumpable(task)) {
60694 cred = __task_cred(task);
60695 stat->uid = cred->euid;
60696+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60697+ stat->gid = grsec_proc_gid;
60698+#else
60699 stat->gid = cred->egid;
60700+#endif
60701 }
60702 }
60703 rcu_read_unlock();
60704@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
60705
60706 if (task) {
60707 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60708+#ifdef CONFIG_GRKERNSEC_PROC_USER
60709+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60710+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60711+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60712+#endif
60713 task_dumpable(task)) {
60714 rcu_read_lock();
60715 cred = __task_cred(task);
60716 inode->i_uid = cred->euid;
60717+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60718+ inode->i_gid = grsec_proc_gid;
60719+#else
60720 inode->i_gid = cred->egid;
60721+#endif
60722 rcu_read_unlock();
60723 } else {
60724 inode->i_uid = GLOBAL_ROOT_UID;
60725@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
60726 if (!task)
60727 goto out_no_task;
60728
60729+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60730+ goto out;
60731+
60732 /*
60733 * Yes, it does not scale. And it should not. Don't add
60734 * new entries into /proc/<tgid>/ without very good reasons.
60735@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
60736 if (!task)
60737 return -ENOENT;
60738
60739+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60740+ goto out;
60741+
60742 if (!dir_emit_dots(file, ctx))
60743 goto out;
60744
60745@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
60746 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
60747 #endif
60748 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60749-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60750+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60751 INF("syscall", S_IRUGO, proc_pid_syscall),
60752 #endif
60753 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60754@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
60755 #ifdef CONFIG_SECURITY
60756 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60757 #endif
60758-#ifdef CONFIG_KALLSYMS
60759+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60760 INF("wchan", S_IRUGO, proc_pid_wchan),
60761 #endif
60762-#ifdef CONFIG_STACKTRACE
60763+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60764 ONE("stack", S_IRUGO, proc_pid_stack),
60765 #endif
60766 #ifdef CONFIG_SCHEDSTATS
60767@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
60768 #ifdef CONFIG_HARDWALL
60769 INF("hardwall", S_IRUGO, proc_pid_hardwall),
60770 #endif
60771+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60772+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
60773+#endif
60774 #ifdef CONFIG_USER_NS
60775 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
60776 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
60777@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
60778 if (!inode)
60779 goto out;
60780
60781+#ifdef CONFIG_GRKERNSEC_PROC_USER
60782+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
60783+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60784+ inode->i_gid = grsec_proc_gid;
60785+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
60786+#else
60787 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
60788+#endif
60789 inode->i_op = &proc_tgid_base_inode_operations;
60790 inode->i_fop = &proc_tgid_base_operations;
60791 inode->i_flags|=S_IMMUTABLE;
60792@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
60793 if (!task)
60794 goto out;
60795
60796+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60797+ goto out_put_task;
60798+
60799 result = proc_pid_instantiate(dir, dentry, task, NULL);
60800+out_put_task:
60801 put_task_struct(task);
60802 out:
60803 return ERR_PTR(result);
60804@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
60805 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
60806 #endif
60807 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60808-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60809+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60810 INF("syscall", S_IRUGO, proc_pid_syscall),
60811 #endif
60812 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60813@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
60814 #ifdef CONFIG_SECURITY
60815 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60816 #endif
60817-#ifdef CONFIG_KALLSYMS
60818+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60819 INF("wchan", S_IRUGO, proc_pid_wchan),
60820 #endif
60821-#ifdef CONFIG_STACKTRACE
60822+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60823 ONE("stack", S_IRUGO, proc_pid_stack),
60824 #endif
60825 #ifdef CONFIG_SCHEDSTATS
60826diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60827index 82676e3..5f8518a 100644
60828--- a/fs/proc/cmdline.c
60829+++ b/fs/proc/cmdline.c
60830@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60831
60832 static int __init proc_cmdline_init(void)
60833 {
60834+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60835+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60836+#else
60837 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60838+#endif
60839 return 0;
60840 }
60841 module_init(proc_cmdline_init);
60842diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60843index b143471..bb105e5 100644
60844--- a/fs/proc/devices.c
60845+++ b/fs/proc/devices.c
60846@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60847
60848 static int __init proc_devices_init(void)
60849 {
60850+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60851+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60852+#else
60853 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60854+#endif
60855 return 0;
60856 }
60857 module_init(proc_devices_init);
60858diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60859index 985ea88..d118a0a 100644
60860--- a/fs/proc/fd.c
60861+++ b/fs/proc/fd.c
60862@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60863 if (!task)
60864 return -ENOENT;
60865
60866- files = get_files_struct(task);
60867+ if (!gr_acl_handle_procpidmem(task))
60868+ files = get_files_struct(task);
60869 put_task_struct(task);
60870
60871 if (files) {
60872@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60873 */
60874 int proc_fd_permission(struct inode *inode, int mask)
60875 {
60876+ struct task_struct *task;
60877 int rv = generic_permission(inode, mask);
60878- if (rv == 0)
60879- return 0;
60880+
60881 if (task_tgid(current) == proc_pid(inode))
60882 rv = 0;
60883+
60884+ task = get_proc_task(inode);
60885+ if (task == NULL)
60886+ return rv;
60887+
60888+ if (gr_acl_handle_procpidmem(task))
60889+ rv = -EACCES;
60890+
60891+ put_task_struct(task);
60892+
60893 return rv;
60894 }
60895
60896diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60897index 8eaa1ba..cc6ff42 100644
60898--- a/fs/proc/inode.c
60899+++ b/fs/proc/inode.c
60900@@ -23,11 +23,17 @@
60901 #include <linux/slab.h>
60902 #include <linux/mount.h>
60903 #include <linux/magic.h>
60904+#include <linux/grsecurity.h>
60905
60906 #include <asm/uaccess.h>
60907
60908 #include "internal.h"
60909
60910+#ifdef CONFIG_PROC_SYSCTL
60911+extern const struct inode_operations proc_sys_inode_operations;
60912+extern const struct inode_operations proc_sys_dir_operations;
60913+#endif
60914+
60915 static void proc_evict_inode(struct inode *inode)
60916 {
60917 struct proc_dir_entry *de;
60918@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60919 ns = PROC_I(inode)->ns.ns;
60920 if (ns_ops && ns)
60921 ns_ops->put(ns);
60922+
60923+#ifdef CONFIG_PROC_SYSCTL
60924+ if (inode->i_op == &proc_sys_inode_operations ||
60925+ inode->i_op == &proc_sys_dir_operations)
60926+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60927+#endif
60928+
60929 }
60930
60931 static struct kmem_cache * proc_inode_cachep;
60932@@ -405,7 +418,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60933 if (de->mode) {
60934 inode->i_mode = de->mode;
60935 inode->i_uid = de->uid;
60936+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60937+ inode->i_gid = grsec_proc_gid;
60938+#else
60939 inode->i_gid = de->gid;
60940+#endif
60941 }
60942 if (de->size)
60943 inode->i_size = de->size;
60944diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60945index 651d09a..60c73ae 100644
60946--- a/fs/proc/internal.h
60947+++ b/fs/proc/internal.h
60948@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60949 struct pid *, struct task_struct *);
60950 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60951 struct pid *, struct task_struct *);
60952+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60953+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60954+#endif
60955
60956 /*
60957 * base.c
60958diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60959index 06ea155..9a798c7 100644
60960--- a/fs/proc/kcore.c
60961+++ b/fs/proc/kcore.c
60962@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60963 * the addresses in the elf_phdr on our list.
60964 */
60965 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60966- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60967+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60968+ if (tsz > buflen)
60969 tsz = buflen;
60970-
60971+
60972 while (buflen) {
60973 struct kcore_list *m;
60974
60975@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60976 kfree(elf_buf);
60977 } else {
60978 if (kern_addr_valid(start)) {
60979- unsigned long n;
60980+ char *elf_buf;
60981+ mm_segment_t oldfs;
60982
60983- n = copy_to_user(buffer, (char *)start, tsz);
60984- /*
60985- * We cannot distinguish between fault on source
60986- * and fault on destination. When this happens
60987- * we clear too and hope it will trigger the
60988- * EFAULT again.
60989- */
60990- if (n) {
60991- if (clear_user(buffer + tsz - n,
60992- n))
60993+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60994+ if (!elf_buf)
60995+ return -ENOMEM;
60996+ oldfs = get_fs();
60997+ set_fs(KERNEL_DS);
60998+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60999+ set_fs(oldfs);
61000+ if (copy_to_user(buffer, elf_buf, tsz)) {
61001+ kfree(elf_buf);
61002 return -EFAULT;
61003+ }
61004 }
61005+ set_fs(oldfs);
61006+ kfree(elf_buf);
61007 } else {
61008 if (clear_user(buffer, tsz))
61009 return -EFAULT;
61010@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
61011
61012 static int open_kcore(struct inode *inode, struct file *filp)
61013 {
61014+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
61015+ return -EPERM;
61016+#endif
61017 if (!capable(CAP_SYS_RAWIO))
61018 return -EPERM;
61019 if (kcore_need_update)
61020diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
61021index 59d85d6..ac6fc05 100644
61022--- a/fs/proc/meminfo.c
61023+++ b/fs/proc/meminfo.c
61024@@ -153,7 +153,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
61025 vmi.used >> 10,
61026 vmi.largest_chunk >> 10
61027 #ifdef CONFIG_MEMORY_FAILURE
61028- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
61029+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
61030 #endif
61031 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
61032 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
61033diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
61034index ccfd99b..1b7e255 100644
61035--- a/fs/proc/nommu.c
61036+++ b/fs/proc/nommu.c
61037@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
61038 if (len < 1)
61039 len = 1;
61040 seq_printf(m, "%*c", len, ' ');
61041- seq_path(m, &file->f_path, "");
61042+ seq_path(m, &file->f_path, "\n\\");
61043 }
61044
61045 seq_putc(m, '\n');
61046diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
61047index 4677bb7..408e936 100644
61048--- a/fs/proc/proc_net.c
61049+++ b/fs/proc/proc_net.c
61050@@ -23,6 +23,7 @@
61051 #include <linux/nsproxy.h>
61052 #include <net/net_namespace.h>
61053 #include <linux/seq_file.h>
61054+#include <linux/grsecurity.h>
61055
61056 #include "internal.h"
61057
61058@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
61059 struct task_struct *task;
61060 struct nsproxy *ns;
61061 struct net *net = NULL;
61062+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61063+ const struct cred *cred = current_cred();
61064+#endif
61065+
61066+#ifdef CONFIG_GRKERNSEC_PROC_USER
61067+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
61068+ return net;
61069+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61070+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
61071+ return net;
61072+#endif
61073
61074 rcu_read_lock();
61075 task = pid_task(proc_pid(dir), PIDTYPE_PID);
61076diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
61077index 7129046..6914844 100644
61078--- a/fs/proc/proc_sysctl.c
61079+++ b/fs/proc/proc_sysctl.c
61080@@ -11,13 +11,21 @@
61081 #include <linux/namei.h>
61082 #include <linux/mm.h>
61083 #include <linux/module.h>
61084+#include <linux/nsproxy.h>
61085+#ifdef CONFIG_GRKERNSEC
61086+#include <net/net_namespace.h>
61087+#endif
61088 #include "internal.h"
61089
61090+extern int gr_handle_chroot_sysctl(const int op);
61091+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
61092+ const int op);
61093+
61094 static const struct dentry_operations proc_sys_dentry_operations;
61095 static const struct file_operations proc_sys_file_operations;
61096-static const struct inode_operations proc_sys_inode_operations;
61097+const struct inode_operations proc_sys_inode_operations;
61098 static const struct file_operations proc_sys_dir_file_operations;
61099-static const struct inode_operations proc_sys_dir_operations;
61100+const struct inode_operations proc_sys_dir_operations;
61101
61102 void proc_sys_poll_notify(struct ctl_table_poll *poll)
61103 {
61104@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
61105
61106 err = NULL;
61107 d_set_d_op(dentry, &proc_sys_dentry_operations);
61108+
61109+ gr_handle_proc_create(dentry, inode);
61110+
61111 d_add(dentry, inode);
61112
61113 out:
61114@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61115 struct inode *inode = file_inode(filp);
61116 struct ctl_table_header *head = grab_header(inode);
61117 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
61118+ int op = write ? MAY_WRITE : MAY_READ;
61119 ssize_t error;
61120 size_t res;
61121
61122@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61123 * and won't be until we finish.
61124 */
61125 error = -EPERM;
61126- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
61127+ if (sysctl_perm(head, table, op))
61128 goto out;
61129
61130 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
61131@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61132 if (!table->proc_handler)
61133 goto out;
61134
61135+#ifdef CONFIG_GRKERNSEC
61136+ error = -EPERM;
61137+ if (gr_handle_chroot_sysctl(op))
61138+ goto out;
61139+ dget(filp->f_path.dentry);
61140+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
61141+ dput(filp->f_path.dentry);
61142+ goto out;
61143+ }
61144+ dput(filp->f_path.dentry);
61145+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
61146+ goto out;
61147+ if (write) {
61148+ if (current->nsproxy->net_ns != table->extra2) {
61149+ if (!capable(CAP_SYS_ADMIN))
61150+ goto out;
61151+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
61152+ goto out;
61153+ }
61154+#endif
61155+
61156 /* careful: calling conventions are nasty here */
61157 res = count;
61158 error = table->proc_handler(table, write, buf, &res, ppos);
61159@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
61160 return false;
61161 } else {
61162 d_set_d_op(child, &proc_sys_dentry_operations);
61163+
61164+ gr_handle_proc_create(child, inode);
61165+
61166 d_add(child, inode);
61167 }
61168 } else {
61169@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
61170 if ((*pos)++ < ctx->pos)
61171 return true;
61172
61173+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
61174+ return 0;
61175+
61176 if (unlikely(S_ISLNK(table->mode)))
61177 res = proc_sys_link_fill_cache(file, ctx, head, table);
61178 else
61179@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
61180 if (IS_ERR(head))
61181 return PTR_ERR(head);
61182
61183+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
61184+ return -ENOENT;
61185+
61186 generic_fillattr(inode, stat);
61187 if (table)
61188 stat->mode = (stat->mode & S_IFMT) | table->mode;
61189@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
61190 .llseek = generic_file_llseek,
61191 };
61192
61193-static const struct inode_operations proc_sys_inode_operations = {
61194+const struct inode_operations proc_sys_inode_operations = {
61195 .permission = proc_sys_permission,
61196 .setattr = proc_sys_setattr,
61197 .getattr = proc_sys_getattr,
61198 };
61199
61200-static const struct inode_operations proc_sys_dir_operations = {
61201+const struct inode_operations proc_sys_dir_operations = {
61202 .lookup = proc_sys_lookup,
61203 .permission = proc_sys_permission,
61204 .setattr = proc_sys_setattr,
61205@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
61206 static struct ctl_dir *new_dir(struct ctl_table_set *set,
61207 const char *name, int namelen)
61208 {
61209- struct ctl_table *table;
61210+ ctl_table_no_const *table;
61211 struct ctl_dir *new;
61212 struct ctl_node *node;
61213 char *new_name;
61214@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
61215 return NULL;
61216
61217 node = (struct ctl_node *)(new + 1);
61218- table = (struct ctl_table *)(node + 1);
61219+ table = (ctl_table_no_const *)(node + 1);
61220 new_name = (char *)(table + 2);
61221 memcpy(new_name, name, namelen);
61222 new_name[namelen] = '\0';
61223@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
61224 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
61225 struct ctl_table_root *link_root)
61226 {
61227- struct ctl_table *link_table, *entry, *link;
61228+ ctl_table_no_const *link_table, *link;
61229+ struct ctl_table *entry;
61230 struct ctl_table_header *links;
61231 struct ctl_node *node;
61232 char *link_name;
61233@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
61234 return NULL;
61235
61236 node = (struct ctl_node *)(links + 1);
61237- link_table = (struct ctl_table *)(node + nr_entries);
61238+ link_table = (ctl_table_no_const *)(node + nr_entries);
61239 link_name = (char *)&link_table[nr_entries + 1];
61240
61241 for (link = link_table, entry = table; entry->procname; link++, entry++) {
61242@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61243 struct ctl_table_header ***subheader, struct ctl_table_set *set,
61244 struct ctl_table *table)
61245 {
61246- struct ctl_table *ctl_table_arg = NULL;
61247- struct ctl_table *entry, *files;
61248+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
61249+ struct ctl_table *entry;
61250 int nr_files = 0;
61251 int nr_dirs = 0;
61252 int err = -ENOMEM;
61253@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61254 nr_files++;
61255 }
61256
61257- files = table;
61258 /* If there are mixed files and directories we need a new table */
61259 if (nr_dirs && nr_files) {
61260- struct ctl_table *new;
61261+ ctl_table_no_const *new;
61262 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
61263 GFP_KERNEL);
61264 if (!files)
61265@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61266 /* Register everything except a directory full of subdirectories */
61267 if (nr_files || !nr_dirs) {
61268 struct ctl_table_header *header;
61269- header = __register_sysctl_table(set, path, files);
61270+ header = __register_sysctl_table(set, path, files ? files : table);
61271 if (!header) {
61272 kfree(ctl_table_arg);
61273 goto out;
61274diff --git a/fs/proc/root.c b/fs/proc/root.c
61275index 87dbcbe..55e1b4d 100644
61276--- a/fs/proc/root.c
61277+++ b/fs/proc/root.c
61278@@ -186,7 +186,15 @@ void __init proc_root_init(void)
61279 #ifdef CONFIG_PROC_DEVICETREE
61280 proc_device_tree_init();
61281 #endif
61282+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61283+#ifdef CONFIG_GRKERNSEC_PROC_USER
61284+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
61285+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61286+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
61287+#endif
61288+#else
61289 proc_mkdir("bus", NULL);
61290+#endif
61291 proc_sys_init();
61292 }
61293
61294diff --git a/fs/proc/self.c b/fs/proc/self.c
61295index 6b6a993..807cccc 100644
61296--- a/fs/proc/self.c
61297+++ b/fs/proc/self.c
61298@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
61299 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
61300 void *cookie)
61301 {
61302- char *s = nd_get_link(nd);
61303+ const char *s = nd_get_link(nd);
61304 if (!IS_ERR(s))
61305 kfree(s);
61306 }
61307diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
61308index 390bdab..83c1e8a 100644
61309--- a/fs/proc/task_mmu.c
61310+++ b/fs/proc/task_mmu.c
61311@@ -12,12 +12,19 @@
61312 #include <linux/swap.h>
61313 #include <linux/swapops.h>
61314 #include <linux/mmu_notifier.h>
61315+#include <linux/grsecurity.h>
61316
61317 #include <asm/elf.h>
61318 #include <asm/uaccess.h>
61319 #include <asm/tlbflush.h>
61320 #include "internal.h"
61321
61322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61323+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61324+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61325+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61326+#endif
61327+
61328 void task_mem(struct seq_file *m, struct mm_struct *mm)
61329 {
61330 unsigned long data, text, lib, swap;
61331@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61332 "VmExe:\t%8lu kB\n"
61333 "VmLib:\t%8lu kB\n"
61334 "VmPTE:\t%8lu kB\n"
61335- "VmSwap:\t%8lu kB\n",
61336- hiwater_vm << (PAGE_SHIFT-10),
61337+ "VmSwap:\t%8lu kB\n"
61338+
61339+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61340+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
61341+#endif
61342+
61343+ ,hiwater_vm << (PAGE_SHIFT-10),
61344 total_vm << (PAGE_SHIFT-10),
61345 mm->locked_vm << (PAGE_SHIFT-10),
61346 mm->pinned_vm << (PAGE_SHIFT-10),
61347@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61348 data << (PAGE_SHIFT-10),
61349 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
61350 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
61351- swap << (PAGE_SHIFT-10));
61352+ swap << (PAGE_SHIFT-10)
61353+
61354+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61355+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61356+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
61357+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
61358+#else
61359+ , mm->context.user_cs_base
61360+ , mm->context.user_cs_limit
61361+#endif
61362+#endif
61363+
61364+ );
61365 }
61366
61367 unsigned long task_vsize(struct mm_struct *mm)
61368@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61369 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
61370 }
61371
61372- /* We don't show the stack guard page in /proc/maps */
61373+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61374+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
61375+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
61376+#else
61377 start = vma->vm_start;
61378- if (stack_guard_page_start(vma, start))
61379- start += PAGE_SIZE;
61380 end = vma->vm_end;
61381- if (stack_guard_page_end(vma, end))
61382- end -= PAGE_SIZE;
61383+#endif
61384
61385 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
61386 start,
61387@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61388 flags & VM_WRITE ? 'w' : '-',
61389 flags & VM_EXEC ? 'x' : '-',
61390 flags & VM_MAYSHARE ? 's' : 'p',
61391+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61392+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
61393+#else
61394 pgoff,
61395+#endif
61396 MAJOR(dev), MINOR(dev), ino, &len);
61397
61398 /*
61399@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61400 */
61401 if (file) {
61402 pad_len_spaces(m, len);
61403- seq_path(m, &file->f_path, "\n");
61404+ seq_path(m, &file->f_path, "\n\\");
61405 goto done;
61406 }
61407
61408@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61409 * Thread stack in /proc/PID/task/TID/maps or
61410 * the main process stack.
61411 */
61412- if (!is_pid || (vma->vm_start <= mm->start_stack &&
61413- vma->vm_end >= mm->start_stack)) {
61414+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
61415+ (vma->vm_start <= mm->start_stack &&
61416+ vma->vm_end >= mm->start_stack)) {
61417 name = "[stack]";
61418 } else {
61419 /* Thread stack in /proc/PID/maps */
61420@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
61421 struct proc_maps_private *priv = m->private;
61422 struct task_struct *task = priv->task;
61423
61424+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61425+ if (current->exec_id != m->exec_id) {
61426+ gr_log_badprocpid("maps");
61427+ return 0;
61428+ }
61429+#endif
61430+
61431 show_map_vma(m, vma, is_pid);
61432
61433 if (m->count < m->size) /* vma is copied successfully */
61434@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61435 .private = &mss,
61436 };
61437
61438+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61439+ if (current->exec_id != m->exec_id) {
61440+ gr_log_badprocpid("smaps");
61441+ return 0;
61442+ }
61443+#endif
61444 memset(&mss, 0, sizeof mss);
61445- mss.vma = vma;
61446- /* mmap_sem is held in m_start */
61447- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61448- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61449-
61450+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61451+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
61452+#endif
61453+ mss.vma = vma;
61454+ /* mmap_sem is held in m_start */
61455+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61456+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61457+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61458+ }
61459+#endif
61460 show_map_vma(m, vma, is_pid);
61461
61462 seq_printf(m,
61463@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61464 "KernelPageSize: %8lu kB\n"
61465 "MMUPageSize: %8lu kB\n"
61466 "Locked: %8lu kB\n",
61467+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61468+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
61469+#else
61470 (vma->vm_end - vma->vm_start) >> 10,
61471+#endif
61472 mss.resident >> 10,
61473 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
61474 mss.shared_clean >> 10,
61475@@ -1390,6 +1441,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61476 int n;
61477 char buffer[50];
61478
61479+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61480+ if (current->exec_id != m->exec_id) {
61481+ gr_log_badprocpid("numa_maps");
61482+ return 0;
61483+ }
61484+#endif
61485+
61486 if (!mm)
61487 return 0;
61488
61489@@ -1409,11 +1467,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61490 if (n < 0)
61491 return n;
61492
61493+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61494+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
61495+#else
61496 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
61497+#endif
61498
61499 if (file) {
61500 seq_printf(m, " file=");
61501- seq_path(m, &file->f_path, "\n\t= ");
61502+ seq_path(m, &file->f_path, "\n\t\\= ");
61503 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
61504 seq_printf(m, " heap");
61505 } else {
61506diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
61507index 56123a6..5a2f6ec 100644
61508--- a/fs/proc/task_nommu.c
61509+++ b/fs/proc/task_nommu.c
61510@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61511 else
61512 bytes += kobjsize(mm);
61513
61514- if (current->fs && current->fs->users > 1)
61515+ if (current->fs && atomic_read(&current->fs->users) > 1)
61516 sbytes += kobjsize(current->fs);
61517 else
61518 bytes += kobjsize(current->fs);
61519@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
61520
61521 if (file) {
61522 pad_len_spaces(m, len);
61523- seq_path(m, &file->f_path, "");
61524+ seq_path(m, &file->f_path, "\n\\");
61525 } else if (mm) {
61526 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
61527
61528diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
61529index 9100d69..f1f9fc9 100644
61530--- a/fs/proc/vmcore.c
61531+++ b/fs/proc/vmcore.c
61532@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
61533 nr_bytes = count;
61534
61535 /* If pfn is not ram, return zeros for sparse dump files */
61536- if (pfn_is_ram(pfn) == 0)
61537- memset(buf, 0, nr_bytes);
61538- else {
61539+ if (pfn_is_ram(pfn) == 0) {
61540+ if (userbuf) {
61541+ if (clear_user((char __force_user *)buf, nr_bytes))
61542+ return -EFAULT;
61543+ } else
61544+ memset(buf, 0, nr_bytes);
61545+ } else {
61546 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
61547 offset, userbuf);
61548 if (tmp < 0)
61549@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
61550 if (*fpos < m->offset + m->size) {
61551 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
61552 start = m->paddr + *fpos - m->offset;
61553- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
61554+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
61555 if (tmp < 0)
61556 return tmp;
61557 buflen -= tsz;
61558diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
61559index b00fcc9..e0c6381 100644
61560--- a/fs/qnx6/qnx6.h
61561+++ b/fs/qnx6/qnx6.h
61562@@ -74,7 +74,7 @@ enum {
61563 BYTESEX_BE,
61564 };
61565
61566-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61567+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61568 {
61569 if (sbi->s_bytesex == BYTESEX_LE)
61570 return le64_to_cpu((__force __le64)n);
61571@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
61572 return (__force __fs64)cpu_to_be64(n);
61573 }
61574
61575-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61576+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61577 {
61578 if (sbi->s_bytesex == BYTESEX_LE)
61579 return le32_to_cpu((__force __le32)n);
61580diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
61581index 16e8abb..2dcf914 100644
61582--- a/fs/quota/netlink.c
61583+++ b/fs/quota/netlink.c
61584@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
61585 void quota_send_warning(struct kqid qid, dev_t dev,
61586 const char warntype)
61587 {
61588- static atomic_t seq;
61589+ static atomic_unchecked_t seq;
61590 struct sk_buff *skb;
61591 void *msg_head;
61592 int ret;
61593@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
61594 "VFS: Not enough memory to send quota warning.\n");
61595 return;
61596 }
61597- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
61598+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
61599 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
61600 if (!msg_head) {
61601 printk(KERN_ERR
61602diff --git a/fs/read_write.c b/fs/read_write.c
61603index e3cd280..a378473 100644
61604--- a/fs/read_write.c
61605+++ b/fs/read_write.c
61606@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
61607
61608 old_fs = get_fs();
61609 set_fs(get_ds());
61610- p = (__force const char __user *)buf;
61611+ p = (const char __force_user *)buf;
61612 if (count > MAX_RW_COUNT)
61613 count = MAX_RW_COUNT;
61614 if (file->f_op->write)
61615diff --git a/fs/readdir.c b/fs/readdir.c
61616index 93d71e5..6a14be8 100644
61617--- a/fs/readdir.c
61618+++ b/fs/readdir.c
61619@@ -17,6 +17,7 @@
61620 #include <linux/security.h>
61621 #include <linux/syscalls.h>
61622 #include <linux/unistd.h>
61623+#include <linux/namei.h>
61624
61625 #include <asm/uaccess.h>
61626
61627@@ -69,6 +70,7 @@ struct old_linux_dirent {
61628 struct readdir_callback {
61629 struct dir_context ctx;
61630 struct old_linux_dirent __user * dirent;
61631+ struct file * file;
61632 int result;
61633 };
61634
61635@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
61636 buf->result = -EOVERFLOW;
61637 return -EOVERFLOW;
61638 }
61639+
61640+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61641+ return 0;
61642+
61643 buf->result++;
61644 dirent = buf->dirent;
61645 if (!access_ok(VERIFY_WRITE, dirent,
61646@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61647 if (!f.file)
61648 return -EBADF;
61649
61650+ buf.file = f.file;
61651 error = iterate_dir(f.file, &buf.ctx);
61652 if (buf.result)
61653 error = buf.result;
61654@@ -142,6 +149,7 @@ struct getdents_callback {
61655 struct dir_context ctx;
61656 struct linux_dirent __user * current_dir;
61657 struct linux_dirent __user * previous;
61658+ struct file * file;
61659 int count;
61660 int error;
61661 };
61662@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
61663 buf->error = -EOVERFLOW;
61664 return -EOVERFLOW;
61665 }
61666+
61667+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61668+ return 0;
61669+
61670 dirent = buf->previous;
61671 if (dirent) {
61672 if (__put_user(offset, &dirent->d_off))
61673@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61674 if (!f.file)
61675 return -EBADF;
61676
61677+ buf.file = f.file;
61678 error = iterate_dir(f.file, &buf.ctx);
61679 if (error >= 0)
61680 error = buf.error;
61681@@ -226,6 +239,7 @@ struct getdents_callback64 {
61682 struct dir_context ctx;
61683 struct linux_dirent64 __user * current_dir;
61684 struct linux_dirent64 __user * previous;
61685+ struct file *file;
61686 int count;
61687 int error;
61688 };
61689@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
61690 buf->error = -EINVAL; /* only used if we fail.. */
61691 if (reclen > buf->count)
61692 return -EINVAL;
61693+
61694+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61695+ return 0;
61696+
61697 dirent = buf->previous;
61698 if (dirent) {
61699 if (__put_user(offset, &dirent->d_off))
61700@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61701 if (!f.file)
61702 return -EBADF;
61703
61704+ buf.file = f.file;
61705 error = iterate_dir(f.file, &buf.ctx);
61706 if (error >= 0)
61707 error = buf.error;
61708diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
61709index 2b7882b..1c5ef48 100644
61710--- a/fs/reiserfs/do_balan.c
61711+++ b/fs/reiserfs/do_balan.c
61712@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
61713 return;
61714 }
61715
61716- atomic_inc(&(fs_generation(tb->tb_sb)));
61717+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
61718 do_balance_starts(tb);
61719
61720 /* balance leaf returns 0 except if combining L R and S into
61721diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
61722index a958444..42b2323 100644
61723--- a/fs/reiserfs/procfs.c
61724+++ b/fs/reiserfs/procfs.c
61725@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
61726 "SMALL_TAILS " : "NO_TAILS ",
61727 replay_only(sb) ? "REPLAY_ONLY " : "",
61728 convert_reiserfs(sb) ? "CONV " : "",
61729- atomic_read(&r->s_generation_counter),
61730+ atomic_read_unchecked(&r->s_generation_counter),
61731 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
61732 SF(s_do_balance), SF(s_unneeded_left_neighbor),
61733 SF(s_good_search_by_key_reada), SF(s_bmaps),
61734diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
61735index f8adaee..0eeeeca 100644
61736--- a/fs/reiserfs/reiserfs.h
61737+++ b/fs/reiserfs/reiserfs.h
61738@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
61739 /* Comment? -Hans */
61740 wait_queue_head_t s_wait;
61741 /* To be obsoleted soon by per buffer seals.. -Hans */
61742- atomic_t s_generation_counter; // increased by one every time the
61743+ atomic_unchecked_t s_generation_counter; // increased by one every time the
61744 // tree gets re-balanced
61745 unsigned long s_properties; /* File system properties. Currently holds
61746 on-disk FS format */
61747@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61748 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61749
61750 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61751-#define get_generation(s) atomic_read (&fs_generation(s))
61752+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61753 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61754 #define __fs_changed(gen,s) (gen != get_generation (s))
61755 #define fs_changed(gen,s) \
61756diff --git a/fs/select.c b/fs/select.c
61757index dfd5cb1..1754d57 100644
61758--- a/fs/select.c
61759+++ b/fs/select.c
61760@@ -20,6 +20,7 @@
61761 #include <linux/export.h>
61762 #include <linux/slab.h>
61763 #include <linux/poll.h>
61764+#include <linux/security.h>
61765 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
61766 #include <linux/file.h>
61767 #include <linux/fdtable.h>
61768@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
61769 struct poll_list *walk = head;
61770 unsigned long todo = nfds;
61771
61772+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
61773 if (nfds > rlimit(RLIMIT_NOFILE))
61774 return -EINVAL;
61775
61776diff --git a/fs/seq_file.c b/fs/seq_file.c
61777index a290157..ec3211a 100644
61778--- a/fs/seq_file.c
61779+++ b/fs/seq_file.c
61780@@ -10,6 +10,7 @@
61781 #include <linux/seq_file.h>
61782 #include <linux/slab.h>
61783 #include <linux/cred.h>
61784+#include <linux/sched.h>
61785
61786 #include <asm/uaccess.h>
61787 #include <asm/page.h>
61788@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
61789 #ifdef CONFIG_USER_NS
61790 p->user_ns = file->f_cred->user_ns;
61791 #endif
61792+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61793+ p->exec_id = current->exec_id;
61794+#endif
61795
61796 /*
61797 * Wrappers around seq_open(e.g. swaps_open) need to be
61798@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61799 return 0;
61800 }
61801 if (!m->buf) {
61802- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61803+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61804 if (!m->buf)
61805 return -ENOMEM;
61806 }
61807@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61808 Eoverflow:
61809 m->op->stop(m, p);
61810 kfree(m->buf);
61811- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61812+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61813 return !m->buf ? -ENOMEM : -EAGAIN;
61814 }
61815
61816@@ -152,7 +156,7 @@ Eoverflow:
61817 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61818 {
61819 struct seq_file *m = file->private_data;
61820- size_t copied = 0;
61821+ ssize_t copied = 0;
61822 loff_t pos;
61823 size_t n;
61824 void *p;
61825@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61826
61827 /* grab buffer if we didn't have one */
61828 if (!m->buf) {
61829- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61830+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61831 if (!m->buf)
61832 goto Enomem;
61833 }
61834@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61835 goto Fill;
61836 m->op->stop(m, p);
61837 kfree(m->buf);
61838- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61839+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61840 if (!m->buf)
61841 goto Enomem;
61842 m->count = 0;
61843@@ -583,7 +587,7 @@ static void single_stop(struct seq_file *p, void *v)
61844 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61845 void *data)
61846 {
61847- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61848+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61849 int res = -ENOMEM;
61850
61851 if (op) {
61852diff --git a/fs/splice.c b/fs/splice.c
61853index 3b7ee65..87fc2e4 100644
61854--- a/fs/splice.c
61855+++ b/fs/splice.c
61856@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61857 pipe_lock(pipe);
61858
61859 for (;;) {
61860- if (!pipe->readers) {
61861+ if (!atomic_read(&pipe->readers)) {
61862 send_sig(SIGPIPE, current, 0);
61863 if (!ret)
61864 ret = -EPIPE;
61865@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61866 page_nr++;
61867 ret += buf->len;
61868
61869- if (pipe->files)
61870+ if (atomic_read(&pipe->files))
61871 do_wakeup = 1;
61872
61873 if (!--spd->nr_pages)
61874@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61875 do_wakeup = 0;
61876 }
61877
61878- pipe->waiting_writers++;
61879+ atomic_inc(&pipe->waiting_writers);
61880 pipe_wait(pipe);
61881- pipe->waiting_writers--;
61882+ atomic_dec(&pipe->waiting_writers);
61883 }
61884
61885 pipe_unlock(pipe);
61886@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61887 old_fs = get_fs();
61888 set_fs(get_ds());
61889 /* The cast to a user pointer is valid due to the set_fs() */
61890- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61891+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61892 set_fs(old_fs);
61893
61894 return res;
61895@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61896 old_fs = get_fs();
61897 set_fs(get_ds());
61898 /* The cast to a user pointer is valid due to the set_fs() */
61899- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61900+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61901 set_fs(old_fs);
61902
61903 return res;
61904@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61905 goto err;
61906
61907 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61908- vec[i].iov_base = (void __user *) page_address(page);
61909+ vec[i].iov_base = (void __force_user *) page_address(page);
61910 vec[i].iov_len = this_len;
61911 spd.pages[i] = page;
61912 spd.nr_pages++;
61913@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61914 ops->release(pipe, buf);
61915 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61916 pipe->nrbufs--;
61917- if (pipe->files)
61918+ if (atomic_read(&pipe->files))
61919 sd->need_wakeup = true;
61920 }
61921
61922@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61923 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61924 {
61925 while (!pipe->nrbufs) {
61926- if (!pipe->writers)
61927+ if (!atomic_read(&pipe->writers))
61928 return 0;
61929
61930- if (!pipe->waiting_writers && sd->num_spliced)
61931+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61932 return 0;
61933
61934 if (sd->flags & SPLICE_F_NONBLOCK)
61935@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61936 * out of the pipe right after the splice_to_pipe(). So set
61937 * PIPE_READERS appropriately.
61938 */
61939- pipe->readers = 1;
61940+ atomic_set(&pipe->readers, 1);
61941
61942 current->splice_pipe = pipe;
61943 }
61944@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
61945
61946 partial[buffers].offset = off;
61947 partial[buffers].len = plen;
61948+ partial[buffers].private = 0;
61949
61950 off = 0;
61951 len -= plen;
61952@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61953 ret = -ERESTARTSYS;
61954 break;
61955 }
61956- if (!pipe->writers)
61957+ if (!atomic_read(&pipe->writers))
61958 break;
61959- if (!pipe->waiting_writers) {
61960+ if (!atomic_read(&pipe->waiting_writers)) {
61961 if (flags & SPLICE_F_NONBLOCK) {
61962 ret = -EAGAIN;
61963 break;
61964@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61965 pipe_lock(pipe);
61966
61967 while (pipe->nrbufs >= pipe->buffers) {
61968- if (!pipe->readers) {
61969+ if (!atomic_read(&pipe->readers)) {
61970 send_sig(SIGPIPE, current, 0);
61971 ret = -EPIPE;
61972 break;
61973@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61974 ret = -ERESTARTSYS;
61975 break;
61976 }
61977- pipe->waiting_writers++;
61978+ atomic_inc(&pipe->waiting_writers);
61979 pipe_wait(pipe);
61980- pipe->waiting_writers--;
61981+ atomic_dec(&pipe->waiting_writers);
61982 }
61983
61984 pipe_unlock(pipe);
61985@@ -1862,14 +1863,14 @@ retry:
61986 pipe_double_lock(ipipe, opipe);
61987
61988 do {
61989- if (!opipe->readers) {
61990+ if (!atomic_read(&opipe->readers)) {
61991 send_sig(SIGPIPE, current, 0);
61992 if (!ret)
61993 ret = -EPIPE;
61994 break;
61995 }
61996
61997- if (!ipipe->nrbufs && !ipipe->writers)
61998+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
61999 break;
62000
62001 /*
62002@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
62003 pipe_double_lock(ipipe, opipe);
62004
62005 do {
62006- if (!opipe->readers) {
62007+ if (!atomic_read(&opipe->readers)) {
62008 send_sig(SIGPIPE, current, 0);
62009 if (!ret)
62010 ret = -EPIPE;
62011@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
62012 * return EAGAIN if we have the potential of some data in the
62013 * future, otherwise just return 0
62014 */
62015- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
62016+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
62017 ret = -EAGAIN;
62018
62019 pipe_unlock(ipipe);
62020diff --git a/fs/stat.c b/fs/stat.c
62021index d0ea7ef..f463f9d 100644
62022--- a/fs/stat.c
62023+++ b/fs/stat.c
62024@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
62025 stat->gid = inode->i_gid;
62026 stat->rdev = inode->i_rdev;
62027 stat->size = i_size_read(inode);
62028- stat->atime = inode->i_atime;
62029- stat->mtime = inode->i_mtime;
62030+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
62031+ stat->atime = inode->i_ctime;
62032+ stat->mtime = inode->i_ctime;
62033+ } else {
62034+ stat->atime = inode->i_atime;
62035+ stat->mtime = inode->i_mtime;
62036+ }
62037 stat->ctime = inode->i_ctime;
62038 stat->blksize = (1 << inode->i_blkbits);
62039 stat->blocks = inode->i_blocks;
62040@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
62041 if (retval)
62042 return retval;
62043
62044- if (inode->i_op->getattr)
62045- return inode->i_op->getattr(path->mnt, path->dentry, stat);
62046+ if (inode->i_op->getattr) {
62047+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
62048+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
62049+ stat->atime = stat->ctime;
62050+ stat->mtime = stat->ctime;
62051+ }
62052+ return retval;
62053+ }
62054
62055 generic_fillattr(inode, stat);
62056 return 0;
62057diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
62058index c590cab..6dfd6fc 100644
62059--- a/fs/sysfs/bin.c
62060+++ b/fs/sysfs/bin.c
62061@@ -234,13 +234,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
62062 return ret;
62063 }
62064
62065-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
62066- void *buf, int len, int write)
62067+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
62068+ void *buf, size_t len, int write)
62069 {
62070 struct file *file = vma->vm_file;
62071 struct bin_buffer *bb = file->private_data;
62072 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
62073- int ret;
62074+ ssize_t ret;
62075
62076 if (!bb->vm_ops)
62077 return -EINVAL;
62078diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
62079index 4d83ced..049dc45 100644
62080--- a/fs/sysfs/dir.c
62081+++ b/fs/sysfs/dir.c
62082@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
62083 *
62084 * Returns 31 bit hash of ns + name (so it fits in an off_t )
62085 */
62086-static unsigned int sysfs_name_hash(const void *ns, const char *name)
62087+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
62088 {
62089 unsigned long hash = init_name_hash();
62090 unsigned int len = strlen(name);
62091@@ -675,6 +675,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
62092 struct sysfs_dirent *sd;
62093 int rc;
62094
62095+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
62096+ const char *parent_name = parent_sd->s_name;
62097+
62098+ mode = S_IFDIR | S_IRWXU;
62099+
62100+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
62101+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
62102+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
62103+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
62104+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
62105+#endif
62106+
62107 /* allocate */
62108 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
62109 if (!sd)
62110diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
62111index 15ef5eb..e474372 100644
62112--- a/fs/sysfs/file.c
62113+++ b/fs/sysfs/file.c
62114@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
62115
62116 struct sysfs_open_dirent {
62117 atomic_t refcnt;
62118- atomic_t event;
62119+ atomic_unchecked_t event;
62120 wait_queue_head_t poll;
62121 struct list_head buffers; /* goes through sysfs_buffer.list */
62122 };
62123@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
62124 if (!sysfs_get_active(attr_sd))
62125 return -ENODEV;
62126
62127- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
62128+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
62129 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
62130
62131 sysfs_put_active(attr_sd);
62132@@ -284,7 +284,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
62133 return -ENOMEM;
62134
62135 atomic_set(&new_od->refcnt, 0);
62136- atomic_set(&new_od->event, 1);
62137+ atomic_set_unchecked(&new_od->event, 1);
62138 init_waitqueue_head(&new_od->poll);
62139 INIT_LIST_HEAD(&new_od->buffers);
62140 goto retry;
62141@@ -430,7 +430,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
62142
62143 sysfs_put_active(attr_sd);
62144
62145- if (buffer->event != atomic_read(&od->event))
62146+ if (buffer->event != atomic_read_unchecked(&od->event))
62147 goto trigger;
62148
62149 return DEFAULT_POLLMASK;
62150@@ -450,7 +450,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
62151 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
62152 od = sd->s_attr.open;
62153 if (od) {
62154- atomic_inc(&od->event);
62155+ atomic_inc_unchecked(&od->event);
62156 wake_up_interruptible(&od->poll);
62157 }
62158 }
62159diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
62160index 2dd4507..62a215a 100644
62161--- a/fs/sysfs/symlink.c
62162+++ b/fs/sysfs/symlink.c
62163@@ -308,7 +308,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
62164 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
62165 void *cookie)
62166 {
62167- char *page = nd_get_link(nd);
62168+ const char *page = nd_get_link(nd);
62169 if (!IS_ERR(page))
62170 free_page((unsigned long)page);
62171 }
62172diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
62173index 69d4889..a810bd4 100644
62174--- a/fs/sysv/sysv.h
62175+++ b/fs/sysv/sysv.h
62176@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
62177 #endif
62178 }
62179
62180-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62181+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62182 {
62183 if (sbi->s_bytesex == BYTESEX_PDP)
62184 return PDP_swab((__force __u32)n);
62185diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
62186index e18b988..f1d4ad0f 100644
62187--- a/fs/ubifs/io.c
62188+++ b/fs/ubifs/io.c
62189@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
62190 return err;
62191 }
62192
62193-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62194+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62195 {
62196 int err;
62197
62198diff --git a/fs/udf/misc.c b/fs/udf/misc.c
62199index c175b4d..8f36a16 100644
62200--- a/fs/udf/misc.c
62201+++ b/fs/udf/misc.c
62202@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
62203
62204 u8 udf_tag_checksum(const struct tag *t)
62205 {
62206- u8 *data = (u8 *)t;
62207+ const u8 *data = (const u8 *)t;
62208 u8 checksum = 0;
62209 int i;
62210 for (i = 0; i < sizeof(struct tag); ++i)
62211diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
62212index 8d974c4..b82f6ec 100644
62213--- a/fs/ufs/swab.h
62214+++ b/fs/ufs/swab.h
62215@@ -22,7 +22,7 @@ enum {
62216 BYTESEX_BE
62217 };
62218
62219-static inline u64
62220+static inline u64 __intentional_overflow(-1)
62221 fs64_to_cpu(struct super_block *sbp, __fs64 n)
62222 {
62223 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62224@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
62225 return (__force __fs64)cpu_to_be64(n);
62226 }
62227
62228-static inline u32
62229+static inline u32 __intentional_overflow(-1)
62230 fs32_to_cpu(struct super_block *sbp, __fs32 n)
62231 {
62232 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62233diff --git a/fs/utimes.c b/fs/utimes.c
62234index f4fb7ec..3fe03c0 100644
62235--- a/fs/utimes.c
62236+++ b/fs/utimes.c
62237@@ -1,6 +1,7 @@
62238 #include <linux/compiler.h>
62239 #include <linux/file.h>
62240 #include <linux/fs.h>
62241+#include <linux/security.h>
62242 #include <linux/linkage.h>
62243 #include <linux/mount.h>
62244 #include <linux/namei.h>
62245@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
62246 goto mnt_drop_write_and_out;
62247 }
62248 }
62249+
62250+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
62251+ error = -EACCES;
62252+ goto mnt_drop_write_and_out;
62253+ }
62254+
62255 mutex_lock(&inode->i_mutex);
62256 error = notify_change(path->dentry, &newattrs);
62257 mutex_unlock(&inode->i_mutex);
62258diff --git a/fs/xattr.c b/fs/xattr.c
62259index 3377dff..4d074d9 100644
62260--- a/fs/xattr.c
62261+++ b/fs/xattr.c
62262@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
62263 return rc;
62264 }
62265
62266+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
62267+ssize_t
62268+pax_getxattr(struct dentry *dentry, void *value, size_t size)
62269+{
62270+ struct inode *inode = dentry->d_inode;
62271+ ssize_t error;
62272+
62273+ error = inode_permission(inode, MAY_EXEC);
62274+ if (error)
62275+ return error;
62276+
62277+ if (inode->i_op->getxattr)
62278+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
62279+ else
62280+ error = -EOPNOTSUPP;
62281+
62282+ return error;
62283+}
62284+EXPORT_SYMBOL(pax_getxattr);
62285+#endif
62286+
62287 ssize_t
62288 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
62289 {
62290@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
62291 * Extended attribute SET operations
62292 */
62293 static long
62294-setxattr(struct dentry *d, const char __user *name, const void __user *value,
62295+setxattr(struct path *path, const char __user *name, const void __user *value,
62296 size_t size, int flags)
62297 {
62298 int error;
62299@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
62300 posix_acl_fix_xattr_from_user(kvalue, size);
62301 }
62302
62303- error = vfs_setxattr(d, kname, kvalue, size, flags);
62304+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
62305+ error = -EACCES;
62306+ goto out;
62307+ }
62308+
62309+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
62310 out:
62311 if (vvalue)
62312 vfree(vvalue);
62313@@ -377,7 +403,7 @@ retry:
62314 return error;
62315 error = mnt_want_write(path.mnt);
62316 if (!error) {
62317- error = setxattr(path.dentry, name, value, size, flags);
62318+ error = setxattr(&path, name, value, size, flags);
62319 mnt_drop_write(path.mnt);
62320 }
62321 path_put(&path);
62322@@ -401,7 +427,7 @@ retry:
62323 return error;
62324 error = mnt_want_write(path.mnt);
62325 if (!error) {
62326- error = setxattr(path.dentry, name, value, size, flags);
62327+ error = setxattr(&path, name, value, size, flags);
62328 mnt_drop_write(path.mnt);
62329 }
62330 path_put(&path);
62331@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
62332 const void __user *,value, size_t, size, int, flags)
62333 {
62334 struct fd f = fdget(fd);
62335- struct dentry *dentry;
62336 int error = -EBADF;
62337
62338 if (!f.file)
62339 return error;
62340- dentry = f.file->f_path.dentry;
62341- audit_inode(NULL, dentry, 0);
62342+ audit_inode(NULL, f.file->f_path.dentry, 0);
62343 error = mnt_want_write_file(f.file);
62344 if (!error) {
62345- error = setxattr(dentry, name, value, size, flags);
62346+ error = setxattr(&f.file->f_path, name, value, size, flags);
62347 mnt_drop_write_file(f.file);
62348 }
62349 fdput(f);
62350diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
62351index 9fbea87..6b19972 100644
62352--- a/fs/xattr_acl.c
62353+++ b/fs/xattr_acl.c
62354@@ -76,8 +76,8 @@ struct posix_acl *
62355 posix_acl_from_xattr(struct user_namespace *user_ns,
62356 const void *value, size_t size)
62357 {
62358- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62359- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62360+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62361+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62362 int count;
62363 struct posix_acl *acl;
62364 struct posix_acl_entry *acl_e;
62365diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
62366index f47e65c..e7125d9 100644
62367--- a/fs/xfs/xfs_bmap.c
62368+++ b/fs/xfs/xfs_bmap.c
62369@@ -586,7 +586,7 @@ xfs_bmap_validate_ret(
62370
62371 #else
62372 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
62373-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
62374+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
62375 #endif /* DEBUG */
62376
62377 /*
62378diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
62379index 8f84153..7ce60d0 100644
62380--- a/fs/xfs/xfs_dir2_readdir.c
62381+++ b/fs/xfs/xfs_dir2_readdir.c
62382@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
62383 ino = xfs_dir3_sfe_get_ino(mp, sfp, sfep);
62384 filetype = xfs_dir3_sfe_get_ftype(mp, sfp, sfep);
62385 ctx->pos = off & 0x7fffffff;
62386- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
62387+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
62388+ char name[sfep->namelen];
62389+ memcpy(name, sfep->name, sfep->namelen);
62390+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
62391+ return 0;
62392+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
62393 xfs_dir3_get_dtype(mp, filetype)))
62394 return 0;
62395 sfep = xfs_dir3_sf_nextentry(mp, sfp, sfep);
62396diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
62397index 2e1e6c3..689f742 100644
62398--- a/fs/xfs/xfs_ioctl.c
62399+++ b/fs/xfs/xfs_ioctl.c
62400@@ -127,7 +127,7 @@ xfs_find_handle(
62401 }
62402
62403 error = -EFAULT;
62404- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
62405+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
62406 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
62407 goto out_put;
62408
62409@@ -443,7 +443,8 @@ xfs_attrlist_by_handle(
62410 return -XFS_ERROR(EPERM);
62411 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
62412 return -XFS_ERROR(EFAULT);
62413- if (al_hreq.buflen > XATTR_LIST_MAX)
62414+ if (al_hreq.buflen < sizeof(struct attrlist) ||
62415+ al_hreq.buflen > XATTR_LIST_MAX)
62416 return -XFS_ERROR(EINVAL);
62417
62418 /*
62419diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c
62420index f671f7e..53365c6 100644
62421--- a/fs/xfs/xfs_ioctl32.c
62422+++ b/fs/xfs/xfs_ioctl32.c
62423@@ -357,7 +357,8 @@ xfs_compat_attrlist_by_handle(
62424 if (copy_from_user(&al_hreq, arg,
62425 sizeof(compat_xfs_fsop_attrlist_handlereq_t)))
62426 return -XFS_ERROR(EFAULT);
62427- if (al_hreq.buflen > XATTR_LIST_MAX)
62428+ if (al_hreq.buflen < sizeof(struct attrlist) ||
62429+ al_hreq.buflen > XATTR_LIST_MAX)
62430 return -XFS_ERROR(EINVAL);
62431
62432 /*
62433diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
62434index 2b8952d..a60c6be 100644
62435--- a/fs/xfs/xfs_iops.c
62436+++ b/fs/xfs/xfs_iops.c
62437@@ -401,7 +401,7 @@ xfs_vn_put_link(
62438 struct nameidata *nd,
62439 void *p)
62440 {
62441- char *s = nd_get_link(nd);
62442+ const char *s = nd_get_link(nd);
62443
62444 if (!IS_ERR(s))
62445 kfree(s);
62446diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
62447new file mode 100644
62448index 0000000..a78d810
62449--- /dev/null
62450+++ b/grsecurity/Kconfig
62451@@ -0,0 +1,1107 @@
62452+#
62453+# grecurity configuration
62454+#
62455+menu "Memory Protections"
62456+depends on GRKERNSEC
62457+
62458+config GRKERNSEC_KMEM
62459+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
62460+ default y if GRKERNSEC_CONFIG_AUTO
62461+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
62462+ help
62463+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
62464+ be written to or read from to modify or leak the contents of the running
62465+ kernel. /dev/port will also not be allowed to be opened, and support
62466+ for /dev/cpu/*/msr and kexec will be removed. If you have module
62467+ support disabled, enabling this will close up six ways that are
62468+ currently used to insert malicious code into the running kernel.
62469+
62470+ Even with this feature enabled, we still highly recommend that
62471+ you use the RBAC system, as it is still possible for an attacker to
62472+ modify the running kernel through other more obscure methods.
62473+
62474+ Enabling this feature will prevent the "cpupower" and "powertop" tools
62475+ from working.
62476+
62477+ It is highly recommended that you say Y here if you meet all the
62478+ conditions above.
62479+
62480+config GRKERNSEC_VM86
62481+ bool "Restrict VM86 mode"
62482+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62483+ depends on X86_32
62484+
62485+ help
62486+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
62487+ make use of a special execution mode on 32bit x86 processors called
62488+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
62489+ video cards and will still work with this option enabled. The purpose
62490+ of the option is to prevent exploitation of emulation errors in
62491+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
62492+ Nearly all users should be able to enable this option.
62493+
62494+config GRKERNSEC_IO
62495+ bool "Disable privileged I/O"
62496+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62497+ depends on X86
62498+ select RTC_CLASS
62499+ select RTC_INTF_DEV
62500+ select RTC_DRV_CMOS
62501+
62502+ help
62503+ If you say Y here, all ioperm and iopl calls will return an error.
62504+ Ioperm and iopl can be used to modify the running kernel.
62505+ Unfortunately, some programs need this access to operate properly,
62506+ the most notable of which are XFree86 and hwclock. hwclock can be
62507+ remedied by having RTC support in the kernel, so real-time
62508+ clock support is enabled if this option is enabled, to ensure
62509+ that hwclock operates correctly.
62510+
62511+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
62512+ you may not be able to boot into a graphical environment with this
62513+ option enabled. In this case, you should use the RBAC system instead.
62514+
62515+config GRKERNSEC_JIT_HARDEN
62516+ bool "Harden BPF JIT against spray attacks"
62517+ default y if GRKERNSEC_CONFIG_AUTO
62518+ depends on BPF_JIT
62519+ help
62520+ If you say Y here, the native code generated by the kernel's Berkeley
62521+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
62522+ attacks that attempt to fit attacker-beneficial instructions in
62523+ 32bit immediate fields of JIT-generated native instructions. The
62524+ attacker will generally aim to cause an unintended instruction sequence
62525+ of JIT-generated native code to execute by jumping into the middle of
62526+ a generated instruction. This feature effectively randomizes the 32bit
62527+ immediate constants present in the generated code to thwart such attacks.
62528+
62529+ If you're using KERNEXEC, it's recommended that you enable this option
62530+ to supplement the hardening of the kernel.
62531+
62532+config GRKERNSEC_PERF_HARDEN
62533+ bool "Disable unprivileged PERF_EVENTS usage by default"
62534+ default y if GRKERNSEC_CONFIG_AUTO
62535+ depends on PERF_EVENTS
62536+ help
62537+ If you say Y here, the range of acceptable values for the
62538+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
62539+ default to a new value: 3. When the sysctl is set to this value, no
62540+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
62541+
62542+ Though PERF_EVENTS can be used legitimately for performance monitoring
62543+ and low-level application profiling, it is forced on regardless of
62544+ configuration, has been at fault for several vulnerabilities, and
62545+ creates new opportunities for side channels and other information leaks.
62546+
62547+ This feature puts PERF_EVENTS into a secure default state and permits
62548+ the administrator to change out of it temporarily if unprivileged
62549+ application profiling is needed.
62550+
62551+config GRKERNSEC_RAND_THREADSTACK
62552+ bool "Insert random gaps between thread stacks"
62553+ default y if GRKERNSEC_CONFIG_AUTO
62554+ depends on PAX_RANDMMAP && !PPC
62555+ help
62556+ If you say Y here, a random-sized gap will be enforced between allocated
62557+ thread stacks. Glibc's NPTL and other threading libraries that
62558+ pass MAP_STACK to the kernel for thread stack allocation are supported.
62559+ The implementation currently provides 8 bits of entropy for the gap.
62560+
62561+ Many distributions do not compile threaded remote services with the
62562+ -fstack-check argument to GCC, causing the variable-sized stack-based
62563+ allocator, alloca(), to not probe the stack on allocation. This
62564+ permits an unbounded alloca() to skip over any guard page and potentially
62565+ modify another thread's stack reliably. An enforced random gap
62566+ reduces the reliability of such an attack and increases the chance
62567+ that such a read/write to another thread's stack instead lands in
62568+ an unmapped area, causing a crash and triggering grsecurity's
62569+ anti-bruteforcing logic.
62570+
62571+config GRKERNSEC_PROC_MEMMAP
62572+ bool "Harden ASLR against information leaks and entropy reduction"
62573+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
62574+ depends on PAX_NOEXEC || PAX_ASLR
62575+ help
62576+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
62577+ give no information about the addresses of its mappings if
62578+ PaX features that rely on random addresses are enabled on the task.
62579+ In addition to sanitizing this information and disabling other
62580+ dangerous sources of information, this option causes reads of sensitive
62581+ /proc/<pid> entries where the file descriptor was opened in a different
62582+ task than the one performing the read. Such attempts are logged.
62583+ This option also limits argv/env strings for suid/sgid binaries
62584+ to 512KB to prevent a complete exhaustion of the stack entropy provided
62585+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
62586+ binaries to prevent alternative mmap layouts from being abused.
62587+
62588+ If you use PaX it is essential that you say Y here as it closes up
62589+ several holes that make full ASLR useless locally.
62590+
62591+config GRKERNSEC_BRUTE
62592+ bool "Deter exploit bruteforcing"
62593+ default y if GRKERNSEC_CONFIG_AUTO
62594+ help
62595+ If you say Y here, attempts to bruteforce exploits against forking
62596+ daemons such as apache or sshd, as well as against suid/sgid binaries
62597+ will be deterred. When a child of a forking daemon is killed by PaX
62598+ or crashes due to an illegal instruction or other suspicious signal,
62599+ the parent process will be delayed 30 seconds upon every subsequent
62600+ fork until the administrator is able to assess the situation and
62601+ restart the daemon.
62602+ In the suid/sgid case, the attempt is logged, the user has all their
62603+ existing instances of the suid/sgid binary terminated and will
62604+ be unable to execute any suid/sgid binaries for 15 minutes.
62605+
62606+ It is recommended that you also enable signal logging in the auditing
62607+ section so that logs are generated when a process triggers a suspicious
62608+ signal.
62609+ If the sysctl option is enabled, a sysctl option with name
62610+ "deter_bruteforce" is created.
62611+
62612+
62613+config GRKERNSEC_MODHARDEN
62614+ bool "Harden module auto-loading"
62615+ default y if GRKERNSEC_CONFIG_AUTO
62616+ depends on MODULES
62617+ help
62618+ If you say Y here, module auto-loading in response to use of some
62619+ feature implemented by an unloaded module will be restricted to
62620+ root users. Enabling this option helps defend against attacks
62621+ by unprivileged users who abuse the auto-loading behavior to
62622+ cause a vulnerable module to load that is then exploited.
62623+
62624+ If this option prevents a legitimate use of auto-loading for a
62625+ non-root user, the administrator can execute modprobe manually
62626+ with the exact name of the module mentioned in the alert log.
62627+ Alternatively, the administrator can add the module to the list
62628+ of modules loaded at boot by modifying init scripts.
62629+
62630+ Modification of init scripts will most likely be needed on
62631+ Ubuntu servers with encrypted home directory support enabled,
62632+ as the first non-root user logging in will cause the ecb(aes),
62633+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
62634+
62635+config GRKERNSEC_HIDESYM
62636+ bool "Hide kernel symbols"
62637+ default y if GRKERNSEC_CONFIG_AUTO
62638+ select PAX_USERCOPY_SLABS
62639+ help
62640+ If you say Y here, getting information on loaded modules, and
62641+ displaying all kernel symbols through a syscall will be restricted
62642+ to users with CAP_SYS_MODULE. For software compatibility reasons,
62643+ /proc/kallsyms will be restricted to the root user. The RBAC
62644+ system can hide that entry even from root.
62645+
62646+ This option also prevents leaking of kernel addresses through
62647+ several /proc entries.
62648+
62649+ Note that this option is only effective provided the following
62650+ conditions are met:
62651+ 1) The kernel using grsecurity is not precompiled by some distribution
62652+ 2) You have also enabled GRKERNSEC_DMESG
62653+ 3) You are using the RBAC system and hiding other files such as your
62654+ kernel image and System.map. Alternatively, enabling this option
62655+ causes the permissions on /boot, /lib/modules, and the kernel
62656+ source directory to change at compile time to prevent
62657+ reading by non-root users.
62658+ If the above conditions are met, this option will aid in providing a
62659+ useful protection against local kernel exploitation of overflows
62660+ and arbitrary read/write vulnerabilities.
62661+
62662+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
62663+ in addition to this feature.
62664+
62665+config GRKERNSEC_KERN_LOCKOUT
62666+ bool "Active kernel exploit response"
62667+ default y if GRKERNSEC_CONFIG_AUTO
62668+ depends on X86 || ARM || PPC || SPARC
62669+ help
62670+ If you say Y here, when a PaX alert is triggered due to suspicious
62671+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
62672+ or an OOPS occurs due to bad memory accesses, instead of just
62673+ terminating the offending process (and potentially allowing
62674+ a subsequent exploit from the same user), we will take one of two
62675+ actions:
62676+ If the user was root, we will panic the system
62677+ If the user was non-root, we will log the attempt, terminate
62678+ all processes owned by the user, then prevent them from creating
62679+ any new processes until the system is restarted
62680+ This deters repeated kernel exploitation/bruteforcing attempts
62681+ and is useful for later forensics.
62682+
62683+config GRKERNSEC_OLD_ARM_USERLAND
62684+ bool "Old ARM userland compatibility"
62685+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
62686+ help
62687+ If you say Y here, stubs of executable code to perform such operations
62688+ as "compare-exchange" will be placed at fixed locations in the ARM vector
62689+ table. This is unfortunately needed for old ARM userland meant to run
62690+ across a wide range of processors. Without this option enabled,
62691+ the get_tls and data memory barrier stubs will be emulated by the kernel,
62692+ which is enough for Linaro userlands or other userlands designed for v6
62693+ and newer ARM CPUs. It's recommended that you try without this option enabled
62694+ first, and only enable it if your userland does not boot (it will likely fail
62695+ at init time).
62696+
62697+endmenu
62698+menu "Role Based Access Control Options"
62699+depends on GRKERNSEC
62700+
62701+config GRKERNSEC_RBAC_DEBUG
62702+ bool
62703+
62704+config GRKERNSEC_NO_RBAC
62705+ bool "Disable RBAC system"
62706+ help
62707+ If you say Y here, the /dev/grsec device will be removed from the kernel,
62708+ preventing the RBAC system from being enabled. You should only say Y
62709+ here if you have no intention of using the RBAC system, so as to prevent
62710+ an attacker with root access from misusing the RBAC system to hide files
62711+ and processes when loadable module support and /dev/[k]mem have been
62712+ locked down.
62713+
62714+config GRKERNSEC_ACL_HIDEKERN
62715+ bool "Hide kernel processes"
62716+ help
62717+ If you say Y here, all kernel threads will be hidden to all
62718+ processes but those whose subject has the "view hidden processes"
62719+ flag.
62720+
62721+config GRKERNSEC_ACL_MAXTRIES
62722+ int "Maximum tries before password lockout"
62723+ default 3
62724+ help
62725+ This option enforces the maximum number of times a user can attempt
62726+ to authorize themselves with the grsecurity RBAC system before being
62727+ denied the ability to attempt authorization again for a specified time.
62728+ The lower the number, the harder it will be to brute-force a password.
62729+
62730+config GRKERNSEC_ACL_TIMEOUT
62731+ int "Time to wait after max password tries, in seconds"
62732+ default 30
62733+ help
62734+ This option specifies the time the user must wait after attempting to
62735+ authorize to the RBAC system with the maximum number of invalid
62736+ passwords. The higher the number, the harder it will be to brute-force
62737+ a password.
62738+
62739+endmenu
62740+menu "Filesystem Protections"
62741+depends on GRKERNSEC
62742+
62743+config GRKERNSEC_PROC
62744+ bool "Proc restrictions"
62745+ default y if GRKERNSEC_CONFIG_AUTO
62746+ help
62747+ If you say Y here, the permissions of the /proc filesystem
62748+ will be altered to enhance system security and privacy. You MUST
62749+ choose either a user only restriction or a user and group restriction.
62750+ Depending upon the option you choose, you can either restrict users to
62751+ see only the processes they themselves run, or choose a group that can
62752+ view all processes and files normally restricted to root if you choose
62753+ the "restrict to user only" option. NOTE: If you're running identd or
62754+ ntpd as a non-root user, you will have to run it as the group you
62755+ specify here.
62756+
62757+config GRKERNSEC_PROC_USER
62758+ bool "Restrict /proc to user only"
62759+ depends on GRKERNSEC_PROC
62760+ help
62761+ If you say Y here, non-root users will only be able to view their own
62762+ processes, and restricts them from viewing network-related information,
62763+ and viewing kernel symbol and module information.
62764+
62765+config GRKERNSEC_PROC_USERGROUP
62766+ bool "Allow special group"
62767+ default y if GRKERNSEC_CONFIG_AUTO
62768+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
62769+ help
62770+ If you say Y here, you will be able to select a group that will be
62771+ able to view all processes and network-related information. If you've
62772+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
62773+ remain hidden. This option is useful if you want to run identd as
62774+ a non-root user. The group you select may also be chosen at boot time
62775+ via "grsec_proc_gid=" on the kernel commandline.
62776+
62777+config GRKERNSEC_PROC_GID
62778+ int "GID for special group"
62779+ depends on GRKERNSEC_PROC_USERGROUP
62780+ default 1001
62781+
62782+config GRKERNSEC_PROC_ADD
62783+ bool "Additional restrictions"
62784+ default y if GRKERNSEC_CONFIG_AUTO
62785+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
62786+ help
62787+ If you say Y here, additional restrictions will be placed on
62788+ /proc that keep normal users from viewing device information and
62789+ slabinfo information that could be useful for exploits.
62790+
62791+config GRKERNSEC_LINK
62792+ bool "Linking restrictions"
62793+ default y if GRKERNSEC_CONFIG_AUTO
62794+ help
62795+ If you say Y here, /tmp race exploits will be prevented, since users
62796+ will no longer be able to follow symlinks owned by other users in
62797+ world-writable +t directories (e.g. /tmp), unless the owner of the
62798+ symlink is the owner of the directory. users will also not be
62799+ able to hardlink to files they do not own. If the sysctl option is
62800+ enabled, a sysctl option with name "linking_restrictions" is created.
62801+
62802+config GRKERNSEC_SYMLINKOWN
62803+ bool "Kernel-enforced SymlinksIfOwnerMatch"
62804+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62805+ help
62806+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
62807+ that prevents it from being used as a security feature. As Apache
62808+ verifies the symlink by performing a stat() against the target of
62809+ the symlink before it is followed, an attacker can setup a symlink
62810+ to point to a same-owned file, then replace the symlink with one
62811+ that targets another user's file just after Apache "validates" the
62812+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
62813+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
62814+ will be in place for the group you specify. If the sysctl option
62815+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
62816+ created.
62817+
62818+config GRKERNSEC_SYMLINKOWN_GID
62819+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
62820+ depends on GRKERNSEC_SYMLINKOWN
62821+ default 1006
62822+ help
62823+ Setting this GID determines what group kernel-enforced
62824+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
62825+ is enabled, a sysctl option with name "symlinkown_gid" is created.
62826+
62827+config GRKERNSEC_FIFO
62828+ bool "FIFO restrictions"
62829+ default y if GRKERNSEC_CONFIG_AUTO
62830+ help
62831+ If you say Y here, users will not be able to write to FIFOs they don't
62832+ own in world-writable +t directories (e.g. /tmp), unless the owner of
62833+ the FIFO is the same owner of the directory it's held in. If the sysctl
62834+ option is enabled, a sysctl option with name "fifo_restrictions" is
62835+ created.
62836+
62837+config GRKERNSEC_SYSFS_RESTRICT
62838+ bool "Sysfs/debugfs restriction"
62839+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62840+ depends on SYSFS
62841+ help
62842+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
62843+ any filesystem normally mounted under it (e.g. debugfs) will be
62844+ mostly accessible only by root. These filesystems generally provide access
62845+ to hardware and debug information that isn't appropriate for unprivileged
62846+ users of the system. Sysfs and debugfs have also become a large source
62847+ of new vulnerabilities, ranging from infoleaks to local compromise.
62848+ There has been very little oversight with an eye toward security involved
62849+ in adding new exporters of information to these filesystems, so their
62850+ use is discouraged.
62851+ For reasons of compatibility, a few directories have been whitelisted
62852+ for access by non-root users:
62853+ /sys/fs/selinux
62854+ /sys/fs/fuse
62855+ /sys/devices/system/cpu
62856+
62857+config GRKERNSEC_ROFS
62858+ bool "Runtime read-only mount protection"
62859+ depends on SYSCTL
62860+ help
62861+ If you say Y here, a sysctl option with name "romount_protect" will
62862+ be created. By setting this option to 1 at runtime, filesystems
62863+ will be protected in the following ways:
62864+ * No new writable mounts will be allowed
62865+ * Existing read-only mounts won't be able to be remounted read/write
62866+ * Write operations will be denied on all block devices
62867+ This option acts independently of grsec_lock: once it is set to 1,
62868+ it cannot be turned off. Therefore, please be mindful of the resulting
62869+ behavior if this option is enabled in an init script on a read-only
62870+ filesystem. This feature is mainly intended for secure embedded systems.
62871+
62872+config GRKERNSEC_DEVICE_SIDECHANNEL
62873+ bool "Eliminate stat/notify-based device sidechannels"
62874+ default y if GRKERNSEC_CONFIG_AUTO
62875+ help
62876+ If you say Y here, timing analyses on block or character
62877+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62878+ will be thwarted for unprivileged users. If a process without
62879+ CAP_MKNOD stats such a device, the last access and last modify times
62880+ will match the device's create time. No access or modify events
62881+ will be triggered through inotify/dnotify/fanotify for such devices.
62882+ This feature will prevent attacks that may at a minimum
62883+ allow an attacker to determine the administrator's password length.
62884+
62885+config GRKERNSEC_CHROOT
62886+ bool "Chroot jail restrictions"
62887+ default y if GRKERNSEC_CONFIG_AUTO
62888+ help
62889+ If you say Y here, you will be able to choose several options that will
62890+ make breaking out of a chrooted jail much more difficult. If you
62891+ encounter no software incompatibilities with the following options, it
62892+ is recommended that you enable each one.
62893+
62894+config GRKERNSEC_CHROOT_MOUNT
62895+ bool "Deny mounts"
62896+ default y if GRKERNSEC_CONFIG_AUTO
62897+ depends on GRKERNSEC_CHROOT
62898+ help
62899+ If you say Y here, processes inside a chroot will not be able to
62900+ mount or remount filesystems. If the sysctl option is enabled, a
62901+ sysctl option with name "chroot_deny_mount" is created.
62902+
62903+config GRKERNSEC_CHROOT_DOUBLE
62904+ bool "Deny double-chroots"
62905+ default y if GRKERNSEC_CONFIG_AUTO
62906+ depends on GRKERNSEC_CHROOT
62907+ help
62908+ If you say Y here, processes inside a chroot will not be able to chroot
62909+ again outside the chroot. This is a widely used method of breaking
62910+ out of a chroot jail and should not be allowed. If the sysctl
62911+ option is enabled, a sysctl option with name
62912+ "chroot_deny_chroot" is created.
62913+
62914+config GRKERNSEC_CHROOT_PIVOT
62915+ bool "Deny pivot_root in chroot"
62916+ default y if GRKERNSEC_CONFIG_AUTO
62917+ depends on GRKERNSEC_CHROOT
62918+ help
62919+ If you say Y here, processes inside a chroot will not be able to use
62920+ a function called pivot_root() that was introduced in Linux 2.3.41. It
62921+ works similar to chroot in that it changes the root filesystem. This
62922+ function could be misused in a chrooted process to attempt to break out
62923+ of the chroot, and therefore should not be allowed. If the sysctl
62924+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
62925+ created.
62926+
62927+config GRKERNSEC_CHROOT_CHDIR
62928+ bool "Enforce chdir(\"/\") on all chroots"
62929+ default y if GRKERNSEC_CONFIG_AUTO
62930+ depends on GRKERNSEC_CHROOT
62931+ help
62932+ If you say Y here, the current working directory of all newly-chrooted
62933+ applications will be set to the the root directory of the chroot.
62934+ The man page on chroot(2) states:
62935+ Note that this call does not change the current working
62936+ directory, so that `.' can be outside the tree rooted at
62937+ `/'. In particular, the super-user can escape from a
62938+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
62939+
62940+ It is recommended that you say Y here, since it's not known to break
62941+ any software. If the sysctl option is enabled, a sysctl option with
62942+ name "chroot_enforce_chdir" is created.
62943+
62944+config GRKERNSEC_CHROOT_CHMOD
62945+ bool "Deny (f)chmod +s"
62946+ default y if GRKERNSEC_CONFIG_AUTO
62947+ depends on GRKERNSEC_CHROOT
62948+ help
62949+ If you say Y here, processes inside a chroot will not be able to chmod
62950+ or fchmod files to make them have suid or sgid bits. This protects
62951+ against another published method of breaking a chroot. If the sysctl
62952+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
62953+ created.
62954+
62955+config GRKERNSEC_CHROOT_FCHDIR
62956+ bool "Deny fchdir out of chroot"
62957+ default y if GRKERNSEC_CONFIG_AUTO
62958+ depends on GRKERNSEC_CHROOT
62959+ help
62960+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
62961+ to a file descriptor of the chrooting process that points to a directory
62962+ outside the filesystem will be stopped. If the sysctl option
62963+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
62964+
62965+config GRKERNSEC_CHROOT_MKNOD
62966+ bool "Deny mknod"
62967+ default y if GRKERNSEC_CONFIG_AUTO
62968+ depends on GRKERNSEC_CHROOT
62969+ help
62970+ If you say Y here, processes inside a chroot will not be allowed to
62971+ mknod. The problem with using mknod inside a chroot is that it
62972+ would allow an attacker to create a device entry that is the same
62973+ as one on the physical root of your system, which could range from
62974+ anything from the console device to a device for your harddrive (which
62975+ they could then use to wipe the drive or steal data). It is recommended
62976+ that you say Y here, unless you run into software incompatibilities.
62977+ If the sysctl option is enabled, a sysctl option with name
62978+ "chroot_deny_mknod" is created.
62979+
62980+config GRKERNSEC_CHROOT_SHMAT
62981+ bool "Deny shmat() out of chroot"
62982+ default y if GRKERNSEC_CONFIG_AUTO
62983+ depends on GRKERNSEC_CHROOT
62984+ help
62985+ If you say Y here, processes inside a chroot will not be able to attach
62986+ to shared memory segments that were created outside of the chroot jail.
62987+ It is recommended that you say Y here. If the sysctl option is enabled,
62988+ a sysctl option with name "chroot_deny_shmat" is created.
62989+
62990+config GRKERNSEC_CHROOT_UNIX
62991+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
62992+ default y if GRKERNSEC_CONFIG_AUTO
62993+ depends on GRKERNSEC_CHROOT
62994+ help
62995+ If you say Y here, processes inside a chroot will not be able to
62996+ connect to abstract (meaning not belonging to a filesystem) Unix
62997+ domain sockets that were bound outside of a chroot. It is recommended
62998+ that you say Y here. If the sysctl option is enabled, a sysctl option
62999+ with name "chroot_deny_unix" is created.
63000+
63001+config GRKERNSEC_CHROOT_FINDTASK
63002+ bool "Protect outside processes"
63003+ default y if GRKERNSEC_CONFIG_AUTO
63004+ depends on GRKERNSEC_CHROOT
63005+ help
63006+ If you say Y here, processes inside a chroot will not be able to
63007+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
63008+ getsid, or view any process outside of the chroot. If the sysctl
63009+ option is enabled, a sysctl option with name "chroot_findtask" is
63010+ created.
63011+
63012+config GRKERNSEC_CHROOT_NICE
63013+ bool "Restrict priority changes"
63014+ default y if GRKERNSEC_CONFIG_AUTO
63015+ depends on GRKERNSEC_CHROOT
63016+ help
63017+ If you say Y here, processes inside a chroot will not be able to raise
63018+ the priority of processes in the chroot, or alter the priority of
63019+ processes outside the chroot. This provides more security than simply
63020+ removing CAP_SYS_NICE from the process' capability set. If the
63021+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
63022+ is created.
63023+
63024+config GRKERNSEC_CHROOT_SYSCTL
63025+ bool "Deny sysctl writes"
63026+ default y if GRKERNSEC_CONFIG_AUTO
63027+ depends on GRKERNSEC_CHROOT
63028+ help
63029+ If you say Y here, an attacker in a chroot will not be able to
63030+ write to sysctl entries, either by sysctl(2) or through a /proc
63031+ interface. It is strongly recommended that you say Y here. If the
63032+ sysctl option is enabled, a sysctl option with name
63033+ "chroot_deny_sysctl" is created.
63034+
63035+config GRKERNSEC_CHROOT_CAPS
63036+ bool "Capability restrictions"
63037+ default y if GRKERNSEC_CONFIG_AUTO
63038+ depends on GRKERNSEC_CHROOT
63039+ help
63040+ If you say Y here, the capabilities on all processes within a
63041+ chroot jail will be lowered to stop module insertion, raw i/o,
63042+ system and net admin tasks, rebooting the system, modifying immutable
63043+ files, modifying IPC owned by another, and changing the system time.
63044+ This is left an option because it can break some apps. Disable this
63045+ if your chrooted apps are having problems performing those kinds of
63046+ tasks. If the sysctl option is enabled, a sysctl option with
63047+ name "chroot_caps" is created.
63048+
63049+config GRKERNSEC_CHROOT_INITRD
63050+ bool "Exempt initrd tasks from restrictions"
63051+ default y if GRKERNSEC_CONFIG_AUTO
63052+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
63053+ help
63054+ If you say Y here, tasks started prior to init will be exempted from
63055+ grsecurity's chroot restrictions. This option is mainly meant to
63056+ resolve Plymouth's performing privileged operations unnecessarily
63057+ in a chroot.
63058+
63059+endmenu
63060+menu "Kernel Auditing"
63061+depends on GRKERNSEC
63062+
63063+config GRKERNSEC_AUDIT_GROUP
63064+ bool "Single group for auditing"
63065+ help
63066+ If you say Y here, the exec and chdir logging features will only operate
63067+ on a group you specify. This option is recommended if you only want to
63068+ watch certain users instead of having a large amount of logs from the
63069+ entire system. If the sysctl option is enabled, a sysctl option with
63070+ name "audit_group" is created.
63071+
63072+config GRKERNSEC_AUDIT_GID
63073+ int "GID for auditing"
63074+ depends on GRKERNSEC_AUDIT_GROUP
63075+ default 1007
63076+
63077+config GRKERNSEC_EXECLOG
63078+ bool "Exec logging"
63079+ help
63080+ If you say Y here, all execve() calls will be logged (since the
63081+ other exec*() calls are frontends to execve(), all execution
63082+ will be logged). Useful for shell-servers that like to keep track
63083+ of their users. If the sysctl option is enabled, a sysctl option with
63084+ name "exec_logging" is created.
63085+ WARNING: This option when enabled will produce a LOT of logs, especially
63086+ on an active system.
63087+
63088+config GRKERNSEC_RESLOG
63089+ bool "Resource logging"
63090+ default y if GRKERNSEC_CONFIG_AUTO
63091+ help
63092+ If you say Y here, all attempts to overstep resource limits will
63093+ be logged with the resource name, the requested size, and the current
63094+ limit. It is highly recommended that you say Y here. If the sysctl
63095+ option is enabled, a sysctl option with name "resource_logging" is
63096+ created. If the RBAC system is enabled, the sysctl value is ignored.
63097+
63098+config GRKERNSEC_CHROOT_EXECLOG
63099+ bool "Log execs within chroot"
63100+ help
63101+ If you say Y here, all executions inside a chroot jail will be logged
63102+ to syslog. This can cause a large amount of logs if certain
63103+ applications (eg. djb's daemontools) are installed on the system, and
63104+ is therefore left as an option. If the sysctl option is enabled, a
63105+ sysctl option with name "chroot_execlog" is created.
63106+
63107+config GRKERNSEC_AUDIT_PTRACE
63108+ bool "Ptrace logging"
63109+ help
63110+ If you say Y here, all attempts to attach to a process via ptrace
63111+ will be logged. If the sysctl option is enabled, a sysctl option
63112+ with name "audit_ptrace" is created.
63113+
63114+config GRKERNSEC_AUDIT_CHDIR
63115+ bool "Chdir logging"
63116+ help
63117+ If you say Y here, all chdir() calls will be logged. If the sysctl
63118+ option is enabled, a sysctl option with name "audit_chdir" is created.
63119+
63120+config GRKERNSEC_AUDIT_MOUNT
63121+ bool "(Un)Mount logging"
63122+ help
63123+ If you say Y here, all mounts and unmounts will be logged. If the
63124+ sysctl option is enabled, a sysctl option with name "audit_mount" is
63125+ created.
63126+
63127+config GRKERNSEC_SIGNAL
63128+ bool "Signal logging"
63129+ default y if GRKERNSEC_CONFIG_AUTO
63130+ help
63131+ If you say Y here, certain important signals will be logged, such as
63132+ SIGSEGV, which will as a result inform you of when a error in a program
63133+ occurred, which in some cases could mean a possible exploit attempt.
63134+ If the sysctl option is enabled, a sysctl option with name
63135+ "signal_logging" is created.
63136+
63137+config GRKERNSEC_FORKFAIL
63138+ bool "Fork failure logging"
63139+ help
63140+ If you say Y here, all failed fork() attempts will be logged.
63141+ This could suggest a fork bomb, or someone attempting to overstep
63142+ their process limit. If the sysctl option is enabled, a sysctl option
63143+ with name "forkfail_logging" is created.
63144+
63145+config GRKERNSEC_TIME
63146+ bool "Time change logging"
63147+ default y if GRKERNSEC_CONFIG_AUTO
63148+ help
63149+ If you say Y here, any changes of the system clock will be logged.
63150+ If the sysctl option is enabled, a sysctl option with name
63151+ "timechange_logging" is created.
63152+
63153+config GRKERNSEC_PROC_IPADDR
63154+ bool "/proc/<pid>/ipaddr support"
63155+ default y if GRKERNSEC_CONFIG_AUTO
63156+ help
63157+ If you say Y here, a new entry will be added to each /proc/<pid>
63158+ directory that contains the IP address of the person using the task.
63159+ The IP is carried across local TCP and AF_UNIX stream sockets.
63160+ This information can be useful for IDS/IPSes to perform remote response
63161+ to a local attack. The entry is readable by only the owner of the
63162+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
63163+ the RBAC system), and thus does not create privacy concerns.
63164+
63165+config GRKERNSEC_RWXMAP_LOG
63166+ bool 'Denied RWX mmap/mprotect logging'
63167+ default y if GRKERNSEC_CONFIG_AUTO
63168+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
63169+ help
63170+ If you say Y here, calls to mmap() and mprotect() with explicit
63171+ usage of PROT_WRITE and PROT_EXEC together will be logged when
63172+ denied by the PAX_MPROTECT feature. This feature will also
63173+ log other problematic scenarios that can occur when PAX_MPROTECT
63174+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
63175+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
63176+ is created.
63177+
63178+endmenu
63179+
63180+menu "Executable Protections"
63181+depends on GRKERNSEC
63182+
63183+config GRKERNSEC_DMESG
63184+ bool "Dmesg(8) restriction"
63185+ default y if GRKERNSEC_CONFIG_AUTO
63186+ help
63187+ If you say Y here, non-root users will not be able to use dmesg(8)
63188+ to view the contents of the kernel's circular log buffer.
63189+ The kernel's log buffer often contains kernel addresses and other
63190+ identifying information useful to an attacker in fingerprinting a
63191+ system for a targeted exploit.
63192+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
63193+ created.
63194+
63195+config GRKERNSEC_HARDEN_PTRACE
63196+ bool "Deter ptrace-based process snooping"
63197+ default y if GRKERNSEC_CONFIG_AUTO
63198+ help
63199+ If you say Y here, TTY sniffers and other malicious monitoring
63200+ programs implemented through ptrace will be defeated. If you
63201+ have been using the RBAC system, this option has already been
63202+ enabled for several years for all users, with the ability to make
63203+ fine-grained exceptions.
63204+
63205+ This option only affects the ability of non-root users to ptrace
63206+ processes that are not a descendent of the ptracing process.
63207+ This means that strace ./binary and gdb ./binary will still work,
63208+ but attaching to arbitrary processes will not. If the sysctl
63209+ option is enabled, a sysctl option with name "harden_ptrace" is
63210+ created.
63211+
63212+config GRKERNSEC_PTRACE_READEXEC
63213+ bool "Require read access to ptrace sensitive binaries"
63214+ default y if GRKERNSEC_CONFIG_AUTO
63215+ help
63216+ If you say Y here, unprivileged users will not be able to ptrace unreadable
63217+ binaries. This option is useful in environments that
63218+ remove the read bits (e.g. file mode 4711) from suid binaries to
63219+ prevent infoleaking of their contents. This option adds
63220+ consistency to the use of that file mode, as the binary could normally
63221+ be read out when run without privileges while ptracing.
63222+
63223+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
63224+ is created.
63225+
63226+config GRKERNSEC_SETXID
63227+ bool "Enforce consistent multithreaded privileges"
63228+ default y if GRKERNSEC_CONFIG_AUTO
63229+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
63230+ help
63231+ If you say Y here, a change from a root uid to a non-root uid
63232+ in a multithreaded application will cause the resulting uids,
63233+ gids, supplementary groups, and capabilities in that thread
63234+ to be propagated to the other threads of the process. In most
63235+ cases this is unnecessary, as glibc will emulate this behavior
63236+ on behalf of the application. Other libcs do not act in the
63237+ same way, allowing the other threads of the process to continue
63238+ running with root privileges. If the sysctl option is enabled,
63239+ a sysctl option with name "consistent_setxid" is created.
63240+
63241+config GRKERNSEC_HARDEN_IPC
63242+ bool "Disallow access to world-accessible IPC objects"
63243+ default y if GRKERNSEC_CONFIG_AUTO
63244+ depends on SYSVIPC
63245+ help
63246+ If you say Y here, access to overly-permissive IPC (shared memory,
63247+ message queues, and semaphores) will be denied for processes whose
63248+ effective user or group would not grant them permission. It's a
63249+ common error to grant too much permission to these objects, with
63250+ impact ranging from denial of service and information leaking to
63251+ privilege escalation. This feature was developed in response to
63252+ research by Tim Brown:
63253+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
63254+ who found hundreds of such insecure usages. Processes with
63255+ CAP_IPC_OWNER are still permitted to access these IPC objects.
63256+ If the sysctl option is enabled, a sysctl option with name
63257+ "harden_ipc" is created.
63258+
63259+config GRKERNSEC_TPE
63260+ bool "Trusted Path Execution (TPE)"
63261+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
63262+ help
63263+ If you say Y here, you will be able to choose a gid to add to the
63264+ supplementary groups of users you want to mark as "untrusted."
63265+ These users will not be able to execute any files that are not in
63266+ root-owned directories writable only by root. If the sysctl option
63267+ is enabled, a sysctl option with name "tpe" is created.
63268+
63269+config GRKERNSEC_TPE_ALL
63270+ bool "Partially restrict all non-root users"
63271+ depends on GRKERNSEC_TPE
63272+ help
63273+ If you say Y here, all non-root users will be covered under
63274+ a weaker TPE restriction. This is separate from, and in addition to,
63275+ the main TPE options that you have selected elsewhere. Thus, if a
63276+ "trusted" GID is chosen, this restriction applies to even that GID.
63277+ Under this restriction, all non-root users will only be allowed to
63278+ execute files in directories they own that are not group or
63279+ world-writable, or in directories owned by root and writable only by
63280+ root. If the sysctl option is enabled, a sysctl option with name
63281+ "tpe_restrict_all" is created.
63282+
63283+config GRKERNSEC_TPE_INVERT
63284+ bool "Invert GID option"
63285+ depends on GRKERNSEC_TPE
63286+ help
63287+ If you say Y here, the group you specify in the TPE configuration will
63288+ decide what group TPE restrictions will be *disabled* for. This
63289+ option is useful if you want TPE restrictions to be applied to most
63290+ users on the system. If the sysctl option is enabled, a sysctl option
63291+ with name "tpe_invert" is created. Unlike other sysctl options, this
63292+ entry will default to on for backward-compatibility.
63293+
63294+config GRKERNSEC_TPE_GID
63295+ int
63296+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
63297+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
63298+
63299+config GRKERNSEC_TPE_UNTRUSTED_GID
63300+ int "GID for TPE-untrusted users"
63301+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
63302+ default 1005
63303+ help
63304+ Setting this GID determines what group TPE restrictions will be
63305+ *enabled* for. If the sysctl option is enabled, a sysctl option
63306+ with name "tpe_gid" is created.
63307+
63308+config GRKERNSEC_TPE_TRUSTED_GID
63309+ int "GID for TPE-trusted users"
63310+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
63311+ default 1005
63312+ help
63313+ Setting this GID determines what group TPE restrictions will be
63314+ *disabled* for. If the sysctl option is enabled, a sysctl option
63315+ with name "tpe_gid" is created.
63316+
63317+endmenu
63318+menu "Network Protections"
63319+depends on GRKERNSEC
63320+
63321+config GRKERNSEC_RANDNET
63322+ bool "Larger entropy pools"
63323+ default y if GRKERNSEC_CONFIG_AUTO
63324+ help
63325+ If you say Y here, the entropy pools used for many features of Linux
63326+ and grsecurity will be doubled in size. Since several grsecurity
63327+ features use additional randomness, it is recommended that you say Y
63328+ here. Saying Y here has a similar effect as modifying
63329+ /proc/sys/kernel/random/poolsize.
63330+
63331+config GRKERNSEC_BLACKHOLE
63332+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
63333+ default y if GRKERNSEC_CONFIG_AUTO
63334+ depends on NET
63335+ help
63336+ If you say Y here, neither TCP resets nor ICMP
63337+ destination-unreachable packets will be sent in response to packets
63338+ sent to ports for which no associated listening process exists.
63339+ This feature supports both IPV4 and IPV6 and exempts the
63340+ loopback interface from blackholing. Enabling this feature
63341+ makes a host more resilient to DoS attacks and reduces network
63342+ visibility against scanners.
63343+
63344+ The blackhole feature as-implemented is equivalent to the FreeBSD
63345+ blackhole feature, as it prevents RST responses to all packets, not
63346+ just SYNs. Under most application behavior this causes no
63347+ problems, but applications (like haproxy) may not close certain
63348+ connections in a way that cleanly terminates them on the remote
63349+ end, leaving the remote host in LAST_ACK state. Because of this
63350+ side-effect and to prevent intentional LAST_ACK DoSes, this
63351+ feature also adds automatic mitigation against such attacks.
63352+ The mitigation drastically reduces the amount of time a socket
63353+ can spend in LAST_ACK state. If you're using haproxy and not
63354+ all servers it connects to have this option enabled, consider
63355+ disabling this feature on the haproxy host.
63356+
63357+ If the sysctl option is enabled, two sysctl options with names
63358+ "ip_blackhole" and "lastack_retries" will be created.
63359+ While "ip_blackhole" takes the standard zero/non-zero on/off
63360+ toggle, "lastack_retries" uses the same kinds of values as
63361+ "tcp_retries1" and "tcp_retries2". The default value of 4
63362+ prevents a socket from lasting more than 45 seconds in LAST_ACK
63363+ state.
63364+
63365+config GRKERNSEC_NO_SIMULT_CONNECT
63366+ bool "Disable TCP Simultaneous Connect"
63367+ default y if GRKERNSEC_CONFIG_AUTO
63368+ depends on NET
63369+ help
63370+ If you say Y here, a feature by Willy Tarreau will be enabled that
63371+ removes a weakness in Linux's strict implementation of TCP that
63372+ allows two clients to connect to each other without either entering
63373+ a listening state. The weakness allows an attacker to easily prevent
63374+ a client from connecting to a known server provided the source port
63375+ for the connection is guessed correctly.
63376+
63377+ As the weakness could be used to prevent an antivirus or IPS from
63378+ fetching updates, or prevent an SSL gateway from fetching a CRL,
63379+ it should be eliminated by enabling this option. Though Linux is
63380+ one of few operating systems supporting simultaneous connect, it
63381+ has no legitimate use in practice and is rarely supported by firewalls.
63382+
63383+config GRKERNSEC_SOCKET
63384+ bool "Socket restrictions"
63385+ depends on NET
63386+ help
63387+ If you say Y here, you will be able to choose from several options.
63388+ If you assign a GID on your system and add it to the supplementary
63389+ groups of users you want to restrict socket access to, this patch
63390+ will perform up to three things, based on the option(s) you choose.
63391+
63392+config GRKERNSEC_SOCKET_ALL
63393+ bool "Deny any sockets to group"
63394+ depends on GRKERNSEC_SOCKET
63395+ help
63396+ If you say Y here, you will be able to choose a GID of whose users will
63397+ be unable to connect to other hosts from your machine or run server
63398+ applications from your machine. If the sysctl option is enabled, a
63399+ sysctl option with name "socket_all" is created.
63400+
63401+config GRKERNSEC_SOCKET_ALL_GID
63402+ int "GID to deny all sockets for"
63403+ depends on GRKERNSEC_SOCKET_ALL
63404+ default 1004
63405+ help
63406+ Here you can choose the GID to disable socket access for. Remember to
63407+ add the users you want socket access disabled for to the GID
63408+ specified here. If the sysctl option is enabled, a sysctl option
63409+ with name "socket_all_gid" is created.
63410+
63411+config GRKERNSEC_SOCKET_CLIENT
63412+ bool "Deny client sockets to group"
63413+ depends on GRKERNSEC_SOCKET
63414+ help
63415+ If you say Y here, you will be able to choose a GID of whose users will
63416+ be unable to connect to other hosts from your machine, but will be
63417+ able to run servers. If this option is enabled, all users in the group
63418+ you specify will have to use passive mode when initiating ftp transfers
63419+ from the shell on your machine. If the sysctl option is enabled, a
63420+ sysctl option with name "socket_client" is created.
63421+
63422+config GRKERNSEC_SOCKET_CLIENT_GID
63423+ int "GID to deny client sockets for"
63424+ depends on GRKERNSEC_SOCKET_CLIENT
63425+ default 1003
63426+ help
63427+ Here you can choose the GID to disable client socket access for.
63428+ Remember to add the users you want client socket access disabled for to
63429+ the GID specified here. If the sysctl option is enabled, a sysctl
63430+ option with name "socket_client_gid" is created.
63431+
63432+config GRKERNSEC_SOCKET_SERVER
63433+ bool "Deny server sockets to group"
63434+ depends on GRKERNSEC_SOCKET
63435+ help
63436+ If you say Y here, you will be able to choose a GID of whose users will
63437+ be unable to run server applications from your machine. If the sysctl
63438+ option is enabled, a sysctl option with name "socket_server" is created.
63439+
63440+config GRKERNSEC_SOCKET_SERVER_GID
63441+ int "GID to deny server sockets for"
63442+ depends on GRKERNSEC_SOCKET_SERVER
63443+ default 1002
63444+ help
63445+ Here you can choose the GID to disable server socket access for.
63446+ Remember to add the users you want server socket access disabled for to
63447+ the GID specified here. If the sysctl option is enabled, a sysctl
63448+ option with name "socket_server_gid" is created.
63449+
63450+endmenu
63451+
63452+menu "Physical Protections"
63453+depends on GRKERNSEC
63454+
63455+config GRKERNSEC_DENYUSB
63456+ bool "Deny new USB connections after toggle"
63457+ default y if GRKERNSEC_CONFIG_AUTO
63458+ depends on SYSCTL && USB_SUPPORT
63459+ help
63460+ If you say Y here, a new sysctl option with name "deny_new_usb"
63461+ will be created. Setting its value to 1 will prevent any new
63462+ USB devices from being recognized by the OS. Any attempted USB
63463+ device insertion will be logged. This option is intended to be
63464+ used against custom USB devices designed to exploit vulnerabilities
63465+ in various USB device drivers.
63466+
63467+ For greatest effectiveness, this sysctl should be set after any
63468+ relevant init scripts. This option is safe to enable in distros
63469+ as each user can choose whether or not to toggle the sysctl.
63470+
63471+config GRKERNSEC_DENYUSB_FORCE
63472+ bool "Reject all USB devices not connected at boot"
63473+ select USB
63474+ depends on GRKERNSEC_DENYUSB
63475+ help
63476+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
63477+ that doesn't involve a sysctl entry. This option should only be
63478+ enabled if you're sure you want to deny all new USB connections
63479+ at runtime and don't want to modify init scripts. This should not
63480+ be enabled by distros. It forces the core USB code to be built
63481+ into the kernel image so that all devices connected at boot time
63482+ can be recognized and new USB device connections can be prevented
63483+ prior to init running.
63484+
63485+endmenu
63486+
63487+menu "Sysctl Support"
63488+depends on GRKERNSEC && SYSCTL
63489+
63490+config GRKERNSEC_SYSCTL
63491+ bool "Sysctl support"
63492+ default y if GRKERNSEC_CONFIG_AUTO
63493+ help
63494+ If you say Y here, you will be able to change the options that
63495+ grsecurity runs with at bootup, without having to recompile your
63496+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
63497+ to enable (1) or disable (0) various features. All the sysctl entries
63498+ are mutable until the "grsec_lock" entry is set to a non-zero value.
63499+ All features enabled in the kernel configuration are disabled at boot
63500+ if you do not say Y to the "Turn on features by default" option.
63501+ All options should be set at startup, and the grsec_lock entry should
63502+ be set to a non-zero value after all the options are set.
63503+ *THIS IS EXTREMELY IMPORTANT*
63504+
63505+config GRKERNSEC_SYSCTL_DISTRO
63506+ bool "Extra sysctl support for distro makers (READ HELP)"
63507+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
63508+ help
63509+ If you say Y here, additional sysctl options will be created
63510+ for features that affect processes running as root. Therefore,
63511+ it is critical when using this option that the grsec_lock entry be
63512+ enabled after boot. Only distros with prebuilt kernel packages
63513+ with this option enabled that can ensure grsec_lock is enabled
63514+ after boot should use this option.
63515+ *Failure to set grsec_lock after boot makes all grsec features
63516+ this option covers useless*
63517+
63518+ Currently this option creates the following sysctl entries:
63519+ "Disable Privileged I/O": "disable_priv_io"
63520+
63521+config GRKERNSEC_SYSCTL_ON
63522+ bool "Turn on features by default"
63523+ default y if GRKERNSEC_CONFIG_AUTO
63524+ depends on GRKERNSEC_SYSCTL
63525+ help
63526+ If you say Y here, instead of having all features enabled in the
63527+ kernel configuration disabled at boot time, the features will be
63528+ enabled at boot time. It is recommended you say Y here unless
63529+ there is some reason you would want all sysctl-tunable features to
63530+ be disabled by default. As mentioned elsewhere, it is important
63531+ to enable the grsec_lock entry once you have finished modifying
63532+ the sysctl entries.
63533+
63534+endmenu
63535+menu "Logging Options"
63536+depends on GRKERNSEC
63537+
63538+config GRKERNSEC_FLOODTIME
63539+ int "Seconds in between log messages (minimum)"
63540+ default 10
63541+ help
63542+ This option allows you to enforce the number of seconds between
63543+ grsecurity log messages. The default should be suitable for most
63544+ people, however, if you choose to change it, choose a value small enough
63545+ to allow informative logs to be produced, but large enough to
63546+ prevent flooding.
63547+
63548+config GRKERNSEC_FLOODBURST
63549+ int "Number of messages in a burst (maximum)"
63550+ default 6
63551+ help
63552+ This option allows you to choose the maximum number of messages allowed
63553+ within the flood time interval you chose in a separate option. The
63554+ default should be suitable for most people, however if you find that
63555+ many of your logs are being interpreted as flooding, you may want to
63556+ raise this value.
63557+
63558+endmenu
63559diff --git a/grsecurity/Makefile b/grsecurity/Makefile
63560new file mode 100644
63561index 0000000..85beb79
63562--- /dev/null
63563+++ b/grsecurity/Makefile
63564@@ -0,0 +1,43 @@
63565+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
63566+# during 2001-2009 it has been completely redesigned by Brad Spengler
63567+# into an RBAC system
63568+#
63569+# All code in this directory and various hooks inserted throughout the kernel
63570+# are copyright Brad Spengler - Open Source Security, Inc., and released
63571+# under the GPL v2 or higher
63572+
63573+KBUILD_CFLAGS += -Werror
63574+
63575+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
63576+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
63577+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
63578+ grsec_usb.o grsec_ipc.o
63579+
63580+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
63581+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
63582+ gracl_learn.o grsec_log.o gracl_policy.o
63583+ifdef CONFIG_COMPAT
63584+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
63585+endif
63586+
63587+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
63588+
63589+ifdef CONFIG_NET
63590+obj-y += grsec_sock.o
63591+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
63592+endif
63593+
63594+ifndef CONFIG_GRKERNSEC
63595+obj-y += grsec_disabled.o
63596+endif
63597+
63598+ifdef CONFIG_GRKERNSEC_HIDESYM
63599+extra-y := grsec_hidesym.o
63600+$(obj)/grsec_hidesym.o:
63601+ @-chmod -f 500 /boot
63602+ @-chmod -f 500 /lib/modules
63603+ @-chmod -f 500 /lib64/modules
63604+ @-chmod -f 500 /lib32/modules
63605+ @-chmod -f 700 .
63606+ @echo ' grsec: protected kernel image paths'
63607+endif
63608diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
63609new file mode 100644
63610index 0000000..6affeea
63611--- /dev/null
63612+++ b/grsecurity/gracl.c
63613@@ -0,0 +1,2679 @@
63614+#include <linux/kernel.h>
63615+#include <linux/module.h>
63616+#include <linux/sched.h>
63617+#include <linux/mm.h>
63618+#include <linux/file.h>
63619+#include <linux/fs.h>
63620+#include <linux/namei.h>
63621+#include <linux/mount.h>
63622+#include <linux/tty.h>
63623+#include <linux/proc_fs.h>
63624+#include <linux/lglock.h>
63625+#include <linux/slab.h>
63626+#include <linux/vmalloc.h>
63627+#include <linux/types.h>
63628+#include <linux/sysctl.h>
63629+#include <linux/netdevice.h>
63630+#include <linux/ptrace.h>
63631+#include <linux/gracl.h>
63632+#include <linux/gralloc.h>
63633+#include <linux/security.h>
63634+#include <linux/grinternal.h>
63635+#include <linux/pid_namespace.h>
63636+#include <linux/stop_machine.h>
63637+#include <linux/fdtable.h>
63638+#include <linux/percpu.h>
63639+#include <linux/lglock.h>
63640+#include <linux/hugetlb.h>
63641+#include <linux/posix-timers.h>
63642+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63643+#include <linux/magic.h>
63644+#include <linux/pagemap.h>
63645+#include "../fs/btrfs/async-thread.h"
63646+#include "../fs/btrfs/ctree.h"
63647+#include "../fs/btrfs/btrfs_inode.h"
63648+#endif
63649+#include "../fs/mount.h"
63650+
63651+#include <asm/uaccess.h>
63652+#include <asm/errno.h>
63653+#include <asm/mman.h>
63654+
63655+#define FOR_EACH_ROLE_START(role) \
63656+ role = running_polstate.role_list; \
63657+ while (role) {
63658+
63659+#define FOR_EACH_ROLE_END(role) \
63660+ role = role->prev; \
63661+ }
63662+
63663+extern struct lglock vfsmount_lock;
63664+
63665+extern struct path gr_real_root;
63666+
63667+static struct gr_policy_state running_polstate;
63668+struct gr_policy_state *polstate = &running_polstate;
63669+extern struct gr_alloc_state *current_alloc_state;
63670+
63671+extern char *gr_shared_page[4];
63672+DEFINE_RWLOCK(gr_inode_lock);
63673+
63674+static unsigned int gr_status __read_only = GR_STATUS_INIT;
63675+
63676+#ifdef CONFIG_NET
63677+extern struct vfsmount *sock_mnt;
63678+#endif
63679+
63680+extern struct vfsmount *pipe_mnt;
63681+extern struct vfsmount *shm_mnt;
63682+
63683+#ifdef CONFIG_HUGETLBFS
63684+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63685+#endif
63686+
63687+extern u16 acl_sp_role_value;
63688+extern struct acl_object_label *fakefs_obj_rw;
63689+extern struct acl_object_label *fakefs_obj_rwx;
63690+
63691+int gr_acl_is_enabled(void)
63692+{
63693+ return (gr_status & GR_READY);
63694+}
63695+
63696+void gr_enable_rbac_system(void)
63697+{
63698+ pax_open_kernel();
63699+ gr_status |= GR_READY;
63700+ pax_close_kernel();
63701+}
63702+
63703+int gr_rbac_disable(void *unused)
63704+{
63705+ pax_open_kernel();
63706+ gr_status &= ~GR_READY;
63707+ pax_close_kernel();
63708+
63709+ return 0;
63710+}
63711+
63712+static inline dev_t __get_dev(const struct dentry *dentry)
63713+{
63714+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63715+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63716+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63717+ else
63718+#endif
63719+ return dentry->d_sb->s_dev;
63720+}
63721+
63722+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63723+{
63724+ return __get_dev(dentry);
63725+}
63726+
63727+static char gr_task_roletype_to_char(struct task_struct *task)
63728+{
63729+ switch (task->role->roletype &
63730+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
63731+ GR_ROLE_SPECIAL)) {
63732+ case GR_ROLE_DEFAULT:
63733+ return 'D';
63734+ case GR_ROLE_USER:
63735+ return 'U';
63736+ case GR_ROLE_GROUP:
63737+ return 'G';
63738+ case GR_ROLE_SPECIAL:
63739+ return 'S';
63740+ }
63741+
63742+ return 'X';
63743+}
63744+
63745+char gr_roletype_to_char(void)
63746+{
63747+ return gr_task_roletype_to_char(current);
63748+}
63749+
63750+__inline__ int
63751+gr_acl_tpe_check(void)
63752+{
63753+ if (unlikely(!(gr_status & GR_READY)))
63754+ return 0;
63755+ if (current->role->roletype & GR_ROLE_TPE)
63756+ return 1;
63757+ else
63758+ return 0;
63759+}
63760+
63761+int
63762+gr_handle_rawio(const struct inode *inode)
63763+{
63764+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63765+ if (inode && S_ISBLK(inode->i_mode) &&
63766+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
63767+ !capable(CAP_SYS_RAWIO))
63768+ return 1;
63769+#endif
63770+ return 0;
63771+}
63772+
63773+int
63774+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
63775+{
63776+ if (likely(lena != lenb))
63777+ return 0;
63778+
63779+ return !memcmp(a, b, lena);
63780+}
63781+
63782+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
63783+{
63784+ *buflen -= namelen;
63785+ if (*buflen < 0)
63786+ return -ENAMETOOLONG;
63787+ *buffer -= namelen;
63788+ memcpy(*buffer, str, namelen);
63789+ return 0;
63790+}
63791+
63792+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
63793+{
63794+ return prepend(buffer, buflen, name->name, name->len);
63795+}
63796+
63797+static int prepend_path(const struct path *path, struct path *root,
63798+ char **buffer, int *buflen)
63799+{
63800+ struct dentry *dentry = path->dentry;
63801+ struct vfsmount *vfsmnt = path->mnt;
63802+ struct mount *mnt = real_mount(vfsmnt);
63803+ bool slash = false;
63804+ int error = 0;
63805+
63806+ while (dentry != root->dentry || vfsmnt != root->mnt) {
63807+ struct dentry * parent;
63808+
63809+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
63810+ /* Global root? */
63811+ if (!mnt_has_parent(mnt)) {
63812+ goto out;
63813+ }
63814+ dentry = mnt->mnt_mountpoint;
63815+ mnt = mnt->mnt_parent;
63816+ vfsmnt = &mnt->mnt;
63817+ continue;
63818+ }
63819+ parent = dentry->d_parent;
63820+ prefetch(parent);
63821+ spin_lock(&dentry->d_lock);
63822+ error = prepend_name(buffer, buflen, &dentry->d_name);
63823+ spin_unlock(&dentry->d_lock);
63824+ if (!error)
63825+ error = prepend(buffer, buflen, "/", 1);
63826+ if (error)
63827+ break;
63828+
63829+ slash = true;
63830+ dentry = parent;
63831+ }
63832+
63833+out:
63834+ if (!error && !slash)
63835+ error = prepend(buffer, buflen, "/", 1);
63836+
63837+ return error;
63838+}
63839+
63840+/* this must be called with vfsmount_lock and rename_lock held */
63841+
63842+static char *__our_d_path(const struct path *path, struct path *root,
63843+ char *buf, int buflen)
63844+{
63845+ char *res = buf + buflen;
63846+ int error;
63847+
63848+ prepend(&res, &buflen, "\0", 1);
63849+ error = prepend_path(path, root, &res, &buflen);
63850+ if (error)
63851+ return ERR_PTR(error);
63852+
63853+ return res;
63854+}
63855+
63856+static char *
63857+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63858+{
63859+ char *retval;
63860+
63861+ retval = __our_d_path(path, root, buf, buflen);
63862+ if (unlikely(IS_ERR(retval)))
63863+ retval = strcpy(buf, "<path too long>");
63864+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63865+ retval[1] = '\0';
63866+
63867+ return retval;
63868+}
63869+
63870+static char *
63871+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63872+ char *buf, int buflen)
63873+{
63874+ struct path path;
63875+ char *res;
63876+
63877+ path.dentry = (struct dentry *)dentry;
63878+ path.mnt = (struct vfsmount *)vfsmnt;
63879+
63880+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
63881+ by the RBAC system */
63882+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
63883+
63884+ return res;
63885+}
63886+
63887+static char *
63888+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63889+ char *buf, int buflen)
63890+{
63891+ char *res;
63892+ struct path path;
63893+ struct path root;
63894+ struct task_struct *reaper = init_pid_ns.child_reaper;
63895+
63896+ path.dentry = (struct dentry *)dentry;
63897+ path.mnt = (struct vfsmount *)vfsmnt;
63898+
63899+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
63900+ get_fs_root(reaper->fs, &root);
63901+
63902+ br_read_lock(&vfsmount_lock);
63903+ write_seqlock(&rename_lock);
63904+ res = gen_full_path(&path, &root, buf, buflen);
63905+ write_sequnlock(&rename_lock);
63906+ br_read_unlock(&vfsmount_lock);
63907+
63908+ path_put(&root);
63909+ return res;
63910+}
63911+
63912+char *
63913+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63914+{
63915+ char *ret;
63916+ br_read_lock(&vfsmount_lock);
63917+ write_seqlock(&rename_lock);
63918+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63919+ PAGE_SIZE);
63920+ write_sequnlock(&rename_lock);
63921+ br_read_unlock(&vfsmount_lock);
63922+ return ret;
63923+}
63924+
63925+static char *
63926+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63927+{
63928+ char *ret;
63929+ char *buf;
63930+ int buflen;
63931+
63932+ br_read_lock(&vfsmount_lock);
63933+ write_seqlock(&rename_lock);
63934+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
63935+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
63936+ buflen = (int)(ret - buf);
63937+ if (buflen >= 5)
63938+ prepend(&ret, &buflen, "/proc", 5);
63939+ else
63940+ ret = strcpy(buf, "<path too long>");
63941+ write_sequnlock(&rename_lock);
63942+ br_read_unlock(&vfsmount_lock);
63943+ return ret;
63944+}
63945+
63946+char *
63947+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
63948+{
63949+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63950+ PAGE_SIZE);
63951+}
63952+
63953+char *
63954+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
63955+{
63956+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
63957+ PAGE_SIZE);
63958+}
63959+
63960+char *
63961+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
63962+{
63963+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
63964+ PAGE_SIZE);
63965+}
63966+
63967+char *
63968+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
63969+{
63970+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
63971+ PAGE_SIZE);
63972+}
63973+
63974+char *
63975+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
63976+{
63977+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
63978+ PAGE_SIZE);
63979+}
63980+
63981+__inline__ __u32
63982+to_gr_audit(const __u32 reqmode)
63983+{
63984+ /* masks off auditable permission flags, then shifts them to create
63985+ auditing flags, and adds the special case of append auditing if
63986+ we're requesting write */
63987+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
63988+}
63989+
63990+struct acl_role_label *
63991+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
63992+ const gid_t gid)
63993+{
63994+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
63995+ struct acl_role_label *match;
63996+ struct role_allowed_ip *ipp;
63997+ unsigned int x;
63998+ u32 curr_ip = task->signal->saved_ip;
63999+
64000+ match = state->acl_role_set.r_hash[index];
64001+
64002+ while (match) {
64003+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
64004+ for (x = 0; x < match->domain_child_num; x++) {
64005+ if (match->domain_children[x] == uid)
64006+ goto found;
64007+ }
64008+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
64009+ break;
64010+ match = match->next;
64011+ }
64012+found:
64013+ if (match == NULL) {
64014+ try_group:
64015+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
64016+ match = state->acl_role_set.r_hash[index];
64017+
64018+ while (match) {
64019+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
64020+ for (x = 0; x < match->domain_child_num; x++) {
64021+ if (match->domain_children[x] == gid)
64022+ goto found2;
64023+ }
64024+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
64025+ break;
64026+ match = match->next;
64027+ }
64028+found2:
64029+ if (match == NULL)
64030+ match = state->default_role;
64031+ if (match->allowed_ips == NULL)
64032+ return match;
64033+ else {
64034+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64035+ if (likely
64036+ ((ntohl(curr_ip) & ipp->netmask) ==
64037+ (ntohl(ipp->addr) & ipp->netmask)))
64038+ return match;
64039+ }
64040+ match = state->default_role;
64041+ }
64042+ } else if (match->allowed_ips == NULL) {
64043+ return match;
64044+ } else {
64045+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64046+ if (likely
64047+ ((ntohl(curr_ip) & ipp->netmask) ==
64048+ (ntohl(ipp->addr) & ipp->netmask)))
64049+ return match;
64050+ }
64051+ goto try_group;
64052+ }
64053+
64054+ return match;
64055+}
64056+
64057+static struct acl_role_label *
64058+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
64059+ const gid_t gid)
64060+{
64061+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
64062+}
64063+
64064+struct acl_subject_label *
64065+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
64066+ const struct acl_role_label *role)
64067+{
64068+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64069+ struct acl_subject_label *match;
64070+
64071+ match = role->subj_hash[index];
64072+
64073+ while (match && (match->inode != ino || match->device != dev ||
64074+ (match->mode & GR_DELETED))) {
64075+ match = match->next;
64076+ }
64077+
64078+ if (match && !(match->mode & GR_DELETED))
64079+ return match;
64080+ else
64081+ return NULL;
64082+}
64083+
64084+struct acl_subject_label *
64085+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
64086+ const struct acl_role_label *role)
64087+{
64088+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64089+ struct acl_subject_label *match;
64090+
64091+ match = role->subj_hash[index];
64092+
64093+ while (match && (match->inode != ino || match->device != dev ||
64094+ !(match->mode & GR_DELETED))) {
64095+ match = match->next;
64096+ }
64097+
64098+ if (match && (match->mode & GR_DELETED))
64099+ return match;
64100+ else
64101+ return NULL;
64102+}
64103+
64104+static struct acl_object_label *
64105+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
64106+ const struct acl_subject_label *subj)
64107+{
64108+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64109+ struct acl_object_label *match;
64110+
64111+ match = subj->obj_hash[index];
64112+
64113+ while (match && (match->inode != ino || match->device != dev ||
64114+ (match->mode & GR_DELETED))) {
64115+ match = match->next;
64116+ }
64117+
64118+ if (match && !(match->mode & GR_DELETED))
64119+ return match;
64120+ else
64121+ return NULL;
64122+}
64123+
64124+static struct acl_object_label *
64125+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
64126+ const struct acl_subject_label *subj)
64127+{
64128+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64129+ struct acl_object_label *match;
64130+
64131+ match = subj->obj_hash[index];
64132+
64133+ while (match && (match->inode != ino || match->device != dev ||
64134+ !(match->mode & GR_DELETED))) {
64135+ match = match->next;
64136+ }
64137+
64138+ if (match && (match->mode & GR_DELETED))
64139+ return match;
64140+
64141+ match = subj->obj_hash[index];
64142+
64143+ while (match && (match->inode != ino || match->device != dev ||
64144+ (match->mode & GR_DELETED))) {
64145+ match = match->next;
64146+ }
64147+
64148+ if (match && !(match->mode & GR_DELETED))
64149+ return match;
64150+ else
64151+ return NULL;
64152+}
64153+
64154+struct name_entry *
64155+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
64156+{
64157+ unsigned int len = strlen(name);
64158+ unsigned int key = full_name_hash(name, len);
64159+ unsigned int index = key % state->name_set.n_size;
64160+ struct name_entry *match;
64161+
64162+ match = state->name_set.n_hash[index];
64163+
64164+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
64165+ match = match->next;
64166+
64167+ return match;
64168+}
64169+
64170+static struct name_entry *
64171+lookup_name_entry(const char *name)
64172+{
64173+ return __lookup_name_entry(&running_polstate, name);
64174+}
64175+
64176+static struct name_entry *
64177+lookup_name_entry_create(const char *name)
64178+{
64179+ unsigned int len = strlen(name);
64180+ unsigned int key = full_name_hash(name, len);
64181+ unsigned int index = key % running_polstate.name_set.n_size;
64182+ struct name_entry *match;
64183+
64184+ match = running_polstate.name_set.n_hash[index];
64185+
64186+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64187+ !match->deleted))
64188+ match = match->next;
64189+
64190+ if (match && match->deleted)
64191+ return match;
64192+
64193+ match = running_polstate.name_set.n_hash[index];
64194+
64195+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64196+ match->deleted))
64197+ match = match->next;
64198+
64199+ if (match && !match->deleted)
64200+ return match;
64201+ else
64202+ return NULL;
64203+}
64204+
64205+static struct inodev_entry *
64206+lookup_inodev_entry(const ino_t ino, const dev_t dev)
64207+{
64208+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
64209+ struct inodev_entry *match;
64210+
64211+ match = running_polstate.inodev_set.i_hash[index];
64212+
64213+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
64214+ match = match->next;
64215+
64216+ return match;
64217+}
64218+
64219+void
64220+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
64221+{
64222+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
64223+ state->inodev_set.i_size);
64224+ struct inodev_entry **curr;
64225+
64226+ entry->prev = NULL;
64227+
64228+ curr = &state->inodev_set.i_hash[index];
64229+ if (*curr != NULL)
64230+ (*curr)->prev = entry;
64231+
64232+ entry->next = *curr;
64233+ *curr = entry;
64234+
64235+ return;
64236+}
64237+
64238+static void
64239+insert_inodev_entry(struct inodev_entry *entry)
64240+{
64241+ __insert_inodev_entry(&running_polstate, entry);
64242+}
64243+
64244+void
64245+insert_acl_obj_label(struct acl_object_label *obj,
64246+ struct acl_subject_label *subj)
64247+{
64248+ unsigned int index =
64249+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
64250+ struct acl_object_label **curr;
64251+
64252+ obj->prev = NULL;
64253+
64254+ curr = &subj->obj_hash[index];
64255+ if (*curr != NULL)
64256+ (*curr)->prev = obj;
64257+
64258+ obj->next = *curr;
64259+ *curr = obj;
64260+
64261+ return;
64262+}
64263+
64264+void
64265+insert_acl_subj_label(struct acl_subject_label *obj,
64266+ struct acl_role_label *role)
64267+{
64268+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
64269+ struct acl_subject_label **curr;
64270+
64271+ obj->prev = NULL;
64272+
64273+ curr = &role->subj_hash[index];
64274+ if (*curr != NULL)
64275+ (*curr)->prev = obj;
64276+
64277+ obj->next = *curr;
64278+ *curr = obj;
64279+
64280+ return;
64281+}
64282+
64283+/* derived from glibc fnmatch() 0: match, 1: no match*/
64284+
64285+static int
64286+glob_match(const char *p, const char *n)
64287+{
64288+ char c;
64289+
64290+ while ((c = *p++) != '\0') {
64291+ switch (c) {
64292+ case '?':
64293+ if (*n == '\0')
64294+ return 1;
64295+ else if (*n == '/')
64296+ return 1;
64297+ break;
64298+ case '\\':
64299+ if (*n != c)
64300+ return 1;
64301+ break;
64302+ case '*':
64303+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
64304+ if (*n == '/')
64305+ return 1;
64306+ else if (c == '?') {
64307+ if (*n == '\0')
64308+ return 1;
64309+ else
64310+ ++n;
64311+ }
64312+ }
64313+ if (c == '\0') {
64314+ return 0;
64315+ } else {
64316+ const char *endp;
64317+
64318+ if ((endp = strchr(n, '/')) == NULL)
64319+ endp = n + strlen(n);
64320+
64321+ if (c == '[') {
64322+ for (--p; n < endp; ++n)
64323+ if (!glob_match(p, n))
64324+ return 0;
64325+ } else if (c == '/') {
64326+ while (*n != '\0' && *n != '/')
64327+ ++n;
64328+ if (*n == '/' && !glob_match(p, n + 1))
64329+ return 0;
64330+ } else {
64331+ for (--p; n < endp; ++n)
64332+ if (*n == c && !glob_match(p, n))
64333+ return 0;
64334+ }
64335+
64336+ return 1;
64337+ }
64338+ case '[':
64339+ {
64340+ int not;
64341+ char cold;
64342+
64343+ if (*n == '\0' || *n == '/')
64344+ return 1;
64345+
64346+ not = (*p == '!' || *p == '^');
64347+ if (not)
64348+ ++p;
64349+
64350+ c = *p++;
64351+ for (;;) {
64352+ unsigned char fn = (unsigned char)*n;
64353+
64354+ if (c == '\0')
64355+ return 1;
64356+ else {
64357+ if (c == fn)
64358+ goto matched;
64359+ cold = c;
64360+ c = *p++;
64361+
64362+ if (c == '-' && *p != ']') {
64363+ unsigned char cend = *p++;
64364+
64365+ if (cend == '\0')
64366+ return 1;
64367+
64368+ if (cold <= fn && fn <= cend)
64369+ goto matched;
64370+
64371+ c = *p++;
64372+ }
64373+ }
64374+
64375+ if (c == ']')
64376+ break;
64377+ }
64378+ if (!not)
64379+ return 1;
64380+ break;
64381+ matched:
64382+ while (c != ']') {
64383+ if (c == '\0')
64384+ return 1;
64385+
64386+ c = *p++;
64387+ }
64388+ if (not)
64389+ return 1;
64390+ }
64391+ break;
64392+ default:
64393+ if (c != *n)
64394+ return 1;
64395+ }
64396+
64397+ ++n;
64398+ }
64399+
64400+ if (*n == '\0')
64401+ return 0;
64402+
64403+ if (*n == '/')
64404+ return 0;
64405+
64406+ return 1;
64407+}
64408+
64409+static struct acl_object_label *
64410+chk_glob_label(struct acl_object_label *globbed,
64411+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64412+{
64413+ struct acl_object_label *tmp;
64414+
64415+ if (*path == NULL)
64416+ *path = gr_to_filename_nolock(dentry, mnt);
64417+
64418+ tmp = globbed;
64419+
64420+ while (tmp) {
64421+ if (!glob_match(tmp->filename, *path))
64422+ return tmp;
64423+ tmp = tmp->next;
64424+ }
64425+
64426+ return NULL;
64427+}
64428+
64429+static struct acl_object_label *
64430+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64431+ const ino_t curr_ino, const dev_t curr_dev,
64432+ const struct acl_subject_label *subj, char **path, const int checkglob)
64433+{
64434+ struct acl_subject_label *tmpsubj;
64435+ struct acl_object_label *retval;
64436+ struct acl_object_label *retval2;
64437+
64438+ tmpsubj = (struct acl_subject_label *) subj;
64439+ read_lock(&gr_inode_lock);
64440+ do {
64441+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64442+ if (retval) {
64443+ if (checkglob && retval->globbed) {
64444+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64445+ if (retval2)
64446+ retval = retval2;
64447+ }
64448+ break;
64449+ }
64450+ } while ((tmpsubj = tmpsubj->parent_subject));
64451+ read_unlock(&gr_inode_lock);
64452+
64453+ return retval;
64454+}
64455+
64456+static __inline__ struct acl_object_label *
64457+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64458+ struct dentry *curr_dentry,
64459+ const struct acl_subject_label *subj, char **path, const int checkglob)
64460+{
64461+ int newglob = checkglob;
64462+ ino_t inode;
64463+ dev_t device;
64464+
64465+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64466+ as we don't want a / * rule to match instead of the / object
64467+ don't do this for create lookups that call this function though, since they're looking up
64468+ on the parent and thus need globbing checks on all paths
64469+ */
64470+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64471+ newglob = GR_NO_GLOB;
64472+
64473+ spin_lock(&curr_dentry->d_lock);
64474+ inode = curr_dentry->d_inode->i_ino;
64475+ device = __get_dev(curr_dentry);
64476+ spin_unlock(&curr_dentry->d_lock);
64477+
64478+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64479+}
64480+
64481+#ifdef CONFIG_HUGETLBFS
64482+static inline bool
64483+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64484+{
64485+ int i;
64486+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64487+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64488+ return true;
64489+ }
64490+
64491+ return false;
64492+}
64493+#endif
64494+
64495+static struct acl_object_label *
64496+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64497+ const struct acl_subject_label *subj, char *path, const int checkglob)
64498+{
64499+ struct dentry *dentry = (struct dentry *) l_dentry;
64500+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64501+ struct mount *real_mnt = real_mount(mnt);
64502+ struct acl_object_label *retval;
64503+ struct dentry *parent;
64504+
64505+ br_read_lock(&vfsmount_lock);
64506+ write_seqlock(&rename_lock);
64507+
64508+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64509+#ifdef CONFIG_NET
64510+ mnt == sock_mnt ||
64511+#endif
64512+#ifdef CONFIG_HUGETLBFS
64513+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64514+#endif
64515+ /* ignore Eric Biederman */
64516+ IS_PRIVATE(l_dentry->d_inode))) {
64517+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64518+ goto out;
64519+ }
64520+
64521+ for (;;) {
64522+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
64523+ break;
64524+
64525+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64526+ if (!mnt_has_parent(real_mnt))
64527+ break;
64528+
64529+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64530+ if (retval != NULL)
64531+ goto out;
64532+
64533+ dentry = real_mnt->mnt_mountpoint;
64534+ real_mnt = real_mnt->mnt_parent;
64535+ mnt = &real_mnt->mnt;
64536+ continue;
64537+ }
64538+
64539+ parent = dentry->d_parent;
64540+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64541+ if (retval != NULL)
64542+ goto out;
64543+
64544+ dentry = parent;
64545+ }
64546+
64547+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64548+
64549+ /* gr_real_root is pinned so we don't have to hold a reference */
64550+ if (retval == NULL)
64551+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
64552+out:
64553+ write_sequnlock(&rename_lock);
64554+ br_read_unlock(&vfsmount_lock);
64555+
64556+ BUG_ON(retval == NULL);
64557+
64558+ return retval;
64559+}
64560+
64561+static __inline__ struct acl_object_label *
64562+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64563+ const struct acl_subject_label *subj)
64564+{
64565+ char *path = NULL;
64566+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64567+}
64568+
64569+static __inline__ struct acl_object_label *
64570+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64571+ const struct acl_subject_label *subj)
64572+{
64573+ char *path = NULL;
64574+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64575+}
64576+
64577+static __inline__ struct acl_object_label *
64578+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64579+ const struct acl_subject_label *subj, char *path)
64580+{
64581+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64582+}
64583+
64584+struct acl_subject_label *
64585+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64586+ const struct acl_role_label *role)
64587+{
64588+ struct dentry *dentry = (struct dentry *) l_dentry;
64589+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64590+ struct mount *real_mnt = real_mount(mnt);
64591+ struct acl_subject_label *retval;
64592+ struct dentry *parent;
64593+
64594+ br_read_lock(&vfsmount_lock);
64595+ write_seqlock(&rename_lock);
64596+
64597+ for (;;) {
64598+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
64599+ break;
64600+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64601+ if (!mnt_has_parent(real_mnt))
64602+ break;
64603+
64604+ spin_lock(&dentry->d_lock);
64605+ read_lock(&gr_inode_lock);
64606+ retval =
64607+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64608+ __get_dev(dentry), role);
64609+ read_unlock(&gr_inode_lock);
64610+ spin_unlock(&dentry->d_lock);
64611+ if (retval != NULL)
64612+ goto out;
64613+
64614+ dentry = real_mnt->mnt_mountpoint;
64615+ real_mnt = real_mnt->mnt_parent;
64616+ mnt = &real_mnt->mnt;
64617+ continue;
64618+ }
64619+
64620+ spin_lock(&dentry->d_lock);
64621+ read_lock(&gr_inode_lock);
64622+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64623+ __get_dev(dentry), role);
64624+ read_unlock(&gr_inode_lock);
64625+ parent = dentry->d_parent;
64626+ spin_unlock(&dentry->d_lock);
64627+
64628+ if (retval != NULL)
64629+ goto out;
64630+
64631+ dentry = parent;
64632+ }
64633+
64634+ spin_lock(&dentry->d_lock);
64635+ read_lock(&gr_inode_lock);
64636+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64637+ __get_dev(dentry), role);
64638+ read_unlock(&gr_inode_lock);
64639+ spin_unlock(&dentry->d_lock);
64640+
64641+ if (unlikely(retval == NULL)) {
64642+ /* gr_real_root is pinned, we don't need to hold a reference */
64643+ read_lock(&gr_inode_lock);
64644+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
64645+ __get_dev(gr_real_root.dentry), role);
64646+ read_unlock(&gr_inode_lock);
64647+ }
64648+out:
64649+ write_sequnlock(&rename_lock);
64650+ br_read_unlock(&vfsmount_lock);
64651+
64652+ BUG_ON(retval == NULL);
64653+
64654+ return retval;
64655+}
64656+
64657+void
64658+assign_special_role(const char *rolename)
64659+{
64660+ struct acl_object_label *obj;
64661+ struct acl_role_label *r;
64662+ struct acl_role_label *assigned = NULL;
64663+ struct task_struct *tsk;
64664+ struct file *filp;
64665+
64666+ FOR_EACH_ROLE_START(r)
64667+ if (!strcmp(rolename, r->rolename) &&
64668+ (r->roletype & GR_ROLE_SPECIAL)) {
64669+ assigned = r;
64670+ break;
64671+ }
64672+ FOR_EACH_ROLE_END(r)
64673+
64674+ if (!assigned)
64675+ return;
64676+
64677+ read_lock(&tasklist_lock);
64678+ read_lock(&grsec_exec_file_lock);
64679+
64680+ tsk = current->real_parent;
64681+ if (tsk == NULL)
64682+ goto out_unlock;
64683+
64684+ filp = tsk->exec_file;
64685+ if (filp == NULL)
64686+ goto out_unlock;
64687+
64688+ tsk->is_writable = 0;
64689+ tsk->inherited = 0;
64690+
64691+ tsk->acl_sp_role = 1;
64692+ tsk->acl_role_id = ++acl_sp_role_value;
64693+ tsk->role = assigned;
64694+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
64695+
64696+ /* ignore additional mmap checks for processes that are writable
64697+ by the default ACL */
64698+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
64699+ if (unlikely(obj->mode & GR_WRITE))
64700+ tsk->is_writable = 1;
64701+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
64702+ if (unlikely(obj->mode & GR_WRITE))
64703+ tsk->is_writable = 1;
64704+
64705+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64706+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
64707+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
64708+#endif
64709+
64710+out_unlock:
64711+ read_unlock(&grsec_exec_file_lock);
64712+ read_unlock(&tasklist_lock);
64713+ return;
64714+}
64715+
64716+
64717+static void
64718+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64719+{
64720+ struct task_struct *task = current;
64721+ const struct cred *cred = current_cred();
64722+
64723+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64724+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64725+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64726+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64727+
64728+ return;
64729+}
64730+
64731+static void
64732+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64733+{
64734+ struct task_struct *task = current;
64735+ const struct cred *cred = current_cred();
64736+
64737+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64738+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64739+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64740+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64741+
64742+ return;
64743+}
64744+
64745+static void
64746+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64747+{
64748+ struct task_struct *task = current;
64749+ const struct cred *cred = current_cred();
64750+
64751+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64752+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64753+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64754+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64755+
64756+ return;
64757+}
64758+
64759+static void
64760+gr_set_proc_res(struct task_struct *task)
64761+{
64762+ struct acl_subject_label *proc;
64763+ unsigned short i;
64764+
64765+ proc = task->acl;
64766+
64767+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64768+ return;
64769+
64770+ for (i = 0; i < RLIM_NLIMITS; i++) {
64771+ if (!(proc->resmask & (1U << i)))
64772+ continue;
64773+
64774+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64775+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64776+
64777+ if (i == RLIMIT_CPU)
64778+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64779+ }
64780+
64781+ return;
64782+}
64783+
64784+/* both of the below must be called with
64785+ rcu_read_lock();
64786+ read_lock(&tasklist_lock);
64787+ read_lock(&grsec_exec_file_lock);
64788+*/
64789+
64790+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
64791+{
64792+ char *tmpname;
64793+ struct acl_subject_label *tmpsubj;
64794+ struct file *filp;
64795+ struct name_entry *nmatch;
64796+
64797+ filp = task->exec_file;
64798+ if (filp == NULL)
64799+ return NULL;
64800+
64801+ /* the following is to apply the correct subject
64802+ on binaries running when the RBAC system
64803+ is enabled, when the binaries have been
64804+ replaced or deleted since their execution
64805+ -----
64806+ when the RBAC system starts, the inode/dev
64807+ from exec_file will be one the RBAC system
64808+ is unaware of. It only knows the inode/dev
64809+ of the present file on disk, or the absence
64810+ of it.
64811+ */
64812+
64813+ if (filename)
64814+ nmatch = __lookup_name_entry(state, filename);
64815+ else {
64816+ preempt_disable();
64817+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
64818+
64819+ nmatch = __lookup_name_entry(state, tmpname);
64820+ preempt_enable();
64821+ }
64822+ tmpsubj = NULL;
64823+ if (nmatch) {
64824+ if (nmatch->deleted)
64825+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
64826+ else
64827+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
64828+ }
64829+ /* this also works for the reload case -- if we don't match a potentially inherited subject
64830+ then we fall back to a normal lookup based on the binary's ino/dev
64831+ */
64832+ if (tmpsubj == NULL)
64833+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
64834+
64835+ return tmpsubj;
64836+}
64837+
64838+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
64839+{
64840+ return __gr_get_subject_for_task(&running_polstate, task, filename);
64841+}
64842+
64843+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
64844+{
64845+ struct acl_object_label *obj;
64846+ struct file *filp;
64847+
64848+ filp = task->exec_file;
64849+
64850+ task->acl = subj;
64851+ task->is_writable = 0;
64852+ /* ignore additional mmap checks for processes that are writable
64853+ by the default ACL */
64854+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
64855+ if (unlikely(obj->mode & GR_WRITE))
64856+ task->is_writable = 1;
64857+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64858+ if (unlikely(obj->mode & GR_WRITE))
64859+ task->is_writable = 1;
64860+
64861+ gr_set_proc_res(task);
64862+
64863+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64864+ 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);
64865+#endif
64866+}
64867+
64868+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
64869+{
64870+ __gr_apply_subject_to_task(&running_polstate, task, subj);
64871+}
64872+
64873+__u32
64874+gr_search_file(const struct dentry * dentry, const __u32 mode,
64875+ const struct vfsmount * mnt)
64876+{
64877+ __u32 retval = mode;
64878+ struct acl_subject_label *curracl;
64879+ struct acl_object_label *currobj;
64880+
64881+ if (unlikely(!(gr_status & GR_READY)))
64882+ return (mode & ~GR_AUDITS);
64883+
64884+ curracl = current->acl;
64885+
64886+ currobj = chk_obj_label(dentry, mnt, curracl);
64887+ retval = currobj->mode & mode;
64888+
64889+ /* if we're opening a specified transfer file for writing
64890+ (e.g. /dev/initctl), then transfer our role to init
64891+ */
64892+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64893+ current->role->roletype & GR_ROLE_PERSIST)) {
64894+ struct task_struct *task = init_pid_ns.child_reaper;
64895+
64896+ if (task->role != current->role) {
64897+ struct acl_subject_label *subj;
64898+
64899+ task->acl_sp_role = 0;
64900+ task->acl_role_id = current->acl_role_id;
64901+ task->role = current->role;
64902+ rcu_read_lock();
64903+ read_lock(&grsec_exec_file_lock);
64904+ subj = gr_get_subject_for_task(task, NULL);
64905+ gr_apply_subject_to_task(task, subj);
64906+ read_unlock(&grsec_exec_file_lock);
64907+ rcu_read_unlock();
64908+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64909+ }
64910+ }
64911+
64912+ if (unlikely
64913+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64914+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64915+ __u32 new_mode = mode;
64916+
64917+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64918+
64919+ retval = new_mode;
64920+
64921+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64922+ new_mode |= GR_INHERIT;
64923+
64924+ if (!(mode & GR_NOLEARN))
64925+ gr_log_learn(dentry, mnt, new_mode);
64926+ }
64927+
64928+ return retval;
64929+}
64930+
64931+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64932+ const struct dentry *parent,
64933+ const struct vfsmount *mnt)
64934+{
64935+ struct name_entry *match;
64936+ struct acl_object_label *matchpo;
64937+ struct acl_subject_label *curracl;
64938+ char *path;
64939+
64940+ if (unlikely(!(gr_status & GR_READY)))
64941+ return NULL;
64942+
64943+ preempt_disable();
64944+ path = gr_to_filename_rbac(new_dentry, mnt);
64945+ match = lookup_name_entry_create(path);
64946+
64947+ curracl = current->acl;
64948+
64949+ if (match) {
64950+ read_lock(&gr_inode_lock);
64951+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64952+ read_unlock(&gr_inode_lock);
64953+
64954+ if (matchpo) {
64955+ preempt_enable();
64956+ return matchpo;
64957+ }
64958+ }
64959+
64960+ // lookup parent
64961+
64962+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64963+
64964+ preempt_enable();
64965+ return matchpo;
64966+}
64967+
64968+__u32
64969+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64970+ const struct vfsmount * mnt, const __u32 mode)
64971+{
64972+ struct acl_object_label *matchpo;
64973+ __u32 retval;
64974+
64975+ if (unlikely(!(gr_status & GR_READY)))
64976+ return (mode & ~GR_AUDITS);
64977+
64978+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64979+
64980+ retval = matchpo->mode & mode;
64981+
64982+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64983+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64984+ __u32 new_mode = mode;
64985+
64986+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64987+
64988+ gr_log_learn(new_dentry, mnt, new_mode);
64989+ return new_mode;
64990+ }
64991+
64992+ return retval;
64993+}
64994+
64995+__u32
64996+gr_check_link(const struct dentry * new_dentry,
64997+ const struct dentry * parent_dentry,
64998+ const struct vfsmount * parent_mnt,
64999+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
65000+{
65001+ struct acl_object_label *obj;
65002+ __u32 oldmode, newmode;
65003+ __u32 needmode;
65004+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
65005+ GR_DELETE | GR_INHERIT;
65006+
65007+ if (unlikely(!(gr_status & GR_READY)))
65008+ return (GR_CREATE | GR_LINK);
65009+
65010+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
65011+ oldmode = obj->mode;
65012+
65013+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
65014+ newmode = obj->mode;
65015+
65016+ needmode = newmode & checkmodes;
65017+
65018+ // old name for hardlink must have at least the permissions of the new name
65019+ if ((oldmode & needmode) != needmode)
65020+ goto bad;
65021+
65022+ // if old name had restrictions/auditing, make sure the new name does as well
65023+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
65024+
65025+ // don't allow hardlinking of suid/sgid/fcapped files without permission
65026+ if (is_privileged_binary(old_dentry))
65027+ needmode |= GR_SETID;
65028+
65029+ if ((newmode & needmode) != needmode)
65030+ goto bad;
65031+
65032+ // enforce minimum permissions
65033+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
65034+ return newmode;
65035+bad:
65036+ needmode = oldmode;
65037+ if (is_privileged_binary(old_dentry))
65038+ needmode |= GR_SETID;
65039+
65040+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
65041+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
65042+ return (GR_CREATE | GR_LINK);
65043+ } else if (newmode & GR_SUPPRESS)
65044+ return GR_SUPPRESS;
65045+ else
65046+ return 0;
65047+}
65048+
65049+int
65050+gr_check_hidden_task(const struct task_struct *task)
65051+{
65052+ if (unlikely(!(gr_status & GR_READY)))
65053+ return 0;
65054+
65055+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
65056+ return 1;
65057+
65058+ return 0;
65059+}
65060+
65061+int
65062+gr_check_protected_task(const struct task_struct *task)
65063+{
65064+ if (unlikely(!(gr_status & GR_READY) || !task))
65065+ return 0;
65066+
65067+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65068+ task->acl != current->acl)
65069+ return 1;
65070+
65071+ return 0;
65072+}
65073+
65074+int
65075+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
65076+{
65077+ struct task_struct *p;
65078+ int ret = 0;
65079+
65080+ if (unlikely(!(gr_status & GR_READY) || !pid))
65081+ return ret;
65082+
65083+ read_lock(&tasklist_lock);
65084+ do_each_pid_task(pid, type, p) {
65085+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65086+ p->acl != current->acl) {
65087+ ret = 1;
65088+ goto out;
65089+ }
65090+ } while_each_pid_task(pid, type, p);
65091+out:
65092+ read_unlock(&tasklist_lock);
65093+
65094+ return ret;
65095+}
65096+
65097+void
65098+gr_copy_label(struct task_struct *tsk)
65099+{
65100+ struct task_struct *p = current;
65101+
65102+ tsk->inherited = p->inherited;
65103+ tsk->acl_sp_role = 0;
65104+ tsk->acl_role_id = p->acl_role_id;
65105+ tsk->acl = p->acl;
65106+ tsk->role = p->role;
65107+ tsk->signal->used_accept = 0;
65108+ tsk->signal->curr_ip = p->signal->curr_ip;
65109+ tsk->signal->saved_ip = p->signal->saved_ip;
65110+ if (p->exec_file)
65111+ get_file(p->exec_file);
65112+ tsk->exec_file = p->exec_file;
65113+ tsk->is_writable = p->is_writable;
65114+ if (unlikely(p->signal->used_accept)) {
65115+ p->signal->curr_ip = 0;
65116+ p->signal->saved_ip = 0;
65117+ }
65118+
65119+ return;
65120+}
65121+
65122+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
65123+
65124+int
65125+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65126+{
65127+ unsigned int i;
65128+ __u16 num;
65129+ uid_t *uidlist;
65130+ uid_t curuid;
65131+ int realok = 0;
65132+ int effectiveok = 0;
65133+ int fsok = 0;
65134+ uid_t globalreal, globaleffective, globalfs;
65135+
65136+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
65137+ struct user_struct *user;
65138+
65139+ if (!uid_valid(real))
65140+ goto skipit;
65141+
65142+ /* find user based on global namespace */
65143+
65144+ globalreal = GR_GLOBAL_UID(real);
65145+
65146+ user = find_user(make_kuid(&init_user_ns, globalreal));
65147+ if (user == NULL)
65148+ goto skipit;
65149+
65150+ if (gr_process_kernel_setuid_ban(user)) {
65151+ /* for find_user */
65152+ free_uid(user);
65153+ return 1;
65154+ }
65155+
65156+ /* for find_user */
65157+ free_uid(user);
65158+
65159+skipit:
65160+#endif
65161+
65162+ if (unlikely(!(gr_status & GR_READY)))
65163+ return 0;
65164+
65165+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65166+ gr_log_learn_uid_change(real, effective, fs);
65167+
65168+ num = current->acl->user_trans_num;
65169+ uidlist = current->acl->user_transitions;
65170+
65171+ if (uidlist == NULL)
65172+ return 0;
65173+
65174+ if (!uid_valid(real)) {
65175+ realok = 1;
65176+ globalreal = (uid_t)-1;
65177+ } else {
65178+ globalreal = GR_GLOBAL_UID(real);
65179+ }
65180+ if (!uid_valid(effective)) {
65181+ effectiveok = 1;
65182+ globaleffective = (uid_t)-1;
65183+ } else {
65184+ globaleffective = GR_GLOBAL_UID(effective);
65185+ }
65186+ if (!uid_valid(fs)) {
65187+ fsok = 1;
65188+ globalfs = (uid_t)-1;
65189+ } else {
65190+ globalfs = GR_GLOBAL_UID(fs);
65191+ }
65192+
65193+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
65194+ for (i = 0; i < num; i++) {
65195+ curuid = uidlist[i];
65196+ if (globalreal == curuid)
65197+ realok = 1;
65198+ if (globaleffective == curuid)
65199+ effectiveok = 1;
65200+ if (globalfs == curuid)
65201+ fsok = 1;
65202+ }
65203+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
65204+ for (i = 0; i < num; i++) {
65205+ curuid = uidlist[i];
65206+ if (globalreal == curuid)
65207+ break;
65208+ if (globaleffective == curuid)
65209+ break;
65210+ if (globalfs == curuid)
65211+ break;
65212+ }
65213+ /* not in deny list */
65214+ if (i == num) {
65215+ realok = 1;
65216+ effectiveok = 1;
65217+ fsok = 1;
65218+ }
65219+ }
65220+
65221+ if (realok && effectiveok && fsok)
65222+ return 0;
65223+ else {
65224+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65225+ return 1;
65226+ }
65227+}
65228+
65229+int
65230+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65231+{
65232+ unsigned int i;
65233+ __u16 num;
65234+ gid_t *gidlist;
65235+ gid_t curgid;
65236+ int realok = 0;
65237+ int effectiveok = 0;
65238+ int fsok = 0;
65239+ gid_t globalreal, globaleffective, globalfs;
65240+
65241+ if (unlikely(!(gr_status & GR_READY)))
65242+ return 0;
65243+
65244+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65245+ gr_log_learn_gid_change(real, effective, fs);
65246+
65247+ num = current->acl->group_trans_num;
65248+ gidlist = current->acl->group_transitions;
65249+
65250+ if (gidlist == NULL)
65251+ return 0;
65252+
65253+ if (!gid_valid(real)) {
65254+ realok = 1;
65255+ globalreal = (gid_t)-1;
65256+ } else {
65257+ globalreal = GR_GLOBAL_GID(real);
65258+ }
65259+ if (!gid_valid(effective)) {
65260+ effectiveok = 1;
65261+ globaleffective = (gid_t)-1;
65262+ } else {
65263+ globaleffective = GR_GLOBAL_GID(effective);
65264+ }
65265+ if (!gid_valid(fs)) {
65266+ fsok = 1;
65267+ globalfs = (gid_t)-1;
65268+ } else {
65269+ globalfs = GR_GLOBAL_GID(fs);
65270+ }
65271+
65272+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
65273+ for (i = 0; i < num; i++) {
65274+ curgid = gidlist[i];
65275+ if (globalreal == curgid)
65276+ realok = 1;
65277+ if (globaleffective == curgid)
65278+ effectiveok = 1;
65279+ if (globalfs == curgid)
65280+ fsok = 1;
65281+ }
65282+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
65283+ for (i = 0; i < num; i++) {
65284+ curgid = gidlist[i];
65285+ if (globalreal == curgid)
65286+ break;
65287+ if (globaleffective == curgid)
65288+ break;
65289+ if (globalfs == curgid)
65290+ break;
65291+ }
65292+ /* not in deny list */
65293+ if (i == num) {
65294+ realok = 1;
65295+ effectiveok = 1;
65296+ fsok = 1;
65297+ }
65298+ }
65299+
65300+ if (realok && effectiveok && fsok)
65301+ return 0;
65302+ else {
65303+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65304+ return 1;
65305+ }
65306+}
65307+
65308+extern int gr_acl_is_capable(const int cap);
65309+
65310+void
65311+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
65312+{
65313+ struct acl_role_label *role = task->role;
65314+ struct acl_subject_label *subj = NULL;
65315+ struct acl_object_label *obj;
65316+ struct file *filp;
65317+ uid_t uid;
65318+ gid_t gid;
65319+
65320+ if (unlikely(!(gr_status & GR_READY)))
65321+ return;
65322+
65323+ uid = GR_GLOBAL_UID(kuid);
65324+ gid = GR_GLOBAL_GID(kgid);
65325+
65326+ filp = task->exec_file;
65327+
65328+ /* kernel process, we'll give them the kernel role */
65329+ if (unlikely(!filp)) {
65330+ task->role = running_polstate.kernel_role;
65331+ task->acl = running_polstate.kernel_role->root_label;
65332+ return;
65333+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
65334+ /* save the current ip at time of role lookup so that the proper
65335+ IP will be learned for role_allowed_ip */
65336+ task->signal->saved_ip = task->signal->curr_ip;
65337+ role = lookup_acl_role_label(task, uid, gid);
65338+ }
65339+
65340+ /* don't change the role if we're not a privileged process */
65341+ if (role && task->role != role &&
65342+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
65343+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
65344+ return;
65345+
65346+ /* perform subject lookup in possibly new role
65347+ we can use this result below in the case where role == task->role
65348+ */
65349+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
65350+
65351+ /* if we changed uid/gid, but result in the same role
65352+ and are using inheritance, don't lose the inherited subject
65353+ if current subject is other than what normal lookup
65354+ would result in, we arrived via inheritance, don't
65355+ lose subject
65356+ */
65357+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
65358+ (subj == task->acl)))
65359+ task->acl = subj;
65360+
65361+ /* leave task->inherited unaffected */
65362+
65363+ task->role = role;
65364+
65365+ task->is_writable = 0;
65366+
65367+ /* ignore additional mmap checks for processes that are writable
65368+ by the default ACL */
65369+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
65370+ if (unlikely(obj->mode & GR_WRITE))
65371+ task->is_writable = 1;
65372+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65373+ if (unlikely(obj->mode & GR_WRITE))
65374+ task->is_writable = 1;
65375+
65376+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65377+ 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);
65378+#endif
65379+
65380+ gr_set_proc_res(task);
65381+
65382+ return;
65383+}
65384+
65385+int
65386+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
65387+ const int unsafe_flags)
65388+{
65389+ struct task_struct *task = current;
65390+ struct acl_subject_label *newacl;
65391+ struct acl_object_label *obj;
65392+ __u32 retmode;
65393+
65394+ if (unlikely(!(gr_status & GR_READY)))
65395+ return 0;
65396+
65397+ newacl = chk_subj_label(dentry, mnt, task->role);
65398+
65399+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
65400+ did an exec
65401+ */
65402+ rcu_read_lock();
65403+ read_lock(&tasklist_lock);
65404+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
65405+ (task->parent->acl->mode & GR_POVERRIDE))) {
65406+ read_unlock(&tasklist_lock);
65407+ rcu_read_unlock();
65408+ goto skip_check;
65409+ }
65410+ read_unlock(&tasklist_lock);
65411+ rcu_read_unlock();
65412+
65413+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
65414+ !(task->role->roletype & GR_ROLE_GOD) &&
65415+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
65416+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65417+ if (unsafe_flags & LSM_UNSAFE_SHARE)
65418+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
65419+ else
65420+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
65421+ return -EACCES;
65422+ }
65423+
65424+skip_check:
65425+
65426+ obj = chk_obj_label(dentry, mnt, task->acl);
65427+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
65428+
65429+ if (!(task->acl->mode & GR_INHERITLEARN) &&
65430+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
65431+ if (obj->nested)
65432+ task->acl = obj->nested;
65433+ else
65434+ task->acl = newacl;
65435+ task->inherited = 0;
65436+ } else {
65437+ task->inherited = 1;
65438+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
65439+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
65440+ }
65441+
65442+ task->is_writable = 0;
65443+
65444+ /* ignore additional mmap checks for processes that are writable
65445+ by the default ACL */
65446+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
65447+ if (unlikely(obj->mode & GR_WRITE))
65448+ task->is_writable = 1;
65449+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
65450+ if (unlikely(obj->mode & GR_WRITE))
65451+ task->is_writable = 1;
65452+
65453+ gr_set_proc_res(task);
65454+
65455+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65456+ 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);
65457+#endif
65458+ return 0;
65459+}
65460+
65461+/* always called with valid inodev ptr */
65462+static void
65463+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
65464+{
65465+ struct acl_object_label *matchpo;
65466+ struct acl_subject_label *matchps;
65467+ struct acl_subject_label *subj;
65468+ struct acl_role_label *role;
65469+ unsigned int x;
65470+
65471+ FOR_EACH_ROLE_START(role)
65472+ FOR_EACH_SUBJECT_START(role, subj, x)
65473+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65474+ matchpo->mode |= GR_DELETED;
65475+ FOR_EACH_SUBJECT_END(subj,x)
65476+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65477+ /* nested subjects aren't in the role's subj_hash table */
65478+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65479+ matchpo->mode |= GR_DELETED;
65480+ FOR_EACH_NESTED_SUBJECT_END(subj)
65481+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
65482+ matchps->mode |= GR_DELETED;
65483+ FOR_EACH_ROLE_END(role)
65484+
65485+ inodev->nentry->deleted = 1;
65486+
65487+ return;
65488+}
65489+
65490+void
65491+gr_handle_delete(const ino_t ino, const dev_t dev)
65492+{
65493+ struct inodev_entry *inodev;
65494+
65495+ if (unlikely(!(gr_status & GR_READY)))
65496+ return;
65497+
65498+ write_lock(&gr_inode_lock);
65499+ inodev = lookup_inodev_entry(ino, dev);
65500+ if (inodev != NULL)
65501+ do_handle_delete(inodev, ino, dev);
65502+ write_unlock(&gr_inode_lock);
65503+
65504+ return;
65505+}
65506+
65507+static void
65508+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
65509+ const ino_t newinode, const dev_t newdevice,
65510+ struct acl_subject_label *subj)
65511+{
65512+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
65513+ struct acl_object_label *match;
65514+
65515+ match = subj->obj_hash[index];
65516+
65517+ while (match && (match->inode != oldinode ||
65518+ match->device != olddevice ||
65519+ !(match->mode & GR_DELETED)))
65520+ match = match->next;
65521+
65522+ if (match && (match->inode == oldinode)
65523+ && (match->device == olddevice)
65524+ && (match->mode & GR_DELETED)) {
65525+ if (match->prev == NULL) {
65526+ subj->obj_hash[index] = match->next;
65527+ if (match->next != NULL)
65528+ match->next->prev = NULL;
65529+ } else {
65530+ match->prev->next = match->next;
65531+ if (match->next != NULL)
65532+ match->next->prev = match->prev;
65533+ }
65534+ match->prev = NULL;
65535+ match->next = NULL;
65536+ match->inode = newinode;
65537+ match->device = newdevice;
65538+ match->mode &= ~GR_DELETED;
65539+
65540+ insert_acl_obj_label(match, subj);
65541+ }
65542+
65543+ return;
65544+}
65545+
65546+static void
65547+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65548+ const ino_t newinode, const dev_t newdevice,
65549+ struct acl_role_label *role)
65550+{
65551+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65552+ struct acl_subject_label *match;
65553+
65554+ match = role->subj_hash[index];
65555+
65556+ while (match && (match->inode != oldinode ||
65557+ match->device != olddevice ||
65558+ !(match->mode & GR_DELETED)))
65559+ match = match->next;
65560+
65561+ if (match && (match->inode == oldinode)
65562+ && (match->device == olddevice)
65563+ && (match->mode & GR_DELETED)) {
65564+ if (match->prev == NULL) {
65565+ role->subj_hash[index] = match->next;
65566+ if (match->next != NULL)
65567+ match->next->prev = NULL;
65568+ } else {
65569+ match->prev->next = match->next;
65570+ if (match->next != NULL)
65571+ match->next->prev = match->prev;
65572+ }
65573+ match->prev = NULL;
65574+ match->next = NULL;
65575+ match->inode = newinode;
65576+ match->device = newdevice;
65577+ match->mode &= ~GR_DELETED;
65578+
65579+ insert_acl_subj_label(match, role);
65580+ }
65581+
65582+ return;
65583+}
65584+
65585+static void
65586+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65587+ const ino_t newinode, const dev_t newdevice)
65588+{
65589+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
65590+ struct inodev_entry *match;
65591+
65592+ match = running_polstate.inodev_set.i_hash[index];
65593+
65594+ while (match && (match->nentry->inode != oldinode ||
65595+ match->nentry->device != olddevice || !match->nentry->deleted))
65596+ match = match->next;
65597+
65598+ if (match && (match->nentry->inode == oldinode)
65599+ && (match->nentry->device == olddevice) &&
65600+ match->nentry->deleted) {
65601+ if (match->prev == NULL) {
65602+ running_polstate.inodev_set.i_hash[index] = match->next;
65603+ if (match->next != NULL)
65604+ match->next->prev = NULL;
65605+ } else {
65606+ match->prev->next = match->next;
65607+ if (match->next != NULL)
65608+ match->next->prev = match->prev;
65609+ }
65610+ match->prev = NULL;
65611+ match->next = NULL;
65612+ match->nentry->inode = newinode;
65613+ match->nentry->device = newdevice;
65614+ match->nentry->deleted = 0;
65615+
65616+ insert_inodev_entry(match);
65617+ }
65618+
65619+ return;
65620+}
65621+
65622+static void
65623+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65624+{
65625+ struct acl_subject_label *subj;
65626+ struct acl_role_label *role;
65627+ unsigned int x;
65628+
65629+ FOR_EACH_ROLE_START(role)
65630+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65631+
65632+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65633+ if ((subj->inode == ino) && (subj->device == dev)) {
65634+ subj->inode = ino;
65635+ subj->device = dev;
65636+ }
65637+ /* nested subjects aren't in the role's subj_hash table */
65638+ update_acl_obj_label(matchn->inode, matchn->device,
65639+ ino, dev, subj);
65640+ FOR_EACH_NESTED_SUBJECT_END(subj)
65641+ FOR_EACH_SUBJECT_START(role, subj, x)
65642+ update_acl_obj_label(matchn->inode, matchn->device,
65643+ ino, dev, subj);
65644+ FOR_EACH_SUBJECT_END(subj,x)
65645+ FOR_EACH_ROLE_END(role)
65646+
65647+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65648+
65649+ return;
65650+}
65651+
65652+static void
65653+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65654+ const struct vfsmount *mnt)
65655+{
65656+ ino_t ino = dentry->d_inode->i_ino;
65657+ dev_t dev = __get_dev(dentry);
65658+
65659+ __do_handle_create(matchn, ino, dev);
65660+
65661+ return;
65662+}
65663+
65664+void
65665+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65666+{
65667+ struct name_entry *matchn;
65668+
65669+ if (unlikely(!(gr_status & GR_READY)))
65670+ return;
65671+
65672+ preempt_disable();
65673+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65674+
65675+ if (unlikely((unsigned long)matchn)) {
65676+ write_lock(&gr_inode_lock);
65677+ do_handle_create(matchn, dentry, mnt);
65678+ write_unlock(&gr_inode_lock);
65679+ }
65680+ preempt_enable();
65681+
65682+ return;
65683+}
65684+
65685+void
65686+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65687+{
65688+ struct name_entry *matchn;
65689+
65690+ if (unlikely(!(gr_status & GR_READY)))
65691+ return;
65692+
65693+ preempt_disable();
65694+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65695+
65696+ if (unlikely((unsigned long)matchn)) {
65697+ write_lock(&gr_inode_lock);
65698+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65699+ write_unlock(&gr_inode_lock);
65700+ }
65701+ preempt_enable();
65702+
65703+ return;
65704+}
65705+
65706+void
65707+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65708+ struct dentry *old_dentry,
65709+ struct dentry *new_dentry,
65710+ struct vfsmount *mnt, const __u8 replace)
65711+{
65712+ struct name_entry *matchn;
65713+ struct inodev_entry *inodev;
65714+ struct inode *inode = new_dentry->d_inode;
65715+ ino_t old_ino = old_dentry->d_inode->i_ino;
65716+ dev_t old_dev = __get_dev(old_dentry);
65717+
65718+ /* vfs_rename swaps the name and parent link for old_dentry and
65719+ new_dentry
65720+ at this point, old_dentry has the new name, parent link, and inode
65721+ for the renamed file
65722+ if a file is being replaced by a rename, new_dentry has the inode
65723+ and name for the replaced file
65724+ */
65725+
65726+ if (unlikely(!(gr_status & GR_READY)))
65727+ return;
65728+
65729+ preempt_disable();
65730+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65731+
65732+ /* we wouldn't have to check d_inode if it weren't for
65733+ NFS silly-renaming
65734+ */
65735+
65736+ write_lock(&gr_inode_lock);
65737+ if (unlikely(replace && inode)) {
65738+ ino_t new_ino = inode->i_ino;
65739+ dev_t new_dev = __get_dev(new_dentry);
65740+
65741+ inodev = lookup_inodev_entry(new_ino, new_dev);
65742+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65743+ do_handle_delete(inodev, new_ino, new_dev);
65744+ }
65745+
65746+ inodev = lookup_inodev_entry(old_ino, old_dev);
65747+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65748+ do_handle_delete(inodev, old_ino, old_dev);
65749+
65750+ if (unlikely((unsigned long)matchn))
65751+ do_handle_create(matchn, old_dentry, mnt);
65752+
65753+ write_unlock(&gr_inode_lock);
65754+ preempt_enable();
65755+
65756+ return;
65757+}
65758+
65759+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65760+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65761+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65762+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65763+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65764+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65765+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65766+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65767+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65768+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65769+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65770+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65771+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65772+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65773+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65774+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65775+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65776+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65777+};
65778+
65779+void
65780+gr_learn_resource(const struct task_struct *task,
65781+ const int res, const unsigned long wanted, const int gt)
65782+{
65783+ struct acl_subject_label *acl;
65784+ const struct cred *cred;
65785+
65786+ if (unlikely((gr_status & GR_READY) &&
65787+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65788+ goto skip_reslog;
65789+
65790+ gr_log_resource(task, res, wanted, gt);
65791+skip_reslog:
65792+
65793+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65794+ return;
65795+
65796+ acl = task->acl;
65797+
65798+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65799+ !(acl->resmask & (1U << (unsigned short) res))))
65800+ return;
65801+
65802+ if (wanted >= acl->res[res].rlim_cur) {
65803+ unsigned long res_add;
65804+
65805+ res_add = wanted + res_learn_bumps[res];
65806+
65807+ acl->res[res].rlim_cur = res_add;
65808+
65809+ if (wanted > acl->res[res].rlim_max)
65810+ acl->res[res].rlim_max = res_add;
65811+
65812+ /* only log the subject filename, since resource logging is supported for
65813+ single-subject learning only */
65814+ rcu_read_lock();
65815+ cred = __task_cred(task);
65816+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65817+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65818+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65819+ "", (unsigned long) res, &task->signal->saved_ip);
65820+ rcu_read_unlock();
65821+ }
65822+
65823+ return;
65824+}
65825+EXPORT_SYMBOL(gr_learn_resource);
65826+#endif
65827+
65828+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65829+void
65830+pax_set_initial_flags(struct linux_binprm *bprm)
65831+{
65832+ struct task_struct *task = current;
65833+ struct acl_subject_label *proc;
65834+ unsigned long flags;
65835+
65836+ if (unlikely(!(gr_status & GR_READY)))
65837+ return;
65838+
65839+ flags = pax_get_flags(task);
65840+
65841+ proc = task->acl;
65842+
65843+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65844+ flags &= ~MF_PAX_PAGEEXEC;
65845+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65846+ flags &= ~MF_PAX_SEGMEXEC;
65847+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65848+ flags &= ~MF_PAX_RANDMMAP;
65849+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65850+ flags &= ~MF_PAX_EMUTRAMP;
65851+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65852+ flags &= ~MF_PAX_MPROTECT;
65853+
65854+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65855+ flags |= MF_PAX_PAGEEXEC;
65856+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65857+ flags |= MF_PAX_SEGMEXEC;
65858+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65859+ flags |= MF_PAX_RANDMMAP;
65860+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65861+ flags |= MF_PAX_EMUTRAMP;
65862+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65863+ flags |= MF_PAX_MPROTECT;
65864+
65865+ pax_set_flags(task, flags);
65866+
65867+ return;
65868+}
65869+#endif
65870+
65871+int
65872+gr_handle_proc_ptrace(struct task_struct *task)
65873+{
65874+ struct file *filp;
65875+ struct task_struct *tmp = task;
65876+ struct task_struct *curtemp = current;
65877+ __u32 retmode;
65878+
65879+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65880+ if (unlikely(!(gr_status & GR_READY)))
65881+ return 0;
65882+#endif
65883+
65884+ read_lock(&tasklist_lock);
65885+ read_lock(&grsec_exec_file_lock);
65886+ filp = task->exec_file;
65887+
65888+ while (task_pid_nr(tmp) > 0) {
65889+ if (tmp == curtemp)
65890+ break;
65891+ tmp = tmp->real_parent;
65892+ }
65893+
65894+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65895+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65896+ read_unlock(&grsec_exec_file_lock);
65897+ read_unlock(&tasklist_lock);
65898+ return 1;
65899+ }
65900+
65901+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65902+ if (!(gr_status & GR_READY)) {
65903+ read_unlock(&grsec_exec_file_lock);
65904+ read_unlock(&tasklist_lock);
65905+ return 0;
65906+ }
65907+#endif
65908+
65909+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65910+ read_unlock(&grsec_exec_file_lock);
65911+ read_unlock(&tasklist_lock);
65912+
65913+ if (retmode & GR_NOPTRACE)
65914+ return 1;
65915+
65916+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65917+ && (current->acl != task->acl || (current->acl != current->role->root_label
65918+ && task_pid_nr(current) != task_pid_nr(task))))
65919+ return 1;
65920+
65921+ return 0;
65922+}
65923+
65924+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65925+{
65926+ if (unlikely(!(gr_status & GR_READY)))
65927+ return;
65928+
65929+ if (!(current->role->roletype & GR_ROLE_GOD))
65930+ return;
65931+
65932+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65933+ p->role->rolename, gr_task_roletype_to_char(p),
65934+ p->acl->filename);
65935+}
65936+
65937+int
65938+gr_handle_ptrace(struct task_struct *task, const long request)
65939+{
65940+ struct task_struct *tmp = task;
65941+ struct task_struct *curtemp = current;
65942+ __u32 retmode;
65943+
65944+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65945+ if (unlikely(!(gr_status & GR_READY)))
65946+ return 0;
65947+#endif
65948+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65949+ read_lock(&tasklist_lock);
65950+ while (task_pid_nr(tmp) > 0) {
65951+ if (tmp == curtemp)
65952+ break;
65953+ tmp = tmp->real_parent;
65954+ }
65955+
65956+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65957+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65958+ read_unlock(&tasklist_lock);
65959+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65960+ return 1;
65961+ }
65962+ read_unlock(&tasklist_lock);
65963+ }
65964+
65965+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65966+ if (!(gr_status & GR_READY))
65967+ return 0;
65968+#endif
65969+
65970+ read_lock(&grsec_exec_file_lock);
65971+ if (unlikely(!task->exec_file)) {
65972+ read_unlock(&grsec_exec_file_lock);
65973+ return 0;
65974+ }
65975+
65976+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65977+ read_unlock(&grsec_exec_file_lock);
65978+
65979+ if (retmode & GR_NOPTRACE) {
65980+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65981+ return 1;
65982+ }
65983+
65984+ if (retmode & GR_PTRACERD) {
65985+ switch (request) {
65986+ case PTRACE_SEIZE:
65987+ case PTRACE_POKETEXT:
65988+ case PTRACE_POKEDATA:
65989+ case PTRACE_POKEUSR:
65990+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65991+ case PTRACE_SETREGS:
65992+ case PTRACE_SETFPREGS:
65993+#endif
65994+#ifdef CONFIG_X86
65995+ case PTRACE_SETFPXREGS:
65996+#endif
65997+#ifdef CONFIG_ALTIVEC
65998+ case PTRACE_SETVRREGS:
65999+#endif
66000+ return 1;
66001+ default:
66002+ return 0;
66003+ }
66004+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66005+ !(current->role->roletype & GR_ROLE_GOD) &&
66006+ (current->acl != task->acl)) {
66007+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66008+ return 1;
66009+ }
66010+
66011+ return 0;
66012+}
66013+
66014+static int is_writable_mmap(const struct file *filp)
66015+{
66016+ struct task_struct *task = current;
66017+ struct acl_object_label *obj, *obj2;
66018+
66019+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66020+ !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))) {
66021+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66022+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66023+ task->role->root_label);
66024+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66025+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66026+ return 1;
66027+ }
66028+ }
66029+ return 0;
66030+}
66031+
66032+int
66033+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66034+{
66035+ __u32 mode;
66036+
66037+ if (unlikely(!file || !(prot & PROT_EXEC)))
66038+ return 1;
66039+
66040+ if (is_writable_mmap(file))
66041+ return 0;
66042+
66043+ mode =
66044+ gr_search_file(file->f_path.dentry,
66045+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66046+ file->f_path.mnt);
66047+
66048+ if (!gr_tpe_allow(file))
66049+ return 0;
66050+
66051+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66052+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66053+ return 0;
66054+ } else if (unlikely(!(mode & GR_EXEC))) {
66055+ return 0;
66056+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66057+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66058+ return 1;
66059+ }
66060+
66061+ return 1;
66062+}
66063+
66064+int
66065+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66066+{
66067+ __u32 mode;
66068+
66069+ if (unlikely(!file || !(prot & PROT_EXEC)))
66070+ return 1;
66071+
66072+ if (is_writable_mmap(file))
66073+ return 0;
66074+
66075+ mode =
66076+ gr_search_file(file->f_path.dentry,
66077+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66078+ file->f_path.mnt);
66079+
66080+ if (!gr_tpe_allow(file))
66081+ return 0;
66082+
66083+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66084+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66085+ return 0;
66086+ } else if (unlikely(!(mode & GR_EXEC))) {
66087+ return 0;
66088+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66089+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66090+ return 1;
66091+ }
66092+
66093+ return 1;
66094+}
66095+
66096+void
66097+gr_acl_handle_psacct(struct task_struct *task, const long code)
66098+{
66099+ unsigned long runtime;
66100+ unsigned long cputime;
66101+ unsigned int wday, cday;
66102+ __u8 whr, chr;
66103+ __u8 wmin, cmin;
66104+ __u8 wsec, csec;
66105+ struct timespec timeval;
66106+
66107+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66108+ !(task->acl->mode & GR_PROCACCT)))
66109+ return;
66110+
66111+ do_posix_clock_monotonic_gettime(&timeval);
66112+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66113+ wday = runtime / (3600 * 24);
66114+ runtime -= wday * (3600 * 24);
66115+ whr = runtime / 3600;
66116+ runtime -= whr * 3600;
66117+ wmin = runtime / 60;
66118+ runtime -= wmin * 60;
66119+ wsec = runtime;
66120+
66121+ cputime = (task->utime + task->stime) / HZ;
66122+ cday = cputime / (3600 * 24);
66123+ cputime -= cday * (3600 * 24);
66124+ chr = cputime / 3600;
66125+ cputime -= chr * 3600;
66126+ cmin = cputime / 60;
66127+ cputime -= cmin * 60;
66128+ csec = cputime;
66129+
66130+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66131+
66132+ return;
66133+}
66134+
66135+#ifdef CONFIG_TASKSTATS
66136+int gr_is_taskstats_denied(int pid)
66137+{
66138+ struct task_struct *task;
66139+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66140+ const struct cred *cred;
66141+#endif
66142+ int ret = 0;
66143+
66144+ /* restrict taskstats viewing to un-chrooted root users
66145+ who have the 'view' subject flag if the RBAC system is enabled
66146+ */
66147+
66148+ rcu_read_lock();
66149+ read_lock(&tasklist_lock);
66150+ task = find_task_by_vpid(pid);
66151+ if (task) {
66152+#ifdef CONFIG_GRKERNSEC_CHROOT
66153+ if (proc_is_chrooted(task))
66154+ ret = -EACCES;
66155+#endif
66156+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66157+ cred = __task_cred(task);
66158+#ifdef CONFIG_GRKERNSEC_PROC_USER
66159+ if (gr_is_global_nonroot(cred->uid))
66160+ ret = -EACCES;
66161+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66162+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66163+ ret = -EACCES;
66164+#endif
66165+#endif
66166+ if (gr_status & GR_READY) {
66167+ if (!(task->acl->mode & GR_VIEW))
66168+ ret = -EACCES;
66169+ }
66170+ } else
66171+ ret = -ENOENT;
66172+
66173+ read_unlock(&tasklist_lock);
66174+ rcu_read_unlock();
66175+
66176+ return ret;
66177+}
66178+#endif
66179+
66180+/* AUXV entries are filled via a descendant of search_binary_handler
66181+ after we've already applied the subject for the target
66182+*/
66183+int gr_acl_enable_at_secure(void)
66184+{
66185+ if (unlikely(!(gr_status & GR_READY)))
66186+ return 0;
66187+
66188+ if (current->acl->mode & GR_ATSECURE)
66189+ return 1;
66190+
66191+ return 0;
66192+}
66193+
66194+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66195+{
66196+ struct task_struct *task = current;
66197+ struct dentry *dentry = file->f_path.dentry;
66198+ struct vfsmount *mnt = file->f_path.mnt;
66199+ struct acl_object_label *obj, *tmp;
66200+ struct acl_subject_label *subj;
66201+ unsigned int bufsize;
66202+ int is_not_root;
66203+ char *path;
66204+ dev_t dev = __get_dev(dentry);
66205+
66206+ if (unlikely(!(gr_status & GR_READY)))
66207+ return 1;
66208+
66209+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66210+ return 1;
66211+
66212+ /* ignore Eric Biederman */
66213+ if (IS_PRIVATE(dentry->d_inode))
66214+ return 1;
66215+
66216+ subj = task->acl;
66217+ read_lock(&gr_inode_lock);
66218+ do {
66219+ obj = lookup_acl_obj_label(ino, dev, subj);
66220+ if (obj != NULL) {
66221+ read_unlock(&gr_inode_lock);
66222+ return (obj->mode & GR_FIND) ? 1 : 0;
66223+ }
66224+ } while ((subj = subj->parent_subject));
66225+ read_unlock(&gr_inode_lock);
66226+
66227+ /* this is purely an optimization since we're looking for an object
66228+ for the directory we're doing a readdir on
66229+ if it's possible for any globbed object to match the entry we're
66230+ filling into the directory, then the object we find here will be
66231+ an anchor point with attached globbed objects
66232+ */
66233+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66234+ if (obj->globbed == NULL)
66235+ return (obj->mode & GR_FIND) ? 1 : 0;
66236+
66237+ is_not_root = ((obj->filename[0] == '/') &&
66238+ (obj->filename[1] == '\0')) ? 0 : 1;
66239+ bufsize = PAGE_SIZE - namelen - is_not_root;
66240+
66241+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66242+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66243+ return 1;
66244+
66245+ preempt_disable();
66246+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66247+ bufsize);
66248+
66249+ bufsize = strlen(path);
66250+
66251+ /* if base is "/", don't append an additional slash */
66252+ if (is_not_root)
66253+ *(path + bufsize) = '/';
66254+ memcpy(path + bufsize + is_not_root, name, namelen);
66255+ *(path + bufsize + namelen + is_not_root) = '\0';
66256+
66257+ tmp = obj->globbed;
66258+ while (tmp) {
66259+ if (!glob_match(tmp->filename, path)) {
66260+ preempt_enable();
66261+ return (tmp->mode & GR_FIND) ? 1 : 0;
66262+ }
66263+ tmp = tmp->next;
66264+ }
66265+ preempt_enable();
66266+ return (obj->mode & GR_FIND) ? 1 : 0;
66267+}
66268+
66269+void gr_put_exec_file(struct task_struct *task)
66270+{
66271+ struct file *filp;
66272+
66273+ write_lock(&grsec_exec_file_lock);
66274+ filp = task->exec_file;
66275+ task->exec_file = NULL;
66276+ write_unlock(&grsec_exec_file_lock);
66277+
66278+ if (filp)
66279+ fput(filp);
66280+
66281+ return;
66282+}
66283+
66284+
66285+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66286+EXPORT_SYMBOL(gr_acl_is_enabled);
66287+#endif
66288+#ifdef CONFIG_SECURITY
66289+EXPORT_SYMBOL(gr_check_user_change);
66290+EXPORT_SYMBOL(gr_check_group_change);
66291+#endif
66292+
66293diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66294new file mode 100644
66295index 0000000..18ffbbd
66296--- /dev/null
66297+++ b/grsecurity/gracl_alloc.c
66298@@ -0,0 +1,105 @@
66299+#include <linux/kernel.h>
66300+#include <linux/mm.h>
66301+#include <linux/slab.h>
66302+#include <linux/vmalloc.h>
66303+#include <linux/gracl.h>
66304+#include <linux/grsecurity.h>
66305+
66306+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
66307+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
66308+
66309+static __inline__ int
66310+alloc_pop(void)
66311+{
66312+ if (current_alloc_state->alloc_stack_next == 1)
66313+ return 0;
66314+
66315+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
66316+
66317+ current_alloc_state->alloc_stack_next--;
66318+
66319+ return 1;
66320+}
66321+
66322+static __inline__ int
66323+alloc_push(void *buf)
66324+{
66325+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
66326+ return 1;
66327+
66328+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
66329+
66330+ current_alloc_state->alloc_stack_next++;
66331+
66332+ return 0;
66333+}
66334+
66335+void *
66336+acl_alloc(unsigned long len)
66337+{
66338+ void *ret = NULL;
66339+
66340+ if (!len || len > PAGE_SIZE)
66341+ goto out;
66342+
66343+ ret = kmalloc(len, GFP_KERNEL);
66344+
66345+ if (ret) {
66346+ if (alloc_push(ret)) {
66347+ kfree(ret);
66348+ ret = NULL;
66349+ }
66350+ }
66351+
66352+out:
66353+ return ret;
66354+}
66355+
66356+void *
66357+acl_alloc_num(unsigned long num, unsigned long len)
66358+{
66359+ if (!len || (num > (PAGE_SIZE / len)))
66360+ return NULL;
66361+
66362+ return acl_alloc(num * len);
66363+}
66364+
66365+void
66366+acl_free_all(void)
66367+{
66368+ if (!current_alloc_state->alloc_stack)
66369+ return;
66370+
66371+ while (alloc_pop()) ;
66372+
66373+ if (current_alloc_state->alloc_stack) {
66374+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66375+ kfree(current_alloc_state->alloc_stack);
66376+ else
66377+ vfree(current_alloc_state->alloc_stack);
66378+ }
66379+
66380+ current_alloc_state->alloc_stack = NULL;
66381+ current_alloc_state->alloc_stack_size = 1;
66382+ current_alloc_state->alloc_stack_next = 1;
66383+
66384+ return;
66385+}
66386+
66387+int
66388+acl_alloc_stack_init(unsigned long size)
66389+{
66390+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66391+ current_alloc_state->alloc_stack =
66392+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66393+ else
66394+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
66395+
66396+ current_alloc_state->alloc_stack_size = size;
66397+ current_alloc_state->alloc_stack_next = 1;
66398+
66399+ if (!current_alloc_state->alloc_stack)
66400+ return 0;
66401+ else
66402+ return 1;
66403+}
66404diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66405new file mode 100644
66406index 0000000..bdd51ea
66407--- /dev/null
66408+++ b/grsecurity/gracl_cap.c
66409@@ -0,0 +1,110 @@
66410+#include <linux/kernel.h>
66411+#include <linux/module.h>
66412+#include <linux/sched.h>
66413+#include <linux/gracl.h>
66414+#include <linux/grsecurity.h>
66415+#include <linux/grinternal.h>
66416+
66417+extern const char *captab_log[];
66418+extern int captab_log_entries;
66419+
66420+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66421+{
66422+ struct acl_subject_label *curracl;
66423+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66424+ kernel_cap_t cap_audit = __cap_empty_set;
66425+
66426+ if (!gr_acl_is_enabled())
66427+ return 1;
66428+
66429+ curracl = task->acl;
66430+
66431+ cap_drop = curracl->cap_lower;
66432+ cap_mask = curracl->cap_mask;
66433+ cap_audit = curracl->cap_invert_audit;
66434+
66435+ while ((curracl = curracl->parent_subject)) {
66436+ /* if the cap isn't specified in the current computed mask but is specified in the
66437+ current level subject, and is lowered in the current level subject, then add
66438+ it to the set of dropped capabilities
66439+ otherwise, add the current level subject's mask to the current computed mask
66440+ */
66441+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66442+ cap_raise(cap_mask, cap);
66443+ if (cap_raised(curracl->cap_lower, cap))
66444+ cap_raise(cap_drop, cap);
66445+ if (cap_raised(curracl->cap_invert_audit, cap))
66446+ cap_raise(cap_audit, cap);
66447+ }
66448+ }
66449+
66450+ if (!cap_raised(cap_drop, cap)) {
66451+ if (cap_raised(cap_audit, cap))
66452+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66453+ return 1;
66454+ }
66455+
66456+ curracl = task->acl;
66457+
66458+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66459+ && cap_raised(cred->cap_effective, cap)) {
66460+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66461+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66462+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66463+ gr_to_filename(task->exec_file->f_path.dentry,
66464+ task->exec_file->f_path.mnt) : curracl->filename,
66465+ curracl->filename, 0UL,
66466+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66467+ return 1;
66468+ }
66469+
66470+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66471+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66472+
66473+ return 0;
66474+}
66475+
66476+int
66477+gr_acl_is_capable(const int cap)
66478+{
66479+ return gr_task_acl_is_capable(current, current_cred(), cap);
66480+}
66481+
66482+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66483+{
66484+ struct acl_subject_label *curracl;
66485+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66486+
66487+ if (!gr_acl_is_enabled())
66488+ return 1;
66489+
66490+ curracl = task->acl;
66491+
66492+ cap_drop = curracl->cap_lower;
66493+ cap_mask = curracl->cap_mask;
66494+
66495+ while ((curracl = curracl->parent_subject)) {
66496+ /* if the cap isn't specified in the current computed mask but is specified in the
66497+ current level subject, and is lowered in the current level subject, then add
66498+ it to the set of dropped capabilities
66499+ otherwise, add the current level subject's mask to the current computed mask
66500+ */
66501+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66502+ cap_raise(cap_mask, cap);
66503+ if (cap_raised(curracl->cap_lower, cap))
66504+ cap_raise(cap_drop, cap);
66505+ }
66506+ }
66507+
66508+ if (!cap_raised(cap_drop, cap))
66509+ return 1;
66510+
66511+ return 0;
66512+}
66513+
66514+int
66515+gr_acl_is_capable_nolog(const int cap)
66516+{
66517+ return gr_task_acl_is_capable_nolog(current, cap);
66518+}
66519+
66520diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66521new file mode 100644
66522index 0000000..ca25605
66523--- /dev/null
66524+++ b/grsecurity/gracl_compat.c
66525@@ -0,0 +1,270 @@
66526+#include <linux/kernel.h>
66527+#include <linux/gracl.h>
66528+#include <linux/compat.h>
66529+#include <linux/gracl_compat.h>
66530+
66531+#include <asm/uaccess.h>
66532+
66533+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66534+{
66535+ struct gr_arg_wrapper_compat uwrapcompat;
66536+
66537+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66538+ return -EFAULT;
66539+
66540+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
66541+ (uwrapcompat.version != 0x2901)) ||
66542+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66543+ return -EINVAL;
66544+
66545+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66546+ uwrap->version = uwrapcompat.version;
66547+ uwrap->size = sizeof(struct gr_arg);
66548+
66549+ return 0;
66550+}
66551+
66552+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66553+{
66554+ struct gr_arg_compat argcompat;
66555+
66556+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66557+ return -EFAULT;
66558+
66559+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66560+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66561+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66562+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66563+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66564+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66565+
66566+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66567+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66568+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66569+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66570+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66571+ arg->segv_device = argcompat.segv_device;
66572+ arg->segv_inode = argcompat.segv_inode;
66573+ arg->segv_uid = argcompat.segv_uid;
66574+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66575+ arg->mode = argcompat.mode;
66576+
66577+ return 0;
66578+}
66579+
66580+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66581+{
66582+ struct acl_object_label_compat objcompat;
66583+
66584+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66585+ return -EFAULT;
66586+
66587+ obj->filename = compat_ptr(objcompat.filename);
66588+ obj->inode = objcompat.inode;
66589+ obj->device = objcompat.device;
66590+ obj->mode = objcompat.mode;
66591+
66592+ obj->nested = compat_ptr(objcompat.nested);
66593+ obj->globbed = compat_ptr(objcompat.globbed);
66594+
66595+ obj->prev = compat_ptr(objcompat.prev);
66596+ obj->next = compat_ptr(objcompat.next);
66597+
66598+ return 0;
66599+}
66600+
66601+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66602+{
66603+ unsigned int i;
66604+ struct acl_subject_label_compat subjcompat;
66605+
66606+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66607+ return -EFAULT;
66608+
66609+ subj->filename = compat_ptr(subjcompat.filename);
66610+ subj->inode = subjcompat.inode;
66611+ subj->device = subjcompat.device;
66612+ subj->mode = subjcompat.mode;
66613+ subj->cap_mask = subjcompat.cap_mask;
66614+ subj->cap_lower = subjcompat.cap_lower;
66615+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66616+
66617+ for (i = 0; i < GR_NLIMITS; i++) {
66618+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66619+ subj->res[i].rlim_cur = RLIM_INFINITY;
66620+ else
66621+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66622+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66623+ subj->res[i].rlim_max = RLIM_INFINITY;
66624+ else
66625+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66626+ }
66627+ subj->resmask = subjcompat.resmask;
66628+
66629+ subj->user_trans_type = subjcompat.user_trans_type;
66630+ subj->group_trans_type = subjcompat.group_trans_type;
66631+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66632+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66633+ subj->user_trans_num = subjcompat.user_trans_num;
66634+ subj->group_trans_num = subjcompat.group_trans_num;
66635+
66636+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66637+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66638+ subj->ip_type = subjcompat.ip_type;
66639+ subj->ips = compat_ptr(subjcompat.ips);
66640+ subj->ip_num = subjcompat.ip_num;
66641+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66642+
66643+ subj->crashes = subjcompat.crashes;
66644+ subj->expires = subjcompat.expires;
66645+
66646+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66647+ subj->hash = compat_ptr(subjcompat.hash);
66648+ subj->prev = compat_ptr(subjcompat.prev);
66649+ subj->next = compat_ptr(subjcompat.next);
66650+
66651+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66652+ subj->obj_hash_size = subjcompat.obj_hash_size;
66653+ subj->pax_flags = subjcompat.pax_flags;
66654+
66655+ return 0;
66656+}
66657+
66658+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66659+{
66660+ struct acl_role_label_compat rolecompat;
66661+
66662+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66663+ return -EFAULT;
66664+
66665+ role->rolename = compat_ptr(rolecompat.rolename);
66666+ role->uidgid = rolecompat.uidgid;
66667+ role->roletype = rolecompat.roletype;
66668+
66669+ role->auth_attempts = rolecompat.auth_attempts;
66670+ role->expires = rolecompat.expires;
66671+
66672+ role->root_label = compat_ptr(rolecompat.root_label);
66673+ role->hash = compat_ptr(rolecompat.hash);
66674+
66675+ role->prev = compat_ptr(rolecompat.prev);
66676+ role->next = compat_ptr(rolecompat.next);
66677+
66678+ role->transitions = compat_ptr(rolecompat.transitions);
66679+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66680+ role->domain_children = compat_ptr(rolecompat.domain_children);
66681+ role->domain_child_num = rolecompat.domain_child_num;
66682+
66683+ role->umask = rolecompat.umask;
66684+
66685+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66686+ role->subj_hash_size = rolecompat.subj_hash_size;
66687+
66688+ return 0;
66689+}
66690+
66691+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66692+{
66693+ struct role_allowed_ip_compat roleip_compat;
66694+
66695+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66696+ return -EFAULT;
66697+
66698+ roleip->addr = roleip_compat.addr;
66699+ roleip->netmask = roleip_compat.netmask;
66700+
66701+ roleip->prev = compat_ptr(roleip_compat.prev);
66702+ roleip->next = compat_ptr(roleip_compat.next);
66703+
66704+ return 0;
66705+}
66706+
66707+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66708+{
66709+ struct role_transition_compat trans_compat;
66710+
66711+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66712+ return -EFAULT;
66713+
66714+ trans->rolename = compat_ptr(trans_compat.rolename);
66715+
66716+ trans->prev = compat_ptr(trans_compat.prev);
66717+ trans->next = compat_ptr(trans_compat.next);
66718+
66719+ return 0;
66720+
66721+}
66722+
66723+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66724+{
66725+ struct gr_hash_struct_compat hash_compat;
66726+
66727+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66728+ return -EFAULT;
66729+
66730+ hash->table = compat_ptr(hash_compat.table);
66731+ hash->nametable = compat_ptr(hash_compat.nametable);
66732+ hash->first = compat_ptr(hash_compat.first);
66733+
66734+ hash->table_size = hash_compat.table_size;
66735+ hash->used_size = hash_compat.used_size;
66736+
66737+ hash->type = hash_compat.type;
66738+
66739+ return 0;
66740+}
66741+
66742+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66743+{
66744+ compat_uptr_t ptrcompat;
66745+
66746+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66747+ return -EFAULT;
66748+
66749+ *(void **)ptr = compat_ptr(ptrcompat);
66750+
66751+ return 0;
66752+}
66753+
66754+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66755+{
66756+ struct acl_ip_label_compat ip_compat;
66757+
66758+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66759+ return -EFAULT;
66760+
66761+ ip->iface = compat_ptr(ip_compat.iface);
66762+ ip->addr = ip_compat.addr;
66763+ ip->netmask = ip_compat.netmask;
66764+ ip->low = ip_compat.low;
66765+ ip->high = ip_compat.high;
66766+ ip->mode = ip_compat.mode;
66767+ ip->type = ip_compat.type;
66768+
66769+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66770+
66771+ ip->prev = compat_ptr(ip_compat.prev);
66772+ ip->next = compat_ptr(ip_compat.next);
66773+
66774+ return 0;
66775+}
66776+
66777+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66778+{
66779+ struct sprole_pw_compat pw_compat;
66780+
66781+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66782+ return -EFAULT;
66783+
66784+ pw->rolename = compat_ptr(pw_compat.rolename);
66785+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66786+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66787+
66788+ return 0;
66789+}
66790+
66791+size_t get_gr_arg_wrapper_size_compat(void)
66792+{
66793+ return sizeof(struct gr_arg_wrapper_compat);
66794+}
66795+
66796diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66797new file mode 100644
66798index 0000000..a340c17
66799--- /dev/null
66800+++ b/grsecurity/gracl_fs.c
66801@@ -0,0 +1,431 @@
66802+#include <linux/kernel.h>
66803+#include <linux/sched.h>
66804+#include <linux/types.h>
66805+#include <linux/fs.h>
66806+#include <linux/file.h>
66807+#include <linux/stat.h>
66808+#include <linux/grsecurity.h>
66809+#include <linux/grinternal.h>
66810+#include <linux/gracl.h>
66811+
66812+umode_t
66813+gr_acl_umask(void)
66814+{
66815+ if (unlikely(!gr_acl_is_enabled()))
66816+ return 0;
66817+
66818+ return current->role->umask;
66819+}
66820+
66821+__u32
66822+gr_acl_handle_hidden_file(const struct dentry * dentry,
66823+ const struct vfsmount * mnt)
66824+{
66825+ __u32 mode;
66826+
66827+ if (unlikely(!dentry->d_inode))
66828+ return GR_FIND;
66829+
66830+ mode =
66831+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66832+
66833+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66834+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66835+ return mode;
66836+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66837+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66838+ return 0;
66839+ } else if (unlikely(!(mode & GR_FIND)))
66840+ return 0;
66841+
66842+ return GR_FIND;
66843+}
66844+
66845+__u32
66846+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66847+ int acc_mode)
66848+{
66849+ __u32 reqmode = GR_FIND;
66850+ __u32 mode;
66851+
66852+ if (unlikely(!dentry->d_inode))
66853+ return reqmode;
66854+
66855+ if (acc_mode & MAY_APPEND)
66856+ reqmode |= GR_APPEND;
66857+ else if (acc_mode & MAY_WRITE)
66858+ reqmode |= GR_WRITE;
66859+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66860+ reqmode |= GR_READ;
66861+
66862+ mode =
66863+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66864+ mnt);
66865+
66866+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66867+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66868+ reqmode & GR_READ ? " reading" : "",
66869+ reqmode & GR_WRITE ? " writing" : reqmode &
66870+ GR_APPEND ? " appending" : "");
66871+ return reqmode;
66872+ } else
66873+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66874+ {
66875+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66876+ reqmode & GR_READ ? " reading" : "",
66877+ reqmode & GR_WRITE ? " writing" : reqmode &
66878+ GR_APPEND ? " appending" : "");
66879+ return 0;
66880+ } else if (unlikely((mode & reqmode) != reqmode))
66881+ return 0;
66882+
66883+ return reqmode;
66884+}
66885+
66886+__u32
66887+gr_acl_handle_creat(const struct dentry * dentry,
66888+ const struct dentry * p_dentry,
66889+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66890+ const int imode)
66891+{
66892+ __u32 reqmode = GR_WRITE | GR_CREATE;
66893+ __u32 mode;
66894+
66895+ if (acc_mode & MAY_APPEND)
66896+ reqmode |= GR_APPEND;
66897+ // if a directory was required or the directory already exists, then
66898+ // don't count this open as a read
66899+ if ((acc_mode & MAY_READ) &&
66900+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66901+ reqmode |= GR_READ;
66902+ if ((open_flags & O_CREAT) &&
66903+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66904+ reqmode |= GR_SETID;
66905+
66906+ mode =
66907+ gr_check_create(dentry, p_dentry, p_mnt,
66908+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66909+
66910+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66911+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66912+ reqmode & GR_READ ? " reading" : "",
66913+ reqmode & GR_WRITE ? " writing" : reqmode &
66914+ GR_APPEND ? " appending" : "");
66915+ return reqmode;
66916+ } else
66917+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66918+ {
66919+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66920+ reqmode & GR_READ ? " reading" : "",
66921+ reqmode & GR_WRITE ? " writing" : reqmode &
66922+ GR_APPEND ? " appending" : "");
66923+ return 0;
66924+ } else if (unlikely((mode & reqmode) != reqmode))
66925+ return 0;
66926+
66927+ return reqmode;
66928+}
66929+
66930+__u32
66931+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66932+ const int fmode)
66933+{
66934+ __u32 mode, reqmode = GR_FIND;
66935+
66936+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66937+ reqmode |= GR_EXEC;
66938+ if (fmode & S_IWOTH)
66939+ reqmode |= GR_WRITE;
66940+ if (fmode & S_IROTH)
66941+ reqmode |= GR_READ;
66942+
66943+ mode =
66944+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66945+ mnt);
66946+
66947+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66948+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66949+ reqmode & GR_READ ? " reading" : "",
66950+ reqmode & GR_WRITE ? " writing" : "",
66951+ reqmode & GR_EXEC ? " executing" : "");
66952+ return reqmode;
66953+ } else
66954+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66955+ {
66956+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66957+ reqmode & GR_READ ? " reading" : "",
66958+ reqmode & GR_WRITE ? " writing" : "",
66959+ reqmode & GR_EXEC ? " executing" : "");
66960+ return 0;
66961+ } else if (unlikely((mode & reqmode) != reqmode))
66962+ return 0;
66963+
66964+ return reqmode;
66965+}
66966+
66967+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66968+{
66969+ __u32 mode;
66970+
66971+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66972+
66973+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66974+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66975+ return mode;
66976+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66977+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66978+ return 0;
66979+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66980+ return 0;
66981+
66982+ return (reqmode);
66983+}
66984+
66985+__u32
66986+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66987+{
66988+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66989+}
66990+
66991+__u32
66992+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66993+{
66994+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66995+}
66996+
66997+__u32
66998+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66999+{
67000+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67001+}
67002+
67003+__u32
67004+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67005+{
67006+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67007+}
67008+
67009+__u32
67010+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67011+ umode_t *modeptr)
67012+{
67013+ umode_t mode;
67014+
67015+ *modeptr &= ~gr_acl_umask();
67016+ mode = *modeptr;
67017+
67018+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67019+ return 1;
67020+
67021+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67022+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67023+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67024+ GR_CHMOD_ACL_MSG);
67025+ } else {
67026+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67027+ }
67028+}
67029+
67030+__u32
67031+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67032+{
67033+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67034+}
67035+
67036+__u32
67037+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67038+{
67039+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67040+}
67041+
67042+__u32
67043+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67044+{
67045+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67046+}
67047+
67048+__u32
67049+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67050+{
67051+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67052+ GR_UNIXCONNECT_ACL_MSG);
67053+}
67054+
67055+/* hardlinks require at minimum create and link permission,
67056+ any additional privilege required is based on the
67057+ privilege of the file being linked to
67058+*/
67059+__u32
67060+gr_acl_handle_link(const struct dentry * new_dentry,
67061+ const struct dentry * parent_dentry,
67062+ const struct vfsmount * parent_mnt,
67063+ const struct dentry * old_dentry,
67064+ const struct vfsmount * old_mnt, const struct filename *to)
67065+{
67066+ __u32 mode;
67067+ __u32 needmode = GR_CREATE | GR_LINK;
67068+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67069+
67070+ mode =
67071+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67072+ old_mnt);
67073+
67074+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67075+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67076+ return mode;
67077+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67078+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67079+ return 0;
67080+ } else if (unlikely((mode & needmode) != needmode))
67081+ return 0;
67082+
67083+ return 1;
67084+}
67085+
67086+__u32
67087+gr_acl_handle_symlink(const struct dentry * new_dentry,
67088+ const struct dentry * parent_dentry,
67089+ const struct vfsmount * parent_mnt, const struct filename *from)
67090+{
67091+ __u32 needmode = GR_WRITE | GR_CREATE;
67092+ __u32 mode;
67093+
67094+ mode =
67095+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67096+ GR_CREATE | GR_AUDIT_CREATE |
67097+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67098+
67099+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67100+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67101+ return mode;
67102+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67103+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67104+ return 0;
67105+ } else if (unlikely((mode & needmode) != needmode))
67106+ return 0;
67107+
67108+ return (GR_WRITE | GR_CREATE);
67109+}
67110+
67111+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)
67112+{
67113+ __u32 mode;
67114+
67115+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67116+
67117+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67118+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67119+ return mode;
67120+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67121+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67122+ return 0;
67123+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67124+ return 0;
67125+
67126+ return (reqmode);
67127+}
67128+
67129+__u32
67130+gr_acl_handle_mknod(const struct dentry * new_dentry,
67131+ const struct dentry * parent_dentry,
67132+ const struct vfsmount * parent_mnt,
67133+ const int mode)
67134+{
67135+ __u32 reqmode = GR_WRITE | GR_CREATE;
67136+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67137+ reqmode |= GR_SETID;
67138+
67139+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67140+ reqmode, GR_MKNOD_ACL_MSG);
67141+}
67142+
67143+__u32
67144+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67145+ const struct dentry *parent_dentry,
67146+ const struct vfsmount *parent_mnt)
67147+{
67148+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67149+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67150+}
67151+
67152+#define RENAME_CHECK_SUCCESS(old, new) \
67153+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67154+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67155+
67156+int
67157+gr_acl_handle_rename(struct dentry *new_dentry,
67158+ struct dentry *parent_dentry,
67159+ const struct vfsmount *parent_mnt,
67160+ struct dentry *old_dentry,
67161+ struct inode *old_parent_inode,
67162+ struct vfsmount *old_mnt, const struct filename *newname)
67163+{
67164+ __u32 comp1, comp2;
67165+ int error = 0;
67166+
67167+ if (unlikely(!gr_acl_is_enabled()))
67168+ return 0;
67169+
67170+ if (!new_dentry->d_inode) {
67171+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67172+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67173+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67174+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67175+ GR_DELETE | GR_AUDIT_DELETE |
67176+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67177+ GR_SUPPRESS, old_mnt);
67178+ } else {
67179+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67180+ GR_CREATE | GR_DELETE |
67181+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67182+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67183+ GR_SUPPRESS, parent_mnt);
67184+ comp2 =
67185+ gr_search_file(old_dentry,
67186+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67187+ GR_DELETE | GR_AUDIT_DELETE |
67188+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67189+ }
67190+
67191+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67192+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67193+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67194+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67195+ && !(comp2 & GR_SUPPRESS)) {
67196+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67197+ error = -EACCES;
67198+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67199+ error = -EACCES;
67200+
67201+ return error;
67202+}
67203+
67204+void
67205+gr_acl_handle_exit(void)
67206+{
67207+ u16 id;
67208+ char *rolename;
67209+
67210+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67211+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67212+ id = current->acl_role_id;
67213+ rolename = current->role->rolename;
67214+ gr_set_acls(1);
67215+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67216+ }
67217+
67218+ gr_put_exec_file(current);
67219+ return;
67220+}
67221+
67222+int
67223+gr_acl_handle_procpidmem(const struct task_struct *task)
67224+{
67225+ if (unlikely(!gr_acl_is_enabled()))
67226+ return 0;
67227+
67228+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67229+ return -EACCES;
67230+
67231+ return 0;
67232+}
67233diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67234new file mode 100644
67235index 0000000..f056b81
67236--- /dev/null
67237+++ b/grsecurity/gracl_ip.c
67238@@ -0,0 +1,386 @@
67239+#include <linux/kernel.h>
67240+#include <asm/uaccess.h>
67241+#include <asm/errno.h>
67242+#include <net/sock.h>
67243+#include <linux/file.h>
67244+#include <linux/fs.h>
67245+#include <linux/net.h>
67246+#include <linux/in.h>
67247+#include <linux/skbuff.h>
67248+#include <linux/ip.h>
67249+#include <linux/udp.h>
67250+#include <linux/types.h>
67251+#include <linux/sched.h>
67252+#include <linux/netdevice.h>
67253+#include <linux/inetdevice.h>
67254+#include <linux/gracl.h>
67255+#include <linux/grsecurity.h>
67256+#include <linux/grinternal.h>
67257+
67258+#define GR_BIND 0x01
67259+#define GR_CONNECT 0x02
67260+#define GR_INVERT 0x04
67261+#define GR_BINDOVERRIDE 0x08
67262+#define GR_CONNECTOVERRIDE 0x10
67263+#define GR_SOCK_FAMILY 0x20
67264+
67265+static const char * gr_protocols[IPPROTO_MAX] = {
67266+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67267+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67268+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67269+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67270+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67271+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67272+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67273+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67274+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67275+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67276+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67277+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67278+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67279+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67280+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67281+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67282+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67283+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67284+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67285+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67286+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67287+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67288+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67289+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67290+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67291+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67292+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67293+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67294+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67295+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67296+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67297+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67298+ };
67299+
67300+static const char * gr_socktypes[SOCK_MAX] = {
67301+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67302+ "unknown:7", "unknown:8", "unknown:9", "packet"
67303+ };
67304+
67305+static const char * gr_sockfamilies[AF_MAX+1] = {
67306+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67307+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67308+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67309+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67310+ };
67311+
67312+const char *
67313+gr_proto_to_name(unsigned char proto)
67314+{
67315+ return gr_protocols[proto];
67316+}
67317+
67318+const char *
67319+gr_socktype_to_name(unsigned char type)
67320+{
67321+ return gr_socktypes[type];
67322+}
67323+
67324+const char *
67325+gr_sockfamily_to_name(unsigned char family)
67326+{
67327+ return gr_sockfamilies[family];
67328+}
67329+
67330+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67331+
67332+int
67333+gr_search_socket(const int domain, const int type, const int protocol)
67334+{
67335+ struct acl_subject_label *curr;
67336+ const struct cred *cred = current_cred();
67337+
67338+ if (unlikely(!gr_acl_is_enabled()))
67339+ goto exit;
67340+
67341+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67342+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67343+ goto exit; // let the kernel handle it
67344+
67345+ curr = current->acl;
67346+
67347+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67348+ /* the family is allowed, if this is PF_INET allow it only if
67349+ the extra sock type/protocol checks pass */
67350+ if (domain == PF_INET)
67351+ goto inet_check;
67352+ goto exit;
67353+ } else {
67354+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67355+ __u32 fakeip = 0;
67356+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67357+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67358+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67359+ gr_to_filename(current->exec_file->f_path.dentry,
67360+ current->exec_file->f_path.mnt) :
67361+ curr->filename, curr->filename,
67362+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67363+ &current->signal->saved_ip);
67364+ goto exit;
67365+ }
67366+ goto exit_fail;
67367+ }
67368+
67369+inet_check:
67370+ /* the rest of this checking is for IPv4 only */
67371+ if (!curr->ips)
67372+ goto exit;
67373+
67374+ if ((curr->ip_type & (1U << type)) &&
67375+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67376+ goto exit;
67377+
67378+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67379+ /* we don't place acls on raw sockets , and sometimes
67380+ dgram/ip sockets are opened for ioctl and not
67381+ bind/connect, so we'll fake a bind learn log */
67382+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67383+ __u32 fakeip = 0;
67384+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67385+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67386+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67387+ gr_to_filename(current->exec_file->f_path.dentry,
67388+ current->exec_file->f_path.mnt) :
67389+ curr->filename, curr->filename,
67390+ &fakeip, 0, type,
67391+ protocol, GR_CONNECT, &current->signal->saved_ip);
67392+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67393+ __u32 fakeip = 0;
67394+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67395+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67396+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67397+ gr_to_filename(current->exec_file->f_path.dentry,
67398+ current->exec_file->f_path.mnt) :
67399+ curr->filename, curr->filename,
67400+ &fakeip, 0, type,
67401+ protocol, GR_BIND, &current->signal->saved_ip);
67402+ }
67403+ /* we'll log when they use connect or bind */
67404+ goto exit;
67405+ }
67406+
67407+exit_fail:
67408+ if (domain == PF_INET)
67409+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67410+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67411+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67412+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67413+ gr_socktype_to_name(type), protocol);
67414+
67415+ return 0;
67416+exit:
67417+ return 1;
67418+}
67419+
67420+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)
67421+{
67422+ if ((ip->mode & mode) &&
67423+ (ip_port >= ip->low) &&
67424+ (ip_port <= ip->high) &&
67425+ ((ntohl(ip_addr) & our_netmask) ==
67426+ (ntohl(our_addr) & our_netmask))
67427+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67428+ && (ip->type & (1U << type))) {
67429+ if (ip->mode & GR_INVERT)
67430+ return 2; // specifically denied
67431+ else
67432+ return 1; // allowed
67433+ }
67434+
67435+ return 0; // not specifically allowed, may continue parsing
67436+}
67437+
67438+static int
67439+gr_search_connectbind(const int full_mode, struct sock *sk,
67440+ struct sockaddr_in *addr, const int type)
67441+{
67442+ char iface[IFNAMSIZ] = {0};
67443+ struct acl_subject_label *curr;
67444+ struct acl_ip_label *ip;
67445+ struct inet_sock *isk;
67446+ struct net_device *dev;
67447+ struct in_device *idev;
67448+ unsigned long i;
67449+ int ret;
67450+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67451+ __u32 ip_addr = 0;
67452+ __u32 our_addr;
67453+ __u32 our_netmask;
67454+ char *p;
67455+ __u16 ip_port = 0;
67456+ const struct cred *cred = current_cred();
67457+
67458+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67459+ return 0;
67460+
67461+ curr = current->acl;
67462+ isk = inet_sk(sk);
67463+
67464+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67465+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67466+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67467+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67468+ struct sockaddr_in saddr;
67469+ int err;
67470+
67471+ saddr.sin_family = AF_INET;
67472+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67473+ saddr.sin_port = isk->inet_sport;
67474+
67475+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67476+ if (err)
67477+ return err;
67478+
67479+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67480+ if (err)
67481+ return err;
67482+ }
67483+
67484+ if (!curr->ips)
67485+ return 0;
67486+
67487+ ip_addr = addr->sin_addr.s_addr;
67488+ ip_port = ntohs(addr->sin_port);
67489+
67490+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67491+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67492+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67493+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67494+ gr_to_filename(current->exec_file->f_path.dentry,
67495+ current->exec_file->f_path.mnt) :
67496+ curr->filename, curr->filename,
67497+ &ip_addr, ip_port, type,
67498+ sk->sk_protocol, mode, &current->signal->saved_ip);
67499+ return 0;
67500+ }
67501+
67502+ for (i = 0; i < curr->ip_num; i++) {
67503+ ip = *(curr->ips + i);
67504+ if (ip->iface != NULL) {
67505+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67506+ p = strchr(iface, ':');
67507+ if (p != NULL)
67508+ *p = '\0';
67509+ dev = dev_get_by_name(sock_net(sk), iface);
67510+ if (dev == NULL)
67511+ continue;
67512+ idev = in_dev_get(dev);
67513+ if (idev == NULL) {
67514+ dev_put(dev);
67515+ continue;
67516+ }
67517+ rcu_read_lock();
67518+ for_ifa(idev) {
67519+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67520+ our_addr = ifa->ifa_address;
67521+ our_netmask = 0xffffffff;
67522+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67523+ if (ret == 1) {
67524+ rcu_read_unlock();
67525+ in_dev_put(idev);
67526+ dev_put(dev);
67527+ return 0;
67528+ } else if (ret == 2) {
67529+ rcu_read_unlock();
67530+ in_dev_put(idev);
67531+ dev_put(dev);
67532+ goto denied;
67533+ }
67534+ }
67535+ } endfor_ifa(idev);
67536+ rcu_read_unlock();
67537+ in_dev_put(idev);
67538+ dev_put(dev);
67539+ } else {
67540+ our_addr = ip->addr;
67541+ our_netmask = ip->netmask;
67542+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67543+ if (ret == 1)
67544+ return 0;
67545+ else if (ret == 2)
67546+ goto denied;
67547+ }
67548+ }
67549+
67550+denied:
67551+ if (mode == GR_BIND)
67552+ 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));
67553+ else if (mode == GR_CONNECT)
67554+ 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));
67555+
67556+ return -EACCES;
67557+}
67558+
67559+int
67560+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67561+{
67562+ /* always allow disconnection of dgram sockets with connect */
67563+ if (addr->sin_family == AF_UNSPEC)
67564+ return 0;
67565+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67566+}
67567+
67568+int
67569+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67570+{
67571+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67572+}
67573+
67574+int gr_search_listen(struct socket *sock)
67575+{
67576+ struct sock *sk = sock->sk;
67577+ struct sockaddr_in addr;
67578+
67579+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67580+ addr.sin_port = inet_sk(sk)->inet_sport;
67581+
67582+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67583+}
67584+
67585+int gr_search_accept(struct socket *sock)
67586+{
67587+ struct sock *sk = sock->sk;
67588+ struct sockaddr_in addr;
67589+
67590+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67591+ addr.sin_port = inet_sk(sk)->inet_sport;
67592+
67593+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67594+}
67595+
67596+int
67597+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67598+{
67599+ if (addr)
67600+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67601+ else {
67602+ struct sockaddr_in sin;
67603+ const struct inet_sock *inet = inet_sk(sk);
67604+
67605+ sin.sin_addr.s_addr = inet->inet_daddr;
67606+ sin.sin_port = inet->inet_dport;
67607+
67608+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67609+ }
67610+}
67611+
67612+int
67613+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67614+{
67615+ struct sockaddr_in sin;
67616+
67617+ if (unlikely(skb->len < sizeof (struct udphdr)))
67618+ return 0; // skip this packet
67619+
67620+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67621+ sin.sin_port = udp_hdr(skb)->source;
67622+
67623+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67624+}
67625diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67626new file mode 100644
67627index 0000000..25f54ef
67628--- /dev/null
67629+++ b/grsecurity/gracl_learn.c
67630@@ -0,0 +1,207 @@
67631+#include <linux/kernel.h>
67632+#include <linux/mm.h>
67633+#include <linux/sched.h>
67634+#include <linux/poll.h>
67635+#include <linux/string.h>
67636+#include <linux/file.h>
67637+#include <linux/types.h>
67638+#include <linux/vmalloc.h>
67639+#include <linux/grinternal.h>
67640+
67641+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67642+ size_t count, loff_t *ppos);
67643+extern int gr_acl_is_enabled(void);
67644+
67645+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67646+static int gr_learn_attached;
67647+
67648+/* use a 512k buffer */
67649+#define LEARN_BUFFER_SIZE (512 * 1024)
67650+
67651+static DEFINE_SPINLOCK(gr_learn_lock);
67652+static DEFINE_MUTEX(gr_learn_user_mutex);
67653+
67654+/* we need to maintain two buffers, so that the kernel context of grlearn
67655+ uses a semaphore around the userspace copying, and the other kernel contexts
67656+ use a spinlock when copying into the buffer, since they cannot sleep
67657+*/
67658+static char *learn_buffer;
67659+static char *learn_buffer_user;
67660+static int learn_buffer_len;
67661+static int learn_buffer_user_len;
67662+
67663+static ssize_t
67664+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67665+{
67666+ DECLARE_WAITQUEUE(wait, current);
67667+ ssize_t retval = 0;
67668+
67669+ add_wait_queue(&learn_wait, &wait);
67670+ set_current_state(TASK_INTERRUPTIBLE);
67671+ do {
67672+ mutex_lock(&gr_learn_user_mutex);
67673+ spin_lock(&gr_learn_lock);
67674+ if (learn_buffer_len)
67675+ break;
67676+ spin_unlock(&gr_learn_lock);
67677+ mutex_unlock(&gr_learn_user_mutex);
67678+ if (file->f_flags & O_NONBLOCK) {
67679+ retval = -EAGAIN;
67680+ goto out;
67681+ }
67682+ if (signal_pending(current)) {
67683+ retval = -ERESTARTSYS;
67684+ goto out;
67685+ }
67686+
67687+ schedule();
67688+ } while (1);
67689+
67690+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67691+ learn_buffer_user_len = learn_buffer_len;
67692+ retval = learn_buffer_len;
67693+ learn_buffer_len = 0;
67694+
67695+ spin_unlock(&gr_learn_lock);
67696+
67697+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67698+ retval = -EFAULT;
67699+
67700+ mutex_unlock(&gr_learn_user_mutex);
67701+out:
67702+ set_current_state(TASK_RUNNING);
67703+ remove_wait_queue(&learn_wait, &wait);
67704+ return retval;
67705+}
67706+
67707+static unsigned int
67708+poll_learn(struct file * file, poll_table * wait)
67709+{
67710+ poll_wait(file, &learn_wait, wait);
67711+
67712+ if (learn_buffer_len)
67713+ return (POLLIN | POLLRDNORM);
67714+
67715+ return 0;
67716+}
67717+
67718+void
67719+gr_clear_learn_entries(void)
67720+{
67721+ char *tmp;
67722+
67723+ mutex_lock(&gr_learn_user_mutex);
67724+ spin_lock(&gr_learn_lock);
67725+ tmp = learn_buffer;
67726+ learn_buffer = NULL;
67727+ spin_unlock(&gr_learn_lock);
67728+ if (tmp)
67729+ vfree(tmp);
67730+ if (learn_buffer_user != NULL) {
67731+ vfree(learn_buffer_user);
67732+ learn_buffer_user = NULL;
67733+ }
67734+ learn_buffer_len = 0;
67735+ mutex_unlock(&gr_learn_user_mutex);
67736+
67737+ return;
67738+}
67739+
67740+void
67741+gr_add_learn_entry(const char *fmt, ...)
67742+{
67743+ va_list args;
67744+ unsigned int len;
67745+
67746+ if (!gr_learn_attached)
67747+ return;
67748+
67749+ spin_lock(&gr_learn_lock);
67750+
67751+ /* leave a gap at the end so we know when it's "full" but don't have to
67752+ compute the exact length of the string we're trying to append
67753+ */
67754+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67755+ spin_unlock(&gr_learn_lock);
67756+ wake_up_interruptible(&learn_wait);
67757+ return;
67758+ }
67759+ if (learn_buffer == NULL) {
67760+ spin_unlock(&gr_learn_lock);
67761+ return;
67762+ }
67763+
67764+ va_start(args, fmt);
67765+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67766+ va_end(args);
67767+
67768+ learn_buffer_len += len + 1;
67769+
67770+ spin_unlock(&gr_learn_lock);
67771+ wake_up_interruptible(&learn_wait);
67772+
67773+ return;
67774+}
67775+
67776+static int
67777+open_learn(struct inode *inode, struct file *file)
67778+{
67779+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67780+ return -EBUSY;
67781+ if (file->f_mode & FMODE_READ) {
67782+ int retval = 0;
67783+ mutex_lock(&gr_learn_user_mutex);
67784+ if (learn_buffer == NULL)
67785+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67786+ if (learn_buffer_user == NULL)
67787+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67788+ if (learn_buffer == NULL) {
67789+ retval = -ENOMEM;
67790+ goto out_error;
67791+ }
67792+ if (learn_buffer_user == NULL) {
67793+ retval = -ENOMEM;
67794+ goto out_error;
67795+ }
67796+ learn_buffer_len = 0;
67797+ learn_buffer_user_len = 0;
67798+ gr_learn_attached = 1;
67799+out_error:
67800+ mutex_unlock(&gr_learn_user_mutex);
67801+ return retval;
67802+ }
67803+ return 0;
67804+}
67805+
67806+static int
67807+close_learn(struct inode *inode, struct file *file)
67808+{
67809+ if (file->f_mode & FMODE_READ) {
67810+ char *tmp = NULL;
67811+ mutex_lock(&gr_learn_user_mutex);
67812+ spin_lock(&gr_learn_lock);
67813+ tmp = learn_buffer;
67814+ learn_buffer = NULL;
67815+ spin_unlock(&gr_learn_lock);
67816+ if (tmp)
67817+ vfree(tmp);
67818+ if (learn_buffer_user != NULL) {
67819+ vfree(learn_buffer_user);
67820+ learn_buffer_user = NULL;
67821+ }
67822+ learn_buffer_len = 0;
67823+ learn_buffer_user_len = 0;
67824+ gr_learn_attached = 0;
67825+ mutex_unlock(&gr_learn_user_mutex);
67826+ }
67827+
67828+ return 0;
67829+}
67830+
67831+const struct file_operations grsec_fops = {
67832+ .read = read_learn,
67833+ .write = write_grsec_handler,
67834+ .open = open_learn,
67835+ .release = close_learn,
67836+ .poll = poll_learn,
67837+};
67838diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
67839new file mode 100644
67840index 0000000..361a099
67841--- /dev/null
67842+++ b/grsecurity/gracl_policy.c
67843@@ -0,0 +1,1782 @@
67844+#include <linux/kernel.h>
67845+#include <linux/module.h>
67846+#include <linux/sched.h>
67847+#include <linux/mm.h>
67848+#include <linux/file.h>
67849+#include <linux/fs.h>
67850+#include <linux/namei.h>
67851+#include <linux/mount.h>
67852+#include <linux/tty.h>
67853+#include <linux/proc_fs.h>
67854+#include <linux/lglock.h>
67855+#include <linux/slab.h>
67856+#include <linux/vmalloc.h>
67857+#include <linux/types.h>
67858+#include <linux/sysctl.h>
67859+#include <linux/netdevice.h>
67860+#include <linux/ptrace.h>
67861+#include <linux/gracl.h>
67862+#include <linux/gralloc.h>
67863+#include <linux/security.h>
67864+#include <linux/grinternal.h>
67865+#include <linux/pid_namespace.h>
67866+#include <linux/stop_machine.h>
67867+#include <linux/fdtable.h>
67868+#include <linux/percpu.h>
67869+#include <linux/lglock.h>
67870+#include <linux/hugetlb.h>
67871+#include <linux/posix-timers.h>
67872+#include "../fs/mount.h"
67873+
67874+#include <asm/uaccess.h>
67875+#include <asm/errno.h>
67876+#include <asm/mman.h>
67877+
67878+extern struct gr_policy_state *polstate;
67879+
67880+#define FOR_EACH_ROLE_START(role) \
67881+ role = polstate->role_list; \
67882+ while (role) {
67883+
67884+#define FOR_EACH_ROLE_END(role) \
67885+ role = role->prev; \
67886+ }
67887+
67888+struct path gr_real_root;
67889+
67890+extern struct gr_alloc_state *current_alloc_state;
67891+
67892+u16 acl_sp_role_value;
67893+
67894+static DEFINE_MUTEX(gr_dev_mutex);
67895+
67896+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
67897+extern void gr_clear_learn_entries(void);
67898+
67899+static struct gr_arg gr_usermode;
67900+static unsigned char gr_system_salt[GR_SALT_LEN];
67901+static unsigned char gr_system_sum[GR_SHA_LEN];
67902+
67903+static unsigned int gr_auth_attempts = 0;
67904+static unsigned long gr_auth_expires = 0UL;
67905+
67906+struct acl_object_label *fakefs_obj_rw;
67907+struct acl_object_label *fakefs_obj_rwx;
67908+
67909+extern int gr_init_uidset(void);
67910+extern void gr_free_uidset(void);
67911+extern void gr_remove_uid(uid_t uid);
67912+extern int gr_find_uid(uid_t uid);
67913+
67914+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
67915+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
67916+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
67917+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
67918+extern struct acl_role_label *__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid, const gid_t gid);
67919+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
67920+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
67921+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
67922+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
67923+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67924+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67925+extern void assign_special_role(const char *rolename);
67926+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
67927+extern int gr_rbac_disable(void *unused);
67928+extern void gr_enable_rbac_system(void);
67929+
67930+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
67931+{
67932+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
67933+ return -EFAULT;
67934+
67935+ return 0;
67936+}
67937+
67938+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
67939+{
67940+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
67941+ return -EFAULT;
67942+
67943+ return 0;
67944+}
67945+
67946+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
67947+{
67948+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
67949+ return -EFAULT;
67950+
67951+ return 0;
67952+}
67953+
67954+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
67955+{
67956+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
67957+ return -EFAULT;
67958+
67959+ return 0;
67960+}
67961+
67962+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
67963+{
67964+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
67965+ return -EFAULT;
67966+
67967+ return 0;
67968+}
67969+
67970+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
67971+{
67972+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
67973+ return -EFAULT;
67974+
67975+ return 0;
67976+}
67977+
67978+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
67979+{
67980+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
67981+ return -EFAULT;
67982+
67983+ return 0;
67984+}
67985+
67986+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
67987+{
67988+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
67989+ return -EFAULT;
67990+
67991+ return 0;
67992+}
67993+
67994+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
67995+{
67996+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
67997+ return -EFAULT;
67998+
67999+ return 0;
68000+}
68001+
68002+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
68003+{
68004+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
68005+ return -EFAULT;
68006+
68007+ if (((uwrap->version != GRSECURITY_VERSION) &&
68008+ (uwrap->version != 0x2901)) ||
68009+ (uwrap->size != sizeof(struct gr_arg)))
68010+ return -EINVAL;
68011+
68012+ return 0;
68013+}
68014+
68015+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
68016+{
68017+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
68018+ return -EFAULT;
68019+
68020+ return 0;
68021+}
68022+
68023+static size_t get_gr_arg_wrapper_size_normal(void)
68024+{
68025+ return sizeof(struct gr_arg_wrapper);
68026+}
68027+
68028+#ifdef CONFIG_COMPAT
68029+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
68030+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
68031+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
68032+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
68033+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
68034+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
68035+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
68036+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
68037+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
68038+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
68039+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
68040+extern size_t get_gr_arg_wrapper_size_compat(void);
68041+
68042+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
68043+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
68044+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
68045+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
68046+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
68047+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
68048+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
68049+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
68050+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
68051+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
68052+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
68053+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
68054+
68055+#else
68056+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
68057+#define copy_gr_arg copy_gr_arg_normal
68058+#define copy_gr_hash_struct copy_gr_hash_struct_normal
68059+#define copy_acl_object_label copy_acl_object_label_normal
68060+#define copy_acl_subject_label copy_acl_subject_label_normal
68061+#define copy_acl_role_label copy_acl_role_label_normal
68062+#define copy_acl_ip_label copy_acl_ip_label_normal
68063+#define copy_pointer_from_array copy_pointer_from_array_normal
68064+#define copy_sprole_pw copy_sprole_pw_normal
68065+#define copy_role_transition copy_role_transition_normal
68066+#define copy_role_allowed_ip copy_role_allowed_ip_normal
68067+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
68068+#endif
68069+
68070+static struct acl_subject_label *
68071+lookup_subject_map(const struct acl_subject_label *userp)
68072+{
68073+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
68074+ struct subject_map *match;
68075+
68076+ match = polstate->subj_map_set.s_hash[index];
68077+
68078+ while (match && match->user != userp)
68079+ match = match->next;
68080+
68081+ if (match != NULL)
68082+ return match->kernel;
68083+ else
68084+ return NULL;
68085+}
68086+
68087+static void
68088+insert_subj_map_entry(struct subject_map *subjmap)
68089+{
68090+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
68091+ struct subject_map **curr;
68092+
68093+ subjmap->prev = NULL;
68094+
68095+ curr = &polstate->subj_map_set.s_hash[index];
68096+ if (*curr != NULL)
68097+ (*curr)->prev = subjmap;
68098+
68099+ subjmap->next = *curr;
68100+ *curr = subjmap;
68101+
68102+ return;
68103+}
68104+
68105+static void
68106+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
68107+{
68108+ unsigned int index =
68109+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
68110+ struct acl_role_label **curr;
68111+ struct acl_role_label *tmp, *tmp2;
68112+
68113+ curr = &polstate->acl_role_set.r_hash[index];
68114+
68115+ /* simple case, slot is empty, just set it to our role */
68116+ if (*curr == NULL) {
68117+ *curr = role;
68118+ } else {
68119+ /* example:
68120+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
68121+ 2 -> 3
68122+ */
68123+ /* first check to see if we can already be reached via this slot */
68124+ tmp = *curr;
68125+ while (tmp && tmp != role)
68126+ tmp = tmp->next;
68127+ if (tmp == role) {
68128+ /* we don't need to add ourselves to this slot's chain */
68129+ return;
68130+ }
68131+ /* we need to add ourselves to this chain, two cases */
68132+ if (role->next == NULL) {
68133+ /* simple case, append the current chain to our role */
68134+ role->next = *curr;
68135+ *curr = role;
68136+ } else {
68137+ /* 1 -> 2 -> 3 -> 4
68138+ 2 -> 3 -> 4
68139+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
68140+ */
68141+ /* trickier case: walk our role's chain until we find
68142+ the role for the start of the current slot's chain */
68143+ tmp = role;
68144+ tmp2 = *curr;
68145+ while (tmp->next && tmp->next != tmp2)
68146+ tmp = tmp->next;
68147+ if (tmp->next == tmp2) {
68148+ /* from example above, we found 3, so just
68149+ replace this slot's chain with ours */
68150+ *curr = role;
68151+ } else {
68152+ /* we didn't find a subset of our role's chain
68153+ in the current slot's chain, so append their
68154+ chain to ours, and set us as the first role in
68155+ the slot's chain
68156+
68157+ we could fold this case with the case above,
68158+ but making it explicit for clarity
68159+ */
68160+ tmp->next = tmp2;
68161+ *curr = role;
68162+ }
68163+ }
68164+ }
68165+
68166+ return;
68167+}
68168+
68169+static void
68170+insert_acl_role_label(struct acl_role_label *role)
68171+{
68172+ int i;
68173+
68174+ if (polstate->role_list == NULL) {
68175+ polstate->role_list = role;
68176+ role->prev = NULL;
68177+ } else {
68178+ role->prev = polstate->role_list;
68179+ polstate->role_list = role;
68180+ }
68181+
68182+ /* used for hash chains */
68183+ role->next = NULL;
68184+
68185+ if (role->roletype & GR_ROLE_DOMAIN) {
68186+ for (i = 0; i < role->domain_child_num; i++)
68187+ __insert_acl_role_label(role, role->domain_children[i]);
68188+ } else
68189+ __insert_acl_role_label(role, role->uidgid);
68190+}
68191+
68192+static int
68193+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
68194+{
68195+ struct name_entry **curr, *nentry;
68196+ struct inodev_entry *ientry;
68197+ unsigned int len = strlen(name);
68198+ unsigned int key = full_name_hash(name, len);
68199+ unsigned int index = key % polstate->name_set.n_size;
68200+
68201+ curr = &polstate->name_set.n_hash[index];
68202+
68203+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
68204+ curr = &((*curr)->next);
68205+
68206+ if (*curr != NULL)
68207+ return 1;
68208+
68209+ nentry = acl_alloc(sizeof (struct name_entry));
68210+ if (nentry == NULL)
68211+ return 0;
68212+ ientry = acl_alloc(sizeof (struct inodev_entry));
68213+ if (ientry == NULL)
68214+ return 0;
68215+ ientry->nentry = nentry;
68216+
68217+ nentry->key = key;
68218+ nentry->name = name;
68219+ nentry->inode = inode;
68220+ nentry->device = device;
68221+ nentry->len = len;
68222+ nentry->deleted = deleted;
68223+
68224+ nentry->prev = NULL;
68225+ curr = &polstate->name_set.n_hash[index];
68226+ if (*curr != NULL)
68227+ (*curr)->prev = nentry;
68228+ nentry->next = *curr;
68229+ *curr = nentry;
68230+
68231+ /* insert us into the table searchable by inode/dev */
68232+ __insert_inodev_entry(polstate, ientry);
68233+
68234+ return 1;
68235+}
68236+
68237+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
68238+
68239+static void *
68240+create_table(__u32 * len, int elementsize)
68241+{
68242+ unsigned int table_sizes[] = {
68243+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
68244+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
68245+ 4194301, 8388593, 16777213, 33554393, 67108859
68246+ };
68247+ void *newtable = NULL;
68248+ unsigned int pwr = 0;
68249+
68250+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
68251+ table_sizes[pwr] <= *len)
68252+ pwr++;
68253+
68254+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
68255+ return newtable;
68256+
68257+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
68258+ newtable =
68259+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
68260+ else
68261+ newtable = vmalloc(table_sizes[pwr] * elementsize);
68262+
68263+ *len = table_sizes[pwr];
68264+
68265+ return newtable;
68266+}
68267+
68268+static int
68269+init_variables(const struct gr_arg *arg, bool reload)
68270+{
68271+ struct task_struct *reaper = init_pid_ns.child_reaper;
68272+ unsigned int stacksize;
68273+
68274+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
68275+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
68276+ polstate->name_set.n_size = arg->role_db.num_objects;
68277+ polstate->inodev_set.i_size = arg->role_db.num_objects;
68278+
68279+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
68280+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
68281+ return 1;
68282+
68283+ if (!reload) {
68284+ if (!gr_init_uidset())
68285+ return 1;
68286+ }
68287+
68288+ /* set up the stack that holds allocation info */
68289+
68290+ stacksize = arg->role_db.num_pointers + 5;
68291+
68292+ if (!acl_alloc_stack_init(stacksize))
68293+ return 1;
68294+
68295+ if (!reload) {
68296+ /* grab reference for the real root dentry and vfsmount */
68297+ get_fs_root(reaper->fs, &gr_real_root);
68298+
68299+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68300+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(gr_real_root.dentry), gr_real_root.dentry->d_inode->i_ino);
68301+#endif
68302+
68303+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
68304+ if (fakefs_obj_rw == NULL)
68305+ return 1;
68306+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
68307+
68308+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
68309+ if (fakefs_obj_rwx == NULL)
68310+ return 1;
68311+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
68312+ }
68313+
68314+ polstate->subj_map_set.s_hash =
68315+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
68316+ polstate->acl_role_set.r_hash =
68317+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
68318+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
68319+ polstate->inodev_set.i_hash =
68320+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
68321+
68322+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
68323+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
68324+ return 1;
68325+
68326+ memset(polstate->subj_map_set.s_hash, 0,
68327+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
68328+ memset(polstate->acl_role_set.r_hash, 0,
68329+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
68330+ memset(polstate->name_set.n_hash, 0,
68331+ sizeof (struct name_entry *) * polstate->name_set.n_size);
68332+ memset(polstate->inodev_set.i_hash, 0,
68333+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
68334+
68335+ return 0;
68336+}
68337+
68338+/* free information not needed after startup
68339+ currently contains user->kernel pointer mappings for subjects
68340+*/
68341+
68342+static void
68343+free_init_variables(void)
68344+{
68345+ __u32 i;
68346+
68347+ if (polstate->subj_map_set.s_hash) {
68348+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
68349+ if (polstate->subj_map_set.s_hash[i]) {
68350+ kfree(polstate->subj_map_set.s_hash[i]);
68351+ polstate->subj_map_set.s_hash[i] = NULL;
68352+ }
68353+ }
68354+
68355+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
68356+ PAGE_SIZE)
68357+ kfree(polstate->subj_map_set.s_hash);
68358+ else
68359+ vfree(polstate->subj_map_set.s_hash);
68360+ }
68361+
68362+ return;
68363+}
68364+
68365+static void
68366+free_variables(bool reload)
68367+{
68368+ struct acl_subject_label *s;
68369+ struct acl_role_label *r;
68370+ struct task_struct *task, *task2;
68371+ unsigned int x;
68372+
68373+ if (!reload) {
68374+ gr_clear_learn_entries();
68375+
68376+ read_lock(&tasklist_lock);
68377+ do_each_thread(task2, task) {
68378+ task->acl_sp_role = 0;
68379+ task->acl_role_id = 0;
68380+ task->inherited = 0;
68381+ task->acl = NULL;
68382+ task->role = NULL;
68383+ } while_each_thread(task2, task);
68384+ read_unlock(&tasklist_lock);
68385+
68386+ kfree(fakefs_obj_rw);
68387+ fakefs_obj_rw = NULL;
68388+ kfree(fakefs_obj_rwx);
68389+ fakefs_obj_rwx = NULL;
68390+
68391+ /* release the reference to the real root dentry and vfsmount */
68392+ path_put(&gr_real_root);
68393+ memset(&gr_real_root, 0, sizeof(gr_real_root));
68394+ }
68395+
68396+ /* free all object hash tables */
68397+
68398+ FOR_EACH_ROLE_START(r)
68399+ if (r->subj_hash == NULL)
68400+ goto next_role;
68401+ FOR_EACH_SUBJECT_START(r, s, x)
68402+ if (s->obj_hash == NULL)
68403+ break;
68404+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
68405+ kfree(s->obj_hash);
68406+ else
68407+ vfree(s->obj_hash);
68408+ FOR_EACH_SUBJECT_END(s, x)
68409+ FOR_EACH_NESTED_SUBJECT_START(r, s)
68410+ if (s->obj_hash == NULL)
68411+ break;
68412+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
68413+ kfree(s->obj_hash);
68414+ else
68415+ vfree(s->obj_hash);
68416+ FOR_EACH_NESTED_SUBJECT_END(s)
68417+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
68418+ kfree(r->subj_hash);
68419+ else
68420+ vfree(r->subj_hash);
68421+ r->subj_hash = NULL;
68422+next_role:
68423+ FOR_EACH_ROLE_END(r)
68424+
68425+ acl_free_all();
68426+
68427+ if (polstate->acl_role_set.r_hash) {
68428+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
68429+ PAGE_SIZE)
68430+ kfree(polstate->acl_role_set.r_hash);
68431+ else
68432+ vfree(polstate->acl_role_set.r_hash);
68433+ }
68434+ if (polstate->name_set.n_hash) {
68435+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
68436+ PAGE_SIZE)
68437+ kfree(polstate->name_set.n_hash);
68438+ else
68439+ vfree(polstate->name_set.n_hash);
68440+ }
68441+
68442+ if (polstate->inodev_set.i_hash) {
68443+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
68444+ PAGE_SIZE)
68445+ kfree(polstate->inodev_set.i_hash);
68446+ else
68447+ vfree(polstate->inodev_set.i_hash);
68448+ }
68449+
68450+ if (!reload)
68451+ gr_free_uidset();
68452+
68453+ memset(&polstate->name_set, 0, sizeof (struct name_db));
68454+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
68455+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
68456+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
68457+
68458+ polstate->default_role = NULL;
68459+ polstate->kernel_role = NULL;
68460+ polstate->role_list = NULL;
68461+
68462+ return;
68463+}
68464+
68465+static struct acl_subject_label *
68466+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
68467+
68468+static int alloc_and_copy_string(char **name, unsigned int maxlen)
68469+{
68470+ unsigned int len = strnlen_user(*name, maxlen);
68471+ char *tmp;
68472+
68473+ if (!len || len >= maxlen)
68474+ return -EINVAL;
68475+
68476+ if ((tmp = (char *) acl_alloc(len)) == NULL)
68477+ return -ENOMEM;
68478+
68479+ if (copy_from_user(tmp, *name, len))
68480+ return -EFAULT;
68481+
68482+ tmp[len-1] = '\0';
68483+ *name = tmp;
68484+
68485+ return 0;
68486+}
68487+
68488+static int
68489+copy_user_glob(struct acl_object_label *obj)
68490+{
68491+ struct acl_object_label *g_tmp, **guser;
68492+ int error;
68493+
68494+ if (obj->globbed == NULL)
68495+ return 0;
68496+
68497+ guser = &obj->globbed;
68498+ while (*guser) {
68499+ g_tmp = (struct acl_object_label *)
68500+ acl_alloc(sizeof (struct acl_object_label));
68501+ if (g_tmp == NULL)
68502+ return -ENOMEM;
68503+
68504+ if (copy_acl_object_label(g_tmp, *guser))
68505+ return -EFAULT;
68506+
68507+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
68508+ if (error)
68509+ return error;
68510+
68511+ *guser = g_tmp;
68512+ guser = &(g_tmp->next);
68513+ }
68514+
68515+ return 0;
68516+}
68517+
68518+static int
68519+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
68520+ struct acl_role_label *role)
68521+{
68522+ struct acl_object_label *o_tmp;
68523+ int ret;
68524+
68525+ while (userp) {
68526+ if ((o_tmp = (struct acl_object_label *)
68527+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
68528+ return -ENOMEM;
68529+
68530+ if (copy_acl_object_label(o_tmp, userp))
68531+ return -EFAULT;
68532+
68533+ userp = o_tmp->prev;
68534+
68535+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
68536+ if (ret)
68537+ return ret;
68538+
68539+ insert_acl_obj_label(o_tmp, subj);
68540+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
68541+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
68542+ return -ENOMEM;
68543+
68544+ ret = copy_user_glob(o_tmp);
68545+ if (ret)
68546+ return ret;
68547+
68548+ if (o_tmp->nested) {
68549+ int already_copied;
68550+
68551+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
68552+ if (IS_ERR(o_tmp->nested))
68553+ return PTR_ERR(o_tmp->nested);
68554+
68555+ /* insert into nested subject list if we haven't copied this one yet
68556+ to prevent duplicate entries */
68557+ if (!already_copied) {
68558+ o_tmp->nested->next = role->hash->first;
68559+ role->hash->first = o_tmp->nested;
68560+ }
68561+ }
68562+ }
68563+
68564+ return 0;
68565+}
68566+
68567+static __u32
68568+count_user_subjs(struct acl_subject_label *userp)
68569+{
68570+ struct acl_subject_label s_tmp;
68571+ __u32 num = 0;
68572+
68573+ while (userp) {
68574+ if (copy_acl_subject_label(&s_tmp, userp))
68575+ break;
68576+
68577+ userp = s_tmp.prev;
68578+ }
68579+
68580+ return num;
68581+}
68582+
68583+static int
68584+copy_user_allowedips(struct acl_role_label *rolep)
68585+{
68586+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
68587+
68588+ ruserip = rolep->allowed_ips;
68589+
68590+ while (ruserip) {
68591+ rlast = rtmp;
68592+
68593+ if ((rtmp = (struct role_allowed_ip *)
68594+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
68595+ return -ENOMEM;
68596+
68597+ if (copy_role_allowed_ip(rtmp, ruserip))
68598+ return -EFAULT;
68599+
68600+ ruserip = rtmp->prev;
68601+
68602+ if (!rlast) {
68603+ rtmp->prev = NULL;
68604+ rolep->allowed_ips = rtmp;
68605+ } else {
68606+ rlast->next = rtmp;
68607+ rtmp->prev = rlast;
68608+ }
68609+
68610+ if (!ruserip)
68611+ rtmp->next = NULL;
68612+ }
68613+
68614+ return 0;
68615+}
68616+
68617+static int
68618+copy_user_transitions(struct acl_role_label *rolep)
68619+{
68620+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
68621+ int error;
68622+
68623+ rusertp = rolep->transitions;
68624+
68625+ while (rusertp) {
68626+ rlast = rtmp;
68627+
68628+ if ((rtmp = (struct role_transition *)
68629+ acl_alloc(sizeof (struct role_transition))) == NULL)
68630+ return -ENOMEM;
68631+
68632+ if (copy_role_transition(rtmp, rusertp))
68633+ return -EFAULT;
68634+
68635+ rusertp = rtmp->prev;
68636+
68637+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
68638+ if (error)
68639+ return error;
68640+
68641+ if (!rlast) {
68642+ rtmp->prev = NULL;
68643+ rolep->transitions = rtmp;
68644+ } else {
68645+ rlast->next = rtmp;
68646+ rtmp->prev = rlast;
68647+ }
68648+
68649+ if (!rusertp)
68650+ rtmp->next = NULL;
68651+ }
68652+
68653+ return 0;
68654+}
68655+
68656+static __u32 count_user_objs(const struct acl_object_label __user *userp)
68657+{
68658+ struct acl_object_label o_tmp;
68659+ __u32 num = 0;
68660+
68661+ while (userp) {
68662+ if (copy_acl_object_label(&o_tmp, userp))
68663+ break;
68664+
68665+ userp = o_tmp.prev;
68666+ num++;
68667+ }
68668+
68669+ return num;
68670+}
68671+
68672+static struct acl_subject_label *
68673+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
68674+{
68675+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
68676+ __u32 num_objs;
68677+ struct acl_ip_label **i_tmp, *i_utmp2;
68678+ struct gr_hash_struct ghash;
68679+ struct subject_map *subjmap;
68680+ unsigned int i_num;
68681+ int err;
68682+
68683+ if (already_copied != NULL)
68684+ *already_copied = 0;
68685+
68686+ s_tmp = lookup_subject_map(userp);
68687+
68688+ /* we've already copied this subject into the kernel, just return
68689+ the reference to it, and don't copy it over again
68690+ */
68691+ if (s_tmp) {
68692+ if (already_copied != NULL)
68693+ *already_copied = 1;
68694+ return(s_tmp);
68695+ }
68696+
68697+ if ((s_tmp = (struct acl_subject_label *)
68698+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
68699+ return ERR_PTR(-ENOMEM);
68700+
68701+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
68702+ if (subjmap == NULL)
68703+ return ERR_PTR(-ENOMEM);
68704+
68705+ subjmap->user = userp;
68706+ subjmap->kernel = s_tmp;
68707+ insert_subj_map_entry(subjmap);
68708+
68709+ if (copy_acl_subject_label(s_tmp, userp))
68710+ return ERR_PTR(-EFAULT);
68711+
68712+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
68713+ if (err)
68714+ return ERR_PTR(err);
68715+
68716+ if (!strcmp(s_tmp->filename, "/"))
68717+ role->root_label = s_tmp;
68718+
68719+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
68720+ return ERR_PTR(-EFAULT);
68721+
68722+ /* copy user and group transition tables */
68723+
68724+ if (s_tmp->user_trans_num) {
68725+ uid_t *uidlist;
68726+
68727+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
68728+ if (uidlist == NULL)
68729+ return ERR_PTR(-ENOMEM);
68730+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
68731+ return ERR_PTR(-EFAULT);
68732+
68733+ s_tmp->user_transitions = uidlist;
68734+ }
68735+
68736+ if (s_tmp->group_trans_num) {
68737+ gid_t *gidlist;
68738+
68739+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
68740+ if (gidlist == NULL)
68741+ return ERR_PTR(-ENOMEM);
68742+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
68743+ return ERR_PTR(-EFAULT);
68744+
68745+ s_tmp->group_transitions = gidlist;
68746+ }
68747+
68748+ /* set up object hash table */
68749+ num_objs = count_user_objs(ghash.first);
68750+
68751+ s_tmp->obj_hash_size = num_objs;
68752+ s_tmp->obj_hash =
68753+ (struct acl_object_label **)
68754+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
68755+
68756+ if (!s_tmp->obj_hash)
68757+ return ERR_PTR(-ENOMEM);
68758+
68759+ memset(s_tmp->obj_hash, 0,
68760+ s_tmp->obj_hash_size *
68761+ sizeof (struct acl_object_label *));
68762+
68763+ /* add in objects */
68764+ err = copy_user_objs(ghash.first, s_tmp, role);
68765+
68766+ if (err)
68767+ return ERR_PTR(err);
68768+
68769+ /* set pointer for parent subject */
68770+ if (s_tmp->parent_subject) {
68771+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
68772+
68773+ if (IS_ERR(s_tmp2))
68774+ return s_tmp2;
68775+
68776+ s_tmp->parent_subject = s_tmp2;
68777+ }
68778+
68779+ /* add in ip acls */
68780+
68781+ if (!s_tmp->ip_num) {
68782+ s_tmp->ips = NULL;
68783+ goto insert;
68784+ }
68785+
68786+ i_tmp =
68787+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
68788+ sizeof (struct acl_ip_label *));
68789+
68790+ if (!i_tmp)
68791+ return ERR_PTR(-ENOMEM);
68792+
68793+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
68794+ *(i_tmp + i_num) =
68795+ (struct acl_ip_label *)
68796+ acl_alloc(sizeof (struct acl_ip_label));
68797+ if (!*(i_tmp + i_num))
68798+ return ERR_PTR(-ENOMEM);
68799+
68800+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
68801+ return ERR_PTR(-EFAULT);
68802+
68803+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
68804+ return ERR_PTR(-EFAULT);
68805+
68806+ if ((*(i_tmp + i_num))->iface == NULL)
68807+ continue;
68808+
68809+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
68810+ if (err)
68811+ return ERR_PTR(err);
68812+ }
68813+
68814+ s_tmp->ips = i_tmp;
68815+
68816+insert:
68817+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
68818+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
68819+ return ERR_PTR(-ENOMEM);
68820+
68821+ return s_tmp;
68822+}
68823+
68824+static int
68825+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
68826+{
68827+ struct acl_subject_label s_pre;
68828+ struct acl_subject_label * ret;
68829+ int err;
68830+
68831+ while (userp) {
68832+ if (copy_acl_subject_label(&s_pre, userp))
68833+ return -EFAULT;
68834+
68835+ ret = do_copy_user_subj(userp, role, NULL);
68836+
68837+ err = PTR_ERR(ret);
68838+ if (IS_ERR(ret))
68839+ return err;
68840+
68841+ insert_acl_subj_label(ret, role);
68842+
68843+ userp = s_pre.prev;
68844+ }
68845+
68846+ return 0;
68847+}
68848+
68849+static int
68850+copy_user_acl(struct gr_arg *arg)
68851+{
68852+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
68853+ struct acl_subject_label *subj_list;
68854+ struct sprole_pw *sptmp;
68855+ struct gr_hash_struct *ghash;
68856+ uid_t *domainlist;
68857+ unsigned int r_num;
68858+ int err = 0;
68859+ __u16 i;
68860+ __u32 num_subjs;
68861+
68862+ /* we need a default and kernel role */
68863+ if (arg->role_db.num_roles < 2)
68864+ return -EINVAL;
68865+
68866+ /* copy special role authentication info from userspace */
68867+
68868+ polstate->num_sprole_pws = arg->num_sprole_pws;
68869+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
68870+
68871+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
68872+ return -ENOMEM;
68873+
68874+ for (i = 0; i < polstate->num_sprole_pws; i++) {
68875+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
68876+ if (!sptmp)
68877+ return -ENOMEM;
68878+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
68879+ return -EFAULT;
68880+
68881+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
68882+ if (err)
68883+ return err;
68884+
68885+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68886+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
68887+#endif
68888+
68889+ polstate->acl_special_roles[i] = sptmp;
68890+ }
68891+
68892+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
68893+
68894+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
68895+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
68896+
68897+ if (!r_tmp)
68898+ return -ENOMEM;
68899+
68900+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
68901+ return -EFAULT;
68902+
68903+ if (copy_acl_role_label(r_tmp, r_utmp2))
68904+ return -EFAULT;
68905+
68906+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
68907+ if (err)
68908+ return err;
68909+
68910+ if (!strcmp(r_tmp->rolename, "default")
68911+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
68912+ polstate->default_role = r_tmp;
68913+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
68914+ polstate->kernel_role = r_tmp;
68915+ }
68916+
68917+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
68918+ return -ENOMEM;
68919+
68920+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
68921+ return -EFAULT;
68922+
68923+ r_tmp->hash = ghash;
68924+
68925+ num_subjs = count_user_subjs(r_tmp->hash->first);
68926+
68927+ r_tmp->subj_hash_size = num_subjs;
68928+ r_tmp->subj_hash =
68929+ (struct acl_subject_label **)
68930+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
68931+
68932+ if (!r_tmp->subj_hash)
68933+ return -ENOMEM;
68934+
68935+ err = copy_user_allowedips(r_tmp);
68936+ if (err)
68937+ return err;
68938+
68939+ /* copy domain info */
68940+ if (r_tmp->domain_children != NULL) {
68941+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
68942+ if (domainlist == NULL)
68943+ return -ENOMEM;
68944+
68945+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
68946+ return -EFAULT;
68947+
68948+ r_tmp->domain_children = domainlist;
68949+ }
68950+
68951+ err = copy_user_transitions(r_tmp);
68952+ if (err)
68953+ return err;
68954+
68955+ memset(r_tmp->subj_hash, 0,
68956+ r_tmp->subj_hash_size *
68957+ sizeof (struct acl_subject_label *));
68958+
68959+ /* acquire the list of subjects, then NULL out
68960+ the list prior to parsing the subjects for this role,
68961+ as during this parsing the list is replaced with a list
68962+ of *nested* subjects for the role
68963+ */
68964+ subj_list = r_tmp->hash->first;
68965+
68966+ /* set nested subject list to null */
68967+ r_tmp->hash->first = NULL;
68968+
68969+ err = copy_user_subjs(subj_list, r_tmp);
68970+
68971+ if (err)
68972+ return err;
68973+
68974+ insert_acl_role_label(r_tmp);
68975+ }
68976+
68977+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
68978+ return -EINVAL;
68979+
68980+ return err;
68981+}
68982+
68983+static int gracl_reload_apply_policies(void *reload)
68984+{
68985+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
68986+ struct task_struct *task, *task2;
68987+ struct acl_role_label *role, *rtmp;
68988+ struct acl_subject_label *subj;
68989+ const struct cred *cred;
68990+ int role_applied;
68991+ int ret = 0;
68992+
68993+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
68994+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
68995+
68996+ /* first make sure we'll be able to apply the new policy cleanly */
68997+ do_each_thread(task2, task) {
68998+ if (task->exec_file == NULL)
68999+ continue;
69000+ role_applied = 0;
69001+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
69002+ /* preserve special roles */
69003+ FOR_EACH_ROLE_START(role)
69004+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
69005+ rtmp = task->role;
69006+ task->role = role;
69007+ role_applied = 1;
69008+ break;
69009+ }
69010+ FOR_EACH_ROLE_END(role)
69011+ }
69012+ if (!role_applied) {
69013+ cred = __task_cred(task);
69014+ rtmp = task->role;
69015+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69016+ }
69017+ /* this handles non-nested inherited subjects, nested subjects will still
69018+ be dropped currently */
69019+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
69020+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
69021+ /* change the role back so that we've made no modifications to the policy */
69022+ task->role = rtmp;
69023+
69024+ if (subj == NULL || task->tmpacl == NULL) {
69025+ ret = -EINVAL;
69026+ goto out;
69027+ }
69028+ } while_each_thread(task2, task);
69029+
69030+ /* now actually apply the policy */
69031+
69032+ do_each_thread(task2, task) {
69033+ if (task->exec_file) {
69034+ role_applied = 0;
69035+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
69036+ /* preserve special roles */
69037+ FOR_EACH_ROLE_START(role)
69038+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
69039+ task->role = role;
69040+ role_applied = 1;
69041+ break;
69042+ }
69043+ FOR_EACH_ROLE_END(role)
69044+ }
69045+ if (!role_applied) {
69046+ cred = __task_cred(task);
69047+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69048+ }
69049+ /* this handles non-nested inherited subjects, nested subjects will still
69050+ be dropped currently */
69051+ if (!reload_state->oldmode && task->inherited)
69052+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
69053+ else {
69054+ /* looked up and tagged to the task previously */
69055+ subj = task->tmpacl;
69056+ }
69057+ /* subj will be non-null */
69058+ __gr_apply_subject_to_task(polstate, task, subj);
69059+ if (reload_state->oldmode) {
69060+ task->acl_role_id = 0;
69061+ task->acl_sp_role = 0;
69062+ task->inherited = 0;
69063+ }
69064+ } else {
69065+ // it's a kernel process
69066+ task->role = polstate->kernel_role;
69067+ task->acl = polstate->kernel_role->root_label;
69068+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
69069+ task->acl->mode &= ~GR_PROCFIND;
69070+#endif
69071+ }
69072+ } while_each_thread(task2, task);
69073+
69074+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
69075+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
69076+
69077+out:
69078+
69079+ return ret;
69080+}
69081+
69082+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
69083+{
69084+ struct gr_reload_state new_reload_state = { };
69085+ int err;
69086+
69087+ new_reload_state.oldpolicy_ptr = polstate;
69088+ new_reload_state.oldalloc_ptr = current_alloc_state;
69089+ new_reload_state.oldmode = oldmode;
69090+
69091+ current_alloc_state = &new_reload_state.newalloc;
69092+ polstate = &new_reload_state.newpolicy;
69093+
69094+ /* everything relevant is now saved off, copy in the new policy */
69095+ if (init_variables(args, true)) {
69096+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
69097+ err = -ENOMEM;
69098+ goto error;
69099+ }
69100+
69101+ err = copy_user_acl(args);
69102+ free_init_variables();
69103+ if (err)
69104+ goto error;
69105+ /* the new policy is copied in, with the old policy available via saved_state
69106+ first go through applying roles, making sure to preserve special roles
69107+ then apply new subjects, making sure to preserve inherited and nested subjects,
69108+ though currently only inherited subjects will be preserved
69109+ */
69110+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
69111+ if (err)
69112+ goto error;
69113+
69114+ /* we've now applied the new policy, so restore the old policy state to free it */
69115+ polstate = &new_reload_state.oldpolicy;
69116+ current_alloc_state = &new_reload_state.oldalloc;
69117+ free_variables(true);
69118+
69119+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
69120+ to running_polstate/current_alloc_state inside stop_machine
69121+ */
69122+ err = 0;
69123+ goto out;
69124+error:
69125+ /* on error of loading the new policy, we'll just keep the previous
69126+ policy set around
69127+ */
69128+ free_variables(true);
69129+
69130+ /* doesn't affect runtime, but maintains consistent state */
69131+out:
69132+ polstate = new_reload_state.oldpolicy_ptr;
69133+ current_alloc_state = new_reload_state.oldalloc_ptr;
69134+
69135+ return err;
69136+}
69137+
69138+static int
69139+gracl_init(struct gr_arg *args)
69140+{
69141+ int error = 0;
69142+
69143+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
69144+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
69145+
69146+ if (init_variables(args, false)) {
69147+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
69148+ error = -ENOMEM;
69149+ goto out;
69150+ }
69151+
69152+ error = copy_user_acl(args);
69153+ free_init_variables();
69154+ if (error)
69155+ goto out;
69156+
69157+ error = gr_set_acls(0);
69158+ if (error)
69159+ goto out;
69160+
69161+ gr_enable_rbac_system();
69162+
69163+ return 0;
69164+
69165+out:
69166+ free_variables(false);
69167+ return error;
69168+}
69169+
69170+static int
69171+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
69172+ unsigned char **sum)
69173+{
69174+ struct acl_role_label *r;
69175+ struct role_allowed_ip *ipp;
69176+ struct role_transition *trans;
69177+ unsigned int i;
69178+ int found = 0;
69179+ u32 curr_ip = current->signal->curr_ip;
69180+
69181+ current->signal->saved_ip = curr_ip;
69182+
69183+ /* check transition table */
69184+
69185+ for (trans = current->role->transitions; trans; trans = trans->next) {
69186+ if (!strcmp(rolename, trans->rolename)) {
69187+ found = 1;
69188+ break;
69189+ }
69190+ }
69191+
69192+ if (!found)
69193+ return 0;
69194+
69195+ /* handle special roles that do not require authentication
69196+ and check ip */
69197+
69198+ FOR_EACH_ROLE_START(r)
69199+ if (!strcmp(rolename, r->rolename) &&
69200+ (r->roletype & GR_ROLE_SPECIAL)) {
69201+ found = 0;
69202+ if (r->allowed_ips != NULL) {
69203+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
69204+ if ((ntohl(curr_ip) & ipp->netmask) ==
69205+ (ntohl(ipp->addr) & ipp->netmask))
69206+ found = 1;
69207+ }
69208+ } else
69209+ found = 2;
69210+ if (!found)
69211+ return 0;
69212+
69213+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
69214+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
69215+ *salt = NULL;
69216+ *sum = NULL;
69217+ return 1;
69218+ }
69219+ }
69220+ FOR_EACH_ROLE_END(r)
69221+
69222+ for (i = 0; i < polstate->num_sprole_pws; i++) {
69223+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
69224+ *salt = polstate->acl_special_roles[i]->salt;
69225+ *sum = polstate->acl_special_roles[i]->sum;
69226+ return 1;
69227+ }
69228+ }
69229+
69230+ return 0;
69231+}
69232+
69233+int gr_check_secure_terminal(struct task_struct *task)
69234+{
69235+ struct task_struct *p, *p2, *p3;
69236+ struct files_struct *files;
69237+ struct fdtable *fdt;
69238+ struct file *our_file = NULL, *file;
69239+ int i;
69240+
69241+ if (task->signal->tty == NULL)
69242+ return 1;
69243+
69244+ files = get_files_struct(task);
69245+ if (files != NULL) {
69246+ rcu_read_lock();
69247+ fdt = files_fdtable(files);
69248+ for (i=0; i < fdt->max_fds; i++) {
69249+ file = fcheck_files(files, i);
69250+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
69251+ get_file(file);
69252+ our_file = file;
69253+ }
69254+ }
69255+ rcu_read_unlock();
69256+ put_files_struct(files);
69257+ }
69258+
69259+ if (our_file == NULL)
69260+ return 1;
69261+
69262+ read_lock(&tasklist_lock);
69263+ do_each_thread(p2, p) {
69264+ files = get_files_struct(p);
69265+ if (files == NULL ||
69266+ (p->signal && p->signal->tty == task->signal->tty)) {
69267+ if (files != NULL)
69268+ put_files_struct(files);
69269+ continue;
69270+ }
69271+ rcu_read_lock();
69272+ fdt = files_fdtable(files);
69273+ for (i=0; i < fdt->max_fds; i++) {
69274+ file = fcheck_files(files, i);
69275+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
69276+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
69277+ p3 = task;
69278+ while (task_pid_nr(p3) > 0) {
69279+ if (p3 == p)
69280+ break;
69281+ p3 = p3->real_parent;
69282+ }
69283+ if (p3 == p)
69284+ break;
69285+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
69286+ gr_handle_alertkill(p);
69287+ rcu_read_unlock();
69288+ put_files_struct(files);
69289+ read_unlock(&tasklist_lock);
69290+ fput(our_file);
69291+ return 0;
69292+ }
69293+ }
69294+ rcu_read_unlock();
69295+ put_files_struct(files);
69296+ } while_each_thread(p2, p);
69297+ read_unlock(&tasklist_lock);
69298+
69299+ fput(our_file);
69300+ return 1;
69301+}
69302+
69303+ssize_t
69304+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
69305+{
69306+ struct gr_arg_wrapper uwrap;
69307+ unsigned char *sprole_salt = NULL;
69308+ unsigned char *sprole_sum = NULL;
69309+ int error = 0;
69310+ int error2 = 0;
69311+ size_t req_count = 0;
69312+ unsigned char oldmode = 0;
69313+
69314+ mutex_lock(&gr_dev_mutex);
69315+
69316+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
69317+ error = -EPERM;
69318+ goto out;
69319+ }
69320+
69321+#ifdef CONFIG_COMPAT
69322+ pax_open_kernel();
69323+ if (is_compat_task()) {
69324+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
69325+ copy_gr_arg = &copy_gr_arg_compat;
69326+ copy_acl_object_label = &copy_acl_object_label_compat;
69327+ copy_acl_subject_label = &copy_acl_subject_label_compat;
69328+ copy_acl_role_label = &copy_acl_role_label_compat;
69329+ copy_acl_ip_label = &copy_acl_ip_label_compat;
69330+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
69331+ copy_role_transition = &copy_role_transition_compat;
69332+ copy_sprole_pw = &copy_sprole_pw_compat;
69333+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
69334+ copy_pointer_from_array = &copy_pointer_from_array_compat;
69335+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
69336+ } else {
69337+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
69338+ copy_gr_arg = &copy_gr_arg_normal;
69339+ copy_acl_object_label = &copy_acl_object_label_normal;
69340+ copy_acl_subject_label = &copy_acl_subject_label_normal;
69341+ copy_acl_role_label = &copy_acl_role_label_normal;
69342+ copy_acl_ip_label = &copy_acl_ip_label_normal;
69343+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
69344+ copy_role_transition = &copy_role_transition_normal;
69345+ copy_sprole_pw = &copy_sprole_pw_normal;
69346+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
69347+ copy_pointer_from_array = &copy_pointer_from_array_normal;
69348+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
69349+ }
69350+ pax_close_kernel();
69351+#endif
69352+
69353+ req_count = get_gr_arg_wrapper_size();
69354+
69355+ if (count != req_count) {
69356+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
69357+ error = -EINVAL;
69358+ goto out;
69359+ }
69360+
69361+
69362+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
69363+ gr_auth_expires = 0;
69364+ gr_auth_attempts = 0;
69365+ }
69366+
69367+ error = copy_gr_arg_wrapper(buf, &uwrap);
69368+ if (error)
69369+ goto out;
69370+
69371+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
69372+ if (error)
69373+ goto out;
69374+
69375+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
69376+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
69377+ time_after(gr_auth_expires, get_seconds())) {
69378+ error = -EBUSY;
69379+ goto out;
69380+ }
69381+
69382+ /* if non-root trying to do anything other than use a special role,
69383+ do not attempt authentication, do not count towards authentication
69384+ locking
69385+ */
69386+
69387+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
69388+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
69389+ gr_is_global_nonroot(current_uid())) {
69390+ error = -EPERM;
69391+ goto out;
69392+ }
69393+
69394+ /* ensure pw and special role name are null terminated */
69395+
69396+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
69397+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
69398+
69399+ /* Okay.
69400+ * We have our enough of the argument structure..(we have yet
69401+ * to copy_from_user the tables themselves) . Copy the tables
69402+ * only if we need them, i.e. for loading operations. */
69403+
69404+ switch (gr_usermode.mode) {
69405+ case GR_STATUS:
69406+ if (gr_acl_is_enabled()) {
69407+ error = 1;
69408+ if (!gr_check_secure_terminal(current))
69409+ error = 3;
69410+ } else
69411+ error = 2;
69412+ goto out;
69413+ case GR_SHUTDOWN:
69414+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69415+ stop_machine(gr_rbac_disable, NULL, NULL);
69416+ free_variables(false);
69417+ memset(&gr_usermode, 0, sizeof(gr_usermode));
69418+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
69419+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
69420+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
69421+ } else if (gr_acl_is_enabled()) {
69422+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
69423+ error = -EPERM;
69424+ } else {
69425+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
69426+ error = -EAGAIN;
69427+ }
69428+ break;
69429+ case GR_ENABLE:
69430+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
69431+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
69432+ else {
69433+ if (gr_acl_is_enabled())
69434+ error = -EAGAIN;
69435+ else
69436+ error = error2;
69437+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
69438+ }
69439+ break;
69440+ case GR_OLDRELOAD:
69441+ oldmode = 1;
69442+ case GR_RELOAD:
69443+ if (!gr_acl_is_enabled()) {
69444+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
69445+ error = -EAGAIN;
69446+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69447+ error2 = gracl_reload(&gr_usermode, oldmode);
69448+ if (!error2)
69449+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
69450+ else {
69451+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
69452+ error = error2;
69453+ }
69454+ } else {
69455+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
69456+ error = -EPERM;
69457+ }
69458+ break;
69459+ case GR_SEGVMOD:
69460+ if (unlikely(!gr_acl_is_enabled())) {
69461+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
69462+ error = -EAGAIN;
69463+ break;
69464+ }
69465+
69466+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
69467+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
69468+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
69469+ struct acl_subject_label *segvacl;
69470+ segvacl =
69471+ lookup_acl_subj_label(gr_usermode.segv_inode,
69472+ gr_usermode.segv_device,
69473+ current->role);
69474+ if (segvacl) {
69475+ segvacl->crashes = 0;
69476+ segvacl->expires = 0;
69477+ }
69478+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
69479+ gr_remove_uid(gr_usermode.segv_uid);
69480+ }
69481+ } else {
69482+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
69483+ error = -EPERM;
69484+ }
69485+ break;
69486+ case GR_SPROLE:
69487+ case GR_SPROLEPAM:
69488+ if (unlikely(!gr_acl_is_enabled())) {
69489+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
69490+ error = -EAGAIN;
69491+ break;
69492+ }
69493+
69494+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
69495+ current->role->expires = 0;
69496+ current->role->auth_attempts = 0;
69497+ }
69498+
69499+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
69500+ time_after(current->role->expires, get_seconds())) {
69501+ error = -EBUSY;
69502+ goto out;
69503+ }
69504+
69505+ if (lookup_special_role_auth
69506+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
69507+ && ((!sprole_salt && !sprole_sum)
69508+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
69509+ char *p = "";
69510+ assign_special_role(gr_usermode.sp_role);
69511+ read_lock(&tasklist_lock);
69512+ if (current->real_parent)
69513+ p = current->real_parent->role->rolename;
69514+ read_unlock(&tasklist_lock);
69515+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
69516+ p, acl_sp_role_value);
69517+ } else {
69518+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
69519+ error = -EPERM;
69520+ if(!(current->role->auth_attempts++))
69521+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
69522+
69523+ goto out;
69524+ }
69525+ break;
69526+ case GR_UNSPROLE:
69527+ if (unlikely(!gr_acl_is_enabled())) {
69528+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
69529+ error = -EAGAIN;
69530+ break;
69531+ }
69532+
69533+ if (current->role->roletype & GR_ROLE_SPECIAL) {
69534+ char *p = "";
69535+ int i = 0;
69536+
69537+ read_lock(&tasklist_lock);
69538+ if (current->real_parent) {
69539+ p = current->real_parent->role->rolename;
69540+ i = current->real_parent->acl_role_id;
69541+ }
69542+ read_unlock(&tasklist_lock);
69543+
69544+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
69545+ gr_set_acls(1);
69546+ } else {
69547+ error = -EPERM;
69548+ goto out;
69549+ }
69550+ break;
69551+ default:
69552+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
69553+ error = -EINVAL;
69554+ break;
69555+ }
69556+
69557+ if (error != -EPERM)
69558+ goto out;
69559+
69560+ if(!(gr_auth_attempts++))
69561+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
69562+
69563+ out:
69564+ mutex_unlock(&gr_dev_mutex);
69565+
69566+ if (!error)
69567+ error = req_count;
69568+
69569+ return error;
69570+}
69571+
69572+int
69573+gr_set_acls(const int type)
69574+{
69575+ struct task_struct *task, *task2;
69576+ struct acl_role_label *role = current->role;
69577+ struct acl_subject_label *subj;
69578+ __u16 acl_role_id = current->acl_role_id;
69579+ const struct cred *cred;
69580+ int ret;
69581+
69582+ rcu_read_lock();
69583+ read_lock(&tasklist_lock);
69584+ read_lock(&grsec_exec_file_lock);
69585+ do_each_thread(task2, task) {
69586+ /* check to see if we're called from the exit handler,
69587+ if so, only replace ACLs that have inherited the admin
69588+ ACL */
69589+
69590+ if (type && (task->role != role ||
69591+ task->acl_role_id != acl_role_id))
69592+ continue;
69593+
69594+ task->acl_role_id = 0;
69595+ task->acl_sp_role = 0;
69596+ task->inherited = 0;
69597+
69598+ if (task->exec_file) {
69599+ cred = __task_cred(task);
69600+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
69601+ subj = __gr_get_subject_for_task(polstate, task, NULL);
69602+ if (subj == NULL) {
69603+ ret = -EINVAL;
69604+ read_unlock(&grsec_exec_file_lock);
69605+ read_unlock(&tasklist_lock);
69606+ rcu_read_unlock();
69607+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
69608+ return ret;
69609+ }
69610+ __gr_apply_subject_to_task(polstate, task, subj);
69611+ } else {
69612+ // it's a kernel process
69613+ task->role = polstate->kernel_role;
69614+ task->acl = polstate->kernel_role->root_label;
69615+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
69616+ task->acl->mode &= ~GR_PROCFIND;
69617+#endif
69618+ }
69619+ } while_each_thread(task2, task);
69620+ read_unlock(&grsec_exec_file_lock);
69621+ read_unlock(&tasklist_lock);
69622+ rcu_read_unlock();
69623+
69624+ return 0;
69625+}
69626diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
69627new file mode 100644
69628index 0000000..39645c9
69629--- /dev/null
69630+++ b/grsecurity/gracl_res.c
69631@@ -0,0 +1,68 @@
69632+#include <linux/kernel.h>
69633+#include <linux/sched.h>
69634+#include <linux/gracl.h>
69635+#include <linux/grinternal.h>
69636+
69637+static const char *restab_log[] = {
69638+ [RLIMIT_CPU] = "RLIMIT_CPU",
69639+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
69640+ [RLIMIT_DATA] = "RLIMIT_DATA",
69641+ [RLIMIT_STACK] = "RLIMIT_STACK",
69642+ [RLIMIT_CORE] = "RLIMIT_CORE",
69643+ [RLIMIT_RSS] = "RLIMIT_RSS",
69644+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
69645+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
69646+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
69647+ [RLIMIT_AS] = "RLIMIT_AS",
69648+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
69649+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
69650+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
69651+ [RLIMIT_NICE] = "RLIMIT_NICE",
69652+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
69653+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
69654+ [GR_CRASH_RES] = "RLIMIT_CRASH"
69655+};
69656+
69657+void
69658+gr_log_resource(const struct task_struct *task,
69659+ const int res, const unsigned long wanted, const int gt)
69660+{
69661+ const struct cred *cred;
69662+ unsigned long rlim;
69663+
69664+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
69665+ return;
69666+
69667+ // not yet supported resource
69668+ if (unlikely(!restab_log[res]))
69669+ return;
69670+
69671+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
69672+ rlim = task_rlimit_max(task, res);
69673+ else
69674+ rlim = task_rlimit(task, res);
69675+
69676+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
69677+ return;
69678+
69679+ rcu_read_lock();
69680+ cred = __task_cred(task);
69681+
69682+ if (res == RLIMIT_NPROC &&
69683+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
69684+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
69685+ goto out_rcu_unlock;
69686+ else if (res == RLIMIT_MEMLOCK &&
69687+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
69688+ goto out_rcu_unlock;
69689+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
69690+ goto out_rcu_unlock;
69691+ rcu_read_unlock();
69692+
69693+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
69694+
69695+ return;
69696+out_rcu_unlock:
69697+ rcu_read_unlock();
69698+ return;
69699+}
69700diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
69701new file mode 100644
69702index 0000000..2040e61
69703--- /dev/null
69704+++ b/grsecurity/gracl_segv.c
69705@@ -0,0 +1,313 @@
69706+#include <linux/kernel.h>
69707+#include <linux/mm.h>
69708+#include <asm/uaccess.h>
69709+#include <asm/errno.h>
69710+#include <asm/mman.h>
69711+#include <net/sock.h>
69712+#include <linux/file.h>
69713+#include <linux/fs.h>
69714+#include <linux/net.h>
69715+#include <linux/in.h>
69716+#include <linux/slab.h>
69717+#include <linux/types.h>
69718+#include <linux/sched.h>
69719+#include <linux/timer.h>
69720+#include <linux/gracl.h>
69721+#include <linux/grsecurity.h>
69722+#include <linux/grinternal.h>
69723+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69724+#include <linux/magic.h>
69725+#include <linux/pagemap.h>
69726+#include "../fs/btrfs/async-thread.h"
69727+#include "../fs/btrfs/ctree.h"
69728+#include "../fs/btrfs/btrfs_inode.h"
69729+#endif
69730+
69731+static struct crash_uid *uid_set;
69732+static unsigned short uid_used;
69733+static DEFINE_SPINLOCK(gr_uid_lock);
69734+extern rwlock_t gr_inode_lock;
69735+extern struct acl_subject_label *
69736+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
69737+ struct acl_role_label *role);
69738+
69739+static inline dev_t __get_dev(const struct dentry *dentry)
69740+{
69741+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69742+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69743+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69744+ else
69745+#endif
69746+ return dentry->d_sb->s_dev;
69747+}
69748+
69749+int
69750+gr_init_uidset(void)
69751+{
69752+ uid_set =
69753+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
69754+ uid_used = 0;
69755+
69756+ return uid_set ? 1 : 0;
69757+}
69758+
69759+void
69760+gr_free_uidset(void)
69761+{
69762+ if (uid_set) {
69763+ struct crash_uid *tmpset;
69764+ spin_lock(&gr_uid_lock);
69765+ tmpset = uid_set;
69766+ uid_set = NULL;
69767+ uid_used = 0;
69768+ spin_unlock(&gr_uid_lock);
69769+ if (tmpset)
69770+ kfree(tmpset);
69771+ }
69772+
69773+ return;
69774+}
69775+
69776+int
69777+gr_find_uid(const uid_t uid)
69778+{
69779+ struct crash_uid *tmp = uid_set;
69780+ uid_t buid;
69781+ int low = 0, high = uid_used - 1, mid;
69782+
69783+ while (high >= low) {
69784+ mid = (low + high) >> 1;
69785+ buid = tmp[mid].uid;
69786+ if (buid == uid)
69787+ return mid;
69788+ if (buid > uid)
69789+ high = mid - 1;
69790+ if (buid < uid)
69791+ low = mid + 1;
69792+ }
69793+
69794+ return -1;
69795+}
69796+
69797+static __inline__ void
69798+gr_insertsort(void)
69799+{
69800+ unsigned short i, j;
69801+ struct crash_uid index;
69802+
69803+ for (i = 1; i < uid_used; i++) {
69804+ index = uid_set[i];
69805+ j = i;
69806+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
69807+ uid_set[j] = uid_set[j - 1];
69808+ j--;
69809+ }
69810+ uid_set[j] = index;
69811+ }
69812+
69813+ return;
69814+}
69815+
69816+static __inline__ void
69817+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
69818+{
69819+ int loc;
69820+ uid_t uid = GR_GLOBAL_UID(kuid);
69821+
69822+ if (uid_used == GR_UIDTABLE_MAX)
69823+ return;
69824+
69825+ loc = gr_find_uid(uid);
69826+
69827+ if (loc >= 0) {
69828+ uid_set[loc].expires = expires;
69829+ return;
69830+ }
69831+
69832+ uid_set[uid_used].uid = uid;
69833+ uid_set[uid_used].expires = expires;
69834+ uid_used++;
69835+
69836+ gr_insertsort();
69837+
69838+ return;
69839+}
69840+
69841+void
69842+gr_remove_uid(const unsigned short loc)
69843+{
69844+ unsigned short i;
69845+
69846+ for (i = loc + 1; i < uid_used; i++)
69847+ uid_set[i - 1] = uid_set[i];
69848+
69849+ uid_used--;
69850+
69851+ return;
69852+}
69853+
69854+int
69855+gr_check_crash_uid(const kuid_t kuid)
69856+{
69857+ int loc;
69858+ int ret = 0;
69859+ uid_t uid;
69860+
69861+ if (unlikely(!gr_acl_is_enabled()))
69862+ return 0;
69863+
69864+ uid = GR_GLOBAL_UID(kuid);
69865+
69866+ spin_lock(&gr_uid_lock);
69867+ loc = gr_find_uid(uid);
69868+
69869+ if (loc < 0)
69870+ goto out_unlock;
69871+
69872+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69873+ gr_remove_uid(loc);
69874+ else
69875+ ret = 1;
69876+
69877+out_unlock:
69878+ spin_unlock(&gr_uid_lock);
69879+ return ret;
69880+}
69881+
69882+static __inline__ int
69883+proc_is_setxid(const struct cred *cred)
69884+{
69885+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69886+ !uid_eq(cred->uid, cred->fsuid))
69887+ return 1;
69888+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69889+ !gid_eq(cred->gid, cred->fsgid))
69890+ return 1;
69891+
69892+ return 0;
69893+}
69894+
69895+extern int gr_fake_force_sig(int sig, struct task_struct *t);
69896+
69897+void
69898+gr_handle_crash(struct task_struct *task, const int sig)
69899+{
69900+ struct acl_subject_label *curr;
69901+ struct task_struct *tsk, *tsk2;
69902+ const struct cred *cred;
69903+ const struct cred *cred2;
69904+
69905+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
69906+ return;
69907+
69908+ if (unlikely(!gr_acl_is_enabled()))
69909+ return;
69910+
69911+ curr = task->acl;
69912+
69913+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
69914+ return;
69915+
69916+ if (time_before_eq(curr->expires, get_seconds())) {
69917+ curr->expires = 0;
69918+ curr->crashes = 0;
69919+ }
69920+
69921+ curr->crashes++;
69922+
69923+ if (!curr->expires)
69924+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
69925+
69926+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69927+ time_after(curr->expires, get_seconds())) {
69928+ rcu_read_lock();
69929+ cred = __task_cred(task);
69930+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
69931+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69932+ spin_lock(&gr_uid_lock);
69933+ gr_insert_uid(cred->uid, curr->expires);
69934+ spin_unlock(&gr_uid_lock);
69935+ curr->expires = 0;
69936+ curr->crashes = 0;
69937+ read_lock(&tasklist_lock);
69938+ do_each_thread(tsk2, tsk) {
69939+ cred2 = __task_cred(tsk);
69940+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
69941+ gr_fake_force_sig(SIGKILL, tsk);
69942+ } while_each_thread(tsk2, tsk);
69943+ read_unlock(&tasklist_lock);
69944+ } else {
69945+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69946+ read_lock(&tasklist_lock);
69947+ read_lock(&grsec_exec_file_lock);
69948+ do_each_thread(tsk2, tsk) {
69949+ if (likely(tsk != task)) {
69950+ // if this thread has the same subject as the one that triggered
69951+ // RES_CRASH and it's the same binary, kill it
69952+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
69953+ gr_fake_force_sig(SIGKILL, tsk);
69954+ }
69955+ } while_each_thread(tsk2, tsk);
69956+ read_unlock(&grsec_exec_file_lock);
69957+ read_unlock(&tasklist_lock);
69958+ }
69959+ rcu_read_unlock();
69960+ }
69961+
69962+ return;
69963+}
69964+
69965+int
69966+gr_check_crash_exec(const struct file *filp)
69967+{
69968+ struct acl_subject_label *curr;
69969+
69970+ if (unlikely(!gr_acl_is_enabled()))
69971+ return 0;
69972+
69973+ read_lock(&gr_inode_lock);
69974+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
69975+ __get_dev(filp->f_path.dentry),
69976+ current->role);
69977+ read_unlock(&gr_inode_lock);
69978+
69979+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
69980+ (!curr->crashes && !curr->expires))
69981+ return 0;
69982+
69983+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69984+ time_after(curr->expires, get_seconds()))
69985+ return 1;
69986+ else if (time_before_eq(curr->expires, get_seconds())) {
69987+ curr->crashes = 0;
69988+ curr->expires = 0;
69989+ }
69990+
69991+ return 0;
69992+}
69993+
69994+void
69995+gr_handle_alertkill(struct task_struct *task)
69996+{
69997+ struct acl_subject_label *curracl;
69998+ __u32 curr_ip;
69999+ struct task_struct *p, *p2;
70000+
70001+ if (unlikely(!gr_acl_is_enabled()))
70002+ return;
70003+
70004+ curracl = task->acl;
70005+ curr_ip = task->signal->curr_ip;
70006+
70007+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
70008+ read_lock(&tasklist_lock);
70009+ do_each_thread(p2, p) {
70010+ if (p->signal->curr_ip == curr_ip)
70011+ gr_fake_force_sig(SIGKILL, p);
70012+ } while_each_thread(p2, p);
70013+ read_unlock(&tasklist_lock);
70014+ } else if (curracl->mode & GR_KILLPROC)
70015+ gr_fake_force_sig(SIGKILL, task);
70016+
70017+ return;
70018+}
70019diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
70020new file mode 100644
70021index 0000000..98011b0
70022--- /dev/null
70023+++ b/grsecurity/gracl_shm.c
70024@@ -0,0 +1,40 @@
70025+#include <linux/kernel.h>
70026+#include <linux/mm.h>
70027+#include <linux/sched.h>
70028+#include <linux/file.h>
70029+#include <linux/ipc.h>
70030+#include <linux/gracl.h>
70031+#include <linux/grsecurity.h>
70032+#include <linux/grinternal.h>
70033+
70034+int
70035+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70036+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70037+{
70038+ struct task_struct *task;
70039+
70040+ if (!gr_acl_is_enabled())
70041+ return 1;
70042+
70043+ rcu_read_lock();
70044+ read_lock(&tasklist_lock);
70045+
70046+ task = find_task_by_vpid(shm_cprid);
70047+
70048+ if (unlikely(!task))
70049+ task = find_task_by_vpid(shm_lapid);
70050+
70051+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
70052+ (task_pid_nr(task) == shm_lapid)) &&
70053+ (task->acl->mode & GR_PROTSHM) &&
70054+ (task->acl != current->acl))) {
70055+ read_unlock(&tasklist_lock);
70056+ rcu_read_unlock();
70057+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
70058+ return 0;
70059+ }
70060+ read_unlock(&tasklist_lock);
70061+ rcu_read_unlock();
70062+
70063+ return 1;
70064+}
70065diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
70066new file mode 100644
70067index 0000000..bc0be01
70068--- /dev/null
70069+++ b/grsecurity/grsec_chdir.c
70070@@ -0,0 +1,19 @@
70071+#include <linux/kernel.h>
70072+#include <linux/sched.h>
70073+#include <linux/fs.h>
70074+#include <linux/file.h>
70075+#include <linux/grsecurity.h>
70076+#include <linux/grinternal.h>
70077+
70078+void
70079+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
70080+{
70081+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70082+ if ((grsec_enable_chdir && grsec_enable_group &&
70083+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
70084+ !grsec_enable_group)) {
70085+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
70086+ }
70087+#endif
70088+ return;
70089+}
70090diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
70091new file mode 100644
70092index 0000000..e10b319
70093--- /dev/null
70094+++ b/grsecurity/grsec_chroot.c
70095@@ -0,0 +1,370 @@
70096+#include <linux/kernel.h>
70097+#include <linux/module.h>
70098+#include <linux/sched.h>
70099+#include <linux/file.h>
70100+#include <linux/fs.h>
70101+#include <linux/mount.h>
70102+#include <linux/types.h>
70103+#include "../fs/mount.h"
70104+#include <linux/grsecurity.h>
70105+#include <linux/grinternal.h>
70106+
70107+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70108+int gr_init_ran;
70109+#endif
70110+
70111+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
70112+{
70113+#ifdef CONFIG_GRKERNSEC
70114+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
70115+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
70116+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70117+ && gr_init_ran
70118+#endif
70119+ )
70120+ task->gr_is_chrooted = 1;
70121+ else {
70122+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
70123+ if (task_pid_nr(task) == 1 && !gr_init_ran)
70124+ gr_init_ran = 1;
70125+#endif
70126+ task->gr_is_chrooted = 0;
70127+ }
70128+
70129+ task->gr_chroot_dentry = path->dentry;
70130+#endif
70131+ return;
70132+}
70133+
70134+void gr_clear_chroot_entries(struct task_struct *task)
70135+{
70136+#ifdef CONFIG_GRKERNSEC
70137+ task->gr_is_chrooted = 0;
70138+ task->gr_chroot_dentry = NULL;
70139+#endif
70140+ return;
70141+}
70142+
70143+int
70144+gr_handle_chroot_unix(const pid_t pid)
70145+{
70146+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70147+ struct task_struct *p;
70148+
70149+ if (unlikely(!grsec_enable_chroot_unix))
70150+ return 1;
70151+
70152+ if (likely(!proc_is_chrooted(current)))
70153+ return 1;
70154+
70155+ rcu_read_lock();
70156+ read_lock(&tasklist_lock);
70157+ p = find_task_by_vpid_unrestricted(pid);
70158+ if (unlikely(p && !have_same_root(current, p))) {
70159+ read_unlock(&tasklist_lock);
70160+ rcu_read_unlock();
70161+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
70162+ return 0;
70163+ }
70164+ read_unlock(&tasklist_lock);
70165+ rcu_read_unlock();
70166+#endif
70167+ return 1;
70168+}
70169+
70170+int
70171+gr_handle_chroot_nice(void)
70172+{
70173+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70174+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
70175+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
70176+ return -EPERM;
70177+ }
70178+#endif
70179+ return 0;
70180+}
70181+
70182+int
70183+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
70184+{
70185+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70186+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
70187+ && proc_is_chrooted(current)) {
70188+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
70189+ return -EACCES;
70190+ }
70191+#endif
70192+ return 0;
70193+}
70194+
70195+int
70196+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
70197+{
70198+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70199+ struct task_struct *p;
70200+ int ret = 0;
70201+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
70202+ return ret;
70203+
70204+ read_lock(&tasklist_lock);
70205+ do_each_pid_task(pid, type, p) {
70206+ if (!have_same_root(current, p)) {
70207+ ret = 1;
70208+ goto out;
70209+ }
70210+ } while_each_pid_task(pid, type, p);
70211+out:
70212+ read_unlock(&tasklist_lock);
70213+ return ret;
70214+#endif
70215+ return 0;
70216+}
70217+
70218+int
70219+gr_pid_is_chrooted(struct task_struct *p)
70220+{
70221+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70222+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
70223+ return 0;
70224+
70225+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
70226+ !have_same_root(current, p)) {
70227+ return 1;
70228+ }
70229+#endif
70230+ return 0;
70231+}
70232+
70233+EXPORT_SYMBOL(gr_pid_is_chrooted);
70234+
70235+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
70236+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
70237+{
70238+ struct path path, currentroot;
70239+ int ret = 0;
70240+
70241+ path.dentry = (struct dentry *)u_dentry;
70242+ path.mnt = (struct vfsmount *)u_mnt;
70243+ get_fs_root(current->fs, &currentroot);
70244+ if (path_is_under(&path, &currentroot))
70245+ ret = 1;
70246+ path_put(&currentroot);
70247+
70248+ return ret;
70249+}
70250+#endif
70251+
70252+int
70253+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
70254+{
70255+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70256+ if (!grsec_enable_chroot_fchdir)
70257+ return 1;
70258+
70259+ if (!proc_is_chrooted(current))
70260+ return 1;
70261+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
70262+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
70263+ return 0;
70264+ }
70265+#endif
70266+ return 1;
70267+}
70268+
70269+int
70270+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70271+ const time_t shm_createtime)
70272+{
70273+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70274+ struct task_struct *p;
70275+ time_t starttime;
70276+
70277+ if (unlikely(!grsec_enable_chroot_shmat))
70278+ return 1;
70279+
70280+ if (likely(!proc_is_chrooted(current)))
70281+ return 1;
70282+
70283+ rcu_read_lock();
70284+ read_lock(&tasklist_lock);
70285+
70286+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
70287+ starttime = p->start_time.tv_sec;
70288+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
70289+ if (have_same_root(current, p)) {
70290+ goto allow;
70291+ } else {
70292+ read_unlock(&tasklist_lock);
70293+ rcu_read_unlock();
70294+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
70295+ return 0;
70296+ }
70297+ }
70298+ /* creator exited, pid reuse, fall through to next check */
70299+ }
70300+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
70301+ if (unlikely(!have_same_root(current, p))) {
70302+ read_unlock(&tasklist_lock);
70303+ rcu_read_unlock();
70304+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
70305+ return 0;
70306+ }
70307+ }
70308+
70309+allow:
70310+ read_unlock(&tasklist_lock);
70311+ rcu_read_unlock();
70312+#endif
70313+ return 1;
70314+}
70315+
70316+void
70317+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
70318+{
70319+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70320+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
70321+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
70322+#endif
70323+ return;
70324+}
70325+
70326+int
70327+gr_handle_chroot_mknod(const struct dentry *dentry,
70328+ const struct vfsmount *mnt, const int mode)
70329+{
70330+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70331+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
70332+ proc_is_chrooted(current)) {
70333+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
70334+ return -EPERM;
70335+ }
70336+#endif
70337+ return 0;
70338+}
70339+
70340+int
70341+gr_handle_chroot_mount(const struct dentry *dentry,
70342+ const struct vfsmount *mnt, const char *dev_name)
70343+{
70344+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70345+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
70346+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
70347+ return -EPERM;
70348+ }
70349+#endif
70350+ return 0;
70351+}
70352+
70353+int
70354+gr_handle_chroot_pivot(void)
70355+{
70356+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70357+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
70358+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
70359+ return -EPERM;
70360+ }
70361+#endif
70362+ return 0;
70363+}
70364+
70365+int
70366+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
70367+{
70368+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70369+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
70370+ !gr_is_outside_chroot(dentry, mnt)) {
70371+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
70372+ return -EPERM;
70373+ }
70374+#endif
70375+ return 0;
70376+}
70377+
70378+extern const char *captab_log[];
70379+extern int captab_log_entries;
70380+
70381+int
70382+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70383+{
70384+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70385+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
70386+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
70387+ if (cap_raised(chroot_caps, cap)) {
70388+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
70389+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
70390+ }
70391+ return 0;
70392+ }
70393+ }
70394+#endif
70395+ return 1;
70396+}
70397+
70398+int
70399+gr_chroot_is_capable(const int cap)
70400+{
70401+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70402+ return gr_task_chroot_is_capable(current, current_cred(), cap);
70403+#endif
70404+ return 1;
70405+}
70406+
70407+int
70408+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
70409+{
70410+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70411+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
70412+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
70413+ if (cap_raised(chroot_caps, cap)) {
70414+ return 0;
70415+ }
70416+ }
70417+#endif
70418+ return 1;
70419+}
70420+
70421+int
70422+gr_chroot_is_capable_nolog(const int cap)
70423+{
70424+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70425+ return gr_task_chroot_is_capable_nolog(current, cap);
70426+#endif
70427+ return 1;
70428+}
70429+
70430+int
70431+gr_handle_chroot_sysctl(const int op)
70432+{
70433+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70434+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
70435+ proc_is_chrooted(current))
70436+ return -EACCES;
70437+#endif
70438+ return 0;
70439+}
70440+
70441+void
70442+gr_handle_chroot_chdir(const struct path *path)
70443+{
70444+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70445+ if (grsec_enable_chroot_chdir)
70446+ set_fs_pwd(current->fs, path);
70447+#endif
70448+ return;
70449+}
70450+
70451+int
70452+gr_handle_chroot_chmod(const struct dentry *dentry,
70453+ const struct vfsmount *mnt, const int mode)
70454+{
70455+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70456+ /* allow chmod +s on directories, but not files */
70457+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
70458+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
70459+ proc_is_chrooted(current)) {
70460+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
70461+ return -EPERM;
70462+ }
70463+#endif
70464+ return 0;
70465+}
70466diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
70467new file mode 100644
70468index 0000000..0866ab2
70469--- /dev/null
70470+++ b/grsecurity/grsec_disabled.c
70471@@ -0,0 +1,427 @@
70472+#include <linux/kernel.h>
70473+#include <linux/module.h>
70474+#include <linux/sched.h>
70475+#include <linux/file.h>
70476+#include <linux/fs.h>
70477+#include <linux/kdev_t.h>
70478+#include <linux/net.h>
70479+#include <linux/in.h>
70480+#include <linux/ip.h>
70481+#include <linux/skbuff.h>
70482+#include <linux/sysctl.h>
70483+
70484+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70485+void
70486+pax_set_initial_flags(struct linux_binprm *bprm)
70487+{
70488+ return;
70489+}
70490+#endif
70491+
70492+#ifdef CONFIG_SYSCTL
70493+__u32
70494+gr_handle_sysctl(const struct ctl_table * table, const int op)
70495+{
70496+ return 0;
70497+}
70498+#endif
70499+
70500+#ifdef CONFIG_TASKSTATS
70501+int gr_is_taskstats_denied(int pid)
70502+{
70503+ return 0;
70504+}
70505+#endif
70506+
70507+int
70508+gr_acl_is_enabled(void)
70509+{
70510+ return 0;
70511+}
70512+
70513+void
70514+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
70515+{
70516+ return;
70517+}
70518+
70519+int
70520+gr_handle_rawio(const struct inode *inode)
70521+{
70522+ return 0;
70523+}
70524+
70525+void
70526+gr_acl_handle_psacct(struct task_struct *task, const long code)
70527+{
70528+ return;
70529+}
70530+
70531+int
70532+gr_handle_ptrace(struct task_struct *task, const long request)
70533+{
70534+ return 0;
70535+}
70536+
70537+int
70538+gr_handle_proc_ptrace(struct task_struct *task)
70539+{
70540+ return 0;
70541+}
70542+
70543+int
70544+gr_set_acls(const int type)
70545+{
70546+ return 0;
70547+}
70548+
70549+int
70550+gr_check_hidden_task(const struct task_struct *tsk)
70551+{
70552+ return 0;
70553+}
70554+
70555+int
70556+gr_check_protected_task(const struct task_struct *task)
70557+{
70558+ return 0;
70559+}
70560+
70561+int
70562+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70563+{
70564+ return 0;
70565+}
70566+
70567+void
70568+gr_copy_label(struct task_struct *tsk)
70569+{
70570+ return;
70571+}
70572+
70573+void
70574+gr_set_pax_flags(struct task_struct *task)
70575+{
70576+ return;
70577+}
70578+
70579+int
70580+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70581+ const int unsafe_share)
70582+{
70583+ return 0;
70584+}
70585+
70586+void
70587+gr_handle_delete(const ino_t ino, const dev_t dev)
70588+{
70589+ return;
70590+}
70591+
70592+void
70593+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
70594+{
70595+ return;
70596+}
70597+
70598+void
70599+gr_handle_crash(struct task_struct *task, const int sig)
70600+{
70601+ return;
70602+}
70603+
70604+int
70605+gr_check_crash_exec(const struct file *filp)
70606+{
70607+ return 0;
70608+}
70609+
70610+int
70611+gr_check_crash_uid(const kuid_t uid)
70612+{
70613+ return 0;
70614+}
70615+
70616+void
70617+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70618+ struct dentry *old_dentry,
70619+ struct dentry *new_dentry,
70620+ struct vfsmount *mnt, const __u8 replace)
70621+{
70622+ return;
70623+}
70624+
70625+int
70626+gr_search_socket(const int family, const int type, const int protocol)
70627+{
70628+ return 1;
70629+}
70630+
70631+int
70632+gr_search_connectbind(const int mode, const struct socket *sock,
70633+ const struct sockaddr_in *addr)
70634+{
70635+ return 0;
70636+}
70637+
70638+void
70639+gr_handle_alertkill(struct task_struct *task)
70640+{
70641+ return;
70642+}
70643+
70644+__u32
70645+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
70646+{
70647+ return 1;
70648+}
70649+
70650+__u32
70651+gr_acl_handle_hidden_file(const struct dentry * dentry,
70652+ const struct vfsmount * mnt)
70653+{
70654+ return 1;
70655+}
70656+
70657+__u32
70658+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70659+ int acc_mode)
70660+{
70661+ return 1;
70662+}
70663+
70664+__u32
70665+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70666+{
70667+ return 1;
70668+}
70669+
70670+__u32
70671+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
70672+{
70673+ return 1;
70674+}
70675+
70676+int
70677+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
70678+ unsigned int *vm_flags)
70679+{
70680+ return 1;
70681+}
70682+
70683+__u32
70684+gr_acl_handle_truncate(const struct dentry * dentry,
70685+ const struct vfsmount * mnt)
70686+{
70687+ return 1;
70688+}
70689+
70690+__u32
70691+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
70692+{
70693+ return 1;
70694+}
70695+
70696+__u32
70697+gr_acl_handle_access(const struct dentry * dentry,
70698+ const struct vfsmount * mnt, const int fmode)
70699+{
70700+ return 1;
70701+}
70702+
70703+__u32
70704+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
70705+ umode_t *mode)
70706+{
70707+ return 1;
70708+}
70709+
70710+__u32
70711+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
70712+{
70713+ return 1;
70714+}
70715+
70716+__u32
70717+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
70718+{
70719+ return 1;
70720+}
70721+
70722+void
70723+grsecurity_init(void)
70724+{
70725+ return;
70726+}
70727+
70728+umode_t gr_acl_umask(void)
70729+{
70730+ return 0;
70731+}
70732+
70733+__u32
70734+gr_acl_handle_mknod(const struct dentry * new_dentry,
70735+ const struct dentry * parent_dentry,
70736+ const struct vfsmount * parent_mnt,
70737+ const int mode)
70738+{
70739+ return 1;
70740+}
70741+
70742+__u32
70743+gr_acl_handle_mkdir(const struct dentry * new_dentry,
70744+ const struct dentry * parent_dentry,
70745+ const struct vfsmount * parent_mnt)
70746+{
70747+ return 1;
70748+}
70749+
70750+__u32
70751+gr_acl_handle_symlink(const struct dentry * new_dentry,
70752+ const struct dentry * parent_dentry,
70753+ const struct vfsmount * parent_mnt, const struct filename *from)
70754+{
70755+ return 1;
70756+}
70757+
70758+__u32
70759+gr_acl_handle_link(const struct dentry * new_dentry,
70760+ const struct dentry * parent_dentry,
70761+ const struct vfsmount * parent_mnt,
70762+ const struct dentry * old_dentry,
70763+ const struct vfsmount * old_mnt, const struct filename *to)
70764+{
70765+ return 1;
70766+}
70767+
70768+int
70769+gr_acl_handle_rename(const struct dentry *new_dentry,
70770+ const struct dentry *parent_dentry,
70771+ const struct vfsmount *parent_mnt,
70772+ const struct dentry *old_dentry,
70773+ const struct inode *old_parent_inode,
70774+ const struct vfsmount *old_mnt, const struct filename *newname)
70775+{
70776+ return 0;
70777+}
70778+
70779+int
70780+gr_acl_handle_filldir(const struct file *file, const char *name,
70781+ const int namelen, const ino_t ino)
70782+{
70783+ return 1;
70784+}
70785+
70786+int
70787+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70788+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70789+{
70790+ return 1;
70791+}
70792+
70793+int
70794+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
70795+{
70796+ return 0;
70797+}
70798+
70799+int
70800+gr_search_accept(const struct socket *sock)
70801+{
70802+ return 0;
70803+}
70804+
70805+int
70806+gr_search_listen(const struct socket *sock)
70807+{
70808+ return 0;
70809+}
70810+
70811+int
70812+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
70813+{
70814+ return 0;
70815+}
70816+
70817+__u32
70818+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
70819+{
70820+ return 1;
70821+}
70822+
70823+__u32
70824+gr_acl_handle_creat(const struct dentry * dentry,
70825+ const struct dentry * p_dentry,
70826+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70827+ const int imode)
70828+{
70829+ return 1;
70830+}
70831+
70832+void
70833+gr_acl_handle_exit(void)
70834+{
70835+ return;
70836+}
70837+
70838+int
70839+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
70840+{
70841+ return 1;
70842+}
70843+
70844+void
70845+gr_set_role_label(const kuid_t uid, const kgid_t gid)
70846+{
70847+ return;
70848+}
70849+
70850+int
70851+gr_acl_handle_procpidmem(const struct task_struct *task)
70852+{
70853+ return 0;
70854+}
70855+
70856+int
70857+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
70858+{
70859+ return 0;
70860+}
70861+
70862+int
70863+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70864+{
70865+ return 0;
70866+}
70867+
70868+int
70869+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70870+{
70871+ return 0;
70872+}
70873+
70874+int
70875+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70876+{
70877+ return 0;
70878+}
70879+
70880+int gr_acl_enable_at_secure(void)
70881+{
70882+ return 0;
70883+}
70884+
70885+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70886+{
70887+ return dentry->d_sb->s_dev;
70888+}
70889+
70890+void gr_put_exec_file(struct task_struct *task)
70891+{
70892+ return;
70893+}
70894+
70895+#ifdef CONFIG_SECURITY
70896+EXPORT_SYMBOL(gr_check_user_change);
70897+EXPORT_SYMBOL(gr_check_group_change);
70898+#endif
70899diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
70900new file mode 100644
70901index 0000000..387032b
70902--- /dev/null
70903+++ b/grsecurity/grsec_exec.c
70904@@ -0,0 +1,187 @@
70905+#include <linux/kernel.h>
70906+#include <linux/sched.h>
70907+#include <linux/file.h>
70908+#include <linux/binfmts.h>
70909+#include <linux/fs.h>
70910+#include <linux/types.h>
70911+#include <linux/grdefs.h>
70912+#include <linux/grsecurity.h>
70913+#include <linux/grinternal.h>
70914+#include <linux/capability.h>
70915+#include <linux/module.h>
70916+#include <linux/compat.h>
70917+
70918+#include <asm/uaccess.h>
70919+
70920+#ifdef CONFIG_GRKERNSEC_EXECLOG
70921+static char gr_exec_arg_buf[132];
70922+static DEFINE_MUTEX(gr_exec_arg_mutex);
70923+#endif
70924+
70925+struct user_arg_ptr {
70926+#ifdef CONFIG_COMPAT
70927+ bool is_compat;
70928+#endif
70929+ union {
70930+ const char __user *const __user *native;
70931+#ifdef CONFIG_COMPAT
70932+ const compat_uptr_t __user *compat;
70933+#endif
70934+ } ptr;
70935+};
70936+
70937+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
70938+
70939+void
70940+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
70941+{
70942+#ifdef CONFIG_GRKERNSEC_EXECLOG
70943+ char *grarg = gr_exec_arg_buf;
70944+ unsigned int i, x, execlen = 0;
70945+ char c;
70946+
70947+ if (!((grsec_enable_execlog && grsec_enable_group &&
70948+ in_group_p(grsec_audit_gid))
70949+ || (grsec_enable_execlog && !grsec_enable_group)))
70950+ return;
70951+
70952+ mutex_lock(&gr_exec_arg_mutex);
70953+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
70954+
70955+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
70956+ const char __user *p;
70957+ unsigned int len;
70958+
70959+ p = get_user_arg_ptr(argv, i);
70960+ if (IS_ERR(p))
70961+ goto log;
70962+
70963+ len = strnlen_user(p, 128 - execlen);
70964+ if (len > 128 - execlen)
70965+ len = 128 - execlen;
70966+ else if (len > 0)
70967+ len--;
70968+ if (copy_from_user(grarg + execlen, p, len))
70969+ goto log;
70970+
70971+ /* rewrite unprintable characters */
70972+ for (x = 0; x < len; x++) {
70973+ c = *(grarg + execlen + x);
70974+ if (c < 32 || c > 126)
70975+ *(grarg + execlen + x) = ' ';
70976+ }
70977+
70978+ execlen += len;
70979+ *(grarg + execlen) = ' ';
70980+ *(grarg + execlen + 1) = '\0';
70981+ execlen++;
70982+ }
70983+
70984+ log:
70985+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
70986+ bprm->file->f_path.mnt, grarg);
70987+ mutex_unlock(&gr_exec_arg_mutex);
70988+#endif
70989+ return;
70990+}
70991+
70992+#ifdef CONFIG_GRKERNSEC
70993+extern int gr_acl_is_capable(const int cap);
70994+extern int gr_acl_is_capable_nolog(const int cap);
70995+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70996+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
70997+extern int gr_chroot_is_capable(const int cap);
70998+extern int gr_chroot_is_capable_nolog(const int cap);
70999+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
71000+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
71001+#endif
71002+
71003+const char *captab_log[] = {
71004+ "CAP_CHOWN",
71005+ "CAP_DAC_OVERRIDE",
71006+ "CAP_DAC_READ_SEARCH",
71007+ "CAP_FOWNER",
71008+ "CAP_FSETID",
71009+ "CAP_KILL",
71010+ "CAP_SETGID",
71011+ "CAP_SETUID",
71012+ "CAP_SETPCAP",
71013+ "CAP_LINUX_IMMUTABLE",
71014+ "CAP_NET_BIND_SERVICE",
71015+ "CAP_NET_BROADCAST",
71016+ "CAP_NET_ADMIN",
71017+ "CAP_NET_RAW",
71018+ "CAP_IPC_LOCK",
71019+ "CAP_IPC_OWNER",
71020+ "CAP_SYS_MODULE",
71021+ "CAP_SYS_RAWIO",
71022+ "CAP_SYS_CHROOT",
71023+ "CAP_SYS_PTRACE",
71024+ "CAP_SYS_PACCT",
71025+ "CAP_SYS_ADMIN",
71026+ "CAP_SYS_BOOT",
71027+ "CAP_SYS_NICE",
71028+ "CAP_SYS_RESOURCE",
71029+ "CAP_SYS_TIME",
71030+ "CAP_SYS_TTY_CONFIG",
71031+ "CAP_MKNOD",
71032+ "CAP_LEASE",
71033+ "CAP_AUDIT_WRITE",
71034+ "CAP_AUDIT_CONTROL",
71035+ "CAP_SETFCAP",
71036+ "CAP_MAC_OVERRIDE",
71037+ "CAP_MAC_ADMIN",
71038+ "CAP_SYSLOG",
71039+ "CAP_WAKE_ALARM"
71040+};
71041+
71042+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
71043+
71044+int gr_is_capable(const int cap)
71045+{
71046+#ifdef CONFIG_GRKERNSEC
71047+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
71048+ return 1;
71049+ return 0;
71050+#else
71051+ return 1;
71052+#endif
71053+}
71054+
71055+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
71056+{
71057+#ifdef CONFIG_GRKERNSEC
71058+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
71059+ return 1;
71060+ return 0;
71061+#else
71062+ return 1;
71063+#endif
71064+}
71065+
71066+int gr_is_capable_nolog(const int cap)
71067+{
71068+#ifdef CONFIG_GRKERNSEC
71069+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
71070+ return 1;
71071+ return 0;
71072+#else
71073+ return 1;
71074+#endif
71075+}
71076+
71077+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
71078+{
71079+#ifdef CONFIG_GRKERNSEC
71080+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
71081+ return 1;
71082+ return 0;
71083+#else
71084+ return 1;
71085+#endif
71086+}
71087+
71088+EXPORT_SYMBOL(gr_is_capable);
71089+EXPORT_SYMBOL(gr_is_capable_nolog);
71090+EXPORT_SYMBOL(gr_task_is_capable);
71091+EXPORT_SYMBOL(gr_task_is_capable_nolog);
71092diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
71093new file mode 100644
71094index 0000000..06cc6ea
71095--- /dev/null
71096+++ b/grsecurity/grsec_fifo.c
71097@@ -0,0 +1,24 @@
71098+#include <linux/kernel.h>
71099+#include <linux/sched.h>
71100+#include <linux/fs.h>
71101+#include <linux/file.h>
71102+#include <linux/grinternal.h>
71103+
71104+int
71105+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
71106+ const struct dentry *dir, const int flag, const int acc_mode)
71107+{
71108+#ifdef CONFIG_GRKERNSEC_FIFO
71109+ const struct cred *cred = current_cred();
71110+
71111+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
71112+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
71113+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
71114+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
71115+ if (!inode_permission(dentry->d_inode, acc_mode))
71116+ 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));
71117+ return -EACCES;
71118+ }
71119+#endif
71120+ return 0;
71121+}
71122diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
71123new file mode 100644
71124index 0000000..8ca18bf
71125--- /dev/null
71126+++ b/grsecurity/grsec_fork.c
71127@@ -0,0 +1,23 @@
71128+#include <linux/kernel.h>
71129+#include <linux/sched.h>
71130+#include <linux/grsecurity.h>
71131+#include <linux/grinternal.h>
71132+#include <linux/errno.h>
71133+
71134+void
71135+gr_log_forkfail(const int retval)
71136+{
71137+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71138+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
71139+ switch (retval) {
71140+ case -EAGAIN:
71141+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
71142+ break;
71143+ case -ENOMEM:
71144+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
71145+ break;
71146+ }
71147+ }
71148+#endif
71149+ return;
71150+}
71151diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
71152new file mode 100644
71153index 0000000..a88e901
71154--- /dev/null
71155+++ b/grsecurity/grsec_init.c
71156@@ -0,0 +1,272 @@
71157+#include <linux/kernel.h>
71158+#include <linux/sched.h>
71159+#include <linux/mm.h>
71160+#include <linux/gracl.h>
71161+#include <linux/slab.h>
71162+#include <linux/vmalloc.h>
71163+#include <linux/percpu.h>
71164+#include <linux/module.h>
71165+
71166+int grsec_enable_ptrace_readexec;
71167+int grsec_enable_setxid;
71168+int grsec_enable_symlinkown;
71169+kgid_t grsec_symlinkown_gid;
71170+int grsec_enable_brute;
71171+int grsec_enable_link;
71172+int grsec_enable_dmesg;
71173+int grsec_enable_harden_ptrace;
71174+int grsec_enable_harden_ipc;
71175+int grsec_enable_fifo;
71176+int grsec_enable_execlog;
71177+int grsec_enable_signal;
71178+int grsec_enable_forkfail;
71179+int grsec_enable_audit_ptrace;
71180+int grsec_enable_time;
71181+int grsec_enable_group;
71182+kgid_t grsec_audit_gid;
71183+int grsec_enable_chdir;
71184+int grsec_enable_mount;
71185+int grsec_enable_rofs;
71186+int grsec_deny_new_usb;
71187+int grsec_enable_chroot_findtask;
71188+int grsec_enable_chroot_mount;
71189+int grsec_enable_chroot_shmat;
71190+int grsec_enable_chroot_fchdir;
71191+int grsec_enable_chroot_double;
71192+int grsec_enable_chroot_pivot;
71193+int grsec_enable_chroot_chdir;
71194+int grsec_enable_chroot_chmod;
71195+int grsec_enable_chroot_mknod;
71196+int grsec_enable_chroot_nice;
71197+int grsec_enable_chroot_execlog;
71198+int grsec_enable_chroot_caps;
71199+int grsec_enable_chroot_sysctl;
71200+int grsec_enable_chroot_unix;
71201+int grsec_enable_tpe;
71202+kgid_t grsec_tpe_gid;
71203+int grsec_enable_blackhole;
71204+#ifdef CONFIG_IPV6_MODULE
71205+EXPORT_SYMBOL(grsec_enable_blackhole);
71206+#endif
71207+int grsec_lastack_retries;
71208+int grsec_enable_tpe_all;
71209+int grsec_enable_tpe_invert;
71210+int grsec_enable_socket_all;
71211+kgid_t grsec_socket_all_gid;
71212+int grsec_enable_socket_client;
71213+kgid_t grsec_socket_client_gid;
71214+int grsec_enable_socket_server;
71215+kgid_t grsec_socket_server_gid;
71216+int grsec_resource_logging;
71217+int grsec_disable_privio;
71218+int grsec_enable_log_rwxmaps;
71219+int grsec_lock;
71220+
71221+DEFINE_SPINLOCK(grsec_alert_lock);
71222+unsigned long grsec_alert_wtime = 0;
71223+unsigned long grsec_alert_fyet = 0;
71224+
71225+DEFINE_SPINLOCK(grsec_audit_lock);
71226+
71227+DEFINE_RWLOCK(grsec_exec_file_lock);
71228+
71229+char *gr_shared_page[4];
71230+
71231+char *gr_alert_log_fmt;
71232+char *gr_audit_log_fmt;
71233+char *gr_alert_log_buf;
71234+char *gr_audit_log_buf;
71235+
71236+void __init
71237+grsecurity_init(void)
71238+{
71239+ int j;
71240+ /* create the per-cpu shared pages */
71241+
71242+#ifdef CONFIG_X86
71243+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
71244+#endif
71245+
71246+ for (j = 0; j < 4; j++) {
71247+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
71248+ if (gr_shared_page[j] == NULL) {
71249+ panic("Unable to allocate grsecurity shared page");
71250+ return;
71251+ }
71252+ }
71253+
71254+ /* allocate log buffers */
71255+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
71256+ if (!gr_alert_log_fmt) {
71257+ panic("Unable to allocate grsecurity alert log format buffer");
71258+ return;
71259+ }
71260+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
71261+ if (!gr_audit_log_fmt) {
71262+ panic("Unable to allocate grsecurity audit log format buffer");
71263+ return;
71264+ }
71265+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
71266+ if (!gr_alert_log_buf) {
71267+ panic("Unable to allocate grsecurity alert log buffer");
71268+ return;
71269+ }
71270+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
71271+ if (!gr_audit_log_buf) {
71272+ panic("Unable to allocate grsecurity audit log buffer");
71273+ return;
71274+ }
71275+
71276+#ifdef CONFIG_GRKERNSEC_IO
71277+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
71278+ grsec_disable_privio = 1;
71279+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
71280+ grsec_disable_privio = 1;
71281+#else
71282+ grsec_disable_privio = 0;
71283+#endif
71284+#endif
71285+
71286+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71287+ /* for backward compatibility, tpe_invert always defaults to on if
71288+ enabled in the kernel
71289+ */
71290+ grsec_enable_tpe_invert = 1;
71291+#endif
71292+
71293+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
71294+#ifndef CONFIG_GRKERNSEC_SYSCTL
71295+ grsec_lock = 1;
71296+#endif
71297+
71298+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71299+ grsec_enable_log_rwxmaps = 1;
71300+#endif
71301+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71302+ grsec_enable_group = 1;
71303+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
71304+#endif
71305+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71306+ grsec_enable_ptrace_readexec = 1;
71307+#endif
71308+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71309+ grsec_enable_chdir = 1;
71310+#endif
71311+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71312+ grsec_enable_harden_ptrace = 1;
71313+#endif
71314+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
71315+ grsec_enable_harden_ipc = 1;
71316+#endif
71317+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71318+ grsec_enable_mount = 1;
71319+#endif
71320+#ifdef CONFIG_GRKERNSEC_LINK
71321+ grsec_enable_link = 1;
71322+#endif
71323+#ifdef CONFIG_GRKERNSEC_BRUTE
71324+ grsec_enable_brute = 1;
71325+#endif
71326+#ifdef CONFIG_GRKERNSEC_DMESG
71327+ grsec_enable_dmesg = 1;
71328+#endif
71329+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71330+ grsec_enable_blackhole = 1;
71331+ grsec_lastack_retries = 4;
71332+#endif
71333+#ifdef CONFIG_GRKERNSEC_FIFO
71334+ grsec_enable_fifo = 1;
71335+#endif
71336+#ifdef CONFIG_GRKERNSEC_EXECLOG
71337+ grsec_enable_execlog = 1;
71338+#endif
71339+#ifdef CONFIG_GRKERNSEC_SETXID
71340+ grsec_enable_setxid = 1;
71341+#endif
71342+#ifdef CONFIG_GRKERNSEC_SIGNAL
71343+ grsec_enable_signal = 1;
71344+#endif
71345+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71346+ grsec_enable_forkfail = 1;
71347+#endif
71348+#ifdef CONFIG_GRKERNSEC_TIME
71349+ grsec_enable_time = 1;
71350+#endif
71351+#ifdef CONFIG_GRKERNSEC_RESLOG
71352+ grsec_resource_logging = 1;
71353+#endif
71354+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71355+ grsec_enable_chroot_findtask = 1;
71356+#endif
71357+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71358+ grsec_enable_chroot_unix = 1;
71359+#endif
71360+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71361+ grsec_enable_chroot_mount = 1;
71362+#endif
71363+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71364+ grsec_enable_chroot_fchdir = 1;
71365+#endif
71366+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71367+ grsec_enable_chroot_shmat = 1;
71368+#endif
71369+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71370+ grsec_enable_audit_ptrace = 1;
71371+#endif
71372+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71373+ grsec_enable_chroot_double = 1;
71374+#endif
71375+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71376+ grsec_enable_chroot_pivot = 1;
71377+#endif
71378+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71379+ grsec_enable_chroot_chdir = 1;
71380+#endif
71381+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71382+ grsec_enable_chroot_chmod = 1;
71383+#endif
71384+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71385+ grsec_enable_chroot_mknod = 1;
71386+#endif
71387+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71388+ grsec_enable_chroot_nice = 1;
71389+#endif
71390+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71391+ grsec_enable_chroot_execlog = 1;
71392+#endif
71393+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71394+ grsec_enable_chroot_caps = 1;
71395+#endif
71396+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71397+ grsec_enable_chroot_sysctl = 1;
71398+#endif
71399+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71400+ grsec_enable_symlinkown = 1;
71401+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
71402+#endif
71403+#ifdef CONFIG_GRKERNSEC_TPE
71404+ grsec_enable_tpe = 1;
71405+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
71406+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71407+ grsec_enable_tpe_all = 1;
71408+#endif
71409+#endif
71410+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71411+ grsec_enable_socket_all = 1;
71412+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
71413+#endif
71414+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71415+ grsec_enable_socket_client = 1;
71416+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
71417+#endif
71418+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71419+ grsec_enable_socket_server = 1;
71420+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
71421+#endif
71422+#endif
71423+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
71424+ grsec_deny_new_usb = 1;
71425+#endif
71426+
71427+ return;
71428+}
71429diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
71430new file mode 100644
71431index 0000000..f365de0
71432--- /dev/null
71433+++ b/grsecurity/grsec_ipc.c
71434@@ -0,0 +1,22 @@
71435+#include <linux/kernel.h>
71436+#include <linux/mm.h>
71437+#include <linux/sched.h>
71438+#include <linux/file.h>
71439+#include <linux/ipc.h>
71440+#include <linux/ipc_namespace.h>
71441+#include <linux/grsecurity.h>
71442+#include <linux/grinternal.h>
71443+
71444+int
71445+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
71446+{
71447+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
71448+ int write = (requested_mode & 00002);
71449+
71450+ if (grsec_enable_harden_ipc && !(requested_mode & ~granted_mode & 0007) && !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
71451+ gr_log_str2_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", write ? "writ" : "read", GR_GLOBAL_UID(ipcp->cuid));
71452+ return 0;
71453+ }
71454+#endif
71455+ return 1;
71456+}
71457diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
71458new file mode 100644
71459index 0000000..5e05e20
71460--- /dev/null
71461+++ b/grsecurity/grsec_link.c
71462@@ -0,0 +1,58 @@
71463+#include <linux/kernel.h>
71464+#include <linux/sched.h>
71465+#include <linux/fs.h>
71466+#include <linux/file.h>
71467+#include <linux/grinternal.h>
71468+
71469+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
71470+{
71471+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71472+ const struct inode *link_inode = link->dentry->d_inode;
71473+
71474+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
71475+ /* ignore root-owned links, e.g. /proc/self */
71476+ gr_is_global_nonroot(link_inode->i_uid) && target &&
71477+ !uid_eq(link_inode->i_uid, target->i_uid)) {
71478+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
71479+ return 1;
71480+ }
71481+#endif
71482+ return 0;
71483+}
71484+
71485+int
71486+gr_handle_follow_link(const struct inode *parent,
71487+ const struct inode *inode,
71488+ const struct dentry *dentry, const struct vfsmount *mnt)
71489+{
71490+#ifdef CONFIG_GRKERNSEC_LINK
71491+ const struct cred *cred = current_cred();
71492+
71493+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
71494+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
71495+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
71496+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
71497+ return -EACCES;
71498+ }
71499+#endif
71500+ return 0;
71501+}
71502+
71503+int
71504+gr_handle_hardlink(const struct dentry *dentry,
71505+ const struct vfsmount *mnt,
71506+ struct inode *inode, const int mode, const struct filename *to)
71507+{
71508+#ifdef CONFIG_GRKERNSEC_LINK
71509+ const struct cred *cred = current_cred();
71510+
71511+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
71512+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
71513+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
71514+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
71515+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
71516+ return -EPERM;
71517+ }
71518+#endif
71519+ return 0;
71520+}
71521diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
71522new file mode 100644
71523index 0000000..dbe0a6b
71524--- /dev/null
71525+++ b/grsecurity/grsec_log.c
71526@@ -0,0 +1,341 @@
71527+#include <linux/kernel.h>
71528+#include <linux/sched.h>
71529+#include <linux/file.h>
71530+#include <linux/tty.h>
71531+#include <linux/fs.h>
71532+#include <linux/mm.h>
71533+#include <linux/grinternal.h>
71534+
71535+#ifdef CONFIG_TREE_PREEMPT_RCU
71536+#define DISABLE_PREEMPT() preempt_disable()
71537+#define ENABLE_PREEMPT() preempt_enable()
71538+#else
71539+#define DISABLE_PREEMPT()
71540+#define ENABLE_PREEMPT()
71541+#endif
71542+
71543+#define BEGIN_LOCKS(x) \
71544+ DISABLE_PREEMPT(); \
71545+ rcu_read_lock(); \
71546+ read_lock(&tasklist_lock); \
71547+ read_lock(&grsec_exec_file_lock); \
71548+ if (x != GR_DO_AUDIT) \
71549+ spin_lock(&grsec_alert_lock); \
71550+ else \
71551+ spin_lock(&grsec_audit_lock)
71552+
71553+#define END_LOCKS(x) \
71554+ if (x != GR_DO_AUDIT) \
71555+ spin_unlock(&grsec_alert_lock); \
71556+ else \
71557+ spin_unlock(&grsec_audit_lock); \
71558+ read_unlock(&grsec_exec_file_lock); \
71559+ read_unlock(&tasklist_lock); \
71560+ rcu_read_unlock(); \
71561+ ENABLE_PREEMPT(); \
71562+ if (x == GR_DONT_AUDIT) \
71563+ gr_handle_alertkill(current)
71564+
71565+enum {
71566+ FLOODING,
71567+ NO_FLOODING
71568+};
71569+
71570+extern char *gr_alert_log_fmt;
71571+extern char *gr_audit_log_fmt;
71572+extern char *gr_alert_log_buf;
71573+extern char *gr_audit_log_buf;
71574+
71575+static int gr_log_start(int audit)
71576+{
71577+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
71578+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
71579+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71580+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
71581+ unsigned long curr_secs = get_seconds();
71582+
71583+ if (audit == GR_DO_AUDIT)
71584+ goto set_fmt;
71585+
71586+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
71587+ grsec_alert_wtime = curr_secs;
71588+ grsec_alert_fyet = 0;
71589+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
71590+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
71591+ grsec_alert_fyet++;
71592+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
71593+ grsec_alert_wtime = curr_secs;
71594+ grsec_alert_fyet++;
71595+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
71596+ return FLOODING;
71597+ }
71598+ else return FLOODING;
71599+
71600+set_fmt:
71601+#endif
71602+ memset(buf, 0, PAGE_SIZE);
71603+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
71604+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
71605+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71606+ } else if (current->signal->curr_ip) {
71607+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
71608+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
71609+ } else if (gr_acl_is_enabled()) {
71610+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
71611+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71612+ } else {
71613+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
71614+ strcpy(buf, fmt);
71615+ }
71616+
71617+ return NO_FLOODING;
71618+}
71619+
71620+static void gr_log_middle(int audit, const char *msg, va_list ap)
71621+ __attribute__ ((format (printf, 2, 0)));
71622+
71623+static void gr_log_middle(int audit, const char *msg, va_list ap)
71624+{
71625+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71626+ unsigned int len = strlen(buf);
71627+
71628+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71629+
71630+ return;
71631+}
71632+
71633+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71634+ __attribute__ ((format (printf, 2, 3)));
71635+
71636+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71637+{
71638+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71639+ unsigned int len = strlen(buf);
71640+ va_list ap;
71641+
71642+ va_start(ap, msg);
71643+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71644+ va_end(ap);
71645+
71646+ return;
71647+}
71648+
71649+static void gr_log_end(int audit, int append_default)
71650+{
71651+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71652+ if (append_default) {
71653+ struct task_struct *task = current;
71654+ struct task_struct *parent = task->real_parent;
71655+ const struct cred *cred = __task_cred(task);
71656+ const struct cred *pcred = __task_cred(parent);
71657+ unsigned int len = strlen(buf);
71658+
71659+ 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));
71660+ }
71661+
71662+ printk("%s\n", buf);
71663+
71664+ return;
71665+}
71666+
71667+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
71668+{
71669+ int logtype;
71670+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
71671+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
71672+ void *voidptr = NULL;
71673+ int num1 = 0, num2 = 0;
71674+ unsigned long ulong1 = 0, ulong2 = 0;
71675+ struct dentry *dentry = NULL;
71676+ struct vfsmount *mnt = NULL;
71677+ struct file *file = NULL;
71678+ struct task_struct *task = NULL;
71679+ struct vm_area_struct *vma = NULL;
71680+ const struct cred *cred, *pcred;
71681+ va_list ap;
71682+
71683+ BEGIN_LOCKS(audit);
71684+ logtype = gr_log_start(audit);
71685+ if (logtype == FLOODING) {
71686+ END_LOCKS(audit);
71687+ return;
71688+ }
71689+ va_start(ap, argtypes);
71690+ switch (argtypes) {
71691+ case GR_TTYSNIFF:
71692+ task = va_arg(ap, struct task_struct *);
71693+ 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));
71694+ break;
71695+ case GR_SYSCTL_HIDDEN:
71696+ str1 = va_arg(ap, char *);
71697+ gr_log_middle_varargs(audit, msg, result, str1);
71698+ break;
71699+ case GR_RBAC:
71700+ dentry = va_arg(ap, struct dentry *);
71701+ mnt = va_arg(ap, struct vfsmount *);
71702+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
71703+ break;
71704+ case GR_RBAC_STR:
71705+ dentry = va_arg(ap, struct dentry *);
71706+ mnt = va_arg(ap, struct vfsmount *);
71707+ str1 = va_arg(ap, char *);
71708+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
71709+ break;
71710+ case GR_STR_RBAC:
71711+ str1 = va_arg(ap, char *);
71712+ dentry = va_arg(ap, struct dentry *);
71713+ mnt = va_arg(ap, struct vfsmount *);
71714+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
71715+ break;
71716+ case GR_RBAC_MODE2:
71717+ dentry = va_arg(ap, struct dentry *);
71718+ mnt = va_arg(ap, struct vfsmount *);
71719+ str1 = va_arg(ap, char *);
71720+ str2 = va_arg(ap, char *);
71721+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
71722+ break;
71723+ case GR_RBAC_MODE3:
71724+ dentry = va_arg(ap, struct dentry *);
71725+ mnt = va_arg(ap, struct vfsmount *);
71726+ str1 = va_arg(ap, char *);
71727+ str2 = va_arg(ap, char *);
71728+ str3 = va_arg(ap, char *);
71729+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
71730+ break;
71731+ case GR_FILENAME:
71732+ dentry = va_arg(ap, struct dentry *);
71733+ mnt = va_arg(ap, struct vfsmount *);
71734+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
71735+ break;
71736+ case GR_STR_FILENAME:
71737+ str1 = va_arg(ap, char *);
71738+ dentry = va_arg(ap, struct dentry *);
71739+ mnt = va_arg(ap, struct vfsmount *);
71740+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
71741+ break;
71742+ case GR_FILENAME_STR:
71743+ dentry = va_arg(ap, struct dentry *);
71744+ mnt = va_arg(ap, struct vfsmount *);
71745+ str1 = va_arg(ap, char *);
71746+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
71747+ break;
71748+ case GR_FILENAME_TWO_INT:
71749+ dentry = va_arg(ap, struct dentry *);
71750+ mnt = va_arg(ap, struct vfsmount *);
71751+ num1 = va_arg(ap, int);
71752+ num2 = va_arg(ap, int);
71753+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
71754+ break;
71755+ case GR_FILENAME_TWO_INT_STR:
71756+ dentry = va_arg(ap, struct dentry *);
71757+ mnt = va_arg(ap, struct vfsmount *);
71758+ num1 = va_arg(ap, int);
71759+ num2 = va_arg(ap, int);
71760+ str1 = va_arg(ap, char *);
71761+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
71762+ break;
71763+ case GR_TEXTREL:
71764+ file = va_arg(ap, struct file *);
71765+ ulong1 = va_arg(ap, unsigned long);
71766+ ulong2 = va_arg(ap, unsigned long);
71767+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
71768+ break;
71769+ case GR_PTRACE:
71770+ task = va_arg(ap, struct task_struct *);
71771+ 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));
71772+ break;
71773+ case GR_RESOURCE:
71774+ task = va_arg(ap, struct task_struct *);
71775+ cred = __task_cred(task);
71776+ pcred = __task_cred(task->real_parent);
71777+ ulong1 = va_arg(ap, unsigned long);
71778+ str1 = va_arg(ap, char *);
71779+ ulong2 = va_arg(ap, unsigned long);
71780+ 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));
71781+ break;
71782+ case GR_CAP:
71783+ task = va_arg(ap, struct task_struct *);
71784+ cred = __task_cred(task);
71785+ pcred = __task_cred(task->real_parent);
71786+ str1 = va_arg(ap, char *);
71787+ 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));
71788+ break;
71789+ case GR_SIG:
71790+ str1 = va_arg(ap, char *);
71791+ voidptr = va_arg(ap, void *);
71792+ gr_log_middle_varargs(audit, msg, str1, voidptr);
71793+ break;
71794+ case GR_SIG2:
71795+ task = va_arg(ap, struct task_struct *);
71796+ cred = __task_cred(task);
71797+ pcred = __task_cred(task->real_parent);
71798+ num1 = va_arg(ap, int);
71799+ 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));
71800+ break;
71801+ case GR_CRASH1:
71802+ task = va_arg(ap, struct task_struct *);
71803+ cred = __task_cred(task);
71804+ pcred = __task_cred(task->real_parent);
71805+ ulong1 = va_arg(ap, unsigned long);
71806+ 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);
71807+ break;
71808+ case GR_CRASH2:
71809+ task = va_arg(ap, struct task_struct *);
71810+ cred = __task_cred(task);
71811+ pcred = __task_cred(task->real_parent);
71812+ ulong1 = va_arg(ap, unsigned long);
71813+ 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);
71814+ break;
71815+ case GR_RWXMAP:
71816+ file = va_arg(ap, struct file *);
71817+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
71818+ break;
71819+ case GR_RWXMAPVMA:
71820+ vma = va_arg(ap, struct vm_area_struct *);
71821+ if (vma->vm_file)
71822+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
71823+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
71824+ str1 = "<stack>";
71825+ else if (vma->vm_start <= current->mm->brk &&
71826+ vma->vm_end >= current->mm->start_brk)
71827+ str1 = "<heap>";
71828+ else
71829+ str1 = "<anonymous mapping>";
71830+ gr_log_middle_varargs(audit, msg, str1);
71831+ break;
71832+ case GR_PSACCT:
71833+ {
71834+ unsigned int wday, cday;
71835+ __u8 whr, chr;
71836+ __u8 wmin, cmin;
71837+ __u8 wsec, csec;
71838+ char cur_tty[64] = { 0 };
71839+ char parent_tty[64] = { 0 };
71840+
71841+ task = va_arg(ap, struct task_struct *);
71842+ wday = va_arg(ap, unsigned int);
71843+ cday = va_arg(ap, unsigned int);
71844+ whr = va_arg(ap, int);
71845+ chr = va_arg(ap, int);
71846+ wmin = va_arg(ap, int);
71847+ cmin = va_arg(ap, int);
71848+ wsec = va_arg(ap, int);
71849+ csec = va_arg(ap, int);
71850+ ulong1 = va_arg(ap, unsigned long);
71851+ cred = __task_cred(task);
71852+ pcred = __task_cred(task->real_parent);
71853+
71854+ 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));
71855+ }
71856+ break;
71857+ default:
71858+ gr_log_middle(audit, msg, ap);
71859+ }
71860+ va_end(ap);
71861+ // these don't need DEFAULTSECARGS printed on the end
71862+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
71863+ gr_log_end(audit, 0);
71864+ else
71865+ gr_log_end(audit, 1);
71866+ END_LOCKS(audit);
71867+}
71868diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
71869new file mode 100644
71870index 0000000..f536303
71871--- /dev/null
71872+++ b/grsecurity/grsec_mem.c
71873@@ -0,0 +1,40 @@
71874+#include <linux/kernel.h>
71875+#include <linux/sched.h>
71876+#include <linux/mm.h>
71877+#include <linux/mman.h>
71878+#include <linux/grinternal.h>
71879+
71880+void
71881+gr_handle_ioperm(void)
71882+{
71883+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
71884+ return;
71885+}
71886+
71887+void
71888+gr_handle_iopl(void)
71889+{
71890+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
71891+ return;
71892+}
71893+
71894+void
71895+gr_handle_mem_readwrite(u64 from, u64 to)
71896+{
71897+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
71898+ return;
71899+}
71900+
71901+void
71902+gr_handle_vm86(void)
71903+{
71904+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
71905+ return;
71906+}
71907+
71908+void
71909+gr_log_badprocpid(const char *entry)
71910+{
71911+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
71912+ return;
71913+}
71914diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
71915new file mode 100644
71916index 0000000..2131422
71917--- /dev/null
71918+++ b/grsecurity/grsec_mount.c
71919@@ -0,0 +1,62 @@
71920+#include <linux/kernel.h>
71921+#include <linux/sched.h>
71922+#include <linux/mount.h>
71923+#include <linux/grsecurity.h>
71924+#include <linux/grinternal.h>
71925+
71926+void
71927+gr_log_remount(const char *devname, const int retval)
71928+{
71929+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71930+ if (grsec_enable_mount && (retval >= 0))
71931+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
71932+#endif
71933+ return;
71934+}
71935+
71936+void
71937+gr_log_unmount(const char *devname, const int retval)
71938+{
71939+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71940+ if (grsec_enable_mount && (retval >= 0))
71941+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
71942+#endif
71943+ return;
71944+}
71945+
71946+void
71947+gr_log_mount(const char *from, const char *to, const int retval)
71948+{
71949+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71950+ if (grsec_enable_mount && (retval >= 0))
71951+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
71952+#endif
71953+ return;
71954+}
71955+
71956+int
71957+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
71958+{
71959+#ifdef CONFIG_GRKERNSEC_ROFS
71960+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
71961+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
71962+ return -EPERM;
71963+ } else
71964+ return 0;
71965+#endif
71966+ return 0;
71967+}
71968+
71969+int
71970+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
71971+{
71972+#ifdef CONFIG_GRKERNSEC_ROFS
71973+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
71974+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
71975+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
71976+ return -EPERM;
71977+ } else
71978+ return 0;
71979+#endif
71980+ return 0;
71981+}
71982diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
71983new file mode 100644
71984index 0000000..6ee9d50
71985--- /dev/null
71986+++ b/grsecurity/grsec_pax.c
71987@@ -0,0 +1,45 @@
71988+#include <linux/kernel.h>
71989+#include <linux/sched.h>
71990+#include <linux/mm.h>
71991+#include <linux/file.h>
71992+#include <linux/grinternal.h>
71993+#include <linux/grsecurity.h>
71994+
71995+void
71996+gr_log_textrel(struct vm_area_struct * vma)
71997+{
71998+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71999+ if (grsec_enable_log_rwxmaps)
72000+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
72001+#endif
72002+ return;
72003+}
72004+
72005+void gr_log_ptgnustack(struct file *file)
72006+{
72007+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72008+ if (grsec_enable_log_rwxmaps)
72009+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
72010+#endif
72011+ return;
72012+}
72013+
72014+void
72015+gr_log_rwxmmap(struct file *file)
72016+{
72017+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72018+ if (grsec_enable_log_rwxmaps)
72019+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
72020+#endif
72021+ return;
72022+}
72023+
72024+void
72025+gr_log_rwxmprotect(struct vm_area_struct *vma)
72026+{
72027+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72028+ if (grsec_enable_log_rwxmaps)
72029+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
72030+#endif
72031+ return;
72032+}
72033diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
72034new file mode 100644
72035index 0000000..f7f29aa
72036--- /dev/null
72037+++ b/grsecurity/grsec_ptrace.c
72038@@ -0,0 +1,30 @@
72039+#include <linux/kernel.h>
72040+#include <linux/sched.h>
72041+#include <linux/grinternal.h>
72042+#include <linux/security.h>
72043+
72044+void
72045+gr_audit_ptrace(struct task_struct *task)
72046+{
72047+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72048+ if (grsec_enable_audit_ptrace)
72049+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
72050+#endif
72051+ return;
72052+}
72053+
72054+int
72055+gr_ptrace_readexec(struct file *file, int unsafe_flags)
72056+{
72057+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72058+ const struct dentry *dentry = file->f_path.dentry;
72059+ const struct vfsmount *mnt = file->f_path.mnt;
72060+
72061+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
72062+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
72063+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
72064+ return -EACCES;
72065+ }
72066+#endif
72067+ return 0;
72068+}
72069diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
72070new file mode 100644
72071index 0000000..3860c7e
72072--- /dev/null
72073+++ b/grsecurity/grsec_sig.c
72074@@ -0,0 +1,236 @@
72075+#include <linux/kernel.h>
72076+#include <linux/sched.h>
72077+#include <linux/fs.h>
72078+#include <linux/delay.h>
72079+#include <linux/grsecurity.h>
72080+#include <linux/grinternal.h>
72081+#include <linux/hardirq.h>
72082+
72083+char *signames[] = {
72084+ [SIGSEGV] = "Segmentation fault",
72085+ [SIGILL] = "Illegal instruction",
72086+ [SIGABRT] = "Abort",
72087+ [SIGBUS] = "Invalid alignment/Bus error"
72088+};
72089+
72090+void
72091+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
72092+{
72093+#ifdef CONFIG_GRKERNSEC_SIGNAL
72094+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
72095+ (sig == SIGABRT) || (sig == SIGBUS))) {
72096+ if (task_pid_nr(t) == task_pid_nr(current)) {
72097+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
72098+ } else {
72099+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
72100+ }
72101+ }
72102+#endif
72103+ return;
72104+}
72105+
72106+int
72107+gr_handle_signal(const struct task_struct *p, const int sig)
72108+{
72109+#ifdef CONFIG_GRKERNSEC
72110+ /* ignore the 0 signal for protected task checks */
72111+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
72112+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
72113+ return -EPERM;
72114+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
72115+ return -EPERM;
72116+ }
72117+#endif
72118+ return 0;
72119+}
72120+
72121+#ifdef CONFIG_GRKERNSEC
72122+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
72123+
72124+int gr_fake_force_sig(int sig, struct task_struct *t)
72125+{
72126+ unsigned long int flags;
72127+ int ret, blocked, ignored;
72128+ struct k_sigaction *action;
72129+
72130+ spin_lock_irqsave(&t->sighand->siglock, flags);
72131+ action = &t->sighand->action[sig-1];
72132+ ignored = action->sa.sa_handler == SIG_IGN;
72133+ blocked = sigismember(&t->blocked, sig);
72134+ if (blocked || ignored) {
72135+ action->sa.sa_handler = SIG_DFL;
72136+ if (blocked) {
72137+ sigdelset(&t->blocked, sig);
72138+ recalc_sigpending_and_wake(t);
72139+ }
72140+ }
72141+ if (action->sa.sa_handler == SIG_DFL)
72142+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
72143+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
72144+
72145+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
72146+
72147+ return ret;
72148+}
72149+#endif
72150+
72151+#define GR_USER_BAN_TIME (15 * 60)
72152+#define GR_DAEMON_BRUTE_TIME (30 * 60)
72153+
72154+void gr_handle_brute_attach(int dumpable)
72155+{
72156+#ifdef CONFIG_GRKERNSEC_BRUTE
72157+ struct task_struct *p = current;
72158+ kuid_t uid = GLOBAL_ROOT_UID;
72159+ int daemon = 0;
72160+
72161+ if (!grsec_enable_brute)
72162+ return;
72163+
72164+ rcu_read_lock();
72165+ read_lock(&tasklist_lock);
72166+ read_lock(&grsec_exec_file_lock);
72167+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
72168+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
72169+ p->real_parent->brute = 1;
72170+ daemon = 1;
72171+ } else {
72172+ const struct cred *cred = __task_cred(p), *cred2;
72173+ struct task_struct *tsk, *tsk2;
72174+
72175+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
72176+ struct user_struct *user;
72177+
72178+ uid = cred->uid;
72179+
72180+ /* this is put upon execution past expiration */
72181+ user = find_user(uid);
72182+ if (user == NULL)
72183+ goto unlock;
72184+ user->suid_banned = 1;
72185+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
72186+ if (user->suid_ban_expires == ~0UL)
72187+ user->suid_ban_expires--;
72188+
72189+ /* only kill other threads of the same binary, from the same user */
72190+ do_each_thread(tsk2, tsk) {
72191+ cred2 = __task_cred(tsk);
72192+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
72193+ gr_fake_force_sig(SIGKILL, tsk);
72194+ } while_each_thread(tsk2, tsk);
72195+ }
72196+ }
72197+unlock:
72198+ read_unlock(&grsec_exec_file_lock);
72199+ read_unlock(&tasklist_lock);
72200+ rcu_read_unlock();
72201+
72202+ if (gr_is_global_nonroot(uid))
72203+ 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);
72204+ else if (daemon)
72205+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
72206+
72207+#endif
72208+ return;
72209+}
72210+
72211+void gr_handle_brute_check(void)
72212+{
72213+#ifdef CONFIG_GRKERNSEC_BRUTE
72214+ struct task_struct *p = current;
72215+
72216+ if (unlikely(p->brute)) {
72217+ if (!grsec_enable_brute)
72218+ p->brute = 0;
72219+ else if (time_before(get_seconds(), p->brute_expires))
72220+ msleep(30 * 1000);
72221+ }
72222+#endif
72223+ return;
72224+}
72225+
72226+void gr_handle_kernel_exploit(void)
72227+{
72228+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72229+ const struct cred *cred;
72230+ struct task_struct *tsk, *tsk2;
72231+ struct user_struct *user;
72232+ kuid_t uid;
72233+
72234+ if (in_irq() || in_serving_softirq() || in_nmi())
72235+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
72236+
72237+ uid = current_uid();
72238+
72239+ if (gr_is_global_root(uid))
72240+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
72241+ else {
72242+ /* kill all the processes of this user, hold a reference
72243+ to their creds struct, and prevent them from creating
72244+ another process until system reset
72245+ */
72246+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
72247+ GR_GLOBAL_UID(uid));
72248+ /* we intentionally leak this ref */
72249+ user = get_uid(current->cred->user);
72250+ if (user)
72251+ user->kernel_banned = 1;
72252+
72253+ /* kill all processes of this user */
72254+ read_lock(&tasklist_lock);
72255+ do_each_thread(tsk2, tsk) {
72256+ cred = __task_cred(tsk);
72257+ if (uid_eq(cred->uid, uid))
72258+ gr_fake_force_sig(SIGKILL, tsk);
72259+ } while_each_thread(tsk2, tsk);
72260+ read_unlock(&tasklist_lock);
72261+ }
72262+#endif
72263+}
72264+
72265+#ifdef CONFIG_GRKERNSEC_BRUTE
72266+static bool suid_ban_expired(struct user_struct *user)
72267+{
72268+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
72269+ user->suid_banned = 0;
72270+ user->suid_ban_expires = 0;
72271+ free_uid(user);
72272+ return true;
72273+ }
72274+
72275+ return false;
72276+}
72277+#endif
72278+
72279+int gr_process_kernel_exec_ban(void)
72280+{
72281+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72282+ if (unlikely(current->cred->user->kernel_banned))
72283+ return -EPERM;
72284+#endif
72285+ return 0;
72286+}
72287+
72288+int gr_process_kernel_setuid_ban(struct user_struct *user)
72289+{
72290+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72291+ if (unlikely(user->kernel_banned))
72292+ gr_fake_force_sig(SIGKILL, current);
72293+#endif
72294+ return 0;
72295+}
72296+
72297+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
72298+{
72299+#ifdef CONFIG_GRKERNSEC_BRUTE
72300+ struct user_struct *user = current->cred->user;
72301+ if (unlikely(user->suid_banned)) {
72302+ if (suid_ban_expired(user))
72303+ return 0;
72304+ /* disallow execution of suid binaries only */
72305+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
72306+ return -EPERM;
72307+ }
72308+#endif
72309+ return 0;
72310+}
72311diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
72312new file mode 100644
72313index 0000000..4030d57
72314--- /dev/null
72315+++ b/grsecurity/grsec_sock.c
72316@@ -0,0 +1,244 @@
72317+#include <linux/kernel.h>
72318+#include <linux/module.h>
72319+#include <linux/sched.h>
72320+#include <linux/file.h>
72321+#include <linux/net.h>
72322+#include <linux/in.h>
72323+#include <linux/ip.h>
72324+#include <net/sock.h>
72325+#include <net/inet_sock.h>
72326+#include <linux/grsecurity.h>
72327+#include <linux/grinternal.h>
72328+#include <linux/gracl.h>
72329+
72330+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
72331+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
72332+
72333+EXPORT_SYMBOL(gr_search_udp_recvmsg);
72334+EXPORT_SYMBOL(gr_search_udp_sendmsg);
72335+
72336+#ifdef CONFIG_UNIX_MODULE
72337+EXPORT_SYMBOL(gr_acl_handle_unix);
72338+EXPORT_SYMBOL(gr_acl_handle_mknod);
72339+EXPORT_SYMBOL(gr_handle_chroot_unix);
72340+EXPORT_SYMBOL(gr_handle_create);
72341+#endif
72342+
72343+#ifdef CONFIG_GRKERNSEC
72344+#define gr_conn_table_size 32749
72345+struct conn_table_entry {
72346+ struct conn_table_entry *next;
72347+ struct signal_struct *sig;
72348+};
72349+
72350+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
72351+DEFINE_SPINLOCK(gr_conn_table_lock);
72352+
72353+extern const char * gr_socktype_to_name(unsigned char type);
72354+extern const char * gr_proto_to_name(unsigned char proto);
72355+extern const char * gr_sockfamily_to_name(unsigned char family);
72356+
72357+static __inline__ int
72358+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
72359+{
72360+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
72361+}
72362+
72363+static __inline__ int
72364+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
72365+ __u16 sport, __u16 dport)
72366+{
72367+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
72368+ sig->gr_sport == sport && sig->gr_dport == dport))
72369+ return 1;
72370+ else
72371+ return 0;
72372+}
72373+
72374+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
72375+{
72376+ struct conn_table_entry **match;
72377+ unsigned int index;
72378+
72379+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
72380+ sig->gr_sport, sig->gr_dport,
72381+ gr_conn_table_size);
72382+
72383+ newent->sig = sig;
72384+
72385+ match = &gr_conn_table[index];
72386+ newent->next = *match;
72387+ *match = newent;
72388+
72389+ return;
72390+}
72391+
72392+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
72393+{
72394+ struct conn_table_entry *match, *last = NULL;
72395+ unsigned int index;
72396+
72397+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
72398+ sig->gr_sport, sig->gr_dport,
72399+ gr_conn_table_size);
72400+
72401+ match = gr_conn_table[index];
72402+ while (match && !conn_match(match->sig,
72403+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
72404+ sig->gr_dport)) {
72405+ last = match;
72406+ match = match->next;
72407+ }
72408+
72409+ if (match) {
72410+ if (last)
72411+ last->next = match->next;
72412+ else
72413+ gr_conn_table[index] = NULL;
72414+ kfree(match);
72415+ }
72416+
72417+ return;
72418+}
72419+
72420+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
72421+ __u16 sport, __u16 dport)
72422+{
72423+ struct conn_table_entry *match;
72424+ unsigned int index;
72425+
72426+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
72427+
72428+ match = gr_conn_table[index];
72429+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
72430+ match = match->next;
72431+
72432+ if (match)
72433+ return match->sig;
72434+ else
72435+ return NULL;
72436+}
72437+
72438+#endif
72439+
72440+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
72441+{
72442+#ifdef CONFIG_GRKERNSEC
72443+ struct signal_struct *sig = task->signal;
72444+ struct conn_table_entry *newent;
72445+
72446+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
72447+ if (newent == NULL)
72448+ return;
72449+ /* no bh lock needed since we are called with bh disabled */
72450+ spin_lock(&gr_conn_table_lock);
72451+ gr_del_task_from_ip_table_nolock(sig);
72452+ sig->gr_saddr = inet->inet_rcv_saddr;
72453+ sig->gr_daddr = inet->inet_daddr;
72454+ sig->gr_sport = inet->inet_sport;
72455+ sig->gr_dport = inet->inet_dport;
72456+ gr_add_to_task_ip_table_nolock(sig, newent);
72457+ spin_unlock(&gr_conn_table_lock);
72458+#endif
72459+ return;
72460+}
72461+
72462+void gr_del_task_from_ip_table(struct task_struct *task)
72463+{
72464+#ifdef CONFIG_GRKERNSEC
72465+ spin_lock_bh(&gr_conn_table_lock);
72466+ gr_del_task_from_ip_table_nolock(task->signal);
72467+ spin_unlock_bh(&gr_conn_table_lock);
72468+#endif
72469+ return;
72470+}
72471+
72472+void
72473+gr_attach_curr_ip(const struct sock *sk)
72474+{
72475+#ifdef CONFIG_GRKERNSEC
72476+ struct signal_struct *p, *set;
72477+ const struct inet_sock *inet = inet_sk(sk);
72478+
72479+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
72480+ return;
72481+
72482+ set = current->signal;
72483+
72484+ spin_lock_bh(&gr_conn_table_lock);
72485+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
72486+ inet->inet_dport, inet->inet_sport);
72487+ if (unlikely(p != NULL)) {
72488+ set->curr_ip = p->curr_ip;
72489+ set->used_accept = 1;
72490+ gr_del_task_from_ip_table_nolock(p);
72491+ spin_unlock_bh(&gr_conn_table_lock);
72492+ return;
72493+ }
72494+ spin_unlock_bh(&gr_conn_table_lock);
72495+
72496+ set->curr_ip = inet->inet_daddr;
72497+ set->used_accept = 1;
72498+#endif
72499+ return;
72500+}
72501+
72502+int
72503+gr_handle_sock_all(const int family, const int type, const int protocol)
72504+{
72505+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72506+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
72507+ (family != AF_UNIX)) {
72508+ if (family == AF_INET)
72509+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
72510+ else
72511+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
72512+ return -EACCES;
72513+ }
72514+#endif
72515+ return 0;
72516+}
72517+
72518+int
72519+gr_handle_sock_server(const struct sockaddr *sck)
72520+{
72521+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72522+ if (grsec_enable_socket_server &&
72523+ in_group_p(grsec_socket_server_gid) &&
72524+ sck && (sck->sa_family != AF_UNIX) &&
72525+ (sck->sa_family != AF_LOCAL)) {
72526+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72527+ return -EACCES;
72528+ }
72529+#endif
72530+ return 0;
72531+}
72532+
72533+int
72534+gr_handle_sock_server_other(const struct sock *sck)
72535+{
72536+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72537+ if (grsec_enable_socket_server &&
72538+ in_group_p(grsec_socket_server_gid) &&
72539+ sck && (sck->sk_family != AF_UNIX) &&
72540+ (sck->sk_family != AF_LOCAL)) {
72541+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72542+ return -EACCES;
72543+ }
72544+#endif
72545+ return 0;
72546+}
72547+
72548+int
72549+gr_handle_sock_client(const struct sockaddr *sck)
72550+{
72551+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72552+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
72553+ sck && (sck->sa_family != AF_UNIX) &&
72554+ (sck->sa_family != AF_LOCAL)) {
72555+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
72556+ return -EACCES;
72557+ }
72558+#endif
72559+ return 0;
72560+}
72561diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
72562new file mode 100644
72563index 0000000..8159888
72564--- /dev/null
72565+++ b/grsecurity/grsec_sysctl.c
72566@@ -0,0 +1,479 @@
72567+#include <linux/kernel.h>
72568+#include <linux/sched.h>
72569+#include <linux/sysctl.h>
72570+#include <linux/grsecurity.h>
72571+#include <linux/grinternal.h>
72572+
72573+int
72574+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
72575+{
72576+#ifdef CONFIG_GRKERNSEC_SYSCTL
72577+ if (dirname == NULL || name == NULL)
72578+ return 0;
72579+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
72580+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
72581+ return -EACCES;
72582+ }
72583+#endif
72584+ return 0;
72585+}
72586+
72587+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
72588+static int __maybe_unused __read_only one = 1;
72589+#endif
72590+
72591+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
72592+ defined(CONFIG_GRKERNSEC_DENYUSB)
72593+struct ctl_table grsecurity_table[] = {
72594+#ifdef CONFIG_GRKERNSEC_SYSCTL
72595+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
72596+#ifdef CONFIG_GRKERNSEC_IO
72597+ {
72598+ .procname = "disable_priv_io",
72599+ .data = &grsec_disable_privio,
72600+ .maxlen = sizeof(int),
72601+ .mode = 0600,
72602+ .proc_handler = &proc_dointvec,
72603+ },
72604+#endif
72605+#endif
72606+#ifdef CONFIG_GRKERNSEC_LINK
72607+ {
72608+ .procname = "linking_restrictions",
72609+ .data = &grsec_enable_link,
72610+ .maxlen = sizeof(int),
72611+ .mode = 0600,
72612+ .proc_handler = &proc_dointvec,
72613+ },
72614+#endif
72615+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72616+ {
72617+ .procname = "enforce_symlinksifowner",
72618+ .data = &grsec_enable_symlinkown,
72619+ .maxlen = sizeof(int),
72620+ .mode = 0600,
72621+ .proc_handler = &proc_dointvec,
72622+ },
72623+ {
72624+ .procname = "symlinkown_gid",
72625+ .data = &grsec_symlinkown_gid,
72626+ .maxlen = sizeof(int),
72627+ .mode = 0600,
72628+ .proc_handler = &proc_dointvec,
72629+ },
72630+#endif
72631+#ifdef CONFIG_GRKERNSEC_BRUTE
72632+ {
72633+ .procname = "deter_bruteforce",
72634+ .data = &grsec_enable_brute,
72635+ .maxlen = sizeof(int),
72636+ .mode = 0600,
72637+ .proc_handler = &proc_dointvec,
72638+ },
72639+#endif
72640+#ifdef CONFIG_GRKERNSEC_FIFO
72641+ {
72642+ .procname = "fifo_restrictions",
72643+ .data = &grsec_enable_fifo,
72644+ .maxlen = sizeof(int),
72645+ .mode = 0600,
72646+ .proc_handler = &proc_dointvec,
72647+ },
72648+#endif
72649+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72650+ {
72651+ .procname = "ptrace_readexec",
72652+ .data = &grsec_enable_ptrace_readexec,
72653+ .maxlen = sizeof(int),
72654+ .mode = 0600,
72655+ .proc_handler = &proc_dointvec,
72656+ },
72657+#endif
72658+#ifdef CONFIG_GRKERNSEC_SETXID
72659+ {
72660+ .procname = "consistent_setxid",
72661+ .data = &grsec_enable_setxid,
72662+ .maxlen = sizeof(int),
72663+ .mode = 0600,
72664+ .proc_handler = &proc_dointvec,
72665+ },
72666+#endif
72667+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72668+ {
72669+ .procname = "ip_blackhole",
72670+ .data = &grsec_enable_blackhole,
72671+ .maxlen = sizeof(int),
72672+ .mode = 0600,
72673+ .proc_handler = &proc_dointvec,
72674+ },
72675+ {
72676+ .procname = "lastack_retries",
72677+ .data = &grsec_lastack_retries,
72678+ .maxlen = sizeof(int),
72679+ .mode = 0600,
72680+ .proc_handler = &proc_dointvec,
72681+ },
72682+#endif
72683+#ifdef CONFIG_GRKERNSEC_EXECLOG
72684+ {
72685+ .procname = "exec_logging",
72686+ .data = &grsec_enable_execlog,
72687+ .maxlen = sizeof(int),
72688+ .mode = 0600,
72689+ .proc_handler = &proc_dointvec,
72690+ },
72691+#endif
72692+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72693+ {
72694+ .procname = "rwxmap_logging",
72695+ .data = &grsec_enable_log_rwxmaps,
72696+ .maxlen = sizeof(int),
72697+ .mode = 0600,
72698+ .proc_handler = &proc_dointvec,
72699+ },
72700+#endif
72701+#ifdef CONFIG_GRKERNSEC_SIGNAL
72702+ {
72703+ .procname = "signal_logging",
72704+ .data = &grsec_enable_signal,
72705+ .maxlen = sizeof(int),
72706+ .mode = 0600,
72707+ .proc_handler = &proc_dointvec,
72708+ },
72709+#endif
72710+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72711+ {
72712+ .procname = "forkfail_logging",
72713+ .data = &grsec_enable_forkfail,
72714+ .maxlen = sizeof(int),
72715+ .mode = 0600,
72716+ .proc_handler = &proc_dointvec,
72717+ },
72718+#endif
72719+#ifdef CONFIG_GRKERNSEC_TIME
72720+ {
72721+ .procname = "timechange_logging",
72722+ .data = &grsec_enable_time,
72723+ .maxlen = sizeof(int),
72724+ .mode = 0600,
72725+ .proc_handler = &proc_dointvec,
72726+ },
72727+#endif
72728+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72729+ {
72730+ .procname = "chroot_deny_shmat",
72731+ .data = &grsec_enable_chroot_shmat,
72732+ .maxlen = sizeof(int),
72733+ .mode = 0600,
72734+ .proc_handler = &proc_dointvec,
72735+ },
72736+#endif
72737+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72738+ {
72739+ .procname = "chroot_deny_unix",
72740+ .data = &grsec_enable_chroot_unix,
72741+ .maxlen = sizeof(int),
72742+ .mode = 0600,
72743+ .proc_handler = &proc_dointvec,
72744+ },
72745+#endif
72746+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72747+ {
72748+ .procname = "chroot_deny_mount",
72749+ .data = &grsec_enable_chroot_mount,
72750+ .maxlen = sizeof(int),
72751+ .mode = 0600,
72752+ .proc_handler = &proc_dointvec,
72753+ },
72754+#endif
72755+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72756+ {
72757+ .procname = "chroot_deny_fchdir",
72758+ .data = &grsec_enable_chroot_fchdir,
72759+ .maxlen = sizeof(int),
72760+ .mode = 0600,
72761+ .proc_handler = &proc_dointvec,
72762+ },
72763+#endif
72764+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72765+ {
72766+ .procname = "chroot_deny_chroot",
72767+ .data = &grsec_enable_chroot_double,
72768+ .maxlen = sizeof(int),
72769+ .mode = 0600,
72770+ .proc_handler = &proc_dointvec,
72771+ },
72772+#endif
72773+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72774+ {
72775+ .procname = "chroot_deny_pivot",
72776+ .data = &grsec_enable_chroot_pivot,
72777+ .maxlen = sizeof(int),
72778+ .mode = 0600,
72779+ .proc_handler = &proc_dointvec,
72780+ },
72781+#endif
72782+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72783+ {
72784+ .procname = "chroot_enforce_chdir",
72785+ .data = &grsec_enable_chroot_chdir,
72786+ .maxlen = sizeof(int),
72787+ .mode = 0600,
72788+ .proc_handler = &proc_dointvec,
72789+ },
72790+#endif
72791+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72792+ {
72793+ .procname = "chroot_deny_chmod",
72794+ .data = &grsec_enable_chroot_chmod,
72795+ .maxlen = sizeof(int),
72796+ .mode = 0600,
72797+ .proc_handler = &proc_dointvec,
72798+ },
72799+#endif
72800+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72801+ {
72802+ .procname = "chroot_deny_mknod",
72803+ .data = &grsec_enable_chroot_mknod,
72804+ .maxlen = sizeof(int),
72805+ .mode = 0600,
72806+ .proc_handler = &proc_dointvec,
72807+ },
72808+#endif
72809+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72810+ {
72811+ .procname = "chroot_restrict_nice",
72812+ .data = &grsec_enable_chroot_nice,
72813+ .maxlen = sizeof(int),
72814+ .mode = 0600,
72815+ .proc_handler = &proc_dointvec,
72816+ },
72817+#endif
72818+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72819+ {
72820+ .procname = "chroot_execlog",
72821+ .data = &grsec_enable_chroot_execlog,
72822+ .maxlen = sizeof(int),
72823+ .mode = 0600,
72824+ .proc_handler = &proc_dointvec,
72825+ },
72826+#endif
72827+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72828+ {
72829+ .procname = "chroot_caps",
72830+ .data = &grsec_enable_chroot_caps,
72831+ .maxlen = sizeof(int),
72832+ .mode = 0600,
72833+ .proc_handler = &proc_dointvec,
72834+ },
72835+#endif
72836+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72837+ {
72838+ .procname = "chroot_deny_sysctl",
72839+ .data = &grsec_enable_chroot_sysctl,
72840+ .maxlen = sizeof(int),
72841+ .mode = 0600,
72842+ .proc_handler = &proc_dointvec,
72843+ },
72844+#endif
72845+#ifdef CONFIG_GRKERNSEC_TPE
72846+ {
72847+ .procname = "tpe",
72848+ .data = &grsec_enable_tpe,
72849+ .maxlen = sizeof(int),
72850+ .mode = 0600,
72851+ .proc_handler = &proc_dointvec,
72852+ },
72853+ {
72854+ .procname = "tpe_gid",
72855+ .data = &grsec_tpe_gid,
72856+ .maxlen = sizeof(int),
72857+ .mode = 0600,
72858+ .proc_handler = &proc_dointvec,
72859+ },
72860+#endif
72861+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72862+ {
72863+ .procname = "tpe_invert",
72864+ .data = &grsec_enable_tpe_invert,
72865+ .maxlen = sizeof(int),
72866+ .mode = 0600,
72867+ .proc_handler = &proc_dointvec,
72868+ },
72869+#endif
72870+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72871+ {
72872+ .procname = "tpe_restrict_all",
72873+ .data = &grsec_enable_tpe_all,
72874+ .maxlen = sizeof(int),
72875+ .mode = 0600,
72876+ .proc_handler = &proc_dointvec,
72877+ },
72878+#endif
72879+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72880+ {
72881+ .procname = "socket_all",
72882+ .data = &grsec_enable_socket_all,
72883+ .maxlen = sizeof(int),
72884+ .mode = 0600,
72885+ .proc_handler = &proc_dointvec,
72886+ },
72887+ {
72888+ .procname = "socket_all_gid",
72889+ .data = &grsec_socket_all_gid,
72890+ .maxlen = sizeof(int),
72891+ .mode = 0600,
72892+ .proc_handler = &proc_dointvec,
72893+ },
72894+#endif
72895+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72896+ {
72897+ .procname = "socket_client",
72898+ .data = &grsec_enable_socket_client,
72899+ .maxlen = sizeof(int),
72900+ .mode = 0600,
72901+ .proc_handler = &proc_dointvec,
72902+ },
72903+ {
72904+ .procname = "socket_client_gid",
72905+ .data = &grsec_socket_client_gid,
72906+ .maxlen = sizeof(int),
72907+ .mode = 0600,
72908+ .proc_handler = &proc_dointvec,
72909+ },
72910+#endif
72911+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72912+ {
72913+ .procname = "socket_server",
72914+ .data = &grsec_enable_socket_server,
72915+ .maxlen = sizeof(int),
72916+ .mode = 0600,
72917+ .proc_handler = &proc_dointvec,
72918+ },
72919+ {
72920+ .procname = "socket_server_gid",
72921+ .data = &grsec_socket_server_gid,
72922+ .maxlen = sizeof(int),
72923+ .mode = 0600,
72924+ .proc_handler = &proc_dointvec,
72925+ },
72926+#endif
72927+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72928+ {
72929+ .procname = "audit_group",
72930+ .data = &grsec_enable_group,
72931+ .maxlen = sizeof(int),
72932+ .mode = 0600,
72933+ .proc_handler = &proc_dointvec,
72934+ },
72935+ {
72936+ .procname = "audit_gid",
72937+ .data = &grsec_audit_gid,
72938+ .maxlen = sizeof(int),
72939+ .mode = 0600,
72940+ .proc_handler = &proc_dointvec,
72941+ },
72942+#endif
72943+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72944+ {
72945+ .procname = "audit_chdir",
72946+ .data = &grsec_enable_chdir,
72947+ .maxlen = sizeof(int),
72948+ .mode = 0600,
72949+ .proc_handler = &proc_dointvec,
72950+ },
72951+#endif
72952+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72953+ {
72954+ .procname = "audit_mount",
72955+ .data = &grsec_enable_mount,
72956+ .maxlen = sizeof(int),
72957+ .mode = 0600,
72958+ .proc_handler = &proc_dointvec,
72959+ },
72960+#endif
72961+#ifdef CONFIG_GRKERNSEC_DMESG
72962+ {
72963+ .procname = "dmesg",
72964+ .data = &grsec_enable_dmesg,
72965+ .maxlen = sizeof(int),
72966+ .mode = 0600,
72967+ .proc_handler = &proc_dointvec,
72968+ },
72969+#endif
72970+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72971+ {
72972+ .procname = "chroot_findtask",
72973+ .data = &grsec_enable_chroot_findtask,
72974+ .maxlen = sizeof(int),
72975+ .mode = 0600,
72976+ .proc_handler = &proc_dointvec,
72977+ },
72978+#endif
72979+#ifdef CONFIG_GRKERNSEC_RESLOG
72980+ {
72981+ .procname = "resource_logging",
72982+ .data = &grsec_resource_logging,
72983+ .maxlen = sizeof(int),
72984+ .mode = 0600,
72985+ .proc_handler = &proc_dointvec,
72986+ },
72987+#endif
72988+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72989+ {
72990+ .procname = "audit_ptrace",
72991+ .data = &grsec_enable_audit_ptrace,
72992+ .maxlen = sizeof(int),
72993+ .mode = 0600,
72994+ .proc_handler = &proc_dointvec,
72995+ },
72996+#endif
72997+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72998+ {
72999+ .procname = "harden_ptrace",
73000+ .data = &grsec_enable_harden_ptrace,
73001+ .maxlen = sizeof(int),
73002+ .mode = 0600,
73003+ .proc_handler = &proc_dointvec,
73004+ },
73005+#endif
73006+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73007+ {
73008+ .procname = "harden_ipc",
73009+ .data = &grsec_enable_harden_ipc,
73010+ .maxlen = sizeof(int),
73011+ .mode = 0600,
73012+ .proc_handler = &proc_dointvec,
73013+ },
73014+#endif
73015+ {
73016+ .procname = "grsec_lock",
73017+ .data = &grsec_lock,
73018+ .maxlen = sizeof(int),
73019+ .mode = 0600,
73020+ .proc_handler = &proc_dointvec,
73021+ },
73022+#endif
73023+#ifdef CONFIG_GRKERNSEC_ROFS
73024+ {
73025+ .procname = "romount_protect",
73026+ .data = &grsec_enable_rofs,
73027+ .maxlen = sizeof(int),
73028+ .mode = 0600,
73029+ .proc_handler = &proc_dointvec_minmax,
73030+ .extra1 = &one,
73031+ .extra2 = &one,
73032+ },
73033+#endif
73034+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
73035+ {
73036+ .procname = "deny_new_usb",
73037+ .data = &grsec_deny_new_usb,
73038+ .maxlen = sizeof(int),
73039+ .mode = 0600,
73040+ .proc_handler = &proc_dointvec,
73041+ },
73042+#endif
73043+ { }
73044+};
73045+#endif
73046diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
73047new file mode 100644
73048index 0000000..0dc13c3
73049--- /dev/null
73050+++ b/grsecurity/grsec_time.c
73051@@ -0,0 +1,16 @@
73052+#include <linux/kernel.h>
73053+#include <linux/sched.h>
73054+#include <linux/grinternal.h>
73055+#include <linux/module.h>
73056+
73057+void
73058+gr_log_timechange(void)
73059+{
73060+#ifdef CONFIG_GRKERNSEC_TIME
73061+ if (grsec_enable_time)
73062+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
73063+#endif
73064+ return;
73065+}
73066+
73067+EXPORT_SYMBOL(gr_log_timechange);
73068diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
73069new file mode 100644
73070index 0000000..ee57dcf
73071--- /dev/null
73072+++ b/grsecurity/grsec_tpe.c
73073@@ -0,0 +1,73 @@
73074+#include <linux/kernel.h>
73075+#include <linux/sched.h>
73076+#include <linux/file.h>
73077+#include <linux/fs.h>
73078+#include <linux/grinternal.h>
73079+
73080+extern int gr_acl_tpe_check(void);
73081+
73082+int
73083+gr_tpe_allow(const struct file *file)
73084+{
73085+#ifdef CONFIG_GRKERNSEC
73086+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
73087+ const struct cred *cred = current_cred();
73088+ char *msg = NULL;
73089+ char *msg2 = NULL;
73090+
73091+ // never restrict root
73092+ if (gr_is_global_root(cred->uid))
73093+ return 1;
73094+
73095+ if (grsec_enable_tpe) {
73096+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73097+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
73098+ msg = "not being in trusted group";
73099+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
73100+ msg = "being in untrusted group";
73101+#else
73102+ if (in_group_p(grsec_tpe_gid))
73103+ msg = "being in untrusted group";
73104+#endif
73105+ }
73106+ if (!msg && gr_acl_tpe_check())
73107+ msg = "being in untrusted role";
73108+
73109+ // not in any affected group/role
73110+ if (!msg)
73111+ goto next_check;
73112+
73113+ if (gr_is_global_nonroot(inode->i_uid))
73114+ msg2 = "file in non-root-owned directory";
73115+ else if (inode->i_mode & S_IWOTH)
73116+ msg2 = "file in world-writable directory";
73117+ else if (inode->i_mode & S_IWGRP)
73118+ msg2 = "file in group-writable directory";
73119+
73120+ if (msg && msg2) {
73121+ char fullmsg[70] = {0};
73122+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
73123+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
73124+ return 0;
73125+ }
73126+ msg = NULL;
73127+next_check:
73128+#ifdef CONFIG_GRKERNSEC_TPE_ALL
73129+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
73130+ return 1;
73131+
73132+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
73133+ msg = "directory not owned by user";
73134+ else if (inode->i_mode & S_IWOTH)
73135+ msg = "file in world-writable directory";
73136+ else if (inode->i_mode & S_IWGRP)
73137+ msg = "file in group-writable directory";
73138+
73139+ if (msg) {
73140+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
73141+ return 0;
73142+ }
73143+#endif
73144+#endif
73145+ return 1;
73146+}
73147diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
73148new file mode 100644
73149index 0000000..ae02d8e
73150--- /dev/null
73151+++ b/grsecurity/grsec_usb.c
73152@@ -0,0 +1,15 @@
73153+#include <linux/kernel.h>
73154+#include <linux/grinternal.h>
73155+#include <linux/module.h>
73156+
73157+int gr_handle_new_usb(void)
73158+{
73159+#ifdef CONFIG_GRKERNSEC_DENYUSB
73160+ if (grsec_deny_new_usb) {
73161+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
73162+ return 1;
73163+ }
73164+#endif
73165+ return 0;
73166+}
73167+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
73168diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
73169new file mode 100644
73170index 0000000..9f7b1ac
73171--- /dev/null
73172+++ b/grsecurity/grsum.c
73173@@ -0,0 +1,61 @@
73174+#include <linux/err.h>
73175+#include <linux/kernel.h>
73176+#include <linux/sched.h>
73177+#include <linux/mm.h>
73178+#include <linux/scatterlist.h>
73179+#include <linux/crypto.h>
73180+#include <linux/gracl.h>
73181+
73182+
73183+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
73184+#error "crypto and sha256 must be built into the kernel"
73185+#endif
73186+
73187+int
73188+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
73189+{
73190+ char *p;
73191+ struct crypto_hash *tfm;
73192+ struct hash_desc desc;
73193+ struct scatterlist sg;
73194+ unsigned char temp_sum[GR_SHA_LEN];
73195+ volatile int retval = 0;
73196+ volatile int dummy = 0;
73197+ unsigned int i;
73198+
73199+ sg_init_table(&sg, 1);
73200+
73201+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
73202+ if (IS_ERR(tfm)) {
73203+ /* should never happen, since sha256 should be built in */
73204+ return 1;
73205+ }
73206+
73207+ desc.tfm = tfm;
73208+ desc.flags = 0;
73209+
73210+ crypto_hash_init(&desc);
73211+
73212+ p = salt;
73213+ sg_set_buf(&sg, p, GR_SALT_LEN);
73214+ crypto_hash_update(&desc, &sg, sg.length);
73215+
73216+ p = entry->pw;
73217+ sg_set_buf(&sg, p, strlen(p));
73218+
73219+ crypto_hash_update(&desc, &sg, sg.length);
73220+
73221+ crypto_hash_final(&desc, temp_sum);
73222+
73223+ memset(entry->pw, 0, GR_PW_LEN);
73224+
73225+ for (i = 0; i < GR_SHA_LEN; i++)
73226+ if (sum[i] != temp_sum[i])
73227+ retval = 1;
73228+ else
73229+ dummy = 1; // waste a cycle
73230+
73231+ crypto_free_hash(tfm);
73232+
73233+ return retval;
73234+}
73235diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
73236index 77ff547..181834f 100644
73237--- a/include/asm-generic/4level-fixup.h
73238+++ b/include/asm-generic/4level-fixup.h
73239@@ -13,8 +13,10 @@
73240 #define pmd_alloc(mm, pud, address) \
73241 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
73242 NULL: pmd_offset(pud, address))
73243+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
73244
73245 #define pud_alloc(mm, pgd, address) (pgd)
73246+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
73247 #define pud_offset(pgd, start) (pgd)
73248 #define pud_none(pud) 0
73249 #define pud_bad(pud) 0
73250diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
73251index b7babf0..04ad282 100644
73252--- a/include/asm-generic/atomic-long.h
73253+++ b/include/asm-generic/atomic-long.h
73254@@ -22,6 +22,12 @@
73255
73256 typedef atomic64_t atomic_long_t;
73257
73258+#ifdef CONFIG_PAX_REFCOUNT
73259+typedef atomic64_unchecked_t atomic_long_unchecked_t;
73260+#else
73261+typedef atomic64_t atomic_long_unchecked_t;
73262+#endif
73263+
73264 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
73265
73266 static inline long atomic_long_read(atomic_long_t *l)
73267@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
73268 return (long)atomic64_read(v);
73269 }
73270
73271+#ifdef CONFIG_PAX_REFCOUNT
73272+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
73273+{
73274+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73275+
73276+ return (long)atomic64_read_unchecked(v);
73277+}
73278+#endif
73279+
73280 static inline void atomic_long_set(atomic_long_t *l, long i)
73281 {
73282 atomic64_t *v = (atomic64_t *)l;
73283@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
73284 atomic64_set(v, i);
73285 }
73286
73287+#ifdef CONFIG_PAX_REFCOUNT
73288+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
73289+{
73290+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73291+
73292+ atomic64_set_unchecked(v, i);
73293+}
73294+#endif
73295+
73296 static inline void atomic_long_inc(atomic_long_t *l)
73297 {
73298 atomic64_t *v = (atomic64_t *)l;
73299@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
73300 atomic64_inc(v);
73301 }
73302
73303+#ifdef CONFIG_PAX_REFCOUNT
73304+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
73305+{
73306+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73307+
73308+ atomic64_inc_unchecked(v);
73309+}
73310+#endif
73311+
73312 static inline void atomic_long_dec(atomic_long_t *l)
73313 {
73314 atomic64_t *v = (atomic64_t *)l;
73315@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
73316 atomic64_dec(v);
73317 }
73318
73319+#ifdef CONFIG_PAX_REFCOUNT
73320+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
73321+{
73322+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73323+
73324+ atomic64_dec_unchecked(v);
73325+}
73326+#endif
73327+
73328 static inline void atomic_long_add(long i, atomic_long_t *l)
73329 {
73330 atomic64_t *v = (atomic64_t *)l;
73331@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
73332 atomic64_add(i, v);
73333 }
73334
73335+#ifdef CONFIG_PAX_REFCOUNT
73336+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
73337+{
73338+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73339+
73340+ atomic64_add_unchecked(i, v);
73341+}
73342+#endif
73343+
73344 static inline void atomic_long_sub(long i, atomic_long_t *l)
73345 {
73346 atomic64_t *v = (atomic64_t *)l;
73347@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73348 atomic64_sub(i, v);
73349 }
73350
73351+#ifdef CONFIG_PAX_REFCOUNT
73352+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73353+{
73354+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73355+
73356+ atomic64_sub_unchecked(i, v);
73357+}
73358+#endif
73359+
73360 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73361 {
73362 atomic64_t *v = (atomic64_t *)l;
73363@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
73364 return (long)atomic64_add_return(i, v);
73365 }
73366
73367+#ifdef CONFIG_PAX_REFCOUNT
73368+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73369+{
73370+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73371+
73372+ return (long)atomic64_add_return_unchecked(i, v);
73373+}
73374+#endif
73375+
73376 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73377 {
73378 atomic64_t *v = (atomic64_t *)l;
73379@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73380 return (long)atomic64_inc_return(v);
73381 }
73382
73383+#ifdef CONFIG_PAX_REFCOUNT
73384+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73385+{
73386+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
73387+
73388+ return (long)atomic64_inc_return_unchecked(v);
73389+}
73390+#endif
73391+
73392 static inline long atomic_long_dec_return(atomic_long_t *l)
73393 {
73394 atomic64_t *v = (atomic64_t *)l;
73395@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73396
73397 typedef atomic_t atomic_long_t;
73398
73399+#ifdef CONFIG_PAX_REFCOUNT
73400+typedef atomic_unchecked_t atomic_long_unchecked_t;
73401+#else
73402+typedef atomic_t atomic_long_unchecked_t;
73403+#endif
73404+
73405 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
73406 static inline long atomic_long_read(atomic_long_t *l)
73407 {
73408@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
73409 return (long)atomic_read(v);
73410 }
73411
73412+#ifdef CONFIG_PAX_REFCOUNT
73413+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
73414+{
73415+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73416+
73417+ return (long)atomic_read_unchecked(v);
73418+}
73419+#endif
73420+
73421 static inline void atomic_long_set(atomic_long_t *l, long i)
73422 {
73423 atomic_t *v = (atomic_t *)l;
73424@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
73425 atomic_set(v, i);
73426 }
73427
73428+#ifdef CONFIG_PAX_REFCOUNT
73429+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
73430+{
73431+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73432+
73433+ atomic_set_unchecked(v, i);
73434+}
73435+#endif
73436+
73437 static inline void atomic_long_inc(atomic_long_t *l)
73438 {
73439 atomic_t *v = (atomic_t *)l;
73440@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
73441 atomic_inc(v);
73442 }
73443
73444+#ifdef CONFIG_PAX_REFCOUNT
73445+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
73446+{
73447+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73448+
73449+ atomic_inc_unchecked(v);
73450+}
73451+#endif
73452+
73453 static inline void atomic_long_dec(atomic_long_t *l)
73454 {
73455 atomic_t *v = (atomic_t *)l;
73456@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
73457 atomic_dec(v);
73458 }
73459
73460+#ifdef CONFIG_PAX_REFCOUNT
73461+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
73462+{
73463+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73464+
73465+ atomic_dec_unchecked(v);
73466+}
73467+#endif
73468+
73469 static inline void atomic_long_add(long i, atomic_long_t *l)
73470 {
73471 atomic_t *v = (atomic_t *)l;
73472@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
73473 atomic_add(i, v);
73474 }
73475
73476+#ifdef CONFIG_PAX_REFCOUNT
73477+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
73478+{
73479+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73480+
73481+ atomic_add_unchecked(i, v);
73482+}
73483+#endif
73484+
73485 static inline void atomic_long_sub(long i, atomic_long_t *l)
73486 {
73487 atomic_t *v = (atomic_t *)l;
73488@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73489 atomic_sub(i, v);
73490 }
73491
73492+#ifdef CONFIG_PAX_REFCOUNT
73493+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73494+{
73495+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73496+
73497+ atomic_sub_unchecked(i, v);
73498+}
73499+#endif
73500+
73501 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73502 {
73503 atomic_t *v = (atomic_t *)l;
73504@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
73505 return (long)atomic_add_return(i, v);
73506 }
73507
73508+#ifdef CONFIG_PAX_REFCOUNT
73509+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73510+{
73511+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73512+
73513+ return (long)atomic_add_return_unchecked(i, v);
73514+}
73515+
73516+#endif
73517+
73518 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73519 {
73520 atomic_t *v = (atomic_t *)l;
73521@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73522 return (long)atomic_inc_return(v);
73523 }
73524
73525+#ifdef CONFIG_PAX_REFCOUNT
73526+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73527+{
73528+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73529+
73530+ return (long)atomic_inc_return_unchecked(v);
73531+}
73532+#endif
73533+
73534 static inline long atomic_long_dec_return(atomic_long_t *l)
73535 {
73536 atomic_t *v = (atomic_t *)l;
73537@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73538
73539 #endif /* BITS_PER_LONG == 64 */
73540
73541+#ifdef CONFIG_PAX_REFCOUNT
73542+static inline void pax_refcount_needs_these_functions(void)
73543+{
73544+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
73545+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
73546+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
73547+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
73548+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
73549+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
73550+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
73551+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
73552+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
73553+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
73554+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
73555+#ifdef CONFIG_X86
73556+ atomic_clear_mask_unchecked(0, NULL);
73557+ atomic_set_mask_unchecked(0, NULL);
73558+#endif
73559+
73560+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
73561+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
73562+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
73563+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
73564+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
73565+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
73566+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
73567+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
73568+}
73569+#else
73570+#define atomic_read_unchecked(v) atomic_read(v)
73571+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
73572+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
73573+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
73574+#define atomic_inc_unchecked(v) atomic_inc(v)
73575+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
73576+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
73577+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
73578+#define atomic_dec_unchecked(v) atomic_dec(v)
73579+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
73580+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
73581+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
73582+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
73583+
73584+#define atomic_long_read_unchecked(v) atomic_long_read(v)
73585+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
73586+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
73587+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
73588+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
73589+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
73590+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
73591+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
73592+#endif
73593+
73594 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
73595diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
73596index 33bd2de..f31bff97 100644
73597--- a/include/asm-generic/atomic.h
73598+++ b/include/asm-generic/atomic.h
73599@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
73600 * Atomically clears the bits set in @mask from @v
73601 */
73602 #ifndef atomic_clear_mask
73603-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
73604+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
73605 {
73606 unsigned long flags;
73607
73608diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
73609index b18ce4f..2ee2843 100644
73610--- a/include/asm-generic/atomic64.h
73611+++ b/include/asm-generic/atomic64.h
73612@@ -16,6 +16,8 @@ typedef struct {
73613 long long counter;
73614 } atomic64_t;
73615
73616+typedef atomic64_t atomic64_unchecked_t;
73617+
73618 #define ATOMIC64_INIT(i) { (i) }
73619
73620 extern long long atomic64_read(const atomic64_t *v);
73621@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
73622 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
73623 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
73624
73625+#define atomic64_read_unchecked(v) atomic64_read(v)
73626+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
73627+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
73628+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
73629+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
73630+#define atomic64_inc_unchecked(v) atomic64_inc(v)
73631+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
73632+#define atomic64_dec_unchecked(v) atomic64_dec(v)
73633+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
73634+
73635 #endif /* _ASM_GENERIC_ATOMIC64_H */
73636diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
73637index a60a7cc..0fe12f2 100644
73638--- a/include/asm-generic/bitops/__fls.h
73639+++ b/include/asm-generic/bitops/__fls.h
73640@@ -9,7 +9,7 @@
73641 *
73642 * Undefined if no set bit exists, so code should check against 0 first.
73643 */
73644-static __always_inline unsigned long __fls(unsigned long word)
73645+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
73646 {
73647 int num = BITS_PER_LONG - 1;
73648
73649diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
73650index 0576d1f..dad6c71 100644
73651--- a/include/asm-generic/bitops/fls.h
73652+++ b/include/asm-generic/bitops/fls.h
73653@@ -9,7 +9,7 @@
73654 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
73655 */
73656
73657-static __always_inline int fls(int x)
73658+static __always_inline int __intentional_overflow(-1) fls(int x)
73659 {
73660 int r = 32;
73661
73662diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
73663index b097cf8..3d40e14 100644
73664--- a/include/asm-generic/bitops/fls64.h
73665+++ b/include/asm-generic/bitops/fls64.h
73666@@ -15,7 +15,7 @@
73667 * at position 64.
73668 */
73669 #if BITS_PER_LONG == 32
73670-static __always_inline int fls64(__u64 x)
73671+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
73672 {
73673 __u32 h = x >> 32;
73674 if (h)
73675@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
73676 return fls(x);
73677 }
73678 #elif BITS_PER_LONG == 64
73679-static __always_inline int fls64(__u64 x)
73680+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
73681 {
73682 if (x == 0)
73683 return 0;
73684diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
73685index 1bfcfe5..e04c5c9 100644
73686--- a/include/asm-generic/cache.h
73687+++ b/include/asm-generic/cache.h
73688@@ -6,7 +6,7 @@
73689 * cache lines need to provide their own cache.h.
73690 */
73691
73692-#define L1_CACHE_SHIFT 5
73693-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
73694+#define L1_CACHE_SHIFT 5UL
73695+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
73696
73697 #endif /* __ASM_GENERIC_CACHE_H */
73698diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
73699index 0d68a1e..b74a761 100644
73700--- a/include/asm-generic/emergency-restart.h
73701+++ b/include/asm-generic/emergency-restart.h
73702@@ -1,7 +1,7 @@
73703 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
73704 #define _ASM_GENERIC_EMERGENCY_RESTART_H
73705
73706-static inline void machine_emergency_restart(void)
73707+static inline __noreturn void machine_emergency_restart(void)
73708 {
73709 machine_restart(NULL);
73710 }
73711diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
73712index 90f99c7..00ce236 100644
73713--- a/include/asm-generic/kmap_types.h
73714+++ b/include/asm-generic/kmap_types.h
73715@@ -2,9 +2,9 @@
73716 #define _ASM_GENERIC_KMAP_TYPES_H
73717
73718 #ifdef __WITH_KM_FENCE
73719-# define KM_TYPE_NR 41
73720+# define KM_TYPE_NR 42
73721 #else
73722-# define KM_TYPE_NR 20
73723+# define KM_TYPE_NR 21
73724 #endif
73725
73726 #endif
73727diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
73728index 9ceb03b..62b0b8f 100644
73729--- a/include/asm-generic/local.h
73730+++ b/include/asm-generic/local.h
73731@@ -23,24 +23,37 @@ typedef struct
73732 atomic_long_t a;
73733 } local_t;
73734
73735+typedef struct {
73736+ atomic_long_unchecked_t a;
73737+} local_unchecked_t;
73738+
73739 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
73740
73741 #define local_read(l) atomic_long_read(&(l)->a)
73742+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
73743 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
73744+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
73745 #define local_inc(l) atomic_long_inc(&(l)->a)
73746+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
73747 #define local_dec(l) atomic_long_dec(&(l)->a)
73748+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
73749 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
73750+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
73751 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
73752+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
73753
73754 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
73755 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
73756 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
73757 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
73758 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
73759+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
73760 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
73761 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
73762+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
73763
73764 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73765+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73766 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
73767 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
73768 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
73769diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
73770index 725612b..9cc513a 100644
73771--- a/include/asm-generic/pgtable-nopmd.h
73772+++ b/include/asm-generic/pgtable-nopmd.h
73773@@ -1,14 +1,19 @@
73774 #ifndef _PGTABLE_NOPMD_H
73775 #define _PGTABLE_NOPMD_H
73776
73777-#ifndef __ASSEMBLY__
73778-
73779 #include <asm-generic/pgtable-nopud.h>
73780
73781-struct mm_struct;
73782-
73783 #define __PAGETABLE_PMD_FOLDED
73784
73785+#define PMD_SHIFT PUD_SHIFT
73786+#define PTRS_PER_PMD 1
73787+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
73788+#define PMD_MASK (~(PMD_SIZE-1))
73789+
73790+#ifndef __ASSEMBLY__
73791+
73792+struct mm_struct;
73793+
73794 /*
73795 * Having the pmd type consist of a pud gets the size right, and allows
73796 * us to conceptually access the pud entry that this pmd is folded into
73797@@ -16,11 +21,6 @@ struct mm_struct;
73798 */
73799 typedef struct { pud_t pud; } pmd_t;
73800
73801-#define PMD_SHIFT PUD_SHIFT
73802-#define PTRS_PER_PMD 1
73803-#define PMD_SIZE (1UL << PMD_SHIFT)
73804-#define PMD_MASK (~(PMD_SIZE-1))
73805-
73806 /*
73807 * The "pud_xxx()" functions here are trivial for a folded two-level
73808 * setup: the pmd is never bad, and a pmd always exists (as it's folded
73809diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
73810index 810431d..0ec4804f 100644
73811--- a/include/asm-generic/pgtable-nopud.h
73812+++ b/include/asm-generic/pgtable-nopud.h
73813@@ -1,10 +1,15 @@
73814 #ifndef _PGTABLE_NOPUD_H
73815 #define _PGTABLE_NOPUD_H
73816
73817-#ifndef __ASSEMBLY__
73818-
73819 #define __PAGETABLE_PUD_FOLDED
73820
73821+#define PUD_SHIFT PGDIR_SHIFT
73822+#define PTRS_PER_PUD 1
73823+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
73824+#define PUD_MASK (~(PUD_SIZE-1))
73825+
73826+#ifndef __ASSEMBLY__
73827+
73828 /*
73829 * Having the pud type consist of a pgd gets the size right, and allows
73830 * us to conceptually access the pgd entry that this pud is folded into
73831@@ -12,11 +17,6 @@
73832 */
73833 typedef struct { pgd_t pgd; } pud_t;
73834
73835-#define PUD_SHIFT PGDIR_SHIFT
73836-#define PTRS_PER_PUD 1
73837-#define PUD_SIZE (1UL << PUD_SHIFT)
73838-#define PUD_MASK (~(PUD_SIZE-1))
73839-
73840 /*
73841 * The "pgd_xxx()" functions here are trivial for a folded two-level
73842 * setup: the pud is never bad, and a pud always exists (as it's folded
73843@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
73844 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
73845
73846 #define pgd_populate(mm, pgd, pud) do { } while (0)
73847+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
73848 /*
73849 * (puds are folded into pgds so this doesn't get actually called,
73850 * but the define is needed for a generic inline function.)
73851diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
73852index f330d28..83ce28f 100644
73853--- a/include/asm-generic/pgtable.h
73854+++ b/include/asm-generic/pgtable.h
73855@@ -737,6 +737,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
73856 }
73857 #endif /* CONFIG_NUMA_BALANCING */
73858
73859+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
73860+#ifdef CONFIG_PAX_KERNEXEC
73861+#error KERNEXEC requires pax_open_kernel
73862+#else
73863+static inline unsigned long pax_open_kernel(void) { return 0; }
73864+#endif
73865+#endif
73866+
73867+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
73868+#ifdef CONFIG_PAX_KERNEXEC
73869+#error KERNEXEC requires pax_close_kernel
73870+#else
73871+static inline unsigned long pax_close_kernel(void) { return 0; }
73872+#endif
73873+#endif
73874+
73875 #endif /* CONFIG_MMU */
73876
73877 #endif /* !__ASSEMBLY__ */
73878diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
73879index dc1269c..48a4f51 100644
73880--- a/include/asm-generic/uaccess.h
73881+++ b/include/asm-generic/uaccess.h
73882@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
73883 return __clear_user(to, n);
73884 }
73885
73886+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
73887+#ifdef CONFIG_PAX_MEMORY_UDEREF
73888+#error UDEREF requires pax_open_userland
73889+#else
73890+static inline unsigned long pax_open_userland(void) { return 0; }
73891+#endif
73892+#endif
73893+
73894+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
73895+#ifdef CONFIG_PAX_MEMORY_UDEREF
73896+#error UDEREF requires pax_close_userland
73897+#else
73898+static inline unsigned long pax_close_userland(void) { return 0; }
73899+#endif
73900+#endif
73901+
73902 #endif /* __ASM_GENERIC_UACCESS_H */
73903diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
73904index 83e2c31..eeb4a04 100644
73905--- a/include/asm-generic/vmlinux.lds.h
73906+++ b/include/asm-generic/vmlinux.lds.h
73907@@ -232,6 +232,7 @@
73908 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
73909 VMLINUX_SYMBOL(__start_rodata) = .; \
73910 *(.rodata) *(.rodata.*) \
73911+ *(.data..read_only) \
73912 *(__vermagic) /* Kernel version magic */ \
73913 . = ALIGN(8); \
73914 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
73915@@ -715,17 +716,18 @@
73916 * section in the linker script will go there too. @phdr should have
73917 * a leading colon.
73918 *
73919- * Note that this macros defines __per_cpu_load as an absolute symbol.
73920+ * Note that this macros defines per_cpu_load as an absolute symbol.
73921 * If there is no need to put the percpu section at a predetermined
73922 * address, use PERCPU_SECTION.
73923 */
73924 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
73925- VMLINUX_SYMBOL(__per_cpu_load) = .; \
73926- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
73927+ per_cpu_load = .; \
73928+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
73929 - LOAD_OFFSET) { \
73930+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
73931 PERCPU_INPUT(cacheline) \
73932 } phdr \
73933- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
73934+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
73935
73936 /**
73937 * PERCPU_SECTION - define output section for percpu area, simple version
73938diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
73939index 418d270..bfd2794 100644
73940--- a/include/crypto/algapi.h
73941+++ b/include/crypto/algapi.h
73942@@ -34,7 +34,7 @@ struct crypto_type {
73943 unsigned int maskclear;
73944 unsigned int maskset;
73945 unsigned int tfmsize;
73946-};
73947+} __do_const;
73948
73949 struct crypto_instance {
73950 struct crypto_alg alg;
73951diff --git a/include/drm/drmP.h b/include/drm/drmP.h
73952index b46fb45..b30d6d5 100644
73953--- a/include/drm/drmP.h
73954+++ b/include/drm/drmP.h
73955@@ -66,6 +66,7 @@
73956 #include <linux/workqueue.h>
73957 #include <linux/poll.h>
73958 #include <asm/pgalloc.h>
73959+#include <asm/local.h>
73960 #include <drm/drm.h>
73961 #include <drm/drm_sarea.h>
73962 #include <drm/drm_vma_manager.h>
73963@@ -277,10 +278,12 @@ do { \
73964 * \param cmd command.
73965 * \param arg argument.
73966 */
73967-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
73968+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
73969+ struct drm_file *file_priv);
73970+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
73971 struct drm_file *file_priv);
73972
73973-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73974+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
73975 unsigned long arg);
73976
73977 #define DRM_IOCTL_NR(n) _IOC_NR(n)
73978@@ -296,10 +299,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73979 struct drm_ioctl_desc {
73980 unsigned int cmd;
73981 int flags;
73982- drm_ioctl_t *func;
73983+ drm_ioctl_t func;
73984 unsigned int cmd_drv;
73985 const char *name;
73986-};
73987+} __do_const;
73988
73989 /**
73990 * Creates a driver or general drm_ioctl_desc array entry for the given
73991@@ -1027,7 +1030,7 @@ struct drm_info_list {
73992 int (*show)(struct seq_file*, void*); /** show callback */
73993 u32 driver_features; /**< Required driver features for this entry */
73994 void *data;
73995-};
73996+} __do_const;
73997
73998 /**
73999 * debugfs node structure. This structure represents a debugfs file.
74000@@ -1098,7 +1101,7 @@ struct drm_device {
74001
74002 /** \name Usage Counters */
74003 /*@{ */
74004- int open_count; /**< Outstanding files open */
74005+ local_t open_count; /**< Outstanding files open */
74006 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
74007 atomic_t vma_count; /**< Outstanding vma areas open */
74008 int buf_use; /**< Buffers in use -- cannot alloc */
74009@@ -1109,7 +1112,7 @@ struct drm_device {
74010 /*@{ */
74011 unsigned long counters;
74012 enum drm_stat_type types[15];
74013- atomic_t counts[15];
74014+ atomic_unchecked_t counts[15];
74015 /*@} */
74016
74017 struct list_head filelist;
74018diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
74019index f43d556..94d9343 100644
74020--- a/include/drm/drm_crtc_helper.h
74021+++ b/include/drm/drm_crtc_helper.h
74022@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
74023 struct drm_connector *connector);
74024 /* disable encoder when not in use - more explicit than dpms off */
74025 void (*disable)(struct drm_encoder *encoder);
74026-};
74027+} __no_const;
74028
74029 /**
74030 * drm_connector_helper_funcs - helper operations for connectors
74031diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
74032index 8a10f5c..5de7f5c 100644
74033--- a/include/drm/i915_pciids.h
74034+++ b/include/drm/i915_pciids.h
74035@@ -37,7 +37,7 @@
74036 */
74037 #define INTEL_VGA_DEVICE(id, info) { \
74038 0x8086, id, \
74039- ~0, ~0, \
74040+ PCI_ANY_ID, PCI_ANY_ID, \
74041 0x030000, 0xff0000, \
74042 (unsigned long) info }
74043
74044diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
74045index 72dcbe8..8db58d7 100644
74046--- a/include/drm/ttm/ttm_memory.h
74047+++ b/include/drm/ttm/ttm_memory.h
74048@@ -48,7 +48,7 @@
74049
74050 struct ttm_mem_shrink {
74051 int (*do_shrink) (struct ttm_mem_shrink *);
74052-};
74053+} __no_const;
74054
74055 /**
74056 * struct ttm_mem_global - Global memory accounting structure.
74057diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
74058index 4b840e8..155d235 100644
74059--- a/include/keys/asymmetric-subtype.h
74060+++ b/include/keys/asymmetric-subtype.h
74061@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
74062 /* Verify the signature on a key of this subtype (optional) */
74063 int (*verify_signature)(const struct key *key,
74064 const struct public_key_signature *sig);
74065-};
74066+} __do_const;
74067
74068 /**
74069 * asymmetric_key_subtype - Get the subtype from an asymmetric key
74070diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
74071index c1da539..1dcec55 100644
74072--- a/include/linux/atmdev.h
74073+++ b/include/linux/atmdev.h
74074@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
74075 #endif
74076
74077 struct k_atm_aal_stats {
74078-#define __HANDLE_ITEM(i) atomic_t i
74079+#define __HANDLE_ITEM(i) atomic_unchecked_t i
74080 __AAL_STAT_ITEMS
74081 #undef __HANDLE_ITEM
74082 };
74083@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
74084 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
74085 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
74086 struct module *owner;
74087-};
74088+} __do_const ;
74089
74090 struct atmphy_ops {
74091 int (*start)(struct atm_dev *dev);
74092diff --git a/include/linux/audit.h b/include/linux/audit.h
74093index 729a4d1..9b304ae 100644
74094--- a/include/linux/audit.h
74095+++ b/include/linux/audit.h
74096@@ -193,7 +193,7 @@ static inline void audit_ptrace(struct task_struct *t)
74097 extern unsigned int audit_serial(void);
74098 extern int auditsc_get_stamp(struct audit_context *ctx,
74099 struct timespec *t, unsigned int *serial);
74100-extern int audit_set_loginuid(kuid_t loginuid);
74101+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
74102
74103 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
74104 {
74105diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
74106index 7554fd4..0f86379 100644
74107--- a/include/linux/binfmts.h
74108+++ b/include/linux/binfmts.h
74109@@ -73,8 +73,10 @@ struct linux_binfmt {
74110 int (*load_binary)(struct linux_binprm *);
74111 int (*load_shlib)(struct file *);
74112 int (*core_dump)(struct coredump_params *cprm);
74113+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
74114+ void (*handle_mmap)(struct file *);
74115 unsigned long min_coredump; /* minimal dump size */
74116-};
74117+} __do_const;
74118
74119 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
74120
74121diff --git a/include/linux/bitops.h b/include/linux/bitops.h
74122index a3b6b82..2a7d758 100644
74123--- a/include/linux/bitops.h
74124+++ b/include/linux/bitops.h
74125@@ -91,7 +91,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
74126 * @word: value to rotate
74127 * @shift: bits to roll
74128 */
74129-static inline __u32 rol32(__u32 word, unsigned int shift)
74130+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
74131 {
74132 return (word << shift) | (word >> (32 - shift));
74133 }
74134@@ -101,7 +101,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
74135 * @word: value to rotate
74136 * @shift: bits to roll
74137 */
74138-static inline __u32 ror32(__u32 word, unsigned int shift)
74139+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
74140 {
74141 return (word >> shift) | (word << (32 - shift));
74142 }
74143@@ -157,7 +157,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
74144 return (__s32)(value << shift) >> shift;
74145 }
74146
74147-static inline unsigned fls_long(unsigned long l)
74148+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
74149 {
74150 if (sizeof(l) == 4)
74151 return fls(l);
74152diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
74153index 0e6f765..885bb2b 100644
74154--- a/include/linux/blkdev.h
74155+++ b/include/linux/blkdev.h
74156@@ -1537,7 +1537,7 @@ struct block_device_operations {
74157 /* this callback is with swap_lock and sometimes page table lock held */
74158 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
74159 struct module *owner;
74160-};
74161+} __do_const;
74162
74163 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
74164 unsigned long);
74165diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
74166index 7c2e030..b72475d 100644
74167--- a/include/linux/blktrace_api.h
74168+++ b/include/linux/blktrace_api.h
74169@@ -23,7 +23,7 @@ struct blk_trace {
74170 struct dentry *dir;
74171 struct dentry *dropped_file;
74172 struct dentry *msg_file;
74173- atomic_t dropped;
74174+ atomic_unchecked_t dropped;
74175 };
74176
74177 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
74178diff --git a/include/linux/cache.h b/include/linux/cache.h
74179index 4c57065..40346da 100644
74180--- a/include/linux/cache.h
74181+++ b/include/linux/cache.h
74182@@ -16,6 +16,14 @@
74183 #define __read_mostly
74184 #endif
74185
74186+#ifndef __read_only
74187+#ifdef CONFIG_PAX_KERNEXEC
74188+#error KERNEXEC requires __read_only
74189+#else
74190+#define __read_only __read_mostly
74191+#endif
74192+#endif
74193+
74194 #ifndef ____cacheline_aligned
74195 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
74196 #endif
74197diff --git a/include/linux/capability.h b/include/linux/capability.h
74198index a6ee1f9..e1ca49d 100644
74199--- a/include/linux/capability.h
74200+++ b/include/linux/capability.h
74201@@ -212,8 +212,13 @@ extern bool capable(int cap);
74202 extern bool ns_capable(struct user_namespace *ns, int cap);
74203 extern bool inode_capable(const struct inode *inode, int cap);
74204 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
74205+extern bool capable_nolog(int cap);
74206+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
74207+extern bool inode_capable_nolog(const struct inode *inode, int cap);
74208
74209 /* audit system wants to get cap info from files as well */
74210 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
74211
74212+extern int is_privileged_binary(const struct dentry *dentry);
74213+
74214 #endif /* !_LINUX_CAPABILITY_H */
74215diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
74216index 8609d57..86e4d79 100644
74217--- a/include/linux/cdrom.h
74218+++ b/include/linux/cdrom.h
74219@@ -87,7 +87,6 @@ struct cdrom_device_ops {
74220
74221 /* driver specifications */
74222 const int capability; /* capability flags */
74223- int n_minors; /* number of active minor devices */
74224 /* handle uniform packets for scsi type devices (scsi,atapi) */
74225 int (*generic_packet) (struct cdrom_device_info *,
74226 struct packet_command *);
74227diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
74228index 4ce9056..86caac6 100644
74229--- a/include/linux/cleancache.h
74230+++ b/include/linux/cleancache.h
74231@@ -31,7 +31,7 @@ struct cleancache_ops {
74232 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
74233 void (*invalidate_inode)(int, struct cleancache_filekey);
74234 void (*invalidate_fs)(int);
74235-};
74236+} __no_const;
74237
74238 extern struct cleancache_ops *
74239 cleancache_register_ops(struct cleancache_ops *ops);
74240diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
74241index 73bdb69..d66d47a 100644
74242--- a/include/linux/clk-provider.h
74243+++ b/include/linux/clk-provider.h
74244@@ -141,6 +141,7 @@ struct clk_ops {
74245 unsigned long);
74246 void (*init)(struct clk_hw *hw);
74247 };
74248+typedef struct clk_ops __no_const clk_ops_no_const;
74249
74250 /**
74251 * struct clk_init_data - holds init data that's common to all clocks and is
74252diff --git a/include/linux/compat.h b/include/linux/compat.h
74253index 345da00..b6eff26 100644
74254--- a/include/linux/compat.h
74255+++ b/include/linux/compat.h
74256@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
74257 compat_size_t __user *len_ptr);
74258
74259 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
74260-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
74261+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
74262 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
74263 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
74264 compat_ssize_t msgsz, int msgflg);
74265@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
74266 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
74267 compat_ulong_t addr, compat_ulong_t data);
74268 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
74269- compat_long_t addr, compat_long_t data);
74270+ compat_ulong_t addr, compat_ulong_t data);
74271
74272 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
74273 /*
74274diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
74275index ded4299..da50e3b 100644
74276--- a/include/linux/compiler-gcc4.h
74277+++ b/include/linux/compiler-gcc4.h
74278@@ -39,9 +39,29 @@
74279 # define __compiletime_warning(message) __attribute__((warning(message)))
74280 # define __compiletime_error(message) __attribute__((error(message)))
74281 #endif /* __CHECKER__ */
74282+
74283+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
74284+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
74285+#define __bos0(ptr) __bos((ptr), 0)
74286+#define __bos1(ptr) __bos((ptr), 1)
74287 #endif /* GCC_VERSION >= 40300 */
74288
74289 #if GCC_VERSION >= 40500
74290+
74291+#ifdef CONSTIFY_PLUGIN
74292+#define __no_const __attribute__((no_const))
74293+#define __do_const __attribute__((do_const))
74294+#endif
74295+
74296+#ifdef SIZE_OVERFLOW_PLUGIN
74297+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
74298+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
74299+#endif
74300+
74301+#ifdef LATENT_ENTROPY_PLUGIN
74302+#define __latent_entropy __attribute__((latent_entropy))
74303+#endif
74304+
74305 /*
74306 * Mark a position in code as unreachable. This can be used to
74307 * suppress control flow warnings after asm blocks that transfer
74308diff --git a/include/linux/compiler.h b/include/linux/compiler.h
74309index 92669cd..1771a15 100644
74310--- a/include/linux/compiler.h
74311+++ b/include/linux/compiler.h
74312@@ -5,11 +5,14 @@
74313
74314 #ifdef __CHECKER__
74315 # define __user __attribute__((noderef, address_space(1)))
74316+# define __force_user __force __user
74317 # define __kernel __attribute__((address_space(0)))
74318+# define __force_kernel __force __kernel
74319 # define __safe __attribute__((safe))
74320 # define __force __attribute__((force))
74321 # define __nocast __attribute__((nocast))
74322 # define __iomem __attribute__((noderef, address_space(2)))
74323+# define __force_iomem __force __iomem
74324 # define __must_hold(x) __attribute__((context(x,1,1)))
74325 # define __acquires(x) __attribute__((context(x,0,1)))
74326 # define __releases(x) __attribute__((context(x,1,0)))
74327@@ -17,20 +20,37 @@
74328 # define __release(x) __context__(x,-1)
74329 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
74330 # define __percpu __attribute__((noderef, address_space(3)))
74331+# define __force_percpu __force __percpu
74332 #ifdef CONFIG_SPARSE_RCU_POINTER
74333 # define __rcu __attribute__((noderef, address_space(4)))
74334+# define __force_rcu __force __rcu
74335 #else
74336 # define __rcu
74337+# define __force_rcu
74338 #endif
74339 extern void __chk_user_ptr(const volatile void __user *);
74340 extern void __chk_io_ptr(const volatile void __iomem *);
74341 #else
74342-# define __user
74343-# define __kernel
74344+# ifdef CHECKER_PLUGIN
74345+//# define __user
74346+//# define __force_user
74347+//# define __kernel
74348+//# define __force_kernel
74349+# else
74350+# ifdef STRUCTLEAK_PLUGIN
74351+# define __user __attribute__((user))
74352+# else
74353+# define __user
74354+# endif
74355+# define __force_user
74356+# define __kernel
74357+# define __force_kernel
74358+# endif
74359 # define __safe
74360 # define __force
74361 # define __nocast
74362 # define __iomem
74363+# define __force_iomem
74364 # define __chk_user_ptr(x) (void)0
74365 # define __chk_io_ptr(x) (void)0
74366 # define __builtin_warning(x, y...) (1)
74367@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
74368 # define __release(x) (void)0
74369 # define __cond_lock(x,c) (c)
74370 # define __percpu
74371+# define __force_percpu
74372 # define __rcu
74373+# define __force_rcu
74374 #endif
74375
74376 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
74377@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74378 # define __attribute_const__ /* unimplemented */
74379 #endif
74380
74381+#ifndef __no_const
74382+# define __no_const
74383+#endif
74384+
74385+#ifndef __do_const
74386+# define __do_const
74387+#endif
74388+
74389+#ifndef __size_overflow
74390+# define __size_overflow(...)
74391+#endif
74392+
74393+#ifndef __intentional_overflow
74394+# define __intentional_overflow(...)
74395+#endif
74396+
74397+#ifndef __latent_entropy
74398+# define __latent_entropy
74399+#endif
74400+
74401 /*
74402 * Tell gcc if a function is cold. The compiler will assume any path
74403 * directly leading to the call is unlikely.
74404@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74405 #define __cold
74406 #endif
74407
74408+#ifndef __alloc_size
74409+#define __alloc_size(...)
74410+#endif
74411+
74412+#ifndef __bos
74413+#define __bos(ptr, arg)
74414+#endif
74415+
74416+#ifndef __bos0
74417+#define __bos0(ptr)
74418+#endif
74419+
74420+#ifndef __bos1
74421+#define __bos1(ptr)
74422+#endif
74423+
74424 /* Simple shorthand for a section definition */
74425 #ifndef __section
74426 # define __section(S) __attribute__ ((__section__(#S)))
74427@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
74428 * use is to mediate communication between process-level code and irq/NMI
74429 * handlers, all running on the same CPU.
74430 */
74431-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
74432+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
74433+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
74434
74435 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
74436 #ifdef CONFIG_KPROBES
74437diff --git a/include/linux/completion.h b/include/linux/completion.h
74438index 3cd574d..240dcb0 100644
74439--- a/include/linux/completion.h
74440+++ b/include/linux/completion.h
74441@@ -78,16 +78,16 @@ static inline void init_completion(struct completion *x)
74442
74443 extern void wait_for_completion(struct completion *);
74444 extern void wait_for_completion_io(struct completion *);
74445-extern int wait_for_completion_interruptible(struct completion *x);
74446-extern int wait_for_completion_killable(struct completion *x);
74447+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
74448+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
74449 extern unsigned long wait_for_completion_timeout(struct completion *x,
74450- unsigned long timeout);
74451+ unsigned long timeout) __intentional_overflow(-1);
74452 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
74453- unsigned long timeout);
74454+ unsigned long timeout) __intentional_overflow(-1);
74455 extern long wait_for_completion_interruptible_timeout(
74456- struct completion *x, unsigned long timeout);
74457+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
74458 extern long wait_for_completion_killable_timeout(
74459- struct completion *x, unsigned long timeout);
74460+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
74461 extern bool try_wait_for_completion(struct completion *x);
74462 extern bool completion_done(struct completion *x);
74463
74464diff --git a/include/linux/configfs.h b/include/linux/configfs.h
74465index 34025df..d94bbbc 100644
74466--- a/include/linux/configfs.h
74467+++ b/include/linux/configfs.h
74468@@ -125,7 +125,7 @@ struct configfs_attribute {
74469 const char *ca_name;
74470 struct module *ca_owner;
74471 umode_t ca_mode;
74472-};
74473+} __do_const;
74474
74475 /*
74476 * Users often need to create attribute structures for their configurable
74477diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
74478index fcabc42..cba5d93 100644
74479--- a/include/linux/cpufreq.h
74480+++ b/include/linux/cpufreq.h
74481@@ -167,6 +167,7 @@ struct global_attr {
74482 ssize_t (*store)(struct kobject *a, struct attribute *b,
74483 const char *c, size_t count);
74484 };
74485+typedef struct global_attr __no_const global_attr_no_const;
74486
74487 #define define_one_global_ro(_name) \
74488 static struct global_attr _name = \
74489@@ -208,7 +209,7 @@ struct cpufreq_driver {
74490 int (*suspend) (struct cpufreq_policy *policy);
74491 int (*resume) (struct cpufreq_policy *policy);
74492 struct freq_attr **attr;
74493-};
74494+} __do_const;
74495
74496 /* flags */
74497 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
74498diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
74499index 781addc..d1e1fe6 100644
74500--- a/include/linux/cpuidle.h
74501+++ b/include/linux/cpuidle.h
74502@@ -50,7 +50,8 @@ struct cpuidle_state {
74503 int index);
74504
74505 int (*enter_dead) (struct cpuidle_device *dev, int index);
74506-};
74507+} __do_const;
74508+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
74509
74510 /* Idle State Flags */
74511 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
74512@@ -192,7 +193,7 @@ struct cpuidle_governor {
74513 void (*reflect) (struct cpuidle_device *dev, int index);
74514
74515 struct module *owner;
74516-};
74517+} __do_const;
74518
74519 #ifdef CONFIG_CPU_IDLE
74520
74521diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
74522index d08e4d2..95fad61 100644
74523--- a/include/linux/cpumask.h
74524+++ b/include/linux/cpumask.h
74525@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
74526 }
74527
74528 /* Valid inputs for n are -1 and 0. */
74529-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74530+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
74531 {
74532 return n+1;
74533 }
74534
74535-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74536+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
74537 {
74538 return n+1;
74539 }
74540
74541-static inline unsigned int cpumask_next_and(int n,
74542+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
74543 const struct cpumask *srcp,
74544 const struct cpumask *andp)
74545 {
74546@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
74547 *
74548 * Returns >= nr_cpu_ids if no further cpus set.
74549 */
74550-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74551+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
74552 {
74553 /* -1 is a legal arg here. */
74554 if (n != -1)
74555@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
74556 *
74557 * Returns >= nr_cpu_ids if no further cpus unset.
74558 */
74559-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74560+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
74561 {
74562 /* -1 is a legal arg here. */
74563 if (n != -1)
74564@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74565 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
74566 }
74567
74568-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
74569+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
74570 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
74571
74572 /**
74573diff --git a/include/linux/cred.h b/include/linux/cred.h
74574index 04421e8..6bce4ef 100644
74575--- a/include/linux/cred.h
74576+++ b/include/linux/cred.h
74577@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
74578 static inline void validate_process_creds(void)
74579 {
74580 }
74581+static inline void validate_task_creds(struct task_struct *task)
74582+{
74583+}
74584 #endif
74585
74586 /**
74587diff --git a/include/linux/crypto.h b/include/linux/crypto.h
74588index b92eadf..b4ecdc1 100644
74589--- a/include/linux/crypto.h
74590+++ b/include/linux/crypto.h
74591@@ -373,7 +373,7 @@ struct cipher_tfm {
74592 const u8 *key, unsigned int keylen);
74593 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74594 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74595-};
74596+} __no_const;
74597
74598 struct hash_tfm {
74599 int (*init)(struct hash_desc *desc);
74600@@ -394,13 +394,13 @@ struct compress_tfm {
74601 int (*cot_decompress)(struct crypto_tfm *tfm,
74602 const u8 *src, unsigned int slen,
74603 u8 *dst, unsigned int *dlen);
74604-};
74605+} __no_const;
74606
74607 struct rng_tfm {
74608 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
74609 unsigned int dlen);
74610 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
74611-};
74612+} __no_const;
74613
74614 #define crt_ablkcipher crt_u.ablkcipher
74615 #define crt_aead crt_u.aead
74616diff --git a/include/linux/ctype.h b/include/linux/ctype.h
74617index 653589e..4ef254a 100644
74618--- a/include/linux/ctype.h
74619+++ b/include/linux/ctype.h
74620@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
74621 * Fast implementation of tolower() for internal usage. Do not use in your
74622 * code.
74623 */
74624-static inline char _tolower(const char c)
74625+static inline unsigned char _tolower(const unsigned char c)
74626 {
74627 return c | 0x20;
74628 }
74629diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
74630index 7925bf0..d5143d2 100644
74631--- a/include/linux/decompress/mm.h
74632+++ b/include/linux/decompress/mm.h
74633@@ -77,7 +77,7 @@ static void free(void *where)
74634 * warnings when not needed (indeed large_malloc / large_free are not
74635 * needed by inflate */
74636
74637-#define malloc(a) kmalloc(a, GFP_KERNEL)
74638+#define malloc(a) kmalloc((a), GFP_KERNEL)
74639 #define free(a) kfree(a)
74640
74641 #define large_malloc(a) vmalloc(a)
74642diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
74643index 5f1ab92..39c35ae 100644
74644--- a/include/linux/devfreq.h
74645+++ b/include/linux/devfreq.h
74646@@ -114,7 +114,7 @@ struct devfreq_governor {
74647 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
74648 int (*event_handler)(struct devfreq *devfreq,
74649 unsigned int event, void *data);
74650-};
74651+} __do_const;
74652
74653 /**
74654 * struct devfreq - Device devfreq structure
74655diff --git a/include/linux/device.h b/include/linux/device.h
74656index 2a9d6ed..d14551e3 100644
74657--- a/include/linux/device.h
74658+++ b/include/linux/device.h
74659@@ -313,7 +313,7 @@ struct subsys_interface {
74660 struct list_head node;
74661 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
74662 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
74663-};
74664+} __do_const;
74665
74666 int subsys_interface_register(struct subsys_interface *sif);
74667 void subsys_interface_unregister(struct subsys_interface *sif);
74668@@ -501,7 +501,7 @@ struct device_type {
74669 void (*release)(struct device *dev);
74670
74671 const struct dev_pm_ops *pm;
74672-};
74673+} __do_const;
74674
74675 /* interface for exporting device attributes */
74676 struct device_attribute {
74677@@ -511,11 +511,12 @@ struct device_attribute {
74678 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
74679 const char *buf, size_t count);
74680 };
74681+typedef struct device_attribute __no_const device_attribute_no_const;
74682
74683 struct dev_ext_attribute {
74684 struct device_attribute attr;
74685 void *var;
74686-};
74687+} __do_const;
74688
74689 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
74690 char *buf);
74691diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
74692index 3a8d0a2..c762be2 100644
74693--- a/include/linux/dma-mapping.h
74694+++ b/include/linux/dma-mapping.h
74695@@ -54,7 +54,7 @@ struct dma_map_ops {
74696 u64 (*get_required_mask)(struct device *dev);
74697 #endif
74698 int is_phys;
74699-};
74700+} __do_const;
74701
74702 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
74703
74704diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
74705index 0bc7275..4ccbf11 100644
74706--- a/include/linux/dmaengine.h
74707+++ b/include/linux/dmaengine.h
74708@@ -1078,9 +1078,9 @@ struct dma_pinned_list {
74709 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
74710 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
74711
74712-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74713+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74714 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
74715-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74716+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74717 struct dma_pinned_list *pinned_list, struct page *page,
74718 unsigned int offset, size_t len);
74719
74720diff --git a/include/linux/efi.h b/include/linux/efi.h
74721index 094ddd0..f1dfcd3 100644
74722--- a/include/linux/efi.h
74723+++ b/include/linux/efi.h
74724@@ -745,6 +745,7 @@ struct efivar_operations {
74725 efi_set_variable_t *set_variable;
74726 efi_query_variable_store_t *query_variable_store;
74727 };
74728+typedef struct efivar_operations __no_const efivar_operations_no_const;
74729
74730 struct efivars {
74731 /*
74732diff --git a/include/linux/elf.h b/include/linux/elf.h
74733index 40a3c0e0..4c45a38 100644
74734--- a/include/linux/elf.h
74735+++ b/include/linux/elf.h
74736@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
74737 #define elf_note elf32_note
74738 #define elf_addr_t Elf32_Off
74739 #define Elf_Half Elf32_Half
74740+#define elf_dyn Elf32_Dyn
74741
74742 #else
74743
74744@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
74745 #define elf_note elf64_note
74746 #define elf_addr_t Elf64_Off
74747 #define Elf_Half Elf64_Half
74748+#define elf_dyn Elf64_Dyn
74749
74750 #endif
74751
74752diff --git a/include/linux/err.h b/include/linux/err.h
74753index 15f92e0..e825a8e 100644
74754--- a/include/linux/err.h
74755+++ b/include/linux/err.h
74756@@ -19,12 +19,12 @@
74757
74758 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
74759
74760-static inline void * __must_check ERR_PTR(long error)
74761+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
74762 {
74763 return (void *) error;
74764 }
74765
74766-static inline long __must_check PTR_ERR(__force const void *ptr)
74767+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
74768 {
74769 return (long) ptr;
74770 }
74771diff --git a/include/linux/extcon.h b/include/linux/extcon.h
74772index fcb51c8..bdafcf6 100644
74773--- a/include/linux/extcon.h
74774+++ b/include/linux/extcon.h
74775@@ -134,7 +134,7 @@ struct extcon_dev {
74776 /* /sys/class/extcon/.../mutually_exclusive/... */
74777 struct attribute_group attr_g_muex;
74778 struct attribute **attrs_muex;
74779- struct device_attribute *d_attrs_muex;
74780+ device_attribute_no_const *d_attrs_muex;
74781 };
74782
74783 /**
74784diff --git a/include/linux/fb.h b/include/linux/fb.h
74785index ffac70a..ca3e711 100644
74786--- a/include/linux/fb.h
74787+++ b/include/linux/fb.h
74788@@ -304,7 +304,7 @@ struct fb_ops {
74789 /* called at KDB enter and leave time to prepare the console */
74790 int (*fb_debug_enter)(struct fb_info *info);
74791 int (*fb_debug_leave)(struct fb_info *info);
74792-};
74793+} __do_const;
74794
74795 #ifdef CONFIG_FB_TILEBLITTING
74796 #define FB_TILE_CURSOR_NONE 0
74797diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
74798index 085197b..0fa6f0b 100644
74799--- a/include/linux/fdtable.h
74800+++ b/include/linux/fdtable.h
74801@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
74802 void put_files_struct(struct files_struct *fs);
74803 void reset_files_struct(struct files_struct *);
74804 int unshare_files(struct files_struct **);
74805-struct files_struct *dup_fd(struct files_struct *, int *);
74806+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
74807 void do_close_on_exec(struct files_struct *);
74808 int iterate_fd(struct files_struct *, unsigned,
74809 int (*)(const void *, struct file *, unsigned),
74810diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
74811index 8293262..2b3b8bd 100644
74812--- a/include/linux/frontswap.h
74813+++ b/include/linux/frontswap.h
74814@@ -11,7 +11,7 @@ struct frontswap_ops {
74815 int (*load)(unsigned, pgoff_t, struct page *);
74816 void (*invalidate_page)(unsigned, pgoff_t);
74817 void (*invalidate_area)(unsigned);
74818-};
74819+} __no_const;
74820
74821 extern bool frontswap_enabled;
74822 extern struct frontswap_ops *
74823diff --git a/include/linux/fs.h b/include/linux/fs.h
74824index fefa7b0..5e04a8b 100644
74825--- a/include/linux/fs.h
74826+++ b/include/linux/fs.h
74827@@ -1552,7 +1552,8 @@ struct file_operations {
74828 long (*fallocate)(struct file *file, int mode, loff_t offset,
74829 loff_t len);
74830 int (*show_fdinfo)(struct seq_file *m, struct file *f);
74831-};
74832+} __do_const;
74833+typedef struct file_operations __no_const file_operations_no_const;
74834
74835 struct inode_operations {
74836 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
74837@@ -2746,4 +2747,14 @@ static inline bool dir_relax(struct inode *inode)
74838 return !IS_DEADDIR(inode);
74839 }
74840
74841+static inline bool is_sidechannel_device(const struct inode *inode)
74842+{
74843+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
74844+ umode_t mode = inode->i_mode;
74845+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
74846+#else
74847+ return false;
74848+#endif
74849+}
74850+
74851 #endif /* _LINUX_FS_H */
74852diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
74853index 0efc3e6..e0e1e5f 100644
74854--- a/include/linux/fs_struct.h
74855+++ b/include/linux/fs_struct.h
74856@@ -6,7 +6,7 @@
74857 #include <linux/seqlock.h>
74858
74859 struct fs_struct {
74860- int users;
74861+ atomic_t users;
74862 spinlock_t lock;
74863 seqcount_t seq;
74864 int umask;
74865diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
74866index 7823e9e..56b6f2f 100644
74867--- a/include/linux/fscache-cache.h
74868+++ b/include/linux/fscache-cache.h
74869@@ -113,7 +113,7 @@ struct fscache_operation {
74870 fscache_operation_release_t release;
74871 };
74872
74873-extern atomic_t fscache_op_debug_id;
74874+extern atomic_unchecked_t fscache_op_debug_id;
74875 extern void fscache_op_work_func(struct work_struct *work);
74876
74877 extern void fscache_enqueue_operation(struct fscache_operation *);
74878@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
74879 INIT_WORK(&op->work, fscache_op_work_func);
74880 atomic_set(&op->usage, 1);
74881 op->state = FSCACHE_OP_ST_INITIALISED;
74882- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
74883+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
74884 op->processor = processor;
74885 op->release = release;
74886 INIT_LIST_HEAD(&op->pend_link);
74887diff --git a/include/linux/fscache.h b/include/linux/fscache.h
74888index 19b4645..3b73dfc 100644
74889--- a/include/linux/fscache.h
74890+++ b/include/linux/fscache.h
74891@@ -152,7 +152,7 @@ struct fscache_cookie_def {
74892 * - this is mandatory for any object that may have data
74893 */
74894 void (*now_uncached)(void *cookie_netfs_data);
74895-};
74896+} __do_const;
74897
74898 /*
74899 * fscache cached network filesystem type
74900diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
74901index 1c804b0..1432c2b 100644
74902--- a/include/linux/fsnotify.h
74903+++ b/include/linux/fsnotify.h
74904@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
74905 struct inode *inode = file_inode(file);
74906 __u32 mask = FS_ACCESS;
74907
74908+ if (is_sidechannel_device(inode))
74909+ return;
74910+
74911 if (S_ISDIR(inode->i_mode))
74912 mask |= FS_ISDIR;
74913
74914@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
74915 struct inode *inode = file_inode(file);
74916 __u32 mask = FS_MODIFY;
74917
74918+ if (is_sidechannel_device(inode))
74919+ return;
74920+
74921 if (S_ISDIR(inode->i_mode))
74922 mask |= FS_ISDIR;
74923
74924@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
74925 */
74926 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
74927 {
74928- return kstrdup(name, GFP_KERNEL);
74929+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
74930 }
74931
74932 /*
74933diff --git a/include/linux/genhd.h b/include/linux/genhd.h
74934index 9f3c275..8bdff5d 100644
74935--- a/include/linux/genhd.h
74936+++ b/include/linux/genhd.h
74937@@ -194,7 +194,7 @@ struct gendisk {
74938 struct kobject *slave_dir;
74939
74940 struct timer_rand_state *random;
74941- atomic_t sync_io; /* RAID */
74942+ atomic_unchecked_t sync_io; /* RAID */
74943 struct disk_events *ev;
74944 #ifdef CONFIG_BLK_DEV_INTEGRITY
74945 struct blk_integrity *integrity;
74946@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
74947 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
74948
74949 /* drivers/char/random.c */
74950-extern void add_disk_randomness(struct gendisk *disk);
74951+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
74952 extern void rand_initialize_disk(struct gendisk *disk);
74953
74954 static inline sector_t get_start_sect(struct block_device *bdev)
74955diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
74956index 023bc34..b02b46a 100644
74957--- a/include/linux/genl_magic_func.h
74958+++ b/include/linux/genl_magic_func.h
74959@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
74960 },
74961
74962 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
74963-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
74964+static struct genl_ops ZZZ_genl_ops[] = {
74965 #include GENL_MAGIC_INCLUDE_FILE
74966 };
74967
74968diff --git a/include/linux/gfp.h b/include/linux/gfp.h
74969index 9b4dd49..61fd41d 100644
74970--- a/include/linux/gfp.h
74971+++ b/include/linux/gfp.h
74972@@ -35,6 +35,13 @@ struct vm_area_struct;
74973 #define ___GFP_NO_KSWAPD 0x400000u
74974 #define ___GFP_OTHER_NODE 0x800000u
74975 #define ___GFP_WRITE 0x1000000u
74976+
74977+#ifdef CONFIG_PAX_USERCOPY_SLABS
74978+#define ___GFP_USERCOPY 0x2000000u
74979+#else
74980+#define ___GFP_USERCOPY 0
74981+#endif
74982+
74983 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
74984
74985 /*
74986@@ -92,6 +99,7 @@ struct vm_area_struct;
74987 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
74988 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
74989 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
74990+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
74991
74992 /*
74993 * This may seem redundant, but it's a way of annotating false positives vs.
74994@@ -99,7 +107,7 @@ struct vm_area_struct;
74995 */
74996 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
74997
74998-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
74999+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
75000 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
75001
75002 /* This equals 0, but use constants in case they ever change */
75003@@ -153,6 +161,8 @@ struct vm_area_struct;
75004 /* 4GB DMA on some platforms */
75005 #define GFP_DMA32 __GFP_DMA32
75006
75007+#define GFP_USERCOPY __GFP_USERCOPY
75008+
75009 /* Convert GFP flags to their corresponding migrate type */
75010 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
75011 {
75012diff --git a/include/linux/gracl.h b/include/linux/gracl.h
75013new file mode 100644
75014index 0000000..edb2cb6
75015--- /dev/null
75016+++ b/include/linux/gracl.h
75017@@ -0,0 +1,340 @@
75018+#ifndef GR_ACL_H
75019+#define GR_ACL_H
75020+
75021+#include <linux/grdefs.h>
75022+#include <linux/resource.h>
75023+#include <linux/capability.h>
75024+#include <linux/dcache.h>
75025+#include <asm/resource.h>
75026+
75027+/* Major status information */
75028+
75029+#define GR_VERSION "grsecurity 3.0"
75030+#define GRSECURITY_VERSION 0x3000
75031+
75032+enum {
75033+ GR_SHUTDOWN = 0,
75034+ GR_ENABLE = 1,
75035+ GR_SPROLE = 2,
75036+ GR_OLDRELOAD = 3,
75037+ GR_SEGVMOD = 4,
75038+ GR_STATUS = 5,
75039+ GR_UNSPROLE = 6,
75040+ GR_PASSSET = 7,
75041+ GR_SPROLEPAM = 8,
75042+ GR_RELOAD = 9,
75043+};
75044+
75045+/* Password setup definitions
75046+ * kernel/grhash.c */
75047+enum {
75048+ GR_PW_LEN = 128,
75049+ GR_SALT_LEN = 16,
75050+ GR_SHA_LEN = 32,
75051+};
75052+
75053+enum {
75054+ GR_SPROLE_LEN = 64,
75055+};
75056+
75057+enum {
75058+ GR_NO_GLOB = 0,
75059+ GR_REG_GLOB,
75060+ GR_CREATE_GLOB
75061+};
75062+
75063+#define GR_NLIMITS 32
75064+
75065+/* Begin Data Structures */
75066+
75067+struct sprole_pw {
75068+ unsigned char *rolename;
75069+ unsigned char salt[GR_SALT_LEN];
75070+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
75071+};
75072+
75073+struct name_entry {
75074+ __u32 key;
75075+ ino_t inode;
75076+ dev_t device;
75077+ char *name;
75078+ __u16 len;
75079+ __u8 deleted;
75080+ struct name_entry *prev;
75081+ struct name_entry *next;
75082+};
75083+
75084+struct inodev_entry {
75085+ struct name_entry *nentry;
75086+ struct inodev_entry *prev;
75087+ struct inodev_entry *next;
75088+};
75089+
75090+struct acl_role_db {
75091+ struct acl_role_label **r_hash;
75092+ __u32 r_size;
75093+};
75094+
75095+struct inodev_db {
75096+ struct inodev_entry **i_hash;
75097+ __u32 i_size;
75098+};
75099+
75100+struct name_db {
75101+ struct name_entry **n_hash;
75102+ __u32 n_size;
75103+};
75104+
75105+struct crash_uid {
75106+ uid_t uid;
75107+ unsigned long expires;
75108+};
75109+
75110+struct gr_hash_struct {
75111+ void **table;
75112+ void **nametable;
75113+ void *first;
75114+ __u32 table_size;
75115+ __u32 used_size;
75116+ int type;
75117+};
75118+
75119+/* Userspace Grsecurity ACL data structures */
75120+
75121+struct acl_subject_label {
75122+ char *filename;
75123+ ino_t inode;
75124+ dev_t device;
75125+ __u32 mode;
75126+ kernel_cap_t cap_mask;
75127+ kernel_cap_t cap_lower;
75128+ kernel_cap_t cap_invert_audit;
75129+
75130+ struct rlimit res[GR_NLIMITS];
75131+ __u32 resmask;
75132+
75133+ __u8 user_trans_type;
75134+ __u8 group_trans_type;
75135+ uid_t *user_transitions;
75136+ gid_t *group_transitions;
75137+ __u16 user_trans_num;
75138+ __u16 group_trans_num;
75139+
75140+ __u32 sock_families[2];
75141+ __u32 ip_proto[8];
75142+ __u32 ip_type;
75143+ struct acl_ip_label **ips;
75144+ __u32 ip_num;
75145+ __u32 inaddr_any_override;
75146+
75147+ __u32 crashes;
75148+ unsigned long expires;
75149+
75150+ struct acl_subject_label *parent_subject;
75151+ struct gr_hash_struct *hash;
75152+ struct acl_subject_label *prev;
75153+ struct acl_subject_label *next;
75154+
75155+ struct acl_object_label **obj_hash;
75156+ __u32 obj_hash_size;
75157+ __u16 pax_flags;
75158+};
75159+
75160+struct role_allowed_ip {
75161+ __u32 addr;
75162+ __u32 netmask;
75163+
75164+ struct role_allowed_ip *prev;
75165+ struct role_allowed_ip *next;
75166+};
75167+
75168+struct role_transition {
75169+ char *rolename;
75170+
75171+ struct role_transition *prev;
75172+ struct role_transition *next;
75173+};
75174+
75175+struct acl_role_label {
75176+ char *rolename;
75177+ uid_t uidgid;
75178+ __u16 roletype;
75179+
75180+ __u16 auth_attempts;
75181+ unsigned long expires;
75182+
75183+ struct acl_subject_label *root_label;
75184+ struct gr_hash_struct *hash;
75185+
75186+ struct acl_role_label *prev;
75187+ struct acl_role_label *next;
75188+
75189+ struct role_transition *transitions;
75190+ struct role_allowed_ip *allowed_ips;
75191+ uid_t *domain_children;
75192+ __u16 domain_child_num;
75193+
75194+ umode_t umask;
75195+
75196+ struct acl_subject_label **subj_hash;
75197+ __u32 subj_hash_size;
75198+};
75199+
75200+struct user_acl_role_db {
75201+ struct acl_role_label **r_table;
75202+ __u32 num_pointers; /* Number of allocations to track */
75203+ __u32 num_roles; /* Number of roles */
75204+ __u32 num_domain_children; /* Number of domain children */
75205+ __u32 num_subjects; /* Number of subjects */
75206+ __u32 num_objects; /* Number of objects */
75207+};
75208+
75209+struct acl_object_label {
75210+ char *filename;
75211+ ino_t inode;
75212+ dev_t device;
75213+ __u32 mode;
75214+
75215+ struct acl_subject_label *nested;
75216+ struct acl_object_label *globbed;
75217+
75218+ /* next two structures not used */
75219+
75220+ struct acl_object_label *prev;
75221+ struct acl_object_label *next;
75222+};
75223+
75224+struct acl_ip_label {
75225+ char *iface;
75226+ __u32 addr;
75227+ __u32 netmask;
75228+ __u16 low, high;
75229+ __u8 mode;
75230+ __u32 type;
75231+ __u32 proto[8];
75232+
75233+ /* next two structures not used */
75234+
75235+ struct acl_ip_label *prev;
75236+ struct acl_ip_label *next;
75237+};
75238+
75239+struct gr_arg {
75240+ struct user_acl_role_db role_db;
75241+ unsigned char pw[GR_PW_LEN];
75242+ unsigned char salt[GR_SALT_LEN];
75243+ unsigned char sum[GR_SHA_LEN];
75244+ unsigned char sp_role[GR_SPROLE_LEN];
75245+ struct sprole_pw *sprole_pws;
75246+ dev_t segv_device;
75247+ ino_t segv_inode;
75248+ uid_t segv_uid;
75249+ __u16 num_sprole_pws;
75250+ __u16 mode;
75251+};
75252+
75253+struct gr_arg_wrapper {
75254+ struct gr_arg *arg;
75255+ __u32 version;
75256+ __u32 size;
75257+};
75258+
75259+struct subject_map {
75260+ struct acl_subject_label *user;
75261+ struct acl_subject_label *kernel;
75262+ struct subject_map *prev;
75263+ struct subject_map *next;
75264+};
75265+
75266+struct acl_subj_map_db {
75267+ struct subject_map **s_hash;
75268+ __u32 s_size;
75269+};
75270+
75271+struct gr_policy_state {
75272+ struct sprole_pw **acl_special_roles;
75273+ __u16 num_sprole_pws;
75274+ struct acl_role_label *kernel_role;
75275+ struct acl_role_label *role_list;
75276+ struct acl_role_label *default_role;
75277+ struct acl_role_db acl_role_set;
75278+ struct acl_subj_map_db subj_map_set;
75279+ struct name_db name_set;
75280+ struct inodev_db inodev_set;
75281+};
75282+
75283+struct gr_alloc_state {
75284+ unsigned long alloc_stack_next;
75285+ unsigned long alloc_stack_size;
75286+ void **alloc_stack;
75287+};
75288+
75289+struct gr_reload_state {
75290+ struct gr_policy_state oldpolicy;
75291+ struct gr_alloc_state oldalloc;
75292+ struct gr_policy_state newpolicy;
75293+ struct gr_alloc_state newalloc;
75294+ struct gr_policy_state *oldpolicy_ptr;
75295+ struct gr_alloc_state *oldalloc_ptr;
75296+ unsigned char oldmode;
75297+};
75298+
75299+/* End Data Structures Section */
75300+
75301+/* Hash functions generated by empirical testing by Brad Spengler
75302+ Makes good use of the low bits of the inode. Generally 0-1 times
75303+ in loop for successful match. 0-3 for unsuccessful match.
75304+ Shift/add algorithm with modulus of table size and an XOR*/
75305+
75306+static __inline__ unsigned int
75307+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
75308+{
75309+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
75310+}
75311+
75312+ static __inline__ unsigned int
75313+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
75314+{
75315+ return ((const unsigned long)userp % sz);
75316+}
75317+
75318+static __inline__ unsigned int
75319+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
75320+{
75321+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
75322+}
75323+
75324+static __inline__ unsigned int
75325+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
75326+{
75327+ return full_name_hash((const unsigned char *)name, len) % sz;
75328+}
75329+
75330+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
75331+ subj = NULL; \
75332+ iter = 0; \
75333+ while (iter < role->subj_hash_size) { \
75334+ if (subj == NULL) \
75335+ subj = role->subj_hash[iter]; \
75336+ if (subj == NULL) { \
75337+ iter++; \
75338+ continue; \
75339+ }
75340+
75341+#define FOR_EACH_SUBJECT_END(subj,iter) \
75342+ subj = subj->next; \
75343+ if (subj == NULL) \
75344+ iter++; \
75345+ }
75346+
75347+
75348+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
75349+ subj = role->hash->first; \
75350+ while (subj != NULL) {
75351+
75352+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
75353+ subj = subj->next; \
75354+ }
75355+
75356+#endif
75357+
75358diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
75359new file mode 100644
75360index 0000000..33ebd1f
75361--- /dev/null
75362+++ b/include/linux/gracl_compat.h
75363@@ -0,0 +1,156 @@
75364+#ifndef GR_ACL_COMPAT_H
75365+#define GR_ACL_COMPAT_H
75366+
75367+#include <linux/resource.h>
75368+#include <asm/resource.h>
75369+
75370+struct sprole_pw_compat {
75371+ compat_uptr_t rolename;
75372+ unsigned char salt[GR_SALT_LEN];
75373+ unsigned char sum[GR_SHA_LEN];
75374+};
75375+
75376+struct gr_hash_struct_compat {
75377+ compat_uptr_t table;
75378+ compat_uptr_t nametable;
75379+ compat_uptr_t first;
75380+ __u32 table_size;
75381+ __u32 used_size;
75382+ int type;
75383+};
75384+
75385+struct acl_subject_label_compat {
75386+ compat_uptr_t filename;
75387+ compat_ino_t inode;
75388+ __u32 device;
75389+ __u32 mode;
75390+ kernel_cap_t cap_mask;
75391+ kernel_cap_t cap_lower;
75392+ kernel_cap_t cap_invert_audit;
75393+
75394+ struct compat_rlimit res[GR_NLIMITS];
75395+ __u32 resmask;
75396+
75397+ __u8 user_trans_type;
75398+ __u8 group_trans_type;
75399+ compat_uptr_t user_transitions;
75400+ compat_uptr_t group_transitions;
75401+ __u16 user_trans_num;
75402+ __u16 group_trans_num;
75403+
75404+ __u32 sock_families[2];
75405+ __u32 ip_proto[8];
75406+ __u32 ip_type;
75407+ compat_uptr_t ips;
75408+ __u32 ip_num;
75409+ __u32 inaddr_any_override;
75410+
75411+ __u32 crashes;
75412+ compat_ulong_t expires;
75413+
75414+ compat_uptr_t parent_subject;
75415+ compat_uptr_t hash;
75416+ compat_uptr_t prev;
75417+ compat_uptr_t next;
75418+
75419+ compat_uptr_t obj_hash;
75420+ __u32 obj_hash_size;
75421+ __u16 pax_flags;
75422+};
75423+
75424+struct role_allowed_ip_compat {
75425+ __u32 addr;
75426+ __u32 netmask;
75427+
75428+ compat_uptr_t prev;
75429+ compat_uptr_t next;
75430+};
75431+
75432+struct role_transition_compat {
75433+ compat_uptr_t rolename;
75434+
75435+ compat_uptr_t prev;
75436+ compat_uptr_t next;
75437+};
75438+
75439+struct acl_role_label_compat {
75440+ compat_uptr_t rolename;
75441+ uid_t uidgid;
75442+ __u16 roletype;
75443+
75444+ __u16 auth_attempts;
75445+ compat_ulong_t expires;
75446+
75447+ compat_uptr_t root_label;
75448+ compat_uptr_t hash;
75449+
75450+ compat_uptr_t prev;
75451+ compat_uptr_t next;
75452+
75453+ compat_uptr_t transitions;
75454+ compat_uptr_t allowed_ips;
75455+ compat_uptr_t domain_children;
75456+ __u16 domain_child_num;
75457+
75458+ umode_t umask;
75459+
75460+ compat_uptr_t subj_hash;
75461+ __u32 subj_hash_size;
75462+};
75463+
75464+struct user_acl_role_db_compat {
75465+ compat_uptr_t r_table;
75466+ __u32 num_pointers;
75467+ __u32 num_roles;
75468+ __u32 num_domain_children;
75469+ __u32 num_subjects;
75470+ __u32 num_objects;
75471+};
75472+
75473+struct acl_object_label_compat {
75474+ compat_uptr_t filename;
75475+ compat_ino_t inode;
75476+ __u32 device;
75477+ __u32 mode;
75478+
75479+ compat_uptr_t nested;
75480+ compat_uptr_t globbed;
75481+
75482+ compat_uptr_t prev;
75483+ compat_uptr_t next;
75484+};
75485+
75486+struct acl_ip_label_compat {
75487+ compat_uptr_t iface;
75488+ __u32 addr;
75489+ __u32 netmask;
75490+ __u16 low, high;
75491+ __u8 mode;
75492+ __u32 type;
75493+ __u32 proto[8];
75494+
75495+ compat_uptr_t prev;
75496+ compat_uptr_t next;
75497+};
75498+
75499+struct gr_arg_compat {
75500+ struct user_acl_role_db_compat role_db;
75501+ unsigned char pw[GR_PW_LEN];
75502+ unsigned char salt[GR_SALT_LEN];
75503+ unsigned char sum[GR_SHA_LEN];
75504+ unsigned char sp_role[GR_SPROLE_LEN];
75505+ compat_uptr_t sprole_pws;
75506+ __u32 segv_device;
75507+ compat_ino_t segv_inode;
75508+ uid_t segv_uid;
75509+ __u16 num_sprole_pws;
75510+ __u16 mode;
75511+};
75512+
75513+struct gr_arg_wrapper_compat {
75514+ compat_uptr_t arg;
75515+ __u32 version;
75516+ __u32 size;
75517+};
75518+
75519+#endif
75520diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
75521new file mode 100644
75522index 0000000..323ecf2
75523--- /dev/null
75524+++ b/include/linux/gralloc.h
75525@@ -0,0 +1,9 @@
75526+#ifndef __GRALLOC_H
75527+#define __GRALLOC_H
75528+
75529+void acl_free_all(void);
75530+int acl_alloc_stack_init(unsigned long size);
75531+void *acl_alloc(unsigned long len);
75532+void *acl_alloc_num(unsigned long num, unsigned long len);
75533+
75534+#endif
75535diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
75536new file mode 100644
75537index 0000000..be66033
75538--- /dev/null
75539+++ b/include/linux/grdefs.h
75540@@ -0,0 +1,140 @@
75541+#ifndef GRDEFS_H
75542+#define GRDEFS_H
75543+
75544+/* Begin grsecurity status declarations */
75545+
75546+enum {
75547+ GR_READY = 0x01,
75548+ GR_STATUS_INIT = 0x00 // disabled state
75549+};
75550+
75551+/* Begin ACL declarations */
75552+
75553+/* Role flags */
75554+
75555+enum {
75556+ GR_ROLE_USER = 0x0001,
75557+ GR_ROLE_GROUP = 0x0002,
75558+ GR_ROLE_DEFAULT = 0x0004,
75559+ GR_ROLE_SPECIAL = 0x0008,
75560+ GR_ROLE_AUTH = 0x0010,
75561+ GR_ROLE_NOPW = 0x0020,
75562+ GR_ROLE_GOD = 0x0040,
75563+ GR_ROLE_LEARN = 0x0080,
75564+ GR_ROLE_TPE = 0x0100,
75565+ GR_ROLE_DOMAIN = 0x0200,
75566+ GR_ROLE_PAM = 0x0400,
75567+ GR_ROLE_PERSIST = 0x0800
75568+};
75569+
75570+/* ACL Subject and Object mode flags */
75571+enum {
75572+ GR_DELETED = 0x80000000
75573+};
75574+
75575+/* ACL Object-only mode flags */
75576+enum {
75577+ GR_READ = 0x00000001,
75578+ GR_APPEND = 0x00000002,
75579+ GR_WRITE = 0x00000004,
75580+ GR_EXEC = 0x00000008,
75581+ GR_FIND = 0x00000010,
75582+ GR_INHERIT = 0x00000020,
75583+ GR_SETID = 0x00000040,
75584+ GR_CREATE = 0x00000080,
75585+ GR_DELETE = 0x00000100,
75586+ GR_LINK = 0x00000200,
75587+ GR_AUDIT_READ = 0x00000400,
75588+ GR_AUDIT_APPEND = 0x00000800,
75589+ GR_AUDIT_WRITE = 0x00001000,
75590+ GR_AUDIT_EXEC = 0x00002000,
75591+ GR_AUDIT_FIND = 0x00004000,
75592+ GR_AUDIT_INHERIT= 0x00008000,
75593+ GR_AUDIT_SETID = 0x00010000,
75594+ GR_AUDIT_CREATE = 0x00020000,
75595+ GR_AUDIT_DELETE = 0x00040000,
75596+ GR_AUDIT_LINK = 0x00080000,
75597+ GR_PTRACERD = 0x00100000,
75598+ GR_NOPTRACE = 0x00200000,
75599+ GR_SUPPRESS = 0x00400000,
75600+ GR_NOLEARN = 0x00800000,
75601+ GR_INIT_TRANSFER= 0x01000000
75602+};
75603+
75604+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
75605+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
75606+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
75607+
75608+/* ACL subject-only mode flags */
75609+enum {
75610+ GR_KILL = 0x00000001,
75611+ GR_VIEW = 0x00000002,
75612+ GR_PROTECTED = 0x00000004,
75613+ GR_LEARN = 0x00000008,
75614+ GR_OVERRIDE = 0x00000010,
75615+ /* just a placeholder, this mode is only used in userspace */
75616+ GR_DUMMY = 0x00000020,
75617+ GR_PROTSHM = 0x00000040,
75618+ GR_KILLPROC = 0x00000080,
75619+ GR_KILLIPPROC = 0x00000100,
75620+ /* just a placeholder, this mode is only used in userspace */
75621+ GR_NOTROJAN = 0x00000200,
75622+ GR_PROTPROCFD = 0x00000400,
75623+ GR_PROCACCT = 0x00000800,
75624+ GR_RELAXPTRACE = 0x00001000,
75625+ //GR_NESTED = 0x00002000,
75626+ GR_INHERITLEARN = 0x00004000,
75627+ GR_PROCFIND = 0x00008000,
75628+ GR_POVERRIDE = 0x00010000,
75629+ GR_KERNELAUTH = 0x00020000,
75630+ GR_ATSECURE = 0x00040000,
75631+ GR_SHMEXEC = 0x00080000
75632+};
75633+
75634+enum {
75635+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
75636+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
75637+ GR_PAX_ENABLE_MPROTECT = 0x0004,
75638+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
75639+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
75640+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
75641+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
75642+ GR_PAX_DISABLE_MPROTECT = 0x0400,
75643+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
75644+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
75645+};
75646+
75647+enum {
75648+ GR_ID_USER = 0x01,
75649+ GR_ID_GROUP = 0x02,
75650+};
75651+
75652+enum {
75653+ GR_ID_ALLOW = 0x01,
75654+ GR_ID_DENY = 0x02,
75655+};
75656+
75657+#define GR_CRASH_RES 31
75658+#define GR_UIDTABLE_MAX 500
75659+
75660+/* begin resource learning section */
75661+enum {
75662+ GR_RLIM_CPU_BUMP = 60,
75663+ GR_RLIM_FSIZE_BUMP = 50000,
75664+ GR_RLIM_DATA_BUMP = 10000,
75665+ GR_RLIM_STACK_BUMP = 1000,
75666+ GR_RLIM_CORE_BUMP = 10000,
75667+ GR_RLIM_RSS_BUMP = 500000,
75668+ GR_RLIM_NPROC_BUMP = 1,
75669+ GR_RLIM_NOFILE_BUMP = 5,
75670+ GR_RLIM_MEMLOCK_BUMP = 50000,
75671+ GR_RLIM_AS_BUMP = 500000,
75672+ GR_RLIM_LOCKS_BUMP = 2,
75673+ GR_RLIM_SIGPENDING_BUMP = 5,
75674+ GR_RLIM_MSGQUEUE_BUMP = 10000,
75675+ GR_RLIM_NICE_BUMP = 1,
75676+ GR_RLIM_RTPRIO_BUMP = 1,
75677+ GR_RLIM_RTTIME_BUMP = 1000000
75678+};
75679+
75680+#endif
75681diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
75682new file mode 100644
75683index 0000000..d25522e
75684--- /dev/null
75685+++ b/include/linux/grinternal.h
75686@@ -0,0 +1,229 @@
75687+#ifndef __GRINTERNAL_H
75688+#define __GRINTERNAL_H
75689+
75690+#ifdef CONFIG_GRKERNSEC
75691+
75692+#include <linux/fs.h>
75693+#include <linux/mnt_namespace.h>
75694+#include <linux/nsproxy.h>
75695+#include <linux/gracl.h>
75696+#include <linux/grdefs.h>
75697+#include <linux/grmsg.h>
75698+
75699+void gr_add_learn_entry(const char *fmt, ...)
75700+ __attribute__ ((format (printf, 1, 2)));
75701+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
75702+ const struct vfsmount *mnt);
75703+__u32 gr_check_create(const struct dentry *new_dentry,
75704+ const struct dentry *parent,
75705+ const struct vfsmount *mnt, const __u32 mode);
75706+int gr_check_protected_task(const struct task_struct *task);
75707+__u32 to_gr_audit(const __u32 reqmode);
75708+int gr_set_acls(const int type);
75709+int gr_acl_is_enabled(void);
75710+char gr_roletype_to_char(void);
75711+
75712+void gr_handle_alertkill(struct task_struct *task);
75713+char *gr_to_filename(const struct dentry *dentry,
75714+ const struct vfsmount *mnt);
75715+char *gr_to_filename1(const struct dentry *dentry,
75716+ const struct vfsmount *mnt);
75717+char *gr_to_filename2(const struct dentry *dentry,
75718+ const struct vfsmount *mnt);
75719+char *gr_to_filename3(const struct dentry *dentry,
75720+ const struct vfsmount *mnt);
75721+
75722+extern int grsec_enable_ptrace_readexec;
75723+extern int grsec_enable_harden_ptrace;
75724+extern int grsec_enable_link;
75725+extern int grsec_enable_fifo;
75726+extern int grsec_enable_execve;
75727+extern int grsec_enable_shm;
75728+extern int grsec_enable_execlog;
75729+extern int grsec_enable_signal;
75730+extern int grsec_enable_audit_ptrace;
75731+extern int grsec_enable_forkfail;
75732+extern int grsec_enable_time;
75733+extern int grsec_enable_rofs;
75734+extern int grsec_deny_new_usb;
75735+extern int grsec_enable_chroot_shmat;
75736+extern int grsec_enable_chroot_mount;
75737+extern int grsec_enable_chroot_double;
75738+extern int grsec_enable_chroot_pivot;
75739+extern int grsec_enable_chroot_chdir;
75740+extern int grsec_enable_chroot_chmod;
75741+extern int grsec_enable_chroot_mknod;
75742+extern int grsec_enable_chroot_fchdir;
75743+extern int grsec_enable_chroot_nice;
75744+extern int grsec_enable_chroot_execlog;
75745+extern int grsec_enable_chroot_caps;
75746+extern int grsec_enable_chroot_sysctl;
75747+extern int grsec_enable_chroot_unix;
75748+extern int grsec_enable_symlinkown;
75749+extern kgid_t grsec_symlinkown_gid;
75750+extern int grsec_enable_tpe;
75751+extern kgid_t grsec_tpe_gid;
75752+extern int grsec_enable_tpe_all;
75753+extern int grsec_enable_tpe_invert;
75754+extern int grsec_enable_socket_all;
75755+extern kgid_t grsec_socket_all_gid;
75756+extern int grsec_enable_socket_client;
75757+extern kgid_t grsec_socket_client_gid;
75758+extern int grsec_enable_socket_server;
75759+extern kgid_t grsec_socket_server_gid;
75760+extern kgid_t grsec_audit_gid;
75761+extern int grsec_enable_group;
75762+extern int grsec_enable_log_rwxmaps;
75763+extern int grsec_enable_mount;
75764+extern int grsec_enable_chdir;
75765+extern int grsec_resource_logging;
75766+extern int grsec_enable_blackhole;
75767+extern int grsec_lastack_retries;
75768+extern int grsec_enable_brute;
75769+extern int grsec_enable_harden_ipc;
75770+extern int grsec_lock;
75771+
75772+extern spinlock_t grsec_alert_lock;
75773+extern unsigned long grsec_alert_wtime;
75774+extern unsigned long grsec_alert_fyet;
75775+
75776+extern spinlock_t grsec_audit_lock;
75777+
75778+extern rwlock_t grsec_exec_file_lock;
75779+
75780+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
75781+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
75782+ (tsk)->exec_file->f_path.mnt) : "/")
75783+
75784+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
75785+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
75786+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75787+
75788+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
75789+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
75790+ (tsk)->exec_file->f_path.mnt) : "/")
75791+
75792+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
75793+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
75794+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75795+
75796+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
75797+
75798+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
75799+
75800+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
75801+{
75802+ if (file1 && file2) {
75803+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
75804+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
75805+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
75806+ return true;
75807+ }
75808+
75809+ return false;
75810+}
75811+
75812+#define GR_CHROOT_CAPS {{ \
75813+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
75814+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
75815+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
75816+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
75817+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
75818+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
75819+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
75820+
75821+#define security_learn(normal_msg,args...) \
75822+({ \
75823+ read_lock(&grsec_exec_file_lock); \
75824+ gr_add_learn_entry(normal_msg "\n", ## args); \
75825+ read_unlock(&grsec_exec_file_lock); \
75826+})
75827+
75828+enum {
75829+ GR_DO_AUDIT,
75830+ GR_DONT_AUDIT,
75831+ /* used for non-audit messages that we shouldn't kill the task on */
75832+ GR_DONT_AUDIT_GOOD
75833+};
75834+
75835+enum {
75836+ GR_TTYSNIFF,
75837+ GR_RBAC,
75838+ GR_RBAC_STR,
75839+ GR_STR_RBAC,
75840+ GR_RBAC_MODE2,
75841+ GR_RBAC_MODE3,
75842+ GR_FILENAME,
75843+ GR_SYSCTL_HIDDEN,
75844+ GR_NOARGS,
75845+ GR_ONE_INT,
75846+ GR_ONE_INT_TWO_STR,
75847+ GR_ONE_STR,
75848+ GR_STR_INT,
75849+ GR_TWO_STR_INT,
75850+ GR_TWO_INT,
75851+ GR_TWO_U64,
75852+ GR_THREE_INT,
75853+ GR_FIVE_INT_TWO_STR,
75854+ GR_TWO_STR,
75855+ GR_THREE_STR,
75856+ GR_FOUR_STR,
75857+ GR_STR_FILENAME,
75858+ GR_FILENAME_STR,
75859+ GR_FILENAME_TWO_INT,
75860+ GR_FILENAME_TWO_INT_STR,
75861+ GR_TEXTREL,
75862+ GR_PTRACE,
75863+ GR_RESOURCE,
75864+ GR_CAP,
75865+ GR_SIG,
75866+ GR_SIG2,
75867+ GR_CRASH1,
75868+ GR_CRASH2,
75869+ GR_PSACCT,
75870+ GR_RWXMAP,
75871+ GR_RWXMAPVMA
75872+};
75873+
75874+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
75875+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
75876+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
75877+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
75878+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
75879+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
75880+#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)
75881+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
75882+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
75883+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
75884+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
75885+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
75886+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
75887+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
75888+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
75889+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
75890+#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)
75891+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
75892+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
75893+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
75894+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
75895+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
75896+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
75897+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
75898+#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)
75899+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
75900+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
75901+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
75902+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
75903+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
75904+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
75905+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
75906+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
75907+#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)
75908+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
75909+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
75910+
75911+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
75912+
75913+#endif
75914+
75915+#endif
75916diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
75917new file mode 100644
75918index 0000000..378a81a
75919--- /dev/null
75920+++ b/include/linux/grmsg.h
75921@@ -0,0 +1,114 @@
75922+#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"
75923+#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"
75924+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
75925+#define GR_STOPMOD_MSG "denied modification of module state by "
75926+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
75927+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
75928+#define GR_IOPERM_MSG "denied use of ioperm() by "
75929+#define GR_IOPL_MSG "denied use of iopl() by "
75930+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
75931+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
75932+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
75933+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
75934+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
75935+#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"
75936+#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"
75937+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
75938+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
75939+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
75940+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
75941+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
75942+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
75943+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
75944+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
75945+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
75946+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
75947+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
75948+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
75949+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
75950+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
75951+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
75952+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
75953+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
75954+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
75955+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
75956+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
75957+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
75958+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
75959+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
75960+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
75961+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
75962+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
75963+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
75964+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
75965+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
75966+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
75967+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
75968+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
75969+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
75970+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
75971+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
75972+#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"
75973+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
75974+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
75975+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
75976+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
75977+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
75978+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
75979+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
75980+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
75981+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
75982+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
75983+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
75984+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
75985+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
75986+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
75987+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
75988+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
75989+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
75990+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
75991+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
75992+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
75993+#define GR_FAILFORK_MSG "failed fork with errno %s by "
75994+#define GR_NICE_CHROOT_MSG "denied priority change by "
75995+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
75996+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
75997+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
75998+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
75999+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
76000+#define GR_TIME_MSG "time set by "
76001+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
76002+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
76003+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
76004+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
76005+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
76006+#define GR_BIND_MSG "denied bind() by "
76007+#define GR_CONNECT_MSG "denied connect() by "
76008+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
76009+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
76010+#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"
76011+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
76012+#define GR_CAP_ACL_MSG "use of %s denied for "
76013+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
76014+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
76015+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
76016+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
76017+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
76018+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
76019+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
76020+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
76021+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
76022+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
76023+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
76024+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
76025+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
76026+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
76027+#define GR_VM86_MSG "denied use of vm86 by "
76028+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
76029+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
76030+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
76031+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
76032+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
76033+#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 "
76034+#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 "
76035+#define GR_IPC_DENIED_MSG "denied %s of globally-%sable IPC with creator uid %u by "
76036diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
76037new file mode 100644
76038index 0000000..134860c
76039--- /dev/null
76040+++ b/include/linux/grsecurity.h
76041@@ -0,0 +1,243 @@
76042+#ifndef GR_SECURITY_H
76043+#define GR_SECURITY_H
76044+#include <linux/fs.h>
76045+#include <linux/fs_struct.h>
76046+#include <linux/binfmts.h>
76047+#include <linux/gracl.h>
76048+
76049+/* notify of brain-dead configs */
76050+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76051+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
76052+#endif
76053+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
76054+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
76055+#endif
76056+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
76057+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
76058+#endif
76059+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
76060+#error "CONFIG_PAX enabled, but no PaX options are enabled."
76061+#endif
76062+
76063+int gr_handle_new_usb(void);
76064+
76065+void gr_handle_brute_attach(int dumpable);
76066+void gr_handle_brute_check(void);
76067+void gr_handle_kernel_exploit(void);
76068+
76069+char gr_roletype_to_char(void);
76070+
76071+int gr_acl_enable_at_secure(void);
76072+
76073+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
76074+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
76075+
76076+void gr_del_task_from_ip_table(struct task_struct *p);
76077+
76078+int gr_pid_is_chrooted(struct task_struct *p);
76079+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
76080+int gr_handle_chroot_nice(void);
76081+int gr_handle_chroot_sysctl(const int op);
76082+int gr_handle_chroot_setpriority(struct task_struct *p,
76083+ const int niceval);
76084+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
76085+int gr_handle_chroot_chroot(const struct dentry *dentry,
76086+ const struct vfsmount *mnt);
76087+void gr_handle_chroot_chdir(const struct path *path);
76088+int gr_handle_chroot_chmod(const struct dentry *dentry,
76089+ const struct vfsmount *mnt, const int mode);
76090+int gr_handle_chroot_mknod(const struct dentry *dentry,
76091+ const struct vfsmount *mnt, const int mode);
76092+int gr_handle_chroot_mount(const struct dentry *dentry,
76093+ const struct vfsmount *mnt,
76094+ const char *dev_name);
76095+int gr_handle_chroot_pivot(void);
76096+int gr_handle_chroot_unix(const pid_t pid);
76097+
76098+int gr_handle_rawio(const struct inode *inode);
76099+
76100+void gr_handle_ioperm(void);
76101+void gr_handle_iopl(void);
76102+
76103+umode_t gr_acl_umask(void);
76104+
76105+int gr_tpe_allow(const struct file *file);
76106+
76107+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
76108+void gr_clear_chroot_entries(struct task_struct *task);
76109+
76110+void gr_log_forkfail(const int retval);
76111+void gr_log_timechange(void);
76112+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
76113+void gr_log_chdir(const struct dentry *dentry,
76114+ const struct vfsmount *mnt);
76115+void gr_log_chroot_exec(const struct dentry *dentry,
76116+ const struct vfsmount *mnt);
76117+void gr_log_remount(const char *devname, const int retval);
76118+void gr_log_unmount(const char *devname, const int retval);
76119+void gr_log_mount(const char *from, const char *to, const int retval);
76120+void gr_log_textrel(struct vm_area_struct *vma);
76121+void gr_log_ptgnustack(struct file *file);
76122+void gr_log_rwxmmap(struct file *file);
76123+void gr_log_rwxmprotect(struct vm_area_struct *vma);
76124+
76125+int gr_handle_follow_link(const struct inode *parent,
76126+ const struct inode *inode,
76127+ const struct dentry *dentry,
76128+ const struct vfsmount *mnt);
76129+int gr_handle_fifo(const struct dentry *dentry,
76130+ const struct vfsmount *mnt,
76131+ const struct dentry *dir, const int flag,
76132+ const int acc_mode);
76133+int gr_handle_hardlink(const struct dentry *dentry,
76134+ const struct vfsmount *mnt,
76135+ struct inode *inode,
76136+ const int mode, const struct filename *to);
76137+
76138+int gr_is_capable(const int cap);
76139+int gr_is_capable_nolog(const int cap);
76140+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76141+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
76142+
76143+void gr_copy_label(struct task_struct *tsk);
76144+void gr_handle_crash(struct task_struct *task, const int sig);
76145+int gr_handle_signal(const struct task_struct *p, const int sig);
76146+int gr_check_crash_uid(const kuid_t uid);
76147+int gr_check_protected_task(const struct task_struct *task);
76148+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
76149+int gr_acl_handle_mmap(const struct file *file,
76150+ const unsigned long prot);
76151+int gr_acl_handle_mprotect(const struct file *file,
76152+ const unsigned long prot);
76153+int gr_check_hidden_task(const struct task_struct *tsk);
76154+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
76155+ const struct vfsmount *mnt);
76156+__u32 gr_acl_handle_utime(const struct dentry *dentry,
76157+ const struct vfsmount *mnt);
76158+__u32 gr_acl_handle_access(const struct dentry *dentry,
76159+ const struct vfsmount *mnt, const int fmode);
76160+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
76161+ const struct vfsmount *mnt, umode_t *mode);
76162+__u32 gr_acl_handle_chown(const struct dentry *dentry,
76163+ const struct vfsmount *mnt);
76164+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
76165+ const struct vfsmount *mnt);
76166+int gr_handle_ptrace(struct task_struct *task, const long request);
76167+int gr_handle_proc_ptrace(struct task_struct *task);
76168+__u32 gr_acl_handle_execve(const struct dentry *dentry,
76169+ const struct vfsmount *mnt);
76170+int gr_check_crash_exec(const struct file *filp);
76171+int gr_acl_is_enabled(void);
76172+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
76173+ const kgid_t gid);
76174+int gr_set_proc_label(const struct dentry *dentry,
76175+ const struct vfsmount *mnt,
76176+ const int unsafe_flags);
76177+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
76178+ const struct vfsmount *mnt);
76179+__u32 gr_acl_handle_open(const struct dentry *dentry,
76180+ const struct vfsmount *mnt, int acc_mode);
76181+__u32 gr_acl_handle_creat(const struct dentry *dentry,
76182+ const struct dentry *p_dentry,
76183+ const struct vfsmount *p_mnt,
76184+ int open_flags, int acc_mode, const int imode);
76185+void gr_handle_create(const struct dentry *dentry,
76186+ const struct vfsmount *mnt);
76187+void gr_handle_proc_create(const struct dentry *dentry,
76188+ const struct inode *inode);
76189+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
76190+ const struct dentry *parent_dentry,
76191+ const struct vfsmount *parent_mnt,
76192+ const int mode);
76193+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
76194+ const struct dentry *parent_dentry,
76195+ const struct vfsmount *parent_mnt);
76196+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
76197+ const struct vfsmount *mnt);
76198+void gr_handle_delete(const ino_t ino, const dev_t dev);
76199+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
76200+ const struct vfsmount *mnt);
76201+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
76202+ const struct dentry *parent_dentry,
76203+ const struct vfsmount *parent_mnt,
76204+ const struct filename *from);
76205+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
76206+ const struct dentry *parent_dentry,
76207+ const struct vfsmount *parent_mnt,
76208+ const struct dentry *old_dentry,
76209+ const struct vfsmount *old_mnt, const struct filename *to);
76210+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
76211+int gr_acl_handle_rename(struct dentry *new_dentry,
76212+ struct dentry *parent_dentry,
76213+ const struct vfsmount *parent_mnt,
76214+ struct dentry *old_dentry,
76215+ struct inode *old_parent_inode,
76216+ struct vfsmount *old_mnt, const struct filename *newname);
76217+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76218+ struct dentry *old_dentry,
76219+ struct dentry *new_dentry,
76220+ struct vfsmount *mnt, const __u8 replace);
76221+__u32 gr_check_link(const struct dentry *new_dentry,
76222+ const struct dentry *parent_dentry,
76223+ const struct vfsmount *parent_mnt,
76224+ const struct dentry *old_dentry,
76225+ const struct vfsmount *old_mnt);
76226+int gr_acl_handle_filldir(const struct file *file, const char *name,
76227+ const unsigned int namelen, const ino_t ino);
76228+
76229+__u32 gr_acl_handle_unix(const struct dentry *dentry,
76230+ const struct vfsmount *mnt);
76231+void gr_acl_handle_exit(void);
76232+void gr_acl_handle_psacct(struct task_struct *task, const long code);
76233+int gr_acl_handle_procpidmem(const struct task_struct *task);
76234+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
76235+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
76236+void gr_audit_ptrace(struct task_struct *task);
76237+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
76238+void gr_put_exec_file(struct task_struct *task);
76239+
76240+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
76241+
76242+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
76243+extern void gr_learn_resource(const struct task_struct *task, const int res,
76244+ const unsigned long wanted, const int gt);
76245+#else
76246+static inline void gr_learn_resource(const struct task_struct *task, const int res,
76247+ const unsigned long wanted, const int gt)
76248+{
76249+}
76250+#endif
76251+
76252+#ifdef CONFIG_GRKERNSEC_RESLOG
76253+extern void gr_log_resource(const struct task_struct *task, const int res,
76254+ const unsigned long wanted, const int gt);
76255+#else
76256+static inline void gr_log_resource(const struct task_struct *task, const int res,
76257+ const unsigned long wanted, const int gt)
76258+{
76259+}
76260+#endif
76261+
76262+#ifdef CONFIG_GRKERNSEC
76263+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
76264+void gr_handle_vm86(void);
76265+void gr_handle_mem_readwrite(u64 from, u64 to);
76266+
76267+void gr_log_badprocpid(const char *entry);
76268+
76269+extern int grsec_enable_dmesg;
76270+extern int grsec_disable_privio;
76271+
76272+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76273+extern kgid_t grsec_proc_gid;
76274+#endif
76275+
76276+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76277+extern int grsec_enable_chroot_findtask;
76278+#endif
76279+#ifdef CONFIG_GRKERNSEC_SETXID
76280+extern int grsec_enable_setxid;
76281+#endif
76282+#endif
76283+
76284+#endif
76285diff --git a/include/linux/grsock.h b/include/linux/grsock.h
76286new file mode 100644
76287index 0000000..e7ffaaf
76288--- /dev/null
76289+++ b/include/linux/grsock.h
76290@@ -0,0 +1,19 @@
76291+#ifndef __GRSOCK_H
76292+#define __GRSOCK_H
76293+
76294+extern void gr_attach_curr_ip(const struct sock *sk);
76295+extern int gr_handle_sock_all(const int family, const int type,
76296+ const int protocol);
76297+extern int gr_handle_sock_server(const struct sockaddr *sck);
76298+extern int gr_handle_sock_server_other(const struct sock *sck);
76299+extern int gr_handle_sock_client(const struct sockaddr *sck);
76300+extern int gr_search_connect(struct socket * sock,
76301+ struct sockaddr_in * addr);
76302+extern int gr_search_bind(struct socket * sock,
76303+ struct sockaddr_in * addr);
76304+extern int gr_search_listen(struct socket * sock);
76305+extern int gr_search_accept(struct socket * sock);
76306+extern int gr_search_socket(const int domain, const int type,
76307+ const int protocol);
76308+
76309+#endif
76310diff --git a/include/linux/highmem.h b/include/linux/highmem.h
76311index 7fb31da..08b5114 100644
76312--- a/include/linux/highmem.h
76313+++ b/include/linux/highmem.h
76314@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
76315 kunmap_atomic(kaddr);
76316 }
76317
76318+static inline void sanitize_highpage(struct page *page)
76319+{
76320+ void *kaddr;
76321+ unsigned long flags;
76322+
76323+ local_irq_save(flags);
76324+ kaddr = kmap_atomic(page);
76325+ clear_page(kaddr);
76326+ kunmap_atomic(kaddr);
76327+ local_irq_restore(flags);
76328+}
76329+
76330 static inline void zero_user_segments(struct page *page,
76331 unsigned start1, unsigned end1,
76332 unsigned start2, unsigned end2)
76333diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
76334index 1c7b89a..7dda400 100644
76335--- a/include/linux/hwmon-sysfs.h
76336+++ b/include/linux/hwmon-sysfs.h
76337@@ -25,7 +25,8 @@
76338 struct sensor_device_attribute{
76339 struct device_attribute dev_attr;
76340 int index;
76341-};
76342+} __do_const;
76343+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
76344 #define to_sensor_dev_attr(_dev_attr) \
76345 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
76346
76347@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
76348 struct device_attribute dev_attr;
76349 u8 index;
76350 u8 nr;
76351-};
76352+} __do_const;
76353+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
76354 #define to_sensor_dev_attr_2(_dev_attr) \
76355 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
76356
76357diff --git a/include/linux/i2c.h b/include/linux/i2c.h
76358index 2ab11dc..663a3f2 100644
76359--- a/include/linux/i2c.h
76360+++ b/include/linux/i2c.h
76361@@ -366,6 +366,7 @@ struct i2c_algorithm {
76362 /* To determine what the adapter supports */
76363 u32 (*functionality) (struct i2c_adapter *);
76364 };
76365+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
76366
76367 /**
76368 * struct i2c_bus_recovery_info - I2C bus recovery information
76369diff --git a/include/linux/i2o.h b/include/linux/i2o.h
76370index d23c3c2..eb63c81 100644
76371--- a/include/linux/i2o.h
76372+++ b/include/linux/i2o.h
76373@@ -565,7 +565,7 @@ struct i2o_controller {
76374 struct i2o_device *exec; /* Executive */
76375 #if BITS_PER_LONG == 64
76376 spinlock_t context_list_lock; /* lock for context_list */
76377- atomic_t context_list_counter; /* needed for unique contexts */
76378+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
76379 struct list_head context_list; /* list of context id's
76380 and pointers */
76381 #endif
76382diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
76383index aff7ad8..3942bbd 100644
76384--- a/include/linux/if_pppox.h
76385+++ b/include/linux/if_pppox.h
76386@@ -76,7 +76,7 @@ struct pppox_proto {
76387 int (*ioctl)(struct socket *sock, unsigned int cmd,
76388 unsigned long arg);
76389 struct module *owner;
76390-};
76391+} __do_const;
76392
76393 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
76394 extern void unregister_pppox_proto(int proto_num);
76395diff --git a/include/linux/init.h b/include/linux/init.h
76396index f1c27a71..7d6010e 100644
76397--- a/include/linux/init.h
76398+++ b/include/linux/init.h
76399@@ -39,9 +39,17 @@
76400 * Also note, that this data cannot be "const".
76401 */
76402
76403+#define add_init_latent_entropy __latent_entropy
76404+
76405+#ifdef CONFIG_MEMORY_HOTPLUG
76406+#define add_meminit_latent_entropy
76407+#else
76408+#define add_meminit_latent_entropy __latent_entropy
76409+#endif
76410+
76411 /* These are for everybody (although not all archs will actually
76412 discard it in modules) */
76413-#define __init __section(.init.text) __cold notrace
76414+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
76415 #define __initdata __section(.init.data)
76416 #define __initconst __constsection(.init.rodata)
76417 #define __exitdata __section(.exit.data)
76418@@ -102,7 +110,7 @@
76419 #define __cpuexitconst
76420
76421 /* Used for MEMORY_HOTPLUG */
76422-#define __meminit __section(.meminit.text) __cold notrace
76423+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
76424 #define __meminitdata __section(.meminit.data)
76425 #define __meminitconst __constsection(.meminit.rodata)
76426 #define __memexit __section(.memexit.text) __exitused __cold notrace
76427diff --git a/include/linux/init_task.h b/include/linux/init_task.h
76428index 5cd0f09..c9f67cc 100644
76429--- a/include/linux/init_task.h
76430+++ b/include/linux/init_task.h
76431@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
76432
76433 #define INIT_TASK_COMM "swapper"
76434
76435+#ifdef CONFIG_X86
76436+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
76437+#else
76438+#define INIT_TASK_THREAD_INFO
76439+#endif
76440+
76441 /*
76442 * INIT_TASK is used to set up the first task table, touch at
76443 * your own risk!. Base=0, limit=0x1fffff (=2MB)
76444@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
76445 RCU_POINTER_INITIALIZER(cred, &init_cred), \
76446 .comm = INIT_TASK_COMM, \
76447 .thread = INIT_THREAD, \
76448+ INIT_TASK_THREAD_INFO \
76449 .fs = &init_fs, \
76450 .files = &init_files, \
76451 .signal = &init_signals, \
76452diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
76453index 5e865b5..71bd258 100644
76454--- a/include/linux/interrupt.h
76455+++ b/include/linux/interrupt.h
76456@@ -361,7 +361,7 @@ enum
76457 /* map softirq index to softirq name. update 'softirq_to_name' in
76458 * kernel/softirq.c when adding a new softirq.
76459 */
76460-extern char *softirq_to_name[NR_SOFTIRQS];
76461+extern const char * const softirq_to_name[NR_SOFTIRQS];
76462
76463 /* softirq mask and active fields moved to irq_cpustat_t in
76464 * asm/hardirq.h to get better cache usage. KAO
76465@@ -369,12 +369,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
76466
76467 struct softirq_action
76468 {
76469- void (*action)(struct softirq_action *);
76470-};
76471+ void (*action)(void);
76472+} __no_const;
76473
76474 asmlinkage void do_softirq(void);
76475 asmlinkage void __do_softirq(void);
76476-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
76477+extern void open_softirq(int nr, void (*action)(void));
76478 extern void softirq_init(void);
76479 extern void __raise_softirq_irqoff(unsigned int nr);
76480
76481diff --git a/include/linux/iommu.h b/include/linux/iommu.h
76482index 7ea319e..f9e971d 100644
76483--- a/include/linux/iommu.h
76484+++ b/include/linux/iommu.h
76485@@ -129,7 +129,7 @@ struct iommu_ops {
76486 u32 (*domain_get_windows)(struct iommu_domain *domain);
76487
76488 unsigned long pgsize_bitmap;
76489-};
76490+} __do_const;
76491
76492 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
76493 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
76494diff --git a/include/linux/ioport.h b/include/linux/ioport.h
76495index 89b7c24..382af74 100644
76496--- a/include/linux/ioport.h
76497+++ b/include/linux/ioport.h
76498@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
76499 int adjust_resource(struct resource *res, resource_size_t start,
76500 resource_size_t size);
76501 resource_size_t resource_alignment(struct resource *res);
76502-static inline resource_size_t resource_size(const struct resource *res)
76503+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
76504 {
76505 return res->end - res->start + 1;
76506 }
76507diff --git a/include/linux/irq.h b/include/linux/irq.h
76508index 56bb0dc..8ae94d62 100644
76509--- a/include/linux/irq.h
76510+++ b/include/linux/irq.h
76511@@ -333,7 +333,8 @@ struct irq_chip {
76512 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
76513
76514 unsigned long flags;
76515-};
76516+} __do_const;
76517+typedef struct irq_chip __no_const irq_chip_no_const;
76518
76519 /*
76520 * irq_chip specific flags
76521diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
76522index 0e5d9ec..46acb3a 100644
76523--- a/include/linux/irqchip/arm-gic.h
76524+++ b/include/linux/irqchip/arm-gic.h
76525@@ -59,9 +59,11 @@
76526
76527 #ifndef __ASSEMBLY__
76528
76529+#include <linux/irq.h>
76530+
76531 struct device_node;
76532
76533-extern struct irq_chip gic_arch_extn;
76534+extern irq_chip_no_const gic_arch_extn;
76535
76536 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
76537 u32 offset, struct device_node *);
76538diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
76539index d235e88..8ccbe74 100644
76540--- a/include/linux/jiffies.h
76541+++ b/include/linux/jiffies.h
76542@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
76543 /*
76544 * Convert various time units to each other:
76545 */
76546-extern unsigned int jiffies_to_msecs(const unsigned long j);
76547-extern unsigned int jiffies_to_usecs(const unsigned long j);
76548-extern unsigned long msecs_to_jiffies(const unsigned int m);
76549-extern unsigned long usecs_to_jiffies(const unsigned int u);
76550-extern unsigned long timespec_to_jiffies(const struct timespec *value);
76551+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
76552+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
76553+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
76554+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
76555+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
76556 extern void jiffies_to_timespec(const unsigned long jiffies,
76557 struct timespec *value);
76558-extern unsigned long timeval_to_jiffies(const struct timeval *value);
76559+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
76560 extern void jiffies_to_timeval(const unsigned long jiffies,
76561 struct timeval *value);
76562
76563diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
76564index 6883e19..e854fcb 100644
76565--- a/include/linux/kallsyms.h
76566+++ b/include/linux/kallsyms.h
76567@@ -15,7 +15,8 @@
76568
76569 struct module;
76570
76571-#ifdef CONFIG_KALLSYMS
76572+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
76573+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76574 /* Lookup the address for a symbol. Returns 0 if not found. */
76575 unsigned long kallsyms_lookup_name(const char *name);
76576
76577@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
76578 /* Stupid that this does nothing, but I didn't create this mess. */
76579 #define __print_symbol(fmt, addr)
76580 #endif /*CONFIG_KALLSYMS*/
76581+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
76582+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
76583+extern unsigned long kallsyms_lookup_name(const char *name);
76584+extern void __print_symbol(const char *fmt, unsigned long address);
76585+extern int sprint_backtrace(char *buffer, unsigned long address);
76586+extern int sprint_symbol(char *buffer, unsigned long address);
76587+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
76588+const char *kallsyms_lookup(unsigned long addr,
76589+ unsigned long *symbolsize,
76590+ unsigned long *offset,
76591+ char **modname, char *namebuf);
76592+extern int kallsyms_lookup_size_offset(unsigned long addr,
76593+ unsigned long *symbolsize,
76594+ unsigned long *offset);
76595+#endif
76596
76597 /* This macro allows us to keep printk typechecking */
76598 static __printf(1, 2)
76599diff --git a/include/linux/key-type.h b/include/linux/key-type.h
76600index 518a53a..5e28358 100644
76601--- a/include/linux/key-type.h
76602+++ b/include/linux/key-type.h
76603@@ -125,7 +125,7 @@ struct key_type {
76604 /* internal fields */
76605 struct list_head link; /* link in types list */
76606 struct lock_class_key lock_class; /* key->sem lock class */
76607-};
76608+} __do_const;
76609
76610 extern struct key_type key_type_keyring;
76611
76612diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
76613index c6e091b..a940adf 100644
76614--- a/include/linux/kgdb.h
76615+++ b/include/linux/kgdb.h
76616@@ -52,7 +52,7 @@ extern int kgdb_connected;
76617 extern int kgdb_io_module_registered;
76618
76619 extern atomic_t kgdb_setting_breakpoint;
76620-extern atomic_t kgdb_cpu_doing_single_step;
76621+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
76622
76623 extern struct task_struct *kgdb_usethread;
76624 extern struct task_struct *kgdb_contthread;
76625@@ -254,7 +254,7 @@ struct kgdb_arch {
76626 void (*correct_hw_break)(void);
76627
76628 void (*enable_nmi)(bool on);
76629-};
76630+} __do_const;
76631
76632 /**
76633 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
76634@@ -279,7 +279,7 @@ struct kgdb_io {
76635 void (*pre_exception) (void);
76636 void (*post_exception) (void);
76637 int is_console;
76638-};
76639+} __do_const;
76640
76641 extern struct kgdb_arch arch_kgdb_ops;
76642
76643diff --git a/include/linux/kmod.h b/include/linux/kmod.h
76644index 0555cc6..40116ce 100644
76645--- a/include/linux/kmod.h
76646+++ b/include/linux/kmod.h
76647@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
76648 * usually useless though. */
76649 extern __printf(2, 3)
76650 int __request_module(bool wait, const char *name, ...);
76651+extern __printf(3, 4)
76652+int ___request_module(bool wait, char *param_name, const char *name, ...);
76653 #define request_module(mod...) __request_module(true, mod)
76654 #define request_module_nowait(mod...) __request_module(false, mod)
76655 #define try_then_request_module(x, mod...) \
76656@@ -57,6 +59,9 @@ struct subprocess_info {
76657 struct work_struct work;
76658 struct completion *complete;
76659 char *path;
76660+#ifdef CONFIG_GRKERNSEC
76661+ char *origpath;
76662+#endif
76663 char **argv;
76664 char **envp;
76665 int wait;
76666diff --git a/include/linux/kobject.h b/include/linux/kobject.h
76667index de6dcbcc..4735f88 100644
76668--- a/include/linux/kobject.h
76669+++ b/include/linux/kobject.h
76670@@ -115,7 +115,7 @@ struct kobj_type {
76671 struct attribute **default_attrs;
76672 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
76673 const void *(*namespace)(struct kobject *kobj);
76674-};
76675+} __do_const;
76676
76677 struct kobj_uevent_env {
76678 char *envp[UEVENT_NUM_ENVP];
76679@@ -138,6 +138,7 @@ struct kobj_attribute {
76680 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
76681 const char *buf, size_t count);
76682 };
76683+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
76684
76685 extern const struct sysfs_ops kobj_sysfs_ops;
76686
76687diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
76688index df32d25..fb52e27 100644
76689--- a/include/linux/kobject_ns.h
76690+++ b/include/linux/kobject_ns.h
76691@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
76692 const void *(*netlink_ns)(struct sock *sk);
76693 const void *(*initial_ns)(void);
76694 void (*drop_ns)(void *);
76695-};
76696+} __do_const;
76697
76698 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
76699 int kobj_ns_type_registered(enum kobj_ns_type type);
76700diff --git a/include/linux/kref.h b/include/linux/kref.h
76701index 484604d..0f6c5b6 100644
76702--- a/include/linux/kref.h
76703+++ b/include/linux/kref.h
76704@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
76705 static inline int kref_sub(struct kref *kref, unsigned int count,
76706 void (*release)(struct kref *kref))
76707 {
76708- WARN_ON(release == NULL);
76709+ BUG_ON(release == NULL);
76710
76711 if (atomic_sub_and_test((int) count, &kref->refcount)) {
76712 release(kref);
76713diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
76714index 0fbbc7a..db081e3 100644
76715--- a/include/linux/kvm_host.h
76716+++ b/include/linux/kvm_host.h
76717@@ -458,7 +458,7 @@ static inline void kvm_irqfd_exit(void)
76718 {
76719 }
76720 #endif
76721-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76722+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76723 struct module *module);
76724 void kvm_exit(void);
76725
76726@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
76727 struct kvm_guest_debug *dbg);
76728 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
76729
76730-int kvm_arch_init(void *opaque);
76731+int kvm_arch_init(const void *opaque);
76732 void kvm_arch_exit(void);
76733
76734 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
76735diff --git a/include/linux/libata.h b/include/linux/libata.h
76736index 0e23c26..6ad8c33 100644
76737--- a/include/linux/libata.h
76738+++ b/include/linux/libata.h
76739@@ -972,7 +972,7 @@ struct ata_port_operations {
76740 * fields must be pointers.
76741 */
76742 const struct ata_port_operations *inherits;
76743-};
76744+} __do_const;
76745
76746 struct ata_port_info {
76747 unsigned long flags;
76748diff --git a/include/linux/linkage.h b/include/linux/linkage.h
76749index d3e8ad2..a949f68 100644
76750--- a/include/linux/linkage.h
76751+++ b/include/linux/linkage.h
76752@@ -31,6 +31,7 @@
76753 #endif
76754
76755 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
76756+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
76757 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
76758
76759 /*
76760diff --git a/include/linux/list.h b/include/linux/list.h
76761index f4d8a2f..38e6e46 100644
76762--- a/include/linux/list.h
76763+++ b/include/linux/list.h
76764@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
76765 extern void list_del(struct list_head *entry);
76766 #endif
76767
76768+extern void __pax_list_add(struct list_head *new,
76769+ struct list_head *prev,
76770+ struct list_head *next);
76771+static inline void pax_list_add(struct list_head *new, struct list_head *head)
76772+{
76773+ __pax_list_add(new, head, head->next);
76774+}
76775+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
76776+{
76777+ __pax_list_add(new, head->prev, head);
76778+}
76779+extern void pax_list_del(struct list_head *entry);
76780+
76781 /**
76782 * list_replace - replace old entry by new one
76783 * @old : the element to be replaced
76784@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
76785 INIT_LIST_HEAD(entry);
76786 }
76787
76788+extern void pax_list_del_init(struct list_head *entry);
76789+
76790 /**
76791 * list_move - delete from one list and add as another's head
76792 * @list: the entry to move
76793diff --git a/include/linux/math64.h b/include/linux/math64.h
76794index 69ed5f5..243ed51 100644
76795--- a/include/linux/math64.h
76796+++ b/include/linux/math64.h
76797@@ -15,7 +15,7 @@
76798 * This is commonly provided by 32bit archs to provide an optimized 64bit
76799 * divide.
76800 */
76801-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76802+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76803 {
76804 *remainder = dividend % divisor;
76805 return dividend / divisor;
76806@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
76807 /**
76808 * div64_u64 - unsigned 64bit divide with 64bit divisor
76809 */
76810-static inline u64 div64_u64(u64 dividend, u64 divisor)
76811+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
76812 {
76813 return dividend / divisor;
76814 }
76815@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
76816 #define div64_ul(x, y) div_u64((x), (y))
76817
76818 #ifndef div_u64_rem
76819-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76820+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76821 {
76822 *remainder = do_div(dividend, divisor);
76823 return dividend;
76824@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
76825 #endif
76826
76827 #ifndef div64_u64
76828-extern u64 div64_u64(u64 dividend, u64 divisor);
76829+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
76830 #endif
76831
76832 #ifndef div64_s64
76833@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
76834 * divide.
76835 */
76836 #ifndef div_u64
76837-static inline u64 div_u64(u64 dividend, u32 divisor)
76838+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
76839 {
76840 u32 remainder;
76841 return div_u64_rem(dividend, divisor, &remainder);
76842diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
76843index da6716b..2e31db3 100644
76844--- a/include/linux/mempolicy.h
76845+++ b/include/linux/mempolicy.h
76846@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
76847 }
76848
76849 #define vma_policy(vma) ((vma)->vm_policy)
76850+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
76851+{
76852+ vma->vm_policy = pol;
76853+}
76854
76855 static inline void mpol_get(struct mempolicy *pol)
76856 {
76857@@ -240,6 +244,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
76858 }
76859
76860 #define vma_policy(vma) NULL
76861+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
76862+{
76863+}
76864
76865 static inline int
76866 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
76867diff --git a/include/linux/mm.h b/include/linux/mm.h
76868index 8b6e55e..c4edf39 100644
76869--- a/include/linux/mm.h
76870+++ b/include/linux/mm.h
76871@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
76872 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
76873 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
76874 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
76875+
76876+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76877+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
76878+#endif
76879+
76880 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
76881
76882 #ifdef CONFIG_MEM_SOFT_DIRTY
76883@@ -215,8 +220,8 @@ struct vm_operations_struct {
76884 /* called by access_process_vm when get_user_pages() fails, typically
76885 * for use by special VMAs that can switch between memory and hardware
76886 */
76887- int (*access)(struct vm_area_struct *vma, unsigned long addr,
76888- void *buf, int len, int write);
76889+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
76890+ void *buf, size_t len, int write);
76891 #ifdef CONFIG_NUMA
76892 /*
76893 * set_policy() op must add a reference to any non-NULL @new mempolicy
76894@@ -246,6 +251,7 @@ struct vm_operations_struct {
76895 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
76896 unsigned long size, pgoff_t pgoff);
76897 };
76898+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
76899
76900 struct mmu_gather;
76901 struct inode;
76902@@ -977,8 +983,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
76903 unsigned long *pfn);
76904 int follow_phys(struct vm_area_struct *vma, unsigned long address,
76905 unsigned int flags, unsigned long *prot, resource_size_t *phys);
76906-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76907- void *buf, int len, int write);
76908+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76909+ void *buf, size_t len, int write);
76910
76911 static inline void unmap_shared_mapping_range(struct address_space *mapping,
76912 loff_t const holebegin, loff_t const holelen)
76913@@ -1017,9 +1023,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
76914 }
76915 #endif
76916
76917-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
76918-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
76919- void *buf, int len, int write);
76920+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
76921+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
76922+ void *buf, size_t len, int write);
76923
76924 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76925 unsigned long start, unsigned long nr_pages,
76926@@ -1051,34 +1057,6 @@ int set_page_dirty(struct page *page);
76927 int set_page_dirty_lock(struct page *page);
76928 int clear_page_dirty_for_io(struct page *page);
76929
76930-/* Is the vma a continuation of the stack vma above it? */
76931-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
76932-{
76933- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
76934-}
76935-
76936-static inline int stack_guard_page_start(struct vm_area_struct *vma,
76937- unsigned long addr)
76938-{
76939- return (vma->vm_flags & VM_GROWSDOWN) &&
76940- (vma->vm_start == addr) &&
76941- !vma_growsdown(vma->vm_prev, addr);
76942-}
76943-
76944-/* Is the vma a continuation of the stack vma below it? */
76945-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
76946-{
76947- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
76948-}
76949-
76950-static inline int stack_guard_page_end(struct vm_area_struct *vma,
76951- unsigned long addr)
76952-{
76953- return (vma->vm_flags & VM_GROWSUP) &&
76954- (vma->vm_end == addr) &&
76955- !vma_growsup(vma->vm_next, addr);
76956-}
76957-
76958 extern pid_t
76959 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
76960
76961@@ -1178,6 +1156,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
76962 }
76963 #endif
76964
76965+#ifdef CONFIG_MMU
76966+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
76967+#else
76968+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76969+{
76970+ return __pgprot(0);
76971+}
76972+#endif
76973+
76974 int vma_wants_writenotify(struct vm_area_struct *vma);
76975
76976 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
76977@@ -1196,8 +1183,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
76978 {
76979 return 0;
76980 }
76981+
76982+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
76983+ unsigned long address)
76984+{
76985+ return 0;
76986+}
76987 #else
76988 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76989+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76990 #endif
76991
76992 #ifdef __PAGETABLE_PMD_FOLDED
76993@@ -1206,8 +1200,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
76994 {
76995 return 0;
76996 }
76997+
76998+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
76999+ unsigned long address)
77000+{
77001+ return 0;
77002+}
77003 #else
77004 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
77005+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
77006 #endif
77007
77008 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
77009@@ -1225,11 +1226,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
77010 NULL: pud_offset(pgd, address);
77011 }
77012
77013+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
77014+{
77015+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
77016+ NULL: pud_offset(pgd, address);
77017+}
77018+
77019 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
77020 {
77021 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
77022 NULL: pmd_offset(pud, address);
77023 }
77024+
77025+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
77026+{
77027+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
77028+ NULL: pmd_offset(pud, address);
77029+}
77030 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
77031
77032 #if USE_SPLIT_PTLOCKS
77033@@ -1517,7 +1530,7 @@ extern int install_special_mapping(struct mm_struct *mm,
77034 unsigned long addr, unsigned long len,
77035 unsigned long flags, struct page **pages);
77036
77037-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
77038+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
77039
77040 extern unsigned long mmap_region(struct file *file, unsigned long addr,
77041 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
77042@@ -1525,6 +1538,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77043 unsigned long len, unsigned long prot, unsigned long flags,
77044 unsigned long pgoff, unsigned long *populate);
77045 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
77046+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
77047
77048 #ifdef CONFIG_MMU
77049 extern int __mm_populate(unsigned long addr, unsigned long len,
77050@@ -1553,10 +1567,11 @@ struct vm_unmapped_area_info {
77051 unsigned long high_limit;
77052 unsigned long align_mask;
77053 unsigned long align_offset;
77054+ unsigned long threadstack_offset;
77055 };
77056
77057-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
77058-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
77059+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
77060+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
77061
77062 /*
77063 * Search for an unmapped address range.
77064@@ -1568,7 +1583,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
77065 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
77066 */
77067 static inline unsigned long
77068-vm_unmapped_area(struct vm_unmapped_area_info *info)
77069+vm_unmapped_area(const struct vm_unmapped_area_info *info)
77070 {
77071 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
77072 return unmapped_area(info);
77073@@ -1631,6 +1646,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
77074 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
77075 struct vm_area_struct **pprev);
77076
77077+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
77078+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
77079+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
77080+
77081 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
77082 NULL if none. Assume start_addr < end_addr. */
77083 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
77084@@ -1659,15 +1678,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
77085 return vma;
77086 }
77087
77088-#ifdef CONFIG_MMU
77089-pgprot_t vm_get_page_prot(unsigned long vm_flags);
77090-#else
77091-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
77092-{
77093- return __pgprot(0);
77094-}
77095-#endif
77096-
77097 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
77098 unsigned long change_prot_numa(struct vm_area_struct *vma,
77099 unsigned long start, unsigned long end);
77100@@ -1719,6 +1729,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
77101 static inline void vm_stat_account(struct mm_struct *mm,
77102 unsigned long flags, struct file *file, long pages)
77103 {
77104+
77105+#ifdef CONFIG_PAX_RANDMMAP
77106+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
77107+#endif
77108+
77109 mm->total_vm += pages;
77110 }
77111 #endif /* CONFIG_PROC_FS */
77112@@ -1800,7 +1815,7 @@ extern int unpoison_memory(unsigned long pfn);
77113 extern int sysctl_memory_failure_early_kill;
77114 extern int sysctl_memory_failure_recovery;
77115 extern void shake_page(struct page *p, int access);
77116-extern atomic_long_t num_poisoned_pages;
77117+extern atomic_long_unchecked_t num_poisoned_pages;
77118 extern int soft_offline_page(struct page *page, int flags);
77119
77120 extern void dump_page(struct page *page);
77121@@ -1837,5 +1852,11 @@ void __init setup_nr_node_ids(void);
77122 static inline void setup_nr_node_ids(void) {}
77123 #endif
77124
77125+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77126+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
77127+#else
77128+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
77129+#endif
77130+
77131 #endif /* __KERNEL__ */
77132 #endif /* _LINUX_MM_H */
77133diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
77134index d9851ee..619492d 100644
77135--- a/include/linux/mm_types.h
77136+++ b/include/linux/mm_types.h
77137@@ -289,6 +289,8 @@ struct vm_area_struct {
77138 #ifdef CONFIG_NUMA
77139 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
77140 #endif
77141+
77142+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
77143 };
77144
77145 struct core_thread {
77146@@ -436,6 +438,24 @@ struct mm_struct {
77147 int first_nid;
77148 #endif
77149 struct uprobes_state uprobes_state;
77150+
77151+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77152+ unsigned long pax_flags;
77153+#endif
77154+
77155+#ifdef CONFIG_PAX_DLRESOLVE
77156+ unsigned long call_dl_resolve;
77157+#endif
77158+
77159+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
77160+ unsigned long call_syscall;
77161+#endif
77162+
77163+#ifdef CONFIG_PAX_ASLR
77164+ unsigned long delta_mmap; /* randomized offset */
77165+ unsigned long delta_stack; /* randomized offset */
77166+#endif
77167+
77168 };
77169
77170 /* first nid will either be a valid NID or one of these values */
77171diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
77172index c5d5278..f0b68c8 100644
77173--- a/include/linux/mmiotrace.h
77174+++ b/include/linux/mmiotrace.h
77175@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
77176 /* Called from ioremap.c */
77177 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
77178 void __iomem *addr);
77179-extern void mmiotrace_iounmap(volatile void __iomem *addr);
77180+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
77181
77182 /* For anyone to insert markers. Remember trailing newline. */
77183 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
77184@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
77185 {
77186 }
77187
77188-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
77189+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
77190 {
77191 }
77192
77193diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
77194index bd791e4..8617c34f 100644
77195--- a/include/linux/mmzone.h
77196+++ b/include/linux/mmzone.h
77197@@ -396,7 +396,7 @@ struct zone {
77198 unsigned long flags; /* zone flags, see below */
77199
77200 /* Zone statistics */
77201- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77202+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77203
77204 /*
77205 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
77206diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
77207index 45e9214..a7227d6 100644
77208--- a/include/linux/mod_devicetable.h
77209+++ b/include/linux/mod_devicetable.h
77210@@ -13,7 +13,7 @@
77211 typedef unsigned long kernel_ulong_t;
77212 #endif
77213
77214-#define PCI_ANY_ID (~0)
77215+#define PCI_ANY_ID ((__u16)~0)
77216
77217 struct pci_device_id {
77218 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
77219@@ -139,7 +139,7 @@ struct usb_device_id {
77220 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
77221 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
77222
77223-#define HID_ANY_ID (~0)
77224+#define HID_ANY_ID (~0U)
77225 #define HID_BUS_ANY 0xffff
77226 #define HID_GROUP_ANY 0x0000
77227
77228@@ -467,7 +467,7 @@ struct dmi_system_id {
77229 const char *ident;
77230 struct dmi_strmatch matches[4];
77231 void *driver_data;
77232-};
77233+} __do_const;
77234 /*
77235 * struct dmi_device_id appears during expansion of
77236 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
77237diff --git a/include/linux/module.h b/include/linux/module.h
77238index 05f2447..2aee07c 100644
77239--- a/include/linux/module.h
77240+++ b/include/linux/module.h
77241@@ -17,9 +17,11 @@
77242 #include <linux/moduleparam.h>
77243 #include <linux/tracepoint.h>
77244 #include <linux/export.h>
77245+#include <linux/fs.h>
77246
77247 #include <linux/percpu.h>
77248 #include <asm/module.h>
77249+#include <asm/pgtable.h>
77250
77251 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
77252 #define MODULE_SIG_STRING "~Module signature appended~\n"
77253@@ -55,12 +57,13 @@ struct module_attribute {
77254 int (*test)(struct module *);
77255 void (*free)(struct module *);
77256 };
77257+typedef struct module_attribute __no_const module_attribute_no_const;
77258
77259 struct module_version_attribute {
77260 struct module_attribute mattr;
77261 const char *module_name;
77262 const char *version;
77263-} __attribute__ ((__aligned__(sizeof(void *))));
77264+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
77265
77266 extern ssize_t __modver_version_show(struct module_attribute *,
77267 struct module_kobject *, char *);
77268@@ -238,7 +241,7 @@ struct module
77269
77270 /* Sysfs stuff. */
77271 struct module_kobject mkobj;
77272- struct module_attribute *modinfo_attrs;
77273+ module_attribute_no_const *modinfo_attrs;
77274 const char *version;
77275 const char *srcversion;
77276 struct kobject *holders_dir;
77277@@ -287,19 +290,16 @@ struct module
77278 int (*init)(void);
77279
77280 /* If this is non-NULL, vfree after init() returns */
77281- void *module_init;
77282+ void *module_init_rx, *module_init_rw;
77283
77284 /* Here is the actual code + data, vfree'd on unload. */
77285- void *module_core;
77286+ void *module_core_rx, *module_core_rw;
77287
77288 /* Here are the sizes of the init and core sections */
77289- unsigned int init_size, core_size;
77290+ unsigned int init_size_rw, core_size_rw;
77291
77292 /* The size of the executable code in each section. */
77293- unsigned int init_text_size, core_text_size;
77294-
77295- /* Size of RO sections of the module (text+rodata) */
77296- unsigned int init_ro_size, core_ro_size;
77297+ unsigned int init_size_rx, core_size_rx;
77298
77299 /* Arch-specific module values */
77300 struct mod_arch_specific arch;
77301@@ -355,6 +355,10 @@ struct module
77302 #ifdef CONFIG_EVENT_TRACING
77303 struct ftrace_event_call **trace_events;
77304 unsigned int num_trace_events;
77305+ struct file_operations trace_id;
77306+ struct file_operations trace_enable;
77307+ struct file_operations trace_format;
77308+ struct file_operations trace_filter;
77309 #endif
77310 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
77311 unsigned int num_ftrace_callsites;
77312@@ -402,16 +406,46 @@ bool is_module_address(unsigned long addr);
77313 bool is_module_percpu_address(unsigned long addr);
77314 bool is_module_text_address(unsigned long addr);
77315
77316+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
77317+{
77318+
77319+#ifdef CONFIG_PAX_KERNEXEC
77320+ if (ktla_ktva(addr) >= (unsigned long)start &&
77321+ ktla_ktva(addr) < (unsigned long)start + size)
77322+ return 1;
77323+#endif
77324+
77325+ return ((void *)addr >= start && (void *)addr < start + size);
77326+}
77327+
77328+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
77329+{
77330+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
77331+}
77332+
77333+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
77334+{
77335+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
77336+}
77337+
77338+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
77339+{
77340+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
77341+}
77342+
77343+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
77344+{
77345+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
77346+}
77347+
77348 static inline int within_module_core(unsigned long addr, const struct module *mod)
77349 {
77350- return (unsigned long)mod->module_core <= addr &&
77351- addr < (unsigned long)mod->module_core + mod->core_size;
77352+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
77353 }
77354
77355 static inline int within_module_init(unsigned long addr, const struct module *mod)
77356 {
77357- return (unsigned long)mod->module_init <= addr &&
77358- addr < (unsigned long)mod->module_init + mod->init_size;
77359+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
77360 }
77361
77362 /* Search for module by name: must hold module_mutex. */
77363diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
77364index 560ca53..ef621ef 100644
77365--- a/include/linux/moduleloader.h
77366+++ b/include/linux/moduleloader.h
77367@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
77368 sections. Returns NULL on failure. */
77369 void *module_alloc(unsigned long size);
77370
77371+#ifdef CONFIG_PAX_KERNEXEC
77372+void *module_alloc_exec(unsigned long size);
77373+#else
77374+#define module_alloc_exec(x) module_alloc(x)
77375+#endif
77376+
77377 /* Free memory returned from module_alloc. */
77378 void module_free(struct module *mod, void *module_region);
77379
77380+#ifdef CONFIG_PAX_KERNEXEC
77381+void module_free_exec(struct module *mod, void *module_region);
77382+#else
77383+#define module_free_exec(x, y) module_free((x), (y))
77384+#endif
77385+
77386 /*
77387 * Apply the given relocation to the (simplified) ELF. Return -error
77388 * or 0.
77389@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
77390 unsigned int relsec,
77391 struct module *me)
77392 {
77393+#ifdef CONFIG_MODULES
77394 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
77395+#endif
77396 return -ENOEXEC;
77397 }
77398 #endif
77399@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
77400 unsigned int relsec,
77401 struct module *me)
77402 {
77403+#ifdef CONFIG_MODULES
77404 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
77405+#endif
77406 return -ENOEXEC;
77407 }
77408 #endif
77409diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
77410index c3eb102..073c4a6 100644
77411--- a/include/linux/moduleparam.h
77412+++ b/include/linux/moduleparam.h
77413@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
77414 * @len is usually just sizeof(string).
77415 */
77416 #define module_param_string(name, string, len, perm) \
77417- static const struct kparam_string __param_string_##name \
77418+ static const struct kparam_string __param_string_##name __used \
77419 = { len, string }; \
77420 __module_param_call(MODULE_PARAM_PREFIX, name, \
77421 &param_ops_string, \
77422@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
77423 */
77424 #define module_param_array_named(name, array, type, nump, perm) \
77425 param_check_##type(name, &(array)[0]); \
77426- static const struct kparam_array __param_arr_##name \
77427+ static const struct kparam_array __param_arr_##name __used \
77428 = { .max = ARRAY_SIZE(array), .num = nump, \
77429 .ops = &param_ops_##type, \
77430 .elemsize = sizeof(array[0]), .elem = array }; \
77431diff --git a/include/linux/namei.h b/include/linux/namei.h
77432index 8e47bc7..c70fd73 100644
77433--- a/include/linux/namei.h
77434+++ b/include/linux/namei.h
77435@@ -19,7 +19,7 @@ struct nameidata {
77436 unsigned seq;
77437 int last_type;
77438 unsigned depth;
77439- char *saved_names[MAX_NESTED_LINKS + 1];
77440+ const char *saved_names[MAX_NESTED_LINKS + 1];
77441 };
77442
77443 /*
77444@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
77445
77446 extern void nd_jump_link(struct nameidata *nd, struct path *path);
77447
77448-static inline void nd_set_link(struct nameidata *nd, char *path)
77449+static inline void nd_set_link(struct nameidata *nd, const char *path)
77450 {
77451 nd->saved_names[nd->depth] = path;
77452 }
77453
77454-static inline char *nd_get_link(struct nameidata *nd)
77455+static inline const char *nd_get_link(const struct nameidata *nd)
77456 {
77457 return nd->saved_names[nd->depth];
77458 }
77459diff --git a/include/linux/net.h b/include/linux/net.h
77460index 8bd9d92..08b1c20 100644
77461--- a/include/linux/net.h
77462+++ b/include/linux/net.h
77463@@ -191,7 +191,7 @@ struct net_proto_family {
77464 int (*create)(struct net *net, struct socket *sock,
77465 int protocol, int kern);
77466 struct module *owner;
77467-};
77468+} __do_const;
77469
77470 struct iovec;
77471 struct kvec;
77472diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
77473index 25f5d2d1..5cf2120 100644
77474--- a/include/linux/netdevice.h
77475+++ b/include/linux/netdevice.h
77476@@ -1098,6 +1098,7 @@ struct net_device_ops {
77477 sa_family_t sa_family,
77478 __be16 port);
77479 };
77480+typedef struct net_device_ops __no_const net_device_ops_no_const;
77481
77482 /*
77483 * The DEVICE structure.
77484@@ -1169,7 +1170,7 @@ struct net_device {
77485 int iflink;
77486
77487 struct net_device_stats stats;
77488- atomic_long_t rx_dropped; /* dropped packets by core network
77489+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
77490 * Do not use this in drivers.
77491 */
77492
77493diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
77494index 708fe72ab9..77084a3 100644
77495--- a/include/linux/netfilter.h
77496+++ b/include/linux/netfilter.h
77497@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
77498 #endif
77499 /* Use the module struct to lock set/get code in place */
77500 struct module *owner;
77501-};
77502+} __do_const;
77503
77504 /* Function to register/unregister hook points. */
77505 int nf_register_hook(struct nf_hook_ops *reg);
77506diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
77507index cadb740..d7c37c0 100644
77508--- a/include/linux/netfilter/nfnetlink.h
77509+++ b/include/linux/netfilter/nfnetlink.h
77510@@ -16,7 +16,7 @@ struct nfnl_callback {
77511 const struct nlattr * const cda[]);
77512 const struct nla_policy *policy; /* netlink attribute policy */
77513 const u_int16_t attr_count; /* number of nlattr's */
77514-};
77515+} __do_const;
77516
77517 struct nfnetlink_subsystem {
77518 const char *name;
77519diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
77520new file mode 100644
77521index 0000000..33f4af8
77522--- /dev/null
77523+++ b/include/linux/netfilter/xt_gradm.h
77524@@ -0,0 +1,9 @@
77525+#ifndef _LINUX_NETFILTER_XT_GRADM_H
77526+#define _LINUX_NETFILTER_XT_GRADM_H 1
77527+
77528+struct xt_gradm_mtinfo {
77529+ __u16 flags;
77530+ __u16 invflags;
77531+};
77532+
77533+#endif
77534diff --git a/include/linux/nls.h b/include/linux/nls.h
77535index 5dc635f..35f5e11 100644
77536--- a/include/linux/nls.h
77537+++ b/include/linux/nls.h
77538@@ -31,7 +31,7 @@ struct nls_table {
77539 const unsigned char *charset2upper;
77540 struct module *owner;
77541 struct nls_table *next;
77542-};
77543+} __do_const;
77544
77545 /* this value hold the maximum octet of charset */
77546 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
77547diff --git a/include/linux/notifier.h b/include/linux/notifier.h
77548index d14a4c3..a078786 100644
77549--- a/include/linux/notifier.h
77550+++ b/include/linux/notifier.h
77551@@ -54,7 +54,8 @@ struct notifier_block {
77552 notifier_fn_t notifier_call;
77553 struct notifier_block __rcu *next;
77554 int priority;
77555-};
77556+} __do_const;
77557+typedef struct notifier_block __no_const notifier_block_no_const;
77558
77559 struct atomic_notifier_head {
77560 spinlock_t lock;
77561diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
77562index b2a0f15..4d7da32 100644
77563--- a/include/linux/oprofile.h
77564+++ b/include/linux/oprofile.h
77565@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
77566 int oprofilefs_create_ro_ulong(struct dentry * root,
77567 char const * name, ulong * val);
77568
77569-/** Create a file for read-only access to an atomic_t. */
77570+/** Create a file for read-only access to an atomic_unchecked_t. */
77571 int oprofilefs_create_ro_atomic(struct dentry * root,
77572- char const * name, atomic_t * val);
77573+ char const * name, atomic_unchecked_t * val);
77574
77575 /** create a directory */
77576 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
77577diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
77578index 430dd96..544e26e 100644
77579--- a/include/linux/pci_hotplug.h
77580+++ b/include/linux/pci_hotplug.h
77581@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
77582 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
77583 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
77584 int (*reset_slot) (struct hotplug_slot *slot, int probe);
77585-};
77586+} __do_const;
77587+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
77588
77589 /**
77590 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
77591diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
77592index c8ba627..24bdfa8 100644
77593--- a/include/linux/perf_event.h
77594+++ b/include/linux/perf_event.h
77595@@ -327,8 +327,8 @@ struct perf_event {
77596
77597 enum perf_event_active_state state;
77598 unsigned int attach_state;
77599- local64_t count;
77600- atomic64_t child_count;
77601+ local64_t count; /* PaX: fix it one day */
77602+ atomic64_unchecked_t child_count;
77603
77604 /*
77605 * These are the total time in nanoseconds that the event
77606@@ -379,8 +379,8 @@ struct perf_event {
77607 * These accumulate total time (in nanoseconds) that children
77608 * events have been enabled and running, respectively.
77609 */
77610- atomic64_t child_total_time_enabled;
77611- atomic64_t child_total_time_running;
77612+ atomic64_unchecked_t child_total_time_enabled;
77613+ atomic64_unchecked_t child_total_time_running;
77614
77615 /*
77616 * Protect attach/detach and child_list:
77617@@ -702,7 +702,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
77618 entry->ip[entry->nr++] = ip;
77619 }
77620
77621-extern int sysctl_perf_event_paranoid;
77622+extern int sysctl_perf_event_legitimately_concerned;
77623 extern int sysctl_perf_event_mlock;
77624 extern int sysctl_perf_event_sample_rate;
77625 extern int sysctl_perf_cpu_time_max_percent;
77626@@ -717,19 +717,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
77627 loff_t *ppos);
77628
77629
77630+static inline bool perf_paranoid_any(void)
77631+{
77632+ return sysctl_perf_event_legitimately_concerned > 2;
77633+}
77634+
77635 static inline bool perf_paranoid_tracepoint_raw(void)
77636 {
77637- return sysctl_perf_event_paranoid > -1;
77638+ return sysctl_perf_event_legitimately_concerned > -1;
77639 }
77640
77641 static inline bool perf_paranoid_cpu(void)
77642 {
77643- return sysctl_perf_event_paranoid > 0;
77644+ return sysctl_perf_event_legitimately_concerned > 0;
77645 }
77646
77647 static inline bool perf_paranoid_kernel(void)
77648 {
77649- return sysctl_perf_event_paranoid > 1;
77650+ return sysctl_perf_event_legitimately_concerned > 1;
77651 }
77652
77653 extern void perf_event_init(void);
77654@@ -845,7 +850,7 @@ struct perf_pmu_events_attr {
77655 struct device_attribute attr;
77656 u64 id;
77657 const char *event_str;
77658-};
77659+} __do_const;
77660
77661 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
77662 static struct perf_pmu_events_attr _var = { \
77663diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
77664index b8809fe..ae4ccd0 100644
77665--- a/include/linux/pipe_fs_i.h
77666+++ b/include/linux/pipe_fs_i.h
77667@@ -47,10 +47,10 @@ struct pipe_inode_info {
77668 struct mutex mutex;
77669 wait_queue_head_t wait;
77670 unsigned int nrbufs, curbuf, buffers;
77671- unsigned int readers;
77672- unsigned int writers;
77673- unsigned int files;
77674- unsigned int waiting_writers;
77675+ atomic_t readers;
77676+ atomic_t writers;
77677+ atomic_t files;
77678+ atomic_t waiting_writers;
77679 unsigned int r_counter;
77680 unsigned int w_counter;
77681 struct page *tmp_page;
77682diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
77683index 5f28cae..3d23723 100644
77684--- a/include/linux/platform_data/usb-ehci-s5p.h
77685+++ b/include/linux/platform_data/usb-ehci-s5p.h
77686@@ -14,7 +14,7 @@
77687 struct s5p_ehci_platdata {
77688 int (*phy_init)(struct platform_device *pdev, int type);
77689 int (*phy_exit)(struct platform_device *pdev, int type);
77690-};
77691+} __no_const;
77692
77693 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
77694
77695diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
77696index c256c59..8ea94c7 100644
77697--- a/include/linux/platform_data/usb-ohci-exynos.h
77698+++ b/include/linux/platform_data/usb-ohci-exynos.h
77699@@ -14,7 +14,7 @@
77700 struct exynos4_ohci_platdata {
77701 int (*phy_init)(struct platform_device *pdev, int type);
77702 int (*phy_exit)(struct platform_device *pdev, int type);
77703-};
77704+} __no_const;
77705
77706 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
77707
77708diff --git a/include/linux/pm.h b/include/linux/pm.h
77709index a224c7f..92d8a97 100644
77710--- a/include/linux/pm.h
77711+++ b/include/linux/pm.h
77712@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
77713 struct dev_pm_domain {
77714 struct dev_pm_ops ops;
77715 };
77716+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
77717
77718 /*
77719 * The PM_EVENT_ messages are also used by drivers implementing the legacy
77720diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
77721index 7c1d252..c5c773e 100644
77722--- a/include/linux/pm_domain.h
77723+++ b/include/linux/pm_domain.h
77724@@ -48,7 +48,7 @@ struct gpd_dev_ops {
77725
77726 struct gpd_cpu_data {
77727 unsigned int saved_exit_latency;
77728- struct cpuidle_state *idle_state;
77729+ cpuidle_state_no_const *idle_state;
77730 };
77731
77732 struct generic_pm_domain {
77733diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
77734index 6fa7cea..7bf6415 100644
77735--- a/include/linux/pm_runtime.h
77736+++ b/include/linux/pm_runtime.h
77737@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
77738
77739 static inline void pm_runtime_mark_last_busy(struct device *dev)
77740 {
77741- ACCESS_ONCE(dev->power.last_busy) = jiffies;
77742+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
77743 }
77744
77745 #else /* !CONFIG_PM_RUNTIME */
77746diff --git a/include/linux/pnp.h b/include/linux/pnp.h
77747index 195aafc..49a7bc2 100644
77748--- a/include/linux/pnp.h
77749+++ b/include/linux/pnp.h
77750@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
77751 struct pnp_fixup {
77752 char id[7];
77753 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
77754-};
77755+} __do_const;
77756
77757 /* config parameters */
77758 #define PNP_CONFIG_NORMAL 0x0001
77759diff --git a/include/linux/poison.h b/include/linux/poison.h
77760index 2110a81..13a11bb 100644
77761--- a/include/linux/poison.h
77762+++ b/include/linux/poison.h
77763@@ -19,8 +19,8 @@
77764 * under normal circumstances, used to verify that nobody uses
77765 * non-initialized list entries.
77766 */
77767-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
77768-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
77769+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
77770+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
77771
77772 /********** include/linux/timer.h **********/
77773 /*
77774diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
77775index d8b187c3..9a9257a 100644
77776--- a/include/linux/power/smartreflex.h
77777+++ b/include/linux/power/smartreflex.h
77778@@ -238,7 +238,7 @@ struct omap_sr_class_data {
77779 int (*notify)(struct omap_sr *sr, u32 status);
77780 u8 notify_flags;
77781 u8 class_type;
77782-};
77783+} __do_const;
77784
77785 /**
77786 * struct omap_sr_nvalue_table - Smartreflex n-target value info
77787diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
77788index 4ea1d37..80f4b33 100644
77789--- a/include/linux/ppp-comp.h
77790+++ b/include/linux/ppp-comp.h
77791@@ -84,7 +84,7 @@ struct compressor {
77792 struct module *owner;
77793 /* Extra skb space needed by the compressor algorithm */
77794 unsigned int comp_extra;
77795-};
77796+} __do_const;
77797
77798 /*
77799 * The return value from decompress routine is the length of the
77800diff --git a/include/linux/preempt.h b/include/linux/preempt.h
77801index f5d4723..a6ea2fa 100644
77802--- a/include/linux/preempt.h
77803+++ b/include/linux/preempt.h
77804@@ -18,8 +18,13 @@
77805 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77806 #endif
77807
77808+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
77809+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77810+
77811 #define inc_preempt_count() add_preempt_count(1)
77812+#define raw_inc_preempt_count() raw_add_preempt_count(1)
77813 #define dec_preempt_count() sub_preempt_count(1)
77814+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
77815
77816 #define preempt_count() (current_thread_info()->preempt_count)
77817
77818@@ -64,6 +69,12 @@ do { \
77819 barrier(); \
77820 } while (0)
77821
77822+#define raw_preempt_disable() \
77823+do { \
77824+ raw_inc_preempt_count(); \
77825+ barrier(); \
77826+} while (0)
77827+
77828 #define sched_preempt_enable_no_resched() \
77829 do { \
77830 barrier(); \
77831@@ -72,6 +83,12 @@ do { \
77832
77833 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
77834
77835+#define raw_preempt_enable_no_resched() \
77836+do { \
77837+ barrier(); \
77838+ raw_dec_preempt_count(); \
77839+} while (0)
77840+
77841 #define preempt_enable() \
77842 do { \
77843 preempt_enable_no_resched(); \
77844@@ -116,8 +133,10 @@ do { \
77845 * region.
77846 */
77847 #define preempt_disable() barrier()
77848+#define raw_preempt_disable() barrier()
77849 #define sched_preempt_enable_no_resched() barrier()
77850 #define preempt_enable_no_resched() barrier()
77851+#define raw_preempt_enable_no_resched() barrier()
77852 #define preempt_enable() barrier()
77853
77854 #define preempt_disable_notrace() barrier()
77855diff --git a/include/linux/printk.h b/include/linux/printk.h
77856index e6131a78..8e9fb61 100644
77857--- a/include/linux/printk.h
77858+++ b/include/linux/printk.h
77859@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
77860 void early_printk(const char *s, ...) { }
77861 #endif
77862
77863+extern int kptr_restrict;
77864+
77865 #ifdef CONFIG_PRINTK
77866 asmlinkage __printf(5, 0)
77867 int vprintk_emit(int facility, int level,
77868@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
77869
77870 extern int printk_delay_msec;
77871 extern int dmesg_restrict;
77872-extern int kptr_restrict;
77873
77874 extern void wake_up_klogd(void);
77875
77876diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
77877index 608e60a..c26f864 100644
77878--- a/include/linux/proc_fs.h
77879+++ b/include/linux/proc_fs.h
77880@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
77881 return proc_create_data(name, mode, parent, proc_fops, NULL);
77882 }
77883
77884+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
77885+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
77886+{
77887+#ifdef CONFIG_GRKERNSEC_PROC_USER
77888+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
77889+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77890+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
77891+#else
77892+ return proc_create_data(name, mode, parent, proc_fops, NULL);
77893+#endif
77894+}
77895+
77896+
77897 extern void proc_set_size(struct proc_dir_entry *, loff_t);
77898 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
77899 extern void *PDE_DATA(const struct inode *);
77900diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
77901index 34a1e10..03a6d03 100644
77902--- a/include/linux/proc_ns.h
77903+++ b/include/linux/proc_ns.h
77904@@ -14,7 +14,7 @@ struct proc_ns_operations {
77905 void (*put)(void *ns);
77906 int (*install)(struct nsproxy *nsproxy, void *ns);
77907 unsigned int (*inum)(void *ns);
77908-};
77909+} __do_const;
77910
77911 struct proc_ns {
77912 void *ns;
77913diff --git a/include/linux/quota.h b/include/linux/quota.h
77914index cc7494a..1e27036 100644
77915--- a/include/linux/quota.h
77916+++ b/include/linux/quota.h
77917@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
77918
77919 extern bool qid_eq(struct kqid left, struct kqid right);
77920 extern bool qid_lt(struct kqid left, struct kqid right);
77921-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
77922+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
77923 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
77924 extern bool qid_valid(struct kqid qid);
77925
77926diff --git a/include/linux/random.h b/include/linux/random.h
77927index bf9085e..1e8bbcf 100644
77928--- a/include/linux/random.h
77929+++ b/include/linux/random.h
77930@@ -10,9 +10,19 @@
77931
77932
77933 extern void add_device_randomness(const void *, unsigned int);
77934+
77935+static inline void add_latent_entropy(void)
77936+{
77937+
77938+#ifdef LATENT_ENTROPY_PLUGIN
77939+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
77940+#endif
77941+
77942+}
77943+
77944 extern void add_input_randomness(unsigned int type, unsigned int code,
77945- unsigned int value);
77946-extern void add_interrupt_randomness(int irq, int irq_flags);
77947+ unsigned int value) __latent_entropy;
77948+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
77949
77950 extern void get_random_bytes(void *buf, int nbytes);
77951 extern void get_random_bytes_arch(void *buf, int nbytes);
77952@@ -23,16 +33,21 @@ extern int random_int_secret_init(void);
77953 extern const struct file_operations random_fops, urandom_fops;
77954 #endif
77955
77956-unsigned int get_random_int(void);
77957+unsigned int __intentional_overflow(-1) get_random_int(void);
77958 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
77959
77960-u32 prandom_u32(void);
77961+u32 prandom_u32(void) __intentional_overflow(-1);
77962 void prandom_bytes(void *buf, int nbytes);
77963 void prandom_seed(u32 seed);
77964
77965 u32 prandom_u32_state(struct rnd_state *);
77966 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
77967
77968+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
77969+{
77970+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
77971+}
77972+
77973 /*
77974 * Handle minimum values for seeds
77975 */
77976diff --git a/include/linux/rculist.h b/include/linux/rculist.h
77977index 4106721..132d42c 100644
77978--- a/include/linux/rculist.h
77979+++ b/include/linux/rculist.h
77980@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
77981 struct list_head *prev, struct list_head *next);
77982 #endif
77983
77984+extern void __pax_list_add_rcu(struct list_head *new,
77985+ struct list_head *prev, struct list_head *next);
77986+
77987 /**
77988 * list_add_rcu - add a new entry to rcu-protected list
77989 * @new: new entry to be added
77990@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
77991 __list_add_rcu(new, head, head->next);
77992 }
77993
77994+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
77995+{
77996+ __pax_list_add_rcu(new, head, head->next);
77997+}
77998+
77999 /**
78000 * list_add_tail_rcu - add a new entry to rcu-protected list
78001 * @new: new entry to be added
78002@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
78003 __list_add_rcu(new, head->prev, head);
78004 }
78005
78006+static inline void pax_list_add_tail_rcu(struct list_head *new,
78007+ struct list_head *head)
78008+{
78009+ __pax_list_add_rcu(new, head->prev, head);
78010+}
78011+
78012 /**
78013 * list_del_rcu - deletes entry from list without re-initialization
78014 * @entry: the element to delete from the list.
78015@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
78016 entry->prev = LIST_POISON2;
78017 }
78018
78019+extern void pax_list_del_rcu(struct list_head *entry);
78020+
78021 /**
78022 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
78023 * @n: the element to delete from the hash list.
78024diff --git a/include/linux/reboot.h b/include/linux/reboot.h
78025index 8e00f9f..9449b55 100644
78026--- a/include/linux/reboot.h
78027+++ b/include/linux/reboot.h
78028@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
78029 * Architecture-specific implementations of sys_reboot commands.
78030 */
78031
78032-extern void machine_restart(char *cmd);
78033-extern void machine_halt(void);
78034-extern void machine_power_off(void);
78035+extern void machine_restart(char *cmd) __noreturn;
78036+extern void machine_halt(void) __noreturn;
78037+extern void machine_power_off(void) __noreturn;
78038
78039 extern void machine_shutdown(void);
78040 struct pt_regs;
78041@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
78042 */
78043
78044 extern void kernel_restart_prepare(char *cmd);
78045-extern void kernel_restart(char *cmd);
78046-extern void kernel_halt(void);
78047-extern void kernel_power_off(void);
78048+extern void kernel_restart(char *cmd) __noreturn;
78049+extern void kernel_halt(void) __noreturn;
78050+extern void kernel_power_off(void) __noreturn;
78051
78052 extern int C_A_D; /* for sysctl */
78053 void ctrl_alt_del(void);
78054@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
78055 * Emergency restart, callable from an interrupt handler.
78056 */
78057
78058-extern void emergency_restart(void);
78059+extern void emergency_restart(void) __noreturn;
78060 #include <asm/emergency-restart.h>
78061
78062 #endif /* _LINUX_REBOOT_H */
78063diff --git a/include/linux/regset.h b/include/linux/regset.h
78064index 8e0c9fe..ac4d221 100644
78065--- a/include/linux/regset.h
78066+++ b/include/linux/regset.h
78067@@ -161,7 +161,8 @@ struct user_regset {
78068 unsigned int align;
78069 unsigned int bias;
78070 unsigned int core_note_type;
78071-};
78072+} __do_const;
78073+typedef struct user_regset __no_const user_regset_no_const;
78074
78075 /**
78076 * struct user_regset_view - available regsets
78077diff --git a/include/linux/relay.h b/include/linux/relay.h
78078index d7c8359..818daf5 100644
78079--- a/include/linux/relay.h
78080+++ b/include/linux/relay.h
78081@@ -157,7 +157,7 @@ struct rchan_callbacks
78082 * The callback should return 0 if successful, negative if not.
78083 */
78084 int (*remove_buf_file)(struct dentry *dentry);
78085-};
78086+} __no_const;
78087
78088 /*
78089 * CONFIG_RELAY kernel API, kernel/relay.c
78090diff --git a/include/linux/rio.h b/include/linux/rio.h
78091index b71d573..2f940bd 100644
78092--- a/include/linux/rio.h
78093+++ b/include/linux/rio.h
78094@@ -355,7 +355,7 @@ struct rio_ops {
78095 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
78096 u64 rstart, u32 size, u32 flags);
78097 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
78098-};
78099+} __no_const;
78100
78101 #define RIO_RESOURCE_MEM 0x00000100
78102 #define RIO_RESOURCE_DOORBELL 0x00000200
78103diff --git a/include/linux/rmap.h b/include/linux/rmap.h
78104index 6dacb93..6174423 100644
78105--- a/include/linux/rmap.h
78106+++ b/include/linux/rmap.h
78107@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
78108 void anon_vma_init(void); /* create anon_vma_cachep */
78109 int anon_vma_prepare(struct vm_area_struct *);
78110 void unlink_anon_vmas(struct vm_area_struct *);
78111-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
78112-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
78113+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
78114+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
78115
78116 static inline void anon_vma_merge(struct vm_area_struct *vma,
78117 struct vm_area_struct *next)
78118diff --git a/include/linux/sched.h b/include/linux/sched.h
78119index b1e963e..114b8fd 100644
78120--- a/include/linux/sched.h
78121+++ b/include/linux/sched.h
78122@@ -62,6 +62,7 @@ struct bio_list;
78123 struct fs_struct;
78124 struct perf_event_context;
78125 struct blk_plug;
78126+struct linux_binprm;
78127
78128 /*
78129 * List of flags we want to share for kernel threads,
78130@@ -295,7 +296,7 @@ extern char __sched_text_start[], __sched_text_end[];
78131 extern int in_sched_functions(unsigned long addr);
78132
78133 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
78134-extern signed long schedule_timeout(signed long timeout);
78135+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
78136 extern signed long schedule_timeout_interruptible(signed long timeout);
78137 extern signed long schedule_timeout_killable(signed long timeout);
78138 extern signed long schedule_timeout_uninterruptible(signed long timeout);
78139@@ -306,6 +307,19 @@ struct nsproxy;
78140 struct user_namespace;
78141
78142 #ifdef CONFIG_MMU
78143+
78144+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
78145+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
78146+#else
78147+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
78148+{
78149+ return 0;
78150+}
78151+#endif
78152+
78153+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
78154+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
78155+
78156 extern void arch_pick_mmap_layout(struct mm_struct *mm);
78157 extern unsigned long
78158 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
78159@@ -585,6 +599,17 @@ struct signal_struct {
78160 #ifdef CONFIG_TASKSTATS
78161 struct taskstats *stats;
78162 #endif
78163+
78164+#ifdef CONFIG_GRKERNSEC
78165+ u32 curr_ip;
78166+ u32 saved_ip;
78167+ u32 gr_saddr;
78168+ u32 gr_daddr;
78169+ u16 gr_sport;
78170+ u16 gr_dport;
78171+ u8 used_accept:1;
78172+#endif
78173+
78174 #ifdef CONFIG_AUDIT
78175 unsigned audit_tty;
78176 unsigned audit_tty_log_passwd;
78177@@ -665,6 +690,14 @@ struct user_struct {
78178 struct key *session_keyring; /* UID's default session keyring */
78179 #endif
78180
78181+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78182+ unsigned char kernel_banned;
78183+#endif
78184+#ifdef CONFIG_GRKERNSEC_BRUTE
78185+ unsigned char suid_banned;
78186+ unsigned long suid_ban_expires;
78187+#endif
78188+
78189 /* Hash table maintenance information */
78190 struct hlist_node uidhash_node;
78191 kuid_t uid;
78192@@ -1150,8 +1183,8 @@ struct task_struct {
78193 struct list_head thread_group;
78194
78195 struct completion *vfork_done; /* for vfork() */
78196- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
78197- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
78198+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
78199+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
78200
78201 cputime_t utime, stime, utimescaled, stimescaled;
78202 cputime_t gtime;
78203@@ -1176,11 +1209,6 @@ struct task_struct {
78204 struct task_cputime cputime_expires;
78205 struct list_head cpu_timers[3];
78206
78207-/* process credentials */
78208- const struct cred __rcu *real_cred; /* objective and real subjective task
78209- * credentials (COW) */
78210- const struct cred __rcu *cred; /* effective (overridable) subjective task
78211- * credentials (COW) */
78212 char comm[TASK_COMM_LEN]; /* executable name excluding path
78213 - access with [gs]et_task_comm (which lock
78214 it with task_lock())
78215@@ -1197,6 +1225,10 @@ struct task_struct {
78216 #endif
78217 /* CPU-specific state of this task */
78218 struct thread_struct thread;
78219+/* thread_info moved to task_struct */
78220+#ifdef CONFIG_X86
78221+ struct thread_info tinfo;
78222+#endif
78223 /* filesystem information */
78224 struct fs_struct *fs;
78225 /* open file information */
78226@@ -1270,6 +1302,10 @@ struct task_struct {
78227 gfp_t lockdep_reclaim_gfp;
78228 #endif
78229
78230+/* process credentials */
78231+ const struct cred __rcu *real_cred; /* objective and real subjective task
78232+ * credentials (COW) */
78233+
78234 /* journalling filesystem info */
78235 void *journal_info;
78236
78237@@ -1308,6 +1344,10 @@ struct task_struct {
78238 /* cg_list protected by css_set_lock and tsk->alloc_lock */
78239 struct list_head cg_list;
78240 #endif
78241+
78242+ const struct cred __rcu *cred; /* effective (overridable) subjective task
78243+ * credentials (COW) */
78244+
78245 #ifdef CONFIG_FUTEX
78246 struct robust_list_head __user *robust_list;
78247 #ifdef CONFIG_COMPAT
78248@@ -1411,8 +1451,78 @@ struct task_struct {
78249 unsigned int sequential_io;
78250 unsigned int sequential_io_avg;
78251 #endif
78252+
78253+#ifdef CONFIG_GRKERNSEC
78254+ /* grsecurity */
78255+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
78256+ u64 exec_id;
78257+#endif
78258+#ifdef CONFIG_GRKERNSEC_SETXID
78259+ const struct cred *delayed_cred;
78260+#endif
78261+ struct dentry *gr_chroot_dentry;
78262+ struct acl_subject_label *acl;
78263+ struct acl_subject_label *tmpacl;
78264+ struct acl_role_label *role;
78265+ struct file *exec_file;
78266+ unsigned long brute_expires;
78267+ u16 acl_role_id;
78268+ u8 inherited;
78269+ /* is this the task that authenticated to the special role */
78270+ u8 acl_sp_role;
78271+ u8 is_writable;
78272+ u8 brute;
78273+ u8 gr_is_chrooted;
78274+#endif
78275+
78276 };
78277
78278+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
78279+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
78280+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
78281+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
78282+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
78283+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
78284+
78285+#ifdef CONFIG_PAX_SOFTMODE
78286+extern int pax_softmode;
78287+#endif
78288+
78289+extern int pax_check_flags(unsigned long *);
78290+
78291+/* if tsk != current then task_lock must be held on it */
78292+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
78293+static inline unsigned long pax_get_flags(struct task_struct *tsk)
78294+{
78295+ if (likely(tsk->mm))
78296+ return tsk->mm->pax_flags;
78297+ else
78298+ return 0UL;
78299+}
78300+
78301+/* if tsk != current then task_lock must be held on it */
78302+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
78303+{
78304+ if (likely(tsk->mm)) {
78305+ tsk->mm->pax_flags = flags;
78306+ return 0;
78307+ }
78308+ return -EINVAL;
78309+}
78310+#endif
78311+
78312+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
78313+extern void pax_set_initial_flags(struct linux_binprm *bprm);
78314+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
78315+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
78316+#endif
78317+
78318+struct path;
78319+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
78320+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
78321+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
78322+extern void pax_report_refcount_overflow(struct pt_regs *regs);
78323+
78324 /* Future-safe accessor for struct task_struct's cpus_allowed. */
78325 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
78326
78327@@ -1471,7 +1581,7 @@ struct pid_namespace;
78328 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
78329 struct pid_namespace *ns);
78330
78331-static inline pid_t task_pid_nr(struct task_struct *tsk)
78332+static inline pid_t task_pid_nr(const struct task_struct *tsk)
78333 {
78334 return tsk->pid;
78335 }
78336@@ -1921,7 +2031,9 @@ void yield(void);
78337 extern struct exec_domain default_exec_domain;
78338
78339 union thread_union {
78340+#ifndef CONFIG_X86
78341 struct thread_info thread_info;
78342+#endif
78343 unsigned long stack[THREAD_SIZE/sizeof(long)];
78344 };
78345
78346@@ -1954,6 +2066,7 @@ extern struct pid_namespace init_pid_ns;
78347 */
78348
78349 extern struct task_struct *find_task_by_vpid(pid_t nr);
78350+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
78351 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
78352 struct pid_namespace *ns);
78353
78354@@ -2118,7 +2231,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
78355 extern void exit_itimers(struct signal_struct *);
78356 extern void flush_itimer_signals(void);
78357
78358-extern void do_group_exit(int);
78359+extern __noreturn void do_group_exit(int);
78360
78361 extern int allow_signal(int);
78362 extern int disallow_signal(int);
78363@@ -2309,9 +2422,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
78364
78365 #endif
78366
78367-static inline int object_is_on_stack(void *obj)
78368+static inline int object_starts_on_stack(void *obj)
78369 {
78370- void *stack = task_stack_page(current);
78371+ const void *stack = task_stack_page(current);
78372
78373 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
78374 }
78375diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
78376index bf8086b..962b035 100644
78377--- a/include/linux/sched/sysctl.h
78378+++ b/include/linux/sched/sysctl.h
78379@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
78380 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
78381
78382 extern int sysctl_max_map_count;
78383+extern unsigned long sysctl_heap_stack_gap;
78384
78385 extern unsigned int sysctl_sched_latency;
78386 extern unsigned int sysctl_sched_min_granularity;
78387diff --git a/include/linux/security.h b/include/linux/security.h
78388index 9d37e2b..43368e4 100644
78389--- a/include/linux/security.h
78390+++ b/include/linux/security.h
78391@@ -27,6 +27,7 @@
78392 #include <linux/slab.h>
78393 #include <linux/err.h>
78394 #include <linux/string.h>
78395+#include <linux/grsecurity.h>
78396
78397 struct linux_binprm;
78398 struct cred;
78399@@ -116,8 +117,6 @@ struct seq_file;
78400
78401 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
78402
78403-void reset_security_ops(void);
78404-
78405 #ifdef CONFIG_MMU
78406 extern unsigned long mmap_min_addr;
78407 extern unsigned long dac_mmap_min_addr;
78408diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
78409index dc368b8..e895209 100644
78410--- a/include/linux/semaphore.h
78411+++ b/include/linux/semaphore.h
78412@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
78413 }
78414
78415 extern void down(struct semaphore *sem);
78416-extern int __must_check down_interruptible(struct semaphore *sem);
78417+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
78418 extern int __must_check down_killable(struct semaphore *sem);
78419 extern int __must_check down_trylock(struct semaphore *sem);
78420 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
78421diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
78422index 4e32edc..f8f2d18 100644
78423--- a/include/linux/seq_file.h
78424+++ b/include/linux/seq_file.h
78425@@ -26,6 +26,9 @@ struct seq_file {
78426 struct mutex lock;
78427 const struct seq_operations *op;
78428 int poll_event;
78429+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
78430+ u64 exec_id;
78431+#endif
78432 #ifdef CONFIG_USER_NS
78433 struct user_namespace *user_ns;
78434 #endif
78435@@ -38,6 +41,7 @@ struct seq_operations {
78436 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
78437 int (*show) (struct seq_file *m, void *v);
78438 };
78439+typedef struct seq_operations __no_const seq_operations_no_const;
78440
78441 #define SEQ_SKIP 1
78442
78443diff --git a/include/linux/shm.h b/include/linux/shm.h
78444index 429c199..4d42e38 100644
78445--- a/include/linux/shm.h
78446+++ b/include/linux/shm.h
78447@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
78448
78449 /* The task created the shm object. NULL if the task is dead. */
78450 struct task_struct *shm_creator;
78451+#ifdef CONFIG_GRKERNSEC
78452+ time_t shm_createtime;
78453+ pid_t shm_lapid;
78454+#endif
78455 };
78456
78457 /* shm_mode upper byte flags */
78458diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
78459index f66f346..2e304d5 100644
78460--- a/include/linux/skbuff.h
78461+++ b/include/linux/skbuff.h
78462@@ -639,7 +639,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
78463 extern struct sk_buff *__alloc_skb(unsigned int size,
78464 gfp_t priority, int flags, int node);
78465 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
78466-static inline struct sk_buff *alloc_skb(unsigned int size,
78467+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
78468 gfp_t priority)
78469 {
78470 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
78471@@ -755,7 +755,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
78472 */
78473 static inline int skb_queue_empty(const struct sk_buff_head *list)
78474 {
78475- return list->next == (struct sk_buff *)list;
78476+ return list->next == (const struct sk_buff *)list;
78477 }
78478
78479 /**
78480@@ -768,7 +768,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
78481 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
78482 const struct sk_buff *skb)
78483 {
78484- return skb->next == (struct sk_buff *)list;
78485+ return skb->next == (const struct sk_buff *)list;
78486 }
78487
78488 /**
78489@@ -781,7 +781,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
78490 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
78491 const struct sk_buff *skb)
78492 {
78493- return skb->prev == (struct sk_buff *)list;
78494+ return skb->prev == (const struct sk_buff *)list;
78495 }
78496
78497 /**
78498@@ -1741,7 +1741,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
78499 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
78500 */
78501 #ifndef NET_SKB_PAD
78502-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
78503+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
78504 #endif
78505
78506 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
78507@@ -2339,7 +2339,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
78508 int noblock, int *err);
78509 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
78510 struct poll_table_struct *wait);
78511-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
78512+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
78513 int offset, struct iovec *to,
78514 int size);
78515 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
78516@@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
78517 nf_bridge_put(skb->nf_bridge);
78518 skb->nf_bridge = NULL;
78519 #endif
78520+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
78521+ skb->nf_trace = 0;
78522+#endif
78523 }
78524
78525 static inline void nf_reset_trace(struct sk_buff *skb)
78526diff --git a/include/linux/slab.h b/include/linux/slab.h
78527index 74f1058..914b7da 100644
78528--- a/include/linux/slab.h
78529+++ b/include/linux/slab.h
78530@@ -14,15 +14,29 @@
78531 #include <linux/gfp.h>
78532 #include <linux/types.h>
78533 #include <linux/workqueue.h>
78534-
78535+#include <linux/err.h>
78536
78537 /*
78538 * Flags to pass to kmem_cache_create().
78539 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
78540 */
78541 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
78542+
78543+#ifdef CONFIG_PAX_USERCOPY_SLABS
78544+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
78545+#else
78546+#define SLAB_USERCOPY 0x00000000UL
78547+#endif
78548+
78549 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
78550 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
78551+
78552+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78553+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
78554+#else
78555+#define SLAB_NO_SANITIZE 0x00000000UL
78556+#endif
78557+
78558 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
78559 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
78560 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
78561@@ -91,10 +105,13 @@
78562 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
78563 * Both make kfree a no-op.
78564 */
78565-#define ZERO_SIZE_PTR ((void *)16)
78566+#define ZERO_SIZE_PTR \
78567+({ \
78568+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
78569+ (void *)(-MAX_ERRNO-1L); \
78570+})
78571
78572-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
78573- (unsigned long)ZERO_SIZE_PTR)
78574+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
78575
78576 #include <linux/kmemleak.h>
78577
78578@@ -135,6 +152,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
78579 void kfree(const void *);
78580 void kzfree(const void *);
78581 size_t ksize(const void *);
78582+const char *check_heap_object(const void *ptr, unsigned long n);
78583+bool is_usercopy_object(const void *ptr);
78584
78585 /*
78586 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
78587@@ -167,7 +186,7 @@ struct kmem_cache {
78588 unsigned int align; /* Alignment as calculated */
78589 unsigned long flags; /* Active flags on the slab */
78590 const char *name; /* Slab name for sysfs */
78591- int refcount; /* Use counter */
78592+ atomic_t refcount; /* Use counter */
78593 void (*ctor)(void *); /* Called on object slot creation */
78594 struct list_head list; /* List of all slab caches on the system */
78595 };
78596@@ -241,6 +260,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
78597 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
78598 #endif
78599
78600+#ifdef CONFIG_PAX_USERCOPY_SLABS
78601+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
78602+#endif
78603+
78604 /*
78605 * Figure out which kmalloc slab an allocation of a certain size
78606 * belongs to.
78607@@ -249,7 +272,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
78608 * 2 = 120 .. 192 bytes
78609 * n = 2^(n-1) .. 2^n -1
78610 */
78611-static __always_inline int kmalloc_index(size_t size)
78612+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
78613 {
78614 if (!size)
78615 return 0;
78616@@ -292,11 +315,11 @@ static __always_inline int kmalloc_index(size_t size)
78617 }
78618 #endif /* !CONFIG_SLOB */
78619
78620-void *__kmalloc(size_t size, gfp_t flags);
78621+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
78622 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
78623
78624 #ifdef CONFIG_NUMA
78625-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78626+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
78627 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78628 #else
78629 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
78630diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
78631index e9346b4..1494959 100644
78632--- a/include/linux/slab_def.h
78633+++ b/include/linux/slab_def.h
78634@@ -36,7 +36,7 @@ struct kmem_cache {
78635 /* 4) cache creation/removal */
78636 const char *name;
78637 struct list_head list;
78638- int refcount;
78639+ atomic_t refcount;
78640 int object_size;
78641 int align;
78642
78643@@ -52,10 +52,14 @@ struct kmem_cache {
78644 unsigned long node_allocs;
78645 unsigned long node_frees;
78646 unsigned long node_overflow;
78647- atomic_t allochit;
78648- atomic_t allocmiss;
78649- atomic_t freehit;
78650- atomic_t freemiss;
78651+ atomic_unchecked_t allochit;
78652+ atomic_unchecked_t allocmiss;
78653+ atomic_unchecked_t freehit;
78654+ atomic_unchecked_t freemiss;
78655+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78656+ atomic_unchecked_t sanitized;
78657+ atomic_unchecked_t not_sanitized;
78658+#endif
78659
78660 /*
78661 * If debugging is enabled, then the allocator can add additional
78662diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
78663index cc0b67e..a0329b1 100644
78664--- a/include/linux/slub_def.h
78665+++ b/include/linux/slub_def.h
78666@@ -74,7 +74,7 @@ struct kmem_cache {
78667 struct kmem_cache_order_objects max;
78668 struct kmem_cache_order_objects min;
78669 gfp_t allocflags; /* gfp flags to use on each alloc */
78670- int refcount; /* Refcount for slab cache destroy */
78671+ atomic_t refcount; /* Refcount for slab cache destroy */
78672 void (*ctor)(void *);
78673 int inuse; /* Offset to metadata */
78674 int align; /* Alignment */
78675diff --git a/include/linux/smp.h b/include/linux/smp.h
78676index 731f523..3340268 100644
78677--- a/include/linux/smp.h
78678+++ b/include/linux/smp.h
78679@@ -186,7 +186,9 @@ static inline void __smp_call_function_single(int cpuid,
78680 #endif
78681
78682 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
78683+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
78684 #define put_cpu() preempt_enable()
78685+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
78686
78687 /*
78688 * Callback to arch code if there's nosmp or maxcpus=0 on the
78689diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
78690index 54f91d3..be2c379 100644
78691--- a/include/linux/sock_diag.h
78692+++ b/include/linux/sock_diag.h
78693@@ -11,7 +11,7 @@ struct sock;
78694 struct sock_diag_handler {
78695 __u8 family;
78696 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
78697-};
78698+} __do_const;
78699
78700 int sock_diag_register(const struct sock_diag_handler *h);
78701 void sock_diag_unregister(const struct sock_diag_handler *h);
78702diff --git a/include/linux/sonet.h b/include/linux/sonet.h
78703index 680f9a3..f13aeb0 100644
78704--- a/include/linux/sonet.h
78705+++ b/include/linux/sonet.h
78706@@ -7,7 +7,7 @@
78707 #include <uapi/linux/sonet.h>
78708
78709 struct k_sonet_stats {
78710-#define __HANDLE_ITEM(i) atomic_t i
78711+#define __HANDLE_ITEM(i) atomic_unchecked_t i
78712 __SONET_ITEMS
78713 #undef __HANDLE_ITEM
78714 };
78715diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
78716index 07d8e53..dc934c9 100644
78717--- a/include/linux/sunrpc/addr.h
78718+++ b/include/linux/sunrpc/addr.h
78719@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
78720 {
78721 switch (sap->sa_family) {
78722 case AF_INET:
78723- return ntohs(((struct sockaddr_in *)sap)->sin_port);
78724+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
78725 case AF_INET6:
78726- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
78727+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
78728 }
78729 return 0;
78730 }
78731@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
78732 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
78733 const struct sockaddr *src)
78734 {
78735- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
78736+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
78737 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
78738
78739 dsin->sin_family = ssin->sin_family;
78740@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
78741 if (sa->sa_family != AF_INET6)
78742 return 0;
78743
78744- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
78745+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
78746 }
78747
78748 #endif /* _LINUX_SUNRPC_ADDR_H */
78749diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
78750index 6740801..c535f27 100644
78751--- a/include/linux/sunrpc/clnt.h
78752+++ b/include/linux/sunrpc/clnt.h
78753@@ -96,7 +96,7 @@ struct rpc_procinfo {
78754 unsigned int p_timer; /* Which RTT timer to use */
78755 u32 p_statidx; /* Which procedure to account */
78756 const char * p_name; /* name of procedure */
78757-};
78758+} __do_const;
78759
78760 #ifdef __KERNEL__
78761
78762diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
78763index 6eecfc2..7ada79d 100644
78764--- a/include/linux/sunrpc/svc.h
78765+++ b/include/linux/sunrpc/svc.h
78766@@ -410,7 +410,7 @@ struct svc_procedure {
78767 unsigned int pc_count; /* call count */
78768 unsigned int pc_cachetype; /* cache info (NFS) */
78769 unsigned int pc_xdrressize; /* maximum size of XDR reply */
78770-};
78771+} __do_const;
78772
78773 /*
78774 * Function prototypes.
78775diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
78776index 0b8e3e6..33e0a01 100644
78777--- a/include/linux/sunrpc/svc_rdma.h
78778+++ b/include/linux/sunrpc/svc_rdma.h
78779@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
78780 extern unsigned int svcrdma_max_requests;
78781 extern unsigned int svcrdma_max_req_size;
78782
78783-extern atomic_t rdma_stat_recv;
78784-extern atomic_t rdma_stat_read;
78785-extern atomic_t rdma_stat_write;
78786-extern atomic_t rdma_stat_sq_starve;
78787-extern atomic_t rdma_stat_rq_starve;
78788-extern atomic_t rdma_stat_rq_poll;
78789-extern atomic_t rdma_stat_rq_prod;
78790-extern atomic_t rdma_stat_sq_poll;
78791-extern atomic_t rdma_stat_sq_prod;
78792+extern atomic_unchecked_t rdma_stat_recv;
78793+extern atomic_unchecked_t rdma_stat_read;
78794+extern atomic_unchecked_t rdma_stat_write;
78795+extern atomic_unchecked_t rdma_stat_sq_starve;
78796+extern atomic_unchecked_t rdma_stat_rq_starve;
78797+extern atomic_unchecked_t rdma_stat_rq_poll;
78798+extern atomic_unchecked_t rdma_stat_rq_prod;
78799+extern atomic_unchecked_t rdma_stat_sq_poll;
78800+extern atomic_unchecked_t rdma_stat_sq_prod;
78801
78802 #define RPCRDMA_VERSION 1
78803
78804diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
78805index 8d71d65..f79586e 100644
78806--- a/include/linux/sunrpc/svcauth.h
78807+++ b/include/linux/sunrpc/svcauth.h
78808@@ -120,7 +120,7 @@ struct auth_ops {
78809 int (*release)(struct svc_rqst *rq);
78810 void (*domain_release)(struct auth_domain *);
78811 int (*set_client)(struct svc_rqst *rq);
78812-};
78813+} __do_const;
78814
78815 #define SVC_GARBAGE 1
78816 #define SVC_SYSERR 2
78817diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
78818index a5ffd32..0935dea 100644
78819--- a/include/linux/swiotlb.h
78820+++ b/include/linux/swiotlb.h
78821@@ -60,7 +60,8 @@ extern void
78822
78823 extern void
78824 swiotlb_free_coherent(struct device *hwdev, size_t size,
78825- void *vaddr, dma_addr_t dma_handle);
78826+ void *vaddr, dma_addr_t dma_handle,
78827+ struct dma_attrs *attrs);
78828
78829 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
78830 unsigned long offset, size_t size,
78831diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
78832index 7fac04e..de57300 100644
78833--- a/include/linux/syscalls.h
78834+++ b/include/linux/syscalls.h
78835@@ -97,8 +97,14 @@ struct sigaltstack;
78836 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
78837
78838 #define __SC_DECL(t, a) t a
78839+#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))
78840 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
78841-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
78842+#define __SC_LONG(t, a) __typeof( \
78843+ __builtin_choose_expr( \
78844+ sizeof(t) > sizeof(int), \
78845+ (t) 0, \
78846+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
78847+ )) a
78848 #define __SC_CAST(t, a) (t) a
78849 #define __SC_ARGS(t, a) a
78850 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
78851@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
78852 asmlinkage long sys_fsync(unsigned int fd);
78853 asmlinkage long sys_fdatasync(unsigned int fd);
78854 asmlinkage long sys_bdflush(int func, long data);
78855-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
78856- char __user *type, unsigned long flags,
78857+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
78858+ const char __user *type, unsigned long flags,
78859 void __user *data);
78860-asmlinkage long sys_umount(char __user *name, int flags);
78861-asmlinkage long sys_oldumount(char __user *name);
78862+asmlinkage long sys_umount(const char __user *name, int flags);
78863+asmlinkage long sys_oldumount(const char __user *name);
78864 asmlinkage long sys_truncate(const char __user *path, long length);
78865 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
78866 asmlinkage long sys_stat(const char __user *filename,
78867@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
78868 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
78869 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
78870 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
78871- struct sockaddr __user *, int);
78872+ struct sockaddr __user *, int) __intentional_overflow(0);
78873 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
78874 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
78875 unsigned int vlen, unsigned flags);
78876diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
78877index 27b3b0b..e093dd9 100644
78878--- a/include/linux/syscore_ops.h
78879+++ b/include/linux/syscore_ops.h
78880@@ -16,7 +16,7 @@ struct syscore_ops {
78881 int (*suspend)(void);
78882 void (*resume)(void);
78883 void (*shutdown)(void);
78884-};
78885+} __do_const;
78886
78887 extern void register_syscore_ops(struct syscore_ops *ops);
78888 extern void unregister_syscore_ops(struct syscore_ops *ops);
78889diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
78890index 14a8ff2..af52bad 100644
78891--- a/include/linux/sysctl.h
78892+++ b/include/linux/sysctl.h
78893@@ -34,13 +34,13 @@ struct ctl_table_root;
78894 struct ctl_table_header;
78895 struct ctl_dir;
78896
78897-typedef struct ctl_table ctl_table;
78898-
78899 typedef int proc_handler (struct ctl_table *ctl, int write,
78900 void __user *buffer, size_t *lenp, loff_t *ppos);
78901
78902 extern int proc_dostring(struct ctl_table *, int,
78903 void __user *, size_t *, loff_t *);
78904+extern int proc_dostring_modpriv(struct ctl_table *, int,
78905+ void __user *, size_t *, loff_t *);
78906 extern int proc_dointvec(struct ctl_table *, int,
78907 void __user *, size_t *, loff_t *);
78908 extern int proc_dointvec_minmax(struct ctl_table *, int,
78909@@ -115,7 +115,9 @@ struct ctl_table
78910 struct ctl_table_poll *poll;
78911 void *extra1;
78912 void *extra2;
78913-};
78914+} __do_const;
78915+typedef struct ctl_table __no_const ctl_table_no_const;
78916+typedef struct ctl_table ctl_table;
78917
78918 struct ctl_node {
78919 struct rb_node node;
78920diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
78921index 11baec7..706f99f 100644
78922--- a/include/linux/sysfs.h
78923+++ b/include/linux/sysfs.h
78924@@ -33,7 +33,8 @@ struct attribute {
78925 struct lock_class_key *key;
78926 struct lock_class_key skey;
78927 #endif
78928-};
78929+} __do_const;
78930+typedef struct attribute __no_const attribute_no_const;
78931
78932 /**
78933 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
78934@@ -62,7 +63,8 @@ struct attribute_group {
78935 struct attribute *, int);
78936 struct attribute **attrs;
78937 struct bin_attribute **bin_attrs;
78938-};
78939+} __do_const;
78940+typedef struct attribute_group __no_const attribute_group_no_const;
78941
78942 /**
78943 * Use these macros to make defining attributes easier. See include/linux/device.h
78944@@ -126,7 +128,8 @@ struct bin_attribute {
78945 char *, loff_t, size_t);
78946 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
78947 struct vm_area_struct *vma);
78948-};
78949+} __do_const;
78950+typedef struct bin_attribute __no_const bin_attribute_no_const;
78951
78952 /**
78953 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
78954diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
78955index 7faf933..9b85a0c 100644
78956--- a/include/linux/sysrq.h
78957+++ b/include/linux/sysrq.h
78958@@ -16,6 +16,7 @@
78959
78960 #include <linux/errno.h>
78961 #include <linux/types.h>
78962+#include <linux/compiler.h>
78963
78964 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
78965 #define SYSRQ_DEFAULT_ENABLE 1
78966@@ -36,7 +37,7 @@ struct sysrq_key_op {
78967 char *help_msg;
78968 char *action_msg;
78969 int enable_mask;
78970-};
78971+} __do_const;
78972
78973 #ifdef CONFIG_MAGIC_SYSRQ
78974
78975diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
78976index 4ae6f32..425d3e1 100644
78977--- a/include/linux/thread_info.h
78978+++ b/include/linux/thread_info.h
78979@@ -150,6 +150,15 @@ static inline bool test_and_clear_restore_sigmask(void)
78980 #error "no set_restore_sigmask() provided and default one won't work"
78981 #endif
78982
78983+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
78984+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
78985+{
78986+#ifndef CONFIG_PAX_USERCOPY_DEBUG
78987+ if (!__builtin_constant_p(n))
78988+#endif
78989+ __check_object_size(ptr, n, to_user);
78990+}
78991+
78992 #endif /* __KERNEL__ */
78993
78994 #endif /* _LINUX_THREAD_INFO_H */
78995diff --git a/include/linux/tty.h b/include/linux/tty.h
78996index 64f8646..1515fc7 100644
78997--- a/include/linux/tty.h
78998+++ b/include/linux/tty.h
78999@@ -197,7 +197,7 @@ struct tty_port {
79000 const struct tty_port_operations *ops; /* Port operations */
79001 spinlock_t lock; /* Lock protecting tty field */
79002 int blocked_open; /* Waiting to open */
79003- int count; /* Usage count */
79004+ atomic_t count; /* Usage count */
79005 wait_queue_head_t open_wait; /* Open waiters */
79006 wait_queue_head_t close_wait; /* Close waiters */
79007 wait_queue_head_t delta_msr_wait; /* Modem status change */
79008@@ -546,7 +546,7 @@ extern int tty_port_open(struct tty_port *port,
79009 struct tty_struct *tty, struct file *filp);
79010 static inline int tty_port_users(struct tty_port *port)
79011 {
79012- return port->count + port->blocked_open;
79013+ return atomic_read(&port->count) + port->blocked_open;
79014 }
79015
79016 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
79017diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
79018index 756a609..b302dd6 100644
79019--- a/include/linux/tty_driver.h
79020+++ b/include/linux/tty_driver.h
79021@@ -285,7 +285,7 @@ struct tty_operations {
79022 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
79023 #endif
79024 const struct file_operations *proc_fops;
79025-};
79026+} __do_const;
79027
79028 struct tty_driver {
79029 int magic; /* magic number for this structure */
79030diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
79031index f15c898..207b7d1 100644
79032--- a/include/linux/tty_ldisc.h
79033+++ b/include/linux/tty_ldisc.h
79034@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
79035
79036 struct module *owner;
79037
79038- int refcount;
79039+ atomic_t refcount;
79040 };
79041
79042 struct tty_ldisc {
79043diff --git a/include/linux/types.h b/include/linux/types.h
79044index 4d118ba..c3ee9bf 100644
79045--- a/include/linux/types.h
79046+++ b/include/linux/types.h
79047@@ -176,10 +176,26 @@ typedef struct {
79048 int counter;
79049 } atomic_t;
79050
79051+#ifdef CONFIG_PAX_REFCOUNT
79052+typedef struct {
79053+ int counter;
79054+} atomic_unchecked_t;
79055+#else
79056+typedef atomic_t atomic_unchecked_t;
79057+#endif
79058+
79059 #ifdef CONFIG_64BIT
79060 typedef struct {
79061 long counter;
79062 } atomic64_t;
79063+
79064+#ifdef CONFIG_PAX_REFCOUNT
79065+typedef struct {
79066+ long counter;
79067+} atomic64_unchecked_t;
79068+#else
79069+typedef atomic64_t atomic64_unchecked_t;
79070+#endif
79071 #endif
79072
79073 struct list_head {
79074diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
79075index 5ca0951..ab496a5 100644
79076--- a/include/linux/uaccess.h
79077+++ b/include/linux/uaccess.h
79078@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
79079 long ret; \
79080 mm_segment_t old_fs = get_fs(); \
79081 \
79082- set_fs(KERNEL_DS); \
79083 pagefault_disable(); \
79084- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
79085- pagefault_enable(); \
79086+ set_fs(KERNEL_DS); \
79087+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
79088 set_fs(old_fs); \
79089+ pagefault_enable(); \
79090 ret; \
79091 })
79092
79093diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
79094index 8e522cbc..aa8572d 100644
79095--- a/include/linux/uidgid.h
79096+++ b/include/linux/uidgid.h
79097@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
79098
79099 #endif /* CONFIG_USER_NS */
79100
79101+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
79102+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
79103+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
79104+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
79105+
79106 #endif /* _LINUX_UIDGID_H */
79107diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
79108index 99c1b4d..562e6f3 100644
79109--- a/include/linux/unaligned/access_ok.h
79110+++ b/include/linux/unaligned/access_ok.h
79111@@ -4,34 +4,34 @@
79112 #include <linux/kernel.h>
79113 #include <asm/byteorder.h>
79114
79115-static inline u16 get_unaligned_le16(const void *p)
79116+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
79117 {
79118- return le16_to_cpup((__le16 *)p);
79119+ return le16_to_cpup((const __le16 *)p);
79120 }
79121
79122-static inline u32 get_unaligned_le32(const void *p)
79123+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
79124 {
79125- return le32_to_cpup((__le32 *)p);
79126+ return le32_to_cpup((const __le32 *)p);
79127 }
79128
79129-static inline u64 get_unaligned_le64(const void *p)
79130+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
79131 {
79132- return le64_to_cpup((__le64 *)p);
79133+ return le64_to_cpup((const __le64 *)p);
79134 }
79135
79136-static inline u16 get_unaligned_be16(const void *p)
79137+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
79138 {
79139- return be16_to_cpup((__be16 *)p);
79140+ return be16_to_cpup((const __be16 *)p);
79141 }
79142
79143-static inline u32 get_unaligned_be32(const void *p)
79144+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
79145 {
79146- return be32_to_cpup((__be32 *)p);
79147+ return be32_to_cpup((const __be32 *)p);
79148 }
79149
79150-static inline u64 get_unaligned_be64(const void *p)
79151+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
79152 {
79153- return be64_to_cpup((__be64 *)p);
79154+ return be64_to_cpup((const __be64 *)p);
79155 }
79156
79157 static inline void put_unaligned_le16(u16 val, void *p)
79158diff --git a/include/linux/usb.h b/include/linux/usb.h
79159index 39cfa0a..d45fa38 100644
79160--- a/include/linux/usb.h
79161+++ b/include/linux/usb.h
79162@@ -563,7 +563,7 @@ struct usb_device {
79163 int maxchild;
79164
79165 u32 quirks;
79166- atomic_t urbnum;
79167+ atomic_unchecked_t urbnum;
79168
79169 unsigned long active_duration;
79170
79171@@ -1637,7 +1637,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
79172
79173 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
79174 __u8 request, __u8 requesttype, __u16 value, __u16 index,
79175- void *data, __u16 size, int timeout);
79176+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
79177 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
79178 void *data, int len, int *actual_length, int timeout);
79179 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
79180diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
79181index e452ba6..78f8e80 100644
79182--- a/include/linux/usb/renesas_usbhs.h
79183+++ b/include/linux/usb/renesas_usbhs.h
79184@@ -39,7 +39,7 @@ enum {
79185 */
79186 struct renesas_usbhs_driver_callback {
79187 int (*notify_hotplug)(struct platform_device *pdev);
79188-};
79189+} __no_const;
79190
79191 /*
79192 * callback functions for platform
79193diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
79194index 6f8fbcf..8259001 100644
79195--- a/include/linux/vermagic.h
79196+++ b/include/linux/vermagic.h
79197@@ -25,9 +25,35 @@
79198 #define MODULE_ARCH_VERMAGIC ""
79199 #endif
79200
79201+#ifdef CONFIG_PAX_REFCOUNT
79202+#define MODULE_PAX_REFCOUNT "REFCOUNT "
79203+#else
79204+#define MODULE_PAX_REFCOUNT ""
79205+#endif
79206+
79207+#ifdef CONSTIFY_PLUGIN
79208+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
79209+#else
79210+#define MODULE_CONSTIFY_PLUGIN ""
79211+#endif
79212+
79213+#ifdef STACKLEAK_PLUGIN
79214+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
79215+#else
79216+#define MODULE_STACKLEAK_PLUGIN ""
79217+#endif
79218+
79219+#ifdef CONFIG_GRKERNSEC
79220+#define MODULE_GRSEC "GRSEC "
79221+#else
79222+#define MODULE_GRSEC ""
79223+#endif
79224+
79225 #define VERMAGIC_STRING \
79226 UTS_RELEASE " " \
79227 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
79228 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
79229- MODULE_ARCH_VERMAGIC
79230+ MODULE_ARCH_VERMAGIC \
79231+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
79232+ MODULE_GRSEC
79233
79234diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
79235index 502073a..a7de024 100644
79236--- a/include/linux/vga_switcheroo.h
79237+++ b/include/linux/vga_switcheroo.h
79238@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
79239
79240 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
79241
79242-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
79243-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
79244+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
79245+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
79246 #else
79247
79248 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
79249@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
79250
79251 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
79252
79253-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
79254-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
79255+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
79256+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
79257
79258 #endif
79259 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
79260diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
79261index 4b8a891..cb8df6e 100644
79262--- a/include/linux/vmalloc.h
79263+++ b/include/linux/vmalloc.h
79264@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
79265 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
79266 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
79267 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
79268+
79269+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79270+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
79271+#endif
79272+
79273 /* bits [20..32] reserved for arch specific ioremap internals */
79274
79275 /*
79276@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
79277
79278 /* for /dev/kmem */
79279 extern long vread(char *buf, char *addr, unsigned long count);
79280-extern long vwrite(char *buf, char *addr, unsigned long count);
79281+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
79282
79283 /*
79284 * Internals. Dont't use..
79285diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
79286index e4b9480..5a5f65a 100644
79287--- a/include/linux/vmstat.h
79288+++ b/include/linux/vmstat.h
79289@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
79290 /*
79291 * Zone based page accounting with per cpu differentials.
79292 */
79293-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79294+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79295
79296 static inline void zone_page_state_add(long x, struct zone *zone,
79297 enum zone_stat_item item)
79298 {
79299- atomic_long_add(x, &zone->vm_stat[item]);
79300- atomic_long_add(x, &vm_stat[item]);
79301+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
79302+ atomic_long_add_unchecked(x, &vm_stat[item]);
79303 }
79304
79305-static inline unsigned long global_page_state(enum zone_stat_item item)
79306+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
79307 {
79308- long x = atomic_long_read(&vm_stat[item]);
79309+ long x = atomic_long_read_unchecked(&vm_stat[item]);
79310 #ifdef CONFIG_SMP
79311 if (x < 0)
79312 x = 0;
79313@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
79314 return x;
79315 }
79316
79317-static inline unsigned long zone_page_state(struct zone *zone,
79318+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
79319 enum zone_stat_item item)
79320 {
79321- long x = atomic_long_read(&zone->vm_stat[item]);
79322+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
79323 #ifdef CONFIG_SMP
79324 if (x < 0)
79325 x = 0;
79326@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
79327 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
79328 enum zone_stat_item item)
79329 {
79330- long x = atomic_long_read(&zone->vm_stat[item]);
79331+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
79332
79333 #ifdef CONFIG_SMP
79334 int cpu;
79335@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
79336
79337 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
79338 {
79339- atomic_long_inc(&zone->vm_stat[item]);
79340- atomic_long_inc(&vm_stat[item]);
79341+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
79342+ atomic_long_inc_unchecked(&vm_stat[item]);
79343 }
79344
79345 static inline void __inc_zone_page_state(struct page *page,
79346@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
79347
79348 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
79349 {
79350- atomic_long_dec(&zone->vm_stat[item]);
79351- atomic_long_dec(&vm_stat[item]);
79352+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
79353+ atomic_long_dec_unchecked(&vm_stat[item]);
79354 }
79355
79356 static inline void __dec_zone_page_state(struct page *page,
79357diff --git a/include/linux/xattr.h b/include/linux/xattr.h
79358index 91b0a68..0e9adf6 100644
79359--- a/include/linux/xattr.h
79360+++ b/include/linux/xattr.h
79361@@ -28,7 +28,7 @@ struct xattr_handler {
79362 size_t size, int handler_flags);
79363 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
79364 size_t size, int flags, int handler_flags);
79365-};
79366+} __do_const;
79367
79368 struct xattr {
79369 const char *name;
79370@@ -37,6 +37,9 @@ struct xattr {
79371 };
79372
79373 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
79374+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
79375+ssize_t pax_getxattr(struct dentry *, void *, size_t);
79376+#endif
79377 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
79378 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
79379 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
79380diff --git a/include/linux/zlib.h b/include/linux/zlib.h
79381index 9c5a6b4..09c9438 100644
79382--- a/include/linux/zlib.h
79383+++ b/include/linux/zlib.h
79384@@ -31,6 +31,7 @@
79385 #define _ZLIB_H
79386
79387 #include <linux/zconf.h>
79388+#include <linux/compiler.h>
79389
79390 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
79391 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
79392@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
79393
79394 /* basic functions */
79395
79396-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
79397+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
79398 /*
79399 Returns the number of bytes that needs to be allocated for a per-
79400 stream workspace with the specified parameters. A pointer to this
79401diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
79402index c768c9f..bdcaa5a 100644
79403--- a/include/media/v4l2-dev.h
79404+++ b/include/media/v4l2-dev.h
79405@@ -76,7 +76,7 @@ struct v4l2_file_operations {
79406 int (*mmap) (struct file *, struct vm_area_struct *);
79407 int (*open) (struct file *);
79408 int (*release) (struct file *);
79409-};
79410+} __do_const;
79411
79412 /*
79413 * Newer version of video_device, handled by videodev2.c
79414diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
79415index c9b1593..a572459 100644
79416--- a/include/media/v4l2-device.h
79417+++ b/include/media/v4l2-device.h
79418@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
79419 this function returns 0. If the name ends with a digit (e.g. cx18),
79420 then the name will be set to cx18-0 since cx180 looks really odd. */
79421 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
79422- atomic_t *instance);
79423+ atomic_unchecked_t *instance);
79424
79425 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
79426 Since the parent disappears this ensures that v4l2_dev doesn't have an
79427diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
79428index 9a36d92..0aafe2a 100644
79429--- a/include/net/9p/transport.h
79430+++ b/include/net/9p/transport.h
79431@@ -60,7 +60,7 @@ struct p9_trans_module {
79432 int (*cancel) (struct p9_client *, struct p9_req_t *req);
79433 int (*zc_request)(struct p9_client *, struct p9_req_t *,
79434 char *, char *, int , int, int, int);
79435-};
79436+} __do_const;
79437
79438 void v9fs_register_trans(struct p9_trans_module *m);
79439 void v9fs_unregister_trans(struct p9_trans_module *m);
79440diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
79441index 1a966af..2767cf6 100644
79442--- a/include/net/bluetooth/l2cap.h
79443+++ b/include/net/bluetooth/l2cap.h
79444@@ -551,7 +551,7 @@ struct l2cap_ops {
79445 void (*defer) (struct l2cap_chan *chan);
79446 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
79447 unsigned long len, int nb);
79448-};
79449+} __do_const;
79450
79451 struct l2cap_conn {
79452 struct hci_conn *hcon;
79453diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
79454index f2ae33d..c457cf0 100644
79455--- a/include/net/caif/cfctrl.h
79456+++ b/include/net/caif/cfctrl.h
79457@@ -52,7 +52,7 @@ struct cfctrl_rsp {
79458 void (*radioset_rsp)(void);
79459 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
79460 struct cflayer *client_layer);
79461-};
79462+} __no_const;
79463
79464 /* Link Setup Parameters for CAIF-Links. */
79465 struct cfctrl_link_param {
79466@@ -101,8 +101,8 @@ struct cfctrl_request_info {
79467 struct cfctrl {
79468 struct cfsrvl serv;
79469 struct cfctrl_rsp res;
79470- atomic_t req_seq_no;
79471- atomic_t rsp_seq_no;
79472+ atomic_unchecked_t req_seq_no;
79473+ atomic_unchecked_t rsp_seq_no;
79474 struct list_head list;
79475 /* Protects from simultaneous access to first_req list */
79476 spinlock_t info_list_lock;
79477diff --git a/include/net/flow.h b/include/net/flow.h
79478index 628e11b..4c475df 100644
79479--- a/include/net/flow.h
79480+++ b/include/net/flow.h
79481@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
79482
79483 extern void flow_cache_flush(void);
79484 extern void flow_cache_flush_deferred(void);
79485-extern atomic_t flow_cache_genid;
79486+extern atomic_unchecked_t flow_cache_genid;
79487
79488 #endif
79489diff --git a/include/net/genetlink.h b/include/net/genetlink.h
79490index 8e0b6c8..73cf605 100644
79491--- a/include/net/genetlink.h
79492+++ b/include/net/genetlink.h
79493@@ -120,7 +120,7 @@ struct genl_ops {
79494 struct netlink_callback *cb);
79495 int (*done)(struct netlink_callback *cb);
79496 struct list_head ops_list;
79497-};
79498+} __do_const;
79499
79500 extern int __genl_register_family(struct genl_family *family);
79501
79502diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
79503index 734d9b5..48a9a4b 100644
79504--- a/include/net/gro_cells.h
79505+++ b/include/net/gro_cells.h
79506@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
79507 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
79508
79509 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
79510- atomic_long_inc(&dev->rx_dropped);
79511+ atomic_long_inc_unchecked(&dev->rx_dropped);
79512 kfree_skb(skb);
79513 return;
79514 }
79515diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
79516index de2c785..0588a6b 100644
79517--- a/include/net/inet_connection_sock.h
79518+++ b/include/net/inet_connection_sock.h
79519@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
79520 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
79521 int (*bind_conflict)(const struct sock *sk,
79522 const struct inet_bind_bucket *tb, bool relax);
79523-};
79524+} __do_const;
79525
79526 /** inet_connection_sock - INET connection oriented sock
79527 *
79528diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
79529index 53f464d..0bd0b49 100644
79530--- a/include/net/inetpeer.h
79531+++ b/include/net/inetpeer.h
79532@@ -47,8 +47,8 @@ struct inet_peer {
79533 */
79534 union {
79535 struct {
79536- atomic_t rid; /* Frag reception counter */
79537- atomic_t ip_id_count; /* IP ID for the next packet */
79538+ atomic_unchecked_t rid; /* Frag reception counter */
79539+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
79540 };
79541 struct rcu_head rcu;
79542 struct inet_peer *gc_next;
79543@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
79544 /* can be called with or without local BH being disabled */
79545 static inline int inet_getid(struct inet_peer *p, int more)
79546 {
79547- int old, new;
79548+ int id;
79549 more++;
79550 inet_peer_refcheck(p);
79551- do {
79552- old = atomic_read(&p->ip_id_count);
79553- new = old + more;
79554- if (!new)
79555- new = 1;
79556- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
79557- return new;
79558+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
79559+ if (!id)
79560+ id = atomic_inc_return_unchecked(&p->ip_id_count);
79561+ return id;
79562 }
79563
79564 #endif /* _NET_INETPEER_H */
79565diff --git a/include/net/ip.h b/include/net/ip.h
79566index 301f10c..b52cdaf 100644
79567--- a/include/net/ip.h
79568+++ b/include/net/ip.h
79569@@ -212,7 +212,7 @@ extern struct local_ports {
79570 } sysctl_local_ports;
79571 extern void inet_get_local_port_range(int *low, int *high);
79572
79573-extern unsigned long *sysctl_local_reserved_ports;
79574+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
79575 static inline int inet_is_reserved_local_port(int port)
79576 {
79577 return test_bit(port, sysctl_local_reserved_ports);
79578diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
79579index cbf2be3..3683f6d 100644
79580--- a/include/net/ip_fib.h
79581+++ b/include/net/ip_fib.h
79582@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
79583
79584 #define FIB_RES_SADDR(net, res) \
79585 ((FIB_RES_NH(res).nh_saddr_genid == \
79586- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
79587+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
79588 FIB_RES_NH(res).nh_saddr : \
79589 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
79590 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
79591diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
79592index 772252d..1e69799 100644
79593--- a/include/net/ip_vs.h
79594+++ b/include/net/ip_vs.h
79595@@ -558,7 +558,7 @@ struct ip_vs_conn {
79596 struct ip_vs_conn *control; /* Master control connection */
79597 atomic_t n_control; /* Number of controlled ones */
79598 struct ip_vs_dest *dest; /* real server */
79599- atomic_t in_pkts; /* incoming packet counter */
79600+ atomic_unchecked_t in_pkts; /* incoming packet counter */
79601
79602 /* packet transmitter for different forwarding methods. If it
79603 mangles the packet, it must return NF_DROP or better NF_STOLEN,
79604@@ -705,7 +705,7 @@ struct ip_vs_dest {
79605 __be16 port; /* port number of the server */
79606 union nf_inet_addr addr; /* IP address of the server */
79607 volatile unsigned int flags; /* dest status flags */
79608- atomic_t conn_flags; /* flags to copy to conn */
79609+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
79610 atomic_t weight; /* server weight */
79611
79612 atomic_t refcnt; /* reference counter */
79613@@ -960,11 +960,11 @@ struct netns_ipvs {
79614 /* ip_vs_lblc */
79615 int sysctl_lblc_expiration;
79616 struct ctl_table_header *lblc_ctl_header;
79617- struct ctl_table *lblc_ctl_table;
79618+ ctl_table_no_const *lblc_ctl_table;
79619 /* ip_vs_lblcr */
79620 int sysctl_lblcr_expiration;
79621 struct ctl_table_header *lblcr_ctl_header;
79622- struct ctl_table *lblcr_ctl_table;
79623+ ctl_table_no_const *lblcr_ctl_table;
79624 /* ip_vs_est */
79625 struct list_head est_list; /* estimator list */
79626 spinlock_t est_lock;
79627diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
79628index 80ffde3..968b0f4 100644
79629--- a/include/net/irda/ircomm_tty.h
79630+++ b/include/net/irda/ircomm_tty.h
79631@@ -35,6 +35,7 @@
79632 #include <linux/termios.h>
79633 #include <linux/timer.h>
79634 #include <linux/tty.h> /* struct tty_struct */
79635+#include <asm/local.h>
79636
79637 #include <net/irda/irias_object.h>
79638 #include <net/irda/ircomm_core.h>
79639diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
79640index 714cc9a..ea05f3e 100644
79641--- a/include/net/iucv/af_iucv.h
79642+++ b/include/net/iucv/af_iucv.h
79643@@ -149,7 +149,7 @@ struct iucv_skb_cb {
79644 struct iucv_sock_list {
79645 struct hlist_head head;
79646 rwlock_t lock;
79647- atomic_t autobind_name;
79648+ atomic_unchecked_t autobind_name;
79649 };
79650
79651 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
79652diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
79653index df83f69..9b640b8 100644
79654--- a/include/net/llc_c_ac.h
79655+++ b/include/net/llc_c_ac.h
79656@@ -87,7 +87,7 @@
79657 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
79658 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
79659
79660-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79661+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79662
79663 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
79664 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
79665diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
79666index 6ca3113..f8026dd 100644
79667--- a/include/net/llc_c_ev.h
79668+++ b/include/net/llc_c_ev.h
79669@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
79670 return (struct llc_conn_state_ev *)skb->cb;
79671 }
79672
79673-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79674-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79675+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79676+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79677
79678 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
79679 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
79680diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
79681index 0e79cfb..f46db31 100644
79682--- a/include/net/llc_c_st.h
79683+++ b/include/net/llc_c_st.h
79684@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
79685 u8 next_state;
79686 llc_conn_ev_qfyr_t *ev_qualifiers;
79687 llc_conn_action_t *ev_actions;
79688-};
79689+} __do_const;
79690
79691 struct llc_conn_state {
79692 u8 current_state;
79693diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
79694index 37a3bbd..55a4241 100644
79695--- a/include/net/llc_s_ac.h
79696+++ b/include/net/llc_s_ac.h
79697@@ -23,7 +23,7 @@
79698 #define SAP_ACT_TEST_IND 9
79699
79700 /* All action functions must look like this */
79701-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79702+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79703
79704 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
79705 struct sk_buff *skb);
79706diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
79707index 567c681..cd73ac0 100644
79708--- a/include/net/llc_s_st.h
79709+++ b/include/net/llc_s_st.h
79710@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
79711 llc_sap_ev_t ev;
79712 u8 next_state;
79713 llc_sap_action_t *ev_actions;
79714-};
79715+} __do_const;
79716
79717 struct llc_sap_state {
79718 u8 curr_state;
79719diff --git a/include/net/mac80211.h b/include/net/mac80211.h
79720index cc6035f..a8406fc 100644
79721--- a/include/net/mac80211.h
79722+++ b/include/net/mac80211.h
79723@@ -4361,7 +4361,7 @@ struct rate_control_ops {
79724 void (*add_sta_debugfs)(void *priv, void *priv_sta,
79725 struct dentry *dir);
79726 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
79727-};
79728+} __do_const;
79729
79730 static inline int rate_supported(struct ieee80211_sta *sta,
79731 enum ieee80211_band band,
79732diff --git a/include/net/neighbour.h b/include/net/neighbour.h
79733index 536501a..7c6193c 100644
79734--- a/include/net/neighbour.h
79735+++ b/include/net/neighbour.h
79736@@ -123,7 +123,7 @@ struct neigh_ops {
79737 void (*error_report)(struct neighbour *, struct sk_buff *);
79738 int (*output)(struct neighbour *, struct sk_buff *);
79739 int (*connected_output)(struct neighbour *, struct sk_buff *);
79740-};
79741+} __do_const;
79742
79743 struct pneigh_entry {
79744 struct pneigh_entry *next;
79745diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
79746index 9d22f08..980fbf8 100644
79747--- a/include/net/net_namespace.h
79748+++ b/include/net/net_namespace.h
79749@@ -120,7 +120,7 @@ struct net {
79750 struct netns_ipvs *ipvs;
79751 #endif
79752 struct sock *diag_nlsk;
79753- atomic_t fnhe_genid;
79754+ atomic_unchecked_t fnhe_genid;
79755 };
79756
79757 /*
79758@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
79759 #define __net_init __init
79760 #define __net_exit __exit_refok
79761 #define __net_initdata __initdata
79762+#ifdef CONSTIFY_PLUGIN
79763 #define __net_initconst __initconst
79764+#else
79765+#define __net_initconst __initdata
79766+#endif
79767 #endif
79768
79769 struct pernet_operations {
79770@@ -287,7 +291,7 @@ struct pernet_operations {
79771 void (*exit_batch)(struct list_head *net_exit_list);
79772 int *id;
79773 size_t size;
79774-};
79775+} __do_const;
79776
79777 /*
79778 * Use these carefully. If you implement a network device and it
79779@@ -335,23 +339,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
79780
79781 static inline int rt_genid_ipv4(struct net *net)
79782 {
79783- return atomic_read(&net->ipv4.rt_genid);
79784+ return atomic_read_unchecked(&net->ipv4.rt_genid);
79785 }
79786
79787 static inline void rt_genid_bump_ipv4(struct net *net)
79788 {
79789- atomic_inc(&net->ipv4.rt_genid);
79790+ atomic_inc_unchecked(&net->ipv4.rt_genid);
79791 }
79792
79793 #if IS_ENABLED(CONFIG_IPV6)
79794 static inline int rt_genid_ipv6(struct net *net)
79795 {
79796- return atomic_read(&net->ipv6.rt_genid);
79797+ return atomic_read_unchecked(&net->ipv6.rt_genid);
79798 }
79799
79800 static inline void rt_genid_bump_ipv6(struct net *net)
79801 {
79802- atomic_inc(&net->ipv6.rt_genid);
79803+ atomic_inc_unchecked(&net->ipv6.rt_genid);
79804 }
79805 #else
79806 static inline int rt_genid_ipv6(struct net *net)
79807@@ -373,12 +377,12 @@ static inline void rt_genid_bump_all(struct net *net)
79808
79809 static inline int fnhe_genid(struct net *net)
79810 {
79811- return atomic_read(&net->fnhe_genid);
79812+ return atomic_read_unchecked(&net->fnhe_genid);
79813 }
79814
79815 static inline void fnhe_genid_bump(struct net *net)
79816 {
79817- atomic_inc(&net->fnhe_genid);
79818+ atomic_inc_unchecked(&net->fnhe_genid);
79819 }
79820
79821 #endif /* __NET_NET_NAMESPACE_H */
79822diff --git a/include/net/netdma.h b/include/net/netdma.h
79823index 8ba8ce2..99b7fff 100644
79824--- a/include/net/netdma.h
79825+++ b/include/net/netdma.h
79826@@ -24,7 +24,7 @@
79827 #include <linux/dmaengine.h>
79828 #include <linux/skbuff.h>
79829
79830-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79831+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79832 struct sk_buff *skb, int offset, struct iovec *to,
79833 size_t len, struct dma_pinned_list *pinned_list);
79834
79835diff --git a/include/net/netlink.h b/include/net/netlink.h
79836index 9690b0f..87aded7 100644
79837--- a/include/net/netlink.h
79838+++ b/include/net/netlink.h
79839@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
79840 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
79841 {
79842 if (mark)
79843- skb_trim(skb, (unsigned char *) mark - skb->data);
79844+ skb_trim(skb, (const unsigned char *) mark - skb->data);
79845 }
79846
79847 /**
79848diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
79849index c9c0c53..53f24c3 100644
79850--- a/include/net/netns/conntrack.h
79851+++ b/include/net/netns/conntrack.h
79852@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
79853 struct nf_proto_net {
79854 #ifdef CONFIG_SYSCTL
79855 struct ctl_table_header *ctl_table_header;
79856- struct ctl_table *ctl_table;
79857+ ctl_table_no_const *ctl_table;
79858 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
79859 struct ctl_table_header *ctl_compat_header;
79860- struct ctl_table *ctl_compat_table;
79861+ ctl_table_no_const *ctl_compat_table;
79862 #endif
79863 #endif
79864 unsigned int users;
79865@@ -58,7 +58,7 @@ struct nf_ip_net {
79866 struct nf_icmp_net icmpv6;
79867 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
79868 struct ctl_table_header *ctl_table_header;
79869- struct ctl_table *ctl_table;
79870+ ctl_table_no_const *ctl_table;
79871 #endif
79872 };
79873
79874diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
79875index bf2ec22..5e7f9d9 100644
79876--- a/include/net/netns/ipv4.h
79877+++ b/include/net/netns/ipv4.h
79878@@ -67,7 +67,7 @@ struct netns_ipv4 {
79879 kgid_t sysctl_ping_group_range[2];
79880 long sysctl_tcp_mem[3];
79881
79882- atomic_t dev_addr_genid;
79883+ atomic_unchecked_t dev_addr_genid;
79884
79885 #ifdef CONFIG_IP_MROUTE
79886 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
79887@@ -77,6 +77,6 @@ struct netns_ipv4 {
79888 struct fib_rules_ops *mr_rules_ops;
79889 #endif
79890 #endif
79891- atomic_t rt_genid;
79892+ atomic_unchecked_t rt_genid;
79893 };
79894 #endif
79895diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
79896index 0fb2401..477d81c 100644
79897--- a/include/net/netns/ipv6.h
79898+++ b/include/net/netns/ipv6.h
79899@@ -71,8 +71,8 @@ struct netns_ipv6 {
79900 struct fib_rules_ops *mr6_rules_ops;
79901 #endif
79902 #endif
79903- atomic_t dev_addr_genid;
79904- atomic_t rt_genid;
79905+ atomic_unchecked_t dev_addr_genid;
79906+ atomic_unchecked_t rt_genid;
79907 };
79908
79909 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
79910diff --git a/include/net/ping.h b/include/net/ping.h
79911index 2b496e9..935fd8d 100644
79912--- a/include/net/ping.h
79913+++ b/include/net/ping.h
79914@@ -56,7 +56,7 @@ struct ping_iter_state {
79915 extern struct proto ping_prot;
79916 extern struct ping_table ping_table;
79917 #if IS_ENABLED(CONFIG_IPV6)
79918-extern struct pingv6_ops pingv6_ops;
79919+extern struct pingv6_ops *pingv6_ops;
79920 #endif
79921
79922 struct pingfakehdr {
79923diff --git a/include/net/protocol.h b/include/net/protocol.h
79924index 047c047..b9dad15 100644
79925--- a/include/net/protocol.h
79926+++ b/include/net/protocol.h
79927@@ -44,7 +44,7 @@ struct net_protocol {
79928 void (*err_handler)(struct sk_buff *skb, u32 info);
79929 unsigned int no_policy:1,
79930 netns_ok:1;
79931-};
79932+} __do_const;
79933
79934 #if IS_ENABLED(CONFIG_IPV6)
79935 struct inet6_protocol {
79936@@ -57,7 +57,7 @@ struct inet6_protocol {
79937 u8 type, u8 code, int offset,
79938 __be32 info);
79939 unsigned int flags; /* INET6_PROTO_xxx */
79940-};
79941+} __do_const;
79942
79943 #define INET6_PROTO_NOPOLICY 0x1
79944 #define INET6_PROTO_FINAL 0x2
79945diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
79946index 7026648..584cc8c 100644
79947--- a/include/net/rtnetlink.h
79948+++ b/include/net/rtnetlink.h
79949@@ -81,7 +81,7 @@ struct rtnl_link_ops {
79950 const struct net_device *dev);
79951 unsigned int (*get_num_tx_queues)(void);
79952 unsigned int (*get_num_rx_queues)(void);
79953-};
79954+} __do_const;
79955
79956 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
79957 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
79958diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
79959index 4ef75af..5aa073a 100644
79960--- a/include/net/sctp/sm.h
79961+++ b/include/net/sctp/sm.h
79962@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
79963 typedef struct {
79964 sctp_state_fn_t *fn;
79965 const char *name;
79966-} sctp_sm_table_entry_t;
79967+} __do_const sctp_sm_table_entry_t;
79968
79969 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
79970 * currently in use.
79971@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
79972 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
79973
79974 /* Extern declarations for major data structures. */
79975-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79976+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79977
79978
79979 /* Get the size of a DATA chunk payload. */
79980diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
79981index 2174d8d..71d5257 100644
79982--- a/include/net/sctp/structs.h
79983+++ b/include/net/sctp/structs.h
79984@@ -508,7 +508,7 @@ struct sctp_pf {
79985 struct sctp_association *asoc);
79986 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
79987 struct sctp_af *af;
79988-};
79989+} __do_const;
79990
79991
79992 /* Structure to track chunk fragments that have been acked, but peer
79993diff --git a/include/net/sock.h b/include/net/sock.h
79994index 808cbc2..8617e9c 100644
79995--- a/include/net/sock.h
79996+++ b/include/net/sock.h
79997@@ -332,7 +332,7 @@ struct sock {
79998 unsigned int sk_napi_id;
79999 unsigned int sk_ll_usec;
80000 #endif
80001- atomic_t sk_drops;
80002+ atomic_unchecked_t sk_drops;
80003 int sk_rcvbuf;
80004
80005 struct sk_filter __rcu *sk_filter;
80006@@ -1194,7 +1194,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
80007 return ret >> PAGE_SHIFT;
80008 }
80009
80010-static inline long
80011+static inline long __intentional_overflow(-1)
80012 sk_memory_allocated(const struct sock *sk)
80013 {
80014 struct proto *prot = sk->sk_prot;
80015@@ -1821,7 +1821,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
80016 }
80017
80018 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
80019- char __user *from, char *to,
80020+ char __user *from, unsigned char *to,
80021 int copy, int offset)
80022 {
80023 if (skb->ip_summed == CHECKSUM_NONE) {
80024@@ -2083,7 +2083,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
80025 }
80026 }
80027
80028-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
80029+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
80030
80031 /**
80032 * sk_page_frag - return an appropriate page_frag
80033diff --git a/include/net/tcp.h b/include/net/tcp.h
80034index b1aa324..b8530ea 100644
80035--- a/include/net/tcp.h
80036+++ b/include/net/tcp.h
80037@@ -527,7 +527,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
80038 extern void tcp_xmit_retransmit_queue(struct sock *);
80039 extern void tcp_simple_retransmit(struct sock *);
80040 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
80041-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
80042+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
80043
80044 extern void tcp_send_probe0(struct sock *);
80045 extern void tcp_send_partial(struct sock *);
80046@@ -699,8 +699,8 @@ struct tcp_skb_cb {
80047 struct inet6_skb_parm h6;
80048 #endif
80049 } header; /* For incoming frames */
80050- __u32 seq; /* Starting sequence number */
80051- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
80052+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
80053+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
80054 __u32 when; /* used to compute rtt's */
80055 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
80056
80057@@ -714,7 +714,7 @@ struct tcp_skb_cb {
80058
80059 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
80060 /* 1 byte hole */
80061- __u32 ack_seq; /* Sequence number ACK'd */
80062+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
80063 };
80064
80065 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
80066diff --git a/include/net/xfrm.h b/include/net/xfrm.h
80067index e253bf0..2278b4b 100644
80068--- a/include/net/xfrm.h
80069+++ b/include/net/xfrm.h
80070@@ -287,7 +287,6 @@ struct xfrm_dst;
80071 struct xfrm_policy_afinfo {
80072 unsigned short family;
80073 struct dst_ops *dst_ops;
80074- void (*garbage_collect)(struct net *net);
80075 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
80076 const xfrm_address_t *saddr,
80077 const xfrm_address_t *daddr);
80078@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
80079 struct net_device *dev,
80080 const struct flowi *fl);
80081 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
80082-};
80083+} __do_const;
80084
80085 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
80086 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
80087@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
80088 int (*transport_finish)(struct sk_buff *skb,
80089 int async);
80090 void (*local_error)(struct sk_buff *skb, u32 mtu);
80091-};
80092+} __do_const;
80093
80094 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
80095 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
80096@@ -427,7 +426,7 @@ struct xfrm_mode {
80097 struct module *owner;
80098 unsigned int encap;
80099 int flags;
80100-};
80101+} __do_const;
80102
80103 /* Flags for xfrm_mode. */
80104 enum {
80105@@ -524,7 +523,7 @@ struct xfrm_policy {
80106 struct timer_list timer;
80107
80108 struct flow_cache_object flo;
80109- atomic_t genid;
80110+ atomic_unchecked_t genid;
80111 u32 priority;
80112 u32 index;
80113 struct xfrm_mark mark;
80114@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
80115 }
80116
80117 extern void xfrm_garbage_collect(struct net *net);
80118+extern void xfrm_garbage_collect_deferred(struct net *net);
80119
80120 #else
80121
80122@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
80123 static inline void xfrm_garbage_collect(struct net *net)
80124 {
80125 }
80126+static inline void xfrm_garbage_collect_deferred(struct net *net)
80127+{
80128+}
80129 #endif
80130
80131 static __inline__
80132diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
80133index 1017e0b..227aa4d 100644
80134--- a/include/rdma/iw_cm.h
80135+++ b/include/rdma/iw_cm.h
80136@@ -122,7 +122,7 @@ struct iw_cm_verbs {
80137 int backlog);
80138
80139 int (*destroy_listen)(struct iw_cm_id *cm_id);
80140-};
80141+} __no_const;
80142
80143 /**
80144 * iw_create_cm_id - Create an IW CM identifier.
80145diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
80146index e1379b4..67eafbe 100644
80147--- a/include/scsi/libfc.h
80148+++ b/include/scsi/libfc.h
80149@@ -762,6 +762,7 @@ struct libfc_function_template {
80150 */
80151 void (*disc_stop_final) (struct fc_lport *);
80152 };
80153+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
80154
80155 /**
80156 * struct fc_disc - Discovery context
80157@@ -866,7 +867,7 @@ struct fc_lport {
80158 struct fc_vport *vport;
80159
80160 /* Operational Information */
80161- struct libfc_function_template tt;
80162+ libfc_function_template_no_const tt;
80163 u8 link_up;
80164 u8 qfull;
80165 enum fc_lport_state state;
80166diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
80167index d65fbec..f80fef2 100644
80168--- a/include/scsi/scsi_device.h
80169+++ b/include/scsi/scsi_device.h
80170@@ -180,9 +180,9 @@ struct scsi_device {
80171 unsigned int max_device_blocked; /* what device_blocked counts down from */
80172 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
80173
80174- atomic_t iorequest_cnt;
80175- atomic_t iodone_cnt;
80176- atomic_t ioerr_cnt;
80177+ atomic_unchecked_t iorequest_cnt;
80178+ atomic_unchecked_t iodone_cnt;
80179+ atomic_unchecked_t ioerr_cnt;
80180
80181 struct device sdev_gendev,
80182 sdev_dev;
80183diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
80184index b797e8f..8e2c3aa 100644
80185--- a/include/scsi/scsi_transport_fc.h
80186+++ b/include/scsi/scsi_transport_fc.h
80187@@ -751,7 +751,8 @@ struct fc_function_template {
80188 unsigned long show_host_system_hostname:1;
80189
80190 unsigned long disable_target_scan:1;
80191-};
80192+} __do_const;
80193+typedef struct fc_function_template __no_const fc_function_template_no_const;
80194
80195
80196 /**
80197diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
80198index ae6c3b8..fd748ac 100644
80199--- a/include/sound/compress_driver.h
80200+++ b/include/sound/compress_driver.h
80201@@ -128,7 +128,7 @@ struct snd_compr_ops {
80202 struct snd_compr_caps *caps);
80203 int (*get_codec_caps) (struct snd_compr_stream *stream,
80204 struct snd_compr_codec_caps *codec);
80205-};
80206+} __no_const;
80207
80208 /**
80209 * struct snd_compr: Compressed device
80210diff --git a/include/sound/soc.h b/include/sound/soc.h
80211index d22cb0a..c6ba150 100644
80212--- a/include/sound/soc.h
80213+++ b/include/sound/soc.h
80214@@ -780,7 +780,7 @@ struct snd_soc_codec_driver {
80215 /* probe ordering - for components with runtime dependencies */
80216 int probe_order;
80217 int remove_order;
80218-};
80219+} __do_const;
80220
80221 /* SoC platform interface */
80222 struct snd_soc_platform_driver {
80223@@ -826,7 +826,7 @@ struct snd_soc_platform_driver {
80224 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
80225 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
80226 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
80227-};
80228+} __do_const;
80229
80230 struct snd_soc_platform {
80231 const char *name;
80232diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
80233index 5bdb8b7..bb1096c 100644
80234--- a/include/target/target_core_base.h
80235+++ b/include/target/target_core_base.h
80236@@ -663,7 +663,7 @@ struct se_device {
80237 spinlock_t stats_lock;
80238 /* Active commands on this virtual SE device */
80239 atomic_t simple_cmds;
80240- atomic_t dev_ordered_id;
80241+ atomic_unchecked_t dev_ordered_id;
80242 atomic_t dev_ordered_sync;
80243 atomic_t dev_qf_count;
80244 int export_count;
80245diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
80246new file mode 100644
80247index 0000000..fb634b7
80248--- /dev/null
80249+++ b/include/trace/events/fs.h
80250@@ -0,0 +1,53 @@
80251+#undef TRACE_SYSTEM
80252+#define TRACE_SYSTEM fs
80253+
80254+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
80255+#define _TRACE_FS_H
80256+
80257+#include <linux/fs.h>
80258+#include <linux/tracepoint.h>
80259+
80260+TRACE_EVENT(do_sys_open,
80261+
80262+ TP_PROTO(const char *filename, int flags, int mode),
80263+
80264+ TP_ARGS(filename, flags, mode),
80265+
80266+ TP_STRUCT__entry(
80267+ __string( filename, filename )
80268+ __field( int, flags )
80269+ __field( int, mode )
80270+ ),
80271+
80272+ TP_fast_assign(
80273+ __assign_str(filename, filename);
80274+ __entry->flags = flags;
80275+ __entry->mode = mode;
80276+ ),
80277+
80278+ TP_printk("\"%s\" %x %o",
80279+ __get_str(filename), __entry->flags, __entry->mode)
80280+);
80281+
80282+TRACE_EVENT(open_exec,
80283+
80284+ TP_PROTO(const char *filename),
80285+
80286+ TP_ARGS(filename),
80287+
80288+ TP_STRUCT__entry(
80289+ __string( filename, filename )
80290+ ),
80291+
80292+ TP_fast_assign(
80293+ __assign_str(filename, filename);
80294+ ),
80295+
80296+ TP_printk("\"%s\"",
80297+ __get_str(filename))
80298+);
80299+
80300+#endif /* _TRACE_FS_H */
80301+
80302+/* This part must be outside protection */
80303+#include <trace/define_trace.h>
80304diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
80305index 1c09820..7f5ec79 100644
80306--- a/include/trace/events/irq.h
80307+++ b/include/trace/events/irq.h
80308@@ -36,7 +36,7 @@ struct softirq_action;
80309 */
80310 TRACE_EVENT(irq_handler_entry,
80311
80312- TP_PROTO(int irq, struct irqaction *action),
80313+ TP_PROTO(int irq, const struct irqaction *action),
80314
80315 TP_ARGS(irq, action),
80316
80317@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
80318 */
80319 TRACE_EVENT(irq_handler_exit,
80320
80321- TP_PROTO(int irq, struct irqaction *action, int ret),
80322+ TP_PROTO(int irq, const struct irqaction *action, int ret),
80323
80324 TP_ARGS(irq, action, ret),
80325
80326diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
80327index 7caf44c..23c6f27 100644
80328--- a/include/uapi/linux/a.out.h
80329+++ b/include/uapi/linux/a.out.h
80330@@ -39,6 +39,14 @@ enum machine_type {
80331 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
80332 };
80333
80334+/* Constants for the N_FLAGS field */
80335+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
80336+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
80337+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
80338+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
80339+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
80340+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
80341+
80342 #if !defined (N_MAGIC)
80343 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
80344 #endif
80345diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
80346index d876736..ccce5c0 100644
80347--- a/include/uapi/linux/byteorder/little_endian.h
80348+++ b/include/uapi/linux/byteorder/little_endian.h
80349@@ -42,51 +42,51 @@
80350
80351 static inline __le64 __cpu_to_le64p(const __u64 *p)
80352 {
80353- return (__force __le64)*p;
80354+ return (__force const __le64)*p;
80355 }
80356-static inline __u64 __le64_to_cpup(const __le64 *p)
80357+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
80358 {
80359- return (__force __u64)*p;
80360+ return (__force const __u64)*p;
80361 }
80362 static inline __le32 __cpu_to_le32p(const __u32 *p)
80363 {
80364- return (__force __le32)*p;
80365+ return (__force const __le32)*p;
80366 }
80367 static inline __u32 __le32_to_cpup(const __le32 *p)
80368 {
80369- return (__force __u32)*p;
80370+ return (__force const __u32)*p;
80371 }
80372 static inline __le16 __cpu_to_le16p(const __u16 *p)
80373 {
80374- return (__force __le16)*p;
80375+ return (__force const __le16)*p;
80376 }
80377 static inline __u16 __le16_to_cpup(const __le16 *p)
80378 {
80379- return (__force __u16)*p;
80380+ return (__force const __u16)*p;
80381 }
80382 static inline __be64 __cpu_to_be64p(const __u64 *p)
80383 {
80384- return (__force __be64)__swab64p(p);
80385+ return (__force const __be64)__swab64p(p);
80386 }
80387 static inline __u64 __be64_to_cpup(const __be64 *p)
80388 {
80389- return __swab64p((__u64 *)p);
80390+ return __swab64p((const __u64 *)p);
80391 }
80392 static inline __be32 __cpu_to_be32p(const __u32 *p)
80393 {
80394- return (__force __be32)__swab32p(p);
80395+ return (__force const __be32)__swab32p(p);
80396 }
80397-static inline __u32 __be32_to_cpup(const __be32 *p)
80398+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
80399 {
80400- return __swab32p((__u32 *)p);
80401+ return __swab32p((const __u32 *)p);
80402 }
80403 static inline __be16 __cpu_to_be16p(const __u16 *p)
80404 {
80405- return (__force __be16)__swab16p(p);
80406+ return (__force const __be16)__swab16p(p);
80407 }
80408 static inline __u16 __be16_to_cpup(const __be16 *p)
80409 {
80410- return __swab16p((__u16 *)p);
80411+ return __swab16p((const __u16 *)p);
80412 }
80413 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
80414 #define __le64_to_cpus(x) do { (void)(x); } while (0)
80415diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
80416index ef6103b..d4e65dd 100644
80417--- a/include/uapi/linux/elf.h
80418+++ b/include/uapi/linux/elf.h
80419@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
80420 #define PT_GNU_EH_FRAME 0x6474e550
80421
80422 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
80423+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
80424+
80425+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
80426+
80427+/* Constants for the e_flags field */
80428+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
80429+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
80430+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
80431+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
80432+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
80433+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
80434
80435 /*
80436 * Extended Numbering
80437@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
80438 #define DT_DEBUG 21
80439 #define DT_TEXTREL 22
80440 #define DT_JMPREL 23
80441+#define DT_FLAGS 30
80442+ #define DF_TEXTREL 0x00000004
80443 #define DT_ENCODING 32
80444 #define OLD_DT_LOOS 0x60000000
80445 #define DT_LOOS 0x6000000d
80446@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
80447 #define PF_W 0x2
80448 #define PF_X 0x1
80449
80450+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
80451+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
80452+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
80453+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
80454+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
80455+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
80456+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
80457+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
80458+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
80459+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
80460+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
80461+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
80462+
80463 typedef struct elf32_phdr{
80464 Elf32_Word p_type;
80465 Elf32_Off p_offset;
80466@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
80467 #define EI_OSABI 7
80468 #define EI_PAD 8
80469
80470+#define EI_PAX 14
80471+
80472 #define ELFMAG0 0x7f /* EI_MAG */
80473 #define ELFMAG1 'E'
80474 #define ELFMAG2 'L'
80475diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
80476index aa169c4..6a2771d 100644
80477--- a/include/uapi/linux/personality.h
80478+++ b/include/uapi/linux/personality.h
80479@@ -30,6 +30,7 @@ enum {
80480 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
80481 ADDR_NO_RANDOMIZE | \
80482 ADDR_COMPAT_LAYOUT | \
80483+ ADDR_LIMIT_3GB | \
80484 MMAP_PAGE_ZERO)
80485
80486 /*
80487diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
80488index 7530e74..e714828 100644
80489--- a/include/uapi/linux/screen_info.h
80490+++ b/include/uapi/linux/screen_info.h
80491@@ -43,7 +43,8 @@ struct screen_info {
80492 __u16 pages; /* 0x32 */
80493 __u16 vesa_attributes; /* 0x34 */
80494 __u32 capabilities; /* 0x36 */
80495- __u8 _reserved[6]; /* 0x3a */
80496+ __u16 vesapm_size; /* 0x3a */
80497+ __u8 _reserved[4]; /* 0x3c */
80498 } __attribute__((packed));
80499
80500 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
80501diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
80502index 0e011eb..82681b1 100644
80503--- a/include/uapi/linux/swab.h
80504+++ b/include/uapi/linux/swab.h
80505@@ -43,7 +43,7 @@
80506 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
80507 */
80508
80509-static inline __attribute_const__ __u16 __fswab16(__u16 val)
80510+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
80511 {
80512 #ifdef __HAVE_BUILTIN_BSWAP16__
80513 return __builtin_bswap16(val);
80514@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
80515 #endif
80516 }
80517
80518-static inline __attribute_const__ __u32 __fswab32(__u32 val)
80519+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
80520 {
80521 #ifdef __HAVE_BUILTIN_BSWAP32__
80522 return __builtin_bswap32(val);
80523@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
80524 #endif
80525 }
80526
80527-static inline __attribute_const__ __u64 __fswab64(__u64 val)
80528+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
80529 {
80530 #ifdef __HAVE_BUILTIN_BSWAP64__
80531 return __builtin_bswap64(val);
80532diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
80533index 6d67213..8dab561 100644
80534--- a/include/uapi/linux/sysctl.h
80535+++ b/include/uapi/linux/sysctl.h
80536@@ -155,7 +155,11 @@ enum
80537 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
80538 };
80539
80540-
80541+#ifdef CONFIG_PAX_SOFTMODE
80542+enum {
80543+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
80544+};
80545+#endif
80546
80547 /* CTL_VM names: */
80548 enum
80549diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
80550index e4629b9..6958086 100644
80551--- a/include/uapi/linux/xattr.h
80552+++ b/include/uapi/linux/xattr.h
80553@@ -63,5 +63,9 @@
80554 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
80555 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
80556
80557+/* User namespace */
80558+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
80559+#define XATTR_PAX_FLAGS_SUFFIX "flags"
80560+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
80561
80562 #endif /* _UAPI_LINUX_XATTR_H */
80563diff --git a/include/video/udlfb.h b/include/video/udlfb.h
80564index f9466fa..f4e2b81 100644
80565--- a/include/video/udlfb.h
80566+++ b/include/video/udlfb.h
80567@@ -53,10 +53,10 @@ struct dlfb_data {
80568 u32 pseudo_palette[256];
80569 int blank_mode; /*one of FB_BLANK_ */
80570 /* blit-only rendering path metrics, exposed through sysfs */
80571- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
80572- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
80573- atomic_t bytes_sent; /* to usb, after compression including overhead */
80574- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
80575+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
80576+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
80577+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
80578+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
80579 };
80580
80581 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
80582diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
80583index 30f5362..8ed8ac9 100644
80584--- a/include/video/uvesafb.h
80585+++ b/include/video/uvesafb.h
80586@@ -122,6 +122,7 @@ struct uvesafb_par {
80587 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
80588 u8 pmi_setpal; /* PMI for palette changes */
80589 u16 *pmi_base; /* protected mode interface location */
80590+ u8 *pmi_code; /* protected mode code location */
80591 void *pmi_start;
80592 void *pmi_pal;
80593 u8 *vbe_state_orig; /*
80594diff --git a/init/Kconfig b/init/Kconfig
80595index 3ecd8a1..627843f 100644
80596--- a/init/Kconfig
80597+++ b/init/Kconfig
80598@@ -1086,6 +1086,7 @@ endif # CGROUPS
80599
80600 config CHECKPOINT_RESTORE
80601 bool "Checkpoint/restore support" if EXPERT
80602+ depends on !GRKERNSEC
80603 default n
80604 help
80605 Enables additional kernel features in a sake of checkpoint/restore.
80606@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
80607
80608 config COMPAT_BRK
80609 bool "Disable heap randomization"
80610- default y
80611+ default n
80612 help
80613 Randomizing heap placement makes heap exploits harder, but it
80614 also breaks ancient binaries (including anything libc5 based).
80615@@ -1832,7 +1833,7 @@ config INIT_ALL_POSSIBLE
80616 config STOP_MACHINE
80617 bool
80618 default y
80619- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
80620+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
80621 help
80622 Need stop_machine() primitive.
80623
80624diff --git a/init/Makefile b/init/Makefile
80625index 7bc47ee..6da2dc7 100644
80626--- a/init/Makefile
80627+++ b/init/Makefile
80628@@ -2,6 +2,9 @@
80629 # Makefile for the linux kernel.
80630 #
80631
80632+ccflags-y := $(GCC_PLUGINS_CFLAGS)
80633+asflags-y := $(GCC_PLUGINS_AFLAGS)
80634+
80635 obj-y := main.o version.o mounts.o
80636 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
80637 obj-y += noinitramfs.o
80638diff --git a/init/do_mounts.c b/init/do_mounts.c
80639index a51cddc..25c2768 100644
80640--- a/init/do_mounts.c
80641+++ b/init/do_mounts.c
80642@@ -357,11 +357,11 @@ static void __init get_fs_names(char *page)
80643 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
80644 {
80645 struct super_block *s;
80646- int err = sys_mount(name, "/root", fs, flags, data);
80647+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
80648 if (err)
80649 return err;
80650
80651- sys_chdir("/root");
80652+ sys_chdir((const char __force_user *)"/root");
80653 s = current->fs->pwd.dentry->d_sb;
80654 ROOT_DEV = s->s_dev;
80655 printk(KERN_INFO
80656@@ -482,18 +482,18 @@ void __init change_floppy(char *fmt, ...)
80657 va_start(args, fmt);
80658 vsprintf(buf, fmt, args);
80659 va_end(args);
80660- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
80661+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
80662 if (fd >= 0) {
80663 sys_ioctl(fd, FDEJECT, 0);
80664 sys_close(fd);
80665 }
80666 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
80667- fd = sys_open("/dev/console", O_RDWR, 0);
80668+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
80669 if (fd >= 0) {
80670 sys_ioctl(fd, TCGETS, (long)&termios);
80671 termios.c_lflag &= ~ICANON;
80672 sys_ioctl(fd, TCSETSF, (long)&termios);
80673- sys_read(fd, &c, 1);
80674+ sys_read(fd, (char __user *)&c, 1);
80675 termios.c_lflag |= ICANON;
80676 sys_ioctl(fd, TCSETSF, (long)&termios);
80677 sys_close(fd);
80678@@ -587,8 +587,8 @@ void __init prepare_namespace(void)
80679 mount_root();
80680 out:
80681 devtmpfs_mount("dev");
80682- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80683- sys_chroot(".");
80684+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80685+ sys_chroot((const char __force_user *)".");
80686 }
80687
80688 static bool is_tmpfs;
80689diff --git a/init/do_mounts.h b/init/do_mounts.h
80690index f5b978a..69dbfe8 100644
80691--- a/init/do_mounts.h
80692+++ b/init/do_mounts.h
80693@@ -15,15 +15,15 @@ extern int root_mountflags;
80694
80695 static inline int create_dev(char *name, dev_t dev)
80696 {
80697- sys_unlink(name);
80698- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
80699+ sys_unlink((char __force_user *)name);
80700+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
80701 }
80702
80703 #if BITS_PER_LONG == 32
80704 static inline u32 bstat(char *name)
80705 {
80706 struct stat64 stat;
80707- if (sys_stat64(name, &stat) != 0)
80708+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
80709 return 0;
80710 if (!S_ISBLK(stat.st_mode))
80711 return 0;
80712@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
80713 static inline u32 bstat(char *name)
80714 {
80715 struct stat stat;
80716- if (sys_newstat(name, &stat) != 0)
80717+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
80718 return 0;
80719 if (!S_ISBLK(stat.st_mode))
80720 return 0;
80721diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
80722index 3e0878e..8a9d7a0 100644
80723--- a/init/do_mounts_initrd.c
80724+++ b/init/do_mounts_initrd.c
80725@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
80726 {
80727 sys_unshare(CLONE_FS | CLONE_FILES);
80728 /* stdin/stdout/stderr for /linuxrc */
80729- sys_open("/dev/console", O_RDWR, 0);
80730+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
80731 sys_dup(0);
80732 sys_dup(0);
80733 /* move initrd over / and chdir/chroot in initrd root */
80734- sys_chdir("/root");
80735- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80736- sys_chroot(".");
80737+ sys_chdir((const char __force_user *)"/root");
80738+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80739+ sys_chroot((const char __force_user *)".");
80740 sys_setsid();
80741 return 0;
80742 }
80743@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
80744 create_dev("/dev/root.old", Root_RAM0);
80745 /* mount initrd on rootfs' /root */
80746 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
80747- sys_mkdir("/old", 0700);
80748- sys_chdir("/old");
80749+ sys_mkdir((const char __force_user *)"/old", 0700);
80750+ sys_chdir((const char __force_user *)"/old");
80751
80752 /* try loading default modules from initrd */
80753 load_default_modules();
80754@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
80755 current->flags &= ~PF_FREEZER_SKIP;
80756
80757 /* move initrd to rootfs' /old */
80758- sys_mount("..", ".", NULL, MS_MOVE, NULL);
80759+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
80760 /* switch root and cwd back to / of rootfs */
80761- sys_chroot("..");
80762+ sys_chroot((const char __force_user *)"..");
80763
80764 if (new_decode_dev(real_root_dev) == Root_RAM0) {
80765- sys_chdir("/old");
80766+ sys_chdir((const char __force_user *)"/old");
80767 return;
80768 }
80769
80770- sys_chdir("/");
80771+ sys_chdir((const char __force_user *)"/");
80772 ROOT_DEV = new_decode_dev(real_root_dev);
80773 mount_root();
80774
80775 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
80776- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
80777+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
80778 if (!error)
80779 printk("okay\n");
80780 else {
80781- int fd = sys_open("/dev/root.old", O_RDWR, 0);
80782+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
80783 if (error == -ENOENT)
80784 printk("/initrd does not exist. Ignored.\n");
80785 else
80786 printk("failed\n");
80787 printk(KERN_NOTICE "Unmounting old root\n");
80788- sys_umount("/old", MNT_DETACH);
80789+ sys_umount((char __force_user *)"/old", MNT_DETACH);
80790 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
80791 if (fd < 0) {
80792 error = fd;
80793@@ -127,11 +127,11 @@ int __init initrd_load(void)
80794 * mounted in the normal path.
80795 */
80796 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
80797- sys_unlink("/initrd.image");
80798+ sys_unlink((const char __force_user *)"/initrd.image");
80799 handle_initrd();
80800 return 1;
80801 }
80802 }
80803- sys_unlink("/initrd.image");
80804+ sys_unlink((const char __force_user *)"/initrd.image");
80805 return 0;
80806 }
80807diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
80808index 8cb6db5..d729f50 100644
80809--- a/init/do_mounts_md.c
80810+++ b/init/do_mounts_md.c
80811@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
80812 partitioned ? "_d" : "", minor,
80813 md_setup_args[ent].device_names);
80814
80815- fd = sys_open(name, 0, 0);
80816+ fd = sys_open((char __force_user *)name, 0, 0);
80817 if (fd < 0) {
80818 printk(KERN_ERR "md: open failed - cannot start "
80819 "array %s\n", name);
80820@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
80821 * array without it
80822 */
80823 sys_close(fd);
80824- fd = sys_open(name, 0, 0);
80825+ fd = sys_open((char __force_user *)name, 0, 0);
80826 sys_ioctl(fd, BLKRRPART, 0);
80827 }
80828 sys_close(fd);
80829@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
80830
80831 wait_for_device_probe();
80832
80833- fd = sys_open("/dev/md0", 0, 0);
80834+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
80835 if (fd >= 0) {
80836 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
80837 sys_close(fd);
80838diff --git a/init/init_task.c b/init/init_task.c
80839index ba0a7f36..2bcf1d5 100644
80840--- a/init/init_task.c
80841+++ b/init/init_task.c
80842@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
80843 * Initial thread structure. Alignment of this is handled by a special
80844 * linker map entry.
80845 */
80846+#ifdef CONFIG_X86
80847+union thread_union init_thread_union __init_task_data;
80848+#else
80849 union thread_union init_thread_union __init_task_data =
80850 { INIT_THREAD_INFO(init_task) };
80851+#endif
80852diff --git a/init/initramfs.c b/init/initramfs.c
80853index a67ef9d..2d17ed9 100644
80854--- a/init/initramfs.c
80855+++ b/init/initramfs.c
80856@@ -84,7 +84,7 @@ static void __init free_hash(void)
80857 }
80858 }
80859
80860-static long __init do_utime(char *filename, time_t mtime)
80861+static long __init do_utime(char __force_user *filename, time_t mtime)
80862 {
80863 struct timespec t[2];
80864
80865@@ -119,7 +119,7 @@ static void __init dir_utime(void)
80866 struct dir_entry *de, *tmp;
80867 list_for_each_entry_safe(de, tmp, &dir_list, list) {
80868 list_del(&de->list);
80869- do_utime(de->name, de->mtime);
80870+ do_utime((char __force_user *)de->name, de->mtime);
80871 kfree(de->name);
80872 kfree(de);
80873 }
80874@@ -281,7 +281,7 @@ static int __init maybe_link(void)
80875 if (nlink >= 2) {
80876 char *old = find_link(major, minor, ino, mode, collected);
80877 if (old)
80878- return (sys_link(old, collected) < 0) ? -1 : 1;
80879+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
80880 }
80881 return 0;
80882 }
80883@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
80884 {
80885 struct stat st;
80886
80887- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
80888+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
80889 if (S_ISDIR(st.st_mode))
80890- sys_rmdir(path);
80891+ sys_rmdir((char __force_user *)path);
80892 else
80893- sys_unlink(path);
80894+ sys_unlink((char __force_user *)path);
80895 }
80896 }
80897
80898@@ -315,7 +315,7 @@ static int __init do_name(void)
80899 int openflags = O_WRONLY|O_CREAT;
80900 if (ml != 1)
80901 openflags |= O_TRUNC;
80902- wfd = sys_open(collected, openflags, mode);
80903+ wfd = sys_open((char __force_user *)collected, openflags, mode);
80904
80905 if (wfd >= 0) {
80906 sys_fchown(wfd, uid, gid);
80907@@ -327,17 +327,17 @@ static int __init do_name(void)
80908 }
80909 }
80910 } else if (S_ISDIR(mode)) {
80911- sys_mkdir(collected, mode);
80912- sys_chown(collected, uid, gid);
80913- sys_chmod(collected, mode);
80914+ sys_mkdir((char __force_user *)collected, mode);
80915+ sys_chown((char __force_user *)collected, uid, gid);
80916+ sys_chmod((char __force_user *)collected, mode);
80917 dir_add(collected, mtime);
80918 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
80919 S_ISFIFO(mode) || S_ISSOCK(mode)) {
80920 if (maybe_link() == 0) {
80921- sys_mknod(collected, mode, rdev);
80922- sys_chown(collected, uid, gid);
80923- sys_chmod(collected, mode);
80924- do_utime(collected, mtime);
80925+ sys_mknod((char __force_user *)collected, mode, rdev);
80926+ sys_chown((char __force_user *)collected, uid, gid);
80927+ sys_chmod((char __force_user *)collected, mode);
80928+ do_utime((char __force_user *)collected, mtime);
80929 }
80930 }
80931 return 0;
80932@@ -346,15 +346,15 @@ static int __init do_name(void)
80933 static int __init do_copy(void)
80934 {
80935 if (count >= body_len) {
80936- sys_write(wfd, victim, body_len);
80937+ sys_write(wfd, (char __force_user *)victim, body_len);
80938 sys_close(wfd);
80939- do_utime(vcollected, mtime);
80940+ do_utime((char __force_user *)vcollected, mtime);
80941 kfree(vcollected);
80942 eat(body_len);
80943 state = SkipIt;
80944 return 0;
80945 } else {
80946- sys_write(wfd, victim, count);
80947+ sys_write(wfd, (char __force_user *)victim, count);
80948 body_len -= count;
80949 eat(count);
80950 return 1;
80951@@ -365,9 +365,9 @@ static int __init do_symlink(void)
80952 {
80953 collected[N_ALIGN(name_len) + body_len] = '\0';
80954 clean_path(collected, 0);
80955- sys_symlink(collected + N_ALIGN(name_len), collected);
80956- sys_lchown(collected, uid, gid);
80957- do_utime(collected, mtime);
80958+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
80959+ sys_lchown((char __force_user *)collected, uid, gid);
80960+ do_utime((char __force_user *)collected, mtime);
80961 state = SkipIt;
80962 next_state = Reset;
80963 return 0;
80964@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
80965 {
80966 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
80967 if (err)
80968- panic(err); /* Failed to decompress INTERNAL initramfs */
80969+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
80970 if (initrd_start) {
80971 #ifdef CONFIG_BLK_DEV_RAM
80972 int fd;
80973diff --git a/init/main.c b/init/main.c
80974index 63d3e8f..50bd5f8 100644
80975--- a/init/main.c
80976+++ b/init/main.c
80977@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
80978 extern void tc_init(void);
80979 #endif
80980
80981+extern void grsecurity_init(void);
80982+
80983 /*
80984 * Debug helper: via this flag we know that we are in 'early bootup code'
80985 * where only the boot processor is running with IRQ disabled. This means
80986@@ -156,6 +158,75 @@ static int __init set_reset_devices(char *str)
80987
80988 __setup("reset_devices", set_reset_devices);
80989
80990+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80991+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
80992+static int __init setup_grsec_proc_gid(char *str)
80993+{
80994+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
80995+ return 1;
80996+}
80997+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
80998+#endif
80999+
81000+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
81001+unsigned long pax_user_shadow_base __read_only;
81002+EXPORT_SYMBOL(pax_user_shadow_base);
81003+extern char pax_enter_kernel_user[];
81004+extern char pax_exit_kernel_user[];
81005+#endif
81006+
81007+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
81008+static int __init setup_pax_nouderef(char *str)
81009+{
81010+#ifdef CONFIG_X86_32
81011+ unsigned int cpu;
81012+ struct desc_struct *gdt;
81013+
81014+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
81015+ gdt = get_cpu_gdt_table(cpu);
81016+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
81017+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
81018+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
81019+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
81020+ }
81021+ loadsegment(ds, __KERNEL_DS);
81022+ loadsegment(es, __KERNEL_DS);
81023+ loadsegment(ss, __KERNEL_DS);
81024+#else
81025+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
81026+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
81027+ clone_pgd_mask = ~(pgdval_t)0UL;
81028+ pax_user_shadow_base = 0UL;
81029+ setup_clear_cpu_cap(X86_FEATURE_PCID);
81030+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
81031+#endif
81032+
81033+ return 0;
81034+}
81035+early_param("pax_nouderef", setup_pax_nouderef);
81036+
81037+#ifdef CONFIG_X86_64
81038+static int __init setup_pax_weakuderef(char *str)
81039+{
81040+ if (clone_pgd_mask != ~(pgdval_t)0UL)
81041+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
81042+ return 1;
81043+}
81044+__setup("pax_weakuderef", setup_pax_weakuderef);
81045+#endif
81046+#endif
81047+
81048+#ifdef CONFIG_PAX_SOFTMODE
81049+int pax_softmode;
81050+
81051+static int __init setup_pax_softmode(char *str)
81052+{
81053+ get_option(&str, &pax_softmode);
81054+ return 1;
81055+}
81056+__setup("pax_softmode=", setup_pax_softmode);
81057+#endif
81058+
81059 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
81060 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
81061 static const char *panic_later, *panic_param;
81062@@ -682,25 +753,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
81063 {
81064 int count = preempt_count();
81065 int ret;
81066- char msgbuf[64];
81067+ const char *msg1 = "", *msg2 = "";
81068
81069 if (initcall_debug)
81070 ret = do_one_initcall_debug(fn);
81071 else
81072 ret = fn();
81073
81074- msgbuf[0] = 0;
81075-
81076 if (preempt_count() != count) {
81077- sprintf(msgbuf, "preemption imbalance ");
81078+ msg1 = " preemption imbalance";
81079 preempt_count() = count;
81080 }
81081 if (irqs_disabled()) {
81082- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
81083+ msg2 = " disabled interrupts";
81084 local_irq_enable();
81085 }
81086- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
81087+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
81088
81089+ add_latent_entropy();
81090 return ret;
81091 }
81092
81093@@ -807,10 +877,14 @@ static int run_init_process(const char *init_filename)
81094 {
81095 argv_init[0] = init_filename;
81096 return do_execve(init_filename,
81097- (const char __user *const __user *)argv_init,
81098- (const char __user *const __user *)envp_init);
81099+ (const char __user *const __force_user *)argv_init,
81100+ (const char __user *const __force_user *)envp_init);
81101 }
81102
81103+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
81104+extern int gr_init_ran;
81105+#endif
81106+
81107 static noinline void __init kernel_init_freeable(void);
81108
81109 static int __ref kernel_init(void *unused)
81110@@ -831,6 +905,11 @@ static int __ref kernel_init(void *unused)
81111 pr_err("Failed to execute %s\n", ramdisk_execute_command);
81112 }
81113
81114+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
81115+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
81116+ gr_init_ran = 1;
81117+#endif
81118+
81119 /*
81120 * We try each of these until one succeeds.
81121 *
81122@@ -885,7 +964,7 @@ static noinline void __init kernel_init_freeable(void)
81123 do_basic_setup();
81124
81125 /* Open the /dev/console on the rootfs, this should never fail */
81126- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
81127+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
81128 pr_err("Warning: unable to open an initial console.\n");
81129
81130 (void) sys_dup(0);
81131@@ -898,11 +977,13 @@ static noinline void __init kernel_init_freeable(void)
81132 if (!ramdisk_execute_command)
81133 ramdisk_execute_command = "/init";
81134
81135- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
81136+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
81137 ramdisk_execute_command = NULL;
81138 prepare_namespace();
81139 }
81140
81141+ grsecurity_init();
81142+
81143 /*
81144 * Ok, we have completed the initial bootup, and
81145 * we're essentially up and running. Get rid of the
81146diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
81147index b0e99de..09f385c 100644
81148--- a/ipc/ipc_sysctl.c
81149+++ b/ipc/ipc_sysctl.c
81150@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
81151 static int proc_ipc_dointvec(ctl_table *table, int write,
81152 void __user *buffer, size_t *lenp, loff_t *ppos)
81153 {
81154- struct ctl_table ipc_table;
81155+ ctl_table_no_const ipc_table;
81156
81157 memcpy(&ipc_table, table, sizeof(ipc_table));
81158 ipc_table.data = get_ipc(table);
81159@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
81160 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
81161 void __user *buffer, size_t *lenp, loff_t *ppos)
81162 {
81163- struct ctl_table ipc_table;
81164+ ctl_table_no_const ipc_table;
81165
81166 memcpy(&ipc_table, table, sizeof(ipc_table));
81167 ipc_table.data = get_ipc(table);
81168@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
81169 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
81170 void __user *buffer, size_t *lenp, loff_t *ppos)
81171 {
81172- struct ctl_table ipc_table;
81173+ ctl_table_no_const ipc_table;
81174 size_t lenp_bef = *lenp;
81175 int rc;
81176
81177@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
81178 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
81179 void __user *buffer, size_t *lenp, loff_t *ppos)
81180 {
81181- struct ctl_table ipc_table;
81182+ ctl_table_no_const ipc_table;
81183 memcpy(&ipc_table, table, sizeof(ipc_table));
81184 ipc_table.data = get_ipc(table);
81185
81186@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
81187 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
81188 void __user *buffer, size_t *lenp, loff_t *ppos)
81189 {
81190- struct ctl_table ipc_table;
81191+ ctl_table_no_const ipc_table;
81192 size_t lenp_bef = *lenp;
81193 int oldval;
81194 int rc;
81195diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
81196index 383d638..943fdbb 100644
81197--- a/ipc/mq_sysctl.c
81198+++ b/ipc/mq_sysctl.c
81199@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
81200 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
81201 void __user *buffer, size_t *lenp, loff_t *ppos)
81202 {
81203- struct ctl_table mq_table;
81204+ ctl_table_no_const mq_table;
81205 memcpy(&mq_table, table, sizeof(mq_table));
81206 mq_table.data = get_mq(table);
81207
81208diff --git a/ipc/mqueue.c b/ipc/mqueue.c
81209index ae1996d..a35f2cc 100644
81210--- a/ipc/mqueue.c
81211+++ b/ipc/mqueue.c
81212@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
81213 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
81214 info->attr.mq_msgsize);
81215
81216+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
81217 spin_lock(&mq_lock);
81218 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
81219 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
81220diff --git a/ipc/msg.c b/ipc/msg.c
81221index 558aa91..359e718 100644
81222--- a/ipc/msg.c
81223+++ b/ipc/msg.c
81224@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
81225 return security_msg_queue_associate(msq, msgflg);
81226 }
81227
81228+static struct ipc_ops msg_ops = {
81229+ .getnew = newque,
81230+ .associate = msg_security,
81231+ .more_checks = NULL
81232+};
81233+
81234 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
81235 {
81236 struct ipc_namespace *ns;
81237- struct ipc_ops msg_ops;
81238 struct ipc_params msg_params;
81239
81240 ns = current->nsproxy->ipc_ns;
81241
81242- msg_ops.getnew = newque;
81243- msg_ops.associate = msg_security;
81244- msg_ops.more_checks = NULL;
81245-
81246 msg_params.key = key;
81247 msg_params.flg = msgflg;
81248
81249diff --git a/ipc/sem.c b/ipc/sem.c
81250index db9d241..bc8427c 100644
81251--- a/ipc/sem.c
81252+++ b/ipc/sem.c
81253@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
81254 return 0;
81255 }
81256
81257+static struct ipc_ops sem_ops = {
81258+ .getnew = newary,
81259+ .associate = sem_security,
81260+ .more_checks = sem_more_checks
81261+};
81262+
81263 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
81264 {
81265 struct ipc_namespace *ns;
81266- struct ipc_ops sem_ops;
81267 struct ipc_params sem_params;
81268
81269 ns = current->nsproxy->ipc_ns;
81270@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
81271 if (nsems < 0 || nsems > ns->sc_semmsl)
81272 return -EINVAL;
81273
81274- sem_ops.getnew = newary;
81275- sem_ops.associate = sem_security;
81276- sem_ops.more_checks = sem_more_checks;
81277-
81278 sem_params.key = key;
81279 sem_params.flg = semflg;
81280 sem_params.u.nsems = nsems;
81281diff --git a/ipc/shm.c b/ipc/shm.c
81282index 7a51443..3a257d8 100644
81283--- a/ipc/shm.c
81284+++ b/ipc/shm.c
81285@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
81286 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
81287 #endif
81288
81289+#ifdef CONFIG_GRKERNSEC
81290+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
81291+ const time_t shm_createtime, const kuid_t cuid,
81292+ const int shmid);
81293+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
81294+ const time_t shm_createtime);
81295+#endif
81296+
81297 void shm_init_ns(struct ipc_namespace *ns)
81298 {
81299 ns->shm_ctlmax = SHMMAX;
81300@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
81301 shp->shm_lprid = 0;
81302 shp->shm_atim = shp->shm_dtim = 0;
81303 shp->shm_ctim = get_seconds();
81304+#ifdef CONFIG_GRKERNSEC
81305+ {
81306+ struct timespec timeval;
81307+ do_posix_clock_monotonic_gettime(&timeval);
81308+
81309+ shp->shm_createtime = timeval.tv_sec;
81310+ }
81311+#endif
81312 shp->shm_segsz = size;
81313 shp->shm_nattch = 0;
81314 shp->shm_file = file;
81315@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
81316 return 0;
81317 }
81318
81319+static struct ipc_ops shm_ops = {
81320+ .getnew = newseg,
81321+ .associate = shm_security,
81322+ .more_checks = shm_more_checks
81323+};
81324+
81325 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
81326 {
81327 struct ipc_namespace *ns;
81328- struct ipc_ops shm_ops;
81329 struct ipc_params shm_params;
81330
81331 ns = current->nsproxy->ipc_ns;
81332
81333- shm_ops.getnew = newseg;
81334- shm_ops.associate = shm_security;
81335- shm_ops.more_checks = shm_more_checks;
81336-
81337 shm_params.key = key;
81338 shm_params.flg = shmflg;
81339 shm_params.u.size = size;
81340@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81341 f_mode = FMODE_READ | FMODE_WRITE;
81342 }
81343 if (shmflg & SHM_EXEC) {
81344+
81345+#ifdef CONFIG_PAX_MPROTECT
81346+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
81347+ goto out;
81348+#endif
81349+
81350 prot |= PROT_EXEC;
81351 acc_mode |= S_IXUGO;
81352 }
81353@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81354 if (err)
81355 goto out_unlock;
81356
81357+#ifdef CONFIG_GRKERNSEC
81358+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
81359+ shp->shm_perm.cuid, shmid) ||
81360+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
81361+ err = -EACCES;
81362+ goto out_unlock;
81363+ }
81364+#endif
81365+
81366 ipc_lock_object(&shp->shm_perm);
81367
81368 /* check if shm_destroy() is tearing down shp */
81369@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
81370 path = shp->shm_file->f_path;
81371 path_get(&path);
81372 shp->shm_nattch++;
81373+#ifdef CONFIG_GRKERNSEC
81374+ shp->shm_lapid = current->pid;
81375+#endif
81376 size = i_size_read(path.dentry->d_inode);
81377 ipc_unlock_object(&shp->shm_perm);
81378 rcu_read_unlock();
81379diff --git a/ipc/util.c b/ipc/util.c
81380index 7684f41..f7da711 100644
81381--- a/ipc/util.c
81382+++ b/ipc/util.c
81383@@ -71,6 +71,8 @@ struct ipc_proc_iface {
81384 int (*show)(struct seq_file *, void *);
81385 };
81386
81387+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
81388+
81389 static void ipc_memory_notifier(struct work_struct *work)
81390 {
81391 ipcns_notify(IPCNS_MEMCHANGED);
81392@@ -560,6 +562,9 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
81393 granted_mode >>= 6;
81394 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
81395 granted_mode >>= 3;
81396+ else if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
81397+ return -1;
81398+
81399 /* is there some bit set in requested_mode but not in granted_mode? */
81400 if ((requested_mode & ~granted_mode & 0007) &&
81401 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
81402diff --git a/kernel/acct.c b/kernel/acct.c
81403index 8d6e145..33e0b1e 100644
81404--- a/kernel/acct.c
81405+++ b/kernel/acct.c
81406@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
81407 */
81408 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
81409 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
81410- file->f_op->write(file, (char *)&ac,
81411+ file->f_op->write(file, (char __force_user *)&ac,
81412 sizeof(acct_t), &file->f_pos);
81413 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
81414 set_fs(fs);
81415diff --git a/kernel/audit.c b/kernel/audit.c
81416index 7ddfd8a..49766eb 100644
81417--- a/kernel/audit.c
81418+++ b/kernel/audit.c
81419@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
81420 3) suppressed due to audit_rate_limit
81421 4) suppressed due to audit_backlog_limit
81422 */
81423-static atomic_t audit_lost = ATOMIC_INIT(0);
81424+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
81425
81426 /* The netlink socket. */
81427 static struct sock *audit_sock;
81428@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
81429 unsigned long now;
81430 int print;
81431
81432- atomic_inc(&audit_lost);
81433+ atomic_inc_unchecked(&audit_lost);
81434
81435 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
81436
81437@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
81438 printk(KERN_WARNING
81439 "audit: audit_lost=%d audit_rate_limit=%d "
81440 "audit_backlog_limit=%d\n",
81441- atomic_read(&audit_lost),
81442+ atomic_read_unchecked(&audit_lost),
81443 audit_rate_limit,
81444 audit_backlog_limit);
81445 audit_panic(message);
81446@@ -665,7 +665,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
81447 status_set.pid = audit_pid;
81448 status_set.rate_limit = audit_rate_limit;
81449 status_set.backlog_limit = audit_backlog_limit;
81450- status_set.lost = atomic_read(&audit_lost);
81451+ status_set.lost = atomic_read_unchecked(&audit_lost);
81452 status_set.backlog = skb_queue_len(&audit_skb_queue);
81453 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
81454 &status_set, sizeof(status_set));
81455@@ -1252,7 +1252,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
81456 int i, avail, new_len;
81457 unsigned char *ptr;
81458 struct sk_buff *skb;
81459- static const unsigned char *hex = "0123456789ABCDEF";
81460+ static const unsigned char hex[] = "0123456789ABCDEF";
81461
81462 if (!ab)
81463 return;
81464diff --git a/kernel/auditsc.c b/kernel/auditsc.c
81465index 9845cb3..3ec9369 100644
81466--- a/kernel/auditsc.c
81467+++ b/kernel/auditsc.c
81468@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
81469 }
81470
81471 /* global counter which is incremented every time something logs in */
81472-static atomic_t session_id = ATOMIC_INIT(0);
81473+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
81474
81475 /**
81476 * audit_set_loginuid - set current task's audit_context loginuid
81477@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
81478 return -EPERM;
81479 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
81480
81481- sessionid = atomic_inc_return(&session_id);
81482+ sessionid = atomic_inc_return_unchecked(&session_id);
81483 if (context && context->in_syscall) {
81484 struct audit_buffer *ab;
81485
81486diff --git a/kernel/capability.c b/kernel/capability.c
81487index 4e66bf9..cdccecf 100644
81488--- a/kernel/capability.c
81489+++ b/kernel/capability.c
81490@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
81491 * before modification is attempted and the application
81492 * fails.
81493 */
81494+ if (tocopy > ARRAY_SIZE(kdata))
81495+ return -EFAULT;
81496+
81497 if (copy_to_user(dataptr, kdata, tocopy
81498 * sizeof(struct __user_cap_data_struct))) {
81499 return -EFAULT;
81500@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
81501 int ret;
81502
81503 rcu_read_lock();
81504- ret = security_capable(__task_cred(t), ns, cap);
81505+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
81506+ gr_task_is_capable(t, __task_cred(t), cap);
81507 rcu_read_unlock();
81508
81509- return (ret == 0);
81510+ return ret;
81511 }
81512
81513 /**
81514@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
81515 int ret;
81516
81517 rcu_read_lock();
81518- ret = security_capable_noaudit(__task_cred(t), ns, cap);
81519+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
81520 rcu_read_unlock();
81521
81522- return (ret == 0);
81523+ return ret;
81524 }
81525
81526 /**
81527@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
81528 BUG();
81529 }
81530
81531- if (security_capable(current_cred(), ns, cap) == 0) {
81532+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
81533 current->flags |= PF_SUPERPRIV;
81534 return true;
81535 }
81536@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
81537 }
81538 EXPORT_SYMBOL(ns_capable);
81539
81540+bool ns_capable_nolog(struct user_namespace *ns, int cap)
81541+{
81542+ if (unlikely(!cap_valid(cap))) {
81543+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
81544+ BUG();
81545+ }
81546+
81547+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
81548+ current->flags |= PF_SUPERPRIV;
81549+ return true;
81550+ }
81551+ return false;
81552+}
81553+EXPORT_SYMBOL(ns_capable_nolog);
81554+
81555 /**
81556 * file_ns_capable - Determine if the file's opener had a capability in effect
81557 * @file: The file we want to check
81558@@ -432,6 +451,12 @@ bool capable(int cap)
81559 }
81560 EXPORT_SYMBOL(capable);
81561
81562+bool capable_nolog(int cap)
81563+{
81564+ return ns_capable_nolog(&init_user_ns, cap);
81565+}
81566+EXPORT_SYMBOL(capable_nolog);
81567+
81568 /**
81569 * inode_capable - Check superior capability over inode
81570 * @inode: The inode in question
81571@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
81572 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
81573 }
81574 EXPORT_SYMBOL(inode_capable);
81575+
81576+bool inode_capable_nolog(const struct inode *inode, int cap)
81577+{
81578+ struct user_namespace *ns = current_user_ns();
81579+
81580+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
81581+}
81582+EXPORT_SYMBOL(inode_capable_nolog);
81583diff --git a/kernel/cgroup.c b/kernel/cgroup.c
81584index 5c9127d..f871169 100644
81585--- a/kernel/cgroup.c
81586+++ b/kernel/cgroup.c
81587@@ -5844,7 +5844,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
81588 struct css_set *cset = link->cset;
81589 struct task_struct *task;
81590 int count = 0;
81591- seq_printf(seq, "css_set %p\n", cset);
81592+ seq_printf(seq, "css_set %pK\n", cset);
81593 list_for_each_entry(task, &cset->tasks, cg_list) {
81594 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
81595 seq_puts(seq, " ...\n");
81596diff --git a/kernel/compat.c b/kernel/compat.c
81597index 0a09e48..f44f3f0 100644
81598--- a/kernel/compat.c
81599+++ b/kernel/compat.c
81600@@ -13,6 +13,7 @@
81601
81602 #include <linux/linkage.h>
81603 #include <linux/compat.h>
81604+#include <linux/module.h>
81605 #include <linux/errno.h>
81606 #include <linux/time.h>
81607 #include <linux/signal.h>
81608@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
81609 mm_segment_t oldfs;
81610 long ret;
81611
81612- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
81613+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
81614 oldfs = get_fs();
81615 set_fs(KERNEL_DS);
81616 ret = hrtimer_nanosleep_restart(restart);
81617@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
81618 oldfs = get_fs();
81619 set_fs(KERNEL_DS);
81620 ret = hrtimer_nanosleep(&tu,
81621- rmtp ? (struct timespec __user *)&rmt : NULL,
81622+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
81623 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
81624 set_fs(oldfs);
81625
81626@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
81627 mm_segment_t old_fs = get_fs();
81628
81629 set_fs(KERNEL_DS);
81630- ret = sys_sigpending((old_sigset_t __user *) &s);
81631+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
81632 set_fs(old_fs);
81633 if (ret == 0)
81634 ret = put_user(s, set);
81635@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
81636 mm_segment_t old_fs = get_fs();
81637
81638 set_fs(KERNEL_DS);
81639- ret = sys_old_getrlimit(resource, &r);
81640+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
81641 set_fs(old_fs);
81642
81643 if (!ret) {
81644@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
81645 set_fs (KERNEL_DS);
81646 ret = sys_wait4(pid,
81647 (stat_addr ?
81648- (unsigned int __user *) &status : NULL),
81649- options, (struct rusage __user *) &r);
81650+ (unsigned int __force_user *) &status : NULL),
81651+ options, (struct rusage __force_user *) &r);
81652 set_fs (old_fs);
81653
81654 if (ret > 0) {
81655@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
81656 memset(&info, 0, sizeof(info));
81657
81658 set_fs(KERNEL_DS);
81659- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
81660- uru ? (struct rusage __user *)&ru : NULL);
81661+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
81662+ uru ? (struct rusage __force_user *)&ru : NULL);
81663 set_fs(old_fs);
81664
81665 if ((ret < 0) || (info.si_signo == 0))
81666@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
81667 oldfs = get_fs();
81668 set_fs(KERNEL_DS);
81669 err = sys_timer_settime(timer_id, flags,
81670- (struct itimerspec __user *) &newts,
81671- (struct itimerspec __user *) &oldts);
81672+ (struct itimerspec __force_user *) &newts,
81673+ (struct itimerspec __force_user *) &oldts);
81674 set_fs(oldfs);
81675 if (!err && old && put_compat_itimerspec(old, &oldts))
81676 return -EFAULT;
81677@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
81678 oldfs = get_fs();
81679 set_fs(KERNEL_DS);
81680 err = sys_timer_gettime(timer_id,
81681- (struct itimerspec __user *) &ts);
81682+ (struct itimerspec __force_user *) &ts);
81683 set_fs(oldfs);
81684 if (!err && put_compat_itimerspec(setting, &ts))
81685 return -EFAULT;
81686@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
81687 oldfs = get_fs();
81688 set_fs(KERNEL_DS);
81689 err = sys_clock_settime(which_clock,
81690- (struct timespec __user *) &ts);
81691+ (struct timespec __force_user *) &ts);
81692 set_fs(oldfs);
81693 return err;
81694 }
81695@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
81696 oldfs = get_fs();
81697 set_fs(KERNEL_DS);
81698 err = sys_clock_gettime(which_clock,
81699- (struct timespec __user *) &ts);
81700+ (struct timespec __force_user *) &ts);
81701 set_fs(oldfs);
81702 if (!err && put_compat_timespec(&ts, tp))
81703 return -EFAULT;
81704@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
81705
81706 oldfs = get_fs();
81707 set_fs(KERNEL_DS);
81708- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
81709+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
81710 set_fs(oldfs);
81711
81712 err = compat_put_timex(utp, &txc);
81713@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
81714 oldfs = get_fs();
81715 set_fs(KERNEL_DS);
81716 err = sys_clock_getres(which_clock,
81717- (struct timespec __user *) &ts);
81718+ (struct timespec __force_user *) &ts);
81719 set_fs(oldfs);
81720 if (!err && tp && put_compat_timespec(&ts, tp))
81721 return -EFAULT;
81722@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
81723 long err;
81724 mm_segment_t oldfs;
81725 struct timespec tu;
81726- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
81727+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
81728
81729- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
81730+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
81731 oldfs = get_fs();
81732 set_fs(KERNEL_DS);
81733 err = clock_nanosleep_restart(restart);
81734@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
81735 oldfs = get_fs();
81736 set_fs(KERNEL_DS);
81737 err = sys_clock_nanosleep(which_clock, flags,
81738- (struct timespec __user *) &in,
81739- (struct timespec __user *) &out);
81740+ (struct timespec __force_user *) &in,
81741+ (struct timespec __force_user *) &out);
81742 set_fs(oldfs);
81743
81744 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
81745diff --git a/kernel/configs.c b/kernel/configs.c
81746index c18b1f1..b9a0132 100644
81747--- a/kernel/configs.c
81748+++ b/kernel/configs.c
81749@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
81750 struct proc_dir_entry *entry;
81751
81752 /* create the current config file */
81753+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
81754+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
81755+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
81756+ &ikconfig_file_ops);
81757+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81758+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
81759+ &ikconfig_file_ops);
81760+#endif
81761+#else
81762 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
81763 &ikconfig_file_ops);
81764+#endif
81765+
81766 if (!entry)
81767 return -ENOMEM;
81768
81769diff --git a/kernel/cred.c b/kernel/cred.c
81770index e0573a4..3874e41 100644
81771--- a/kernel/cred.c
81772+++ b/kernel/cred.c
81773@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
81774 validate_creds(cred);
81775 alter_cred_subscribers(cred, -1);
81776 put_cred(cred);
81777+
81778+#ifdef CONFIG_GRKERNSEC_SETXID
81779+ cred = (struct cred *) tsk->delayed_cred;
81780+ if (cred != NULL) {
81781+ tsk->delayed_cred = NULL;
81782+ validate_creds(cred);
81783+ alter_cred_subscribers(cred, -1);
81784+ put_cred(cred);
81785+ }
81786+#endif
81787 }
81788
81789 /**
81790@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
81791 * Always returns 0 thus allowing this function to be tail-called at the end
81792 * of, say, sys_setgid().
81793 */
81794-int commit_creds(struct cred *new)
81795+static int __commit_creds(struct cred *new)
81796 {
81797 struct task_struct *task = current;
81798 const struct cred *old = task->real_cred;
81799@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
81800
81801 get_cred(new); /* we will require a ref for the subj creds too */
81802
81803+ gr_set_role_label(task, new->uid, new->gid);
81804+
81805 /* dumpability changes */
81806 if (!uid_eq(old->euid, new->euid) ||
81807 !gid_eq(old->egid, new->egid) ||
81808@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
81809 put_cred(old);
81810 return 0;
81811 }
81812+#ifdef CONFIG_GRKERNSEC_SETXID
81813+extern int set_user(struct cred *new);
81814+
81815+void gr_delayed_cred_worker(void)
81816+{
81817+ const struct cred *new = current->delayed_cred;
81818+ struct cred *ncred;
81819+
81820+ current->delayed_cred = NULL;
81821+
81822+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
81823+ // from doing get_cred on it when queueing this
81824+ put_cred(new);
81825+ return;
81826+ } else if (new == NULL)
81827+ return;
81828+
81829+ ncred = prepare_creds();
81830+ if (!ncred)
81831+ goto die;
81832+ // uids
81833+ ncred->uid = new->uid;
81834+ ncred->euid = new->euid;
81835+ ncred->suid = new->suid;
81836+ ncred->fsuid = new->fsuid;
81837+ // gids
81838+ ncred->gid = new->gid;
81839+ ncred->egid = new->egid;
81840+ ncred->sgid = new->sgid;
81841+ ncred->fsgid = new->fsgid;
81842+ // groups
81843+ if (set_groups(ncred, new->group_info) < 0) {
81844+ abort_creds(ncred);
81845+ goto die;
81846+ }
81847+ // caps
81848+ ncred->securebits = new->securebits;
81849+ ncred->cap_inheritable = new->cap_inheritable;
81850+ ncred->cap_permitted = new->cap_permitted;
81851+ ncred->cap_effective = new->cap_effective;
81852+ ncred->cap_bset = new->cap_bset;
81853+
81854+ if (set_user(ncred)) {
81855+ abort_creds(ncred);
81856+ goto die;
81857+ }
81858+
81859+ // from doing get_cred on it when queueing this
81860+ put_cred(new);
81861+
81862+ __commit_creds(ncred);
81863+ return;
81864+die:
81865+ // from doing get_cred on it when queueing this
81866+ put_cred(new);
81867+ do_group_exit(SIGKILL);
81868+}
81869+#endif
81870+
81871+int commit_creds(struct cred *new)
81872+{
81873+#ifdef CONFIG_GRKERNSEC_SETXID
81874+ int ret;
81875+ int schedule_it = 0;
81876+ struct task_struct *t;
81877+
81878+ /* we won't get called with tasklist_lock held for writing
81879+ and interrupts disabled as the cred struct in that case is
81880+ init_cred
81881+ */
81882+ if (grsec_enable_setxid && !current_is_single_threaded() &&
81883+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
81884+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
81885+ schedule_it = 1;
81886+ }
81887+ ret = __commit_creds(new);
81888+ if (schedule_it) {
81889+ rcu_read_lock();
81890+ read_lock(&tasklist_lock);
81891+ for (t = next_thread(current); t != current;
81892+ t = next_thread(t)) {
81893+ if (t->delayed_cred == NULL) {
81894+ t->delayed_cred = get_cred(new);
81895+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
81896+ set_tsk_need_resched(t);
81897+ }
81898+ }
81899+ read_unlock(&tasklist_lock);
81900+ rcu_read_unlock();
81901+ }
81902+ return ret;
81903+#else
81904+ return __commit_creds(new);
81905+#endif
81906+}
81907+
81908 EXPORT_SYMBOL(commit_creds);
81909
81910 /**
81911diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
81912index 0506d44..2c20034 100644
81913--- a/kernel/debug/debug_core.c
81914+++ b/kernel/debug/debug_core.c
81915@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
81916 */
81917 static atomic_t masters_in_kgdb;
81918 static atomic_t slaves_in_kgdb;
81919-static atomic_t kgdb_break_tasklet_var;
81920+static atomic_unchecked_t kgdb_break_tasklet_var;
81921 atomic_t kgdb_setting_breakpoint;
81922
81923 struct task_struct *kgdb_usethread;
81924@@ -133,7 +133,7 @@ int kgdb_single_step;
81925 static pid_t kgdb_sstep_pid;
81926
81927 /* to keep track of the CPU which is doing the single stepping*/
81928-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81929+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81930
81931 /*
81932 * If you are debugging a problem where roundup (the collection of
81933@@ -541,7 +541,7 @@ return_normal:
81934 * kernel will only try for the value of sstep_tries before
81935 * giving up and continuing on.
81936 */
81937- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
81938+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
81939 (kgdb_info[cpu].task &&
81940 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
81941 atomic_set(&kgdb_active, -1);
81942@@ -635,8 +635,8 @@ cpu_master_loop:
81943 }
81944
81945 kgdb_restore:
81946- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
81947- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
81948+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
81949+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
81950 if (kgdb_info[sstep_cpu].task)
81951 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
81952 else
81953@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
81954 static void kgdb_tasklet_bpt(unsigned long ing)
81955 {
81956 kgdb_breakpoint();
81957- atomic_set(&kgdb_break_tasklet_var, 0);
81958+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
81959 }
81960
81961 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
81962
81963 void kgdb_schedule_breakpoint(void)
81964 {
81965- if (atomic_read(&kgdb_break_tasklet_var) ||
81966+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
81967 atomic_read(&kgdb_active) != -1 ||
81968 atomic_read(&kgdb_setting_breakpoint))
81969 return;
81970- atomic_inc(&kgdb_break_tasklet_var);
81971+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
81972 tasklet_schedule(&kgdb_tasklet_breakpoint);
81973 }
81974 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
81975diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
81976index 00eb8f7..d7e3244 100644
81977--- a/kernel/debug/kdb/kdb_main.c
81978+++ b/kernel/debug/kdb/kdb_main.c
81979@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
81980 continue;
81981
81982 kdb_printf("%-20s%8u 0x%p ", mod->name,
81983- mod->core_size, (void *)mod);
81984+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
81985 #ifdef CONFIG_MODULE_UNLOAD
81986 kdb_printf("%4ld ", module_refcount(mod));
81987 #endif
81988@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
81989 kdb_printf(" (Loading)");
81990 else
81991 kdb_printf(" (Live)");
81992- kdb_printf(" 0x%p", mod->module_core);
81993+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
81994
81995 #ifdef CONFIG_MODULE_UNLOAD
81996 {
81997diff --git a/kernel/events/core.c b/kernel/events/core.c
81998index 953c143..5646bb1 100644
81999--- a/kernel/events/core.c
82000+++ b/kernel/events/core.c
82001@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
82002 * 0 - disallow raw tracepoint access for unpriv
82003 * 1 - disallow cpu events for unpriv
82004 * 2 - disallow kernel profiling for unpriv
82005+ * 3 - disallow all unpriv perf event use
82006 */
82007-int sysctl_perf_event_paranoid __read_mostly = 1;
82008+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
82009+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
82010+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
82011+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
82012+#else
82013+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
82014+#endif
82015
82016 /* Minimum for 512 kiB + 1 user control page */
82017 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
82018@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
82019 update_perf_cpu_limits();
82020 }
82021
82022-static atomic64_t perf_event_id;
82023+static atomic64_unchecked_t perf_event_id;
82024
82025 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
82026 enum event_type_t event_type);
82027@@ -2940,7 +2947,7 @@ static void __perf_event_read(void *info)
82028
82029 static inline u64 perf_event_count(struct perf_event *event)
82030 {
82031- return local64_read(&event->count) + atomic64_read(&event->child_count);
82032+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
82033 }
82034
82035 static u64 perf_event_read(struct perf_event *event)
82036@@ -3308,9 +3315,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
82037 mutex_lock(&event->child_mutex);
82038 total += perf_event_read(event);
82039 *enabled += event->total_time_enabled +
82040- atomic64_read(&event->child_total_time_enabled);
82041+ atomic64_read_unchecked(&event->child_total_time_enabled);
82042 *running += event->total_time_running +
82043- atomic64_read(&event->child_total_time_running);
82044+ atomic64_read_unchecked(&event->child_total_time_running);
82045
82046 list_for_each_entry(child, &event->child_list, child_list) {
82047 total += perf_event_read(child);
82048@@ -3725,10 +3732,10 @@ void perf_event_update_userpage(struct perf_event *event)
82049 userpg->offset -= local64_read(&event->hw.prev_count);
82050
82051 userpg->time_enabled = enabled +
82052- atomic64_read(&event->child_total_time_enabled);
82053+ atomic64_read_unchecked(&event->child_total_time_enabled);
82054
82055 userpg->time_running = running +
82056- atomic64_read(&event->child_total_time_running);
82057+ atomic64_read_unchecked(&event->child_total_time_running);
82058
82059 arch_perf_update_userpage(userpg, now);
82060
82061@@ -4279,7 +4286,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
82062
82063 /* Data. */
82064 sp = perf_user_stack_pointer(regs);
82065- rem = __output_copy_user(handle, (void *) sp, dump_size);
82066+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
82067 dyn_size = dump_size - rem;
82068
82069 perf_output_skip(handle, rem);
82070@@ -4370,11 +4377,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
82071 values[n++] = perf_event_count(event);
82072 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
82073 values[n++] = enabled +
82074- atomic64_read(&event->child_total_time_enabled);
82075+ atomic64_read_unchecked(&event->child_total_time_enabled);
82076 }
82077 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
82078 values[n++] = running +
82079- atomic64_read(&event->child_total_time_running);
82080+ atomic64_read_unchecked(&event->child_total_time_running);
82081 }
82082 if (read_format & PERF_FORMAT_ID)
82083 values[n++] = primary_event_id(event);
82084@@ -5112,12 +5119,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
82085 * need to add enough zero bytes after the string to handle
82086 * the 64bit alignment we do later.
82087 */
82088- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
82089+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
82090 if (!buf) {
82091 name = strncpy(tmp, "//enomem", sizeof(tmp));
82092 goto got_name;
82093 }
82094- name = d_path(&file->f_path, buf, PATH_MAX);
82095+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
82096 if (IS_ERR(name)) {
82097 name = strncpy(tmp, "//toolong", sizeof(tmp));
82098 goto got_name;
82099@@ -6639,7 +6646,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
82100 event->parent = parent_event;
82101
82102 event->ns = get_pid_ns(task_active_pid_ns(current));
82103- event->id = atomic64_inc_return(&perf_event_id);
82104+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
82105
82106 event->state = PERF_EVENT_STATE_INACTIVE;
82107
82108@@ -6938,6 +6945,11 @@ SYSCALL_DEFINE5(perf_event_open,
82109 if (flags & ~PERF_FLAG_ALL)
82110 return -EINVAL;
82111
82112+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
82113+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
82114+ return -EACCES;
82115+#endif
82116+
82117 err = perf_copy_attr(attr_uptr, &attr);
82118 if (err)
82119 return err;
82120@@ -7271,10 +7283,10 @@ static void sync_child_event(struct perf_event *child_event,
82121 /*
82122 * Add back the child's count to the parent's count:
82123 */
82124- atomic64_add(child_val, &parent_event->child_count);
82125- atomic64_add(child_event->total_time_enabled,
82126+ atomic64_add_unchecked(child_val, &parent_event->child_count);
82127+ atomic64_add_unchecked(child_event->total_time_enabled,
82128 &parent_event->child_total_time_enabled);
82129- atomic64_add(child_event->total_time_running,
82130+ atomic64_add_unchecked(child_event->total_time_running,
82131 &parent_event->child_total_time_running);
82132
82133 /*
82134diff --git a/kernel/events/internal.h b/kernel/events/internal.h
82135index ca65997..60df03d 100644
82136--- a/kernel/events/internal.h
82137+++ b/kernel/events/internal.h
82138@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
82139 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
82140 }
82141
82142-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
82143-static inline unsigned int \
82144+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
82145+static inline unsigned long \
82146 func_name(struct perf_output_handle *handle, \
82147- const void *buf, unsigned int len) \
82148+ const void user *buf, unsigned long len) \
82149 { \
82150 unsigned long size, written; \
82151 \
82152@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
82153 return n;
82154 }
82155
82156-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
82157+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
82158
82159 #define MEMCPY_SKIP(dst, src, n) (n)
82160
82161-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
82162+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
82163
82164 #ifndef arch_perf_out_copy_user
82165 #define arch_perf_out_copy_user __copy_from_user_inatomic
82166 #endif
82167
82168-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
82169+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
82170
82171 /* Callchain handling */
82172 extern struct perf_callchain_entry *
82173diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
82174index ad8e1bd..fed7ba9 100644
82175--- a/kernel/events/uprobes.c
82176+++ b/kernel/events/uprobes.c
82177@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
82178 {
82179 struct page *page;
82180 uprobe_opcode_t opcode;
82181- int result;
82182+ long result;
82183
82184 pagefault_disable();
82185 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
82186diff --git a/kernel/exit.c b/kernel/exit.c
82187index a949819..a5f127d 100644
82188--- a/kernel/exit.c
82189+++ b/kernel/exit.c
82190@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
82191 struct task_struct *leader;
82192 int zap_leader;
82193 repeat:
82194+#ifdef CONFIG_NET
82195+ gr_del_task_from_ip_table(p);
82196+#endif
82197+
82198 /* don't need to get the RCU readlock here - the process is dead and
82199 * can't be modifying its own credentials. But shut RCU-lockdep up */
82200 rcu_read_lock();
82201@@ -329,7 +333,7 @@ int allow_signal(int sig)
82202 * know it'll be handled, so that they don't get converted to
82203 * SIGKILL or just silently dropped.
82204 */
82205- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
82206+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
82207 recalc_sigpending();
82208 spin_unlock_irq(&current->sighand->siglock);
82209 return 0;
82210@@ -698,6 +702,8 @@ void do_exit(long code)
82211 struct task_struct *tsk = current;
82212 int group_dead;
82213
82214+ set_fs(USER_DS);
82215+
82216 profile_task_exit(tsk);
82217
82218 WARN_ON(blk_needs_flush_plug(tsk));
82219@@ -714,7 +720,6 @@ void do_exit(long code)
82220 * mm_release()->clear_child_tid() from writing to a user-controlled
82221 * kernel address.
82222 */
82223- set_fs(USER_DS);
82224
82225 ptrace_event(PTRACE_EVENT_EXIT, code);
82226
82227@@ -773,6 +778,9 @@ void do_exit(long code)
82228 tsk->exit_code = code;
82229 taskstats_exit(tsk, group_dead);
82230
82231+ gr_acl_handle_psacct(tsk, code);
82232+ gr_acl_handle_exit();
82233+
82234 exit_mm(tsk);
82235
82236 if (group_dead)
82237@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
82238 * Take down every thread in the group. This is called by fatal signals
82239 * as well as by sys_exit_group (below).
82240 */
82241-void
82242+__noreturn void
82243 do_group_exit(int exit_code)
82244 {
82245 struct signal_struct *sig = current->signal;
82246diff --git a/kernel/fork.c b/kernel/fork.c
82247index 086fe73..72c1122 100644
82248--- a/kernel/fork.c
82249+++ b/kernel/fork.c
82250@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
82251 *stackend = STACK_END_MAGIC; /* for overflow detection */
82252
82253 #ifdef CONFIG_CC_STACKPROTECTOR
82254- tsk->stack_canary = get_random_int();
82255+ tsk->stack_canary = pax_get_random_long();
82256 #endif
82257
82258 /*
82259@@ -345,12 +345,80 @@ free_tsk:
82260 }
82261
82262 #ifdef CONFIG_MMU
82263-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82264+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
82265+{
82266+ struct vm_area_struct *tmp;
82267+ unsigned long charge;
82268+ struct file *file;
82269+ int retval;
82270+
82271+ charge = 0;
82272+ if (mpnt->vm_flags & VM_ACCOUNT) {
82273+ unsigned long len = vma_pages(mpnt);
82274+
82275+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
82276+ goto fail_nomem;
82277+ charge = len;
82278+ }
82279+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82280+ if (!tmp)
82281+ goto fail_nomem;
82282+ *tmp = *mpnt;
82283+ tmp->vm_mm = mm;
82284+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
82285+ retval = vma_dup_policy(mpnt, tmp);
82286+ if (retval)
82287+ goto fail_nomem_policy;
82288+ if (anon_vma_fork(tmp, mpnt))
82289+ goto fail_nomem_anon_vma_fork;
82290+ tmp->vm_flags &= ~VM_LOCKED;
82291+ tmp->vm_next = tmp->vm_prev = NULL;
82292+ tmp->vm_mirror = NULL;
82293+ file = tmp->vm_file;
82294+ if (file) {
82295+ struct inode *inode = file_inode(file);
82296+ struct address_space *mapping = file->f_mapping;
82297+
82298+ get_file(file);
82299+ if (tmp->vm_flags & VM_DENYWRITE)
82300+ atomic_dec(&inode->i_writecount);
82301+ mutex_lock(&mapping->i_mmap_mutex);
82302+ if (tmp->vm_flags & VM_SHARED)
82303+ mapping->i_mmap_writable++;
82304+ flush_dcache_mmap_lock(mapping);
82305+ /* insert tmp into the share list, just after mpnt */
82306+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
82307+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
82308+ else
82309+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
82310+ flush_dcache_mmap_unlock(mapping);
82311+ mutex_unlock(&mapping->i_mmap_mutex);
82312+ }
82313+
82314+ /*
82315+ * Clear hugetlb-related page reserves for children. This only
82316+ * affects MAP_PRIVATE mappings. Faults generated by the child
82317+ * are not guaranteed to succeed, even if read-only
82318+ */
82319+ if (is_vm_hugetlb_page(tmp))
82320+ reset_vma_resv_huge_pages(tmp);
82321+
82322+ return tmp;
82323+
82324+fail_nomem_anon_vma_fork:
82325+ mpol_put(vma_policy(tmp));
82326+fail_nomem_policy:
82327+ kmem_cache_free(vm_area_cachep, tmp);
82328+fail_nomem:
82329+ vm_unacct_memory(charge);
82330+ return NULL;
82331+}
82332+
82333+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82334 {
82335 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
82336 struct rb_node **rb_link, *rb_parent;
82337 int retval;
82338- unsigned long charge;
82339
82340 uprobe_start_dup_mmap();
82341 down_write(&oldmm->mmap_sem);
82342@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82343
82344 prev = NULL;
82345 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
82346- struct file *file;
82347-
82348 if (mpnt->vm_flags & VM_DONTCOPY) {
82349 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
82350 -vma_pages(mpnt));
82351 continue;
82352 }
82353- charge = 0;
82354- if (mpnt->vm_flags & VM_ACCOUNT) {
82355- unsigned long len = vma_pages(mpnt);
82356-
82357- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
82358- goto fail_nomem;
82359- charge = len;
82360- }
82361- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82362- if (!tmp)
82363- goto fail_nomem;
82364- *tmp = *mpnt;
82365- INIT_LIST_HEAD(&tmp->anon_vma_chain);
82366- retval = vma_dup_policy(mpnt, tmp);
82367- if (retval)
82368- goto fail_nomem_policy;
82369- tmp->vm_mm = mm;
82370- if (anon_vma_fork(tmp, mpnt))
82371- goto fail_nomem_anon_vma_fork;
82372- tmp->vm_flags &= ~VM_LOCKED;
82373- tmp->vm_next = tmp->vm_prev = NULL;
82374- file = tmp->vm_file;
82375- if (file) {
82376- struct inode *inode = file_inode(file);
82377- struct address_space *mapping = file->f_mapping;
82378-
82379- get_file(file);
82380- if (tmp->vm_flags & VM_DENYWRITE)
82381- atomic_dec(&inode->i_writecount);
82382- mutex_lock(&mapping->i_mmap_mutex);
82383- if (tmp->vm_flags & VM_SHARED)
82384- mapping->i_mmap_writable++;
82385- flush_dcache_mmap_lock(mapping);
82386- /* insert tmp into the share list, just after mpnt */
82387- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
82388- vma_nonlinear_insert(tmp,
82389- &mapping->i_mmap_nonlinear);
82390- else
82391- vma_interval_tree_insert_after(tmp, mpnt,
82392- &mapping->i_mmap);
82393- flush_dcache_mmap_unlock(mapping);
82394- mutex_unlock(&mapping->i_mmap_mutex);
82395+ tmp = dup_vma(mm, oldmm, mpnt);
82396+ if (!tmp) {
82397+ retval = -ENOMEM;
82398+ goto out;
82399 }
82400
82401 /*
82402@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
82403 if (retval)
82404 goto out;
82405 }
82406+
82407+#ifdef CONFIG_PAX_SEGMEXEC
82408+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
82409+ struct vm_area_struct *mpnt_m;
82410+
82411+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
82412+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
82413+
82414+ if (!mpnt->vm_mirror)
82415+ continue;
82416+
82417+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
82418+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
82419+ mpnt->vm_mirror = mpnt_m;
82420+ } else {
82421+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
82422+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
82423+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
82424+ mpnt->vm_mirror->vm_mirror = mpnt;
82425+ }
82426+ }
82427+ BUG_ON(mpnt_m);
82428+ }
82429+#endif
82430+
82431 /* a new mm has just been created */
82432 arch_dup_mmap(oldmm, mm);
82433 retval = 0;
82434@@ -468,14 +521,6 @@ out:
82435 up_write(&oldmm->mmap_sem);
82436 uprobe_end_dup_mmap();
82437 return retval;
82438-fail_nomem_anon_vma_fork:
82439- mpol_put(vma_policy(tmp));
82440-fail_nomem_policy:
82441- kmem_cache_free(vm_area_cachep, tmp);
82442-fail_nomem:
82443- retval = -ENOMEM;
82444- vm_unacct_memory(charge);
82445- goto out;
82446 }
82447
82448 static inline int mm_alloc_pgd(struct mm_struct *mm)
82449@@ -688,8 +733,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
82450 return ERR_PTR(err);
82451
82452 mm = get_task_mm(task);
82453- if (mm && mm != current->mm &&
82454- !ptrace_may_access(task, mode)) {
82455+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
82456+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
82457 mmput(mm);
82458 mm = ERR_PTR(-EACCES);
82459 }
82460@@ -911,13 +956,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
82461 spin_unlock(&fs->lock);
82462 return -EAGAIN;
82463 }
82464- fs->users++;
82465+ atomic_inc(&fs->users);
82466 spin_unlock(&fs->lock);
82467 return 0;
82468 }
82469 tsk->fs = copy_fs_struct(fs);
82470 if (!tsk->fs)
82471 return -ENOMEM;
82472+ /* Carry through gr_chroot_dentry and is_chrooted instead
82473+ of recomputing it here. Already copied when the task struct
82474+ is duplicated. This allows pivot_root to not be treated as
82475+ a chroot
82476+ */
82477+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
82478+
82479 return 0;
82480 }
82481
82482@@ -1128,7 +1180,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
82483 * parts of the process environment (as per the clone
82484 * flags). The actual kick-off is left to the caller.
82485 */
82486-static struct task_struct *copy_process(unsigned long clone_flags,
82487+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
82488 unsigned long stack_start,
82489 unsigned long stack_size,
82490 int __user *child_tidptr,
82491@@ -1200,6 +1252,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
82492 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
82493 #endif
82494 retval = -EAGAIN;
82495+
82496+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
82497+
82498 if (atomic_read(&p->real_cred->user->processes) >=
82499 task_rlimit(p, RLIMIT_NPROC)) {
82500 if (p->real_cred->user != INIT_USER &&
82501@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
82502 goto bad_fork_free_pid;
82503 }
82504
82505+ /* synchronizes with gr_set_acls()
82506+ we need to call this past the point of no return for fork()
82507+ */
82508+ gr_copy_label(p);
82509+
82510 if (likely(p->pid)) {
82511 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
82512
82513@@ -1534,6 +1594,8 @@ bad_fork_cleanup_count:
82514 bad_fork_free:
82515 free_task(p);
82516 fork_out:
82517+ gr_log_forkfail(retval);
82518+
82519 return ERR_PTR(retval);
82520 }
82521
82522@@ -1595,6 +1657,7 @@ long do_fork(unsigned long clone_flags,
82523
82524 p = copy_process(clone_flags, stack_start, stack_size,
82525 child_tidptr, NULL, trace);
82526+ add_latent_entropy();
82527 /*
82528 * Do this prior waking up the new thread - the thread pointer
82529 * might get invalid after that point, if the thread exits quickly.
82530@@ -1609,6 +1672,8 @@ long do_fork(unsigned long clone_flags,
82531 if (clone_flags & CLONE_PARENT_SETTID)
82532 put_user(nr, parent_tidptr);
82533
82534+ gr_handle_brute_check();
82535+
82536 if (clone_flags & CLONE_VFORK) {
82537 p->vfork_done = &vfork;
82538 init_completion(&vfork);
82539@@ -1725,7 +1790,7 @@ void __init proc_caches_init(void)
82540 mm_cachep = kmem_cache_create("mm_struct",
82541 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
82542 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
82543- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
82544+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
82545 mmap_init();
82546 nsproxy_cache_init();
82547 }
82548@@ -1765,7 +1830,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
82549 return 0;
82550
82551 /* don't need lock here; in the worst case we'll do useless copy */
82552- if (fs->users == 1)
82553+ if (atomic_read(&fs->users) == 1)
82554 return 0;
82555
82556 *new_fsp = copy_fs_struct(fs);
82557@@ -1872,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
82558 fs = current->fs;
82559 spin_lock(&fs->lock);
82560 current->fs = new_fs;
82561- if (--fs->users)
82562+ gr_set_chroot_entries(current, &current->fs->root);
82563+ if (atomic_dec_return(&fs->users))
82564 new_fs = NULL;
82565 else
82566 new_fs = fs;
82567diff --git a/kernel/futex.c b/kernel/futex.c
82568index c3a1a55..1b8cfce 100644
82569--- a/kernel/futex.c
82570+++ b/kernel/futex.c
82571@@ -54,6 +54,7 @@
82572 #include <linux/mount.h>
82573 #include <linux/pagemap.h>
82574 #include <linux/syscalls.h>
82575+#include <linux/ptrace.h>
82576 #include <linux/signal.h>
82577 #include <linux/export.h>
82578 #include <linux/magic.h>
82579@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
82580 struct page *page, *page_head;
82581 int err, ro = 0;
82582
82583+#ifdef CONFIG_PAX_SEGMEXEC
82584+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
82585+ return -EFAULT;
82586+#endif
82587+
82588 /*
82589 * The futex address must be "naturally" aligned.
82590 */
82591@@ -288,7 +294,7 @@ again:
82592 put_page(page);
82593 /* serialize against __split_huge_page_splitting() */
82594 local_irq_disable();
82595- if (likely(__get_user_pages_fast(address, 1, 1, &page) == 1)) {
82596+ if (likely(__get_user_pages_fast(address, 1, !ro, &page) == 1)) {
82597 page_head = compound_head(page);
82598 /*
82599 * page_head is valid pointer but we must pin
82600@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
82601
82602 static int get_futex_value_locked(u32 *dest, u32 __user *from)
82603 {
82604- int ret;
82605+ unsigned long ret;
82606
82607 pagefault_disable();
82608 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
82609@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
82610 {
82611 u32 curval;
82612 int i;
82613+ mm_segment_t oldfs;
82614
82615 /*
82616 * This will fail and we want it. Some arch implementations do
82617@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
82618 * implementation, the non-functional ones will return
82619 * -ENOSYS.
82620 */
82621+ oldfs = get_fs();
82622+ set_fs(USER_DS);
82623 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
82624 futex_cmpxchg_enabled = 1;
82625+ set_fs(oldfs);
82626
82627 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
82628 plist_head_init(&futex_queues[i].chain);
82629diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
82630index f9f44fd..29885e4 100644
82631--- a/kernel/futex_compat.c
82632+++ b/kernel/futex_compat.c
82633@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
82634 return 0;
82635 }
82636
82637-static void __user *futex_uaddr(struct robust_list __user *entry,
82638+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
82639 compat_long_t futex_offset)
82640 {
82641 compat_uptr_t base = ptr_to_compat(entry);
82642diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
82643index 9b22d03..6295b62 100644
82644--- a/kernel/gcov/base.c
82645+++ b/kernel/gcov/base.c
82646@@ -102,11 +102,6 @@ void gcov_enable_events(void)
82647 }
82648
82649 #ifdef CONFIG_MODULES
82650-static inline int within(void *addr, void *start, unsigned long size)
82651-{
82652- return ((addr >= start) && (addr < start + size));
82653-}
82654-
82655 /* Update list and generate events when modules are unloaded. */
82656 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82657 void *data)
82658@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82659 prev = NULL;
82660 /* Remove entries located in module from linked list. */
82661 for (info = gcov_info_head; info; info = info->next) {
82662- if (within(info, mod->module_core, mod->core_size)) {
82663+ if (within_module_core_rw((unsigned long)info, mod)) {
82664 if (prev)
82665 prev->next = info->next;
82666 else
82667diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
82668index 383319b..56ebb13 100644
82669--- a/kernel/hrtimer.c
82670+++ b/kernel/hrtimer.c
82671@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
82672 local_irq_restore(flags);
82673 }
82674
82675-static void run_hrtimer_softirq(struct softirq_action *h)
82676+static __latent_entropy void run_hrtimer_softirq(void)
82677 {
82678 hrtimer_peek_ahead_timers();
82679 }
82680diff --git a/kernel/irq_work.c b/kernel/irq_work.c
82681index 55fcce6..0e4cf34 100644
82682--- a/kernel/irq_work.c
82683+++ b/kernel/irq_work.c
82684@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
82685 return NOTIFY_OK;
82686 }
82687
82688-static struct notifier_block cpu_notify;
82689+static struct notifier_block cpu_notify = {
82690+ .notifier_call = irq_work_cpu_notify,
82691+ .priority = 0,
82692+};
82693
82694 static __init int irq_work_init_cpu_notifier(void)
82695 {
82696- cpu_notify.notifier_call = irq_work_cpu_notify;
82697- cpu_notify.priority = 0;
82698 register_cpu_notifier(&cpu_notify);
82699 return 0;
82700 }
82701diff --git a/kernel/jump_label.c b/kernel/jump_label.c
82702index 297a924..7290070 100644
82703--- a/kernel/jump_label.c
82704+++ b/kernel/jump_label.c
82705@@ -14,6 +14,7 @@
82706 #include <linux/err.h>
82707 #include <linux/static_key.h>
82708 #include <linux/jump_label_ratelimit.h>
82709+#include <linux/mm.h>
82710
82711 #ifdef HAVE_JUMP_LABEL
82712
82713@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
82714
82715 size = (((unsigned long)stop - (unsigned long)start)
82716 / sizeof(struct jump_entry));
82717+ pax_open_kernel();
82718 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
82719+ pax_close_kernel();
82720 }
82721
82722 static void jump_label_update(struct static_key *key, int enable);
82723@@ -358,10 +361,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
82724 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
82725 struct jump_entry *iter;
82726
82727+ pax_open_kernel();
82728 for (iter = iter_start; iter < iter_stop; iter++) {
82729 if (within_module_init(iter->code, mod))
82730 iter->code = 0;
82731 }
82732+ pax_close_kernel();
82733 }
82734
82735 static int
82736diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
82737index 3127ad5..159d880 100644
82738--- a/kernel/kallsyms.c
82739+++ b/kernel/kallsyms.c
82740@@ -11,6 +11,9 @@
82741 * Changed the compression method from stem compression to "table lookup"
82742 * compression (see scripts/kallsyms.c for a more complete description)
82743 */
82744+#ifdef CONFIG_GRKERNSEC_HIDESYM
82745+#define __INCLUDED_BY_HIDESYM 1
82746+#endif
82747 #include <linux/kallsyms.h>
82748 #include <linux/module.h>
82749 #include <linux/init.h>
82750@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
82751
82752 static inline int is_kernel_inittext(unsigned long addr)
82753 {
82754+ if (system_state != SYSTEM_BOOTING)
82755+ return 0;
82756+
82757 if (addr >= (unsigned long)_sinittext
82758 && addr <= (unsigned long)_einittext)
82759 return 1;
82760 return 0;
82761 }
82762
82763+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82764+#ifdef CONFIG_MODULES
82765+static inline int is_module_text(unsigned long addr)
82766+{
82767+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
82768+ return 1;
82769+
82770+ addr = ktla_ktva(addr);
82771+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
82772+}
82773+#else
82774+static inline int is_module_text(unsigned long addr)
82775+{
82776+ return 0;
82777+}
82778+#endif
82779+#endif
82780+
82781 static inline int is_kernel_text(unsigned long addr)
82782 {
82783 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
82784@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
82785
82786 static inline int is_kernel(unsigned long addr)
82787 {
82788+
82789+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82790+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
82791+ return 1;
82792+
82793+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
82794+#else
82795 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
82796+#endif
82797+
82798 return 1;
82799 return in_gate_area_no_mm(addr);
82800 }
82801
82802 static int is_ksym_addr(unsigned long addr)
82803 {
82804+
82805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82806+ if (is_module_text(addr))
82807+ return 0;
82808+#endif
82809+
82810 if (all_var)
82811 return is_kernel(addr);
82812
82813@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
82814
82815 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
82816 {
82817- iter->name[0] = '\0';
82818 iter->nameoff = get_symbol_offset(new_pos);
82819 iter->pos = new_pos;
82820 }
82821@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
82822 {
82823 struct kallsym_iter *iter = m->private;
82824
82825+#ifdef CONFIG_GRKERNSEC_HIDESYM
82826+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
82827+ return 0;
82828+#endif
82829+
82830 /* Some debugging symbols have no name. Ignore them. */
82831 if (!iter->name[0])
82832 return 0;
82833@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
82834 */
82835 type = iter->exported ? toupper(iter->type) :
82836 tolower(iter->type);
82837+
82838 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
82839 type, iter->name, iter->module_name);
82840 } else
82841@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
82842 struct kallsym_iter *iter;
82843 int ret;
82844
82845- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
82846+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
82847 if (!iter)
82848 return -ENOMEM;
82849 reset_iter(iter, 0);
82850diff --git a/kernel/kcmp.c b/kernel/kcmp.c
82851index e30ac0f..3528cac 100644
82852--- a/kernel/kcmp.c
82853+++ b/kernel/kcmp.c
82854@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
82855 struct task_struct *task1, *task2;
82856 int ret;
82857
82858+#ifdef CONFIG_GRKERNSEC
82859+ return -ENOSYS;
82860+#endif
82861+
82862 rcu_read_lock();
82863
82864 /*
82865diff --git a/kernel/kexec.c b/kernel/kexec.c
82866index 2a74f30..d139351 100644
82867--- a/kernel/kexec.c
82868+++ b/kernel/kexec.c
82869@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
82870 unsigned long flags)
82871 {
82872 struct compat_kexec_segment in;
82873- struct kexec_segment out, __user *ksegments;
82874+ struct kexec_segment out;
82875+ struct kexec_segment __user *ksegments;
82876 unsigned long i, result;
82877
82878 /* Don't allow clients that don't understand the native
82879diff --git a/kernel/kmod.c b/kernel/kmod.c
82880index b086006..6d2e579 100644
82881--- a/kernel/kmod.c
82882+++ b/kernel/kmod.c
82883@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
82884 kfree(info->argv);
82885 }
82886
82887-static int call_modprobe(char *module_name, int wait)
82888+static int call_modprobe(char *module_name, char *module_param, int wait)
82889 {
82890 struct subprocess_info *info;
82891 static char *envp[] = {
82892@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
82893 NULL
82894 };
82895
82896- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
82897+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
82898 if (!argv)
82899 goto out;
82900
82901@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
82902 argv[1] = "-q";
82903 argv[2] = "--";
82904 argv[3] = module_name; /* check free_modprobe_argv() */
82905- argv[4] = NULL;
82906+ argv[4] = module_param;
82907+ argv[5] = NULL;
82908
82909 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
82910 NULL, free_modprobe_argv, NULL);
82911@@ -129,9 +130,8 @@ out:
82912 * If module auto-loading support is disabled then this function
82913 * becomes a no-operation.
82914 */
82915-int __request_module(bool wait, const char *fmt, ...)
82916+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
82917 {
82918- va_list args;
82919 char module_name[MODULE_NAME_LEN];
82920 unsigned int max_modprobes;
82921 int ret;
82922@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
82923 if (!modprobe_path[0])
82924 return 0;
82925
82926- va_start(args, fmt);
82927- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
82928- va_end(args);
82929+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
82930 if (ret >= MODULE_NAME_LEN)
82931 return -ENAMETOOLONG;
82932
82933@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
82934 if (ret)
82935 return ret;
82936
82937+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82938+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82939+ /* hack to workaround consolekit/udisks stupidity */
82940+ read_lock(&tasklist_lock);
82941+ if (!strcmp(current->comm, "mount") &&
82942+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
82943+ read_unlock(&tasklist_lock);
82944+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
82945+ return -EPERM;
82946+ }
82947+ read_unlock(&tasklist_lock);
82948+ }
82949+#endif
82950+
82951 /* If modprobe needs a service that is in a module, we get a recursive
82952 * loop. Limit the number of running kmod threads to max_threads/2 or
82953 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
82954@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
82955
82956 trace_module_request(module_name, wait, _RET_IP_);
82957
82958- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82959+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82960
82961 atomic_dec(&kmod_concurrent);
82962 return ret;
82963 }
82964+
82965+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
82966+{
82967+ va_list args;
82968+ int ret;
82969+
82970+ va_start(args, fmt);
82971+ ret = ____request_module(wait, module_param, fmt, args);
82972+ va_end(args);
82973+
82974+ return ret;
82975+}
82976+
82977+int __request_module(bool wait, const char *fmt, ...)
82978+{
82979+ va_list args;
82980+ int ret;
82981+
82982+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82983+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82984+ char module_param[MODULE_NAME_LEN];
82985+
82986+ memset(module_param, 0, sizeof(module_param));
82987+
82988+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
82989+
82990+ va_start(args, fmt);
82991+ ret = ____request_module(wait, module_param, fmt, args);
82992+ va_end(args);
82993+
82994+ return ret;
82995+ }
82996+#endif
82997+
82998+ va_start(args, fmt);
82999+ ret = ____request_module(wait, NULL, fmt, args);
83000+ va_end(args);
83001+
83002+ return ret;
83003+}
83004+
83005 EXPORT_SYMBOL(__request_module);
83006 #endif /* CONFIG_MODULES */
83007
83008@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
83009 */
83010 set_user_nice(current, 0);
83011
83012+#ifdef CONFIG_GRKERNSEC
83013+ /* this is race-free as far as userland is concerned as we copied
83014+ out the path to be used prior to this point and are now operating
83015+ on that copy
83016+ */
83017+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
83018+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
83019+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
83020+ retval = -EPERM;
83021+ goto fail;
83022+ }
83023+#endif
83024+
83025 retval = -ENOMEM;
83026 new = prepare_kernel_cred(current);
83027 if (!new)
83028@@ -260,6 +326,10 @@ static int call_helper(void *data)
83029
83030 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
83031 {
83032+#ifdef CONFIG_GRKERNSEC
83033+ kfree(info->path);
83034+ info->path = info->origpath;
83035+#endif
83036 if (info->cleanup)
83037 (*info->cleanup)(info);
83038 kfree(info);
83039@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
83040 *
83041 * Thus the __user pointer cast is valid here.
83042 */
83043- sys_wait4(pid, (int __user *)&ret, 0, NULL);
83044+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
83045
83046 /*
83047 * If ret is 0, either ____call_usermodehelper failed and the
83048@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
83049 goto out;
83050
83051 INIT_WORK(&sub_info->work, __call_usermodehelper);
83052+#ifdef CONFIG_GRKERNSEC
83053+ sub_info->origpath = path;
83054+ sub_info->path = kstrdup(path, gfp_mask);
83055+#else
83056 sub_info->path = path;
83057+#endif
83058 sub_info->argv = argv;
83059 sub_info->envp = envp;
83060
83061@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
83062 static int proc_cap_handler(struct ctl_table *table, int write,
83063 void __user *buffer, size_t *lenp, loff_t *ppos)
83064 {
83065- struct ctl_table t;
83066+ ctl_table_no_const t;
83067 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
83068 kernel_cap_t new_cap;
83069 int err, i;
83070diff --git a/kernel/kprobes.c b/kernel/kprobes.c
83071index a0d367a..11c18b6 100644
83072--- a/kernel/kprobes.c
83073+++ b/kernel/kprobes.c
83074@@ -31,6 +31,9 @@
83075 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
83076 * <prasanna@in.ibm.com> added function-return probes.
83077 */
83078+#ifdef CONFIG_GRKERNSEC_HIDESYM
83079+#define __INCLUDED_BY_HIDESYM 1
83080+#endif
83081 #include <linux/kprobes.h>
83082 #include <linux/hash.h>
83083 #include <linux/init.h>
83084@@ -135,12 +138,12 @@ enum kprobe_slot_state {
83085
83086 static void *alloc_insn_page(void)
83087 {
83088- return module_alloc(PAGE_SIZE);
83089+ return module_alloc_exec(PAGE_SIZE);
83090 }
83091
83092 static void free_insn_page(void *page)
83093 {
83094- module_free(NULL, page);
83095+ module_free_exec(NULL, page);
83096 }
83097
83098 struct kprobe_insn_cache kprobe_insn_slots = {
83099@@ -2066,7 +2069,7 @@ static int __init init_kprobes(void)
83100 {
83101 int i, err = 0;
83102 unsigned long offset = 0, size = 0;
83103- char *modname, namebuf[128];
83104+ char *modname, namebuf[KSYM_NAME_LEN];
83105 const char *symbol_name;
83106 void *addr;
83107 struct kprobe_blackpoint *kb;
83108@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
83109 kprobe_type = "k";
83110
83111 if (sym)
83112- seq_printf(pi, "%p %s %s+0x%x %s ",
83113+ seq_printf(pi, "%pK %s %s+0x%x %s ",
83114 p->addr, kprobe_type, sym, offset,
83115 (modname ? modname : " "));
83116 else
83117- seq_printf(pi, "%p %s %p ",
83118+ seq_printf(pi, "%pK %s %pK ",
83119 p->addr, kprobe_type, p->addr);
83120
83121 if (!pp)
83122@@ -2192,7 +2195,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
83123 const char *sym = NULL;
83124 unsigned int i = *(loff_t *) v;
83125 unsigned long offset = 0;
83126- char *modname, namebuf[128];
83127+ char *modname, namebuf[KSYM_NAME_LEN];
83128
83129 head = &kprobe_table[i];
83130 preempt_disable();
83131diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
83132index 9659d38..bffd520 100644
83133--- a/kernel/ksysfs.c
83134+++ b/kernel/ksysfs.c
83135@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
83136 {
83137 if (count+1 > UEVENT_HELPER_PATH_LEN)
83138 return -ENOENT;
83139+ if (!capable(CAP_SYS_ADMIN))
83140+ return -EPERM;
83141 memcpy(uevent_helper, buf, count);
83142 uevent_helper[count] = '\0';
83143 if (count && uevent_helper[count-1] == '\n')
83144@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
83145 return count;
83146 }
83147
83148-static struct bin_attribute notes_attr = {
83149+static bin_attribute_no_const notes_attr __read_only = {
83150 .attr = {
83151 .name = "notes",
83152 .mode = S_IRUGO,
83153diff --git a/kernel/lockdep.c b/kernel/lockdep.c
83154index e16c45b..6f49c48 100644
83155--- a/kernel/lockdep.c
83156+++ b/kernel/lockdep.c
83157@@ -596,6 +596,10 @@ static int static_obj(void *obj)
83158 end = (unsigned long) &_end,
83159 addr = (unsigned long) obj;
83160
83161+#ifdef CONFIG_PAX_KERNEXEC
83162+ start = ktla_ktva(start);
83163+#endif
83164+
83165 /*
83166 * static variable?
83167 */
83168@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
83169 if (!static_obj(lock->key)) {
83170 debug_locks_off();
83171 printk("INFO: trying to register non-static key.\n");
83172+ printk("lock:%pS key:%pS.\n", lock, lock->key);
83173 printk("the code is fine but needs lockdep annotation.\n");
83174 printk("turning off the locking correctness validator.\n");
83175 dump_stack();
83176@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
83177 if (!class)
83178 return 0;
83179 }
83180- atomic_inc((atomic_t *)&class->ops);
83181+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
83182 if (very_verbose(class)) {
83183 printk("\nacquire class [%p] %s", class->key, class->name);
83184 if (class->name_version > 1)
83185diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
83186index b2c71c5..7b88d63 100644
83187--- a/kernel/lockdep_proc.c
83188+++ b/kernel/lockdep_proc.c
83189@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
83190 return 0;
83191 }
83192
83193- seq_printf(m, "%p", class->key);
83194+ seq_printf(m, "%pK", class->key);
83195 #ifdef CONFIG_DEBUG_LOCKDEP
83196 seq_printf(m, " OPS:%8ld", class->ops);
83197 #endif
83198@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
83199
83200 list_for_each_entry(entry, &class->locks_after, entry) {
83201 if (entry->distance == 1) {
83202- seq_printf(m, " -> [%p] ", entry->class->key);
83203+ seq_printf(m, " -> [%pK] ", entry->class->key);
83204 print_name(m, entry->class);
83205 seq_puts(m, "\n");
83206 }
83207@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
83208 if (!class->key)
83209 continue;
83210
83211- seq_printf(m, "[%p] ", class->key);
83212+ seq_printf(m, "[%pK] ", class->key);
83213 print_name(m, class);
83214 seq_puts(m, "\n");
83215 }
83216@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
83217 if (!i)
83218 seq_line(m, '-', 40-namelen, namelen);
83219
83220- snprintf(ip, sizeof(ip), "[<%p>]",
83221+ snprintf(ip, sizeof(ip), "[<%pK>]",
83222 (void *)class->contention_point[i]);
83223 seq_printf(m, "%40s %14lu %29s %pS\n",
83224 name, stats->contention_point[i],
83225@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
83226 if (!i)
83227 seq_line(m, '-', 40-namelen, namelen);
83228
83229- snprintf(ip, sizeof(ip), "[<%p>]",
83230+ snprintf(ip, sizeof(ip), "[<%pK>]",
83231 (void *)class->contending_point[i]);
83232 seq_printf(m, "%40s %14lu %29s %pS\n",
83233 name, stats->contending_point[i],
83234diff --git a/kernel/module.c b/kernel/module.c
83235index dc58274..3ddfa55 100644
83236--- a/kernel/module.c
83237+++ b/kernel/module.c
83238@@ -61,6 +61,7 @@
83239 #include <linux/pfn.h>
83240 #include <linux/bsearch.h>
83241 #include <linux/fips.h>
83242+#include <linux/grsecurity.h>
83243 #include <uapi/linux/module.h>
83244 #include "module-internal.h"
83245
83246@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
83247
83248 /* Bounds of module allocation, for speeding __module_address.
83249 * Protected by module_mutex. */
83250-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
83251+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
83252+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
83253
83254 int register_module_notifier(struct notifier_block * nb)
83255 {
83256@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
83257 return true;
83258
83259 list_for_each_entry_rcu(mod, &modules, list) {
83260- struct symsearch arr[] = {
83261+ struct symsearch modarr[] = {
83262 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
83263 NOT_GPL_ONLY, false },
83264 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
83265@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
83266 if (mod->state == MODULE_STATE_UNFORMED)
83267 continue;
83268
83269- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
83270+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
83271 return true;
83272 }
83273 return false;
83274@@ -491,7 +493,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
83275 if (!pcpusec->sh_size)
83276 return 0;
83277
83278- if (align > PAGE_SIZE) {
83279+ if (align-1 >= PAGE_SIZE) {
83280 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
83281 mod->name, align, PAGE_SIZE);
83282 align = PAGE_SIZE;
83283@@ -1097,7 +1099,7 @@ struct module_attribute module_uevent =
83284 static ssize_t show_coresize(struct module_attribute *mattr,
83285 struct module_kobject *mk, char *buffer)
83286 {
83287- return sprintf(buffer, "%u\n", mk->mod->core_size);
83288+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
83289 }
83290
83291 static struct module_attribute modinfo_coresize =
83292@@ -1106,7 +1108,7 @@ static struct module_attribute modinfo_coresize =
83293 static ssize_t show_initsize(struct module_attribute *mattr,
83294 struct module_kobject *mk, char *buffer)
83295 {
83296- return sprintf(buffer, "%u\n", mk->mod->init_size);
83297+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
83298 }
83299
83300 static struct module_attribute modinfo_initsize =
83301@@ -1321,7 +1323,7 @@ resolve_symbol_wait(struct module *mod,
83302 */
83303 #ifdef CONFIG_SYSFS
83304
83305-#ifdef CONFIG_KALLSYMS
83306+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83307 static inline bool sect_empty(const Elf_Shdr *sect)
83308 {
83309 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
83310@@ -1461,7 +1463,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
83311 {
83312 unsigned int notes, loaded, i;
83313 struct module_notes_attrs *notes_attrs;
83314- struct bin_attribute *nattr;
83315+ bin_attribute_no_const *nattr;
83316
83317 /* failed to create section attributes, so can't create notes */
83318 if (!mod->sect_attrs)
83319@@ -1573,7 +1575,7 @@ static void del_usage_links(struct module *mod)
83320 static int module_add_modinfo_attrs(struct module *mod)
83321 {
83322 struct module_attribute *attr;
83323- struct module_attribute *temp_attr;
83324+ module_attribute_no_const *temp_attr;
83325 int error = 0;
83326 int i;
83327
83328@@ -1795,21 +1797,21 @@ static void set_section_ro_nx(void *base,
83329
83330 static void unset_module_core_ro_nx(struct module *mod)
83331 {
83332- set_page_attributes(mod->module_core + mod->core_text_size,
83333- mod->module_core + mod->core_size,
83334+ set_page_attributes(mod->module_core_rw,
83335+ mod->module_core_rw + mod->core_size_rw,
83336 set_memory_x);
83337- set_page_attributes(mod->module_core,
83338- mod->module_core + mod->core_ro_size,
83339+ set_page_attributes(mod->module_core_rx,
83340+ mod->module_core_rx + mod->core_size_rx,
83341 set_memory_rw);
83342 }
83343
83344 static void unset_module_init_ro_nx(struct module *mod)
83345 {
83346- set_page_attributes(mod->module_init + mod->init_text_size,
83347- mod->module_init + mod->init_size,
83348+ set_page_attributes(mod->module_init_rw,
83349+ mod->module_init_rw + mod->init_size_rw,
83350 set_memory_x);
83351- set_page_attributes(mod->module_init,
83352- mod->module_init + mod->init_ro_size,
83353+ set_page_attributes(mod->module_init_rx,
83354+ mod->module_init_rx + mod->init_size_rx,
83355 set_memory_rw);
83356 }
83357
83358@@ -1822,14 +1824,14 @@ void set_all_modules_text_rw(void)
83359 list_for_each_entry_rcu(mod, &modules, list) {
83360 if (mod->state == MODULE_STATE_UNFORMED)
83361 continue;
83362- if ((mod->module_core) && (mod->core_text_size)) {
83363- set_page_attributes(mod->module_core,
83364- mod->module_core + mod->core_text_size,
83365+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
83366+ set_page_attributes(mod->module_core_rx,
83367+ mod->module_core_rx + mod->core_size_rx,
83368 set_memory_rw);
83369 }
83370- if ((mod->module_init) && (mod->init_text_size)) {
83371- set_page_attributes(mod->module_init,
83372- mod->module_init + mod->init_text_size,
83373+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
83374+ set_page_attributes(mod->module_init_rx,
83375+ mod->module_init_rx + mod->init_size_rx,
83376 set_memory_rw);
83377 }
83378 }
83379@@ -1845,14 +1847,14 @@ void set_all_modules_text_ro(void)
83380 list_for_each_entry_rcu(mod, &modules, list) {
83381 if (mod->state == MODULE_STATE_UNFORMED)
83382 continue;
83383- if ((mod->module_core) && (mod->core_text_size)) {
83384- set_page_attributes(mod->module_core,
83385- mod->module_core + mod->core_text_size,
83386+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
83387+ set_page_attributes(mod->module_core_rx,
83388+ mod->module_core_rx + mod->core_size_rx,
83389 set_memory_ro);
83390 }
83391- if ((mod->module_init) && (mod->init_text_size)) {
83392- set_page_attributes(mod->module_init,
83393- mod->module_init + mod->init_text_size,
83394+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
83395+ set_page_attributes(mod->module_init_rx,
83396+ mod->module_init_rx + mod->init_size_rx,
83397 set_memory_ro);
83398 }
83399 }
83400@@ -1903,16 +1905,19 @@ static void free_module(struct module *mod)
83401
83402 /* This may be NULL, but that's OK */
83403 unset_module_init_ro_nx(mod);
83404- module_free(mod, mod->module_init);
83405+ module_free(mod, mod->module_init_rw);
83406+ module_free_exec(mod, mod->module_init_rx);
83407 kfree(mod->args);
83408 percpu_modfree(mod);
83409
83410 /* Free lock-classes: */
83411- lockdep_free_key_range(mod->module_core, mod->core_size);
83412+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
83413+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
83414
83415 /* Finally, free the core (containing the module structure) */
83416 unset_module_core_ro_nx(mod);
83417- module_free(mod, mod->module_core);
83418+ module_free_exec(mod, mod->module_core_rx);
83419+ module_free(mod, mod->module_core_rw);
83420
83421 #ifdef CONFIG_MPU
83422 update_protections(current->mm);
83423@@ -1982,9 +1987,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83424 int ret = 0;
83425 const struct kernel_symbol *ksym;
83426
83427+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83428+ int is_fs_load = 0;
83429+ int register_filesystem_found = 0;
83430+ char *p;
83431+
83432+ p = strstr(mod->args, "grsec_modharden_fs");
83433+ if (p) {
83434+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
83435+ /* copy \0 as well */
83436+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
83437+ is_fs_load = 1;
83438+ }
83439+#endif
83440+
83441 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
83442 const char *name = info->strtab + sym[i].st_name;
83443
83444+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83445+ /* it's a real shame this will never get ripped and copied
83446+ upstream! ;(
83447+ */
83448+ if (is_fs_load && !strcmp(name, "register_filesystem"))
83449+ register_filesystem_found = 1;
83450+#endif
83451+
83452 switch (sym[i].st_shndx) {
83453 case SHN_COMMON:
83454 /* We compiled with -fno-common. These are not
83455@@ -2005,7 +2032,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83456 ksym = resolve_symbol_wait(mod, info, name);
83457 /* Ok if resolved. */
83458 if (ksym && !IS_ERR(ksym)) {
83459+ pax_open_kernel();
83460 sym[i].st_value = ksym->value;
83461+ pax_close_kernel();
83462 break;
83463 }
83464
83465@@ -2024,11 +2053,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
83466 secbase = (unsigned long)mod_percpu(mod);
83467 else
83468 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
83469+ pax_open_kernel();
83470 sym[i].st_value += secbase;
83471+ pax_close_kernel();
83472 break;
83473 }
83474 }
83475
83476+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83477+ if (is_fs_load && !register_filesystem_found) {
83478+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
83479+ ret = -EPERM;
83480+ }
83481+#endif
83482+
83483 return ret;
83484 }
83485
83486@@ -2112,22 +2150,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
83487 || s->sh_entsize != ~0UL
83488 || strstarts(sname, ".init"))
83489 continue;
83490- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
83491+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
83492+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
83493+ else
83494+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
83495 pr_debug("\t%s\n", sname);
83496 }
83497- switch (m) {
83498- case 0: /* executable */
83499- mod->core_size = debug_align(mod->core_size);
83500- mod->core_text_size = mod->core_size;
83501- break;
83502- case 1: /* RO: text and ro-data */
83503- mod->core_size = debug_align(mod->core_size);
83504- mod->core_ro_size = mod->core_size;
83505- break;
83506- case 3: /* whole core */
83507- mod->core_size = debug_align(mod->core_size);
83508- break;
83509- }
83510 }
83511
83512 pr_debug("Init section allocation order:\n");
83513@@ -2141,23 +2169,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
83514 || s->sh_entsize != ~0UL
83515 || !strstarts(sname, ".init"))
83516 continue;
83517- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
83518- | INIT_OFFSET_MASK);
83519+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
83520+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
83521+ else
83522+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
83523+ s->sh_entsize |= INIT_OFFSET_MASK;
83524 pr_debug("\t%s\n", sname);
83525 }
83526- switch (m) {
83527- case 0: /* executable */
83528- mod->init_size = debug_align(mod->init_size);
83529- mod->init_text_size = mod->init_size;
83530- break;
83531- case 1: /* RO: text and ro-data */
83532- mod->init_size = debug_align(mod->init_size);
83533- mod->init_ro_size = mod->init_size;
83534- break;
83535- case 3: /* whole init */
83536- mod->init_size = debug_align(mod->init_size);
83537- break;
83538- }
83539 }
83540 }
83541
83542@@ -2330,7 +2348,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
83543
83544 /* Put symbol section at end of init part of module. */
83545 symsect->sh_flags |= SHF_ALLOC;
83546- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
83547+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
83548 info->index.sym) | INIT_OFFSET_MASK;
83549 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
83550
83551@@ -2347,13 +2365,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
83552 }
83553
83554 /* Append room for core symbols at end of core part. */
83555- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
83556- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
83557- mod->core_size += strtab_size;
83558+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
83559+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
83560+ mod->core_size_rx += strtab_size;
83561
83562 /* Put string table section at end of init part of module. */
83563 strsect->sh_flags |= SHF_ALLOC;
83564- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
83565+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
83566 info->index.str) | INIT_OFFSET_MASK;
83567 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
83568 }
83569@@ -2371,12 +2389,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
83570 /* Make sure we get permanent strtab: don't use info->strtab. */
83571 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
83572
83573+ pax_open_kernel();
83574+
83575 /* Set types up while we still have access to sections. */
83576 for (i = 0; i < mod->num_symtab; i++)
83577 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
83578
83579- mod->core_symtab = dst = mod->module_core + info->symoffs;
83580- mod->core_strtab = s = mod->module_core + info->stroffs;
83581+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
83582+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
83583 src = mod->symtab;
83584 for (ndst = i = 0; i < mod->num_symtab; i++) {
83585 if (i == 0 ||
83586@@ -2388,6 +2408,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
83587 }
83588 }
83589 mod->core_num_syms = ndst;
83590+
83591+ pax_close_kernel();
83592 }
83593 #else
83594 static inline void layout_symtab(struct module *mod, struct load_info *info)
83595@@ -2421,17 +2443,33 @@ void * __weak module_alloc(unsigned long size)
83596 return vmalloc_exec(size);
83597 }
83598
83599-static void *module_alloc_update_bounds(unsigned long size)
83600+static void *module_alloc_update_bounds_rw(unsigned long size)
83601 {
83602 void *ret = module_alloc(size);
83603
83604 if (ret) {
83605 mutex_lock(&module_mutex);
83606 /* Update module bounds. */
83607- if ((unsigned long)ret < module_addr_min)
83608- module_addr_min = (unsigned long)ret;
83609- if ((unsigned long)ret + size > module_addr_max)
83610- module_addr_max = (unsigned long)ret + size;
83611+ if ((unsigned long)ret < module_addr_min_rw)
83612+ module_addr_min_rw = (unsigned long)ret;
83613+ if ((unsigned long)ret + size > module_addr_max_rw)
83614+ module_addr_max_rw = (unsigned long)ret + size;
83615+ mutex_unlock(&module_mutex);
83616+ }
83617+ return ret;
83618+}
83619+
83620+static void *module_alloc_update_bounds_rx(unsigned long size)
83621+{
83622+ void *ret = module_alloc_exec(size);
83623+
83624+ if (ret) {
83625+ mutex_lock(&module_mutex);
83626+ /* Update module bounds. */
83627+ if ((unsigned long)ret < module_addr_min_rx)
83628+ module_addr_min_rx = (unsigned long)ret;
83629+ if ((unsigned long)ret + size > module_addr_max_rx)
83630+ module_addr_max_rx = (unsigned long)ret + size;
83631 mutex_unlock(&module_mutex);
83632 }
83633 return ret;
83634@@ -2706,8 +2744,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
83635 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
83636 {
83637 const char *modmagic = get_modinfo(info, "vermagic");
83638+ const char *license = get_modinfo(info, "license");
83639 int err;
83640
83641+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
83642+ if (!license || !license_is_gpl_compatible(license))
83643+ return -ENOEXEC;
83644+#endif
83645+
83646 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
83647 modmagic = NULL;
83648
83649@@ -2733,7 +2777,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
83650 }
83651
83652 /* Set up license info based on the info section */
83653- set_license(mod, get_modinfo(info, "license"));
83654+ set_license(mod, license);
83655
83656 return 0;
83657 }
83658@@ -2814,7 +2858,7 @@ static int move_module(struct module *mod, struct load_info *info)
83659 void *ptr;
83660
83661 /* Do the allocs. */
83662- ptr = module_alloc_update_bounds(mod->core_size);
83663+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
83664 /*
83665 * The pointer to this block is stored in the module structure
83666 * which is inside the block. Just mark it as not being a
83667@@ -2824,11 +2868,11 @@ static int move_module(struct module *mod, struct load_info *info)
83668 if (!ptr)
83669 return -ENOMEM;
83670
83671- memset(ptr, 0, mod->core_size);
83672- mod->module_core = ptr;
83673+ memset(ptr, 0, mod->core_size_rw);
83674+ mod->module_core_rw = ptr;
83675
83676- if (mod->init_size) {
83677- ptr = module_alloc_update_bounds(mod->init_size);
83678+ if (mod->init_size_rw) {
83679+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
83680 /*
83681 * The pointer to this block is stored in the module structure
83682 * which is inside the block. This block doesn't need to be
83683@@ -2837,13 +2881,45 @@ static int move_module(struct module *mod, struct load_info *info)
83684 */
83685 kmemleak_ignore(ptr);
83686 if (!ptr) {
83687- module_free(mod, mod->module_core);
83688+ module_free(mod, mod->module_core_rw);
83689 return -ENOMEM;
83690 }
83691- memset(ptr, 0, mod->init_size);
83692- mod->module_init = ptr;
83693+ memset(ptr, 0, mod->init_size_rw);
83694+ mod->module_init_rw = ptr;
83695 } else
83696- mod->module_init = NULL;
83697+ mod->module_init_rw = NULL;
83698+
83699+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
83700+ kmemleak_not_leak(ptr);
83701+ if (!ptr) {
83702+ if (mod->module_init_rw)
83703+ module_free(mod, mod->module_init_rw);
83704+ module_free(mod, mod->module_core_rw);
83705+ return -ENOMEM;
83706+ }
83707+
83708+ pax_open_kernel();
83709+ memset(ptr, 0, mod->core_size_rx);
83710+ pax_close_kernel();
83711+ mod->module_core_rx = ptr;
83712+
83713+ if (mod->init_size_rx) {
83714+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
83715+ kmemleak_ignore(ptr);
83716+ if (!ptr && mod->init_size_rx) {
83717+ module_free_exec(mod, mod->module_core_rx);
83718+ if (mod->module_init_rw)
83719+ module_free(mod, mod->module_init_rw);
83720+ module_free(mod, mod->module_core_rw);
83721+ return -ENOMEM;
83722+ }
83723+
83724+ pax_open_kernel();
83725+ memset(ptr, 0, mod->init_size_rx);
83726+ pax_close_kernel();
83727+ mod->module_init_rx = ptr;
83728+ } else
83729+ mod->module_init_rx = NULL;
83730
83731 /* Transfer each section which specifies SHF_ALLOC */
83732 pr_debug("final section addresses:\n");
83733@@ -2854,16 +2930,45 @@ static int move_module(struct module *mod, struct load_info *info)
83734 if (!(shdr->sh_flags & SHF_ALLOC))
83735 continue;
83736
83737- if (shdr->sh_entsize & INIT_OFFSET_MASK)
83738- dest = mod->module_init
83739- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83740- else
83741- dest = mod->module_core + shdr->sh_entsize;
83742+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
83743+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83744+ dest = mod->module_init_rw
83745+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83746+ else
83747+ dest = mod->module_init_rx
83748+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83749+ } else {
83750+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83751+ dest = mod->module_core_rw + shdr->sh_entsize;
83752+ else
83753+ dest = mod->module_core_rx + shdr->sh_entsize;
83754+ }
83755+
83756+ if (shdr->sh_type != SHT_NOBITS) {
83757+
83758+#ifdef CONFIG_PAX_KERNEXEC
83759+#ifdef CONFIG_X86_64
83760+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
83761+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
83762+#endif
83763+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
83764+ pax_open_kernel();
83765+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83766+ pax_close_kernel();
83767+ } else
83768+#endif
83769
83770- if (shdr->sh_type != SHT_NOBITS)
83771 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83772+ }
83773 /* Update sh_addr to point to copy in image. */
83774- shdr->sh_addr = (unsigned long)dest;
83775+
83776+#ifdef CONFIG_PAX_KERNEXEC
83777+ if (shdr->sh_flags & SHF_EXECINSTR)
83778+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
83779+ else
83780+#endif
83781+
83782+ shdr->sh_addr = (unsigned long)dest;
83783 pr_debug("\t0x%lx %s\n",
83784 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
83785 }
83786@@ -2920,12 +3025,12 @@ static void flush_module_icache(const struct module *mod)
83787 * Do it before processing of module parameters, so the module
83788 * can provide parameter accessor functions of its own.
83789 */
83790- if (mod->module_init)
83791- flush_icache_range((unsigned long)mod->module_init,
83792- (unsigned long)mod->module_init
83793- + mod->init_size);
83794- flush_icache_range((unsigned long)mod->module_core,
83795- (unsigned long)mod->module_core + mod->core_size);
83796+ if (mod->module_init_rx)
83797+ flush_icache_range((unsigned long)mod->module_init_rx,
83798+ (unsigned long)mod->module_init_rx
83799+ + mod->init_size_rx);
83800+ flush_icache_range((unsigned long)mod->module_core_rx,
83801+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
83802
83803 set_fs(old_fs);
83804 }
83805@@ -2982,8 +3087,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
83806 static void module_deallocate(struct module *mod, struct load_info *info)
83807 {
83808 percpu_modfree(mod);
83809- module_free(mod, mod->module_init);
83810- module_free(mod, mod->module_core);
83811+ module_free_exec(mod, mod->module_init_rx);
83812+ module_free_exec(mod, mod->module_core_rx);
83813+ module_free(mod, mod->module_init_rw);
83814+ module_free(mod, mod->module_core_rw);
83815 }
83816
83817 int __weak module_finalize(const Elf_Ehdr *hdr,
83818@@ -2996,7 +3103,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
83819 static int post_relocation(struct module *mod, const struct load_info *info)
83820 {
83821 /* Sort exception table now relocations are done. */
83822+ pax_open_kernel();
83823 sort_extable(mod->extable, mod->extable + mod->num_exentries);
83824+ pax_close_kernel();
83825
83826 /* Copy relocated percpu area over. */
83827 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
83828@@ -3050,16 +3159,16 @@ static int do_init_module(struct module *mod)
83829 MODULE_STATE_COMING, mod);
83830
83831 /* Set RO and NX regions for core */
83832- set_section_ro_nx(mod->module_core,
83833- mod->core_text_size,
83834- mod->core_ro_size,
83835- mod->core_size);
83836+ set_section_ro_nx(mod->module_core_rx,
83837+ mod->core_size_rx,
83838+ mod->core_size_rx,
83839+ mod->core_size_rx);
83840
83841 /* Set RO and NX regions for init */
83842- set_section_ro_nx(mod->module_init,
83843- mod->init_text_size,
83844- mod->init_ro_size,
83845- mod->init_size);
83846+ set_section_ro_nx(mod->module_init_rx,
83847+ mod->init_size_rx,
83848+ mod->init_size_rx,
83849+ mod->init_size_rx);
83850
83851 do_mod_ctors(mod);
83852 /* Start the module */
83853@@ -3121,11 +3230,12 @@ static int do_init_module(struct module *mod)
83854 mod->strtab = mod->core_strtab;
83855 #endif
83856 unset_module_init_ro_nx(mod);
83857- module_free(mod, mod->module_init);
83858- mod->module_init = NULL;
83859- mod->init_size = 0;
83860- mod->init_ro_size = 0;
83861- mod->init_text_size = 0;
83862+ module_free(mod, mod->module_init_rw);
83863+ module_free_exec(mod, mod->module_init_rx);
83864+ mod->module_init_rw = NULL;
83865+ mod->module_init_rx = NULL;
83866+ mod->init_size_rw = 0;
83867+ mod->init_size_rx = 0;
83868 mutex_unlock(&module_mutex);
83869 wake_up_all(&module_wq);
83870
83871@@ -3269,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
83872 if (err)
83873 goto free_unload;
83874
83875+ /* Now copy in args */
83876+ mod->args = strndup_user(uargs, ~0UL >> 1);
83877+ if (IS_ERR(mod->args)) {
83878+ err = PTR_ERR(mod->args);
83879+ goto free_unload;
83880+ }
83881+
83882 /* Set up MODINFO_ATTR fields */
83883 setup_modinfo(mod, info);
83884
83885+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83886+ {
83887+ char *p, *p2;
83888+
83889+ if (strstr(mod->args, "grsec_modharden_netdev")) {
83890+ 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);
83891+ err = -EPERM;
83892+ goto free_modinfo;
83893+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
83894+ p += sizeof("grsec_modharden_normal") - 1;
83895+ p2 = strstr(p, "_");
83896+ if (p2) {
83897+ *p2 = '\0';
83898+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
83899+ *p2 = '_';
83900+ }
83901+ err = -EPERM;
83902+ goto free_modinfo;
83903+ }
83904+ }
83905+#endif
83906+
83907 /* Fix up syms, so that st_value is a pointer to location. */
83908 err = simplify_symbols(mod, info);
83909 if (err < 0)
83910@@ -3287,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
83911
83912 flush_module_icache(mod);
83913
83914- /* Now copy in args */
83915- mod->args = strndup_user(uargs, ~0UL >> 1);
83916- if (IS_ERR(mod->args)) {
83917- err = PTR_ERR(mod->args);
83918- goto free_arch_cleanup;
83919- }
83920-
83921 dynamic_debug_setup(info->debug, info->num_debug);
83922
83923 /* Finally it's fully formed, ready to start executing. */
83924@@ -3328,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
83925 ddebug_cleanup:
83926 dynamic_debug_remove(info->debug);
83927 synchronize_sched();
83928- kfree(mod->args);
83929- free_arch_cleanup:
83930 module_arch_cleanup(mod);
83931 free_modinfo:
83932 free_modinfo(mod);
83933+ kfree(mod->args);
83934 free_unload:
83935 module_unload_free(mod);
83936 unlink_mod:
83937@@ -3415,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
83938 unsigned long nextval;
83939
83940 /* At worse, next value is at end of module */
83941- if (within_module_init(addr, mod))
83942- nextval = (unsigned long)mod->module_init+mod->init_text_size;
83943+ if (within_module_init_rx(addr, mod))
83944+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
83945+ else if (within_module_init_rw(addr, mod))
83946+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
83947+ else if (within_module_core_rx(addr, mod))
83948+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
83949+ else if (within_module_core_rw(addr, mod))
83950+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
83951 else
83952- nextval = (unsigned long)mod->module_core+mod->core_text_size;
83953+ return NULL;
83954
83955 /* Scan for closest preceding symbol, and next symbol. (ELF
83956 starts real symbols at 1). */
83957@@ -3669,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
83958 return 0;
83959
83960 seq_printf(m, "%s %u",
83961- mod->name, mod->init_size + mod->core_size);
83962+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
83963 print_unload_info(m, mod);
83964
83965 /* Informative for users. */
83966@@ -3678,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
83967 mod->state == MODULE_STATE_COMING ? "Loading":
83968 "Live");
83969 /* Used by oprofile and other similar tools. */
83970- seq_printf(m, " 0x%pK", mod->module_core);
83971+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
83972
83973 /* Taints info */
83974 if (mod->taints)
83975@@ -3714,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
83976
83977 static int __init proc_modules_init(void)
83978 {
83979+#ifndef CONFIG_GRKERNSEC_HIDESYM
83980+#ifdef CONFIG_GRKERNSEC_PROC_USER
83981+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83982+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83983+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
83984+#else
83985 proc_create("modules", 0, NULL, &proc_modules_operations);
83986+#endif
83987+#else
83988+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83989+#endif
83990 return 0;
83991 }
83992 module_init(proc_modules_init);
83993@@ -3775,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
83994 {
83995 struct module *mod;
83996
83997- if (addr < module_addr_min || addr > module_addr_max)
83998+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
83999+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
84000 return NULL;
84001
84002 list_for_each_entry_rcu(mod, &modules, list) {
84003 if (mod->state == MODULE_STATE_UNFORMED)
84004 continue;
84005- if (within_module_core(addr, mod)
84006- || within_module_init(addr, mod))
84007+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
84008 return mod;
84009 }
84010 return NULL;
84011@@ -3817,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
84012 */
84013 struct module *__module_text_address(unsigned long addr)
84014 {
84015- struct module *mod = __module_address(addr);
84016+ struct module *mod;
84017+
84018+#ifdef CONFIG_X86_32
84019+ addr = ktla_ktva(addr);
84020+#endif
84021+
84022+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
84023+ return NULL;
84024+
84025+ mod = __module_address(addr);
84026+
84027 if (mod) {
84028 /* Make sure it's within the text section. */
84029- if (!within(addr, mod->module_init, mod->init_text_size)
84030- && !within(addr, mod->module_core, mod->core_text_size))
84031+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
84032 mod = NULL;
84033 }
84034 return mod;
84035diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
84036index 7e3443f..b2a1e6b 100644
84037--- a/kernel/mutex-debug.c
84038+++ b/kernel/mutex-debug.c
84039@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
84040 }
84041
84042 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84043- struct thread_info *ti)
84044+ struct task_struct *task)
84045 {
84046 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
84047
84048 /* Mark the current thread as blocked on the lock: */
84049- ti->task->blocked_on = waiter;
84050+ task->blocked_on = waiter;
84051 }
84052
84053 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84054- struct thread_info *ti)
84055+ struct task_struct *task)
84056 {
84057 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
84058- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
84059- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
84060- ti->task->blocked_on = NULL;
84061+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
84062+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
84063+ task->blocked_on = NULL;
84064
84065 list_del_init(&waiter->list);
84066 waiter->task = NULL;
84067diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
84068index 0799fd3..d06ae3b 100644
84069--- a/kernel/mutex-debug.h
84070+++ b/kernel/mutex-debug.h
84071@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
84072 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
84073 extern void debug_mutex_add_waiter(struct mutex *lock,
84074 struct mutex_waiter *waiter,
84075- struct thread_info *ti);
84076+ struct task_struct *task);
84077 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
84078- struct thread_info *ti);
84079+ struct task_struct *task);
84080 extern void debug_mutex_unlock(struct mutex *lock);
84081 extern void debug_mutex_init(struct mutex *lock, const char *name,
84082 struct lock_class_key *key);
84083diff --git a/kernel/mutex.c b/kernel/mutex.c
84084index d24105b..15648eb 100644
84085--- a/kernel/mutex.c
84086+++ b/kernel/mutex.c
84087@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
84088 node->locked = 1;
84089 return;
84090 }
84091- ACCESS_ONCE(prev->next) = node;
84092+ ACCESS_ONCE_RW(prev->next) = node;
84093 smp_wmb();
84094 /* Wait until the lock holder passes the lock down */
84095 while (!ACCESS_ONCE(node->locked))
84096@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
84097 while (!(next = ACCESS_ONCE(node->next)))
84098 arch_mutex_cpu_relax();
84099 }
84100- ACCESS_ONCE(next->locked) = 1;
84101+ ACCESS_ONCE_RW(next->locked) = 1;
84102 smp_wmb();
84103 }
84104
84105@@ -520,7 +520,7 @@ slowpath:
84106 goto skip_wait;
84107
84108 debug_mutex_lock_common(lock, &waiter);
84109- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
84110+ debug_mutex_add_waiter(lock, &waiter, task);
84111
84112 /* add waiting tasks to the end of the waitqueue (FIFO): */
84113 list_add_tail(&waiter.list, &lock->wait_list);
84114@@ -564,7 +564,7 @@ slowpath:
84115 schedule_preempt_disabled();
84116 spin_lock_mutex(&lock->wait_lock, flags);
84117 }
84118- mutex_remove_waiter(lock, &waiter, current_thread_info());
84119+ mutex_remove_waiter(lock, &waiter, task);
84120 /* set it to 0 if there are no waiters left: */
84121 if (likely(list_empty(&lock->wait_list)))
84122 atomic_set(&lock->count, 0);
84123@@ -601,7 +601,7 @@ skip_wait:
84124 return 0;
84125
84126 err:
84127- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
84128+ mutex_remove_waiter(lock, &waiter, task);
84129 spin_unlock_mutex(&lock->wait_lock, flags);
84130 debug_mutex_free_waiter(&waiter);
84131 mutex_release(&lock->dep_map, 1, ip);
84132diff --git a/kernel/notifier.c b/kernel/notifier.c
84133index 2d5cc4c..d9ea600 100644
84134--- a/kernel/notifier.c
84135+++ b/kernel/notifier.c
84136@@ -5,6 +5,7 @@
84137 #include <linux/rcupdate.h>
84138 #include <linux/vmalloc.h>
84139 #include <linux/reboot.h>
84140+#include <linux/mm.h>
84141
84142 /*
84143 * Notifier list for kernel code which wants to be called
84144@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
84145 while ((*nl) != NULL) {
84146 if (n->priority > (*nl)->priority)
84147 break;
84148- nl = &((*nl)->next);
84149+ nl = (struct notifier_block **)&((*nl)->next);
84150 }
84151- n->next = *nl;
84152+ pax_open_kernel();
84153+ *(const void **)&n->next = *nl;
84154 rcu_assign_pointer(*nl, n);
84155+ pax_close_kernel();
84156 return 0;
84157 }
84158
84159@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
84160 return 0;
84161 if (n->priority > (*nl)->priority)
84162 break;
84163- nl = &((*nl)->next);
84164+ nl = (struct notifier_block **)&((*nl)->next);
84165 }
84166- n->next = *nl;
84167+ pax_open_kernel();
84168+ *(const void **)&n->next = *nl;
84169 rcu_assign_pointer(*nl, n);
84170+ pax_close_kernel();
84171 return 0;
84172 }
84173
84174@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
84175 {
84176 while ((*nl) != NULL) {
84177 if ((*nl) == n) {
84178+ pax_open_kernel();
84179 rcu_assign_pointer(*nl, n->next);
84180+ pax_close_kernel();
84181 return 0;
84182 }
84183- nl = &((*nl)->next);
84184+ nl = (struct notifier_block **)&((*nl)->next);
84185 }
84186 return -ENOENT;
84187 }
84188diff --git a/kernel/panic.c b/kernel/panic.c
84189index b6c482c..5578061 100644
84190--- a/kernel/panic.c
84191+++ b/kernel/panic.c
84192@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
84193 disable_trace_on_warning();
84194
84195 pr_warn("------------[ cut here ]------------\n");
84196- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
84197+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
84198 raw_smp_processor_id(), current->pid, file, line, caller);
84199
84200 if (args)
84201@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
84202 */
84203 void __stack_chk_fail(void)
84204 {
84205- panic("stack-protector: Kernel stack is corrupted in: %p\n",
84206+ dump_stack();
84207+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
84208 __builtin_return_address(0));
84209 }
84210 EXPORT_SYMBOL(__stack_chk_fail);
84211diff --git a/kernel/pid.c b/kernel/pid.c
84212index 9b9a266..c20ef80 100644
84213--- a/kernel/pid.c
84214+++ b/kernel/pid.c
84215@@ -33,6 +33,7 @@
84216 #include <linux/rculist.h>
84217 #include <linux/bootmem.h>
84218 #include <linux/hash.h>
84219+#include <linux/security.h>
84220 #include <linux/pid_namespace.h>
84221 #include <linux/init_task.h>
84222 #include <linux/syscalls.h>
84223@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
84224
84225 int pid_max = PID_MAX_DEFAULT;
84226
84227-#define RESERVED_PIDS 300
84228+#define RESERVED_PIDS 500
84229
84230 int pid_max_min = RESERVED_PIDS + 1;
84231 int pid_max_max = PID_MAX_LIMIT;
84232@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
84233 */
84234 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
84235 {
84236+ struct task_struct *task;
84237+
84238 rcu_lockdep_assert(rcu_read_lock_held(),
84239 "find_task_by_pid_ns() needs rcu_read_lock()"
84240 " protection");
84241- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
84242+
84243+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
84244+
84245+ if (gr_pid_is_chrooted(task))
84246+ return NULL;
84247+
84248+ return task;
84249 }
84250
84251 struct task_struct *find_task_by_vpid(pid_t vnr)
84252@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
84253 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
84254 }
84255
84256+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
84257+{
84258+ rcu_lockdep_assert(rcu_read_lock_held(),
84259+ "find_task_by_pid_ns() needs rcu_read_lock()"
84260+ " protection");
84261+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
84262+}
84263+
84264 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
84265 {
84266 struct pid *pid;
84267diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
84268index 4208655..19f36a5 100644
84269--- a/kernel/pid_namespace.c
84270+++ b/kernel/pid_namespace.c
84271@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
84272 void __user *buffer, size_t *lenp, loff_t *ppos)
84273 {
84274 struct pid_namespace *pid_ns = task_active_pid_ns(current);
84275- struct ctl_table tmp = *table;
84276+ ctl_table_no_const tmp = *table;
84277
84278 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
84279 return -EPERM;
84280diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
84281index c7f31aa..2b44977 100644
84282--- a/kernel/posix-cpu-timers.c
84283+++ b/kernel/posix-cpu-timers.c
84284@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
84285
84286 static __init int init_posix_cpu_timers(void)
84287 {
84288- struct k_clock process = {
84289+ static struct k_clock process = {
84290 .clock_getres = process_cpu_clock_getres,
84291 .clock_get = process_cpu_clock_get,
84292 .timer_create = process_cpu_timer_create,
84293 .nsleep = process_cpu_nsleep,
84294 .nsleep_restart = process_cpu_nsleep_restart,
84295 };
84296- struct k_clock thread = {
84297+ static struct k_clock thread = {
84298 .clock_getres = thread_cpu_clock_getres,
84299 .clock_get = thread_cpu_clock_get,
84300 .timer_create = thread_cpu_timer_create,
84301diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
84302index 424c2d4..679242f 100644
84303--- a/kernel/posix-timers.c
84304+++ b/kernel/posix-timers.c
84305@@ -43,6 +43,7 @@
84306 #include <linux/hash.h>
84307 #include <linux/posix-clock.h>
84308 #include <linux/posix-timers.h>
84309+#include <linux/grsecurity.h>
84310 #include <linux/syscalls.h>
84311 #include <linux/wait.h>
84312 #include <linux/workqueue.h>
84313@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
84314 * which we beg off on and pass to do_sys_settimeofday().
84315 */
84316
84317-static struct k_clock posix_clocks[MAX_CLOCKS];
84318+static struct k_clock *posix_clocks[MAX_CLOCKS];
84319
84320 /*
84321 * These ones are defined below.
84322@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
84323 */
84324 static __init int init_posix_timers(void)
84325 {
84326- struct k_clock clock_realtime = {
84327+ static struct k_clock clock_realtime = {
84328 .clock_getres = hrtimer_get_res,
84329 .clock_get = posix_clock_realtime_get,
84330 .clock_set = posix_clock_realtime_set,
84331@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
84332 .timer_get = common_timer_get,
84333 .timer_del = common_timer_del,
84334 };
84335- struct k_clock clock_monotonic = {
84336+ static struct k_clock clock_monotonic = {
84337 .clock_getres = hrtimer_get_res,
84338 .clock_get = posix_ktime_get_ts,
84339 .nsleep = common_nsleep,
84340@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
84341 .timer_get = common_timer_get,
84342 .timer_del = common_timer_del,
84343 };
84344- struct k_clock clock_monotonic_raw = {
84345+ static struct k_clock clock_monotonic_raw = {
84346 .clock_getres = hrtimer_get_res,
84347 .clock_get = posix_get_monotonic_raw,
84348 };
84349- struct k_clock clock_realtime_coarse = {
84350+ static struct k_clock clock_realtime_coarse = {
84351 .clock_getres = posix_get_coarse_res,
84352 .clock_get = posix_get_realtime_coarse,
84353 };
84354- struct k_clock clock_monotonic_coarse = {
84355+ static struct k_clock clock_monotonic_coarse = {
84356 .clock_getres = posix_get_coarse_res,
84357 .clock_get = posix_get_monotonic_coarse,
84358 };
84359- struct k_clock clock_tai = {
84360+ static struct k_clock clock_tai = {
84361 .clock_getres = hrtimer_get_res,
84362 .clock_get = posix_get_tai,
84363 .nsleep = common_nsleep,
84364@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
84365 .timer_get = common_timer_get,
84366 .timer_del = common_timer_del,
84367 };
84368- struct k_clock clock_boottime = {
84369+ static struct k_clock clock_boottime = {
84370 .clock_getres = hrtimer_get_res,
84371 .clock_get = posix_get_boottime,
84372 .nsleep = common_nsleep,
84373@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
84374 return;
84375 }
84376
84377- posix_clocks[clock_id] = *new_clock;
84378+ posix_clocks[clock_id] = new_clock;
84379 }
84380 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
84381
84382@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
84383 return (id & CLOCKFD_MASK) == CLOCKFD ?
84384 &clock_posix_dynamic : &clock_posix_cpu;
84385
84386- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
84387+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
84388 return NULL;
84389- return &posix_clocks[id];
84390+ return posix_clocks[id];
84391 }
84392
84393 static int common_timer_create(struct k_itimer *new_timer)
84394@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
84395 struct k_clock *kc = clockid_to_kclock(which_clock);
84396 struct k_itimer *new_timer;
84397 int error, new_timer_id;
84398- sigevent_t event;
84399+ sigevent_t event = { };
84400 int it_id_set = IT_ID_NOT_SET;
84401
84402 if (!kc)
84403@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
84404 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
84405 return -EFAULT;
84406
84407+ /* only the CLOCK_REALTIME clock can be set, all other clocks
84408+ have their clock_set fptr set to a nosettime dummy function
84409+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
84410+ call common_clock_set, which calls do_sys_settimeofday, which
84411+ we hook
84412+ */
84413+
84414 return kc->clock_set(which_clock, &new_tp);
84415 }
84416
84417diff --git a/kernel/power/process.c b/kernel/power/process.c
84418index 06ec886..9dba35e 100644
84419--- a/kernel/power/process.c
84420+++ b/kernel/power/process.c
84421@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
84422 unsigned int elapsed_msecs;
84423 bool wakeup = false;
84424 int sleep_usecs = USEC_PER_MSEC;
84425+ bool timedout = false;
84426
84427 do_gettimeofday(&start);
84428
84429@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
84430
84431 while (true) {
84432 todo = 0;
84433+ if (time_after(jiffies, end_time))
84434+ timedout = true;
84435 read_lock(&tasklist_lock);
84436 do_each_thread(g, p) {
84437 if (p == current || !freeze_task(p))
84438 continue;
84439
84440- if (!freezer_should_skip(p))
84441+ if (!freezer_should_skip(p)) {
84442 todo++;
84443+ if (timedout) {
84444+ printk(KERN_ERR "Task refusing to freeze:\n");
84445+ sched_show_task(p);
84446+ }
84447+ }
84448 } while_each_thread(g, p);
84449 read_unlock(&tasklist_lock);
84450
84451@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
84452 todo += wq_busy;
84453 }
84454
84455- if (!todo || time_after(jiffies, end_time))
84456+ if (!todo || timedout)
84457 break;
84458
84459 if (pm_wakeup_pending()) {
84460diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
84461index b4e8500..b457a6c 100644
84462--- a/kernel/printk/printk.c
84463+++ b/kernel/printk/printk.c
84464@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
84465 if (from_file && type != SYSLOG_ACTION_OPEN)
84466 return 0;
84467
84468+#ifdef CONFIG_GRKERNSEC_DMESG
84469+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
84470+ return -EPERM;
84471+#endif
84472+
84473 if (syslog_action_restricted(type)) {
84474 if (capable(CAP_SYSLOG))
84475 return 0;
84476diff --git a/kernel/profile.c b/kernel/profile.c
84477index 6631e1e..310c266 100644
84478--- a/kernel/profile.c
84479+++ b/kernel/profile.c
84480@@ -37,7 +37,7 @@ struct profile_hit {
84481 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
84482 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
84483
84484-static atomic_t *prof_buffer;
84485+static atomic_unchecked_t *prof_buffer;
84486 static unsigned long prof_len, prof_shift;
84487
84488 int prof_on __read_mostly;
84489@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
84490 hits[i].pc = 0;
84491 continue;
84492 }
84493- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
84494+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
84495 hits[i].hits = hits[i].pc = 0;
84496 }
84497 }
84498@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
84499 * Add the current hit(s) and flush the write-queue out
84500 * to the global buffer:
84501 */
84502- atomic_add(nr_hits, &prof_buffer[pc]);
84503+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
84504 for (i = 0; i < NR_PROFILE_HIT; ++i) {
84505- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
84506+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
84507 hits[i].pc = hits[i].hits = 0;
84508 }
84509 out:
84510@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
84511 {
84512 unsigned long pc;
84513 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
84514- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
84515+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
84516 }
84517 #endif /* !CONFIG_SMP */
84518
84519@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
84520 return -EFAULT;
84521 buf++; p++; count--; read++;
84522 }
84523- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
84524+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
84525 if (copy_to_user(buf, (void *)pnt, count))
84526 return -EFAULT;
84527 read += count;
84528@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
84529 }
84530 #endif
84531 profile_discard_flip_buffers();
84532- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
84533+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
84534 return count;
84535 }
84536
84537diff --git a/kernel/ptrace.c b/kernel/ptrace.c
84538index 1f4bcb3..99cf7ab 100644
84539--- a/kernel/ptrace.c
84540+++ b/kernel/ptrace.c
84541@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
84542 if (seize)
84543 flags |= PT_SEIZED;
84544 rcu_read_lock();
84545- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
84546+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
84547 flags |= PT_PTRACE_CAP;
84548 rcu_read_unlock();
84549 task->ptrace = flags;
84550@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
84551 break;
84552 return -EIO;
84553 }
84554- if (copy_to_user(dst, buf, retval))
84555+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
84556 return -EFAULT;
84557 copied += retval;
84558 src += retval;
84559@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
84560 bool seized = child->ptrace & PT_SEIZED;
84561 int ret = -EIO;
84562 siginfo_t siginfo, *si;
84563- void __user *datavp = (void __user *) data;
84564+ void __user *datavp = (__force void __user *) data;
84565 unsigned long __user *datalp = datavp;
84566 unsigned long flags;
84567
84568@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
84569 goto out;
84570 }
84571
84572+ if (gr_handle_ptrace(child, request)) {
84573+ ret = -EPERM;
84574+ goto out_put_task_struct;
84575+ }
84576+
84577 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
84578 ret = ptrace_attach(child, request, addr, data);
84579 /*
84580 * Some architectures need to do book-keeping after
84581 * a ptrace attach.
84582 */
84583- if (!ret)
84584+ if (!ret) {
84585 arch_ptrace_attach(child);
84586+ gr_audit_ptrace(child);
84587+ }
84588 goto out_put_task_struct;
84589 }
84590
84591@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
84592 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
84593 if (copied != sizeof(tmp))
84594 return -EIO;
84595- return put_user(tmp, (unsigned long __user *)data);
84596+ return put_user(tmp, (__force unsigned long __user *)data);
84597 }
84598
84599 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
84600@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
84601 }
84602
84603 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
84604- compat_long_t addr, compat_long_t data)
84605+ compat_ulong_t addr, compat_ulong_t data)
84606 {
84607 struct task_struct *child;
84608 long ret;
84609@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
84610 goto out;
84611 }
84612
84613+ if (gr_handle_ptrace(child, request)) {
84614+ ret = -EPERM;
84615+ goto out_put_task_struct;
84616+ }
84617+
84618 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
84619 ret = ptrace_attach(child, request, addr, data);
84620 /*
84621 * Some architectures need to do book-keeping after
84622 * a ptrace attach.
84623 */
84624- if (!ret)
84625+ if (!ret) {
84626 arch_ptrace_attach(child);
84627+ gr_audit_ptrace(child);
84628+ }
84629 goto out_put_task_struct;
84630 }
84631
84632diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
84633index b02a339..ce2d20c 100644
84634--- a/kernel/rcupdate.c
84635+++ b/kernel/rcupdate.c
84636@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
84637 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
84638 */
84639 if (till_stall_check < 3) {
84640- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
84641+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
84642 till_stall_check = 3;
84643 } else if (till_stall_check > 300) {
84644- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
84645+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
84646 till_stall_check = 300;
84647 }
84648 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
84649diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
84650index 9ed6075..c9e8a63 100644
84651--- a/kernel/rcutiny.c
84652+++ b/kernel/rcutiny.c
84653@@ -45,7 +45,7 @@
84654 /* Forward declarations for rcutiny_plugin.h. */
84655 struct rcu_ctrlblk;
84656 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
84657-static void rcu_process_callbacks(struct softirq_action *unused);
84658+static void rcu_process_callbacks(void);
84659 static void __call_rcu(struct rcu_head *head,
84660 void (*func)(struct rcu_head *rcu),
84661 struct rcu_ctrlblk *rcp);
84662@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
84663 false));
84664 }
84665
84666-static void rcu_process_callbacks(struct softirq_action *unused)
84667+static __latent_entropy void rcu_process_callbacks(void)
84668 {
84669 __rcu_process_callbacks(&rcu_sched_ctrlblk);
84670 __rcu_process_callbacks(&rcu_bh_ctrlblk);
84671diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
84672index be63101..05cf721 100644
84673--- a/kernel/rcutorture.c
84674+++ b/kernel/rcutorture.c
84675@@ -170,12 +170,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
84676 { 0 };
84677 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
84678 { 0 };
84679-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84680-static atomic_t n_rcu_torture_alloc;
84681-static atomic_t n_rcu_torture_alloc_fail;
84682-static atomic_t n_rcu_torture_free;
84683-static atomic_t n_rcu_torture_mberror;
84684-static atomic_t n_rcu_torture_error;
84685+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84686+static atomic_unchecked_t n_rcu_torture_alloc;
84687+static atomic_unchecked_t n_rcu_torture_alloc_fail;
84688+static atomic_unchecked_t n_rcu_torture_free;
84689+static atomic_unchecked_t n_rcu_torture_mberror;
84690+static atomic_unchecked_t n_rcu_torture_error;
84691 static long n_rcu_torture_barrier_error;
84692 static long n_rcu_torture_boost_ktrerror;
84693 static long n_rcu_torture_boost_rterror;
84694@@ -293,11 +293,11 @@ rcu_torture_alloc(void)
84695
84696 spin_lock_bh(&rcu_torture_lock);
84697 if (list_empty(&rcu_torture_freelist)) {
84698- atomic_inc(&n_rcu_torture_alloc_fail);
84699+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
84700 spin_unlock_bh(&rcu_torture_lock);
84701 return NULL;
84702 }
84703- atomic_inc(&n_rcu_torture_alloc);
84704+ atomic_inc_unchecked(&n_rcu_torture_alloc);
84705 p = rcu_torture_freelist.next;
84706 list_del_init(p);
84707 spin_unlock_bh(&rcu_torture_lock);
84708@@ -310,7 +310,7 @@ rcu_torture_alloc(void)
84709 static void
84710 rcu_torture_free(struct rcu_torture *p)
84711 {
84712- atomic_inc(&n_rcu_torture_free);
84713+ atomic_inc_unchecked(&n_rcu_torture_free);
84714 spin_lock_bh(&rcu_torture_lock);
84715 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
84716 spin_unlock_bh(&rcu_torture_lock);
84717@@ -431,7 +431,7 @@ rcu_torture_cb(struct rcu_head *p)
84718 i = rp->rtort_pipe_count;
84719 if (i > RCU_TORTURE_PIPE_LEN)
84720 i = RCU_TORTURE_PIPE_LEN;
84721- atomic_inc(&rcu_torture_wcount[i]);
84722+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84723 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84724 rp->rtort_mbtest = 0;
84725 rcu_torture_free(rp);
84726@@ -821,7 +821,7 @@ rcu_torture_writer(void *arg)
84727 i = old_rp->rtort_pipe_count;
84728 if (i > RCU_TORTURE_PIPE_LEN)
84729 i = RCU_TORTURE_PIPE_LEN;
84730- atomic_inc(&rcu_torture_wcount[i]);
84731+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84732 old_rp->rtort_pipe_count++;
84733 if (gp_normal == gp_exp)
84734 exp = !!(rcu_random(&rand) & 0x80);
84735@@ -839,7 +839,7 @@ rcu_torture_writer(void *arg)
84736 i = rp->rtort_pipe_count;
84737 if (i > RCU_TORTURE_PIPE_LEN)
84738 i = RCU_TORTURE_PIPE_LEN;
84739- atomic_inc(&rcu_torture_wcount[i]);
84740+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84741 if (++rp->rtort_pipe_count >=
84742 RCU_TORTURE_PIPE_LEN) {
84743 rp->rtort_mbtest = 0;
84744@@ -938,7 +938,7 @@ static void rcu_torture_timer(unsigned long unused)
84745 return;
84746 }
84747 if (p->rtort_mbtest == 0)
84748- atomic_inc(&n_rcu_torture_mberror);
84749+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84750 spin_lock(&rand_lock);
84751 cur_ops->read_delay(&rand);
84752 n_rcu_torture_timers++;
84753@@ -1008,7 +1008,7 @@ rcu_torture_reader(void *arg)
84754 continue;
84755 }
84756 if (p->rtort_mbtest == 0)
84757- atomic_inc(&n_rcu_torture_mberror);
84758+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84759 cur_ops->read_delay(&rand);
84760 preempt_disable();
84761 pipe_count = p->rtort_pipe_count;
84762@@ -1071,11 +1071,11 @@ rcu_torture_printk(char *page)
84763 rcu_torture_current,
84764 rcu_torture_current_version,
84765 list_empty(&rcu_torture_freelist),
84766- atomic_read(&n_rcu_torture_alloc),
84767- atomic_read(&n_rcu_torture_alloc_fail),
84768- atomic_read(&n_rcu_torture_free));
84769+ atomic_read_unchecked(&n_rcu_torture_alloc),
84770+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
84771+ atomic_read_unchecked(&n_rcu_torture_free));
84772 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
84773- atomic_read(&n_rcu_torture_mberror),
84774+ atomic_read_unchecked(&n_rcu_torture_mberror),
84775 n_rcu_torture_boost_ktrerror,
84776 n_rcu_torture_boost_rterror);
84777 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
84778@@ -1094,14 +1094,14 @@ rcu_torture_printk(char *page)
84779 n_barrier_attempts,
84780 n_rcu_torture_barrier_error);
84781 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
84782- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
84783+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
84784 n_rcu_torture_barrier_error != 0 ||
84785 n_rcu_torture_boost_ktrerror != 0 ||
84786 n_rcu_torture_boost_rterror != 0 ||
84787 n_rcu_torture_boost_failure != 0 ||
84788 i > 1) {
84789 cnt += sprintf(&page[cnt], "!!! ");
84790- atomic_inc(&n_rcu_torture_error);
84791+ atomic_inc_unchecked(&n_rcu_torture_error);
84792 WARN_ON_ONCE(1);
84793 }
84794 cnt += sprintf(&page[cnt], "Reader Pipe: ");
84795@@ -1115,7 +1115,7 @@ rcu_torture_printk(char *page)
84796 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
84797 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84798 cnt += sprintf(&page[cnt], " %d",
84799- atomic_read(&rcu_torture_wcount[i]));
84800+ atomic_read_unchecked(&rcu_torture_wcount[i]));
84801 }
84802 cnt += sprintf(&page[cnt], "\n");
84803 if (cur_ops->stats)
84804@@ -1830,7 +1830,7 @@ rcu_torture_cleanup(void)
84805
84806 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
84807
84808- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84809+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84810 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
84811 else if (n_online_successes != n_online_attempts ||
84812 n_offline_successes != n_offline_attempts)
84813@@ -1952,18 +1952,18 @@ rcu_torture_init(void)
84814
84815 rcu_torture_current = NULL;
84816 rcu_torture_current_version = 0;
84817- atomic_set(&n_rcu_torture_alloc, 0);
84818- atomic_set(&n_rcu_torture_alloc_fail, 0);
84819- atomic_set(&n_rcu_torture_free, 0);
84820- atomic_set(&n_rcu_torture_mberror, 0);
84821- atomic_set(&n_rcu_torture_error, 0);
84822+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
84823+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
84824+ atomic_set_unchecked(&n_rcu_torture_free, 0);
84825+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
84826+ atomic_set_unchecked(&n_rcu_torture_error, 0);
84827 n_rcu_torture_barrier_error = 0;
84828 n_rcu_torture_boost_ktrerror = 0;
84829 n_rcu_torture_boost_rterror = 0;
84830 n_rcu_torture_boost_failure = 0;
84831 n_rcu_torture_boosts = 0;
84832 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
84833- atomic_set(&rcu_torture_wcount[i], 0);
84834+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
84835 for_each_possible_cpu(cpu) {
84836 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84837 per_cpu(rcu_torture_count, cpu)[i] = 0;
84838diff --git a/kernel/rcutree.c b/kernel/rcutree.c
84839index 32618b3..c1fb822 100644
84840--- a/kernel/rcutree.c
84841+++ b/kernel/rcutree.c
84842@@ -382,9 +382,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
84843 rcu_prepare_for_idle(smp_processor_id());
84844 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84845 smp_mb__before_atomic_inc(); /* See above. */
84846- atomic_inc(&rdtp->dynticks);
84847+ atomic_inc_unchecked(&rdtp->dynticks);
84848 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
84849- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84850+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84851
84852 /*
84853 * It is illegal to enter an extended quiescent state while
84854@@ -501,10 +501,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
84855 int user)
84856 {
84857 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
84858- atomic_inc(&rdtp->dynticks);
84859+ atomic_inc_unchecked(&rdtp->dynticks);
84860 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84861 smp_mb__after_atomic_inc(); /* See above. */
84862- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84863+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84864 rcu_cleanup_after_idle(smp_processor_id());
84865 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
84866 if (!user && !is_idle_task(current)) {
84867@@ -623,14 +623,14 @@ void rcu_nmi_enter(void)
84868 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
84869
84870 if (rdtp->dynticks_nmi_nesting == 0 &&
84871- (atomic_read(&rdtp->dynticks) & 0x1))
84872+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
84873 return;
84874 rdtp->dynticks_nmi_nesting++;
84875 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
84876- atomic_inc(&rdtp->dynticks);
84877+ atomic_inc_unchecked(&rdtp->dynticks);
84878 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84879 smp_mb__after_atomic_inc(); /* See above. */
84880- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84881+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84882 }
84883
84884 /**
84885@@ -649,9 +649,9 @@ void rcu_nmi_exit(void)
84886 return;
84887 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84888 smp_mb__before_atomic_inc(); /* See above. */
84889- atomic_inc(&rdtp->dynticks);
84890+ atomic_inc_unchecked(&rdtp->dynticks);
84891 smp_mb__after_atomic_inc(); /* Force delay to next write. */
84892- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84893+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84894 }
84895
84896 /**
84897@@ -665,7 +665,7 @@ int rcu_is_cpu_idle(void)
84898 int ret;
84899
84900 preempt_disable();
84901- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84902+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84903 preempt_enable();
84904 return ret;
84905 }
84906@@ -734,7 +734,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
84907 static int dyntick_save_progress_counter(struct rcu_data *rdp,
84908 bool *isidle, unsigned long *maxj)
84909 {
84910- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
84911+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84912 rcu_sysidle_check_cpu(rdp, isidle, maxj);
84913 return (rdp->dynticks_snap & 0x1) == 0;
84914 }
84915@@ -751,7 +751,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
84916 unsigned int curr;
84917 unsigned int snap;
84918
84919- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
84920+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84921 snap = (unsigned int)rdp->dynticks_snap;
84922
84923 /*
84924@@ -1341,9 +1341,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
84925 rdp = this_cpu_ptr(rsp->rda);
84926 rcu_preempt_check_blocked_tasks(rnp);
84927 rnp->qsmask = rnp->qsmaskinit;
84928- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
84929+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
84930 WARN_ON_ONCE(rnp->completed != rsp->completed);
84931- ACCESS_ONCE(rnp->completed) = rsp->completed;
84932+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
84933 if (rnp == rdp->mynode)
84934 __note_gp_changes(rsp, rnp, rdp);
84935 rcu_preempt_boost_start_gp(rnp);
84936@@ -1434,7 +1434,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
84937 */
84938 rcu_for_each_node_breadth_first(rsp, rnp) {
84939 raw_spin_lock_irq(&rnp->lock);
84940- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
84941+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
84942 rdp = this_cpu_ptr(rsp->rda);
84943 if (rnp == rdp->mynode)
84944 __note_gp_changes(rsp, rnp, rdp);
84945@@ -1766,7 +1766,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
84946 rsp->qlen += rdp->qlen;
84947 rdp->n_cbs_orphaned += rdp->qlen;
84948 rdp->qlen_lazy = 0;
84949- ACCESS_ONCE(rdp->qlen) = 0;
84950+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84951 }
84952
84953 /*
84954@@ -2012,7 +2012,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
84955 }
84956 smp_mb(); /* List handling before counting for rcu_barrier(). */
84957 rdp->qlen_lazy -= count_lazy;
84958- ACCESS_ONCE(rdp->qlen) -= count;
84959+ ACCESS_ONCE_RW(rdp->qlen) -= count;
84960 rdp->n_cbs_invoked += count;
84961
84962 /* Reinstate batch limit if we have worked down the excess. */
84963@@ -2209,7 +2209,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
84964 /*
84965 * Do RCU core processing for the current CPU.
84966 */
84967-static void rcu_process_callbacks(struct softirq_action *unused)
84968+static __latent_entropy void rcu_process_callbacks(void)
84969 {
84970 struct rcu_state *rsp;
84971
84972@@ -2316,7 +2316,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84973 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
84974 if (debug_rcu_head_queue(head)) {
84975 /* Probable double call_rcu(), so leak the callback. */
84976- ACCESS_ONCE(head->func) = rcu_leak_callback;
84977+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
84978 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
84979 return;
84980 }
84981@@ -2344,7 +2344,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84982 local_irq_restore(flags);
84983 return;
84984 }
84985- ACCESS_ONCE(rdp->qlen)++;
84986+ ACCESS_ONCE_RW(rdp->qlen)++;
84987 if (lazy)
84988 rdp->qlen_lazy++;
84989 else
84990@@ -2553,11 +2553,11 @@ void synchronize_sched_expedited(void)
84991 * counter wrap on a 32-bit system. Quite a few more CPUs would of
84992 * course be required on a 64-bit system.
84993 */
84994- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
84995+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
84996 (ulong)atomic_long_read(&rsp->expedited_done) +
84997 ULONG_MAX / 8)) {
84998 synchronize_sched();
84999- atomic_long_inc(&rsp->expedited_wrap);
85000+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
85001 return;
85002 }
85003
85004@@ -2565,7 +2565,7 @@ void synchronize_sched_expedited(void)
85005 * Take a ticket. Note that atomic_inc_return() implies a
85006 * full memory barrier.
85007 */
85008- snap = atomic_long_inc_return(&rsp->expedited_start);
85009+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
85010 firstsnap = snap;
85011 get_online_cpus();
85012 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
85013@@ -2578,14 +2578,14 @@ void synchronize_sched_expedited(void)
85014 synchronize_sched_expedited_cpu_stop,
85015 NULL) == -EAGAIN) {
85016 put_online_cpus();
85017- atomic_long_inc(&rsp->expedited_tryfail);
85018+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
85019
85020 /* Check to see if someone else did our work for us. */
85021 s = atomic_long_read(&rsp->expedited_done);
85022 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
85023 /* ensure test happens before caller kfree */
85024 smp_mb__before_atomic_inc(); /* ^^^ */
85025- atomic_long_inc(&rsp->expedited_workdone1);
85026+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
85027 return;
85028 }
85029
85030@@ -2594,7 +2594,7 @@ void synchronize_sched_expedited(void)
85031 udelay(trycount * num_online_cpus());
85032 } else {
85033 wait_rcu_gp(call_rcu_sched);
85034- atomic_long_inc(&rsp->expedited_normal);
85035+ atomic_long_inc_unchecked(&rsp->expedited_normal);
85036 return;
85037 }
85038
85039@@ -2603,7 +2603,7 @@ void synchronize_sched_expedited(void)
85040 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
85041 /* ensure test happens before caller kfree */
85042 smp_mb__before_atomic_inc(); /* ^^^ */
85043- atomic_long_inc(&rsp->expedited_workdone2);
85044+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
85045 return;
85046 }
85047
85048@@ -2615,10 +2615,10 @@ void synchronize_sched_expedited(void)
85049 * period works for us.
85050 */
85051 get_online_cpus();
85052- snap = atomic_long_read(&rsp->expedited_start);
85053+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
85054 smp_mb(); /* ensure read is before try_stop_cpus(). */
85055 }
85056- atomic_long_inc(&rsp->expedited_stoppedcpus);
85057+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
85058
85059 /*
85060 * Everyone up to our most recent fetch is covered by our grace
85061@@ -2627,16 +2627,16 @@ void synchronize_sched_expedited(void)
85062 * than we did already did their update.
85063 */
85064 do {
85065- atomic_long_inc(&rsp->expedited_done_tries);
85066+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
85067 s = atomic_long_read(&rsp->expedited_done);
85068 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
85069 /* ensure test happens before caller kfree */
85070 smp_mb__before_atomic_inc(); /* ^^^ */
85071- atomic_long_inc(&rsp->expedited_done_lost);
85072+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
85073 break;
85074 }
85075 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
85076- atomic_long_inc(&rsp->expedited_done_exit);
85077+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
85078
85079 put_online_cpus();
85080 }
85081@@ -2829,7 +2829,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
85082 * ACCESS_ONCE() to prevent the compiler from speculating
85083 * the increment to precede the early-exit check.
85084 */
85085- ACCESS_ONCE(rsp->n_barrier_done)++;
85086+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
85087 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
85088 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
85089 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
85090@@ -2879,7 +2879,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
85091
85092 /* Increment ->n_barrier_done to prevent duplicate work. */
85093 smp_mb(); /* Keep increment after above mechanism. */
85094- ACCESS_ONCE(rsp->n_barrier_done)++;
85095+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
85096 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
85097 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
85098 smp_mb(); /* Keep increment before caller's subsequent code. */
85099@@ -2924,10 +2924,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
85100 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
85101 init_callback_list(rdp);
85102 rdp->qlen_lazy = 0;
85103- ACCESS_ONCE(rdp->qlen) = 0;
85104+ ACCESS_ONCE_RW(rdp->qlen) = 0;
85105 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
85106 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
85107- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
85108+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
85109 rdp->cpu = cpu;
85110 rdp->rsp = rsp;
85111 rcu_boot_init_nocb_percpu_data(rdp);
85112@@ -2961,8 +2961,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
85113 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
85114 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
85115 rcu_sysidle_init_percpu_data(rdp->dynticks);
85116- atomic_set(&rdp->dynticks->dynticks,
85117- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
85118+ atomic_set_unchecked(&rdp->dynticks->dynticks,
85119+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
85120 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
85121
85122 /* Add CPU to rcu_node bitmasks. */
85123diff --git a/kernel/rcutree.h b/kernel/rcutree.h
85124index 5f97eab..db8f687 100644
85125--- a/kernel/rcutree.h
85126+++ b/kernel/rcutree.h
85127@@ -87,11 +87,11 @@ struct rcu_dynticks {
85128 long long dynticks_nesting; /* Track irq/process nesting level. */
85129 /* Process level is worth LLONG_MAX/2. */
85130 int dynticks_nmi_nesting; /* Track NMI nesting level. */
85131- atomic_t dynticks; /* Even value for idle, else odd. */
85132+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
85133 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
85134 long long dynticks_idle_nesting;
85135 /* irq/process nesting level from idle. */
85136- atomic_t dynticks_idle; /* Even value for idle, else odd. */
85137+ atomic_unchecked_t dynticks_idle; /* Even value for idle, else odd. */
85138 /* "Idle" excludes userspace execution. */
85139 unsigned long dynticks_idle_jiffies;
85140 /* End of last non-NMI non-idle period. */
85141@@ -427,17 +427,17 @@ struct rcu_state {
85142 /* _rcu_barrier(). */
85143 /* End of fields guarded by barrier_mutex. */
85144
85145- atomic_long_t expedited_start; /* Starting ticket. */
85146- atomic_long_t expedited_done; /* Done ticket. */
85147- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
85148- atomic_long_t expedited_tryfail; /* # acquisition failures. */
85149- atomic_long_t expedited_workdone1; /* # done by others #1. */
85150- atomic_long_t expedited_workdone2; /* # done by others #2. */
85151- atomic_long_t expedited_normal; /* # fallbacks to normal. */
85152- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
85153- atomic_long_t expedited_done_tries; /* # tries to update _done. */
85154- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
85155- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
85156+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
85157+ atomic_long_t expedited_done; /* Done ticket. */
85158+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
85159+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
85160+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
85161+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
85162+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
85163+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
85164+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
85165+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
85166+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
85167
85168 unsigned long jiffies_force_qs; /* Time at which to invoke */
85169 /* force_quiescent_state(). */
85170diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
85171index 130c97b..bcbe7f7 100644
85172--- a/kernel/rcutree_plugin.h
85173+++ b/kernel/rcutree_plugin.h
85174@@ -744,7 +744,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
85175 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
85176 {
85177 return !rcu_preempted_readers_exp(rnp) &&
85178- ACCESS_ONCE(rnp->expmask) == 0;
85179+ ACCESS_ONCE_RW(rnp->expmask) == 0;
85180 }
85181
85182 /*
85183@@ -900,7 +900,7 @@ void synchronize_rcu_expedited(void)
85184
85185 /* Clean up and exit. */
85186 smp_mb(); /* ensure expedited GP seen before counter increment. */
85187- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
85188+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
85189 unlock_mb_ret:
85190 mutex_unlock(&sync_rcu_preempt_exp_mutex);
85191 mb_ret:
85192@@ -1474,7 +1474,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
85193 free_cpumask_var(cm);
85194 }
85195
85196-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
85197+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
85198 .store = &rcu_cpu_kthread_task,
85199 .thread_should_run = rcu_cpu_kthread_should_run,
85200 .thread_fn = rcu_cpu_kthread,
85201@@ -1939,7 +1939,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
85202 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
85203 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
85204 cpu, ticks_value, ticks_title,
85205- atomic_read(&rdtp->dynticks) & 0xfff,
85206+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
85207 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
85208 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
85209 fast_no_hz);
85210@@ -2102,7 +2102,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
85211
85212 /* Enqueue the callback on the nocb list and update counts. */
85213 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
85214- ACCESS_ONCE(*old_rhpp) = rhp;
85215+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
85216 atomic_long_add(rhcount, &rdp->nocb_q_count);
85217 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
85218
85219@@ -2242,12 +2242,12 @@ static int rcu_nocb_kthread(void *arg)
85220 * Extract queued callbacks, update counts, and wait
85221 * for a grace period to elapse.
85222 */
85223- ACCESS_ONCE(rdp->nocb_head) = NULL;
85224+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
85225 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
85226 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
85227 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
85228- ACCESS_ONCE(rdp->nocb_p_count) += c;
85229- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
85230+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
85231+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
85232 rcu_nocb_wait_gp(rdp);
85233
85234 /* Each pass through the following loop invokes a callback. */
85235@@ -2269,8 +2269,8 @@ static int rcu_nocb_kthread(void *arg)
85236 list = next;
85237 }
85238 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
85239- ACCESS_ONCE(rdp->nocb_p_count) -= c;
85240- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
85241+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
85242+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
85243 rdp->n_nocbs_invoked += c;
85244 }
85245 return 0;
85246@@ -2297,7 +2297,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
85247 t = kthread_run(rcu_nocb_kthread, rdp,
85248 "rcuo%c/%d", rsp->abbr, cpu);
85249 BUG_ON(IS_ERR(t));
85250- ACCESS_ONCE(rdp->nocb_kthread) = t;
85251+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
85252 }
85253 }
85254
85255@@ -2423,11 +2423,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
85256
85257 /* Record start of fully idle period. */
85258 j = jiffies;
85259- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
85260+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
85261 smp_mb__before_atomic_inc();
85262- atomic_inc(&rdtp->dynticks_idle);
85263+ atomic_inc_unchecked(&rdtp->dynticks_idle);
85264 smp_mb__after_atomic_inc();
85265- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
85266+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
85267 }
85268
85269 /*
85270@@ -2492,9 +2492,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
85271
85272 /* Record end of idle period. */
85273 smp_mb__before_atomic_inc();
85274- atomic_inc(&rdtp->dynticks_idle);
85275+ atomic_inc_unchecked(&rdtp->dynticks_idle);
85276 smp_mb__after_atomic_inc();
85277- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
85278+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
85279
85280 /*
85281 * If we are the timekeeping CPU, we are permitted to be non-idle
85282@@ -2535,7 +2535,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
85283 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
85284
85285 /* Pick up current idle and NMI-nesting counter and check. */
85286- cur = atomic_read(&rdtp->dynticks_idle);
85287+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
85288 if (cur & 0x1) {
85289 *isidle = false; /* We are not idle! */
85290 return;
85291@@ -2598,7 +2598,7 @@ static void rcu_sysidle(unsigned long j)
85292 case RCU_SYSIDLE_NOT:
85293
85294 /* First time all are idle, so note a short idle period. */
85295- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
85296+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
85297 break;
85298
85299 case RCU_SYSIDLE_SHORT:
85300@@ -2635,7 +2635,7 @@ static void rcu_sysidle(unsigned long j)
85301 static void rcu_sysidle_cancel(void)
85302 {
85303 smp_mb();
85304- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
85305+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
85306 }
85307
85308 /*
85309@@ -2683,7 +2683,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
85310 smp_mb(); /* grace period precedes setting inuse. */
85311
85312 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
85313- ACCESS_ONCE(rshp->inuse) = 0;
85314+ ACCESS_ONCE_RW(rshp->inuse) = 0;
85315 }
85316
85317 /*
85318diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
85319index cf6c174..a8f4b50 100644
85320--- a/kernel/rcutree_trace.c
85321+++ b/kernel/rcutree_trace.c
85322@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
85323 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
85324 rdp->passed_quiesce, rdp->qs_pending);
85325 seq_printf(m, " dt=%d/%llx/%d df=%lu",
85326- atomic_read(&rdp->dynticks->dynticks),
85327+ atomic_read_unchecked(&rdp->dynticks->dynticks),
85328 rdp->dynticks->dynticks_nesting,
85329 rdp->dynticks->dynticks_nmi_nesting,
85330 rdp->dynticks_fqs);
85331@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
85332 struct rcu_state *rsp = (struct rcu_state *)m->private;
85333
85334 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",
85335- atomic_long_read(&rsp->expedited_start),
85336+ atomic_long_read_unchecked(&rsp->expedited_start),
85337 atomic_long_read(&rsp->expedited_done),
85338- atomic_long_read(&rsp->expedited_wrap),
85339- atomic_long_read(&rsp->expedited_tryfail),
85340- atomic_long_read(&rsp->expedited_workdone1),
85341- atomic_long_read(&rsp->expedited_workdone2),
85342- atomic_long_read(&rsp->expedited_normal),
85343- atomic_long_read(&rsp->expedited_stoppedcpus),
85344- atomic_long_read(&rsp->expedited_done_tries),
85345- atomic_long_read(&rsp->expedited_done_lost),
85346- atomic_long_read(&rsp->expedited_done_exit));
85347+ atomic_long_read_unchecked(&rsp->expedited_wrap),
85348+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
85349+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
85350+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
85351+ atomic_long_read_unchecked(&rsp->expedited_normal),
85352+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
85353+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
85354+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
85355+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
85356 return 0;
85357 }
85358
85359diff --git a/kernel/resource.c b/kernel/resource.c
85360index 3f285dc..5755f62 100644
85361--- a/kernel/resource.c
85362+++ b/kernel/resource.c
85363@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
85364
85365 static int __init ioresources_init(void)
85366 {
85367+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85368+#ifdef CONFIG_GRKERNSEC_PROC_USER
85369+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
85370+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
85371+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85372+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
85373+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
85374+#endif
85375+#else
85376 proc_create("ioports", 0, NULL, &proc_ioports_operations);
85377 proc_create("iomem", 0, NULL, &proc_iomem_operations);
85378+#endif
85379 return 0;
85380 }
85381 __initcall(ioresources_init);
85382diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
85383index 1d96dd0..994ff19 100644
85384--- a/kernel/rtmutex-tester.c
85385+++ b/kernel/rtmutex-tester.c
85386@@ -22,7 +22,7 @@
85387 #define MAX_RT_TEST_MUTEXES 8
85388
85389 static spinlock_t rttest_lock;
85390-static atomic_t rttest_event;
85391+static atomic_unchecked_t rttest_event;
85392
85393 struct test_thread_data {
85394 int opcode;
85395@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85396
85397 case RTTEST_LOCKCONT:
85398 td->mutexes[td->opdata] = 1;
85399- td->event = atomic_add_return(1, &rttest_event);
85400+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85401 return 0;
85402
85403 case RTTEST_RESET:
85404@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85405 return 0;
85406
85407 case RTTEST_RESETEVENT:
85408- atomic_set(&rttest_event, 0);
85409+ atomic_set_unchecked(&rttest_event, 0);
85410 return 0;
85411
85412 default:
85413@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85414 return ret;
85415
85416 td->mutexes[id] = 1;
85417- td->event = atomic_add_return(1, &rttest_event);
85418+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85419 rt_mutex_lock(&mutexes[id]);
85420- td->event = atomic_add_return(1, &rttest_event);
85421+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85422 td->mutexes[id] = 4;
85423 return 0;
85424
85425@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85426 return ret;
85427
85428 td->mutexes[id] = 1;
85429- td->event = atomic_add_return(1, &rttest_event);
85430+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85431 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85432- td->event = atomic_add_return(1, &rttest_event);
85433+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85434 td->mutexes[id] = ret ? 0 : 4;
85435 return ret ? -EINTR : 0;
85436
85437@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85438 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85439 return ret;
85440
85441- td->event = atomic_add_return(1, &rttest_event);
85442+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85443 rt_mutex_unlock(&mutexes[id]);
85444- td->event = atomic_add_return(1, &rttest_event);
85445+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85446 td->mutexes[id] = 0;
85447 return 0;
85448
85449@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85450 break;
85451
85452 td->mutexes[dat] = 2;
85453- td->event = atomic_add_return(1, &rttest_event);
85454+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85455 break;
85456
85457 default:
85458@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85459 return;
85460
85461 td->mutexes[dat] = 3;
85462- td->event = atomic_add_return(1, &rttest_event);
85463+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85464 break;
85465
85466 case RTTEST_LOCKNOWAIT:
85467@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85468 return;
85469
85470 td->mutexes[dat] = 1;
85471- td->event = atomic_add_return(1, &rttest_event);
85472+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85473 return;
85474
85475 default:
85476diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
85477index 4a07353..66b5291 100644
85478--- a/kernel/sched/auto_group.c
85479+++ b/kernel/sched/auto_group.c
85480@@ -11,7 +11,7 @@
85481
85482 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
85483 static struct autogroup autogroup_default;
85484-static atomic_t autogroup_seq_nr;
85485+static atomic_unchecked_t autogroup_seq_nr;
85486
85487 void __init autogroup_init(struct task_struct *init_task)
85488 {
85489@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
85490
85491 kref_init(&ag->kref);
85492 init_rwsem(&ag->lock);
85493- ag->id = atomic_inc_return(&autogroup_seq_nr);
85494+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
85495 ag->tg = tg;
85496 #ifdef CONFIG_RT_GROUP_SCHED
85497 /*
85498diff --git a/kernel/sched/core.c b/kernel/sched/core.c
85499index 5ac63c9..d912786 100644
85500--- a/kernel/sched/core.c
85501+++ b/kernel/sched/core.c
85502@@ -2868,7 +2868,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
85503 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
85504 * or number of jiffies left till timeout) if completed.
85505 */
85506-long __sched
85507+long __sched __intentional_overflow(-1)
85508 wait_for_completion_interruptible_timeout(struct completion *x,
85509 unsigned long timeout)
85510 {
85511@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
85512 *
85513 * Return: -ERESTARTSYS if interrupted, 0 if completed.
85514 */
85515-int __sched wait_for_completion_killable(struct completion *x)
85516+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
85517 {
85518 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
85519 if (t == -ERESTARTSYS)
85520@@ -2906,7 +2906,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
85521 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
85522 * or number of jiffies left till timeout) if completed.
85523 */
85524-long __sched
85525+long __sched __intentional_overflow(-1)
85526 wait_for_completion_killable_timeout(struct completion *x,
85527 unsigned long timeout)
85528 {
85529@@ -3132,6 +3132,8 @@ int can_nice(const struct task_struct *p, const int nice)
85530 /* convert nice value [19,-20] to rlimit style value [1,40] */
85531 int nice_rlim = 20 - nice;
85532
85533+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
85534+
85535 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
85536 capable(CAP_SYS_NICE));
85537 }
85538@@ -3165,7 +3167,8 @@ SYSCALL_DEFINE1(nice, int, increment)
85539 if (nice > 19)
85540 nice = 19;
85541
85542- if (increment < 0 && !can_nice(current, nice))
85543+ if (increment < 0 && (!can_nice(current, nice) ||
85544+ gr_handle_chroot_nice()))
85545 return -EPERM;
85546
85547 retval = security_task_setnice(current, nice);
85548@@ -3327,6 +3330,7 @@ recheck:
85549 unsigned long rlim_rtprio =
85550 task_rlimit(p, RLIMIT_RTPRIO);
85551
85552+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
85553 /* can't set/change the rt policy */
85554 if (policy != p->policy && !rlim_rtprio)
85555 return -EPERM;
85556@@ -4456,7 +4460,7 @@ static void migrate_tasks(unsigned int dead_cpu)
85557
85558 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
85559
85560-static struct ctl_table sd_ctl_dir[] = {
85561+static ctl_table_no_const sd_ctl_dir[] __read_only = {
85562 {
85563 .procname = "sched_domain",
85564 .mode = 0555,
85565@@ -4473,17 +4477,17 @@ static struct ctl_table sd_ctl_root[] = {
85566 {}
85567 };
85568
85569-static struct ctl_table *sd_alloc_ctl_entry(int n)
85570+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
85571 {
85572- struct ctl_table *entry =
85573+ ctl_table_no_const *entry =
85574 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
85575
85576 return entry;
85577 }
85578
85579-static void sd_free_ctl_entry(struct ctl_table **tablep)
85580+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
85581 {
85582- struct ctl_table *entry;
85583+ ctl_table_no_const *entry;
85584
85585 /*
85586 * In the intermediate directories, both the child directory and
85587@@ -4491,22 +4495,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
85588 * will always be set. In the lowest directory the names are
85589 * static strings and all have proc handlers.
85590 */
85591- for (entry = *tablep; entry->mode; entry++) {
85592- if (entry->child)
85593- sd_free_ctl_entry(&entry->child);
85594+ for (entry = tablep; entry->mode; entry++) {
85595+ if (entry->child) {
85596+ sd_free_ctl_entry(entry->child);
85597+ pax_open_kernel();
85598+ entry->child = NULL;
85599+ pax_close_kernel();
85600+ }
85601 if (entry->proc_handler == NULL)
85602 kfree(entry->procname);
85603 }
85604
85605- kfree(*tablep);
85606- *tablep = NULL;
85607+ kfree(tablep);
85608 }
85609
85610 static int min_load_idx = 0;
85611 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
85612
85613 static void
85614-set_table_entry(struct ctl_table *entry,
85615+set_table_entry(ctl_table_no_const *entry,
85616 const char *procname, void *data, int maxlen,
85617 umode_t mode, proc_handler *proc_handler,
85618 bool load_idx)
85619@@ -4526,7 +4533,7 @@ set_table_entry(struct ctl_table *entry,
85620 static struct ctl_table *
85621 sd_alloc_ctl_domain_table(struct sched_domain *sd)
85622 {
85623- struct ctl_table *table = sd_alloc_ctl_entry(13);
85624+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
85625
85626 if (table == NULL)
85627 return NULL;
85628@@ -4561,9 +4568,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
85629 return table;
85630 }
85631
85632-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
85633+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
85634 {
85635- struct ctl_table *entry, *table;
85636+ ctl_table_no_const *entry, *table;
85637 struct sched_domain *sd;
85638 int domain_num = 0, i;
85639 char buf[32];
85640@@ -4590,11 +4597,13 @@ static struct ctl_table_header *sd_sysctl_header;
85641 static void register_sched_domain_sysctl(void)
85642 {
85643 int i, cpu_num = num_possible_cpus();
85644- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
85645+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
85646 char buf[32];
85647
85648 WARN_ON(sd_ctl_dir[0].child);
85649+ pax_open_kernel();
85650 sd_ctl_dir[0].child = entry;
85651+ pax_close_kernel();
85652
85653 if (entry == NULL)
85654 return;
85655@@ -4617,8 +4626,12 @@ static void unregister_sched_domain_sysctl(void)
85656 if (sd_sysctl_header)
85657 unregister_sysctl_table(sd_sysctl_header);
85658 sd_sysctl_header = NULL;
85659- if (sd_ctl_dir[0].child)
85660- sd_free_ctl_entry(&sd_ctl_dir[0].child);
85661+ if (sd_ctl_dir[0].child) {
85662+ sd_free_ctl_entry(sd_ctl_dir[0].child);
85663+ pax_open_kernel();
85664+ sd_ctl_dir[0].child = NULL;
85665+ pax_close_kernel();
85666+ }
85667 }
85668 #else
85669 static void register_sched_domain_sysctl(void)
85670diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
85671index 7c70201..23f52b6 100644
85672--- a/kernel/sched/fair.c
85673+++ b/kernel/sched/fair.c
85674@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
85675
85676 static void reset_ptenuma_scan(struct task_struct *p)
85677 {
85678- ACCESS_ONCE(p->mm->numa_scan_seq)++;
85679+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
85680 p->mm->numa_scan_offset = 0;
85681 }
85682
85683@@ -5838,7 +5838,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
85684 * run_rebalance_domains is triggered when needed from the scheduler tick.
85685 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
85686 */
85687-static void run_rebalance_domains(struct softirq_action *h)
85688+static __latent_entropy void run_rebalance_domains(void)
85689 {
85690 int this_cpu = smp_processor_id();
85691 struct rq *this_rq = cpu_rq(this_cpu);
85692diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
85693index b3c5653..a4d192a 100644
85694--- a/kernel/sched/sched.h
85695+++ b/kernel/sched/sched.h
85696@@ -1004,7 +1004,7 @@ struct sched_class {
85697 #ifdef CONFIG_FAIR_GROUP_SCHED
85698 void (*task_move_group) (struct task_struct *p, int on_rq);
85699 #endif
85700-};
85701+} __do_const;
85702
85703 #define sched_class_highest (&stop_sched_class)
85704 #define for_each_class(class) \
85705diff --git a/kernel/signal.c b/kernel/signal.c
85706index ded28b9..6886c08 100644
85707--- a/kernel/signal.c
85708+++ b/kernel/signal.c
85709@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
85710
85711 int print_fatal_signals __read_mostly;
85712
85713-static void __user *sig_handler(struct task_struct *t, int sig)
85714+static __sighandler_t sig_handler(struct task_struct *t, int sig)
85715 {
85716 return t->sighand->action[sig - 1].sa.sa_handler;
85717 }
85718
85719-static int sig_handler_ignored(void __user *handler, int sig)
85720+static int sig_handler_ignored(__sighandler_t handler, int sig)
85721 {
85722 /* Is it explicitly or implicitly ignored? */
85723 return handler == SIG_IGN ||
85724@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
85725
85726 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
85727 {
85728- void __user *handler;
85729+ __sighandler_t handler;
85730
85731 handler = sig_handler(t, sig);
85732
85733@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
85734 atomic_inc(&user->sigpending);
85735 rcu_read_unlock();
85736
85737+ if (!override_rlimit)
85738+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
85739+
85740 if (override_rlimit ||
85741 atomic_read(&user->sigpending) <=
85742 task_rlimit(t, RLIMIT_SIGPENDING)) {
85743@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
85744
85745 int unhandled_signal(struct task_struct *tsk, int sig)
85746 {
85747- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
85748+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
85749 if (is_global_init(tsk))
85750 return 1;
85751 if (handler != SIG_IGN && handler != SIG_DFL)
85752@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
85753 }
85754 }
85755
85756+ /* allow glibc communication via tgkill to other threads in our
85757+ thread group */
85758+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
85759+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
85760+ && gr_handle_signal(t, sig))
85761+ return -EPERM;
85762+
85763 return security_task_kill(t, info, sig, 0);
85764 }
85765
85766@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85767 return send_signal(sig, info, p, 1);
85768 }
85769
85770-static int
85771+int
85772 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85773 {
85774 return send_signal(sig, info, t, 0);
85775@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85776 unsigned long int flags;
85777 int ret, blocked, ignored;
85778 struct k_sigaction *action;
85779+ int is_unhandled = 0;
85780
85781 spin_lock_irqsave(&t->sighand->siglock, flags);
85782 action = &t->sighand->action[sig-1];
85783@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85784 }
85785 if (action->sa.sa_handler == SIG_DFL)
85786 t->signal->flags &= ~SIGNAL_UNKILLABLE;
85787+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
85788+ is_unhandled = 1;
85789 ret = specific_send_sig_info(sig, info, t);
85790 spin_unlock_irqrestore(&t->sighand->siglock, flags);
85791
85792+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
85793+ normal operation */
85794+ if (is_unhandled) {
85795+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
85796+ gr_handle_crash(t, sig);
85797+ }
85798+
85799 return ret;
85800 }
85801
85802@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85803 ret = check_kill_permission(sig, info, p);
85804 rcu_read_unlock();
85805
85806- if (!ret && sig)
85807+ if (!ret && sig) {
85808 ret = do_send_sig_info(sig, info, p, true);
85809+ if (!ret)
85810+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
85811+ }
85812
85813 return ret;
85814 }
85815@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
85816 int error = -ESRCH;
85817
85818 rcu_read_lock();
85819- p = find_task_by_vpid(pid);
85820+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
85821+ /* allow glibc communication via tgkill to other threads in our
85822+ thread group */
85823+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
85824+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
85825+ p = find_task_by_vpid_unrestricted(pid);
85826+ else
85827+#endif
85828+ p = find_task_by_vpid(pid);
85829 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
85830 error = check_kill_permission(sig, info, p);
85831 /*
85832@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
85833 }
85834 seg = get_fs();
85835 set_fs(KERNEL_DS);
85836- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
85837- (stack_t __force __user *) &uoss,
85838+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
85839+ (stack_t __force_user *) &uoss,
85840 compat_user_stack_pointer());
85841 set_fs(seg);
85842 if (ret >= 0 && uoss_ptr) {
85843diff --git a/kernel/smpboot.c b/kernel/smpboot.c
85844index eb89e18..a4e6792 100644
85845--- a/kernel/smpboot.c
85846+++ b/kernel/smpboot.c
85847@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
85848 }
85849 smpboot_unpark_thread(plug_thread, cpu);
85850 }
85851- list_add(&plug_thread->list, &hotplug_threads);
85852+ pax_list_add(&plug_thread->list, &hotplug_threads);
85853 out:
85854 mutex_unlock(&smpboot_threads_lock);
85855 return ret;
85856@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
85857 {
85858 get_online_cpus();
85859 mutex_lock(&smpboot_threads_lock);
85860- list_del(&plug_thread->list);
85861+ pax_list_del(&plug_thread->list);
85862 smpboot_destroy_threads(plug_thread);
85863 mutex_unlock(&smpboot_threads_lock);
85864 put_online_cpus();
85865diff --git a/kernel/softirq.c b/kernel/softirq.c
85866index d7d498d..94fe0f7 100644
85867--- a/kernel/softirq.c
85868+++ b/kernel/softirq.c
85869@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
85870 EXPORT_SYMBOL(irq_stat);
85871 #endif
85872
85873-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
85874+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
85875
85876 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
85877
85878-char *softirq_to_name[NR_SOFTIRQS] = {
85879+const char * const softirq_to_name[NR_SOFTIRQS] = {
85880 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
85881 "TASKLET", "SCHED", "HRTIMER", "RCU"
85882 };
85883@@ -248,7 +248,7 @@ restart:
85884 kstat_incr_softirqs_this_cpu(vec_nr);
85885
85886 trace_softirq_entry(vec_nr);
85887- h->action(h);
85888+ h->action();
85889 trace_softirq_exit(vec_nr);
85890 if (unlikely(prev_count != preempt_count())) {
85891 printk(KERN_ERR "huh, entered softirq %u %s %p"
85892@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
85893 or_softirq_pending(1UL << nr);
85894 }
85895
85896-void open_softirq(int nr, void (*action)(struct softirq_action *))
85897+void __init open_softirq(int nr, void (*action)(void))
85898 {
85899 softirq_vec[nr].action = action;
85900 }
85901@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
85902
85903 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
85904
85905-static void tasklet_action(struct softirq_action *a)
85906+static __latent_entropy void tasklet_action(void)
85907 {
85908 struct tasklet_struct *list;
85909
85910@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
85911 }
85912 }
85913
85914-static void tasklet_hi_action(struct softirq_action *a)
85915+static __latent_entropy void tasklet_hi_action(void)
85916 {
85917 struct tasklet_struct *list;
85918
85919@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
85920 .notifier_call = cpu_callback
85921 };
85922
85923-static struct smp_hotplug_thread softirq_threads = {
85924+static struct smp_hotplug_thread softirq_threads __read_only = {
85925 .store = &ksoftirqd,
85926 .thread_should_run = ksoftirqd_should_run,
85927 .thread_fn = run_ksoftirqd,
85928diff --git a/kernel/srcu.c b/kernel/srcu.c
85929index 01d5ccb..cdcbee6 100644
85930--- a/kernel/srcu.c
85931+++ b/kernel/srcu.c
85932@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
85933
85934 idx = ACCESS_ONCE(sp->completed) & 0x1;
85935 preempt_disable();
85936- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85937+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85938 smp_mb(); /* B */ /* Avoid leaking the critical section. */
85939- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85940+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85941 preempt_enable();
85942 return idx;
85943 }
85944diff --git a/kernel/sys.c b/kernel/sys.c
85945index c18ecca..b3c2dd2 100644
85946--- a/kernel/sys.c
85947+++ b/kernel/sys.c
85948@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
85949 error = -EACCES;
85950 goto out;
85951 }
85952+
85953+ if (gr_handle_chroot_setpriority(p, niceval)) {
85954+ error = -EACCES;
85955+ goto out;
85956+ }
85957+
85958 no_nice = security_task_setnice(p, niceval);
85959 if (no_nice) {
85960 error = no_nice;
85961@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
85962 goto error;
85963 }
85964
85965+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
85966+ goto error;
85967+
85968 if (rgid != (gid_t) -1 ||
85969 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
85970 new->sgid = new->egid;
85971@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
85972 old = current_cred();
85973
85974 retval = -EPERM;
85975+
85976+ if (gr_check_group_change(kgid, kgid, kgid))
85977+ goto error;
85978+
85979 if (ns_capable(old->user_ns, CAP_SETGID))
85980 new->gid = new->egid = new->sgid = new->fsgid = kgid;
85981 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
85982@@ -404,7 +417,7 @@ error:
85983 /*
85984 * change the user struct in a credentials set to match the new UID
85985 */
85986-static int set_user(struct cred *new)
85987+int set_user(struct cred *new)
85988 {
85989 struct user_struct *new_user;
85990
85991@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
85992 goto error;
85993 }
85994
85995+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
85996+ goto error;
85997+
85998 if (!uid_eq(new->uid, old->uid)) {
85999 retval = set_user(new);
86000 if (retval < 0)
86001@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
86002 old = current_cred();
86003
86004 retval = -EPERM;
86005+
86006+ if (gr_check_crash_uid(kuid))
86007+ goto error;
86008+ if (gr_check_user_change(kuid, kuid, kuid))
86009+ goto error;
86010+
86011 if (ns_capable(old->user_ns, CAP_SETUID)) {
86012 new->suid = new->uid = kuid;
86013 if (!uid_eq(kuid, old->uid)) {
86014@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
86015 goto error;
86016 }
86017
86018+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
86019+ goto error;
86020+
86021 if (ruid != (uid_t) -1) {
86022 new->uid = kruid;
86023 if (!uid_eq(kruid, old->uid)) {
86024@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
86025 goto error;
86026 }
86027
86028+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
86029+ goto error;
86030+
86031 if (rgid != (gid_t) -1)
86032 new->gid = krgid;
86033 if (egid != (gid_t) -1)
86034@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
86035 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
86036 ns_capable(old->user_ns, CAP_SETUID)) {
86037 if (!uid_eq(kuid, old->fsuid)) {
86038+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
86039+ goto error;
86040+
86041 new->fsuid = kuid;
86042 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
86043 goto change_okay;
86044 }
86045 }
86046
86047+error:
86048 abort_creds(new);
86049 return old_fsuid;
86050
86051@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
86052 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
86053 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
86054 ns_capable(old->user_ns, CAP_SETGID)) {
86055+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
86056+ goto error;
86057+
86058 if (!gid_eq(kgid, old->fsgid)) {
86059 new->fsgid = kgid;
86060 goto change_okay;
86061 }
86062 }
86063
86064+error:
86065 abort_creds(new);
86066 return old_fsgid;
86067
86068@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
86069 return -EFAULT;
86070
86071 down_read(&uts_sem);
86072- error = __copy_to_user(&name->sysname, &utsname()->sysname,
86073+ error = __copy_to_user(name->sysname, &utsname()->sysname,
86074 __OLD_UTS_LEN);
86075 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
86076- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
86077+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
86078 __OLD_UTS_LEN);
86079 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
86080- error |= __copy_to_user(&name->release, &utsname()->release,
86081+ error |= __copy_to_user(name->release, &utsname()->release,
86082 __OLD_UTS_LEN);
86083 error |= __put_user(0, name->release + __OLD_UTS_LEN);
86084- error |= __copy_to_user(&name->version, &utsname()->version,
86085+ error |= __copy_to_user(name->version, &utsname()->version,
86086 __OLD_UTS_LEN);
86087 error |= __put_user(0, name->version + __OLD_UTS_LEN);
86088- error |= __copy_to_user(&name->machine, &utsname()->machine,
86089+ error |= __copy_to_user(name->machine, &utsname()->machine,
86090 __OLD_UTS_LEN);
86091 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
86092 up_read(&uts_sem);
86093@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
86094 */
86095 new_rlim->rlim_cur = 1;
86096 }
86097+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
86098+ is changed to a lower value. Since tasks can be created by the same
86099+ user in between this limit change and an execve by this task, force
86100+ a recheck only for this task by setting PF_NPROC_EXCEEDED
86101+ */
86102+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
86103+ tsk->flags |= PF_NPROC_EXCEEDED;
86104 }
86105 if (!retval) {
86106 if (old_rlim)
86107diff --git a/kernel/sysctl.c b/kernel/sysctl.c
86108index b2f06f3..e6354ab 100644
86109--- a/kernel/sysctl.c
86110+++ b/kernel/sysctl.c
86111@@ -93,7 +93,6 @@
86112
86113
86114 #if defined(CONFIG_SYSCTL)
86115-
86116 /* External variables not in a header file. */
86117 extern int sysctl_overcommit_memory;
86118 extern int sysctl_overcommit_ratio;
86119@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
86120
86121 /* Constants used for minimum and maximum */
86122 #ifdef CONFIG_LOCKUP_DETECTOR
86123-static int sixty = 60;
86124+static int sixty __read_only = 60;
86125 #endif
86126
86127-static int zero;
86128-static int __maybe_unused one = 1;
86129-static int __maybe_unused two = 2;
86130-static int __maybe_unused three = 3;
86131-static unsigned long one_ul = 1;
86132-static int one_hundred = 100;
86133+static int neg_one __read_only = -1;
86134+static int zero __read_only = 0;
86135+static int __maybe_unused one __read_only = 1;
86136+static int __maybe_unused two __read_only = 2;
86137+static int __maybe_unused three __read_only = 3;
86138+static unsigned long one_ul __read_only = 1;
86139+static int one_hundred __read_only = 100;
86140 #ifdef CONFIG_PRINTK
86141-static int ten_thousand = 10000;
86142+static int ten_thousand __read_only = 10000;
86143 #endif
86144
86145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
86146@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
86147 void __user *buffer, size_t *lenp, loff_t *ppos);
86148 #endif
86149
86150-#ifdef CONFIG_PRINTK
86151 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86152 void __user *buffer, size_t *lenp, loff_t *ppos);
86153-#endif
86154
86155 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
86156 void __user *buffer, size_t *lenp, loff_t *ppos);
86157@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
86158
86159 #endif
86160
86161+extern struct ctl_table grsecurity_table[];
86162+
86163 static struct ctl_table kern_table[];
86164 static struct ctl_table vm_table[];
86165 static struct ctl_table fs_table[];
86166@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
86167 int sysctl_legacy_va_layout;
86168 #endif
86169
86170+#ifdef CONFIG_PAX_SOFTMODE
86171+static ctl_table pax_table[] = {
86172+ {
86173+ .procname = "softmode",
86174+ .data = &pax_softmode,
86175+ .maxlen = sizeof(unsigned int),
86176+ .mode = 0600,
86177+ .proc_handler = &proc_dointvec,
86178+ },
86179+
86180+ { }
86181+};
86182+#endif
86183+
86184 /* The default sysctl tables: */
86185
86186 static struct ctl_table sysctl_base_table[] = {
86187@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
86188 #endif
86189
86190 static struct ctl_table kern_table[] = {
86191+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
86192+ {
86193+ .procname = "grsecurity",
86194+ .mode = 0500,
86195+ .child = grsecurity_table,
86196+ },
86197+#endif
86198+
86199+#ifdef CONFIG_PAX_SOFTMODE
86200+ {
86201+ .procname = "pax",
86202+ .mode = 0500,
86203+ .child = pax_table,
86204+ },
86205+#endif
86206+
86207 {
86208 .procname = "sched_child_runs_first",
86209 .data = &sysctl_sched_child_runs_first,
86210@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
86211 .data = &modprobe_path,
86212 .maxlen = KMOD_PATH_LEN,
86213 .mode = 0644,
86214- .proc_handler = proc_dostring,
86215+ .proc_handler = proc_dostring_modpriv,
86216 },
86217 {
86218 .procname = "modules_disabled",
86219@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
86220 .extra1 = &zero,
86221 .extra2 = &one,
86222 },
86223+#endif
86224 {
86225 .procname = "kptr_restrict",
86226 .data = &kptr_restrict,
86227 .maxlen = sizeof(int),
86228 .mode = 0644,
86229 .proc_handler = proc_dointvec_minmax_sysadmin,
86230+#ifdef CONFIG_GRKERNSEC_HIDESYM
86231+ .extra1 = &two,
86232+#else
86233 .extra1 = &zero,
86234+#endif
86235 .extra2 = &two,
86236 },
86237-#endif
86238 {
86239 .procname = "ngroups_max",
86240 .data = &ngroups_max,
86241@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
86242 */
86243 {
86244 .procname = "perf_event_paranoid",
86245- .data = &sysctl_perf_event_paranoid,
86246- .maxlen = sizeof(sysctl_perf_event_paranoid),
86247+ .data = &sysctl_perf_event_legitimately_concerned,
86248+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
86249 .mode = 0644,
86250- .proc_handler = proc_dointvec,
86251+ /* go ahead, be a hero */
86252+ .proc_handler = proc_dointvec_minmax_sysadmin,
86253+ .extra1 = &neg_one,
86254+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86255+ .extra2 = &three,
86256+#else
86257+ .extra2 = &two,
86258+#endif
86259 },
86260 {
86261 .procname = "perf_event_mlock_kb",
86262@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
86263 .proc_handler = proc_dointvec_minmax,
86264 .extra1 = &zero,
86265 },
86266+ {
86267+ .procname = "heap_stack_gap",
86268+ .data = &sysctl_heap_stack_gap,
86269+ .maxlen = sizeof(sysctl_heap_stack_gap),
86270+ .mode = 0644,
86271+ .proc_handler = proc_doulongvec_minmax,
86272+ },
86273 #else
86274 {
86275 .procname = "nr_trim_pages",
86276@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
86277 buffer, lenp, ppos);
86278 }
86279
86280+int proc_dostring_modpriv(struct ctl_table *table, int write,
86281+ void __user *buffer, size_t *lenp, loff_t *ppos)
86282+{
86283+ if (write && !capable(CAP_SYS_MODULE))
86284+ return -EPERM;
86285+
86286+ return _proc_do_string(table->data, table->maxlen, write,
86287+ buffer, lenp, ppos);
86288+}
86289+
86290 static size_t proc_skip_spaces(char **buf)
86291 {
86292 size_t ret;
86293@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
86294 len = strlen(tmp);
86295 if (len > *size)
86296 len = *size;
86297+ if (len > sizeof(tmp))
86298+ len = sizeof(tmp);
86299 if (copy_to_user(*buf, tmp, len))
86300 return -EFAULT;
86301 *size -= len;
86302@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
86303 static int proc_taint(struct ctl_table *table, int write,
86304 void __user *buffer, size_t *lenp, loff_t *ppos)
86305 {
86306- struct ctl_table t;
86307+ ctl_table_no_const t;
86308 unsigned long tmptaint = get_taint();
86309 int err;
86310
86311@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
86312 return err;
86313 }
86314
86315-#ifdef CONFIG_PRINTK
86316 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86317 void __user *buffer, size_t *lenp, loff_t *ppos)
86318 {
86319@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
86320
86321 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
86322 }
86323-#endif
86324
86325 struct do_proc_dointvec_minmax_conv_param {
86326 int *min;
86327@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
86328 *i = val;
86329 } else {
86330 val = convdiv * (*i) / convmul;
86331- if (!first)
86332+ if (!first) {
86333 err = proc_put_char(&buffer, &left, '\t');
86334+ if (err)
86335+ break;
86336+ }
86337 err = proc_put_long(&buffer, &left, val, false);
86338 if (err)
86339 break;
86340@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
86341 return -ENOSYS;
86342 }
86343
86344+int proc_dostring_modpriv(struct ctl_table *table, int write,
86345+ void __user *buffer, size_t *lenp, loff_t *ppos)
86346+{
86347+ return -ENOSYS;
86348+}
86349+
86350 int proc_dointvec(struct ctl_table *table, int write,
86351 void __user *buffer, size_t *lenp, loff_t *ppos)
86352 {
86353@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
86354 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
86355 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
86356 EXPORT_SYMBOL(proc_dostring);
86357+EXPORT_SYMBOL(proc_dostring_modpriv);
86358 EXPORT_SYMBOL(proc_doulongvec_minmax);
86359 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
86360diff --git a/kernel/taskstats.c b/kernel/taskstats.c
86361index 145bb4d..b2aa969 100644
86362--- a/kernel/taskstats.c
86363+++ b/kernel/taskstats.c
86364@@ -28,9 +28,12 @@
86365 #include <linux/fs.h>
86366 #include <linux/file.h>
86367 #include <linux/pid_namespace.h>
86368+#include <linux/grsecurity.h>
86369 #include <net/genetlink.h>
86370 #include <linux/atomic.h>
86371
86372+extern int gr_is_taskstats_denied(int pid);
86373+
86374 /*
86375 * Maximum length of a cpumask that can be specified in
86376 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
86377@@ -570,6 +573,9 @@ err:
86378
86379 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
86380 {
86381+ if (gr_is_taskstats_denied(current->pid))
86382+ return -EACCES;
86383+
86384 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
86385 return cmd_attr_register_cpumask(info);
86386 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
86387diff --git a/kernel/time.c b/kernel/time.c
86388index 7c7964c..2a0d412 100644
86389--- a/kernel/time.c
86390+++ b/kernel/time.c
86391@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
86392 return error;
86393
86394 if (tz) {
86395+ /* we log in do_settimeofday called below, so don't log twice
86396+ */
86397+ if (!tv)
86398+ gr_log_timechange();
86399+
86400 sys_tz = *tz;
86401 update_vsyscall_tz();
86402 if (firsttime) {
86403diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
86404index 88c9c65..7497ebc 100644
86405--- a/kernel/time/alarmtimer.c
86406+++ b/kernel/time/alarmtimer.c
86407@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
86408 struct platform_device *pdev;
86409 int error = 0;
86410 int i;
86411- struct k_clock alarm_clock = {
86412+ static struct k_clock alarm_clock = {
86413 .clock_getres = alarm_clock_getres,
86414 .clock_get = alarm_clock_get,
86415 .timer_create = alarm_timer_create,
86416diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
86417index 5cf6c70..ac341b0 100644
86418--- a/kernel/time/timekeeping.c
86419+++ b/kernel/time/timekeeping.c
86420@@ -15,6 +15,7 @@
86421 #include <linux/init.h>
86422 #include <linux/mm.h>
86423 #include <linux/sched.h>
86424+#include <linux/grsecurity.h>
86425 #include <linux/syscore_ops.h>
86426 #include <linux/clocksource.h>
86427 #include <linux/jiffies.h>
86428@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
86429 if (!timespec_valid_strict(tv))
86430 return -EINVAL;
86431
86432+ gr_log_timechange();
86433+
86434 raw_spin_lock_irqsave(&timekeeper_lock, flags);
86435 write_seqcount_begin(&timekeeper_seq);
86436
86437diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
86438index 61ed862..3b52c65 100644
86439--- a/kernel/time/timer_list.c
86440+++ b/kernel/time/timer_list.c
86441@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
86442
86443 static void print_name_offset(struct seq_file *m, void *sym)
86444 {
86445+#ifdef CONFIG_GRKERNSEC_HIDESYM
86446+ SEQ_printf(m, "<%p>", NULL);
86447+#else
86448 char symname[KSYM_NAME_LEN];
86449
86450 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
86451 SEQ_printf(m, "<%pK>", sym);
86452 else
86453 SEQ_printf(m, "%s", symname);
86454+#endif
86455 }
86456
86457 static void
86458@@ -119,7 +123,11 @@ next_one:
86459 static void
86460 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
86461 {
86462+#ifdef CONFIG_GRKERNSEC_HIDESYM
86463+ SEQ_printf(m, " .base: %p\n", NULL);
86464+#else
86465 SEQ_printf(m, " .base: %pK\n", base);
86466+#endif
86467 SEQ_printf(m, " .index: %d\n",
86468 base->index);
86469 SEQ_printf(m, " .resolution: %Lu nsecs\n",
86470@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
86471 {
86472 struct proc_dir_entry *pe;
86473
86474+#ifdef CONFIG_GRKERNSEC_PROC_ADD
86475+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
86476+#else
86477 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
86478+#endif
86479 if (!pe)
86480 return -ENOMEM;
86481 return 0;
86482diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
86483index 0b537f2..40d6c20 100644
86484--- a/kernel/time/timer_stats.c
86485+++ b/kernel/time/timer_stats.c
86486@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
86487 static unsigned long nr_entries;
86488 static struct entry entries[MAX_ENTRIES];
86489
86490-static atomic_t overflow_count;
86491+static atomic_unchecked_t overflow_count;
86492
86493 /*
86494 * The entries are in a hash-table, for fast lookup:
86495@@ -140,7 +140,7 @@ static void reset_entries(void)
86496 nr_entries = 0;
86497 memset(entries, 0, sizeof(entries));
86498 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
86499- atomic_set(&overflow_count, 0);
86500+ atomic_set_unchecked(&overflow_count, 0);
86501 }
86502
86503 static struct entry *alloc_entry(void)
86504@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
86505 if (likely(entry))
86506 entry->count++;
86507 else
86508- atomic_inc(&overflow_count);
86509+ atomic_inc_unchecked(&overflow_count);
86510
86511 out_unlock:
86512 raw_spin_unlock_irqrestore(lock, flags);
86513@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
86514
86515 static void print_name_offset(struct seq_file *m, unsigned long addr)
86516 {
86517+#ifdef CONFIG_GRKERNSEC_HIDESYM
86518+ seq_printf(m, "<%p>", NULL);
86519+#else
86520 char symname[KSYM_NAME_LEN];
86521
86522 if (lookup_symbol_name(addr, symname) < 0)
86523- seq_printf(m, "<%p>", (void *)addr);
86524+ seq_printf(m, "<%pK>", (void *)addr);
86525 else
86526 seq_printf(m, "%s", symname);
86527+#endif
86528 }
86529
86530 static int tstats_show(struct seq_file *m, void *v)
86531@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
86532
86533 seq_puts(m, "Timer Stats Version: v0.2\n");
86534 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
86535- if (atomic_read(&overflow_count))
86536+ if (atomic_read_unchecked(&overflow_count))
86537 seq_printf(m, "Overflow: %d entries\n",
86538- atomic_read(&overflow_count));
86539+ atomic_read_unchecked(&overflow_count));
86540
86541 for (i = 0; i < nr_entries; i++) {
86542 entry = entries + i;
86543@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
86544 {
86545 struct proc_dir_entry *pe;
86546
86547+#ifdef CONFIG_GRKERNSEC_PROC_ADD
86548+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
86549+#else
86550 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
86551+#endif
86552 if (!pe)
86553 return -ENOMEM;
86554 return 0;
86555diff --git a/kernel/timer.c b/kernel/timer.c
86556index 4296d13..0164b04 100644
86557--- a/kernel/timer.c
86558+++ b/kernel/timer.c
86559@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
86560 /*
86561 * This function runs timers and the timer-tq in bottom half context.
86562 */
86563-static void run_timer_softirq(struct softirq_action *h)
86564+static __latent_entropy void run_timer_softirq(void)
86565 {
86566 struct tvec_base *base = __this_cpu_read(tvec_bases);
86567
86568@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
86569 *
86570 * In all cases the return value is guaranteed to be non-negative.
86571 */
86572-signed long __sched schedule_timeout(signed long timeout)
86573+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
86574 {
86575 struct timer_list timer;
86576 unsigned long expire;
86577diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
86578index b8b8560..75b1a09 100644
86579--- a/kernel/trace/blktrace.c
86580+++ b/kernel/trace/blktrace.c
86581@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
86582 struct blk_trace *bt = filp->private_data;
86583 char buf[16];
86584
86585- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
86586+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
86587
86588 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
86589 }
86590@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
86591 return 1;
86592
86593 bt = buf->chan->private_data;
86594- atomic_inc(&bt->dropped);
86595+ atomic_inc_unchecked(&bt->dropped);
86596 return 0;
86597 }
86598
86599@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
86600
86601 bt->dir = dir;
86602 bt->dev = dev;
86603- atomic_set(&bt->dropped, 0);
86604+ atomic_set_unchecked(&bt->dropped, 0);
86605
86606 ret = -EIO;
86607 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
86608diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
86609index f3bd09ee..9bb9586 100644
86610--- a/kernel/trace/ftrace.c
86611+++ b/kernel/trace/ftrace.c
86612@@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
86613 if (unlikely(ftrace_disabled))
86614 return 0;
86615
86616+ ret = ftrace_arch_code_modify_prepare();
86617+ FTRACE_WARN_ON(ret);
86618+ if (ret)
86619+ return 0;
86620+
86621 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
86622+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
86623 if (ret) {
86624 ftrace_bug(ret, ip);
86625- return 0;
86626 }
86627- return 1;
86628+ return ret ? 0 : 1;
86629 }
86630
86631 /*
86632@@ -4043,8 +4048,10 @@ static int ftrace_process_locs(struct module *mod,
86633 if (!count)
86634 return 0;
86635
86636+ pax_open_kernel();
86637 sort(start, count, sizeof(*start),
86638 ftrace_cmp_ips, ftrace_swap_ips);
86639+ pax_close_kernel();
86640
86641 start_pg = ftrace_allocate_pages(count);
86642 if (!start_pg)
86643@@ -4766,8 +4773,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
86644 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
86645
86646 static int ftrace_graph_active;
86647-static struct notifier_block ftrace_suspend_notifier;
86648-
86649 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
86650 {
86651 return 0;
86652@@ -4918,6 +4923,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
86653 FTRACE_OPS_FL_RECURSION_SAFE,
86654 };
86655
86656+static struct notifier_block ftrace_suspend_notifier = {
86657+ .notifier_call = ftrace_suspend_notifier_call
86658+};
86659+
86660 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86661 trace_func_graph_ent_t entryfunc)
86662 {
86663@@ -4931,7 +4940,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86664 goto out;
86665 }
86666
86667- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
86668 register_pm_notifier(&ftrace_suspend_notifier);
86669
86670 ftrace_graph_active++;
86671diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
86672index cc2f66f..05edd54 100644
86673--- a/kernel/trace/ring_buffer.c
86674+++ b/kernel/trace/ring_buffer.c
86675@@ -352,9 +352,9 @@ struct buffer_data_page {
86676 */
86677 struct buffer_page {
86678 struct list_head list; /* list of buffer pages */
86679- local_t write; /* index for next write */
86680+ local_unchecked_t write; /* index for next write */
86681 unsigned read; /* index for next read */
86682- local_t entries; /* entries on this page */
86683+ local_unchecked_t entries; /* entries on this page */
86684 unsigned long real_end; /* real end of data */
86685 struct buffer_data_page *page; /* Actual data page */
86686 };
86687@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
86688 unsigned long last_overrun;
86689 local_t entries_bytes;
86690 local_t entries;
86691- local_t overrun;
86692- local_t commit_overrun;
86693+ local_unchecked_t overrun;
86694+ local_unchecked_t commit_overrun;
86695 local_t dropped_events;
86696 local_t committing;
86697 local_t commits;
86698@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86699 *
86700 * We add a counter to the write field to denote this.
86701 */
86702- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
86703- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
86704+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
86705+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
86706
86707 /*
86708 * Just make sure we have seen our old_write and synchronize
86709@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86710 * cmpxchg to only update if an interrupt did not already
86711 * do it for us. If the cmpxchg fails, we don't care.
86712 */
86713- (void)local_cmpxchg(&next_page->write, old_write, val);
86714- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
86715+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
86716+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
86717
86718 /*
86719 * No need to worry about races with clearing out the commit.
86720@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
86721
86722 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
86723 {
86724- return local_read(&bpage->entries) & RB_WRITE_MASK;
86725+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
86726 }
86727
86728 static inline unsigned long rb_page_write(struct buffer_page *bpage)
86729 {
86730- return local_read(&bpage->write) & RB_WRITE_MASK;
86731+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
86732 }
86733
86734 static int
86735@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
86736 * bytes consumed in ring buffer from here.
86737 * Increment overrun to account for the lost events.
86738 */
86739- local_add(page_entries, &cpu_buffer->overrun);
86740+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
86741 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86742 }
86743
86744@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
86745 * it is our responsibility to update
86746 * the counters.
86747 */
86748- local_add(entries, &cpu_buffer->overrun);
86749+ local_add_unchecked(entries, &cpu_buffer->overrun);
86750 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86751
86752 /*
86753@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86754 if (tail == BUF_PAGE_SIZE)
86755 tail_page->real_end = 0;
86756
86757- local_sub(length, &tail_page->write);
86758+ local_sub_unchecked(length, &tail_page->write);
86759 return;
86760 }
86761
86762@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86763 rb_event_set_padding(event);
86764
86765 /* Set the write back to the previous setting */
86766- local_sub(length, &tail_page->write);
86767+ local_sub_unchecked(length, &tail_page->write);
86768 return;
86769 }
86770
86771@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86772
86773 /* Set write to end of buffer */
86774 length = (tail + length) - BUF_PAGE_SIZE;
86775- local_sub(length, &tail_page->write);
86776+ local_sub_unchecked(length, &tail_page->write);
86777 }
86778
86779 /*
86780@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86781 * about it.
86782 */
86783 if (unlikely(next_page == commit_page)) {
86784- local_inc(&cpu_buffer->commit_overrun);
86785+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86786 goto out_reset;
86787 }
86788
86789@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86790 cpu_buffer->tail_page) &&
86791 (cpu_buffer->commit_page ==
86792 cpu_buffer->reader_page))) {
86793- local_inc(&cpu_buffer->commit_overrun);
86794+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86795 goto out_reset;
86796 }
86797 }
86798@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86799 length += RB_LEN_TIME_EXTEND;
86800
86801 tail_page = cpu_buffer->tail_page;
86802- write = local_add_return(length, &tail_page->write);
86803+ write = local_add_return_unchecked(length, &tail_page->write);
86804
86805 /* set write to only the index of the write */
86806 write &= RB_WRITE_MASK;
86807@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86808 kmemcheck_annotate_bitfield(event, bitfield);
86809 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
86810
86811- local_inc(&tail_page->entries);
86812+ local_inc_unchecked(&tail_page->entries);
86813
86814 /*
86815 * If this is the first commit on the page, then update
86816@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86817
86818 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
86819 unsigned long write_mask =
86820- local_read(&bpage->write) & ~RB_WRITE_MASK;
86821+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
86822 unsigned long event_length = rb_event_length(event);
86823 /*
86824 * This is on the tail page. It is possible that
86825@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86826 */
86827 old_index += write_mask;
86828 new_index += write_mask;
86829- index = local_cmpxchg(&bpage->write, old_index, new_index);
86830+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
86831 if (index == old_index) {
86832 /* update counters */
86833 local_sub(event_length, &cpu_buffer->entries_bytes);
86834@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86835
86836 /* Do the likely case first */
86837 if (likely(bpage->page == (void *)addr)) {
86838- local_dec(&bpage->entries);
86839+ local_dec_unchecked(&bpage->entries);
86840 return;
86841 }
86842
86843@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86844 start = bpage;
86845 do {
86846 if (bpage->page == (void *)addr) {
86847- local_dec(&bpage->entries);
86848+ local_dec_unchecked(&bpage->entries);
86849 return;
86850 }
86851 rb_inc_page(cpu_buffer, &bpage);
86852@@ -3139,7 +3139,7 @@ static inline unsigned long
86853 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
86854 {
86855 return local_read(&cpu_buffer->entries) -
86856- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
86857+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
86858 }
86859
86860 /**
86861@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
86862 return 0;
86863
86864 cpu_buffer = buffer->buffers[cpu];
86865- ret = local_read(&cpu_buffer->overrun);
86866+ ret = local_read_unchecked(&cpu_buffer->overrun);
86867
86868 return ret;
86869 }
86870@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
86871 return 0;
86872
86873 cpu_buffer = buffer->buffers[cpu];
86874- ret = local_read(&cpu_buffer->commit_overrun);
86875+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
86876
86877 return ret;
86878 }
86879@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
86880 /* if you care about this being correct, lock the buffer */
86881 for_each_buffer_cpu(buffer, cpu) {
86882 cpu_buffer = buffer->buffers[cpu];
86883- overruns += local_read(&cpu_buffer->overrun);
86884+ overruns += local_read_unchecked(&cpu_buffer->overrun);
86885 }
86886
86887 return overruns;
86888@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86889 /*
86890 * Reset the reader page to size zero.
86891 */
86892- local_set(&cpu_buffer->reader_page->write, 0);
86893- local_set(&cpu_buffer->reader_page->entries, 0);
86894+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86895+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86896 local_set(&cpu_buffer->reader_page->page->commit, 0);
86897 cpu_buffer->reader_page->real_end = 0;
86898
86899@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86900 * want to compare with the last_overrun.
86901 */
86902 smp_mb();
86903- overwrite = local_read(&(cpu_buffer->overrun));
86904+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
86905
86906 /*
86907 * Here's the tricky part.
86908@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86909
86910 cpu_buffer->head_page
86911 = list_entry(cpu_buffer->pages, struct buffer_page, list);
86912- local_set(&cpu_buffer->head_page->write, 0);
86913- local_set(&cpu_buffer->head_page->entries, 0);
86914+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
86915+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
86916 local_set(&cpu_buffer->head_page->page->commit, 0);
86917
86918 cpu_buffer->head_page->read = 0;
86919@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86920
86921 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
86922 INIT_LIST_HEAD(&cpu_buffer->new_pages);
86923- local_set(&cpu_buffer->reader_page->write, 0);
86924- local_set(&cpu_buffer->reader_page->entries, 0);
86925+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86926+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86927 local_set(&cpu_buffer->reader_page->page->commit, 0);
86928 cpu_buffer->reader_page->read = 0;
86929
86930 local_set(&cpu_buffer->entries_bytes, 0);
86931- local_set(&cpu_buffer->overrun, 0);
86932- local_set(&cpu_buffer->commit_overrun, 0);
86933+ local_set_unchecked(&cpu_buffer->overrun, 0);
86934+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
86935 local_set(&cpu_buffer->dropped_events, 0);
86936 local_set(&cpu_buffer->entries, 0);
86937 local_set(&cpu_buffer->committing, 0);
86938@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
86939 rb_init_page(bpage);
86940 bpage = reader->page;
86941 reader->page = *data_page;
86942- local_set(&reader->write, 0);
86943- local_set(&reader->entries, 0);
86944+ local_set_unchecked(&reader->write, 0);
86945+ local_set_unchecked(&reader->entries, 0);
86946 reader->read = 0;
86947 *data_page = bpage;
86948
86949diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
86950index b778e96..4e84621 100644
86951--- a/kernel/trace/trace.c
86952+++ b/kernel/trace/trace.c
86953@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
86954 return 0;
86955 }
86956
86957-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
86958+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
86959 {
86960 /* do nothing if flag is already set */
86961 if (!!(trace_flags & mask) == !!enabled)
86962diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
86963index 10c86fb..645ab0a 100644
86964--- a/kernel/trace/trace.h
86965+++ b/kernel/trace/trace.h
86966@@ -1029,7 +1029,7 @@ extern const char *__stop___tracepoint_str[];
86967 void trace_printk_init_buffers(void);
86968 void trace_printk_start_comm(void);
86969 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
86970-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
86971+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
86972
86973 /*
86974 * Normal trace_printk() and friends allocates special buffers
86975diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
86976index 26dc348..8708ca7 100644
86977--- a/kernel/trace/trace_clock.c
86978+++ b/kernel/trace/trace_clock.c
86979@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
86980 return now;
86981 }
86982
86983-static atomic64_t trace_counter;
86984+static atomic64_unchecked_t trace_counter;
86985
86986 /*
86987 * trace_clock_counter(): simply an atomic counter.
86988@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
86989 */
86990 u64 notrace trace_clock_counter(void)
86991 {
86992- return atomic64_add_return(1, &trace_counter);
86993+ return atomic64_inc_return_unchecked(&trace_counter);
86994 }
86995diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
86996index 368a4d5..7b6d1d5 100644
86997--- a/kernel/trace/trace_events.c
86998+++ b/kernel/trace/trace_events.c
86999@@ -1673,7 +1673,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
87000 return 0;
87001 }
87002
87003-struct ftrace_module_file_ops;
87004 static void __add_event_to_tracers(struct ftrace_event_call *call);
87005
87006 /* Add an additional event_call dynamically */
87007diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
87008index b3dcfb2..ebee344 100644
87009--- a/kernel/trace/trace_mmiotrace.c
87010+++ b/kernel/trace/trace_mmiotrace.c
87011@@ -24,7 +24,7 @@ struct header_iter {
87012 static struct trace_array *mmio_trace_array;
87013 static bool overrun_detected;
87014 static unsigned long prev_overruns;
87015-static atomic_t dropped_count;
87016+static atomic_unchecked_t dropped_count;
87017
87018 static void mmio_reset_data(struct trace_array *tr)
87019 {
87020@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
87021
87022 static unsigned long count_overruns(struct trace_iterator *iter)
87023 {
87024- unsigned long cnt = atomic_xchg(&dropped_count, 0);
87025+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
87026 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
87027
87028 if (over > prev_overruns)
87029@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
87030 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
87031 sizeof(*entry), 0, pc);
87032 if (!event) {
87033- atomic_inc(&dropped_count);
87034+ atomic_inc_unchecked(&dropped_count);
87035 return;
87036 }
87037 entry = ring_buffer_event_data(event);
87038@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
87039 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
87040 sizeof(*entry), 0, pc);
87041 if (!event) {
87042- atomic_inc(&dropped_count);
87043+ atomic_inc_unchecked(&dropped_count);
87044 return;
87045 }
87046 entry = ring_buffer_event_data(event);
87047diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
87048index 34e7cba..6f9a729 100644
87049--- a/kernel/trace/trace_output.c
87050+++ b/kernel/trace/trace_output.c
87051@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
87052
87053 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
87054 if (!IS_ERR(p)) {
87055- p = mangle_path(s->buffer + s->len, p, "\n");
87056+ p = mangle_path(s->buffer + s->len, p, "\n\\");
87057 if (p) {
87058 s->len = p - s->buffer;
87059 return 1;
87060@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
87061 goto out;
87062 }
87063
87064+ pax_open_kernel();
87065 if (event->funcs->trace == NULL)
87066- event->funcs->trace = trace_nop_print;
87067+ *(void **)&event->funcs->trace = trace_nop_print;
87068 if (event->funcs->raw == NULL)
87069- event->funcs->raw = trace_nop_print;
87070+ *(void **)&event->funcs->raw = trace_nop_print;
87071 if (event->funcs->hex == NULL)
87072- event->funcs->hex = trace_nop_print;
87073+ *(void **)&event->funcs->hex = trace_nop_print;
87074 if (event->funcs->binary == NULL)
87075- event->funcs->binary = trace_nop_print;
87076+ *(void **)&event->funcs->binary = trace_nop_print;
87077+ pax_close_kernel();
87078
87079 key = event->type & (EVENT_HASHSIZE - 1);
87080
87081diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
87082index b20428c..4845a10 100644
87083--- a/kernel/trace/trace_stack.c
87084+++ b/kernel/trace/trace_stack.c
87085@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
87086 return;
87087
87088 /* we do not handle interrupt stacks yet */
87089- if (!object_is_on_stack(stack))
87090+ if (!object_starts_on_stack(stack))
87091 return;
87092
87093 local_irq_save(flags);
87094diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
87095index 13fb113..a6ced3f 100644
87096--- a/kernel/user_namespace.c
87097+++ b/kernel/user_namespace.c
87098@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
87099 !kgid_has_mapping(parent_ns, group))
87100 return -EPERM;
87101
87102+#ifdef CONFIG_GRKERNSEC
87103+ /*
87104+ * This doesn't really inspire confidence:
87105+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
87106+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
87107+ * Increases kernel attack surface in areas developers
87108+ * previously cared little about ("low importance due
87109+ * to requiring "root" capability")
87110+ * To be removed when this code receives *proper* review
87111+ */
87112+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
87113+ !capable(CAP_SETGID))
87114+ return -EPERM;
87115+#endif
87116+
87117 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
87118 if (!ns)
87119 return -ENOMEM;
87120@@ -860,7 +875,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
87121 if (atomic_read(&current->mm->mm_users) > 1)
87122 return -EINVAL;
87123
87124- if (current->fs->users != 1)
87125+ if (atomic_read(&current->fs->users) != 1)
87126 return -EINVAL;
87127
87128 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
87129diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
87130index 4f69f9a..7c6f8f8 100644
87131--- a/kernel/utsname_sysctl.c
87132+++ b/kernel/utsname_sysctl.c
87133@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
87134 static int proc_do_uts_string(ctl_table *table, int write,
87135 void __user *buffer, size_t *lenp, loff_t *ppos)
87136 {
87137- struct ctl_table uts_table;
87138+ ctl_table_no_const uts_table;
87139 int r;
87140 memcpy(&uts_table, table, sizeof(uts_table));
87141 uts_table.data = get_uts(table, write);
87142diff --git a/kernel/watchdog.c b/kernel/watchdog.c
87143index 4431610..4265616 100644
87144--- a/kernel/watchdog.c
87145+++ b/kernel/watchdog.c
87146@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
87147 static void watchdog_nmi_disable(unsigned int cpu) { return; }
87148 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
87149
87150-static struct smp_hotplug_thread watchdog_threads = {
87151+static struct smp_hotplug_thread watchdog_threads __read_only = {
87152 .store = &softlockup_watchdog,
87153 .thread_should_run = watchdog_should_run,
87154 .thread_fn = watchdog,
87155diff --git a/kernel/workqueue.c b/kernel/workqueue.c
87156index 93c2652..66a1cfd 100644
87157--- a/kernel/workqueue.c
87158+++ b/kernel/workqueue.c
87159@@ -4668,7 +4668,7 @@ static void rebind_workers(struct worker_pool *pool)
87160 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
87161 worker_flags |= WORKER_REBOUND;
87162 worker_flags &= ~WORKER_UNBOUND;
87163- ACCESS_ONCE(worker->flags) = worker_flags;
87164+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
87165 }
87166
87167 spin_unlock_irq(&pool->lock);
87168diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
87169index 094f315..244a824 100644
87170--- a/lib/Kconfig.debug
87171+++ b/lib/Kconfig.debug
87172@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
87173
87174 config DEBUG_WW_MUTEX_SLOWPATH
87175 bool "Wait/wound mutex debugging: Slowpath testing"
87176- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87177+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87178 select DEBUG_LOCK_ALLOC
87179 select DEBUG_SPINLOCK
87180 select DEBUG_MUTEXES
87181@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
87182
87183 config DEBUG_LOCK_ALLOC
87184 bool "Lock debugging: detect incorrect freeing of live locks"
87185- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87186+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87187 select DEBUG_SPINLOCK
87188 select DEBUG_MUTEXES
87189 select LOCKDEP
87190@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
87191
87192 config PROVE_LOCKING
87193 bool "Lock debugging: prove locking correctness"
87194- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87195+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87196 select LOCKDEP
87197 select DEBUG_SPINLOCK
87198 select DEBUG_MUTEXES
87199@@ -914,7 +914,7 @@ config LOCKDEP
87200
87201 config LOCK_STAT
87202 bool "Lock usage statistics"
87203- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
87204+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
87205 select LOCKDEP
87206 select DEBUG_SPINLOCK
87207 select DEBUG_MUTEXES
87208@@ -1376,6 +1376,7 @@ config LATENCYTOP
87209 depends on DEBUG_KERNEL
87210 depends on STACKTRACE_SUPPORT
87211 depends on PROC_FS
87212+ depends on !GRKERNSEC_HIDESYM
87213 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
87214 select KALLSYMS
87215 select KALLSYMS_ALL
87216@@ -1392,7 +1393,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
87217 config DEBUG_STRICT_USER_COPY_CHECKS
87218 bool "Strict user copy size checks"
87219 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
87220- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
87221+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
87222 help
87223 Enabling this option turns a certain set of sanity checks for user
87224 copy operations into compile time failures.
87225@@ -1502,7 +1503,7 @@ endmenu # runtime tests
87226
87227 config PROVIDE_OHCI1394_DMA_INIT
87228 bool "Remote debugging over FireWire early on boot"
87229- depends on PCI && X86
87230+ depends on PCI && X86 && !GRKERNSEC
87231 help
87232 If you want to debug problems which hang or crash the kernel early
87233 on boot and the crashing machine has a FireWire port, you can use
87234@@ -1531,7 +1532,7 @@ config PROVIDE_OHCI1394_DMA_INIT
87235
87236 config FIREWIRE_OHCI_REMOTE_DMA
87237 bool "Remote debugging over FireWire with firewire-ohci"
87238- depends on FIREWIRE_OHCI
87239+ depends on FIREWIRE_OHCI && !GRKERNSEC
87240 help
87241 This option lets you use the FireWire bus for remote debugging
87242 with help of the firewire-ohci driver. It enables unfiltered
87243diff --git a/lib/Makefile b/lib/Makefile
87244index f3bb2cb..b358ace 100644
87245--- a/lib/Makefile
87246+++ b/lib/Makefile
87247@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
87248
87249 obj-$(CONFIG_BTREE) += btree.o
87250 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
87251-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
87252+obj-y += list_debug.o
87253 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
87254
87255 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
87256diff --git a/lib/bitmap.c b/lib/bitmap.c
87257index 06f7e4f..f3cf2b0 100644
87258--- a/lib/bitmap.c
87259+++ b/lib/bitmap.c
87260@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
87261 {
87262 int c, old_c, totaldigits, ndigits, nchunks, nbits;
87263 u32 chunk;
87264- const char __user __force *ubuf = (const char __user __force *)buf;
87265+ const char __user *ubuf = (const char __force_user *)buf;
87266
87267 bitmap_zero(maskp, nmaskbits);
87268
87269@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
87270 {
87271 if (!access_ok(VERIFY_READ, ubuf, ulen))
87272 return -EFAULT;
87273- return __bitmap_parse((const char __force *)ubuf,
87274+ return __bitmap_parse((const char __force_kernel *)ubuf,
87275 ulen, 1, maskp, nmaskbits);
87276
87277 }
87278@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
87279 {
87280 unsigned a, b;
87281 int c, old_c, totaldigits;
87282- const char __user __force *ubuf = (const char __user __force *)buf;
87283+ const char __user *ubuf = (const char __force_user *)buf;
87284 int exp_digit, in_range;
87285
87286 totaldigits = c = 0;
87287@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
87288 {
87289 if (!access_ok(VERIFY_READ, ubuf, ulen))
87290 return -EFAULT;
87291- return __bitmap_parselist((const char __force *)ubuf,
87292+ return __bitmap_parselist((const char __force_kernel *)ubuf,
87293 ulen, 1, maskp, nmaskbits);
87294 }
87295 EXPORT_SYMBOL(bitmap_parselist_user);
87296diff --git a/lib/bug.c b/lib/bug.c
87297index 1686034..a9c00c8 100644
87298--- a/lib/bug.c
87299+++ b/lib/bug.c
87300@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
87301 return BUG_TRAP_TYPE_NONE;
87302
87303 bug = find_bug(bugaddr);
87304+ if (!bug)
87305+ return BUG_TRAP_TYPE_NONE;
87306
87307 file = NULL;
87308 line = 0;
87309diff --git a/lib/debugobjects.c b/lib/debugobjects.c
87310index bf2c8b1..1d00ccf 100644
87311--- a/lib/debugobjects.c
87312+++ b/lib/debugobjects.c
87313@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
87314 if (limit > 4)
87315 return;
87316
87317- is_on_stack = object_is_on_stack(addr);
87318+ is_on_stack = object_starts_on_stack(addr);
87319 if (is_on_stack == onstack)
87320 return;
87321
87322diff --git a/lib/devres.c b/lib/devres.c
87323index 8235331..5881053 100644
87324--- a/lib/devres.c
87325+++ b/lib/devres.c
87326@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
87327 void devm_iounmap(struct device *dev, void __iomem *addr)
87328 {
87329 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
87330- (void *)addr));
87331+ (void __force *)addr));
87332 iounmap(addr);
87333 }
87334 EXPORT_SYMBOL(devm_iounmap);
87335@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
87336 {
87337 ioport_unmap(addr);
87338 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
87339- devm_ioport_map_match, (void *)addr));
87340+ devm_ioport_map_match, (void __force *)addr));
87341 }
87342 EXPORT_SYMBOL(devm_ioport_unmap);
87343 #endif /* CONFIG_HAS_IOPORT */
87344diff --git a/lib/div64.c b/lib/div64.c
87345index 4382ad7..08aa558 100644
87346--- a/lib/div64.c
87347+++ b/lib/div64.c
87348@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
87349 EXPORT_SYMBOL(__div64_32);
87350
87351 #ifndef div_s64_rem
87352-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
87353+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
87354 {
87355 u64 quotient;
87356
87357@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
87358 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
87359 */
87360 #ifndef div64_u64
87361-u64 div64_u64(u64 dividend, u64 divisor)
87362+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
87363 {
87364 u32 high = divisor >> 32;
87365 u64 quot;
87366diff --git a/lib/dma-debug.c b/lib/dma-debug.c
87367index d87a17a..ac0d79a 100644
87368--- a/lib/dma-debug.c
87369+++ b/lib/dma-debug.c
87370@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
87371
87372 void dma_debug_add_bus(struct bus_type *bus)
87373 {
87374- struct notifier_block *nb;
87375+ notifier_block_no_const *nb;
87376
87377 if (global_disable)
87378 return;
87379@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
87380
87381 static void check_for_stack(struct device *dev, void *addr)
87382 {
87383- if (object_is_on_stack(addr))
87384+ if (object_starts_on_stack(addr))
87385 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
87386 "stack [addr=%p]\n", addr);
87387 }
87388diff --git a/lib/inflate.c b/lib/inflate.c
87389index 013a761..c28f3fc 100644
87390--- a/lib/inflate.c
87391+++ b/lib/inflate.c
87392@@ -269,7 +269,7 @@ static void free(void *where)
87393 malloc_ptr = free_mem_ptr;
87394 }
87395 #else
87396-#define malloc(a) kmalloc(a, GFP_KERNEL)
87397+#define malloc(a) kmalloc((a), GFP_KERNEL)
87398 #define free(a) kfree(a)
87399 #endif
87400
87401diff --git a/lib/ioremap.c b/lib/ioremap.c
87402index 0c9216c..863bd89 100644
87403--- a/lib/ioremap.c
87404+++ b/lib/ioremap.c
87405@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
87406 unsigned long next;
87407
87408 phys_addr -= addr;
87409- pmd = pmd_alloc(&init_mm, pud, addr);
87410+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
87411 if (!pmd)
87412 return -ENOMEM;
87413 do {
87414@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
87415 unsigned long next;
87416
87417 phys_addr -= addr;
87418- pud = pud_alloc(&init_mm, pgd, addr);
87419+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
87420 if (!pud)
87421 return -ENOMEM;
87422 do {
87423diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
87424index bd2bea9..6b3c95e 100644
87425--- a/lib/is_single_threaded.c
87426+++ b/lib/is_single_threaded.c
87427@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
87428 struct task_struct *p, *t;
87429 bool ret;
87430
87431+ if (!mm)
87432+ return true;
87433+
87434 if (atomic_read(&task->signal->live) != 1)
87435 return false;
87436
87437diff --git a/lib/kobject.c b/lib/kobject.c
87438index 084f7b1..d265b8a 100644
87439--- a/lib/kobject.c
87440+++ b/lib/kobject.c
87441@@ -875,9 +875,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
87442
87443
87444 static DEFINE_SPINLOCK(kobj_ns_type_lock);
87445-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
87446+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
87447
87448-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
87449+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
87450 {
87451 enum kobj_ns_type type = ops->type;
87452 int error;
87453diff --git a/lib/list_debug.c b/lib/list_debug.c
87454index c24c2f7..f0296f4 100644
87455--- a/lib/list_debug.c
87456+++ b/lib/list_debug.c
87457@@ -11,7 +11,9 @@
87458 #include <linux/bug.h>
87459 #include <linux/kernel.h>
87460 #include <linux/rculist.h>
87461+#include <linux/mm.h>
87462
87463+#ifdef CONFIG_DEBUG_LIST
87464 /*
87465 * Insert a new entry between two known consecutive entries.
87466 *
87467@@ -19,21 +21,40 @@
87468 * the prev/next entries already!
87469 */
87470
87471+static bool __list_add_debug(struct list_head *new,
87472+ struct list_head *prev,
87473+ struct list_head *next)
87474+{
87475+ if (unlikely(next->prev != prev)) {
87476+ printk(KERN_ERR "list_add corruption. next->prev should be "
87477+ "prev (%p), but was %p. (next=%p).\n",
87478+ prev, next->prev, next);
87479+ BUG();
87480+ return false;
87481+ }
87482+ if (unlikely(prev->next != next)) {
87483+ printk(KERN_ERR "list_add corruption. prev->next should be "
87484+ "next (%p), but was %p. (prev=%p).\n",
87485+ next, prev->next, prev);
87486+ BUG();
87487+ return false;
87488+ }
87489+ if (unlikely(new == prev || new == next)) {
87490+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
87491+ new, prev, next);
87492+ BUG();
87493+ return false;
87494+ }
87495+ return true;
87496+}
87497+
87498 void __list_add(struct list_head *new,
87499- struct list_head *prev,
87500- struct list_head *next)
87501+ struct list_head *prev,
87502+ struct list_head *next)
87503 {
87504- WARN(next->prev != prev,
87505- "list_add corruption. next->prev should be "
87506- "prev (%p), but was %p. (next=%p).\n",
87507- prev, next->prev, next);
87508- WARN(prev->next != next,
87509- "list_add corruption. prev->next should be "
87510- "next (%p), but was %p. (prev=%p).\n",
87511- next, prev->next, prev);
87512- WARN(new == prev || new == next,
87513- "list_add double add: new=%p, prev=%p, next=%p.\n",
87514- new, prev, next);
87515+ if (!__list_add_debug(new, prev, next))
87516+ return;
87517+
87518 next->prev = new;
87519 new->next = next;
87520 new->prev = prev;
87521@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
87522 }
87523 EXPORT_SYMBOL(__list_add);
87524
87525-void __list_del_entry(struct list_head *entry)
87526+static bool __list_del_entry_debug(struct list_head *entry)
87527 {
87528 struct list_head *prev, *next;
87529
87530 prev = entry->prev;
87531 next = entry->next;
87532
87533- if (WARN(next == LIST_POISON1,
87534- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
87535- entry, LIST_POISON1) ||
87536- WARN(prev == LIST_POISON2,
87537- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
87538- entry, LIST_POISON2) ||
87539- WARN(prev->next != entry,
87540- "list_del corruption. prev->next should be %p, "
87541- "but was %p\n", entry, prev->next) ||
87542- WARN(next->prev != entry,
87543- "list_del corruption. next->prev should be %p, "
87544- "but was %p\n", entry, next->prev))
87545+ if (unlikely(next == LIST_POISON1)) {
87546+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
87547+ entry, LIST_POISON1);
87548+ BUG();
87549+ return false;
87550+ }
87551+ if (unlikely(prev == LIST_POISON2)) {
87552+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
87553+ entry, LIST_POISON2);
87554+ BUG();
87555+ return false;
87556+ }
87557+ if (unlikely(entry->prev->next != entry)) {
87558+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
87559+ "but was %p\n", entry, prev->next);
87560+ BUG();
87561+ return false;
87562+ }
87563+ if (unlikely(entry->next->prev != entry)) {
87564+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
87565+ "but was %p\n", entry, next->prev);
87566+ BUG();
87567+ return false;
87568+ }
87569+ return true;
87570+}
87571+
87572+void __list_del_entry(struct list_head *entry)
87573+{
87574+ if (!__list_del_entry_debug(entry))
87575 return;
87576
87577- __list_del(prev, next);
87578+ __list_del(entry->prev, entry->next);
87579 }
87580 EXPORT_SYMBOL(__list_del_entry);
87581
87582@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
87583 void __list_add_rcu(struct list_head *new,
87584 struct list_head *prev, struct list_head *next)
87585 {
87586- WARN(next->prev != prev,
87587- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
87588- prev, next->prev, next);
87589- WARN(prev->next != next,
87590- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
87591- next, prev->next, prev);
87592+ if (!__list_add_debug(new, prev, next))
87593+ return;
87594+
87595 new->next = next;
87596 new->prev = prev;
87597 rcu_assign_pointer(list_next_rcu(prev), new);
87598 next->prev = new;
87599 }
87600 EXPORT_SYMBOL(__list_add_rcu);
87601+#endif
87602+
87603+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
87604+{
87605+#ifdef CONFIG_DEBUG_LIST
87606+ if (!__list_add_debug(new, prev, next))
87607+ return;
87608+#endif
87609+
87610+ pax_open_kernel();
87611+ next->prev = new;
87612+ new->next = next;
87613+ new->prev = prev;
87614+ prev->next = new;
87615+ pax_close_kernel();
87616+}
87617+EXPORT_SYMBOL(__pax_list_add);
87618+
87619+void pax_list_del(struct list_head *entry)
87620+{
87621+#ifdef CONFIG_DEBUG_LIST
87622+ if (!__list_del_entry_debug(entry))
87623+ return;
87624+#endif
87625+
87626+ pax_open_kernel();
87627+ __list_del(entry->prev, entry->next);
87628+ entry->next = LIST_POISON1;
87629+ entry->prev = LIST_POISON2;
87630+ pax_close_kernel();
87631+}
87632+EXPORT_SYMBOL(pax_list_del);
87633+
87634+void pax_list_del_init(struct list_head *entry)
87635+{
87636+ pax_open_kernel();
87637+ __list_del(entry->prev, entry->next);
87638+ INIT_LIST_HEAD(entry);
87639+ pax_close_kernel();
87640+}
87641+EXPORT_SYMBOL(pax_list_del_init);
87642+
87643+void __pax_list_add_rcu(struct list_head *new,
87644+ struct list_head *prev, struct list_head *next)
87645+{
87646+#ifdef CONFIG_DEBUG_LIST
87647+ if (!__list_add_debug(new, prev, next))
87648+ return;
87649+#endif
87650+
87651+ pax_open_kernel();
87652+ new->next = next;
87653+ new->prev = prev;
87654+ rcu_assign_pointer(list_next_rcu(prev), new);
87655+ next->prev = new;
87656+ pax_close_kernel();
87657+}
87658+EXPORT_SYMBOL(__pax_list_add_rcu);
87659+
87660+void pax_list_del_rcu(struct list_head *entry)
87661+{
87662+#ifdef CONFIG_DEBUG_LIST
87663+ if (!__list_del_entry_debug(entry))
87664+ return;
87665+#endif
87666+
87667+ pax_open_kernel();
87668+ __list_del(entry->prev, entry->next);
87669+ entry->next = LIST_POISON1;
87670+ entry->prev = LIST_POISON2;
87671+ pax_close_kernel();
87672+}
87673+EXPORT_SYMBOL(pax_list_del_rcu);
87674diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
87675index 1a53d49..ace934c 100644
87676--- a/lib/percpu-refcount.c
87677+++ b/lib/percpu-refcount.c
87678@@ -29,7 +29,7 @@
87679 * can't hit 0 before we've added up all the percpu refs.
87680 */
87681
87682-#define PCPU_COUNT_BIAS (1U << 31)
87683+#define PCPU_COUNT_BIAS (1U << 30)
87684
87685 /**
87686 * percpu_ref_init - initialize a percpu refcount
87687diff --git a/lib/radix-tree.c b/lib/radix-tree.c
87688index 7811ed3..f80ca19 100644
87689--- a/lib/radix-tree.c
87690+++ b/lib/radix-tree.c
87691@@ -93,7 +93,7 @@ struct radix_tree_preload {
87692 int nr;
87693 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
87694 };
87695-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
87696+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
87697
87698 static inline void *ptr_to_indirect(void *ptr)
87699 {
87700diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
87701index bb2b201..46abaf9 100644
87702--- a/lib/strncpy_from_user.c
87703+++ b/lib/strncpy_from_user.c
87704@@ -21,7 +21,7 @@
87705 */
87706 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
87707 {
87708- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87709+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87710 long res = 0;
87711
87712 /*
87713diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
87714index a28df52..3d55877 100644
87715--- a/lib/strnlen_user.c
87716+++ b/lib/strnlen_user.c
87717@@ -26,7 +26,7 @@
87718 */
87719 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
87720 {
87721- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87722+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87723 long align, res = 0;
87724 unsigned long c;
87725
87726diff --git a/lib/swiotlb.c b/lib/swiotlb.c
87727index 4e8686c..3e8c92f 100644
87728--- a/lib/swiotlb.c
87729+++ b/lib/swiotlb.c
87730@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
87731
87732 void
87733 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
87734- dma_addr_t dev_addr)
87735+ dma_addr_t dev_addr, struct dma_attrs *attrs)
87736 {
87737 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
87738
87739diff --git a/lib/usercopy.c b/lib/usercopy.c
87740index 4f5b1dd..7cab418 100644
87741--- a/lib/usercopy.c
87742+++ b/lib/usercopy.c
87743@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
87744 WARN(1, "Buffer overflow detected!\n");
87745 }
87746 EXPORT_SYMBOL(copy_from_user_overflow);
87747+
87748+void copy_to_user_overflow(void)
87749+{
87750+ WARN(1, "Buffer overflow detected!\n");
87751+}
87752+EXPORT_SYMBOL(copy_to_user_overflow);
87753diff --git a/lib/vsprintf.c b/lib/vsprintf.c
87754index d76555c..62d4bfe 100644
87755--- a/lib/vsprintf.c
87756+++ b/lib/vsprintf.c
87757@@ -16,6 +16,9 @@
87758 * - scnprintf and vscnprintf
87759 */
87760
87761+#ifdef CONFIG_GRKERNSEC_HIDESYM
87762+#define __INCLUDED_BY_HIDESYM 1
87763+#endif
87764 #include <stdarg.h>
87765 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
87766 #include <linux/types.h>
87767@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
87768 return number(buf, end, *(const netdev_features_t *)addr, spec);
87769 }
87770
87771+#ifdef CONFIG_GRKERNSEC_HIDESYM
87772+int kptr_restrict __read_mostly = 2;
87773+#else
87774 int kptr_restrict __read_mostly;
87775+#endif
87776
87777 /*
87778 * Show a '%p' thing. A kernel extension is that the '%p' is followed
87779@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
87780 * - 'f' For simple symbolic function names without offset
87781 * - 'S' For symbolic direct pointers with offset
87782 * - 's' For symbolic direct pointers without offset
87783+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
87784 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
87785 * - 'B' For backtraced symbolic direct pointers with offset
87786 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
87787@@ -1232,12 +1240,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87788
87789 if (!ptr && *fmt != 'K') {
87790 /*
87791- * Print (null) with the same width as a pointer so it makes
87792+ * Print (nil) with the same width as a pointer so it makes
87793 * tabular output look nice.
87794 */
87795 if (spec.field_width == -1)
87796 spec.field_width = default_width;
87797- return string(buf, end, "(null)", spec);
87798+ return string(buf, end, "(nil)", spec);
87799 }
87800
87801 switch (*fmt) {
87802@@ -1247,6 +1255,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87803 /* Fallthrough */
87804 case 'S':
87805 case 's':
87806+#ifdef CONFIG_GRKERNSEC_HIDESYM
87807+ break;
87808+#else
87809+ return symbol_string(buf, end, ptr, spec, fmt);
87810+#endif
87811+ case 'A':
87812 case 'B':
87813 return symbol_string(buf, end, ptr, spec, fmt);
87814 case 'R':
87815@@ -1302,6 +1316,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87816 va_end(va);
87817 return buf;
87818 }
87819+ case 'P':
87820+ break;
87821 case 'K':
87822 /*
87823 * %pK cannot be used in IRQ context because its test
87824@@ -1363,6 +1379,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87825 ((const struct file *)ptr)->f_path.dentry,
87826 spec, fmt);
87827 }
87828+
87829+#ifdef CONFIG_GRKERNSEC_HIDESYM
87830+ /* 'P' = approved pointers to copy to userland,
87831+ as in the /proc/kallsyms case, as we make it display nothing
87832+ for non-root users, and the real contents for root users
87833+ Also ignore 'K' pointers, since we force their NULLing for non-root users
87834+ above
87835+ */
87836+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
87837+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
87838+ dump_stack();
87839+ ptr = NULL;
87840+ }
87841+#endif
87842+
87843 spec.flags |= SMALL;
87844 if (spec.field_width == -1) {
87845 spec.field_width = default_width;
87846@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87847 typeof(type) value; \
87848 if (sizeof(type) == 8) { \
87849 args = PTR_ALIGN(args, sizeof(u32)); \
87850- *(u32 *)&value = *(u32 *)args; \
87851- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
87852+ *(u32 *)&value = *(const u32 *)args; \
87853+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
87854 } else { \
87855 args = PTR_ALIGN(args, sizeof(type)); \
87856- value = *(typeof(type) *)args; \
87857+ value = *(const typeof(type) *)args; \
87858 } \
87859 args += sizeof(type); \
87860 value; \
87861@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87862 case FORMAT_TYPE_STR: {
87863 const char *str_arg = args;
87864 args += strlen(str_arg) + 1;
87865- str = string(str, end, (char *)str_arg, spec);
87866+ str = string(str, end, str_arg, spec);
87867 break;
87868 }
87869
87870diff --git a/localversion-grsec b/localversion-grsec
87871new file mode 100644
87872index 0000000..7cd6065
87873--- /dev/null
87874+++ b/localversion-grsec
87875@@ -0,0 +1 @@
87876+-grsec
87877diff --git a/mm/Kconfig b/mm/Kconfig
87878index 394838f..0e5f816 100644
87879--- a/mm/Kconfig
87880+++ b/mm/Kconfig
87881@@ -317,10 +317,11 @@ config KSM
87882 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
87883
87884 config DEFAULT_MMAP_MIN_ADDR
87885- int "Low address space to protect from user allocation"
87886+ int "Low address space to protect from user allocation"
87887 depends on MMU
87888- default 4096
87889- help
87890+ default 32768 if ALPHA || ARM || PARISC || SPARC32
87891+ default 65536
87892+ help
87893 This is the portion of low virtual memory which should be protected
87894 from userspace allocation. Keeping a user from writing to low pages
87895 can help reduce the impact of kernel NULL pointer bugs.
87896@@ -351,7 +352,7 @@ config MEMORY_FAILURE
87897
87898 config HWPOISON_INJECT
87899 tristate "HWPoison pages injector"
87900- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
87901+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
87902 select PROC_PAGE_MONITOR
87903
87904 config NOMMU_INITIAL_TRIM_EXCESS
87905diff --git a/mm/backing-dev.c b/mm/backing-dev.c
87906index ce682f7..1fb54f9 100644
87907--- a/mm/backing-dev.c
87908+++ b/mm/backing-dev.c
87909@@ -12,7 +12,7 @@
87910 #include <linux/device.h>
87911 #include <trace/events/writeback.h>
87912
87913-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
87914+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
87915
87916 struct backing_dev_info default_backing_dev_info = {
87917 .name = "default",
87918@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87919 return err;
87920
87921 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
87922- atomic_long_inc_return(&bdi_seq));
87923+ atomic_long_inc_return_unchecked(&bdi_seq));
87924 if (err) {
87925 bdi_destroy(bdi);
87926 return err;
87927diff --git a/mm/filemap.c b/mm/filemap.c
87928index ae4846f..b0acebe 100644
87929--- a/mm/filemap.c
87930+++ b/mm/filemap.c
87931@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
87932 struct address_space *mapping = file->f_mapping;
87933
87934 if (!mapping->a_ops->readpage)
87935- return -ENOEXEC;
87936+ return -ENODEV;
87937 file_accessed(file);
87938 vma->vm_ops = &generic_file_vm_ops;
87939 return 0;
87940@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
87941
87942 while (bytes) {
87943 char __user *buf = iov->iov_base + base;
87944- int copy = min(bytes, iov->iov_len - base);
87945+ size_t copy = min(bytes, iov->iov_len - base);
87946
87947 base = 0;
87948 left = __copy_from_user_inatomic(vaddr, buf, copy);
87949@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
87950 BUG_ON(!in_atomic());
87951 kaddr = kmap_atomic(page);
87952 if (likely(i->nr_segs == 1)) {
87953- int left;
87954+ size_t left;
87955 char __user *buf = i->iov->iov_base + i->iov_offset;
87956 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
87957 copied = bytes - left;
87958@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
87959
87960 kaddr = kmap(page);
87961 if (likely(i->nr_segs == 1)) {
87962- int left;
87963+ size_t left;
87964 char __user *buf = i->iov->iov_base + i->iov_offset;
87965 left = __copy_from_user(kaddr + offset, buf, bytes);
87966 copied = bytes - left;
87967@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
87968 * zero-length segments (without overruning the iovec).
87969 */
87970 while (bytes || unlikely(i->count && !iov->iov_len)) {
87971- int copy;
87972+ size_t copy;
87973
87974 copy = min(bytes, iov->iov_len - base);
87975 BUG_ON(!i->count || i->count < copy);
87976@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
87977 *pos = i_size_read(inode);
87978
87979 if (limit != RLIM_INFINITY) {
87980+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
87981 if (*pos >= limit) {
87982 send_sig(SIGXFSZ, current, 0);
87983 return -EFBIG;
87984diff --git a/mm/fremap.c b/mm/fremap.c
87985index 5bff081..bfa6e93 100644
87986--- a/mm/fremap.c
87987+++ b/mm/fremap.c
87988@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
87989 retry:
87990 vma = find_vma(mm, start);
87991
87992+#ifdef CONFIG_PAX_SEGMEXEC
87993+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
87994+ goto out;
87995+#endif
87996+
87997 /*
87998 * Make sure the vma is shared, that it supports prefaulting,
87999 * and that the remapped range is valid and fully within
88000@@ -208,9 +213,10 @@ get_write_lock:
88001 if (mapping_cap_account_dirty(mapping)) {
88002 unsigned long addr;
88003 struct file *file = get_file(vma->vm_file);
88004+ /* mmap_region may free vma; grab the info now */
88005+ vm_flags = ACCESS_ONCE(vma->vm_flags);
88006
88007- addr = mmap_region(file, start, size,
88008- vma->vm_flags, pgoff);
88009+ addr = mmap_region(file, start, size, vm_flags, pgoff);
88010 fput(file);
88011 if (IS_ERR_VALUE(addr)) {
88012 err = addr;
88013@@ -218,7 +224,7 @@ get_write_lock:
88014 BUG_ON(addr != start);
88015 err = 0;
88016 }
88017- goto out;
88018+ goto out_freed;
88019 }
88020 mutex_lock(&mapping->i_mmap_mutex);
88021 flush_dcache_mmap_lock(mapping);
88022@@ -253,6 +259,7 @@ get_write_lock:
88023 out:
88024 if (vma)
88025 vm_flags = vma->vm_flags;
88026+out_freed:
88027 if (likely(!has_write_lock))
88028 up_read(&mm->mmap_sem);
88029 else
88030diff --git a/mm/highmem.c b/mm/highmem.c
88031index b32b70c..e512eb0 100644
88032--- a/mm/highmem.c
88033+++ b/mm/highmem.c
88034@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
88035 * So no dangers, even with speculative execution.
88036 */
88037 page = pte_page(pkmap_page_table[i]);
88038+ pax_open_kernel();
88039 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
88040-
88041+ pax_close_kernel();
88042 set_page_address(page, NULL);
88043 need_flush = 1;
88044 }
88045@@ -198,9 +199,11 @@ start:
88046 }
88047 }
88048 vaddr = PKMAP_ADDR(last_pkmap_nr);
88049+
88050+ pax_open_kernel();
88051 set_pte_at(&init_mm, vaddr,
88052 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
88053-
88054+ pax_close_kernel();
88055 pkmap_count[last_pkmap_nr] = 1;
88056 set_page_address(page, (void *)vaddr);
88057
88058diff --git a/mm/hugetlb.c b/mm/hugetlb.c
88059index 0b7656e..d21cefc 100644
88060--- a/mm/hugetlb.c
88061+++ b/mm/hugetlb.c
88062@@ -2094,15 +2094,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
88063 struct hstate *h = &default_hstate;
88064 unsigned long tmp;
88065 int ret;
88066+ ctl_table_no_const hugetlb_table;
88067
88068 tmp = h->max_huge_pages;
88069
88070 if (write && h->order >= MAX_ORDER)
88071 return -EINVAL;
88072
88073- table->data = &tmp;
88074- table->maxlen = sizeof(unsigned long);
88075- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
88076+ hugetlb_table = *table;
88077+ hugetlb_table.data = &tmp;
88078+ hugetlb_table.maxlen = sizeof(unsigned long);
88079+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
88080 if (ret)
88081 goto out;
88082
88083@@ -2147,15 +2149,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
88084 struct hstate *h = &default_hstate;
88085 unsigned long tmp;
88086 int ret;
88087+ ctl_table_no_const hugetlb_table;
88088
88089 tmp = h->nr_overcommit_huge_pages;
88090
88091 if (write && h->order >= MAX_ORDER)
88092 return -EINVAL;
88093
88094- table->data = &tmp;
88095- table->maxlen = sizeof(unsigned long);
88096- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
88097+ hugetlb_table = *table;
88098+ hugetlb_table.data = &tmp;
88099+ hugetlb_table.maxlen = sizeof(unsigned long);
88100+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
88101 if (ret)
88102 goto out;
88103
88104@@ -2605,6 +2609,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
88105 return 1;
88106 }
88107
88108+#ifdef CONFIG_PAX_SEGMEXEC
88109+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
88110+{
88111+ struct mm_struct *mm = vma->vm_mm;
88112+ struct vm_area_struct *vma_m;
88113+ unsigned long address_m;
88114+ pte_t *ptep_m;
88115+
88116+ vma_m = pax_find_mirror_vma(vma);
88117+ if (!vma_m)
88118+ return;
88119+
88120+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88121+ address_m = address + SEGMEXEC_TASK_SIZE;
88122+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
88123+ get_page(page_m);
88124+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
88125+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
88126+}
88127+#endif
88128+
88129 /*
88130 * Hugetlb_cow() should be called with page lock of the original hugepage held.
88131 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
88132@@ -2721,6 +2746,11 @@ retry_avoidcopy:
88133 make_huge_pte(vma, new_page, 1));
88134 page_remove_rmap(old_page);
88135 hugepage_add_new_anon_rmap(new_page, vma, address);
88136+
88137+#ifdef CONFIG_PAX_SEGMEXEC
88138+ pax_mirror_huge_pte(vma, address, new_page);
88139+#endif
88140+
88141 /* Make the old page be freed below */
88142 new_page = old_page;
88143 }
88144@@ -2883,6 +2913,10 @@ retry:
88145 && (vma->vm_flags & VM_SHARED)));
88146 set_huge_pte_at(mm, address, ptep, new_pte);
88147
88148+#ifdef CONFIG_PAX_SEGMEXEC
88149+ pax_mirror_huge_pte(vma, address, page);
88150+#endif
88151+
88152 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
88153 /* Optimization, do the COW without a second fault */
88154 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
88155@@ -2912,6 +2946,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88156 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
88157 struct hstate *h = hstate_vma(vma);
88158
88159+#ifdef CONFIG_PAX_SEGMEXEC
88160+ struct vm_area_struct *vma_m;
88161+#endif
88162+
88163 address &= huge_page_mask(h);
88164
88165 ptep = huge_pte_offset(mm, address);
88166@@ -2925,6 +2963,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88167 VM_FAULT_SET_HINDEX(hstate_index(h));
88168 }
88169
88170+#ifdef CONFIG_PAX_SEGMEXEC
88171+ vma_m = pax_find_mirror_vma(vma);
88172+ if (vma_m) {
88173+ unsigned long address_m;
88174+
88175+ if (vma->vm_start > vma_m->vm_start) {
88176+ address_m = address;
88177+ address -= SEGMEXEC_TASK_SIZE;
88178+ vma = vma_m;
88179+ h = hstate_vma(vma);
88180+ } else
88181+ address_m = address + SEGMEXEC_TASK_SIZE;
88182+
88183+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
88184+ return VM_FAULT_OOM;
88185+ address_m &= HPAGE_MASK;
88186+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
88187+ }
88188+#endif
88189+
88190 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
88191 if (!ptep)
88192 return VM_FAULT_OOM;
88193diff --git a/mm/internal.h b/mm/internal.h
88194index 684f7aa..9eb9edc 100644
88195--- a/mm/internal.h
88196+++ b/mm/internal.h
88197@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
88198 * in mm/page_alloc.c
88199 */
88200 extern void __free_pages_bootmem(struct page *page, unsigned int order);
88201+extern void free_compound_page(struct page *page);
88202 extern void prep_compound_page(struct page *page, unsigned long order);
88203 #ifdef CONFIG_MEMORY_FAILURE
88204 extern bool is_free_buddy_page(struct page *page);
88205@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
88206
88207 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
88208 unsigned long, unsigned long,
88209- unsigned long, unsigned long);
88210+ unsigned long, unsigned long) __intentional_overflow(-1);
88211
88212 extern void set_pageblock_order(void);
88213 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
88214diff --git a/mm/kmemleak.c b/mm/kmemleak.c
88215index e126b0e..e986018 100644
88216--- a/mm/kmemleak.c
88217+++ b/mm/kmemleak.c
88218@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
88219
88220 for (i = 0; i < object->trace_len; i++) {
88221 void *ptr = (void *)object->trace[i];
88222- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
88223+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
88224 }
88225 }
88226
88227@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
88228 return -ENOMEM;
88229 }
88230
88231- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
88232+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
88233 &kmemleak_fops);
88234 if (!dentry)
88235 pr_warning("Failed to create the debugfs kmemleak file\n");
88236diff --git a/mm/maccess.c b/mm/maccess.c
88237index d53adf9..03a24bf 100644
88238--- a/mm/maccess.c
88239+++ b/mm/maccess.c
88240@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
88241 set_fs(KERNEL_DS);
88242 pagefault_disable();
88243 ret = __copy_from_user_inatomic(dst,
88244- (__force const void __user *)src, size);
88245+ (const void __force_user *)src, size);
88246 pagefault_enable();
88247 set_fs(old_fs);
88248
88249@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
88250
88251 set_fs(KERNEL_DS);
88252 pagefault_disable();
88253- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
88254+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
88255 pagefault_enable();
88256 set_fs(old_fs);
88257
88258diff --git a/mm/madvise.c b/mm/madvise.c
88259index 539eeb9..e24a987 100644
88260--- a/mm/madvise.c
88261+++ b/mm/madvise.c
88262@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
88263 pgoff_t pgoff;
88264 unsigned long new_flags = vma->vm_flags;
88265
88266+#ifdef CONFIG_PAX_SEGMEXEC
88267+ struct vm_area_struct *vma_m;
88268+#endif
88269+
88270 switch (behavior) {
88271 case MADV_NORMAL:
88272 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
88273@@ -126,6 +130,13 @@ success:
88274 /*
88275 * vm_flags is protected by the mmap_sem held in write mode.
88276 */
88277+
88278+#ifdef CONFIG_PAX_SEGMEXEC
88279+ vma_m = pax_find_mirror_vma(vma);
88280+ if (vma_m)
88281+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
88282+#endif
88283+
88284 vma->vm_flags = new_flags;
88285
88286 out:
88287@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
88288 struct vm_area_struct **prev,
88289 unsigned long start, unsigned long end)
88290 {
88291+
88292+#ifdef CONFIG_PAX_SEGMEXEC
88293+ struct vm_area_struct *vma_m;
88294+#endif
88295+
88296 *prev = vma;
88297 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
88298 return -EINVAL;
88299@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
88300 zap_page_range(vma, start, end - start, &details);
88301 } else
88302 zap_page_range(vma, start, end - start, NULL);
88303+
88304+#ifdef CONFIG_PAX_SEGMEXEC
88305+ vma_m = pax_find_mirror_vma(vma);
88306+ if (vma_m) {
88307+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
88308+ struct zap_details details = {
88309+ .nonlinear_vma = vma_m,
88310+ .last_index = ULONG_MAX,
88311+ };
88312+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
88313+ } else
88314+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
88315+ }
88316+#endif
88317+
88318 return 0;
88319 }
88320
88321@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
88322 if (end < start)
88323 return error;
88324
88325+#ifdef CONFIG_PAX_SEGMEXEC
88326+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88327+ if (end > SEGMEXEC_TASK_SIZE)
88328+ return error;
88329+ } else
88330+#endif
88331+
88332+ if (end > TASK_SIZE)
88333+ return error;
88334+
88335 error = 0;
88336 if (end == start)
88337 return error;
88338diff --git a/mm/memory-failure.c b/mm/memory-failure.c
88339index bf3351b..aea800d 100644
88340--- a/mm/memory-failure.c
88341+++ b/mm/memory-failure.c
88342@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
88343
88344 int sysctl_memory_failure_recovery __read_mostly = 1;
88345
88346-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
88347+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
88348
88349 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
88350
88351@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
88352 pfn, t->comm, t->pid);
88353 si.si_signo = SIGBUS;
88354 si.si_errno = 0;
88355- si.si_addr = (void *)addr;
88356+ si.si_addr = (void __user *)addr;
88357 #ifdef __ARCH_SI_TRAPNO
88358 si.si_trapno = trapno;
88359 #endif
88360@@ -762,7 +762,7 @@ static struct page_state {
88361 unsigned long res;
88362 char *msg;
88363 int (*action)(struct page *p, unsigned long pfn);
88364-} error_states[] = {
88365+} __do_const error_states[] = {
88366 { reserved, reserved, "reserved kernel", me_kernel },
88367 /*
88368 * free pages are specially detected outside this table:
88369@@ -1053,7 +1053,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88370 nr_pages = 1 << compound_order(hpage);
88371 else /* normal page or thp */
88372 nr_pages = 1;
88373- atomic_long_add(nr_pages, &num_poisoned_pages);
88374+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
88375
88376 /*
88377 * We need/can do nothing about count=0 pages.
88378@@ -1083,7 +1083,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88379 if (!PageHWPoison(hpage)
88380 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
88381 || (p != hpage && TestSetPageHWPoison(hpage))) {
88382- atomic_long_sub(nr_pages, &num_poisoned_pages);
88383+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88384 return 0;
88385 }
88386 set_page_hwpoison_huge_page(hpage);
88387@@ -1152,7 +1152,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
88388 }
88389 if (hwpoison_filter(p)) {
88390 if (TestClearPageHWPoison(p))
88391- atomic_long_sub(nr_pages, &num_poisoned_pages);
88392+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88393 unlock_page(hpage);
88394 put_page(hpage);
88395 return 0;
88396@@ -1370,7 +1370,7 @@ int unpoison_memory(unsigned long pfn)
88397 return 0;
88398 }
88399 if (TestClearPageHWPoison(p))
88400- atomic_long_dec(&num_poisoned_pages);
88401+ atomic_long_dec_unchecked(&num_poisoned_pages);
88402 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
88403 return 0;
88404 }
88405@@ -1384,7 +1384,7 @@ int unpoison_memory(unsigned long pfn)
88406 */
88407 if (TestClearPageHWPoison(page)) {
88408 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
88409- atomic_long_sub(nr_pages, &num_poisoned_pages);
88410+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
88411 freeit = 1;
88412 if (PageHuge(page))
88413 clear_page_hwpoison_huge_page(page);
88414@@ -1521,7 +1521,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
88415 } else {
88416 set_page_hwpoison_huge_page(hpage);
88417 dequeue_hwpoisoned_huge_page(hpage);
88418- atomic_long_add(1 << compound_order(hpage),
88419+ atomic_long_add_unchecked(1 << compound_order(hpage),
88420 &num_poisoned_pages);
88421 }
88422 return ret;
88423@@ -1560,7 +1560,7 @@ static int __soft_offline_page(struct page *page, int flags)
88424 put_page(page);
88425 pr_info("soft_offline: %#lx: invalidated\n", pfn);
88426 SetPageHWPoison(page);
88427- atomic_long_inc(&num_poisoned_pages);
88428+ atomic_long_inc_unchecked(&num_poisoned_pages);
88429 return 0;
88430 }
88431
88432@@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
88433 if (!is_free_buddy_page(page))
88434 pr_info("soft offline: %#lx: page leaked\n",
88435 pfn);
88436- atomic_long_inc(&num_poisoned_pages);
88437+ atomic_long_inc_unchecked(&num_poisoned_pages);
88438 }
88439 } else {
88440 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
88441@@ -1666,11 +1666,11 @@ int soft_offline_page(struct page *page, int flags)
88442 if (PageHuge(page)) {
88443 set_page_hwpoison_huge_page(hpage);
88444 dequeue_hwpoisoned_huge_page(hpage);
88445- atomic_long_add(1 << compound_order(hpage),
88446+ atomic_long_add_unchecked(1 << compound_order(hpage),
88447 &num_poisoned_pages);
88448 } else {
88449 SetPageHWPoison(page);
88450- atomic_long_inc(&num_poisoned_pages);
88451+ atomic_long_inc_unchecked(&num_poisoned_pages);
88452 }
88453 }
88454 unset:
88455diff --git a/mm/memory.c b/mm/memory.c
88456index d176154..cd1b387 100644
88457--- a/mm/memory.c
88458+++ b/mm/memory.c
88459@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
88460 free_pte_range(tlb, pmd, addr);
88461 } while (pmd++, addr = next, addr != end);
88462
88463+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
88464 start &= PUD_MASK;
88465 if (start < floor)
88466 return;
88467@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
88468 pmd = pmd_offset(pud, start);
88469 pud_clear(pud);
88470 pmd_free_tlb(tlb, pmd, start);
88471+#endif
88472+
88473 }
88474
88475 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88476@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88477 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
88478 } while (pud++, addr = next, addr != end);
88479
88480+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
88481 start &= PGDIR_MASK;
88482 if (start < floor)
88483 return;
88484@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
88485 pud = pud_offset(pgd, start);
88486 pgd_clear(pgd);
88487 pud_free_tlb(tlb, pud, start);
88488+#endif
88489+
88490 }
88491
88492 /*
88493@@ -1636,12 +1642,6 @@ no_page_table:
88494 return page;
88495 }
88496
88497-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
88498-{
88499- return stack_guard_page_start(vma, addr) ||
88500- stack_guard_page_end(vma, addr+PAGE_SIZE);
88501-}
88502-
88503 /**
88504 * __get_user_pages() - pin user pages in memory
88505 * @tsk: task_struct of target task
88506@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88507
88508 i = 0;
88509
88510- do {
88511+ while (nr_pages) {
88512 struct vm_area_struct *vma;
88513
88514- vma = find_extend_vma(mm, start);
88515+ vma = find_vma(mm, start);
88516 if (!vma && in_gate_area(mm, start)) {
88517 unsigned long pg = start & PAGE_MASK;
88518 pgd_t *pgd;
88519@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88520 goto next_page;
88521 }
88522
88523- if (!vma ||
88524+ if (!vma || start < vma->vm_start ||
88525 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
88526 !(vm_flags & vma->vm_flags))
88527 return i ? : -EFAULT;
88528@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
88529 int ret;
88530 unsigned int fault_flags = 0;
88531
88532- /* For mlock, just skip the stack guard page. */
88533- if (foll_flags & FOLL_MLOCK) {
88534- if (stack_guard_page(vma, start))
88535- goto next_page;
88536- }
88537 if (foll_flags & FOLL_WRITE)
88538 fault_flags |= FAULT_FLAG_WRITE;
88539 if (nonblocking)
88540@@ -1893,7 +1888,7 @@ next_page:
88541 start += page_increm * PAGE_SIZE;
88542 nr_pages -= page_increm;
88543 } while (nr_pages && start < vma->vm_end);
88544- } while (nr_pages);
88545+ }
88546 return i;
88547 }
88548 EXPORT_SYMBOL(__get_user_pages);
88549@@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
88550 page_add_file_rmap(page);
88551 set_pte_at(mm, addr, pte, mk_pte(page, prot));
88552
88553+#ifdef CONFIG_PAX_SEGMEXEC
88554+ pax_mirror_file_pte(vma, addr, page, ptl);
88555+#endif
88556+
88557 retval = 0;
88558 pte_unmap_unlock(pte, ptl);
88559 return retval;
88560@@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
88561 if (!page_count(page))
88562 return -EINVAL;
88563 if (!(vma->vm_flags & VM_MIXEDMAP)) {
88564+
88565+#ifdef CONFIG_PAX_SEGMEXEC
88566+ struct vm_area_struct *vma_m;
88567+#endif
88568+
88569 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
88570 BUG_ON(vma->vm_flags & VM_PFNMAP);
88571 vma->vm_flags |= VM_MIXEDMAP;
88572+
88573+#ifdef CONFIG_PAX_SEGMEXEC
88574+ vma_m = pax_find_mirror_vma(vma);
88575+ if (vma_m)
88576+ vma_m->vm_flags |= VM_MIXEDMAP;
88577+#endif
88578+
88579 }
88580 return insert_page(vma, addr, page, vma->vm_page_prot);
88581 }
88582@@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
88583 unsigned long pfn)
88584 {
88585 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
88586+ BUG_ON(vma->vm_mirror);
88587
88588 if (addr < vma->vm_start || addr >= vma->vm_end)
88589 return -EFAULT;
88590@@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
88591
88592 BUG_ON(pud_huge(*pud));
88593
88594- pmd = pmd_alloc(mm, pud, addr);
88595+ pmd = (mm == &init_mm) ?
88596+ pmd_alloc_kernel(mm, pud, addr) :
88597+ pmd_alloc(mm, pud, addr);
88598 if (!pmd)
88599 return -ENOMEM;
88600 do {
88601@@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
88602 unsigned long next;
88603 int err;
88604
88605- pud = pud_alloc(mm, pgd, addr);
88606+ pud = (mm == &init_mm) ?
88607+ pud_alloc_kernel(mm, pgd, addr) :
88608+ pud_alloc(mm, pgd, addr);
88609 if (!pud)
88610 return -ENOMEM;
88611 do {
88612@@ -2584,6 +2600,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
88613 copy_user_highpage(dst, src, va, vma);
88614 }
88615
88616+#ifdef CONFIG_PAX_SEGMEXEC
88617+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
88618+{
88619+ struct mm_struct *mm = vma->vm_mm;
88620+ spinlock_t *ptl;
88621+ pte_t *pte, entry;
88622+
88623+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
88624+ entry = *pte;
88625+ if (!pte_present(entry)) {
88626+ if (!pte_none(entry)) {
88627+ BUG_ON(pte_file(entry));
88628+ free_swap_and_cache(pte_to_swp_entry(entry));
88629+ pte_clear_not_present_full(mm, address, pte, 0);
88630+ }
88631+ } else {
88632+ struct page *page;
88633+
88634+ flush_cache_page(vma, address, pte_pfn(entry));
88635+ entry = ptep_clear_flush(vma, address, pte);
88636+ BUG_ON(pte_dirty(entry));
88637+ page = vm_normal_page(vma, address, entry);
88638+ if (page) {
88639+ update_hiwater_rss(mm);
88640+ if (PageAnon(page))
88641+ dec_mm_counter_fast(mm, MM_ANONPAGES);
88642+ else
88643+ dec_mm_counter_fast(mm, MM_FILEPAGES);
88644+ page_remove_rmap(page);
88645+ page_cache_release(page);
88646+ }
88647+ }
88648+ pte_unmap_unlock(pte, ptl);
88649+}
88650+
88651+/* PaX: if vma is mirrored, synchronize the mirror's PTE
88652+ *
88653+ * the ptl of the lower mapped page is held on entry and is not released on exit
88654+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
88655+ */
88656+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
88657+{
88658+ struct mm_struct *mm = vma->vm_mm;
88659+ unsigned long address_m;
88660+ spinlock_t *ptl_m;
88661+ struct vm_area_struct *vma_m;
88662+ pmd_t *pmd_m;
88663+ pte_t *pte_m, entry_m;
88664+
88665+ BUG_ON(!page_m || !PageAnon(page_m));
88666+
88667+ vma_m = pax_find_mirror_vma(vma);
88668+ if (!vma_m)
88669+ return;
88670+
88671+ BUG_ON(!PageLocked(page_m));
88672+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88673+ address_m = address + SEGMEXEC_TASK_SIZE;
88674+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88675+ pte_m = pte_offset_map(pmd_m, address_m);
88676+ ptl_m = pte_lockptr(mm, pmd_m);
88677+ if (ptl != ptl_m) {
88678+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88679+ if (!pte_none(*pte_m))
88680+ goto out;
88681+ }
88682+
88683+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88684+ page_cache_get(page_m);
88685+ page_add_anon_rmap(page_m, vma_m, address_m);
88686+ inc_mm_counter_fast(mm, MM_ANONPAGES);
88687+ set_pte_at(mm, address_m, pte_m, entry_m);
88688+ update_mmu_cache(vma_m, address_m, pte_m);
88689+out:
88690+ if (ptl != ptl_m)
88691+ spin_unlock(ptl_m);
88692+ pte_unmap(pte_m);
88693+ unlock_page(page_m);
88694+}
88695+
88696+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
88697+{
88698+ struct mm_struct *mm = vma->vm_mm;
88699+ unsigned long address_m;
88700+ spinlock_t *ptl_m;
88701+ struct vm_area_struct *vma_m;
88702+ pmd_t *pmd_m;
88703+ pte_t *pte_m, entry_m;
88704+
88705+ BUG_ON(!page_m || PageAnon(page_m));
88706+
88707+ vma_m = pax_find_mirror_vma(vma);
88708+ if (!vma_m)
88709+ return;
88710+
88711+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88712+ address_m = address + SEGMEXEC_TASK_SIZE;
88713+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88714+ pte_m = pte_offset_map(pmd_m, address_m);
88715+ ptl_m = pte_lockptr(mm, pmd_m);
88716+ if (ptl != ptl_m) {
88717+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88718+ if (!pte_none(*pte_m))
88719+ goto out;
88720+ }
88721+
88722+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88723+ page_cache_get(page_m);
88724+ page_add_file_rmap(page_m);
88725+ inc_mm_counter_fast(mm, MM_FILEPAGES);
88726+ set_pte_at(mm, address_m, pte_m, entry_m);
88727+ update_mmu_cache(vma_m, address_m, pte_m);
88728+out:
88729+ if (ptl != ptl_m)
88730+ spin_unlock(ptl_m);
88731+ pte_unmap(pte_m);
88732+}
88733+
88734+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
88735+{
88736+ struct mm_struct *mm = vma->vm_mm;
88737+ unsigned long address_m;
88738+ spinlock_t *ptl_m;
88739+ struct vm_area_struct *vma_m;
88740+ pmd_t *pmd_m;
88741+ pte_t *pte_m, entry_m;
88742+
88743+ vma_m = pax_find_mirror_vma(vma);
88744+ if (!vma_m)
88745+ return;
88746+
88747+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88748+ address_m = address + SEGMEXEC_TASK_SIZE;
88749+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88750+ pte_m = pte_offset_map(pmd_m, address_m);
88751+ ptl_m = pte_lockptr(mm, pmd_m);
88752+ if (ptl != ptl_m) {
88753+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88754+ if (!pte_none(*pte_m))
88755+ goto out;
88756+ }
88757+
88758+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
88759+ set_pte_at(mm, address_m, pte_m, entry_m);
88760+out:
88761+ if (ptl != ptl_m)
88762+ spin_unlock(ptl_m);
88763+ pte_unmap(pte_m);
88764+}
88765+
88766+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
88767+{
88768+ struct page *page_m;
88769+ pte_t entry;
88770+
88771+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
88772+ goto out;
88773+
88774+ entry = *pte;
88775+ page_m = vm_normal_page(vma, address, entry);
88776+ if (!page_m)
88777+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
88778+ else if (PageAnon(page_m)) {
88779+ if (pax_find_mirror_vma(vma)) {
88780+ pte_unmap_unlock(pte, ptl);
88781+ lock_page(page_m);
88782+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
88783+ if (pte_same(entry, *pte))
88784+ pax_mirror_anon_pte(vma, address, page_m, ptl);
88785+ else
88786+ unlock_page(page_m);
88787+ }
88788+ } else
88789+ pax_mirror_file_pte(vma, address, page_m, ptl);
88790+
88791+out:
88792+ pte_unmap_unlock(pte, ptl);
88793+}
88794+#endif
88795+
88796 /*
88797 * This routine handles present pages, when users try to write
88798 * to a shared page. It is done by copying the page to a new address
88799@@ -2800,6 +2996,12 @@ gotten:
88800 */
88801 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88802 if (likely(pte_same(*page_table, orig_pte))) {
88803+
88804+#ifdef CONFIG_PAX_SEGMEXEC
88805+ if (pax_find_mirror_vma(vma))
88806+ BUG_ON(!trylock_page(new_page));
88807+#endif
88808+
88809 if (old_page) {
88810 if (!PageAnon(old_page)) {
88811 dec_mm_counter_fast(mm, MM_FILEPAGES);
88812@@ -2851,6 +3053,10 @@ gotten:
88813 page_remove_rmap(old_page);
88814 }
88815
88816+#ifdef CONFIG_PAX_SEGMEXEC
88817+ pax_mirror_anon_pte(vma, address, new_page, ptl);
88818+#endif
88819+
88820 /* Free the old page.. */
88821 new_page = old_page;
88822 ret |= VM_FAULT_WRITE;
88823@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88824 swap_free(entry);
88825 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
88826 try_to_free_swap(page);
88827+
88828+#ifdef CONFIG_PAX_SEGMEXEC
88829+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
88830+#endif
88831+
88832 unlock_page(page);
88833 if (page != swapcache) {
88834 /*
88835@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88836
88837 /* No need to invalidate - it was non-present before */
88838 update_mmu_cache(vma, address, page_table);
88839+
88840+#ifdef CONFIG_PAX_SEGMEXEC
88841+ pax_mirror_anon_pte(vma, address, page, ptl);
88842+#endif
88843+
88844 unlock:
88845 pte_unmap_unlock(page_table, ptl);
88846 out:
88847@@ -3170,40 +3386,6 @@ out_release:
88848 }
88849
88850 /*
88851- * This is like a special single-page "expand_{down|up}wards()",
88852- * except we must first make sure that 'address{-|+}PAGE_SIZE'
88853- * doesn't hit another vma.
88854- */
88855-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
88856-{
88857- address &= PAGE_MASK;
88858- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
88859- struct vm_area_struct *prev = vma->vm_prev;
88860-
88861- /*
88862- * Is there a mapping abutting this one below?
88863- *
88864- * That's only ok if it's the same stack mapping
88865- * that has gotten split..
88866- */
88867- if (prev && prev->vm_end == address)
88868- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
88869-
88870- expand_downwards(vma, address - PAGE_SIZE);
88871- }
88872- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
88873- struct vm_area_struct *next = vma->vm_next;
88874-
88875- /* As VM_GROWSDOWN but s/below/above/ */
88876- if (next && next->vm_start == address + PAGE_SIZE)
88877- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
88878-
88879- expand_upwards(vma, address + PAGE_SIZE);
88880- }
88881- return 0;
88882-}
88883-
88884-/*
88885 * We enter with non-exclusive mmap_sem (to exclude vma changes,
88886 * but allow concurrent faults), and pte mapped but not yet locked.
88887 * We return with mmap_sem still held, but pte unmapped and unlocked.
88888@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88889 unsigned long address, pte_t *page_table, pmd_t *pmd,
88890 unsigned int flags)
88891 {
88892- struct page *page;
88893+ struct page *page = NULL;
88894 spinlock_t *ptl;
88895 pte_t entry;
88896
88897- pte_unmap(page_table);
88898-
88899- /* Check if we need to add a guard page to the stack */
88900- if (check_stack_guard_page(vma, address) < 0)
88901- return VM_FAULT_SIGBUS;
88902-
88903- /* Use the zero-page for reads */
88904 if (!(flags & FAULT_FLAG_WRITE)) {
88905 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
88906 vma->vm_page_prot));
88907- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88908+ ptl = pte_lockptr(mm, pmd);
88909+ spin_lock(ptl);
88910 if (!pte_none(*page_table))
88911 goto unlock;
88912 goto setpte;
88913 }
88914
88915 /* Allocate our own private page. */
88916+ pte_unmap(page_table);
88917+
88918 if (unlikely(anon_vma_prepare(vma)))
88919 goto oom;
88920 page = alloc_zeroed_user_highpage_movable(vma, address);
88921@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88922 if (!pte_none(*page_table))
88923 goto release;
88924
88925+#ifdef CONFIG_PAX_SEGMEXEC
88926+ if (pax_find_mirror_vma(vma))
88927+ BUG_ON(!trylock_page(page));
88928+#endif
88929+
88930 inc_mm_counter_fast(mm, MM_ANONPAGES);
88931 page_add_new_anon_rmap(page, vma, address);
88932 setpte:
88933@@ -3263,6 +3446,12 @@ setpte:
88934
88935 /* No need to invalidate - it was non-present before */
88936 update_mmu_cache(vma, address, page_table);
88937+
88938+#ifdef CONFIG_PAX_SEGMEXEC
88939+ if (page)
88940+ pax_mirror_anon_pte(vma, address, page, ptl);
88941+#endif
88942+
88943 unlock:
88944 pte_unmap_unlock(page_table, ptl);
88945 return 0;
88946@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88947 */
88948 /* Only go through if we didn't race with anybody else... */
88949 if (likely(pte_same(*page_table, orig_pte))) {
88950+
88951+#ifdef CONFIG_PAX_SEGMEXEC
88952+ if (anon && pax_find_mirror_vma(vma))
88953+ BUG_ON(!trylock_page(page));
88954+#endif
88955+
88956 flush_icache_page(vma, page);
88957 entry = mk_pte(page, vma->vm_page_prot);
88958 if (flags & FAULT_FLAG_WRITE)
88959@@ -3427,6 +3622,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88960
88961 /* no need to invalidate: a not-present page won't be cached */
88962 update_mmu_cache(vma, address, page_table);
88963+
88964+#ifdef CONFIG_PAX_SEGMEXEC
88965+ if (anon)
88966+ pax_mirror_anon_pte(vma, address, page, ptl);
88967+ else
88968+ pax_mirror_file_pte(vma, address, page, ptl);
88969+#endif
88970+
88971 } else {
88972 if (cow_page)
88973 mem_cgroup_uncharge_page(cow_page);
88974@@ -3737,6 +3940,12 @@ static int handle_pte_fault(struct mm_struct *mm,
88975 if (flags & FAULT_FLAG_WRITE)
88976 flush_tlb_fix_spurious_fault(vma, address);
88977 }
88978+
88979+#ifdef CONFIG_PAX_SEGMEXEC
88980+ pax_mirror_pte(vma, address, pte, pmd, ptl);
88981+ return 0;
88982+#endif
88983+
88984 unlock:
88985 pte_unmap_unlock(pte, ptl);
88986 return 0;
88987@@ -3753,9 +3962,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88988 pmd_t *pmd;
88989 pte_t *pte;
88990
88991+#ifdef CONFIG_PAX_SEGMEXEC
88992+ struct vm_area_struct *vma_m;
88993+#endif
88994+
88995 if (unlikely(is_vm_hugetlb_page(vma)))
88996 return hugetlb_fault(mm, vma, address, flags);
88997
88998+#ifdef CONFIG_PAX_SEGMEXEC
88999+ vma_m = pax_find_mirror_vma(vma);
89000+ if (vma_m) {
89001+ unsigned long address_m;
89002+ pgd_t *pgd_m;
89003+ pud_t *pud_m;
89004+ pmd_t *pmd_m;
89005+
89006+ if (vma->vm_start > vma_m->vm_start) {
89007+ address_m = address;
89008+ address -= SEGMEXEC_TASK_SIZE;
89009+ vma = vma_m;
89010+ } else
89011+ address_m = address + SEGMEXEC_TASK_SIZE;
89012+
89013+ pgd_m = pgd_offset(mm, address_m);
89014+ pud_m = pud_alloc(mm, pgd_m, address_m);
89015+ if (!pud_m)
89016+ return VM_FAULT_OOM;
89017+ pmd_m = pmd_alloc(mm, pud_m, address_m);
89018+ if (!pmd_m)
89019+ return VM_FAULT_OOM;
89020+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
89021+ return VM_FAULT_OOM;
89022+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
89023+ }
89024+#endif
89025+
89026 retry:
89027 pgd = pgd_offset(mm, address);
89028 pud = pud_alloc(mm, pgd, address);
89029@@ -3894,6 +4135,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
89030 spin_unlock(&mm->page_table_lock);
89031 return 0;
89032 }
89033+
89034+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
89035+{
89036+ pud_t *new = pud_alloc_one(mm, address);
89037+ if (!new)
89038+ return -ENOMEM;
89039+
89040+ smp_wmb(); /* See comment in __pte_alloc */
89041+
89042+ spin_lock(&mm->page_table_lock);
89043+ if (pgd_present(*pgd)) /* Another has populated it */
89044+ pud_free(mm, new);
89045+ else
89046+ pgd_populate_kernel(mm, pgd, new);
89047+ spin_unlock(&mm->page_table_lock);
89048+ return 0;
89049+}
89050 #endif /* __PAGETABLE_PUD_FOLDED */
89051
89052 #ifndef __PAGETABLE_PMD_FOLDED
89053@@ -3924,6 +4182,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
89054 spin_unlock(&mm->page_table_lock);
89055 return 0;
89056 }
89057+
89058+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
89059+{
89060+ pmd_t *new = pmd_alloc_one(mm, address);
89061+ if (!new)
89062+ return -ENOMEM;
89063+
89064+ smp_wmb(); /* See comment in __pte_alloc */
89065+
89066+ spin_lock(&mm->page_table_lock);
89067+#ifndef __ARCH_HAS_4LEVEL_HACK
89068+ if (pud_present(*pud)) /* Another has populated it */
89069+ pmd_free(mm, new);
89070+ else
89071+ pud_populate_kernel(mm, pud, new);
89072+#else
89073+ if (pgd_present(*pud)) /* Another has populated it */
89074+ pmd_free(mm, new);
89075+ else
89076+ pgd_populate_kernel(mm, pud, new);
89077+#endif /* __ARCH_HAS_4LEVEL_HACK */
89078+ spin_unlock(&mm->page_table_lock);
89079+ return 0;
89080+}
89081 #endif /* __PAGETABLE_PMD_FOLDED */
89082
89083 #if !defined(__HAVE_ARCH_GATE_AREA)
89084@@ -3937,7 +4219,7 @@ static int __init gate_vma_init(void)
89085 gate_vma.vm_start = FIXADDR_USER_START;
89086 gate_vma.vm_end = FIXADDR_USER_END;
89087 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
89088- gate_vma.vm_page_prot = __P101;
89089+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
89090
89091 return 0;
89092 }
89093@@ -4071,8 +4353,8 @@ out:
89094 return ret;
89095 }
89096
89097-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
89098- void *buf, int len, int write)
89099+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
89100+ void *buf, size_t len, int write)
89101 {
89102 resource_size_t phys_addr;
89103 unsigned long prot = 0;
89104@@ -4098,8 +4380,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
89105 * Access another process' address space as given in mm. If non-NULL, use the
89106 * given task for page fault accounting.
89107 */
89108-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89109- unsigned long addr, void *buf, int len, int write)
89110+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89111+ unsigned long addr, void *buf, size_t len, int write)
89112 {
89113 struct vm_area_struct *vma;
89114 void *old_buf = buf;
89115@@ -4107,7 +4389,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89116 down_read(&mm->mmap_sem);
89117 /* ignore errors, just check how much was successfully transferred */
89118 while (len) {
89119- int bytes, ret, offset;
89120+ ssize_t bytes, ret, offset;
89121 void *maddr;
89122 struct page *page = NULL;
89123
89124@@ -4166,8 +4448,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89125 *
89126 * The caller must hold a reference on @mm.
89127 */
89128-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89129- void *buf, int len, int write)
89130+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
89131+ void *buf, size_t len, int write)
89132 {
89133 return __access_remote_vm(NULL, mm, addr, buf, len, write);
89134 }
89135@@ -4177,11 +4459,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89136 * Source/target buffer must be kernel space,
89137 * Do not walk the page table directly, use get_user_pages
89138 */
89139-int access_process_vm(struct task_struct *tsk, unsigned long addr,
89140- void *buf, int len, int write)
89141+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
89142+ void *buf, size_t len, int write)
89143 {
89144 struct mm_struct *mm;
89145- int ret;
89146+ ssize_t ret;
89147
89148 mm = get_task_mm(tsk);
89149 if (!mm)
89150diff --git a/mm/mempolicy.c b/mm/mempolicy.c
89151index 0472964..7d5a0ea 100644
89152--- a/mm/mempolicy.c
89153+++ b/mm/mempolicy.c
89154@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
89155 unsigned long vmstart;
89156 unsigned long vmend;
89157
89158+#ifdef CONFIG_PAX_SEGMEXEC
89159+ struct vm_area_struct *vma_m;
89160+#endif
89161+
89162 vma = find_vma(mm, start);
89163 if (!vma || vma->vm_start > start)
89164 return -EFAULT;
89165@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
89166 err = vma_replace_policy(vma, new_pol);
89167 if (err)
89168 goto out;
89169+
89170+#ifdef CONFIG_PAX_SEGMEXEC
89171+ vma_m = pax_find_mirror_vma(vma);
89172+ if (vma_m) {
89173+ err = vma_replace_policy(vma_m, new_pol);
89174+ if (err)
89175+ goto out;
89176+ }
89177+#endif
89178+
89179 }
89180
89181 out:
89182@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
89183
89184 if (end < start)
89185 return -EINVAL;
89186+
89187+#ifdef CONFIG_PAX_SEGMEXEC
89188+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89189+ if (end > SEGMEXEC_TASK_SIZE)
89190+ return -EINVAL;
89191+ } else
89192+#endif
89193+
89194+ if (end > TASK_SIZE)
89195+ return -EINVAL;
89196+
89197 if (end == start)
89198 return 0;
89199
89200@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
89201 */
89202 tcred = __task_cred(task);
89203 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
89204- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
89205- !capable(CAP_SYS_NICE)) {
89206+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
89207 rcu_read_unlock();
89208 err = -EPERM;
89209 goto out_put;
89210@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
89211 goto out;
89212 }
89213
89214+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
89215+ if (mm != current->mm &&
89216+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
89217+ mmput(mm);
89218+ err = -EPERM;
89219+ goto out;
89220+ }
89221+#endif
89222+
89223 err = do_migrate_pages(mm, old, new,
89224 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
89225
89226diff --git a/mm/migrate.c b/mm/migrate.c
89227index c046927..6996b40 100644
89228--- a/mm/migrate.c
89229+++ b/mm/migrate.c
89230@@ -1404,8 +1404,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
89231 */
89232 tcred = __task_cred(task);
89233 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
89234- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
89235- !capable(CAP_SYS_NICE)) {
89236+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
89237 rcu_read_unlock();
89238 err = -EPERM;
89239 goto out;
89240diff --git a/mm/mlock.c b/mm/mlock.c
89241index d480cd6..0f98458 100644
89242--- a/mm/mlock.c
89243+++ b/mm/mlock.c
89244@@ -14,6 +14,7 @@
89245 #include <linux/pagevec.h>
89246 #include <linux/mempolicy.h>
89247 #include <linux/syscalls.h>
89248+#include <linux/security.h>
89249 #include <linux/sched.h>
89250 #include <linux/export.h>
89251 #include <linux/rmap.h>
89252@@ -568,7 +569,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
89253 {
89254 unsigned long nstart, end, tmp;
89255 struct vm_area_struct * vma, * prev;
89256- int error;
89257+ int error = 0;
89258
89259 VM_BUG_ON(start & ~PAGE_MASK);
89260 VM_BUG_ON(len != PAGE_ALIGN(len));
89261@@ -577,6 +578,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
89262 return -EINVAL;
89263 if (end == start)
89264 return 0;
89265+ if (end > TASK_SIZE)
89266+ return -EINVAL;
89267+
89268 vma = find_vma(current->mm, start);
89269 if (!vma || vma->vm_start > start)
89270 return -ENOMEM;
89271@@ -588,6 +592,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
89272 for (nstart = start ; ; ) {
89273 vm_flags_t newflags;
89274
89275+#ifdef CONFIG_PAX_SEGMEXEC
89276+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
89277+ break;
89278+#endif
89279+
89280 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
89281
89282 newflags = vma->vm_flags & ~VM_LOCKED;
89283@@ -700,6 +709,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
89284 lock_limit >>= PAGE_SHIFT;
89285
89286 /* check against resource limits */
89287+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
89288 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
89289 error = do_mlock(start, len, 1);
89290 up_write(&current->mm->mmap_sem);
89291@@ -734,6 +744,11 @@ static int do_mlockall(int flags)
89292 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
89293 vm_flags_t newflags;
89294
89295+#ifdef CONFIG_PAX_SEGMEXEC
89296+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
89297+ break;
89298+#endif
89299+
89300 newflags = vma->vm_flags & ~VM_LOCKED;
89301 if (flags & MCL_CURRENT)
89302 newflags |= VM_LOCKED;
89303@@ -767,6 +782,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
89304 lock_limit >>= PAGE_SHIFT;
89305
89306 ret = -ENOMEM;
89307+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
89308 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
89309 capable(CAP_IPC_LOCK))
89310 ret = do_mlockall(flags);
89311diff --git a/mm/mmap.c b/mm/mmap.c
89312index 362e5f1..8968e02 100644
89313--- a/mm/mmap.c
89314+++ b/mm/mmap.c
89315@@ -36,6 +36,7 @@
89316 #include <linux/sched/sysctl.h>
89317 #include <linux/notifier.h>
89318 #include <linux/memory.h>
89319+#include <linux/random.h>
89320
89321 #include <asm/uaccess.h>
89322 #include <asm/cacheflush.h>
89323@@ -52,6 +53,16 @@
89324 #define arch_rebalance_pgtables(addr, len) (addr)
89325 #endif
89326
89327+static inline void verify_mm_writelocked(struct mm_struct *mm)
89328+{
89329+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
89330+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89331+ up_read(&mm->mmap_sem);
89332+ BUG();
89333+ }
89334+#endif
89335+}
89336+
89337 static void unmap_region(struct mm_struct *mm,
89338 struct vm_area_struct *vma, struct vm_area_struct *prev,
89339 unsigned long start, unsigned long end);
89340@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
89341 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
89342 *
89343 */
89344-pgprot_t protection_map[16] = {
89345+pgprot_t protection_map[16] __read_only = {
89346 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
89347 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
89348 };
89349
89350-pgprot_t vm_get_page_prot(unsigned long vm_flags)
89351+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
89352 {
89353- return __pgprot(pgprot_val(protection_map[vm_flags &
89354+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
89355 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
89356 pgprot_val(arch_vm_get_page_prot(vm_flags)));
89357+
89358+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89359+ if (!(__supported_pte_mask & _PAGE_NX) &&
89360+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
89361+ (vm_flags & (VM_READ | VM_WRITE)))
89362+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
89363+#endif
89364+
89365+ return prot;
89366 }
89367 EXPORT_SYMBOL(vm_get_page_prot);
89368
89369@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
89370 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
89371 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
89372 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
89373+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
89374 /*
89375 * Make sure vm_committed_as in one cacheline and not cacheline shared with
89376 * other variables. It can be updated by several CPUs frequently.
89377@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
89378 struct vm_area_struct *next = vma->vm_next;
89379
89380 might_sleep();
89381+ BUG_ON(vma->vm_mirror);
89382 if (vma->vm_ops && vma->vm_ops->close)
89383 vma->vm_ops->close(vma);
89384 if (vma->vm_file)
89385@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
89386 * not page aligned -Ram Gupta
89387 */
89388 rlim = rlimit(RLIMIT_DATA);
89389+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
89390 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
89391 (mm->end_data - mm->start_data) > rlim)
89392 goto out;
89393@@ -933,6 +956,12 @@ static int
89394 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
89395 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
89396 {
89397+
89398+#ifdef CONFIG_PAX_SEGMEXEC
89399+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
89400+ return 0;
89401+#endif
89402+
89403 if (is_mergeable_vma(vma, file, vm_flags) &&
89404 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
89405 if (vma->vm_pgoff == vm_pgoff)
89406@@ -952,6 +981,12 @@ static int
89407 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
89408 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
89409 {
89410+
89411+#ifdef CONFIG_PAX_SEGMEXEC
89412+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
89413+ return 0;
89414+#endif
89415+
89416 if (is_mergeable_vma(vma, file, vm_flags) &&
89417 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
89418 pgoff_t vm_pglen;
89419@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
89420 struct vm_area_struct *vma_merge(struct mm_struct *mm,
89421 struct vm_area_struct *prev, unsigned long addr,
89422 unsigned long end, unsigned long vm_flags,
89423- struct anon_vma *anon_vma, struct file *file,
89424+ struct anon_vma *anon_vma, struct file *file,
89425 pgoff_t pgoff, struct mempolicy *policy)
89426 {
89427 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
89428 struct vm_area_struct *area, *next;
89429 int err;
89430
89431+#ifdef CONFIG_PAX_SEGMEXEC
89432+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
89433+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
89434+
89435+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
89436+#endif
89437+
89438 /*
89439 * We later require that vma->vm_flags == vm_flags,
89440 * so this tests vma->vm_flags & VM_SPECIAL, too.
89441@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89442 if (next && next->vm_end == end) /* cases 6, 7, 8 */
89443 next = next->vm_next;
89444
89445+#ifdef CONFIG_PAX_SEGMEXEC
89446+ if (prev)
89447+ prev_m = pax_find_mirror_vma(prev);
89448+ if (area)
89449+ area_m = pax_find_mirror_vma(area);
89450+ if (next)
89451+ next_m = pax_find_mirror_vma(next);
89452+#endif
89453+
89454 /*
89455 * Can it merge with the predecessor?
89456 */
89457@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89458 /* cases 1, 6 */
89459 err = vma_adjust(prev, prev->vm_start,
89460 next->vm_end, prev->vm_pgoff, NULL);
89461- } else /* cases 2, 5, 7 */
89462+
89463+#ifdef CONFIG_PAX_SEGMEXEC
89464+ if (!err && prev_m)
89465+ err = vma_adjust(prev_m, prev_m->vm_start,
89466+ next_m->vm_end, prev_m->vm_pgoff, NULL);
89467+#endif
89468+
89469+ } else { /* cases 2, 5, 7 */
89470 err = vma_adjust(prev, prev->vm_start,
89471 end, prev->vm_pgoff, NULL);
89472+
89473+#ifdef CONFIG_PAX_SEGMEXEC
89474+ if (!err && prev_m)
89475+ err = vma_adjust(prev_m, prev_m->vm_start,
89476+ end_m, prev_m->vm_pgoff, NULL);
89477+#endif
89478+
89479+ }
89480 if (err)
89481 return NULL;
89482 khugepaged_enter_vma_merge(prev);
89483@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
89484 mpol_equal(policy, vma_policy(next)) &&
89485 can_vma_merge_before(next, vm_flags,
89486 anon_vma, file, pgoff+pglen)) {
89487- if (prev && addr < prev->vm_end) /* case 4 */
89488+ if (prev && addr < prev->vm_end) { /* case 4 */
89489 err = vma_adjust(prev, prev->vm_start,
89490 addr, prev->vm_pgoff, NULL);
89491- else /* cases 3, 8 */
89492+
89493+#ifdef CONFIG_PAX_SEGMEXEC
89494+ if (!err && prev_m)
89495+ err = vma_adjust(prev_m, prev_m->vm_start,
89496+ addr_m, prev_m->vm_pgoff, NULL);
89497+#endif
89498+
89499+ } else { /* cases 3, 8 */
89500 err = vma_adjust(area, addr, next->vm_end,
89501 next->vm_pgoff - pglen, NULL);
89502+
89503+#ifdef CONFIG_PAX_SEGMEXEC
89504+ if (!err && area_m)
89505+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
89506+ next_m->vm_pgoff - pglen, NULL);
89507+#endif
89508+
89509+ }
89510 if (err)
89511 return NULL;
89512 khugepaged_enter_vma_merge(area);
89513@@ -1165,8 +1246,10 @@ none:
89514 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
89515 struct file *file, long pages)
89516 {
89517- const unsigned long stack_flags
89518- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
89519+
89520+#ifdef CONFIG_PAX_RANDMMAP
89521+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
89522+#endif
89523
89524 mm->total_vm += pages;
89525
89526@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
89527 mm->shared_vm += pages;
89528 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
89529 mm->exec_vm += pages;
89530- } else if (flags & stack_flags)
89531+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
89532 mm->stack_vm += pages;
89533 }
89534 #endif /* CONFIG_PROC_FS */
89535@@ -1212,7 +1295,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89536 * (the exception is when the underlying filesystem is noexec
89537 * mounted, in which case we dont add PROT_EXEC.)
89538 */
89539- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
89540+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
89541 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
89542 prot |= PROT_EXEC;
89543
89544@@ -1238,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89545 /* Obtain the address to map to. we verify (or select) it and ensure
89546 * that it represents a valid section of the address space.
89547 */
89548- addr = get_unmapped_area(file, addr, len, pgoff, flags);
89549+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
89550 if (addr & ~PAGE_MASK)
89551 return addr;
89552
89553@@ -1249,6 +1332,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89554 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
89555 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
89556
89557+#ifdef CONFIG_PAX_MPROTECT
89558+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89559+
89560+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
89561+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
89562+ mm->binfmt->handle_mmap)
89563+ mm->binfmt->handle_mmap(file);
89564+#endif
89565+
89566+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89567+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
89568+ gr_log_rwxmmap(file);
89569+
89570+#ifdef CONFIG_PAX_EMUPLT
89571+ vm_flags &= ~VM_EXEC;
89572+#else
89573+ return -EPERM;
89574+#endif
89575+
89576+ }
89577+
89578+ if (!(vm_flags & VM_EXEC))
89579+ vm_flags &= ~VM_MAYEXEC;
89580+#else
89581+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89582+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89583+#endif
89584+ else
89585+ vm_flags &= ~VM_MAYWRITE;
89586+ }
89587+#endif
89588+
89589+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89590+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
89591+ vm_flags &= ~VM_PAGEEXEC;
89592+#endif
89593+
89594 if (flags & MAP_LOCKED)
89595 if (!can_do_mlock())
89596 return -EPERM;
89597@@ -1260,6 +1380,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89598 locked += mm->locked_vm;
89599 lock_limit = rlimit(RLIMIT_MEMLOCK);
89600 lock_limit >>= PAGE_SHIFT;
89601+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89602 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
89603 return -EAGAIN;
89604 }
89605@@ -1344,6 +1465,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
89606 vm_flags |= VM_NORESERVE;
89607 }
89608
89609+ if (!gr_acl_handle_mmap(file, prot))
89610+ return -EACCES;
89611+
89612 addr = mmap_region(file, addr, len, vm_flags, pgoff);
89613 if (!IS_ERR_VALUE(addr) &&
89614 ((vm_flags & VM_LOCKED) ||
89615@@ -1437,7 +1561,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
89616 vm_flags_t vm_flags = vma->vm_flags;
89617
89618 /* If it was private or non-writable, the write bit is already clear */
89619- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
89620+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
89621 return 0;
89622
89623 /* The backer wishes to know when pages are first written to? */
89624@@ -1483,7 +1607,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
89625 struct rb_node **rb_link, *rb_parent;
89626 unsigned long charged = 0;
89627
89628+#ifdef CONFIG_PAX_SEGMEXEC
89629+ struct vm_area_struct *vma_m = NULL;
89630+#endif
89631+
89632+ /*
89633+ * mm->mmap_sem is required to protect against another thread
89634+ * changing the mappings in case we sleep.
89635+ */
89636+ verify_mm_writelocked(mm);
89637+
89638 /* Check against address space limit. */
89639+
89640+#ifdef CONFIG_PAX_RANDMMAP
89641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
89642+#endif
89643+
89644 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
89645 unsigned long nr_pages;
89646
89647@@ -1502,11 +1641,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
89648
89649 /* Clear old maps */
89650 error = -ENOMEM;
89651-munmap_back:
89652 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89653 if (do_munmap(mm, addr, len))
89654 return -ENOMEM;
89655- goto munmap_back;
89656+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89657 }
89658
89659 /*
89660@@ -1537,6 +1675,16 @@ munmap_back:
89661 goto unacct_error;
89662 }
89663
89664+#ifdef CONFIG_PAX_SEGMEXEC
89665+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
89666+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89667+ if (!vma_m) {
89668+ error = -ENOMEM;
89669+ goto free_vma;
89670+ }
89671+ }
89672+#endif
89673+
89674 vma->vm_mm = mm;
89675 vma->vm_start = addr;
89676 vma->vm_end = addr + len;
89677@@ -1556,6 +1704,13 @@ munmap_back:
89678 if (error)
89679 goto unmap_and_free_vma;
89680
89681+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
89682+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
89683+ vma->vm_flags |= VM_PAGEEXEC;
89684+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89685+ }
89686+#endif
89687+
89688 /* Can addr have changed??
89689 *
89690 * Answer: Yes, several device drivers can do it in their
89691@@ -1589,6 +1744,12 @@ munmap_back:
89692 }
89693
89694 vma_link(mm, vma, prev, rb_link, rb_parent);
89695+
89696+#ifdef CONFIG_PAX_SEGMEXEC
89697+ if (vma_m)
89698+ BUG_ON(pax_mirror_vma(vma_m, vma));
89699+#endif
89700+
89701 /* Once vma denies write, undo our temporary denial count */
89702 if (vm_flags & VM_DENYWRITE)
89703 allow_write_access(file);
89704@@ -1597,6 +1758,7 @@ out:
89705 perf_event_mmap(vma);
89706
89707 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
89708+ track_exec_limit(mm, addr, addr + len, vm_flags);
89709 if (vm_flags & VM_LOCKED) {
89710 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
89711 vma == get_gate_vma(current->mm)))
89712@@ -1629,6 +1791,12 @@ unmap_and_free_vma:
89713 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
89714 charged = 0;
89715 free_vma:
89716+
89717+#ifdef CONFIG_PAX_SEGMEXEC
89718+ if (vma_m)
89719+ kmem_cache_free(vm_area_cachep, vma_m);
89720+#endif
89721+
89722 kmem_cache_free(vm_area_cachep, vma);
89723 unacct_error:
89724 if (charged)
89725@@ -1636,7 +1804,63 @@ unacct_error:
89726 return error;
89727 }
89728
89729-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89730+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
89731+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
89732+{
89733+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
89734+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
89735+
89736+ return 0;
89737+}
89738+#endif
89739+
89740+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
89741+{
89742+ if (!vma) {
89743+#ifdef CONFIG_STACK_GROWSUP
89744+ if (addr > sysctl_heap_stack_gap)
89745+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
89746+ else
89747+ vma = find_vma(current->mm, 0);
89748+ if (vma && (vma->vm_flags & VM_GROWSUP))
89749+ return false;
89750+#endif
89751+ return true;
89752+ }
89753+
89754+ if (addr + len > vma->vm_start)
89755+ return false;
89756+
89757+ if (vma->vm_flags & VM_GROWSDOWN)
89758+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
89759+#ifdef CONFIG_STACK_GROWSUP
89760+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
89761+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
89762+#endif
89763+ else if (offset)
89764+ return offset <= vma->vm_start - addr - len;
89765+
89766+ return true;
89767+}
89768+
89769+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
89770+{
89771+ if (vma->vm_start < len)
89772+ return -ENOMEM;
89773+
89774+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
89775+ if (offset <= vma->vm_start - len)
89776+ return vma->vm_start - len - offset;
89777+ else
89778+ return -ENOMEM;
89779+ }
89780+
89781+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
89782+ return vma->vm_start - len - sysctl_heap_stack_gap;
89783+ return -ENOMEM;
89784+}
89785+
89786+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
89787 {
89788 /*
89789 * We implement the search by looking for an rbtree node that
89790@@ -1684,11 +1908,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89791 }
89792 }
89793
89794- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
89795+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
89796 check_current:
89797 /* Check if current node has a suitable gap */
89798 if (gap_start > high_limit)
89799 return -ENOMEM;
89800+
89801+ if (gap_end - gap_start > info->threadstack_offset)
89802+ gap_start += info->threadstack_offset;
89803+ else
89804+ gap_start = gap_end;
89805+
89806+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89807+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89808+ gap_start += sysctl_heap_stack_gap;
89809+ else
89810+ gap_start = gap_end;
89811+ }
89812+ if (vma->vm_flags & VM_GROWSDOWN) {
89813+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89814+ gap_end -= sysctl_heap_stack_gap;
89815+ else
89816+ gap_end = gap_start;
89817+ }
89818 if (gap_end >= low_limit && gap_end - gap_start >= length)
89819 goto found;
89820
89821@@ -1738,7 +1980,7 @@ found:
89822 return gap_start;
89823 }
89824
89825-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
89826+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
89827 {
89828 struct mm_struct *mm = current->mm;
89829 struct vm_area_struct *vma;
89830@@ -1792,6 +2034,24 @@ check_current:
89831 gap_end = vma->vm_start;
89832 if (gap_end < low_limit)
89833 return -ENOMEM;
89834+
89835+ if (gap_end - gap_start > info->threadstack_offset)
89836+ gap_end -= info->threadstack_offset;
89837+ else
89838+ gap_end = gap_start;
89839+
89840+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89841+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89842+ gap_start += sysctl_heap_stack_gap;
89843+ else
89844+ gap_start = gap_end;
89845+ }
89846+ if (vma->vm_flags & VM_GROWSDOWN) {
89847+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89848+ gap_end -= sysctl_heap_stack_gap;
89849+ else
89850+ gap_end = gap_start;
89851+ }
89852 if (gap_start <= high_limit && gap_end - gap_start >= length)
89853 goto found;
89854
89855@@ -1855,6 +2115,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89856 struct mm_struct *mm = current->mm;
89857 struct vm_area_struct *vma;
89858 struct vm_unmapped_area_info info;
89859+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89860
89861 if (len > TASK_SIZE - mmap_min_addr)
89862 return -ENOMEM;
89863@@ -1862,19 +2123,30 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89864 if (flags & MAP_FIXED)
89865 return addr;
89866
89867+#ifdef CONFIG_PAX_RANDMMAP
89868+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89869+#endif
89870+
89871 if (addr) {
89872 addr = PAGE_ALIGN(addr);
89873 vma = find_vma(mm, addr);
89874 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
89875- (!vma || addr + len <= vma->vm_start))
89876+ check_heap_stack_gap(vma, addr, len, offset))
89877 return addr;
89878 }
89879
89880 info.flags = 0;
89881 info.length = len;
89882 info.low_limit = TASK_UNMAPPED_BASE;
89883+
89884+#ifdef CONFIG_PAX_RANDMMAP
89885+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89886+ info.low_limit += mm->delta_mmap;
89887+#endif
89888+
89889 info.high_limit = TASK_SIZE;
89890 info.align_mask = 0;
89891+ info.threadstack_offset = offset;
89892 return vm_unmapped_area(&info);
89893 }
89894 #endif
89895@@ -1893,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89896 struct mm_struct *mm = current->mm;
89897 unsigned long addr = addr0;
89898 struct vm_unmapped_area_info info;
89899+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89900
89901 /* requested length too big for entire address space */
89902 if (len > TASK_SIZE - mmap_min_addr)
89903@@ -1901,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89904 if (flags & MAP_FIXED)
89905 return addr;
89906
89907+#ifdef CONFIG_PAX_RANDMMAP
89908+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89909+#endif
89910+
89911 /* requesting a specific address */
89912 if (addr) {
89913 addr = PAGE_ALIGN(addr);
89914 vma = find_vma(mm, addr);
89915 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
89916- (!vma || addr + len <= vma->vm_start))
89917+ check_heap_stack_gap(vma, addr, len, offset))
89918 return addr;
89919 }
89920
89921@@ -1915,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89922 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
89923 info.high_limit = mm->mmap_base;
89924 info.align_mask = 0;
89925+ info.threadstack_offset = offset;
89926 addr = vm_unmapped_area(&info);
89927
89928 /*
89929@@ -1927,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89930 VM_BUG_ON(addr != -ENOMEM);
89931 info.flags = 0;
89932 info.low_limit = TASK_UNMAPPED_BASE;
89933+
89934+#ifdef CONFIG_PAX_RANDMMAP
89935+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89936+ info.low_limit += mm->delta_mmap;
89937+#endif
89938+
89939 info.high_limit = TASK_SIZE;
89940 addr = vm_unmapped_area(&info);
89941 }
89942@@ -2028,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
89943 return vma;
89944 }
89945
89946+#ifdef CONFIG_PAX_SEGMEXEC
89947+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
89948+{
89949+ struct vm_area_struct *vma_m;
89950+
89951+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
89952+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
89953+ BUG_ON(vma->vm_mirror);
89954+ return NULL;
89955+ }
89956+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
89957+ vma_m = vma->vm_mirror;
89958+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
89959+ BUG_ON(vma->vm_file != vma_m->vm_file);
89960+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
89961+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
89962+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
89963+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
89964+ return vma_m;
89965+}
89966+#endif
89967+
89968 /*
89969 * Verify that the stack growth is acceptable and
89970 * update accounting. This is shared with both the
89971@@ -2044,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89972 return -ENOMEM;
89973
89974 /* Stack limit test */
89975+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
89976 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
89977 return -ENOMEM;
89978
89979@@ -2054,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89980 locked = mm->locked_vm + grow;
89981 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
89982 limit >>= PAGE_SHIFT;
89983+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89984 if (locked > limit && !capable(CAP_IPC_LOCK))
89985 return -ENOMEM;
89986 }
89987@@ -2083,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89988 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
89989 * vma is the last one with address > vma->vm_end. Have to extend vma.
89990 */
89991+#ifndef CONFIG_IA64
89992+static
89993+#endif
89994 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89995 {
89996 int error;
89997+ bool locknext;
89998
89999 if (!(vma->vm_flags & VM_GROWSUP))
90000 return -EFAULT;
90001
90002+ /* Also guard against wrapping around to address 0. */
90003+ if (address < PAGE_ALIGN(address+1))
90004+ address = PAGE_ALIGN(address+1);
90005+ else
90006+ return -ENOMEM;
90007+
90008 /*
90009 * We must make sure the anon_vma is allocated
90010 * so that the anon_vma locking is not a noop.
90011 */
90012 if (unlikely(anon_vma_prepare(vma)))
90013 return -ENOMEM;
90014+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
90015+ if (locknext && anon_vma_prepare(vma->vm_next))
90016+ return -ENOMEM;
90017 vma_lock_anon_vma(vma);
90018+ if (locknext)
90019+ vma_lock_anon_vma(vma->vm_next);
90020
90021 /*
90022 * vma->vm_start/vm_end cannot change under us because the caller
90023 * is required to hold the mmap_sem in read mode. We need the
90024- * anon_vma lock to serialize against concurrent expand_stacks.
90025- * Also guard against wrapping around to address 0.
90026+ * anon_vma locks to serialize against concurrent expand_stacks
90027+ * and expand_upwards.
90028 */
90029- if (address < PAGE_ALIGN(address+4))
90030- address = PAGE_ALIGN(address+4);
90031- else {
90032- vma_unlock_anon_vma(vma);
90033- return -ENOMEM;
90034- }
90035 error = 0;
90036
90037 /* Somebody else might have raced and expanded it already */
90038- if (address > vma->vm_end) {
90039+ 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)
90040+ error = -ENOMEM;
90041+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
90042 unsigned long size, grow;
90043
90044 size = address - vma->vm_start;
90045@@ -2148,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
90046 }
90047 }
90048 }
90049+ if (locknext)
90050+ vma_unlock_anon_vma(vma->vm_next);
90051 vma_unlock_anon_vma(vma);
90052 khugepaged_enter_vma_merge(vma);
90053 validate_mm(vma->vm_mm);
90054@@ -2162,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
90055 unsigned long address)
90056 {
90057 int error;
90058+ bool lockprev = false;
90059+ struct vm_area_struct *prev;
90060
90061 /*
90062 * We must make sure the anon_vma is allocated
90063@@ -2175,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
90064 if (error)
90065 return error;
90066
90067+ prev = vma->vm_prev;
90068+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
90069+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
90070+#endif
90071+ if (lockprev && anon_vma_prepare(prev))
90072+ return -ENOMEM;
90073+ if (lockprev)
90074+ vma_lock_anon_vma(prev);
90075+
90076 vma_lock_anon_vma(vma);
90077
90078 /*
90079@@ -2184,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
90080 */
90081
90082 /* Somebody else might have raced and expanded it already */
90083- if (address < vma->vm_start) {
90084+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
90085+ error = -ENOMEM;
90086+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
90087 unsigned long size, grow;
90088
90089+#ifdef CONFIG_PAX_SEGMEXEC
90090+ struct vm_area_struct *vma_m;
90091+
90092+ vma_m = pax_find_mirror_vma(vma);
90093+#endif
90094+
90095 size = vma->vm_end - address;
90096 grow = (vma->vm_start - address) >> PAGE_SHIFT;
90097
90098@@ -2211,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
90099 vma->vm_pgoff -= grow;
90100 anon_vma_interval_tree_post_update_vma(vma);
90101 vma_gap_update(vma);
90102+
90103+#ifdef CONFIG_PAX_SEGMEXEC
90104+ if (vma_m) {
90105+ anon_vma_interval_tree_pre_update_vma(vma_m);
90106+ vma_m->vm_start -= grow << PAGE_SHIFT;
90107+ vma_m->vm_pgoff -= grow;
90108+ anon_vma_interval_tree_post_update_vma(vma_m);
90109+ vma_gap_update(vma_m);
90110+ }
90111+#endif
90112+
90113 spin_unlock(&vma->vm_mm->page_table_lock);
90114
90115+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
90116 perf_event_mmap(vma);
90117 }
90118 }
90119 }
90120 vma_unlock_anon_vma(vma);
90121+ if (lockprev)
90122+ vma_unlock_anon_vma(prev);
90123 khugepaged_enter_vma_merge(vma);
90124 validate_mm(vma->vm_mm);
90125 return error;
90126@@ -2315,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
90127 do {
90128 long nrpages = vma_pages(vma);
90129
90130+#ifdef CONFIG_PAX_SEGMEXEC
90131+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
90132+ vma = remove_vma(vma);
90133+ continue;
90134+ }
90135+#endif
90136+
90137 if (vma->vm_flags & VM_ACCOUNT)
90138 nr_accounted += nrpages;
90139 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
90140@@ -2359,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
90141 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
90142 vma->vm_prev = NULL;
90143 do {
90144+
90145+#ifdef CONFIG_PAX_SEGMEXEC
90146+ if (vma->vm_mirror) {
90147+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
90148+ vma->vm_mirror->vm_mirror = NULL;
90149+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
90150+ vma->vm_mirror = NULL;
90151+ }
90152+#endif
90153+
90154 vma_rb_erase(vma, &mm->mm_rb);
90155 mm->map_count--;
90156 tail_vma = vma;
90157@@ -2384,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90158 struct vm_area_struct *new;
90159 int err = -ENOMEM;
90160
90161+#ifdef CONFIG_PAX_SEGMEXEC
90162+ struct vm_area_struct *vma_m, *new_m = NULL;
90163+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
90164+#endif
90165+
90166 if (is_vm_hugetlb_page(vma) && (addr &
90167 ~(huge_page_mask(hstate_vma(vma)))))
90168 return -EINVAL;
90169
90170+#ifdef CONFIG_PAX_SEGMEXEC
90171+ vma_m = pax_find_mirror_vma(vma);
90172+#endif
90173+
90174 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90175 if (!new)
90176 goto out_err;
90177
90178+#ifdef CONFIG_PAX_SEGMEXEC
90179+ if (vma_m) {
90180+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90181+ if (!new_m) {
90182+ kmem_cache_free(vm_area_cachep, new);
90183+ goto out_err;
90184+ }
90185+ }
90186+#endif
90187+
90188 /* most fields are the same, copy all, and then fixup */
90189 *new = *vma;
90190
90191@@ -2404,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90192 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
90193 }
90194
90195+#ifdef CONFIG_PAX_SEGMEXEC
90196+ if (vma_m) {
90197+ *new_m = *vma_m;
90198+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
90199+ new_m->vm_mirror = new;
90200+ new->vm_mirror = new_m;
90201+
90202+ if (new_below)
90203+ new_m->vm_end = addr_m;
90204+ else {
90205+ new_m->vm_start = addr_m;
90206+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
90207+ }
90208+ }
90209+#endif
90210+
90211 err = vma_dup_policy(vma, new);
90212 if (err)
90213 goto out_free_vma;
90214@@ -2423,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90215 else
90216 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
90217
90218+#ifdef CONFIG_PAX_SEGMEXEC
90219+ if (!err && vma_m) {
90220+ struct mempolicy *pol = vma_policy(new);
90221+
90222+ if (anon_vma_clone(new_m, vma_m))
90223+ goto out_free_mpol;
90224+
90225+ mpol_get(pol);
90226+ set_vma_policy(new_m, pol);
90227+
90228+ if (new_m->vm_file)
90229+ get_file(new_m->vm_file);
90230+
90231+ if (new_m->vm_ops && new_m->vm_ops->open)
90232+ new_m->vm_ops->open(new_m);
90233+
90234+ if (new_below)
90235+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
90236+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
90237+ else
90238+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
90239+
90240+ if (err) {
90241+ if (new_m->vm_ops && new_m->vm_ops->close)
90242+ new_m->vm_ops->close(new_m);
90243+ if (new_m->vm_file)
90244+ fput(new_m->vm_file);
90245+ mpol_put(pol);
90246+ }
90247+ }
90248+#endif
90249+
90250 /* Success. */
90251 if (!err)
90252 return 0;
90253@@ -2432,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90254 new->vm_ops->close(new);
90255 if (new->vm_file)
90256 fput(new->vm_file);
90257- unlink_anon_vmas(new);
90258 out_free_mpol:
90259 mpol_put(vma_policy(new));
90260 out_free_vma:
90261+
90262+#ifdef CONFIG_PAX_SEGMEXEC
90263+ if (new_m) {
90264+ unlink_anon_vmas(new_m);
90265+ kmem_cache_free(vm_area_cachep, new_m);
90266+ }
90267+#endif
90268+
90269+ unlink_anon_vmas(new);
90270 kmem_cache_free(vm_area_cachep, new);
90271 out_err:
90272 return err;
90273@@ -2448,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
90274 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90275 unsigned long addr, int new_below)
90276 {
90277+
90278+#ifdef CONFIG_PAX_SEGMEXEC
90279+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
90280+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
90281+ if (mm->map_count >= sysctl_max_map_count-1)
90282+ return -ENOMEM;
90283+ } else
90284+#endif
90285+
90286 if (mm->map_count >= sysctl_max_map_count)
90287 return -ENOMEM;
90288
90289@@ -2459,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90290 * work. This now handles partial unmappings.
90291 * Jeremy Fitzhardinge <jeremy@goop.org>
90292 */
90293+#ifdef CONFIG_PAX_SEGMEXEC
90294 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90295 {
90296+ int ret = __do_munmap(mm, start, len);
90297+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
90298+ return ret;
90299+
90300+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
90301+}
90302+
90303+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90304+#else
90305+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90306+#endif
90307+{
90308 unsigned long end;
90309 struct vm_area_struct *vma, *prev, *last;
90310
90311+ /*
90312+ * mm->mmap_sem is required to protect against another thread
90313+ * changing the mappings in case we sleep.
90314+ */
90315+ verify_mm_writelocked(mm);
90316+
90317 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
90318 return -EINVAL;
90319
90320@@ -2538,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
90321 /* Fix up all other VM information */
90322 remove_vma_list(mm, vma);
90323
90324+ track_exec_limit(mm, start, end, 0UL);
90325+
90326 return 0;
90327 }
90328
90329@@ -2546,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
90330 int ret;
90331 struct mm_struct *mm = current->mm;
90332
90333+
90334+#ifdef CONFIG_PAX_SEGMEXEC
90335+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
90336+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
90337+ return -EINVAL;
90338+#endif
90339+
90340 down_write(&mm->mmap_sem);
90341 ret = do_munmap(mm, start, len);
90342 up_write(&mm->mmap_sem);
90343@@ -2559,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
90344 return vm_munmap(addr, len);
90345 }
90346
90347-static inline void verify_mm_writelocked(struct mm_struct *mm)
90348-{
90349-#ifdef CONFIG_DEBUG_VM
90350- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
90351- WARN_ON(1);
90352- up_read(&mm->mmap_sem);
90353- }
90354-#endif
90355-}
90356-
90357 /*
90358 * this is really a simplified "do_mmap". it only handles
90359 * anonymous maps. eventually we may be able to do some
90360@@ -2582,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90361 struct rb_node ** rb_link, * rb_parent;
90362 pgoff_t pgoff = addr >> PAGE_SHIFT;
90363 int error;
90364+ unsigned long charged;
90365
90366 len = PAGE_ALIGN(len);
90367 if (!len)
90368@@ -2589,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90369
90370 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
90371
90372+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
90373+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
90374+ flags &= ~VM_EXEC;
90375+
90376+#ifdef CONFIG_PAX_MPROTECT
90377+ if (mm->pax_flags & MF_PAX_MPROTECT)
90378+ flags &= ~VM_MAYEXEC;
90379+#endif
90380+
90381+ }
90382+#endif
90383+
90384 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
90385 if (error & ~PAGE_MASK)
90386 return error;
90387
90388+ charged = len >> PAGE_SHIFT;
90389+
90390 /*
90391 * mlock MCL_FUTURE?
90392 */
90393 if (mm->def_flags & VM_LOCKED) {
90394 unsigned long locked, lock_limit;
90395- locked = len >> PAGE_SHIFT;
90396+ locked = charged;
90397 locked += mm->locked_vm;
90398 lock_limit = rlimit(RLIMIT_MEMLOCK);
90399 lock_limit >>= PAGE_SHIFT;
90400@@ -2615,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90401 /*
90402 * Clear old maps. this also does some error checking for us
90403 */
90404- munmap_back:
90405 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
90406 if (do_munmap(mm, addr, len))
90407 return -ENOMEM;
90408- goto munmap_back;
90409+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
90410 }
90411
90412 /* Check against address space limits *after* clearing old maps... */
90413- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
90414+ if (!may_expand_vm(mm, charged))
90415 return -ENOMEM;
90416
90417 if (mm->map_count > sysctl_max_map_count)
90418 return -ENOMEM;
90419
90420- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
90421+ if (security_vm_enough_memory_mm(mm, charged))
90422 return -ENOMEM;
90423
90424 /* Can we just expand an old private anonymous mapping? */
90425@@ -2643,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90426 */
90427 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90428 if (!vma) {
90429- vm_unacct_memory(len >> PAGE_SHIFT);
90430+ vm_unacct_memory(charged);
90431 return -ENOMEM;
90432 }
90433
90434@@ -2657,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
90435 vma_link(mm, vma, prev, rb_link, rb_parent);
90436 out:
90437 perf_event_mmap(vma);
90438- mm->total_vm += len >> PAGE_SHIFT;
90439+ mm->total_vm += charged;
90440 if (flags & VM_LOCKED)
90441- mm->locked_vm += (len >> PAGE_SHIFT);
90442+ mm->locked_vm += charged;
90443 vma->vm_flags |= VM_SOFTDIRTY;
90444+ track_exec_limit(mm, addr, addr + len, flags);
90445 return addr;
90446 }
90447
90448@@ -2722,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
90449 while (vma) {
90450 if (vma->vm_flags & VM_ACCOUNT)
90451 nr_accounted += vma_pages(vma);
90452+ vma->vm_mirror = NULL;
90453 vma = remove_vma(vma);
90454 }
90455 vm_unacct_memory(nr_accounted);
90456@@ -2738,6 +3227,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
90457 struct vm_area_struct *prev;
90458 struct rb_node **rb_link, *rb_parent;
90459
90460+#ifdef CONFIG_PAX_SEGMEXEC
90461+ struct vm_area_struct *vma_m = NULL;
90462+#endif
90463+
90464+ if (security_mmap_addr(vma->vm_start))
90465+ return -EPERM;
90466+
90467 /*
90468 * The vm_pgoff of a purely anonymous vma should be irrelevant
90469 * until its first write fault, when page's anon_vma and index
90470@@ -2761,7 +3257,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
90471 security_vm_enough_memory_mm(mm, vma_pages(vma)))
90472 return -ENOMEM;
90473
90474+#ifdef CONFIG_PAX_SEGMEXEC
90475+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
90476+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90477+ if (!vma_m)
90478+ return -ENOMEM;
90479+ }
90480+#endif
90481+
90482 vma_link(mm, vma, prev, rb_link, rb_parent);
90483+
90484+#ifdef CONFIG_PAX_SEGMEXEC
90485+ if (vma_m)
90486+ BUG_ON(pax_mirror_vma(vma_m, vma));
90487+#endif
90488+
90489 return 0;
90490 }
90491
90492@@ -2780,6 +3290,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
90493 struct rb_node **rb_link, *rb_parent;
90494 bool faulted_in_anon_vma = true;
90495
90496+ BUG_ON(vma->vm_mirror);
90497+
90498 /*
90499 * If anonymous vma has not yet been faulted, update new pgoff
90500 * to match new location, to increase its chance of merging.
90501@@ -2844,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
90502 return NULL;
90503 }
90504
90505+#ifdef CONFIG_PAX_SEGMEXEC
90506+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
90507+{
90508+ struct vm_area_struct *prev_m;
90509+ struct rb_node **rb_link_m, *rb_parent_m;
90510+ struct mempolicy *pol_m;
90511+
90512+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
90513+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
90514+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
90515+ *vma_m = *vma;
90516+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
90517+ if (anon_vma_clone(vma_m, vma))
90518+ return -ENOMEM;
90519+ pol_m = vma_policy(vma_m);
90520+ mpol_get(pol_m);
90521+ set_vma_policy(vma_m, pol_m);
90522+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
90523+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
90524+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
90525+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
90526+ if (vma_m->vm_file)
90527+ get_file(vma_m->vm_file);
90528+ if (vma_m->vm_ops && vma_m->vm_ops->open)
90529+ vma_m->vm_ops->open(vma_m);
90530+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
90531+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
90532+ vma_m->vm_mirror = vma;
90533+ vma->vm_mirror = vma_m;
90534+ return 0;
90535+}
90536+#endif
90537+
90538 /*
90539 * Return true if the calling process may expand its vm space by the passed
90540 * number of pages
90541@@ -2855,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
90542
90543 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
90544
90545+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
90546 if (cur + npages > lim)
90547 return 0;
90548 return 1;
90549@@ -2925,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
90550 vma->vm_start = addr;
90551 vma->vm_end = addr + len;
90552
90553+#ifdef CONFIG_PAX_MPROTECT
90554+ if (mm->pax_flags & MF_PAX_MPROTECT) {
90555+#ifndef CONFIG_PAX_MPROTECT_COMPAT
90556+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
90557+ return -EPERM;
90558+ if (!(vm_flags & VM_EXEC))
90559+ vm_flags &= ~VM_MAYEXEC;
90560+#else
90561+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
90562+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
90563+#endif
90564+ else
90565+ vm_flags &= ~VM_MAYWRITE;
90566+ }
90567+#endif
90568+
90569 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
90570 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
90571
90572diff --git a/mm/mprotect.c b/mm/mprotect.c
90573index 6c3f56f..b2340b0 100644
90574--- a/mm/mprotect.c
90575+++ b/mm/mprotect.c
90576@@ -23,10 +23,18 @@
90577 #include <linux/mmu_notifier.h>
90578 #include <linux/migrate.h>
90579 #include <linux/perf_event.h>
90580+#include <linux/sched/sysctl.h>
90581+
90582+#ifdef CONFIG_PAX_MPROTECT
90583+#include <linux/elf.h>
90584+#include <linux/binfmts.h>
90585+#endif
90586+
90587 #include <asm/uaccess.h>
90588 #include <asm/pgtable.h>
90589 #include <asm/cacheflush.h>
90590 #include <asm/tlbflush.h>
90591+#include <asm/mmu_context.h>
90592
90593 #ifndef pgprot_modify
90594 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
90595@@ -241,6 +249,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
90596 return pages;
90597 }
90598
90599+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90600+/* called while holding the mmap semaphor for writing except stack expansion */
90601+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
90602+{
90603+ unsigned long oldlimit, newlimit = 0UL;
90604+
90605+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
90606+ return;
90607+
90608+ spin_lock(&mm->page_table_lock);
90609+ oldlimit = mm->context.user_cs_limit;
90610+ if ((prot & VM_EXEC) && oldlimit < end)
90611+ /* USER_CS limit moved up */
90612+ newlimit = end;
90613+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
90614+ /* USER_CS limit moved down */
90615+ newlimit = start;
90616+
90617+ if (newlimit) {
90618+ mm->context.user_cs_limit = newlimit;
90619+
90620+#ifdef CONFIG_SMP
90621+ wmb();
90622+ cpus_clear(mm->context.cpu_user_cs_mask);
90623+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
90624+#endif
90625+
90626+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
90627+ }
90628+ spin_unlock(&mm->page_table_lock);
90629+ if (newlimit == end) {
90630+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
90631+
90632+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
90633+ if (is_vm_hugetlb_page(vma))
90634+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
90635+ else
90636+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
90637+ }
90638+}
90639+#endif
90640+
90641 int
90642 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90643 unsigned long start, unsigned long end, unsigned long newflags)
90644@@ -253,11 +303,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90645 int error;
90646 int dirty_accountable = 0;
90647
90648+#ifdef CONFIG_PAX_SEGMEXEC
90649+ struct vm_area_struct *vma_m = NULL;
90650+ unsigned long start_m, end_m;
90651+
90652+ start_m = start + SEGMEXEC_TASK_SIZE;
90653+ end_m = end + SEGMEXEC_TASK_SIZE;
90654+#endif
90655+
90656 if (newflags == oldflags) {
90657 *pprev = vma;
90658 return 0;
90659 }
90660
90661+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
90662+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
90663+
90664+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
90665+ return -ENOMEM;
90666+
90667+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
90668+ return -ENOMEM;
90669+ }
90670+
90671 /*
90672 * If we make a private mapping writable we increase our commit;
90673 * but (without finer accounting) cannot reduce our commit if we
90674@@ -274,6 +342,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90675 }
90676 }
90677
90678+#ifdef CONFIG_PAX_SEGMEXEC
90679+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
90680+ if (start != vma->vm_start) {
90681+ error = split_vma(mm, vma, start, 1);
90682+ if (error)
90683+ goto fail;
90684+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
90685+ *pprev = (*pprev)->vm_next;
90686+ }
90687+
90688+ if (end != vma->vm_end) {
90689+ error = split_vma(mm, vma, end, 0);
90690+ if (error)
90691+ goto fail;
90692+ }
90693+
90694+ if (pax_find_mirror_vma(vma)) {
90695+ error = __do_munmap(mm, start_m, end_m - start_m);
90696+ if (error)
90697+ goto fail;
90698+ } else {
90699+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90700+ if (!vma_m) {
90701+ error = -ENOMEM;
90702+ goto fail;
90703+ }
90704+ vma->vm_flags = newflags;
90705+ error = pax_mirror_vma(vma_m, vma);
90706+ if (error) {
90707+ vma->vm_flags = oldflags;
90708+ goto fail;
90709+ }
90710+ }
90711+ }
90712+#endif
90713+
90714 /*
90715 * First try to merge with previous and/or next vma.
90716 */
90717@@ -304,9 +408,21 @@ success:
90718 * vm_flags and vm_page_prot are protected by the mmap_sem
90719 * held in write mode.
90720 */
90721+
90722+#ifdef CONFIG_PAX_SEGMEXEC
90723+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
90724+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
90725+#endif
90726+
90727 vma->vm_flags = newflags;
90728+
90729+#ifdef CONFIG_PAX_MPROTECT
90730+ if (mm->binfmt && mm->binfmt->handle_mprotect)
90731+ mm->binfmt->handle_mprotect(vma, newflags);
90732+#endif
90733+
90734 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
90735- vm_get_page_prot(newflags));
90736+ vm_get_page_prot(vma->vm_flags));
90737
90738 if (vma_wants_writenotify(vma)) {
90739 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
90740@@ -345,6 +461,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90741 end = start + len;
90742 if (end <= start)
90743 return -ENOMEM;
90744+
90745+#ifdef CONFIG_PAX_SEGMEXEC
90746+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90747+ if (end > SEGMEXEC_TASK_SIZE)
90748+ return -EINVAL;
90749+ } else
90750+#endif
90751+
90752+ if (end > TASK_SIZE)
90753+ return -EINVAL;
90754+
90755 if (!arch_validate_prot(prot))
90756 return -EINVAL;
90757
90758@@ -352,7 +479,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90759 /*
90760 * Does the application expect PROT_READ to imply PROT_EXEC:
90761 */
90762- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
90763+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
90764 prot |= PROT_EXEC;
90765
90766 vm_flags = calc_vm_prot_bits(prot);
90767@@ -384,6 +511,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90768 if (start > vma->vm_start)
90769 prev = vma;
90770
90771+#ifdef CONFIG_PAX_MPROTECT
90772+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
90773+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
90774+#endif
90775+
90776 for (nstart = start ; ; ) {
90777 unsigned long newflags;
90778
90779@@ -394,6 +526,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90780
90781 /* newflags >> 4 shift VM_MAY% in place of VM_% */
90782 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
90783+ if (prot & (PROT_WRITE | PROT_EXEC))
90784+ gr_log_rwxmprotect(vma);
90785+
90786+ error = -EACCES;
90787+ goto out;
90788+ }
90789+
90790+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
90791 error = -EACCES;
90792 goto out;
90793 }
90794@@ -408,6 +548,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90795 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
90796 if (error)
90797 goto out;
90798+
90799+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
90800+
90801 nstart = tmp;
90802
90803 if (nstart < prev->vm_end)
90804diff --git a/mm/mremap.c b/mm/mremap.c
90805index 0843feb..4f5b2e6 100644
90806--- a/mm/mremap.c
90807+++ b/mm/mremap.c
90808@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
90809 continue;
90810 pte = ptep_get_and_clear(mm, old_addr, old_pte);
90811 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
90812+
90813+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90814+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
90815+ pte = pte_exprotect(pte);
90816+#endif
90817+
90818 pte = move_soft_dirty_pte(pte);
90819 set_pte_at(mm, new_addr, new_pte, pte);
90820 }
90821@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
90822 if (is_vm_hugetlb_page(vma))
90823 goto Einval;
90824
90825+#ifdef CONFIG_PAX_SEGMEXEC
90826+ if (pax_find_mirror_vma(vma))
90827+ goto Einval;
90828+#endif
90829+
90830 /* We can't remap across vm area boundaries */
90831 if (old_len > vma->vm_end - addr)
90832 goto Efault;
90833@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
90834 unsigned long ret = -EINVAL;
90835 unsigned long charged = 0;
90836 unsigned long map_flags;
90837+ unsigned long pax_task_size = TASK_SIZE;
90838
90839 if (new_addr & ~PAGE_MASK)
90840 goto out;
90841
90842- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
90843+#ifdef CONFIG_PAX_SEGMEXEC
90844+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90845+ pax_task_size = SEGMEXEC_TASK_SIZE;
90846+#endif
90847+
90848+ pax_task_size -= PAGE_SIZE;
90849+
90850+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
90851 goto out;
90852
90853 /* Check if the location we're moving into overlaps the
90854 * old location at all, and fail if it does.
90855 */
90856- if ((new_addr <= addr) && (new_addr+new_len) > addr)
90857- goto out;
90858-
90859- if ((addr <= new_addr) && (addr+old_len) > new_addr)
90860+ if (addr + old_len > new_addr && new_addr + new_len > addr)
90861 goto out;
90862
90863 ret = do_munmap(mm, new_addr, new_len);
90864@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90865 unsigned long ret = -EINVAL;
90866 unsigned long charged = 0;
90867 bool locked = false;
90868+ unsigned long pax_task_size = TASK_SIZE;
90869
90870 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
90871 return ret;
90872@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90873 if (!new_len)
90874 return ret;
90875
90876+#ifdef CONFIG_PAX_SEGMEXEC
90877+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90878+ pax_task_size = SEGMEXEC_TASK_SIZE;
90879+#endif
90880+
90881+ pax_task_size -= PAGE_SIZE;
90882+
90883+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
90884+ old_len > pax_task_size || addr > pax_task_size-old_len)
90885+ return ret;
90886+
90887 down_write(&current->mm->mmap_sem);
90888
90889 if (flags & MREMAP_FIXED) {
90890@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90891 new_addr = addr;
90892 }
90893 ret = addr;
90894+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
90895 goto out;
90896 }
90897 }
90898@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90899 goto out;
90900 }
90901
90902+ map_flags = vma->vm_flags;
90903 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
90904+ if (!(ret & ~PAGE_MASK)) {
90905+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
90906+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
90907+ }
90908 }
90909 out:
90910 if (ret & ~PAGE_MASK)
90911diff --git a/mm/nommu.c b/mm/nommu.c
90912index ecd1f15..77039bd 100644
90913--- a/mm/nommu.c
90914+++ b/mm/nommu.c
90915@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
90916 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
90917 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
90918 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
90919-int heap_stack_gap = 0;
90920
90921 atomic_long_t mmap_pages_allocated;
90922
90923@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
90924 EXPORT_SYMBOL(find_vma);
90925
90926 /*
90927- * find a VMA
90928- * - we don't extend stack VMAs under NOMMU conditions
90929- */
90930-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
90931-{
90932- return find_vma(mm, addr);
90933-}
90934-
90935-/*
90936 * expand a stack to a given address
90937 * - not supported under NOMMU conditions
90938 */
90939@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90940
90941 /* most fields are the same, copy all, and then fixup */
90942 *new = *vma;
90943+ INIT_LIST_HEAD(&new->anon_vma_chain);
90944 *region = *vma->vm_region;
90945 new->vm_region = region;
90946
90947@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
90948 }
90949 EXPORT_SYMBOL(generic_file_remap_pages);
90950
90951-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90952- unsigned long addr, void *buf, int len, int write)
90953+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90954+ unsigned long addr, void *buf, size_t len, int write)
90955 {
90956 struct vm_area_struct *vma;
90957
90958@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90959 *
90960 * The caller must hold a reference on @mm.
90961 */
90962-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90963- void *buf, int len, int write)
90964+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
90965+ void *buf, size_t len, int write)
90966 {
90967 return __access_remote_vm(NULL, mm, addr, buf, len, write);
90968 }
90969@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90970 * Access another process' address space.
90971 * - source/target buffer must be kernel space
90972 */
90973-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
90974+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
90975 {
90976 struct mm_struct *mm;
90977
90978diff --git a/mm/page-writeback.c b/mm/page-writeback.c
90979index 6380758..4064aec 100644
90980--- a/mm/page-writeback.c
90981+++ b/mm/page-writeback.c
90982@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
90983 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
90984 * - the bdi dirty thresh drops quickly due to change of JBOD workload
90985 */
90986-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
90987+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
90988 unsigned long thresh,
90989 unsigned long bg_thresh,
90990 unsigned long dirty,
90991diff --git a/mm/page_alloc.c b/mm/page_alloc.c
90992index dd886fa..7686339 100644
90993--- a/mm/page_alloc.c
90994+++ b/mm/page_alloc.c
90995@@ -61,6 +61,7 @@
90996 #include <linux/page-debug-flags.h>
90997 #include <linux/hugetlb.h>
90998 #include <linux/sched/rt.h>
90999+#include <linux/random.h>
91000
91001 #include <asm/sections.h>
91002 #include <asm/tlbflush.h>
91003@@ -354,7 +355,7 @@ out:
91004 * This usage means that zero-order pages may not be compound.
91005 */
91006
91007-static void free_compound_page(struct page *page)
91008+void free_compound_page(struct page *page)
91009 {
91010 __free_pages_ok(page, compound_order(page));
91011 }
91012@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
91013 int i;
91014 int bad = 0;
91015
91016+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91017+ unsigned long index = 1UL << order;
91018+#endif
91019+
91020 trace_mm_page_free(page, order);
91021 kmemcheck_free_shadow(page, order);
91022
91023@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
91024 debug_check_no_obj_freed(page_address(page),
91025 PAGE_SIZE << order);
91026 }
91027+
91028+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91029+ for (; index; --index)
91030+ sanitize_highpage(page + index - 1);
91031+#endif
91032+
91033 arch_free_page(page, order);
91034 kernel_map_pages(page, 1 << order, 0);
91035
91036@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
91037 local_irq_restore(flags);
91038 }
91039
91040+#ifdef CONFIG_PAX_LATENT_ENTROPY
91041+bool __meminitdata extra_latent_entropy;
91042+
91043+static int __init setup_pax_extra_latent_entropy(char *str)
91044+{
91045+ extra_latent_entropy = true;
91046+ return 0;
91047+}
91048+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
91049+
91050+volatile u64 latent_entropy __latent_entropy;
91051+EXPORT_SYMBOL(latent_entropy);
91052+#endif
91053+
91054 void __init __free_pages_bootmem(struct page *page, unsigned int order)
91055 {
91056 unsigned int nr_pages = 1 << order;
91057@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
91058 __ClearPageReserved(p);
91059 set_page_count(p, 0);
91060
91061+#ifdef CONFIG_PAX_LATENT_ENTROPY
91062+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
91063+ u64 hash = 0;
91064+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
91065+ const u64 *data = lowmem_page_address(page);
91066+
91067+ for (index = 0; index < end; index++)
91068+ hash ^= hash + data[index];
91069+ latent_entropy ^= hash;
91070+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
91071+ }
91072+#endif
91073+
91074 page_zone(page)->managed_pages += nr_pages;
91075 set_page_refcounted(page);
91076 __free_pages(page, order);
91077@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
91078 arch_alloc_page(page, order);
91079 kernel_map_pages(page, 1 << order, 1);
91080
91081+#ifndef CONFIG_PAX_MEMORY_SANITIZE
91082 if (gfp_flags & __GFP_ZERO)
91083 prep_zero_page(page, order, gfp_flags);
91084+#endif
91085
91086 if (order && (gfp_flags & __GFP_COMP))
91087 prep_compound_page(page, order);
91088diff --git a/mm/page_io.c b/mm/page_io.c
91089index 8c79a47..a689e0d 100644
91090--- a/mm/page_io.c
91091+++ b/mm/page_io.c
91092@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
91093 struct file *swap_file = sis->swap_file;
91094 struct address_space *mapping = swap_file->f_mapping;
91095 struct iovec iov = {
91096- .iov_base = kmap(page),
91097+ .iov_base = (void __force_user *)kmap(page),
91098 .iov_len = PAGE_SIZE,
91099 };
91100
91101diff --git a/mm/percpu.c b/mm/percpu.c
91102index 8c8e08f..73a5cda 100644
91103--- a/mm/percpu.c
91104+++ b/mm/percpu.c
91105@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
91106 static unsigned int pcpu_high_unit_cpu __read_mostly;
91107
91108 /* the address of the first chunk which starts with the kernel static area */
91109-void *pcpu_base_addr __read_mostly;
91110+void *pcpu_base_addr __read_only;
91111 EXPORT_SYMBOL_GPL(pcpu_base_addr);
91112
91113 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
91114diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
91115index fd26d04..0cea1b0 100644
91116--- a/mm/process_vm_access.c
91117+++ b/mm/process_vm_access.c
91118@@ -13,6 +13,7 @@
91119 #include <linux/uio.h>
91120 #include <linux/sched.h>
91121 #include <linux/highmem.h>
91122+#include <linux/security.h>
91123 #include <linux/ptrace.h>
91124 #include <linux/slab.h>
91125 #include <linux/syscalls.h>
91126@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
91127 size_t iov_l_curr_offset = 0;
91128 ssize_t iov_len;
91129
91130+ return -ENOSYS; // PaX: until properly audited
91131+
91132 /*
91133 * Work out how many pages of struct pages we're going to need
91134 * when eventually calling get_user_pages
91135 */
91136 for (i = 0; i < riovcnt; i++) {
91137 iov_len = rvec[i].iov_len;
91138- if (iov_len > 0) {
91139- nr_pages_iov = ((unsigned long)rvec[i].iov_base
91140- + iov_len)
91141- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
91142- / PAGE_SIZE + 1;
91143- nr_pages = max(nr_pages, nr_pages_iov);
91144- }
91145+ if (iov_len <= 0)
91146+ continue;
91147+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
91148+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
91149+ nr_pages = max(nr_pages, nr_pages_iov);
91150 }
91151
91152 if (nr_pages == 0)
91153@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
91154 goto free_proc_pages;
91155 }
91156
91157+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
91158+ rc = -EPERM;
91159+ goto put_task_struct;
91160+ }
91161+
91162 mm = mm_access(task, PTRACE_MODE_ATTACH);
91163 if (!mm || IS_ERR(mm)) {
91164 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
91165diff --git a/mm/rmap.c b/mm/rmap.c
91166index fd3ee7a..3613079 100644
91167--- a/mm/rmap.c
91168+++ b/mm/rmap.c
91169@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91170 struct anon_vma *anon_vma = vma->anon_vma;
91171 struct anon_vma_chain *avc;
91172
91173+#ifdef CONFIG_PAX_SEGMEXEC
91174+ struct anon_vma_chain *avc_m = NULL;
91175+#endif
91176+
91177 might_sleep();
91178 if (unlikely(!anon_vma)) {
91179 struct mm_struct *mm = vma->vm_mm;
91180@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91181 if (!avc)
91182 goto out_enomem;
91183
91184+#ifdef CONFIG_PAX_SEGMEXEC
91185+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
91186+ if (!avc_m)
91187+ goto out_enomem_free_avc;
91188+#endif
91189+
91190 anon_vma = find_mergeable_anon_vma(vma);
91191 allocated = NULL;
91192 if (!anon_vma) {
91193@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91194 /* page_table_lock to protect against threads */
91195 spin_lock(&mm->page_table_lock);
91196 if (likely(!vma->anon_vma)) {
91197+
91198+#ifdef CONFIG_PAX_SEGMEXEC
91199+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
91200+
91201+ if (vma_m) {
91202+ BUG_ON(vma_m->anon_vma);
91203+ vma_m->anon_vma = anon_vma;
91204+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
91205+ avc_m = NULL;
91206+ }
91207+#endif
91208+
91209 vma->anon_vma = anon_vma;
91210 anon_vma_chain_link(vma, avc, anon_vma);
91211 allocated = NULL;
91212@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
91213
91214 if (unlikely(allocated))
91215 put_anon_vma(allocated);
91216+
91217+#ifdef CONFIG_PAX_SEGMEXEC
91218+ if (unlikely(avc_m))
91219+ anon_vma_chain_free(avc_m);
91220+#endif
91221+
91222 if (unlikely(avc))
91223 anon_vma_chain_free(avc);
91224 }
91225 return 0;
91226
91227 out_enomem_free_avc:
91228+
91229+#ifdef CONFIG_PAX_SEGMEXEC
91230+ if (avc_m)
91231+ anon_vma_chain_free(avc_m);
91232+#endif
91233+
91234 anon_vma_chain_free(avc);
91235 out_enomem:
91236 return -ENOMEM;
91237@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
91238 * Attach the anon_vmas from src to dst.
91239 * Returns 0 on success, -ENOMEM on failure.
91240 */
91241-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
91242+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
91243 {
91244 struct anon_vma_chain *avc, *pavc;
91245 struct anon_vma *root = NULL;
91246@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
91247 * the corresponding VMA in the parent process is attached to.
91248 * Returns 0 on success, non-zero on failure.
91249 */
91250-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
91251+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
91252 {
91253 struct anon_vma_chain *avc;
91254 struct anon_vma *anon_vma;
91255@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
91256 void __init anon_vma_init(void)
91257 {
91258 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
91259- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
91260- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
91261+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
91262+ anon_vma_ctor);
91263+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
91264+ SLAB_PANIC|SLAB_NO_SANITIZE);
91265 }
91266
91267 /*
91268diff --git a/mm/shmem.c b/mm/shmem.c
91269index 8297623..6b9dfe9 100644
91270--- a/mm/shmem.c
91271+++ b/mm/shmem.c
91272@@ -33,7 +33,7 @@
91273 #include <linux/swap.h>
91274 #include <linux/aio.h>
91275
91276-static struct vfsmount *shm_mnt;
91277+struct vfsmount *shm_mnt;
91278
91279 #ifdef CONFIG_SHMEM
91280 /*
91281@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
91282 #define BOGO_DIRENT_SIZE 20
91283
91284 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
91285-#define SHORT_SYMLINK_LEN 128
91286+#define SHORT_SYMLINK_LEN 64
91287
91288 /*
91289 * shmem_fallocate and shmem_writepage communicate via inode->i_private
91290@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
91291 static int shmem_xattr_validate(const char *name)
91292 {
91293 struct { const char *prefix; size_t len; } arr[] = {
91294+
91295+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
91296+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
91297+#endif
91298+
91299 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
91300 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
91301 };
91302@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
91303 if (err)
91304 return err;
91305
91306+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
91307+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
91308+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
91309+ return -EOPNOTSUPP;
91310+ if (size > 8)
91311+ return -EINVAL;
91312+ }
91313+#endif
91314+
91315 return simple_xattr_set(&info->xattrs, name, value, size, flags);
91316 }
91317
91318@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
91319 int err = -ENOMEM;
91320
91321 /* Round up to L1_CACHE_BYTES to resist false sharing */
91322- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
91323- L1_CACHE_BYTES), GFP_KERNEL);
91324+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
91325 if (!sbinfo)
91326 return -ENOMEM;
91327
91328diff --git a/mm/slab.c b/mm/slab.c
91329index 2580db0..0523956 100644
91330--- a/mm/slab.c
91331+++ b/mm/slab.c
91332@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
91333 if ((x)->max_freeable < i) \
91334 (x)->max_freeable = i; \
91335 } while (0)
91336-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
91337-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
91338-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
91339-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
91340+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
91341+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
91342+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
91343+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
91344+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
91345+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
91346 #else
91347 #define STATS_INC_ACTIVE(x) do { } while (0)
91348 #define STATS_DEC_ACTIVE(x) do { } while (0)
91349@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
91350 #define STATS_INC_ALLOCMISS(x) do { } while (0)
91351 #define STATS_INC_FREEHIT(x) do { } while (0)
91352 #define STATS_INC_FREEMISS(x) do { } while (0)
91353+#define STATS_INC_SANITIZED(x) do { } while (0)
91354+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
91355 #endif
91356
91357 #if DEBUG
91358@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
91359 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
91360 */
91361 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
91362- const struct slab *slab, void *obj)
91363+ const struct slab *slab, const void *obj)
91364 {
91365 u32 offset = (obj - slab->s_mem);
91366 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
91367@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
91368 */
91369
91370 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
91371- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
91372+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
91373
91374 if (INDEX_AC != INDEX_NODE)
91375 kmalloc_caches[INDEX_NODE] =
91376 create_kmalloc_cache("kmalloc-node",
91377- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
91378+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
91379
91380 slab_early_init = 0;
91381
91382@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
91383 struct array_cache *ac = cpu_cache_get(cachep);
91384
91385 check_irq_off();
91386+
91387+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91388+ if (pax_sanitize_slab) {
91389+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
91390+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
91391+
91392+ if (cachep->ctor)
91393+ cachep->ctor(objp);
91394+
91395+ STATS_INC_SANITIZED(cachep);
91396+ } else
91397+ STATS_INC_NOT_SANITIZED(cachep);
91398+ }
91399+#endif
91400+
91401 kmemleak_free_recursive(objp, cachep->flags);
91402 objp = cache_free_debugcheck(cachep, objp, caller);
91403
91404@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
91405
91406 if (unlikely(ZERO_OR_NULL_PTR(objp)))
91407 return;
91408+ VM_BUG_ON(!virt_addr_valid(objp));
91409 local_irq_save(flags);
91410 kfree_debugcheck(objp);
91411 c = virt_to_cache(objp);
91412@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
91413 }
91414 /* cpu stats */
91415 {
91416- unsigned long allochit = atomic_read(&cachep->allochit);
91417- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
91418- unsigned long freehit = atomic_read(&cachep->freehit);
91419- unsigned long freemiss = atomic_read(&cachep->freemiss);
91420+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
91421+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
91422+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
91423+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
91424
91425 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
91426 allochit, allocmiss, freehit, freemiss);
91427 }
91428+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91429+ {
91430+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
91431+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
91432+
91433+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
91434+ }
91435+#endif
91436 #endif
91437 }
91438
91439@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
91440 static int __init slab_proc_init(void)
91441 {
91442 #ifdef CONFIG_DEBUG_SLAB_LEAK
91443- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
91444+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
91445 #endif
91446 return 0;
91447 }
91448 module_init(slab_proc_init);
91449 #endif
91450
91451+bool is_usercopy_object(const void *ptr)
91452+{
91453+ struct page *page;
91454+ struct kmem_cache *cachep;
91455+
91456+ if (ZERO_OR_NULL_PTR(ptr))
91457+ return false;
91458+
91459+ if (!slab_is_available())
91460+ return false;
91461+
91462+ if (!virt_addr_valid(ptr))
91463+ return false;
91464+
91465+ page = virt_to_head_page(ptr);
91466+
91467+ if (!PageSlab(page))
91468+ return false;
91469+
91470+ cachep = page->slab_cache;
91471+ return cachep->flags & SLAB_USERCOPY;
91472+}
91473+
91474+#ifdef CONFIG_PAX_USERCOPY
91475+const char *check_heap_object(const void *ptr, unsigned long n)
91476+{
91477+ struct page *page;
91478+ struct kmem_cache *cachep;
91479+ struct slab *slabp;
91480+ unsigned int objnr;
91481+ unsigned long offset;
91482+
91483+ if (ZERO_OR_NULL_PTR(ptr))
91484+ return "<null>";
91485+
91486+ if (!virt_addr_valid(ptr))
91487+ return NULL;
91488+
91489+ page = virt_to_head_page(ptr);
91490+
91491+ if (!PageSlab(page))
91492+ return NULL;
91493+
91494+ cachep = page->slab_cache;
91495+ if (!(cachep->flags & SLAB_USERCOPY))
91496+ return cachep->name;
91497+
91498+ slabp = page->slab_page;
91499+ objnr = obj_to_index(cachep, slabp, ptr);
91500+ BUG_ON(objnr >= cachep->num);
91501+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
91502+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
91503+ return NULL;
91504+
91505+ return cachep->name;
91506+}
91507+#endif
91508+
91509 /**
91510 * ksize - get the actual amount of memory allocated for a given object
91511 * @objp: Pointer to the object
91512diff --git a/mm/slab.h b/mm/slab.h
91513index a535033..2f98fe5 100644
91514--- a/mm/slab.h
91515+++ b/mm/slab.h
91516@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
91517 /* The slab cache that manages slab cache information */
91518 extern struct kmem_cache *kmem_cache;
91519
91520+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91521+#ifdef CONFIG_X86_64
91522+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
91523+#else
91524+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
91525+#endif
91526+extern bool pax_sanitize_slab;
91527+#endif
91528+
91529 unsigned long calculate_alignment(unsigned long flags,
91530 unsigned long align, unsigned long size);
91531
91532@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91533
91534 /* Legal flag mask for kmem_cache_create(), for various configurations */
91535 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
91536- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
91537+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
91538+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
91539
91540 #if defined(CONFIG_DEBUG_SLAB)
91541 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
91542@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
91543 return s;
91544
91545 page = virt_to_head_page(x);
91546+
91547+ BUG_ON(!PageSlab(page));
91548+
91549 cachep = page->slab_cache;
91550 if (slab_equal_or_root(cachep, s))
91551 return cachep;
91552diff --git a/mm/slab_common.c b/mm/slab_common.c
91553index e2e98af..3b1a163 100644
91554--- a/mm/slab_common.c
91555+++ b/mm/slab_common.c
91556@@ -23,11 +23,22 @@
91557
91558 #include "slab.h"
91559
91560-enum slab_state slab_state;
91561+enum slab_state slab_state __read_only;
91562 LIST_HEAD(slab_caches);
91563 DEFINE_MUTEX(slab_mutex);
91564 struct kmem_cache *kmem_cache;
91565
91566+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91567+bool pax_sanitize_slab __read_only = true;
91568+static int __init pax_sanitize_slab_setup(char *str)
91569+{
91570+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
91571+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
91572+ return 1;
91573+}
91574+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
91575+#endif
91576+
91577 #ifdef CONFIG_DEBUG_VM
91578 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
91579 size_t size)
91580@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
91581
91582 err = __kmem_cache_create(s, flags);
91583 if (!err) {
91584- s->refcount = 1;
91585+ atomic_set(&s->refcount, 1);
91586 list_add(&s->list, &slab_caches);
91587 memcg_cache_list_add(memcg, s);
91588 } else {
91589@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
91590
91591 get_online_cpus();
91592 mutex_lock(&slab_mutex);
91593- s->refcount--;
91594- if (!s->refcount) {
91595+ if (atomic_dec_and_test(&s->refcount)) {
91596 list_del(&s->list);
91597
91598 if (!__kmem_cache_shutdown(s)) {
91599@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
91600 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
91601 name, size, err);
91602
91603- s->refcount = -1; /* Exempt from merging for now */
91604+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
91605 }
91606
91607 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
91608@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
91609
91610 create_boot_cache(s, name, size, flags);
91611 list_add(&s->list, &slab_caches);
91612- s->refcount = 1;
91613+ atomic_set(&s->refcount, 1);
91614 return s;
91615 }
91616
91617@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
91618 EXPORT_SYMBOL(kmalloc_dma_caches);
91619 #endif
91620
91621+#ifdef CONFIG_PAX_USERCOPY_SLABS
91622+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
91623+EXPORT_SYMBOL(kmalloc_usercopy_caches);
91624+#endif
91625+
91626 /*
91627 * Conversion table for small slabs sizes / 8 to the index in the
91628 * kmalloc array. This is necessary for slabs < 192 since we have non power
91629@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
91630 return kmalloc_dma_caches[index];
91631
91632 #endif
91633+
91634+#ifdef CONFIG_PAX_USERCOPY_SLABS
91635+ if (unlikely((flags & GFP_USERCOPY)))
91636+ return kmalloc_usercopy_caches[index];
91637+
91638+#endif
91639+
91640 return kmalloc_caches[index];
91641 }
91642
91643@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
91644 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
91645 if (!kmalloc_caches[i]) {
91646 kmalloc_caches[i] = create_kmalloc_cache(NULL,
91647- 1 << i, flags);
91648+ 1 << i, SLAB_USERCOPY | flags);
91649 }
91650
91651 /*
91652@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
91653 * earlier power of two caches
91654 */
91655 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
91656- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
91657+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
91658
91659 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
91660- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
91661+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
91662 }
91663
91664 /* Kmalloc array is now usable */
91665@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
91666 }
91667 }
91668 #endif
91669+
91670+#ifdef CONFIG_PAX_USERCOPY_SLABS
91671+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
91672+ struct kmem_cache *s = kmalloc_caches[i];
91673+
91674+ if (s) {
91675+ int size = kmalloc_size(i);
91676+ char *n = kasprintf(GFP_NOWAIT,
91677+ "usercopy-kmalloc-%d", size);
91678+
91679+ BUG_ON(!n);
91680+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
91681+ size, SLAB_USERCOPY | flags);
91682+ }
91683+ }
91684+#endif
91685+
91686 }
91687 #endif /* !CONFIG_SLOB */
91688
91689@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
91690 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
91691 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
91692 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
91693+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91694+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
91695+#endif
91696 #endif
91697 seq_putc(m, '\n');
91698 }
91699diff --git a/mm/slob.c b/mm/slob.c
91700index 4bf8809..98a6914 100644
91701--- a/mm/slob.c
91702+++ b/mm/slob.c
91703@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
91704 /*
91705 * Return the size of a slob block.
91706 */
91707-static slobidx_t slob_units(slob_t *s)
91708+static slobidx_t slob_units(const slob_t *s)
91709 {
91710 if (s->units > 0)
91711 return s->units;
91712@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
91713 /*
91714 * Return the next free slob block pointer after this one.
91715 */
91716-static slob_t *slob_next(slob_t *s)
91717+static slob_t *slob_next(const slob_t *s)
91718 {
91719 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
91720 slobidx_t next;
91721@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
91722 /*
91723 * Returns true if s is the last free block in its page.
91724 */
91725-static int slob_last(slob_t *s)
91726+static int slob_last(const slob_t *s)
91727 {
91728 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
91729 }
91730
91731-static void *slob_new_pages(gfp_t gfp, int order, int node)
91732+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
91733 {
91734- void *page;
91735+ struct page *page;
91736
91737 #ifdef CONFIG_NUMA
91738 if (node != NUMA_NO_NODE)
91739@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
91740 if (!page)
91741 return NULL;
91742
91743- return page_address(page);
91744+ __SetPageSlab(page);
91745+ return page;
91746 }
91747
91748-static void slob_free_pages(void *b, int order)
91749+static void slob_free_pages(struct page *sp, int order)
91750 {
91751 if (current->reclaim_state)
91752 current->reclaim_state->reclaimed_slab += 1 << order;
91753- free_pages((unsigned long)b, order);
91754+ __ClearPageSlab(sp);
91755+ page_mapcount_reset(sp);
91756+ sp->private = 0;
91757+ __free_pages(sp, order);
91758 }
91759
91760 /*
91761@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
91762
91763 /* Not enough space: must allocate a new page */
91764 if (!b) {
91765- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91766- if (!b)
91767+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91768+ if (!sp)
91769 return NULL;
91770- sp = virt_to_page(b);
91771- __SetPageSlab(sp);
91772+ b = page_address(sp);
91773
91774 spin_lock_irqsave(&slob_lock, flags);
91775 sp->units = SLOB_UNITS(PAGE_SIZE);
91776 sp->freelist = b;
91777+ sp->private = 0;
91778 INIT_LIST_HEAD(&sp->list);
91779 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
91780 set_slob_page_free(sp, slob_list);
91781@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
91782 if (slob_page_free(sp))
91783 clear_slob_page_free(sp);
91784 spin_unlock_irqrestore(&slob_lock, flags);
91785- __ClearPageSlab(sp);
91786- page_mapcount_reset(sp);
91787- slob_free_pages(b, 0);
91788+ slob_free_pages(sp, 0);
91789 return;
91790 }
91791
91792+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91793+ if (pax_sanitize_slab)
91794+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
91795+#endif
91796+
91797 if (!slob_page_free(sp)) {
91798 /* This slob page is about to become partially free. Easy! */
91799 sp->units = units;
91800@@ -424,11 +431,10 @@ out:
91801 */
91802
91803 static __always_inline void *
91804-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91805+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
91806 {
91807- unsigned int *m;
91808- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91809- void *ret;
91810+ slob_t *m;
91811+ void *ret = NULL;
91812
91813 gfp &= gfp_allowed_mask;
91814
91815@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91816
91817 if (!m)
91818 return NULL;
91819- *m = size;
91820+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
91821+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
91822+ m[0].units = size;
91823+ m[1].units = align;
91824 ret = (void *)m + align;
91825
91826 trace_kmalloc_node(caller, ret,
91827 size, size + align, gfp, node);
91828 } else {
91829 unsigned int order = get_order(size);
91830+ struct page *page;
91831
91832 if (likely(order))
91833 gfp |= __GFP_COMP;
91834- ret = slob_new_pages(gfp, order, node);
91835+ page = slob_new_pages(gfp, order, node);
91836+ if (page) {
91837+ ret = page_address(page);
91838+ page->private = size;
91839+ }
91840
91841 trace_kmalloc_node(caller, ret,
91842 size, PAGE_SIZE << order, gfp, node);
91843 }
91844
91845- kmemleak_alloc(ret, size, 1, gfp);
91846+ return ret;
91847+}
91848+
91849+static __always_inline void *
91850+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91851+{
91852+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91853+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
91854+
91855+ if (!ZERO_OR_NULL_PTR(ret))
91856+ kmemleak_alloc(ret, size, 1, gfp);
91857 return ret;
91858 }
91859
91860@@ -493,34 +517,112 @@ void kfree(const void *block)
91861 return;
91862 kmemleak_free(block);
91863
91864+ VM_BUG_ON(!virt_addr_valid(block));
91865 sp = virt_to_page(block);
91866- if (PageSlab(sp)) {
91867+ VM_BUG_ON(!PageSlab(sp));
91868+ if (!sp->private) {
91869 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91870- unsigned int *m = (unsigned int *)(block - align);
91871- slob_free(m, *m + align);
91872- } else
91873+ slob_t *m = (slob_t *)(block - align);
91874+ slob_free(m, m[0].units + align);
91875+ } else {
91876+ __ClearPageSlab(sp);
91877+ page_mapcount_reset(sp);
91878+ sp->private = 0;
91879 __free_pages(sp, compound_order(sp));
91880+ }
91881 }
91882 EXPORT_SYMBOL(kfree);
91883
91884+bool is_usercopy_object(const void *ptr)
91885+{
91886+ if (!slab_is_available())
91887+ return false;
91888+
91889+ // PAX: TODO
91890+
91891+ return false;
91892+}
91893+
91894+#ifdef CONFIG_PAX_USERCOPY
91895+const char *check_heap_object(const void *ptr, unsigned long n)
91896+{
91897+ struct page *page;
91898+ const slob_t *free;
91899+ const void *base;
91900+ unsigned long flags;
91901+
91902+ if (ZERO_OR_NULL_PTR(ptr))
91903+ return "<null>";
91904+
91905+ if (!virt_addr_valid(ptr))
91906+ return NULL;
91907+
91908+ page = virt_to_head_page(ptr);
91909+ if (!PageSlab(page))
91910+ return NULL;
91911+
91912+ if (page->private) {
91913+ base = page;
91914+ if (base <= ptr && n <= page->private - (ptr - base))
91915+ return NULL;
91916+ return "<slob>";
91917+ }
91918+
91919+ /* some tricky double walking to find the chunk */
91920+ spin_lock_irqsave(&slob_lock, flags);
91921+ base = (void *)((unsigned long)ptr & PAGE_MASK);
91922+ free = page->freelist;
91923+
91924+ while (!slob_last(free) && (void *)free <= ptr) {
91925+ base = free + slob_units(free);
91926+ free = slob_next(free);
91927+ }
91928+
91929+ while (base < (void *)free) {
91930+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
91931+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
91932+ int offset;
91933+
91934+ if (ptr < base + align)
91935+ break;
91936+
91937+ offset = ptr - base - align;
91938+ if (offset >= m) {
91939+ base += size;
91940+ continue;
91941+ }
91942+
91943+ if (n > m - offset)
91944+ break;
91945+
91946+ spin_unlock_irqrestore(&slob_lock, flags);
91947+ return NULL;
91948+ }
91949+
91950+ spin_unlock_irqrestore(&slob_lock, flags);
91951+ return "<slob>";
91952+}
91953+#endif
91954+
91955 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
91956 size_t ksize(const void *block)
91957 {
91958 struct page *sp;
91959 int align;
91960- unsigned int *m;
91961+ slob_t *m;
91962
91963 BUG_ON(!block);
91964 if (unlikely(block == ZERO_SIZE_PTR))
91965 return 0;
91966
91967 sp = virt_to_page(block);
91968- if (unlikely(!PageSlab(sp)))
91969- return PAGE_SIZE << compound_order(sp);
91970+ VM_BUG_ON(!PageSlab(sp));
91971+ if (sp->private)
91972+ return sp->private;
91973
91974 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91975- m = (unsigned int *)(block - align);
91976- return SLOB_UNITS(*m) * SLOB_UNIT;
91977+ m = (slob_t *)(block - align);
91978+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
91979 }
91980 EXPORT_SYMBOL(ksize);
91981
91982@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
91983
91984 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
91985 {
91986- void *b;
91987+ void *b = NULL;
91988
91989 flags &= gfp_allowed_mask;
91990
91991 lockdep_trace_alloc(flags);
91992
91993+#ifdef CONFIG_PAX_USERCOPY_SLABS
91994+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
91995+#else
91996 if (c->size < PAGE_SIZE) {
91997 b = slob_alloc(c->size, flags, c->align, node);
91998 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91999 SLOB_UNITS(c->size) * SLOB_UNIT,
92000 flags, node);
92001 } else {
92002- b = slob_new_pages(flags, get_order(c->size), node);
92003+ struct page *sp;
92004+
92005+ sp = slob_new_pages(flags, get_order(c->size), node);
92006+ if (sp) {
92007+ b = page_address(sp);
92008+ sp->private = c->size;
92009+ }
92010 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
92011 PAGE_SIZE << get_order(c->size),
92012 flags, node);
92013 }
92014+#endif
92015
92016 if (b && c->ctor)
92017 c->ctor(b);
92018@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
92019
92020 static void __kmem_cache_free(void *b, int size)
92021 {
92022- if (size < PAGE_SIZE)
92023+ struct page *sp;
92024+
92025+ sp = virt_to_page(b);
92026+ BUG_ON(!PageSlab(sp));
92027+ if (!sp->private)
92028 slob_free(b, size);
92029 else
92030- slob_free_pages(b, get_order(size));
92031+ slob_free_pages(sp, get_order(size));
92032 }
92033
92034 static void kmem_rcu_free(struct rcu_head *head)
92035@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
92036
92037 void kmem_cache_free(struct kmem_cache *c, void *b)
92038 {
92039+ int size = c->size;
92040+
92041+#ifdef CONFIG_PAX_USERCOPY_SLABS
92042+ if (size + c->align < PAGE_SIZE) {
92043+ size += c->align;
92044+ b -= c->align;
92045+ }
92046+#endif
92047+
92048 kmemleak_free_recursive(b, c->flags);
92049 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
92050 struct slob_rcu *slob_rcu;
92051- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
92052- slob_rcu->size = c->size;
92053+ slob_rcu = b + (size - sizeof(struct slob_rcu));
92054+ slob_rcu->size = size;
92055 call_rcu(&slob_rcu->head, kmem_rcu_free);
92056 } else {
92057- __kmem_cache_free(b, c->size);
92058+ __kmem_cache_free(b, size);
92059 }
92060
92061+#ifdef CONFIG_PAX_USERCOPY_SLABS
92062+ trace_kfree(_RET_IP_, b);
92063+#else
92064 trace_kmem_cache_free(_RET_IP_, b);
92065+#endif
92066+
92067 }
92068 EXPORT_SYMBOL(kmem_cache_free);
92069
92070diff --git a/mm/slub.c b/mm/slub.c
92071index 96f2169..9111a59 100644
92072--- a/mm/slub.c
92073+++ b/mm/slub.c
92074@@ -207,7 +207,7 @@ struct track {
92075
92076 enum track_item { TRACK_ALLOC, TRACK_FREE };
92077
92078-#ifdef CONFIG_SYSFS
92079+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92080 static int sysfs_slab_add(struct kmem_cache *);
92081 static int sysfs_slab_alias(struct kmem_cache *, const char *);
92082 static void sysfs_slab_remove(struct kmem_cache *);
92083@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
92084 if (!t->addr)
92085 return;
92086
92087- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
92088+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
92089 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
92090 #ifdef CONFIG_STACKTRACE
92091 {
92092@@ -2616,6 +2616,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
92093
92094 slab_free_hook(s, x);
92095
92096+#ifdef CONFIG_PAX_MEMORY_SANITIZE
92097+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
92098+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
92099+ if (s->ctor)
92100+ s->ctor(x);
92101+ }
92102+#endif
92103+
92104 redo:
92105 /*
92106 * Determine the currently cpus per cpu slab.
92107@@ -2683,7 +2691,7 @@ static int slub_min_objects;
92108 * Merge control. If this is set then no merging of slab caches will occur.
92109 * (Could be removed. This was introduced to pacify the merge skeptics.)
92110 */
92111-static int slub_nomerge;
92112+static int slub_nomerge = 1;
92113
92114 /*
92115 * Calculate the order of allocation given an slab object size.
92116@@ -2960,6 +2968,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
92117 s->inuse = size;
92118
92119 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
92120+#ifdef CONFIG_PAX_MEMORY_SANITIZE
92121+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
92122+#endif
92123 s->ctor)) {
92124 /*
92125 * Relocate free pointer after the object if it is not
92126@@ -3305,6 +3316,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
92127 EXPORT_SYMBOL(__kmalloc_node);
92128 #endif
92129
92130+bool is_usercopy_object(const void *ptr)
92131+{
92132+ struct page *page;
92133+ struct kmem_cache *s;
92134+
92135+ if (ZERO_OR_NULL_PTR(ptr))
92136+ return false;
92137+
92138+ if (!slab_is_available())
92139+ return false;
92140+
92141+ if (!virt_addr_valid(ptr))
92142+ return false;
92143+
92144+ page = virt_to_head_page(ptr);
92145+
92146+ if (!PageSlab(page))
92147+ return false;
92148+
92149+ s = page->slab_cache;
92150+ return s->flags & SLAB_USERCOPY;
92151+}
92152+
92153+#ifdef CONFIG_PAX_USERCOPY
92154+const char *check_heap_object(const void *ptr, unsigned long n)
92155+{
92156+ struct page *page;
92157+ struct kmem_cache *s;
92158+ unsigned long offset;
92159+
92160+ if (ZERO_OR_NULL_PTR(ptr))
92161+ return "<null>";
92162+
92163+ if (!virt_addr_valid(ptr))
92164+ return NULL;
92165+
92166+ page = virt_to_head_page(ptr);
92167+
92168+ if (!PageSlab(page))
92169+ return NULL;
92170+
92171+ s = page->slab_cache;
92172+ if (!(s->flags & SLAB_USERCOPY))
92173+ return s->name;
92174+
92175+ offset = (ptr - page_address(page)) % s->size;
92176+ if (offset <= s->object_size && n <= s->object_size - offset)
92177+ return NULL;
92178+
92179+ return s->name;
92180+}
92181+#endif
92182+
92183 size_t ksize(const void *object)
92184 {
92185 struct page *page;
92186@@ -3333,6 +3397,7 @@ void kfree(const void *x)
92187 if (unlikely(ZERO_OR_NULL_PTR(x)))
92188 return;
92189
92190+ VM_BUG_ON(!virt_addr_valid(x));
92191 page = virt_to_head_page(x);
92192 if (unlikely(!PageSlab(page))) {
92193 BUG_ON(!PageCompound(page));
92194@@ -3638,7 +3703,7 @@ static int slab_unmergeable(struct kmem_cache *s)
92195 /*
92196 * We may have set a slab to be unmergeable during bootstrap.
92197 */
92198- if (s->refcount < 0)
92199+ if (atomic_read(&s->refcount) < 0)
92200 return 1;
92201
92202 return 0;
92203@@ -3696,7 +3761,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
92204
92205 s = find_mergeable(memcg, size, align, flags, name, ctor);
92206 if (s) {
92207- s->refcount++;
92208+ atomic_inc(&s->refcount);
92209 /*
92210 * Adjust the object sizes so that we clear
92211 * the complete object on kzalloc.
92212@@ -3705,7 +3770,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
92213 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
92214
92215 if (sysfs_slab_alias(s, name)) {
92216- s->refcount--;
92217+ atomic_dec(&s->refcount);
92218 s = NULL;
92219 }
92220 }
92221@@ -3825,7 +3890,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
92222 }
92223 #endif
92224
92225-#ifdef CONFIG_SYSFS
92226+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92227 static int count_inuse(struct page *page)
92228 {
92229 return page->inuse;
92230@@ -4214,12 +4279,12 @@ static void resiliency_test(void)
92231 validate_slab_cache(kmalloc_caches[9]);
92232 }
92233 #else
92234-#ifdef CONFIG_SYSFS
92235+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92236 static void resiliency_test(void) {};
92237 #endif
92238 #endif
92239
92240-#ifdef CONFIG_SYSFS
92241+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92242 enum slab_stat_type {
92243 SL_ALL, /* All slabs */
92244 SL_PARTIAL, /* Only partially allocated slabs */
92245@@ -4459,7 +4524,7 @@ SLAB_ATTR_RO(ctor);
92246
92247 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
92248 {
92249- return sprintf(buf, "%d\n", s->refcount - 1);
92250+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
92251 }
92252 SLAB_ATTR_RO(aliases);
92253
92254@@ -4547,6 +4612,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
92255 SLAB_ATTR_RO(cache_dma);
92256 #endif
92257
92258+#ifdef CONFIG_PAX_USERCOPY_SLABS
92259+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
92260+{
92261+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
92262+}
92263+SLAB_ATTR_RO(usercopy);
92264+#endif
92265+
92266 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
92267 {
92268 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
92269@@ -4881,6 +4954,9 @@ static struct attribute *slab_attrs[] = {
92270 #ifdef CONFIG_ZONE_DMA
92271 &cache_dma_attr.attr,
92272 #endif
92273+#ifdef CONFIG_PAX_USERCOPY_SLABS
92274+ &usercopy_attr.attr,
92275+#endif
92276 #ifdef CONFIG_NUMA
92277 &remote_node_defrag_ratio_attr.attr,
92278 #endif
92279@@ -5113,6 +5189,7 @@ static char *create_unique_id(struct kmem_cache *s)
92280 return name;
92281 }
92282
92283+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92284 static int sysfs_slab_add(struct kmem_cache *s)
92285 {
92286 int err;
92287@@ -5136,7 +5213,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
92288 }
92289
92290 s->kobj.kset = slab_kset;
92291- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
92292+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
92293 if (err) {
92294 kobject_put(&s->kobj);
92295 return err;
92296@@ -5170,6 +5247,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
92297 kobject_del(&s->kobj);
92298 kobject_put(&s->kobj);
92299 }
92300+#endif
92301
92302 /*
92303 * Need to buffer aliases during bootup until sysfs becomes
92304@@ -5183,6 +5261,7 @@ struct saved_alias {
92305
92306 static struct saved_alias *alias_list;
92307
92308+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
92309 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
92310 {
92311 struct saved_alias *al;
92312@@ -5205,6 +5284,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
92313 alias_list = al;
92314 return 0;
92315 }
92316+#endif
92317
92318 static int __init slab_sysfs_init(void)
92319 {
92320diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
92321index 27eeab3..7c3f7f2 100644
92322--- a/mm/sparse-vmemmap.c
92323+++ b/mm/sparse-vmemmap.c
92324@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
92325 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
92326 if (!p)
92327 return NULL;
92328- pud_populate(&init_mm, pud, p);
92329+ pud_populate_kernel(&init_mm, pud, p);
92330 }
92331 return pud;
92332 }
92333@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
92334 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
92335 if (!p)
92336 return NULL;
92337- pgd_populate(&init_mm, pgd, p);
92338+ pgd_populate_kernel(&init_mm, pgd, p);
92339 }
92340 return pgd;
92341 }
92342diff --git a/mm/sparse.c b/mm/sparse.c
92343index 4ac1d7e..bbfcb1f 100644
92344--- a/mm/sparse.c
92345+++ b/mm/sparse.c
92346@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
92347
92348 for (i = 0; i < PAGES_PER_SECTION; i++) {
92349 if (PageHWPoison(&memmap[i])) {
92350- atomic_long_sub(1, &num_poisoned_pages);
92351+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
92352 ClearPageHWPoison(&memmap[i]);
92353 }
92354 }
92355diff --git a/mm/swap.c b/mm/swap.c
92356index 759c3ca..7c1a5b4 100644
92357--- a/mm/swap.c
92358+++ b/mm/swap.c
92359@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
92360
92361 __page_cache_release(page);
92362 dtor = get_compound_page_dtor(page);
92363+ if (!PageHuge(page))
92364+ BUG_ON(dtor != free_compound_page);
92365 (*dtor)(page);
92366 }
92367
92368diff --git a/mm/swapfile.c b/mm/swapfile.c
92369index de7c904..c84bf11 100644
92370--- a/mm/swapfile.c
92371+++ b/mm/swapfile.c
92372@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
92373
92374 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
92375 /* Activity counter to indicate that a swapon or swapoff has occurred */
92376-static atomic_t proc_poll_event = ATOMIC_INIT(0);
92377+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
92378
92379 static inline unsigned char swap_count(unsigned char ent)
92380 {
92381@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
92382 }
92383 filp_close(swap_file, NULL);
92384 err = 0;
92385- atomic_inc(&proc_poll_event);
92386+ atomic_inc_unchecked(&proc_poll_event);
92387 wake_up_interruptible(&proc_poll_wait);
92388
92389 out_dput:
92390@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
92391
92392 poll_wait(file, &proc_poll_wait, wait);
92393
92394- if (seq->poll_event != atomic_read(&proc_poll_event)) {
92395- seq->poll_event = atomic_read(&proc_poll_event);
92396+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
92397+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
92398 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
92399 }
92400
92401@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
92402 return ret;
92403
92404 seq = file->private_data;
92405- seq->poll_event = atomic_read(&proc_poll_event);
92406+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
92407 return 0;
92408 }
92409
92410@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
92411 (frontswap_map) ? "FS" : "");
92412
92413 mutex_unlock(&swapon_mutex);
92414- atomic_inc(&proc_poll_event);
92415+ atomic_inc_unchecked(&proc_poll_event);
92416 wake_up_interruptible(&proc_poll_wait);
92417
92418 if (S_ISREG(inode->i_mode))
92419diff --git a/mm/util.c b/mm/util.c
92420index eaf63fc2..32b2629 100644
92421--- a/mm/util.c
92422+++ b/mm/util.c
92423@@ -294,6 +294,12 @@ done:
92424 void arch_pick_mmap_layout(struct mm_struct *mm)
92425 {
92426 mm->mmap_base = TASK_UNMAPPED_BASE;
92427+
92428+#ifdef CONFIG_PAX_RANDMMAP
92429+ if (mm->pax_flags & MF_PAX_RANDMMAP)
92430+ mm->mmap_base += mm->delta_mmap;
92431+#endif
92432+
92433 mm->get_unmapped_area = arch_get_unmapped_area;
92434 }
92435 #endif
92436diff --git a/mm/vmalloc.c b/mm/vmalloc.c
92437index 1074543..136dbe0 100644
92438--- a/mm/vmalloc.c
92439+++ b/mm/vmalloc.c
92440@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
92441
92442 pte = pte_offset_kernel(pmd, addr);
92443 do {
92444- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
92445- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
92446+
92447+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92448+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
92449+ BUG_ON(!pte_exec(*pte));
92450+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
92451+ continue;
92452+ }
92453+#endif
92454+
92455+ {
92456+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
92457+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
92458+ }
92459 } while (pte++, addr += PAGE_SIZE, addr != end);
92460 }
92461
92462@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
92463 pte = pte_alloc_kernel(pmd, addr);
92464 if (!pte)
92465 return -ENOMEM;
92466+
92467+ pax_open_kernel();
92468 do {
92469 struct page *page = pages[*nr];
92470
92471- if (WARN_ON(!pte_none(*pte)))
92472+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92473+ if (pgprot_val(prot) & _PAGE_NX)
92474+#endif
92475+
92476+ if (!pte_none(*pte)) {
92477+ pax_close_kernel();
92478+ WARN_ON(1);
92479 return -EBUSY;
92480- if (WARN_ON(!page))
92481+ }
92482+ if (!page) {
92483+ pax_close_kernel();
92484+ WARN_ON(1);
92485 return -ENOMEM;
92486+ }
92487 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
92488 (*nr)++;
92489 } while (pte++, addr += PAGE_SIZE, addr != end);
92490+ pax_close_kernel();
92491 return 0;
92492 }
92493
92494@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
92495 pmd_t *pmd;
92496 unsigned long next;
92497
92498- pmd = pmd_alloc(&init_mm, pud, addr);
92499+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92500 if (!pmd)
92501 return -ENOMEM;
92502 do {
92503@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
92504 pud_t *pud;
92505 unsigned long next;
92506
92507- pud = pud_alloc(&init_mm, pgd, addr);
92508+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
92509 if (!pud)
92510 return -ENOMEM;
92511 do {
92512@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
92513 if (addr >= MODULES_VADDR && addr < MODULES_END)
92514 return 1;
92515 #endif
92516+
92517+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
92518+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
92519+ return 1;
92520+#endif
92521+
92522 return is_vmalloc_addr(x);
92523 }
92524
92525@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
92526
92527 if (!pgd_none(*pgd)) {
92528 pud_t *pud = pud_offset(pgd, addr);
92529+#ifdef CONFIG_X86
92530+ if (!pud_large(*pud))
92531+#endif
92532 if (!pud_none(*pud)) {
92533 pmd_t *pmd = pmd_offset(pud, addr);
92534+#ifdef CONFIG_X86
92535+ if (!pmd_large(*pmd))
92536+#endif
92537 if (!pmd_none(*pmd)) {
92538 pte_t *ptep, pte;
92539
92540@@ -1303,6 +1339,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
92541 struct vm_struct *area;
92542
92543 BUG_ON(in_interrupt());
92544+
92545+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92546+ if (flags & VM_KERNEXEC) {
92547+ if (start != VMALLOC_START || end != VMALLOC_END)
92548+ return NULL;
92549+ start = (unsigned long)MODULES_EXEC_VADDR;
92550+ end = (unsigned long)MODULES_EXEC_END;
92551+ }
92552+#endif
92553+
92554 if (flags & VM_IOREMAP)
92555 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
92556
92557@@ -1528,6 +1574,11 @@ void *vmap(struct page **pages, unsigned int count,
92558 if (count > totalram_pages)
92559 return NULL;
92560
92561+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92562+ if (!(pgprot_val(prot) & _PAGE_NX))
92563+ flags |= VM_KERNEXEC;
92564+#endif
92565+
92566 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
92567 __builtin_return_address(0));
92568 if (!area)
92569@@ -1629,6 +1680,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
92570 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
92571 goto fail;
92572
92573+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
92574+ if (!(pgprot_val(prot) & _PAGE_NX))
92575+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
92576+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
92577+ else
92578+#endif
92579+
92580 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
92581 start, end, node, gfp_mask, caller);
92582 if (!area)
92583@@ -1805,10 +1863,9 @@ EXPORT_SYMBOL(vzalloc_node);
92584 * For tight control over page level allocator and protection flags
92585 * use __vmalloc() instead.
92586 */
92587-
92588 void *vmalloc_exec(unsigned long size)
92589 {
92590- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
92591+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
92592 NUMA_NO_NODE, __builtin_return_address(0));
92593 }
92594
92595@@ -2115,6 +2172,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
92596 {
92597 struct vm_struct *area;
92598
92599+ BUG_ON(vma->vm_mirror);
92600+
92601 size = PAGE_ALIGN(size);
92602
92603 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
92604@@ -2600,7 +2659,11 @@ static int s_show(struct seq_file *m, void *p)
92605 v->addr, v->addr + v->size, v->size);
92606
92607 if (v->caller)
92608+#ifdef CONFIG_GRKERNSEC_HIDESYM
92609+ seq_printf(m, " %pK", v->caller);
92610+#else
92611 seq_printf(m, " %pS", v->caller);
92612+#endif
92613
92614 if (v->nr_pages)
92615 seq_printf(m, " pages=%d", v->nr_pages);
92616diff --git a/mm/vmstat.c b/mm/vmstat.c
92617index 5a442a7..5eb281e 100644
92618--- a/mm/vmstat.c
92619+++ b/mm/vmstat.c
92620@@ -79,7 +79,7 @@ void vm_events_fold_cpu(int cpu)
92621 *
92622 * vm_stat contains the global counters
92623 */
92624-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92625+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92626 EXPORT_SYMBOL(vm_stat);
92627
92628 #ifdef CONFIG_SMP
92629@@ -423,7 +423,7 @@ static inline void fold_diff(int *diff)
92630
92631 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
92632 if (diff[i])
92633- atomic_long_add(diff[i], &vm_stat[i]);
92634+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
92635 }
92636
92637 /*
92638@@ -455,7 +455,7 @@ static void refresh_cpu_vm_stats(void)
92639 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
92640 if (v) {
92641
92642- atomic_long_add(v, &zone->vm_stat[i]);
92643+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92644 global_diff[i] += v;
92645 #ifdef CONFIG_NUMA
92646 /* 3 seconds idle till flush */
92647@@ -517,7 +517,7 @@ void cpu_vm_stats_fold(int cpu)
92648
92649 v = p->vm_stat_diff[i];
92650 p->vm_stat_diff[i] = 0;
92651- atomic_long_add(v, &zone->vm_stat[i]);
92652+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92653 global_diff[i] += v;
92654 }
92655 }
92656@@ -537,8 +537,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
92657 if (pset->vm_stat_diff[i]) {
92658 int v = pset->vm_stat_diff[i];
92659 pset->vm_stat_diff[i] = 0;
92660- atomic_long_add(v, &zone->vm_stat[i]);
92661- atomic_long_add(v, &vm_stat[i]);
92662+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92663+ atomic_long_add_unchecked(v, &vm_stat[i]);
92664 }
92665 }
92666 #endif
92667@@ -1281,10 +1281,20 @@ static int __init setup_vmstat(void)
92668 start_cpu_timer(cpu);
92669 #endif
92670 #ifdef CONFIG_PROC_FS
92671- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
92672- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
92673- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
92674- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
92675+ {
92676+ mode_t gr_mode = S_IRUGO;
92677+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92678+ gr_mode = S_IRUSR;
92679+#endif
92680+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
92681+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
92682+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
92683+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
92684+#else
92685+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
92686+#endif
92687+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
92688+ }
92689 #endif
92690 return 0;
92691 }
92692diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
92693index 61fc573..b5e47d0 100644
92694--- a/net/8021q/vlan.c
92695+++ b/net/8021q/vlan.c
92696@@ -472,7 +472,7 @@ out:
92697 return NOTIFY_DONE;
92698 }
92699
92700-static struct notifier_block vlan_notifier_block __read_mostly = {
92701+static struct notifier_block vlan_notifier_block = {
92702 .notifier_call = vlan_device_event,
92703 };
92704
92705@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
92706 err = -EPERM;
92707 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
92708 break;
92709- if ((args.u.name_type >= 0) &&
92710- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
92711+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
92712 struct vlan_net *vn;
92713
92714 vn = net_generic(net, vlan_net_id);
92715diff --git a/net/9p/mod.c b/net/9p/mod.c
92716index 6ab36ae..6f1841b 100644
92717--- a/net/9p/mod.c
92718+++ b/net/9p/mod.c
92719@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
92720 void v9fs_register_trans(struct p9_trans_module *m)
92721 {
92722 spin_lock(&v9fs_trans_lock);
92723- list_add_tail(&m->list, &v9fs_trans_list);
92724+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
92725 spin_unlock(&v9fs_trans_lock);
92726 }
92727 EXPORT_SYMBOL(v9fs_register_trans);
92728@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
92729 void v9fs_unregister_trans(struct p9_trans_module *m)
92730 {
92731 spin_lock(&v9fs_trans_lock);
92732- list_del_init(&m->list);
92733+ pax_list_del_init((struct list_head *)&m->list);
92734 spin_unlock(&v9fs_trans_lock);
92735 }
92736 EXPORT_SYMBOL(v9fs_unregister_trans);
92737diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
92738index 3ffda1b..fceac96 100644
92739--- a/net/9p/trans_fd.c
92740+++ b/net/9p/trans_fd.c
92741@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
92742 oldfs = get_fs();
92743 set_fs(get_ds());
92744 /* The cast to a user pointer is valid due to the set_fs() */
92745- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
92746+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
92747 set_fs(oldfs);
92748
92749 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
92750diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
92751index 876fbe8..8bbea9f 100644
92752--- a/net/atm/atm_misc.c
92753+++ b/net/atm/atm_misc.c
92754@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
92755 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
92756 return 1;
92757 atm_return(vcc, truesize);
92758- atomic_inc(&vcc->stats->rx_drop);
92759+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92760 return 0;
92761 }
92762 EXPORT_SYMBOL(atm_charge);
92763@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
92764 }
92765 }
92766 atm_return(vcc, guess);
92767- atomic_inc(&vcc->stats->rx_drop);
92768+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92769 return NULL;
92770 }
92771 EXPORT_SYMBOL(atm_alloc_charge);
92772@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
92773
92774 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92775 {
92776-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92777+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92778 __SONET_ITEMS
92779 #undef __HANDLE_ITEM
92780 }
92781@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
92782
92783 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92784 {
92785-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92786+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
92787 __SONET_ITEMS
92788 #undef __HANDLE_ITEM
92789 }
92790diff --git a/net/atm/lec.h b/net/atm/lec.h
92791index 4149db1..f2ab682 100644
92792--- a/net/atm/lec.h
92793+++ b/net/atm/lec.h
92794@@ -48,7 +48,7 @@ struct lane2_ops {
92795 const u8 *tlvs, u32 sizeoftlvs);
92796 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
92797 const u8 *tlvs, u32 sizeoftlvs);
92798-};
92799+} __no_const;
92800
92801 /*
92802 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
92803diff --git a/net/atm/proc.c b/net/atm/proc.c
92804index bbb6461..cf04016 100644
92805--- a/net/atm/proc.c
92806+++ b/net/atm/proc.c
92807@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
92808 const struct k_atm_aal_stats *stats)
92809 {
92810 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
92811- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
92812- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
92813- atomic_read(&stats->rx_drop));
92814+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
92815+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
92816+ atomic_read_unchecked(&stats->rx_drop));
92817 }
92818
92819 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
92820diff --git a/net/atm/resources.c b/net/atm/resources.c
92821index 0447d5d..3cf4728 100644
92822--- a/net/atm/resources.c
92823+++ b/net/atm/resources.c
92824@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
92825 static void copy_aal_stats(struct k_atm_aal_stats *from,
92826 struct atm_aal_stats *to)
92827 {
92828-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92829+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92830 __AAL_STAT_ITEMS
92831 #undef __HANDLE_ITEM
92832 }
92833@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
92834 static void subtract_aal_stats(struct k_atm_aal_stats *from,
92835 struct atm_aal_stats *to)
92836 {
92837-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92838+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
92839 __AAL_STAT_ITEMS
92840 #undef __HANDLE_ITEM
92841 }
92842diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
92843index 919a5ce..cc6b444 100644
92844--- a/net/ax25/sysctl_net_ax25.c
92845+++ b/net/ax25/sysctl_net_ax25.c
92846@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
92847 {
92848 char path[sizeof("net/ax25/") + IFNAMSIZ];
92849 int k;
92850- struct ctl_table *table;
92851+ ctl_table_no_const *table;
92852
92853 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
92854 if (!table)
92855diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
92856index 0a8a80c..f7e89aa 100644
92857--- a/net/batman-adv/bat_iv_ogm.c
92858+++ b/net/batman-adv/bat_iv_ogm.c
92859@@ -121,7 +121,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
92860
92861 /* randomize initial seqno to avoid collision */
92862 get_random_bytes(&random_seqno, sizeof(random_seqno));
92863- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92864+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92865
92866 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
92867 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
92868@@ -703,9 +703,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
92869 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
92870
92871 /* change sequence number to network order */
92872- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
92873+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
92874 batadv_ogm_packet->seqno = htonl(seqno);
92875- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
92876+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
92877
92878 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
92879 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
92880@@ -1111,7 +1111,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
92881 return;
92882
92883 /* could be changed by schedule_own_packet() */
92884- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
92885+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
92886
92887 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
92888 has_directlink_flag = 1;
92889diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
92890index c478e6b..469fd2f 100644
92891--- a/net/batman-adv/hard-interface.c
92892+++ b/net/batman-adv/hard-interface.c
92893@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
92894 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
92895 dev_add_pack(&hard_iface->batman_adv_ptype);
92896
92897- atomic_set(&hard_iface->frag_seqno, 1);
92898+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
92899 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
92900 hard_iface->net_dev->name);
92901
92902diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
92903index 813db4e..847edac 100644
92904--- a/net/batman-adv/soft-interface.c
92905+++ b/net/batman-adv/soft-interface.c
92906@@ -263,7 +263,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92907 primary_if->net_dev->dev_addr, ETH_ALEN);
92908
92909 /* set broadcast sequence number */
92910- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
92911+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
92912 bcast_packet->seqno = htonl(seqno);
92913
92914 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
92915@@ -483,7 +483,7 @@ static int batadv_softif_init_late(struct net_device *dev)
92916 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
92917
92918 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
92919- atomic_set(&bat_priv->bcast_seqno, 1);
92920+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
92921 atomic_set(&bat_priv->tt.vn, 0);
92922 atomic_set(&bat_priv->tt.local_changes, 0);
92923 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
92924diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
92925index b2c94e1..3d47e07 100644
92926--- a/net/batman-adv/types.h
92927+++ b/net/batman-adv/types.h
92928@@ -51,7 +51,7 @@
92929 struct batadv_hard_iface_bat_iv {
92930 unsigned char *ogm_buff;
92931 int ogm_buff_len;
92932- atomic_t ogm_seqno;
92933+ atomic_unchecked_t ogm_seqno;
92934 };
92935
92936 /**
92937@@ -76,7 +76,7 @@ struct batadv_hard_iface {
92938 int16_t if_num;
92939 char if_status;
92940 struct net_device *net_dev;
92941- atomic_t frag_seqno;
92942+ atomic_unchecked_t frag_seqno;
92943 uint8_t num_bcasts;
92944 struct kobject *hardif_obj;
92945 atomic_t refcount;
92946@@ -560,7 +560,7 @@ struct batadv_priv {
92947 #ifdef CONFIG_BATMAN_ADV_DEBUG
92948 atomic_t log_level;
92949 #endif
92950- atomic_t bcast_seqno;
92951+ atomic_unchecked_t bcast_seqno;
92952 atomic_t bcast_queue_left;
92953 atomic_t batman_queue_left;
92954 char num_ifaces;
92955diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
92956index 48b31d3..62a0bcb 100644
92957--- a/net/batman-adv/unicast.c
92958+++ b/net/batman-adv/unicast.c
92959@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
92960 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
92961 frag2->flags = large_tail;
92962
92963- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
92964+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
92965 frag1->seqno = htons(seqno - 1);
92966 frag2->seqno = htons(seqno);
92967
92968diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
92969index fa4bf66..e92948f 100644
92970--- a/net/bluetooth/hci_sock.c
92971+++ b/net/bluetooth/hci_sock.c
92972@@ -932,7 +932,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
92973 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
92974 }
92975
92976- len = min_t(unsigned int, len, sizeof(uf));
92977+ len = min((size_t)len, sizeof(uf));
92978 if (copy_from_user(&uf, optval, len)) {
92979 err = -EFAULT;
92980 break;
92981diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
92982index 63fa111..b166ec6 100644
92983--- a/net/bluetooth/l2cap_core.c
92984+++ b/net/bluetooth/l2cap_core.c
92985@@ -3511,8 +3511,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
92986 break;
92987
92988 case L2CAP_CONF_RFC:
92989- if (olen == sizeof(rfc))
92990- memcpy(&rfc, (void *)val, olen);
92991+ if (olen != sizeof(rfc))
92992+ break;
92993+
92994+ memcpy(&rfc, (void *)val, olen);
92995
92996 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
92997 rfc.mode != chan->mode)
92998diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
92999index 0098af8..fb5a31f 100644
93000--- a/net/bluetooth/l2cap_sock.c
93001+++ b/net/bluetooth/l2cap_sock.c
93002@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
93003 struct sock *sk = sock->sk;
93004 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
93005 struct l2cap_options opts;
93006- int len, err = 0;
93007+ int err = 0;
93008+ size_t len = optlen;
93009 u32 opt;
93010
93011 BT_DBG("sk %p", sk);
93012@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
93013 opts.max_tx = chan->max_tx;
93014 opts.txwin_size = chan->tx_win;
93015
93016- len = min_t(unsigned int, sizeof(opts), optlen);
93017+ len = min(sizeof(opts), len);
93018 if (copy_from_user((char *) &opts, optval, len)) {
93019 err = -EFAULT;
93020 break;
93021@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93022 struct bt_security sec;
93023 struct bt_power pwr;
93024 struct l2cap_conn *conn;
93025- int len, err = 0;
93026+ int err = 0;
93027+ size_t len = optlen;
93028 u32 opt;
93029
93030 BT_DBG("sk %p", sk);
93031@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93032
93033 sec.level = BT_SECURITY_LOW;
93034
93035- len = min_t(unsigned int, sizeof(sec), optlen);
93036+ len = min(sizeof(sec), len);
93037 if (copy_from_user((char *) &sec, optval, len)) {
93038 err = -EFAULT;
93039 break;
93040@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
93041
93042 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
93043
93044- len = min_t(unsigned int, sizeof(pwr), optlen);
93045+ len = min(sizeof(pwr), len);
93046 if (copy_from_user((char *) &pwr, optval, len)) {
93047 err = -EFAULT;
93048 break;
93049diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
93050index c1c6028..17e8dcc 100644
93051--- a/net/bluetooth/rfcomm/sock.c
93052+++ b/net/bluetooth/rfcomm/sock.c
93053@@ -665,7 +665,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
93054 struct sock *sk = sock->sk;
93055 struct bt_security sec;
93056 int err = 0;
93057- size_t len;
93058+ size_t len = optlen;
93059 u32 opt;
93060
93061 BT_DBG("sk %p", sk);
93062@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
93063
93064 sec.level = BT_SECURITY_LOW;
93065
93066- len = min_t(unsigned int, sizeof(sec), optlen);
93067+ len = min(sizeof(sec), len);
93068 if (copy_from_user((char *) &sec, optval, len)) {
93069 err = -EFAULT;
93070 break;
93071diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
93072index 84fcf9f..e389b27 100644
93073--- a/net/bluetooth/rfcomm/tty.c
93074+++ b/net/bluetooth/rfcomm/tty.c
93075@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
93076 BT_DBG("tty %p id %d", tty, tty->index);
93077
93078 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
93079- dev->channel, dev->port.count);
93080+ dev->channel, atomic_read(&dev->port.count));
93081
93082 err = tty_port_open(&dev->port, tty, filp);
93083 if (err)
93084@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
93085 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
93086
93087 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
93088- dev->port.count);
93089+ atomic_read(&dev->port.count));
93090
93091 tty_port_close(&dev->port, tty, filp);
93092 }
93093diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
93094index 5180938..7c470c3 100644
93095--- a/net/bridge/netfilter/ebt_ulog.c
93096+++ b/net/bridge/netfilter/ebt_ulog.c
93097@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93098 ub->qlen++;
93099
93100 pm = nlmsg_data(nlh);
93101+ memset(pm, 0, sizeof(*pm));
93102
93103 /* Fill in the ulog data */
93104 pm->version = EBT_ULOG_VERSION;
93105@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93106 pm->hook = hooknr;
93107 if (uloginfo->prefix != NULL)
93108 strcpy(pm->prefix, uloginfo->prefix);
93109- else
93110- *(pm->prefix) = '\0';
93111
93112 if (in) {
93113 strcpy(pm->physindev, in->name);
93114@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
93115 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
93116 else
93117 strcpy(pm->indev, in->name);
93118- } else
93119- pm->indev[0] = pm->physindev[0] = '\0';
93120+ }
93121
93122 if (out) {
93123 /* If out exists, then out is a bridge port */
93124 strcpy(pm->physoutdev, out->name);
93125 /* rcu_read_lock()ed by nf_hook_slow */
93126 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
93127- } else
93128- pm->outdev[0] = pm->physoutdev[0] = '\0';
93129+ }
93130
93131 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
93132 BUG();
93133diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
93134index ac78024..161a80c 100644
93135--- a/net/bridge/netfilter/ebtables.c
93136+++ b/net/bridge/netfilter/ebtables.c
93137@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93138 tmp.valid_hooks = t->table->valid_hooks;
93139 }
93140 mutex_unlock(&ebt_mutex);
93141- if (copy_to_user(user, &tmp, *len) != 0){
93142+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
93143 BUGPRINT("c2u Didn't work\n");
93144 ret = -EFAULT;
93145 break;
93146@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
93147 goto out;
93148 tmp.valid_hooks = t->valid_hooks;
93149
93150- if (copy_to_user(user, &tmp, *len) != 0) {
93151+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
93152 ret = -EFAULT;
93153 break;
93154 }
93155@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
93156 tmp.entries_size = t->table->entries_size;
93157 tmp.valid_hooks = t->table->valid_hooks;
93158
93159- if (copy_to_user(user, &tmp, *len) != 0) {
93160+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
93161 ret = -EFAULT;
93162 break;
93163 }
93164diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
93165index 0f45522..dab651f 100644
93166--- a/net/caif/cfctrl.c
93167+++ b/net/caif/cfctrl.c
93168@@ -10,6 +10,7 @@
93169 #include <linux/spinlock.h>
93170 #include <linux/slab.h>
93171 #include <linux/pkt_sched.h>
93172+#include <linux/sched.h>
93173 #include <net/caif/caif_layer.h>
93174 #include <net/caif/cfpkt.h>
93175 #include <net/caif/cfctrl.h>
93176@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
93177 memset(&dev_info, 0, sizeof(dev_info));
93178 dev_info.id = 0xff;
93179 cfsrvl_init(&this->serv, 0, &dev_info, false);
93180- atomic_set(&this->req_seq_no, 1);
93181- atomic_set(&this->rsp_seq_no, 1);
93182+ atomic_set_unchecked(&this->req_seq_no, 1);
93183+ atomic_set_unchecked(&this->rsp_seq_no, 1);
93184 this->serv.layer.receive = cfctrl_recv;
93185 sprintf(this->serv.layer.name, "ctrl");
93186 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
93187@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
93188 struct cfctrl_request_info *req)
93189 {
93190 spin_lock_bh(&ctrl->info_list_lock);
93191- atomic_inc(&ctrl->req_seq_no);
93192- req->sequence_no = atomic_read(&ctrl->req_seq_no);
93193+ atomic_inc_unchecked(&ctrl->req_seq_no);
93194+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
93195 list_add_tail(&req->list, &ctrl->list);
93196 spin_unlock_bh(&ctrl->info_list_lock);
93197 }
93198@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
93199 if (p != first)
93200 pr_warn("Requests are not received in order\n");
93201
93202- atomic_set(&ctrl->rsp_seq_no,
93203+ atomic_set_unchecked(&ctrl->rsp_seq_no,
93204 p->sequence_no);
93205 list_del(&p->list);
93206 goto out;
93207diff --git a/net/can/af_can.c b/net/can/af_can.c
93208index 3ab8dd2..b9aef13 100644
93209--- a/net/can/af_can.c
93210+++ b/net/can/af_can.c
93211@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
93212 };
93213
93214 /* notifier block for netdevice event */
93215-static struct notifier_block can_netdev_notifier __read_mostly = {
93216+static struct notifier_block can_netdev_notifier = {
93217 .notifier_call = can_notifier,
93218 };
93219
93220diff --git a/net/can/gw.c b/net/can/gw.c
93221index 3f9b0f3..fc6d4fa 100644
93222--- a/net/can/gw.c
93223+++ b/net/can/gw.c
93224@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
93225 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
93226
93227 static HLIST_HEAD(cgw_list);
93228-static struct notifier_block notifier;
93229
93230 static struct kmem_cache *cgw_cache __read_mostly;
93231
93232@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
93233 return err;
93234 }
93235
93236+static struct notifier_block notifier = {
93237+ .notifier_call = cgw_notifier
93238+};
93239+
93240 static __init int cgw_module_init(void)
93241 {
93242 /* sanitize given module parameter */
93243@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
93244 return -ENOMEM;
93245
93246 /* set notifier */
93247- notifier.notifier_call = cgw_notifier;
93248 register_netdevice_notifier(&notifier);
93249
93250 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
93251diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
93252index 4a5df7b..9ad1f1d 100644
93253--- a/net/ceph/messenger.c
93254+++ b/net/ceph/messenger.c
93255@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
93256 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
93257
93258 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
93259-static atomic_t addr_str_seq = ATOMIC_INIT(0);
93260+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
93261
93262 static struct page *zero_page; /* used in certain error cases */
93263
93264@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
93265 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
93266 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
93267
93268- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
93269+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
93270 s = addr_str[i];
93271
93272 switch (ss->ss_family) {
93273diff --git a/net/compat.c b/net/compat.c
93274index dd32e34..6066f87 100644
93275--- a/net/compat.c
93276+++ b/net/compat.c
93277@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
93278 return -EFAULT;
93279 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
93280 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
93281- kmsg->msg_name = compat_ptr(tmp1);
93282- kmsg->msg_iov = compat_ptr(tmp2);
93283- kmsg->msg_control = compat_ptr(tmp3);
93284+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
93285+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
93286+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
93287 return 0;
93288 }
93289
93290@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93291
93292 if (kern_msg->msg_namelen) {
93293 if (mode == VERIFY_READ) {
93294- int err = move_addr_to_kernel(kern_msg->msg_name,
93295+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
93296 kern_msg->msg_namelen,
93297 kern_address);
93298 if (err < 0)
93299@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93300 kern_msg->msg_name = NULL;
93301
93302 tot_len = iov_from_user_compat_to_kern(kern_iov,
93303- (struct compat_iovec __user *)kern_msg->msg_iov,
93304+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
93305 kern_msg->msg_iovlen);
93306 if (tot_len >= 0)
93307 kern_msg->msg_iov = kern_iov;
93308@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
93309
93310 #define CMSG_COMPAT_FIRSTHDR(msg) \
93311 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
93312- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
93313+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
93314 (struct compat_cmsghdr __user *)NULL)
93315
93316 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
93317 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
93318 (ucmlen) <= (unsigned long) \
93319 ((mhdr)->msg_controllen - \
93320- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
93321+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
93322
93323 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
93324 struct compat_cmsghdr __user *cmsg, int cmsg_len)
93325 {
93326 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
93327- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
93328+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
93329 msg->msg_controllen)
93330 return NULL;
93331 return (struct compat_cmsghdr __user *)ptr;
93332@@ -222,7 +222,7 @@ Efault:
93333
93334 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
93335 {
93336- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
93337+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
93338 struct compat_cmsghdr cmhdr;
93339 struct compat_timeval ctv;
93340 struct compat_timespec cts[3];
93341@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
93342
93343 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
93344 {
93345- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
93346+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
93347 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
93348 int fdnum = scm->fp->count;
93349 struct file **fp = scm->fp->fp;
93350@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
93351 return -EFAULT;
93352 old_fs = get_fs();
93353 set_fs(KERNEL_DS);
93354- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
93355+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
93356 set_fs(old_fs);
93357
93358 return err;
93359@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
93360 len = sizeof(ktime);
93361 old_fs = get_fs();
93362 set_fs(KERNEL_DS);
93363- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
93364+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
93365 set_fs(old_fs);
93366
93367 if (!err) {
93368@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93369 case MCAST_JOIN_GROUP:
93370 case MCAST_LEAVE_GROUP:
93371 {
93372- struct compat_group_req __user *gr32 = (void *)optval;
93373+ struct compat_group_req __user *gr32 = (void __user *)optval;
93374 struct group_req __user *kgr =
93375 compat_alloc_user_space(sizeof(struct group_req));
93376 u32 interface;
93377@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93378 case MCAST_BLOCK_SOURCE:
93379 case MCAST_UNBLOCK_SOURCE:
93380 {
93381- struct compat_group_source_req __user *gsr32 = (void *)optval;
93382+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
93383 struct group_source_req __user *kgsr = compat_alloc_user_space(
93384 sizeof(struct group_source_req));
93385 u32 interface;
93386@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
93387 }
93388 case MCAST_MSFILTER:
93389 {
93390- struct compat_group_filter __user *gf32 = (void *)optval;
93391+ struct compat_group_filter __user *gf32 = (void __user *)optval;
93392 struct group_filter __user *kgf;
93393 u32 interface, fmode, numsrc;
93394
93395@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
93396 char __user *optval, int __user *optlen,
93397 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
93398 {
93399- struct compat_group_filter __user *gf32 = (void *)optval;
93400+ struct compat_group_filter __user *gf32 = (void __user *)optval;
93401 struct group_filter __user *kgf;
93402 int __user *koptlen;
93403 u32 interface, fmode, numsrc;
93404@@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
93405
93406 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
93407 return -EINVAL;
93408- if (copy_from_user(a, args, nas[call]))
93409+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
93410 return -EFAULT;
93411 a0 = a[0];
93412 a1 = a[1];
93413diff --git a/net/core/datagram.c b/net/core/datagram.c
93414index af814e7..3d761de 100644
93415--- a/net/core/datagram.c
93416+++ b/net/core/datagram.c
93417@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
93418 }
93419
93420 kfree_skb(skb);
93421- atomic_inc(&sk->sk_drops);
93422+ atomic_inc_unchecked(&sk->sk_drops);
93423 sk_mem_reclaim_partial(sk);
93424
93425 return err;
93426diff --git a/net/core/dev.c b/net/core/dev.c
93427index 3d13874..6e78dc7 100644
93428--- a/net/core/dev.c
93429+++ b/net/core/dev.c
93430@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
93431 {
93432 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
93433 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
93434- atomic_long_inc(&dev->rx_dropped);
93435+ atomic_long_inc_unchecked(&dev->rx_dropped);
93436 kfree_skb(skb);
93437 return NET_RX_DROP;
93438 }
93439 }
93440
93441 if (unlikely(!is_skb_forwardable(dev, skb))) {
93442- atomic_long_inc(&dev->rx_dropped);
93443+ atomic_long_inc_unchecked(&dev->rx_dropped);
93444 kfree_skb(skb);
93445 return NET_RX_DROP;
93446 }
93447@@ -2428,7 +2428,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
93448
93449 struct dev_gso_cb {
93450 void (*destructor)(struct sk_buff *skb);
93451-};
93452+} __no_const;
93453
93454 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
93455
93456@@ -3203,7 +3203,7 @@ enqueue:
93457
93458 local_irq_restore(flags);
93459
93460- atomic_long_inc(&skb->dev->rx_dropped);
93461+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93462 kfree_skb(skb);
93463 return NET_RX_DROP;
93464 }
93465@@ -3275,7 +3275,7 @@ int netif_rx_ni(struct sk_buff *skb)
93466 }
93467 EXPORT_SYMBOL(netif_rx_ni);
93468
93469-static void net_tx_action(struct softirq_action *h)
93470+static __latent_entropy void net_tx_action(void)
93471 {
93472 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93473
93474@@ -3609,7 +3609,7 @@ ncls:
93475 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
93476 } else {
93477 drop:
93478- atomic_long_inc(&skb->dev->rx_dropped);
93479+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93480 kfree_skb(skb);
93481 /* Jamal, now you will not able to escape explaining
93482 * me how you were going to use this. :-)
93483@@ -4269,7 +4269,7 @@ void netif_napi_del(struct napi_struct *napi)
93484 }
93485 EXPORT_SYMBOL(netif_napi_del);
93486
93487-static void net_rx_action(struct softirq_action *h)
93488+static __latent_entropy void net_rx_action(void)
93489 {
93490 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93491 unsigned long time_limit = jiffies + 2;
93492@@ -5973,7 +5973,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
93493 } else {
93494 netdev_stats_to_stats64(storage, &dev->stats);
93495 }
93496- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
93497+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
93498 return storage;
93499 }
93500 EXPORT_SYMBOL(dev_get_stats);
93501diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
93502index 5b7d0e1..cb960fc 100644
93503--- a/net/core/dev_ioctl.c
93504+++ b/net/core/dev_ioctl.c
93505@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
93506 if (no_module && capable(CAP_NET_ADMIN))
93507 no_module = request_module("netdev-%s", name);
93508 if (no_module && capable(CAP_SYS_MODULE)) {
93509+#ifdef CONFIG_GRKERNSEC_MODHARDEN
93510+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
93511+#else
93512 if (!request_module("%s", name))
93513 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
93514 name);
93515+#endif
93516 }
93517 }
93518 EXPORT_SYMBOL(dev_load);
93519diff --git a/net/core/flow.c b/net/core/flow.c
93520index dfa602c..3103d88 100644
93521--- a/net/core/flow.c
93522+++ b/net/core/flow.c
93523@@ -61,7 +61,7 @@ struct flow_cache {
93524 struct timer_list rnd_timer;
93525 };
93526
93527-atomic_t flow_cache_genid = ATOMIC_INIT(0);
93528+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
93529 EXPORT_SYMBOL(flow_cache_genid);
93530 static struct flow_cache flow_cache_global;
93531 static struct kmem_cache *flow_cachep __read_mostly;
93532@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
93533
93534 static int flow_entry_valid(struct flow_cache_entry *fle)
93535 {
93536- if (atomic_read(&flow_cache_genid) != fle->genid)
93537+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
93538 return 0;
93539 if (fle->object && !fle->object->ops->check(fle->object))
93540 return 0;
93541@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
93542 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
93543 fcp->hash_count++;
93544 }
93545- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
93546+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
93547 flo = fle->object;
93548 if (!flo)
93549 goto ret_object;
93550@@ -279,7 +279,7 @@ nocache:
93551 }
93552 flo = resolver(net, key, family, dir, flo, ctx);
93553 if (fle) {
93554- fle->genid = atomic_read(&flow_cache_genid);
93555+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
93556 if (!IS_ERR(flo))
93557 fle->object = flo;
93558 else
93559diff --git a/net/core/iovec.c b/net/core/iovec.c
93560index 7d84ea1..55385ae 100644
93561--- a/net/core/iovec.c
93562+++ b/net/core/iovec.c
93563@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93564 if (m->msg_namelen) {
93565 if (mode == VERIFY_READ) {
93566 void __user *namep;
93567- namep = (void __user __force *) m->msg_name;
93568+ namep = (void __force_user *) m->msg_name;
93569 err = move_addr_to_kernel(namep, m->msg_namelen,
93570 address);
93571 if (err < 0)
93572@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93573 }
93574
93575 size = m->msg_iovlen * sizeof(struct iovec);
93576- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
93577+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
93578 return -EFAULT;
93579
93580 m->msg_iov = iov;
93581diff --git a/net/core/neighbour.c b/net/core/neighbour.c
93582index 6072610..7374c18 100644
93583--- a/net/core/neighbour.c
93584+++ b/net/core/neighbour.c
93585@@ -2774,7 +2774,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
93586 void __user *buffer, size_t *lenp, loff_t *ppos)
93587 {
93588 int size, ret;
93589- struct ctl_table tmp = *ctl;
93590+ ctl_table_no_const tmp = *ctl;
93591
93592 tmp.extra1 = &zero;
93593 tmp.extra2 = &unres_qlen_max;
93594diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
93595index 2bf8329..7960607 100644
93596--- a/net/core/net-procfs.c
93597+++ b/net/core/net-procfs.c
93598@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
93599 else
93600 seq_printf(seq, "%04x", ntohs(pt->type));
93601
93602+#ifdef CONFIG_GRKERNSEC_HIDESYM
93603+ seq_printf(seq, " %-8s %pf\n",
93604+ pt->dev ? pt->dev->name : "", NULL);
93605+#else
93606 seq_printf(seq, " %-8s %pf\n",
93607 pt->dev ? pt->dev->name : "", pt->func);
93608+#endif
93609 }
93610
93611 return 0;
93612diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
93613index d954b56..b0a0f7a 100644
93614--- a/net/core/net-sysfs.c
93615+++ b/net/core/net-sysfs.c
93616@@ -1356,7 +1356,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
93617 }
93618 EXPORT_SYMBOL(netdev_class_remove_file);
93619
93620-int netdev_kobject_init(void)
93621+int __init netdev_kobject_init(void)
93622 {
93623 kobj_ns_type_register(&net_ns_type_operations);
93624 return class_register(&net_class);
93625diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
93626index 81d3a9a..a0bd7a8 100644
93627--- a/net/core/net_namespace.c
93628+++ b/net/core/net_namespace.c
93629@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
93630 int error;
93631 LIST_HEAD(net_exit_list);
93632
93633- list_add_tail(&ops->list, list);
93634+ pax_list_add_tail((struct list_head *)&ops->list, list);
93635 if (ops->init || (ops->id && ops->size)) {
93636 for_each_net(net) {
93637 error = ops_init(ops, net);
93638@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
93639
93640 out_undo:
93641 /* If I have an error cleanup all namespaces I initialized */
93642- list_del(&ops->list);
93643+ pax_list_del((struct list_head *)&ops->list);
93644 ops_exit_list(ops, &net_exit_list);
93645 ops_free_list(ops, &net_exit_list);
93646 return error;
93647@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
93648 struct net *net;
93649 LIST_HEAD(net_exit_list);
93650
93651- list_del(&ops->list);
93652+ pax_list_del((struct list_head *)&ops->list);
93653 for_each_net(net)
93654 list_add_tail(&net->exit_list, &net_exit_list);
93655 ops_exit_list(ops, &net_exit_list);
93656@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
93657 mutex_lock(&net_mutex);
93658 error = register_pernet_operations(&pernet_list, ops);
93659 if (!error && (first_device == &pernet_list))
93660- first_device = &ops->list;
93661+ first_device = (struct list_head *)&ops->list;
93662 mutex_unlock(&net_mutex);
93663 return error;
93664 }
93665diff --git a/net/core/netpoll.c b/net/core/netpoll.c
93666index fc75c9e..8c8e9be 100644
93667--- a/net/core/netpoll.c
93668+++ b/net/core/netpoll.c
93669@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93670 struct udphdr *udph;
93671 struct iphdr *iph;
93672 struct ethhdr *eth;
93673- static atomic_t ip_ident;
93674+ static atomic_unchecked_t ip_ident;
93675 struct ipv6hdr *ip6h;
93676
93677 udp_len = len + sizeof(*udph);
93678@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93679 put_unaligned(0x45, (unsigned char *)iph);
93680 iph->tos = 0;
93681 put_unaligned(htons(ip_len), &(iph->tot_len));
93682- iph->id = htons(atomic_inc_return(&ip_ident));
93683+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
93684 iph->frag_off = 0;
93685 iph->ttl = 64;
93686 iph->protocol = IPPROTO_UDP;
93687diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
93688index 2a0e21d..6ad7642 100644
93689--- a/net/core/rtnetlink.c
93690+++ b/net/core/rtnetlink.c
93691@@ -58,7 +58,7 @@ struct rtnl_link {
93692 rtnl_doit_func doit;
93693 rtnl_dumpit_func dumpit;
93694 rtnl_calcit_func calcit;
93695-};
93696+} __no_const;
93697
93698 static DEFINE_MUTEX(rtnl_mutex);
93699
93700@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
93701 if (rtnl_link_ops_get(ops->kind))
93702 return -EEXIST;
93703
93704- if (!ops->dellink)
93705- ops->dellink = unregister_netdevice_queue;
93706+ if (!ops->dellink) {
93707+ pax_open_kernel();
93708+ *(void **)&ops->dellink = unregister_netdevice_queue;
93709+ pax_close_kernel();
93710+ }
93711
93712- list_add_tail(&ops->list, &link_ops);
93713+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
93714 return 0;
93715 }
93716 EXPORT_SYMBOL_GPL(__rtnl_link_register);
93717@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
93718 for_each_net(net) {
93719 __rtnl_kill_links(net, ops);
93720 }
93721- list_del(&ops->list);
93722+ pax_list_del((struct list_head *)&ops->list);
93723 }
93724 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
93725
93726diff --git a/net/core/scm.c b/net/core/scm.c
93727index b442e7e..6f5b5a2 100644
93728--- a/net/core/scm.c
93729+++ b/net/core/scm.c
93730@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
93731 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93732 {
93733 struct cmsghdr __user *cm
93734- = (__force struct cmsghdr __user *)msg->msg_control;
93735+ = (struct cmsghdr __force_user *)msg->msg_control;
93736 struct cmsghdr cmhdr;
93737 int cmlen = CMSG_LEN(len);
93738 int err;
93739@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93740 err = -EFAULT;
93741 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
93742 goto out;
93743- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
93744+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
93745 goto out;
93746 cmlen = CMSG_SPACE(len);
93747 if (msg->msg_controllen < cmlen)
93748@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
93749 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93750 {
93751 struct cmsghdr __user *cm
93752- = (__force struct cmsghdr __user*)msg->msg_control;
93753+ = (struct cmsghdr __force_user *)msg->msg_control;
93754
93755 int fdmax = 0;
93756 int fdnum = scm->fp->count;
93757@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93758 if (fdnum < fdmax)
93759 fdmax = fdnum;
93760
93761- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
93762+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
93763 i++, cmfptr++)
93764 {
93765 struct socket *sock;
93766diff --git a/net/core/skbuff.c b/net/core/skbuff.c
93767index c28c7fe..a399a6d 100644
93768--- a/net/core/skbuff.c
93769+++ b/net/core/skbuff.c
93770@@ -3104,13 +3104,15 @@ void __init skb_init(void)
93771 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
93772 sizeof(struct sk_buff),
93773 0,
93774- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93775+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93776+ SLAB_NO_SANITIZE,
93777 NULL);
93778 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
93779 (2*sizeof(struct sk_buff)) +
93780 sizeof(atomic_t),
93781 0,
93782- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93783+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93784+ SLAB_NO_SANITIZE,
93785 NULL);
93786 }
93787
93788@@ -3541,6 +3543,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
93789 skb->tstamp.tv64 = 0;
93790 skb->pkt_type = PACKET_HOST;
93791 skb->skb_iif = 0;
93792+ skb->local_df = 0;
93793 skb_dst_drop(skb);
93794 skb->mark = 0;
93795 secpath_reset(skb);
93796diff --git a/net/core/sock.c b/net/core/sock.c
93797index 0b39e7a..5e9f91e 100644
93798--- a/net/core/sock.c
93799+++ b/net/core/sock.c
93800@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93801 struct sk_buff_head *list = &sk->sk_receive_queue;
93802
93803 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
93804- atomic_inc(&sk->sk_drops);
93805+ atomic_inc_unchecked(&sk->sk_drops);
93806 trace_sock_rcvqueue_full(sk, skb);
93807 return -ENOMEM;
93808 }
93809@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93810 return err;
93811
93812 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
93813- atomic_inc(&sk->sk_drops);
93814+ atomic_inc_unchecked(&sk->sk_drops);
93815 return -ENOBUFS;
93816 }
93817
93818@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93819 skb_dst_force(skb);
93820
93821 spin_lock_irqsave(&list->lock, flags);
93822- skb->dropcount = atomic_read(&sk->sk_drops);
93823+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
93824 __skb_queue_tail(list, skb);
93825 spin_unlock_irqrestore(&list->lock, flags);
93826
93827@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93828 skb->dev = NULL;
93829
93830 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
93831- atomic_inc(&sk->sk_drops);
93832+ atomic_inc_unchecked(&sk->sk_drops);
93833 goto discard_and_relse;
93834 }
93835 if (nested)
93836@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93837 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
93838 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
93839 bh_unlock_sock(sk);
93840- atomic_inc(&sk->sk_drops);
93841+ atomic_inc_unchecked(&sk->sk_drops);
93842 goto discard_and_relse;
93843 }
93844
93845@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93846 struct timeval tm;
93847 } v;
93848
93849- int lv = sizeof(int);
93850- int len;
93851+ unsigned int lv = sizeof(int);
93852+ unsigned int len;
93853
93854 if (get_user(len, optlen))
93855 return -EFAULT;
93856- if (len < 0)
93857+ if (len > INT_MAX)
93858 return -EINVAL;
93859
93860 memset(&v, 0, sizeof(v));
93861@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93862
93863 case SO_PEERNAME:
93864 {
93865- char address[128];
93866+ char address[_K_SS_MAXSIZE];
93867
93868 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
93869 return -ENOTCONN;
93870- if (lv < len)
93871+ if (lv < len || sizeof address < len)
93872 return -EINVAL;
93873 if (copy_to_user(optval, address, len))
93874 return -EFAULT;
93875@@ -1183,7 +1183,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93876
93877 if (len > lv)
93878 len = lv;
93879- if (copy_to_user(optval, &v, len))
93880+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
93881 return -EFAULT;
93882 lenout:
93883 if (put_user(len, optlen))
93884@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
93885 */
93886 smp_wmb();
93887 atomic_set(&sk->sk_refcnt, 1);
93888- atomic_set(&sk->sk_drops, 0);
93889+ atomic_set_unchecked(&sk->sk_drops, 0);
93890 }
93891 EXPORT_SYMBOL(sock_init_data);
93892
93893@@ -2451,6 +2451,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
93894 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
93895 int level, int type)
93896 {
93897+ struct sock_extended_err ee;
93898 struct sock_exterr_skb *serr;
93899 struct sk_buff *skb, *skb2;
93900 int copied, err;
93901@@ -2472,7 +2473,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
93902 sock_recv_timestamp(msg, sk, skb);
93903
93904 serr = SKB_EXT_ERR(skb);
93905- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
93906+ ee = serr->ee;
93907+ put_cmsg(msg, level, type, sizeof ee, &ee);
93908
93909 msg->msg_flags |= MSG_ERRQUEUE;
93910 err = copied;
93911diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
93912index a0e9cf6..ef7f9ed 100644
93913--- a/net/core/sock_diag.c
93914+++ b/net/core/sock_diag.c
93915@@ -9,26 +9,33 @@
93916 #include <linux/inet_diag.h>
93917 #include <linux/sock_diag.h>
93918
93919-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
93920+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
93921 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
93922 static DEFINE_MUTEX(sock_diag_table_mutex);
93923
93924 int sock_diag_check_cookie(void *sk, __u32 *cookie)
93925 {
93926+#ifndef CONFIG_GRKERNSEC_HIDESYM
93927 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
93928 cookie[1] != INET_DIAG_NOCOOKIE) &&
93929 ((u32)(unsigned long)sk != cookie[0] ||
93930 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
93931 return -ESTALE;
93932 else
93933+#endif
93934 return 0;
93935 }
93936 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
93937
93938 void sock_diag_save_cookie(void *sk, __u32 *cookie)
93939 {
93940+#ifdef CONFIG_GRKERNSEC_HIDESYM
93941+ cookie[0] = 0;
93942+ cookie[1] = 0;
93943+#else
93944 cookie[0] = (u32)(unsigned long)sk;
93945 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
93946+#endif
93947 }
93948 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
93949
93950@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
93951 mutex_lock(&sock_diag_table_mutex);
93952 if (sock_diag_handlers[hndl->family])
93953 err = -EBUSY;
93954- else
93955+ else {
93956+ pax_open_kernel();
93957 sock_diag_handlers[hndl->family] = hndl;
93958+ pax_close_kernel();
93959+ }
93960 mutex_unlock(&sock_diag_table_mutex);
93961
93962 return err;
93963@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
93964
93965 mutex_lock(&sock_diag_table_mutex);
93966 BUG_ON(sock_diag_handlers[family] != hnld);
93967+ pax_open_kernel();
93968 sock_diag_handlers[family] = NULL;
93969+ pax_close_kernel();
93970 mutex_unlock(&sock_diag_table_mutex);
93971 }
93972 EXPORT_SYMBOL_GPL(sock_diag_unregister);
93973diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
93974index cca4441..5e616de 100644
93975--- a/net/core/sysctl_net_core.c
93976+++ b/net/core/sysctl_net_core.c
93977@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
93978 {
93979 unsigned int orig_size, size;
93980 int ret, i;
93981- struct ctl_table tmp = {
93982+ ctl_table_no_const tmp = {
93983 .data = &size,
93984 .maxlen = sizeof(size),
93985 .mode = table->mode
93986@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
93987 void __user *buffer, size_t *lenp, loff_t *ppos)
93988 {
93989 char id[IFNAMSIZ];
93990- struct ctl_table tbl = {
93991+ ctl_table_no_const tbl = {
93992 .data = id,
93993 .maxlen = IFNAMSIZ,
93994 };
93995@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
93996
93997 static __net_init int sysctl_core_net_init(struct net *net)
93998 {
93999- struct ctl_table *tbl;
94000+ ctl_table_no_const *tbl = NULL;
94001
94002 net->core.sysctl_somaxconn = SOMAXCONN;
94003
94004- tbl = netns_core_table;
94005 if (!net_eq(net, &init_net)) {
94006- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
94007+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
94008 if (tbl == NULL)
94009 goto err_dup;
94010
94011@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
94012 if (net->user_ns != &init_user_ns) {
94013 tbl[0].procname = NULL;
94014 }
94015- }
94016-
94017- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
94018+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
94019+ } else
94020+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
94021 if (net->core.sysctl_hdr == NULL)
94022 goto err_reg;
94023
94024 return 0;
94025
94026 err_reg:
94027- if (tbl != netns_core_table)
94028- kfree(tbl);
94029+ kfree(tbl);
94030 err_dup:
94031 return -ENOMEM;
94032 }
94033@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
94034 kfree(tbl);
94035 }
94036
94037-static __net_initdata struct pernet_operations sysctl_core_ops = {
94038+static __net_initconst struct pernet_operations sysctl_core_ops = {
94039 .init = sysctl_core_net_init,
94040 .exit = sysctl_core_net_exit,
94041 };
94042diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
94043index dd4d506..fb2fb87 100644
94044--- a/net/decnet/af_decnet.c
94045+++ b/net/decnet/af_decnet.c
94046@@ -465,6 +465,7 @@ static struct proto dn_proto = {
94047 .sysctl_rmem = sysctl_decnet_rmem,
94048 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
94049 .obj_size = sizeof(struct dn_sock),
94050+ .slab_flags = SLAB_USERCOPY,
94051 };
94052
94053 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
94054diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
94055index 5325b54..a0d4d69 100644
94056--- a/net/decnet/sysctl_net_decnet.c
94057+++ b/net/decnet/sysctl_net_decnet.c
94058@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
94059
94060 if (len > *lenp) len = *lenp;
94061
94062- if (copy_to_user(buffer, addr, len))
94063+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
94064 return -EFAULT;
94065
94066 *lenp = len;
94067@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
94068
94069 if (len > *lenp) len = *lenp;
94070
94071- if (copy_to_user(buffer, devname, len))
94072+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
94073 return -EFAULT;
94074
94075 *lenp = len;
94076diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
94077index 008f337..b03b8c9 100644
94078--- a/net/ieee802154/6lowpan.c
94079+++ b/net/ieee802154/6lowpan.c
94080@@ -548,7 +548,7 @@ static int lowpan_header_create(struct sk_buff *skb,
94081 hc06_ptr += 3;
94082 } else {
94083 /* compress nothing */
94084- memcpy(hc06_ptr, &hdr, 4);
94085+ memcpy(hc06_ptr, hdr, 4);
94086 /* replace the top byte with new ECN | DSCP format */
94087 *hc06_ptr = tmp;
94088 hc06_ptr += 4;
94089diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
94090index cfeb85c..385989a 100644
94091--- a/net/ipv4/af_inet.c
94092+++ b/net/ipv4/af_inet.c
94093@@ -1675,13 +1675,9 @@ static int __init inet_init(void)
94094
94095 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
94096
94097- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
94098- if (!sysctl_local_reserved_ports)
94099- goto out;
94100-
94101 rc = proto_register(&tcp_prot, 1);
94102 if (rc)
94103- goto out_free_reserved_ports;
94104+ goto out;
94105
94106 rc = proto_register(&udp_prot, 1);
94107 if (rc)
94108@@ -1790,8 +1786,6 @@ out_unregister_udp_proto:
94109 proto_unregister(&udp_prot);
94110 out_unregister_tcp_proto:
94111 proto_unregister(&tcp_prot);
94112-out_free_reserved_ports:
94113- kfree(sysctl_local_reserved_ports);
94114 goto out;
94115 }
94116
94117diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
94118index a1b5bcb..62ec5c6 100644
94119--- a/net/ipv4/devinet.c
94120+++ b/net/ipv4/devinet.c
94121@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
94122 idx = 0;
94123 head = &net->dev_index_head[h];
94124 rcu_read_lock();
94125- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
94126+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
94127 net->dev_base_seq;
94128 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94129 if (idx < s_idx)
94130@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
94131 idx = 0;
94132 head = &net->dev_index_head[h];
94133 rcu_read_lock();
94134- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
94135+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
94136 net->dev_base_seq;
94137 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94138 if (idx < s_idx)
94139@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
94140 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
94141 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
94142
94143-static struct devinet_sysctl_table {
94144+static const struct devinet_sysctl_table {
94145 struct ctl_table_header *sysctl_header;
94146 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
94147 } devinet_sysctl = {
94148@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
94149 int err;
94150 struct ipv4_devconf *all, *dflt;
94151 #ifdef CONFIG_SYSCTL
94152- struct ctl_table *tbl = ctl_forward_entry;
94153+ ctl_table_no_const *tbl = NULL;
94154 struct ctl_table_header *forw_hdr;
94155 #endif
94156
94157@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
94158 goto err_alloc_dflt;
94159
94160 #ifdef CONFIG_SYSCTL
94161- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
94162+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
94163 if (tbl == NULL)
94164 goto err_alloc_ctl;
94165
94166@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
94167 goto err_reg_dflt;
94168
94169 err = -ENOMEM;
94170- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
94171+ if (!net_eq(net, &init_net))
94172+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
94173+ else
94174+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
94175 if (forw_hdr == NULL)
94176 goto err_reg_ctl;
94177 net->ipv4.forw_hdr = forw_hdr;
94178@@ -2245,8 +2248,7 @@ err_reg_ctl:
94179 err_reg_dflt:
94180 __devinet_sysctl_unregister(all);
94181 err_reg_all:
94182- if (tbl != ctl_forward_entry)
94183- kfree(tbl);
94184+ kfree(tbl);
94185 err_alloc_ctl:
94186 #endif
94187 if (dflt != &ipv4_devconf_dflt)
94188diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
94189index b3f627a..b0f3e99 100644
94190--- a/net/ipv4/fib_frontend.c
94191+++ b/net/ipv4/fib_frontend.c
94192@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
94193 #ifdef CONFIG_IP_ROUTE_MULTIPATH
94194 fib_sync_up(dev);
94195 #endif
94196- atomic_inc(&net->ipv4.dev_addr_genid);
94197+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94198 rt_cache_flush(dev_net(dev));
94199 break;
94200 case NETDEV_DOWN:
94201 fib_del_ifaddr(ifa, NULL);
94202- atomic_inc(&net->ipv4.dev_addr_genid);
94203+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94204 if (ifa->ifa_dev->ifa_list == NULL) {
94205 /* Last address was deleted from this interface.
94206 * Disable IP.
94207@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
94208 #ifdef CONFIG_IP_ROUTE_MULTIPATH
94209 fib_sync_up(dev);
94210 #endif
94211- atomic_inc(&net->ipv4.dev_addr_genid);
94212+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
94213 rt_cache_flush(net);
94214 break;
94215 case NETDEV_DOWN:
94216diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
94217index d5dbca5..6251d5f 100644
94218--- a/net/ipv4/fib_semantics.c
94219+++ b/net/ipv4/fib_semantics.c
94220@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
94221 nh->nh_saddr = inet_select_addr(nh->nh_dev,
94222 nh->nh_gw,
94223 nh->nh_parent->fib_scope);
94224- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
94225+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
94226
94227 return nh->nh_saddr;
94228 }
94229diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
94230index 6acb541..9ea617d 100644
94231--- a/net/ipv4/inet_connection_sock.c
94232+++ b/net/ipv4/inet_connection_sock.c
94233@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
94234 .range = { 32768, 61000 },
94235 };
94236
94237-unsigned long *sysctl_local_reserved_ports;
94238+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
94239 EXPORT_SYMBOL(sysctl_local_reserved_ports);
94240
94241 void inet_get_local_port_range(int *low, int *high)
94242diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
94243index 96da9c7..b956690 100644
94244--- a/net/ipv4/inet_hashtables.c
94245+++ b/net/ipv4/inet_hashtables.c
94246@@ -18,12 +18,15 @@
94247 #include <linux/sched.h>
94248 #include <linux/slab.h>
94249 #include <linux/wait.h>
94250+#include <linux/security.h>
94251
94252 #include <net/inet_connection_sock.h>
94253 #include <net/inet_hashtables.h>
94254 #include <net/secure_seq.h>
94255 #include <net/ip.h>
94256
94257+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
94258+
94259 /*
94260 * Allocate and initialize a new local port bind bucket.
94261 * The bindhash mutex for snum's hash chain must be held here.
94262@@ -554,6 +557,8 @@ ok:
94263 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
94264 spin_unlock(&head->lock);
94265
94266+ gr_update_task_in_ip_table(current, inet_sk(sk));
94267+
94268 if (tw) {
94269 inet_twsk_deschedule(tw, death_row);
94270 while (twrefcnt) {
94271diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
94272index 33d5537..da337a4 100644
94273--- a/net/ipv4/inetpeer.c
94274+++ b/net/ipv4/inetpeer.c
94275@@ -503,8 +503,8 @@ relookup:
94276 if (p) {
94277 p->daddr = *daddr;
94278 atomic_set(&p->refcnt, 1);
94279- atomic_set(&p->rid, 0);
94280- atomic_set(&p->ip_id_count,
94281+ atomic_set_unchecked(&p->rid, 0);
94282+ atomic_set_unchecked(&p->ip_id_count,
94283 (daddr->family == AF_INET) ?
94284 secure_ip_id(daddr->addr.a4) :
94285 secure_ipv6_id(daddr->addr.a6));
94286diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
94287index b66910a..cfe416e 100644
94288--- a/net/ipv4/ip_fragment.c
94289+++ b/net/ipv4/ip_fragment.c
94290@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
94291 return 0;
94292
94293 start = qp->rid;
94294- end = atomic_inc_return(&peer->rid);
94295+ end = atomic_inc_return_unchecked(&peer->rid);
94296 qp->rid = end;
94297
94298 rc = qp->q.fragments && (end - start) > max;
94299@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
94300
94301 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94302 {
94303- struct ctl_table *table;
94304+ ctl_table_no_const *table = NULL;
94305 struct ctl_table_header *hdr;
94306
94307- table = ip4_frags_ns_ctl_table;
94308 if (!net_eq(net, &init_net)) {
94309- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
94310+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
94311 if (table == NULL)
94312 goto err_alloc;
94313
94314@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94315 /* Don't export sysctls to unprivileged users */
94316 if (net->user_ns != &init_user_ns)
94317 table[0].procname = NULL;
94318- }
94319+ hdr = register_net_sysctl(net, "net/ipv4", table);
94320+ } else
94321+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
94322
94323- hdr = register_net_sysctl(net, "net/ipv4", table);
94324 if (hdr == NULL)
94325 goto err_reg;
94326
94327@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
94328 return 0;
94329
94330 err_reg:
94331- if (!net_eq(net, &init_net))
94332- kfree(table);
94333+ kfree(table);
94334 err_alloc:
94335 return -ENOMEM;
94336 }
94337diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
94338index d7aea4c..a8ee872 100644
94339--- a/net/ipv4/ip_gre.c
94340+++ b/net/ipv4/ip_gre.c
94341@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
94342 module_param(log_ecn_error, bool, 0644);
94343 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94344
94345-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
94346+static struct rtnl_link_ops ipgre_link_ops;
94347 static int ipgre_tunnel_init(struct net_device *dev);
94348
94349 static int ipgre_net_id __read_mostly;
94350@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
94351 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
94352 };
94353
94354-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94355+static struct rtnl_link_ops ipgre_link_ops = {
94356 .kind = "gre",
94357 .maxtype = IFLA_GRE_MAX,
94358 .policy = ipgre_policy,
94359@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94360 .fill_info = ipgre_fill_info,
94361 };
94362
94363-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
94364+static struct rtnl_link_ops ipgre_tap_ops = {
94365 .kind = "gretap",
94366 .maxtype = IFLA_GRE_MAX,
94367 .policy = ipgre_policy,
94368diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
94369index 23e6ab0..be67a57 100644
94370--- a/net/ipv4/ip_sockglue.c
94371+++ b/net/ipv4/ip_sockglue.c
94372@@ -1153,7 +1153,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94373 len = min_t(unsigned int, len, opt->optlen);
94374 if (put_user(len, optlen))
94375 return -EFAULT;
94376- if (copy_to_user(optval, opt->__data, len))
94377+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
94378+ copy_to_user(optval, opt->__data, len))
94379 return -EFAULT;
94380 return 0;
94381 }
94382@@ -1284,7 +1285,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94383 if (sk->sk_type != SOCK_STREAM)
94384 return -ENOPROTOOPT;
94385
94386- msg.msg_control = optval;
94387+ msg.msg_control = (void __force_kernel *)optval;
94388 msg.msg_controllen = len;
94389 msg.msg_flags = flags;
94390
94391diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
94392index 26847e1..75d2d2f 100644
94393--- a/net/ipv4/ip_vti.c
94394+++ b/net/ipv4/ip_vti.c
94395@@ -44,7 +44,7 @@
94396 #include <net/net_namespace.h>
94397 #include <net/netns/generic.h>
94398
94399-static struct rtnl_link_ops vti_link_ops __read_mostly;
94400+static struct rtnl_link_ops vti_link_ops;
94401
94402 static int vti_net_id __read_mostly;
94403 static int vti_tunnel_init(struct net_device *dev);
94404@@ -425,7 +425,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
94405 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
94406 };
94407
94408-static struct rtnl_link_ops vti_link_ops __read_mostly = {
94409+static struct rtnl_link_ops vti_link_ops = {
94410 .kind = "vti",
94411 .maxtype = IFLA_VTI_MAX,
94412 .policy = vti_policy,
94413diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
94414index efa1138..20dbba0 100644
94415--- a/net/ipv4/ipconfig.c
94416+++ b/net/ipv4/ipconfig.c
94417@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
94418
94419 mm_segment_t oldfs = get_fs();
94420 set_fs(get_ds());
94421- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94422+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94423 set_fs(oldfs);
94424 return res;
94425 }
94426@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
94427
94428 mm_segment_t oldfs = get_fs();
94429 set_fs(get_ds());
94430- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94431+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94432 set_fs(oldfs);
94433 return res;
94434 }
94435@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
94436
94437 mm_segment_t oldfs = get_fs();
94438 set_fs(get_ds());
94439- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
94440+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
94441 set_fs(oldfs);
94442 return res;
94443 }
94444diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
94445index 7f80fb4..b0328f6 100644
94446--- a/net/ipv4/ipip.c
94447+++ b/net/ipv4/ipip.c
94448@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94449 static int ipip_net_id __read_mostly;
94450
94451 static int ipip_tunnel_init(struct net_device *dev);
94452-static struct rtnl_link_ops ipip_link_ops __read_mostly;
94453+static struct rtnl_link_ops ipip_link_ops;
94454
94455 static int ipip_err(struct sk_buff *skb, u32 info)
94456 {
94457@@ -408,7 +408,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
94458 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
94459 };
94460
94461-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
94462+static struct rtnl_link_ops ipip_link_ops = {
94463 .kind = "ipip",
94464 .maxtype = IFLA_IPTUN_MAX,
94465 .policy = ipip_policy,
94466diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
94467index 85a4f21..1beb1f5 100644
94468--- a/net/ipv4/netfilter/arp_tables.c
94469+++ b/net/ipv4/netfilter/arp_tables.c
94470@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
94471 #endif
94472
94473 static int get_info(struct net *net, void __user *user,
94474- const int *len, int compat)
94475+ int len, int compat)
94476 {
94477 char name[XT_TABLE_MAXNAMELEN];
94478 struct xt_table *t;
94479 int ret;
94480
94481- if (*len != sizeof(struct arpt_getinfo)) {
94482- duprintf("length %u != %Zu\n", *len,
94483+ if (len != sizeof(struct arpt_getinfo)) {
94484+ duprintf("length %u != %Zu\n", len,
94485 sizeof(struct arpt_getinfo));
94486 return -EINVAL;
94487 }
94488@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
94489 info.size = private->size;
94490 strcpy(info.name, name);
94491
94492- if (copy_to_user(user, &info, *len) != 0)
94493+ if (copy_to_user(user, &info, len) != 0)
94494 ret = -EFAULT;
94495 else
94496 ret = 0;
94497@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
94498
94499 switch (cmd) {
94500 case ARPT_SO_GET_INFO:
94501- ret = get_info(sock_net(sk), user, len, 1);
94502+ ret = get_info(sock_net(sk), user, *len, 1);
94503 break;
94504 case ARPT_SO_GET_ENTRIES:
94505 ret = compat_get_entries(sock_net(sk), user, len);
94506@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
94507
94508 switch (cmd) {
94509 case ARPT_SO_GET_INFO:
94510- ret = get_info(sock_net(sk), user, len, 0);
94511+ ret = get_info(sock_net(sk), user, *len, 0);
94512 break;
94513
94514 case ARPT_SO_GET_ENTRIES:
94515diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
94516index d23118d..6ad7277 100644
94517--- a/net/ipv4/netfilter/ip_tables.c
94518+++ b/net/ipv4/netfilter/ip_tables.c
94519@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
94520 #endif
94521
94522 static int get_info(struct net *net, void __user *user,
94523- const int *len, int compat)
94524+ int len, int compat)
94525 {
94526 char name[XT_TABLE_MAXNAMELEN];
94527 struct xt_table *t;
94528 int ret;
94529
94530- if (*len != sizeof(struct ipt_getinfo)) {
94531- duprintf("length %u != %zu\n", *len,
94532+ if (len != sizeof(struct ipt_getinfo)) {
94533+ duprintf("length %u != %zu\n", len,
94534 sizeof(struct ipt_getinfo));
94535 return -EINVAL;
94536 }
94537@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
94538 info.size = private->size;
94539 strcpy(info.name, name);
94540
94541- if (copy_to_user(user, &info, *len) != 0)
94542+ if (copy_to_user(user, &info, len) != 0)
94543 ret = -EFAULT;
94544 else
94545 ret = 0;
94546@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94547
94548 switch (cmd) {
94549 case IPT_SO_GET_INFO:
94550- ret = get_info(sock_net(sk), user, len, 1);
94551+ ret = get_info(sock_net(sk), user, *len, 1);
94552 break;
94553 case IPT_SO_GET_ENTRIES:
94554 ret = compat_get_entries(sock_net(sk), user, len);
94555@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94556
94557 switch (cmd) {
94558 case IPT_SO_GET_INFO:
94559- ret = get_info(sock_net(sk), user, len, 0);
94560+ ret = get_info(sock_net(sk), user, *len, 0);
94561 break;
94562
94563 case IPT_SO_GET_ENTRIES:
94564diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
94565index cbc2215..9cb993c 100644
94566--- a/net/ipv4/netfilter/ipt_ULOG.c
94567+++ b/net/ipv4/netfilter/ipt_ULOG.c
94568@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
94569 ub->qlen++;
94570
94571 pm = nlmsg_data(nlh);
94572+ memset(pm, 0, sizeof(*pm));
94573
94574 /* We might not have a timestamp, get one */
94575 if (skb->tstamp.tv64 == 0)
94576@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
94577 }
94578 else if (loginfo->prefix[0] != '\0')
94579 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
94580- else
94581- *(pm->prefix) = '\0';
94582
94583 if (in && in->hard_header_len > 0 &&
94584 skb->mac_header != skb->network_header &&
94585@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
94586
94587 if (in)
94588 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
94589- else
94590- pm->indev_name[0] = '\0';
94591
94592 if (out)
94593 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
94594- else
94595- pm->outdev_name[0] = '\0';
94596
94597 /* copy_len <= skb->len, so can't fail. */
94598 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
94599diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
94600index c482f7c..2784262 100644
94601--- a/net/ipv4/ping.c
94602+++ b/net/ipv4/ping.c
94603@@ -55,7 +55,7 @@
94604
94605
94606 struct ping_table ping_table;
94607-struct pingv6_ops pingv6_ops;
94608+struct pingv6_ops *pingv6_ops;
94609 EXPORT_SYMBOL_GPL(pingv6_ops);
94610
94611 static u16 ping_port_rover;
94612@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
94613 return -ENODEV;
94614 }
94615 }
94616- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
94617+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
94618 scoped);
94619 rcu_read_unlock();
94620
94621@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
94622 }
94623 #if IS_ENABLED(CONFIG_IPV6)
94624 } else if (skb->protocol == htons(ETH_P_IPV6)) {
94625- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
94626+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
94627 #endif
94628 }
94629
94630@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
94631 info, (u8 *)icmph);
94632 #if IS_ENABLED(CONFIG_IPV6)
94633 } else if (family == AF_INET6) {
94634- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
94635+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
94636 info, (u8 *)icmph);
94637 #endif
94638 }
94639@@ -841,7 +841,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94640 return ip_recv_error(sk, msg, len, addr_len);
94641 #if IS_ENABLED(CONFIG_IPV6)
94642 } else if (family == AF_INET6) {
94643- return pingv6_ops.ipv6_recv_error(sk, msg, len,
94644+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
94645 addr_len);
94646 #endif
94647 }
94648@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94649 }
94650
94651 if (inet6_sk(sk)->rxopt.all)
94652- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
94653+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
94654 #endif
94655 } else {
94656 BUG();
94657@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
94658 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94659 0, sock_i_ino(sp),
94660 atomic_read(&sp->sk_refcnt), sp,
94661- atomic_read(&sp->sk_drops), len);
94662+ atomic_read_unchecked(&sp->sk_drops), len);
94663 }
94664
94665 static int ping_v4_seq_show(struct seq_file *seq, void *v)
94666diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
94667index 7d3db78..9fd511d 100644
94668--- a/net/ipv4/raw.c
94669+++ b/net/ipv4/raw.c
94670@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
94671 int raw_rcv(struct sock *sk, struct sk_buff *skb)
94672 {
94673 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
94674- atomic_inc(&sk->sk_drops);
94675+ atomic_inc_unchecked(&sk->sk_drops);
94676 kfree_skb(skb);
94677 return NET_RX_DROP;
94678 }
94679@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
94680
94681 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
94682 {
94683+ struct icmp_filter filter;
94684+
94685 if (optlen > sizeof(struct icmp_filter))
94686 optlen = sizeof(struct icmp_filter);
94687- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
94688+ if (copy_from_user(&filter, optval, optlen))
94689 return -EFAULT;
94690+ raw_sk(sk)->filter = filter;
94691 return 0;
94692 }
94693
94694 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
94695 {
94696 int len, ret = -EFAULT;
94697+ struct icmp_filter filter;
94698
94699 if (get_user(len, optlen))
94700 goto out;
94701@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
94702 if (len > sizeof(struct icmp_filter))
94703 len = sizeof(struct icmp_filter);
94704 ret = -EFAULT;
94705- if (put_user(len, optlen) ||
94706- copy_to_user(optval, &raw_sk(sk)->filter, len))
94707+ filter = raw_sk(sk)->filter;
94708+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
94709 goto out;
94710 ret = 0;
94711 out: return ret;
94712@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
94713 0, 0L, 0,
94714 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
94715 0, sock_i_ino(sp),
94716- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
94717+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
94718 }
94719
94720 static int raw_seq_show(struct seq_file *seq, void *v)
94721diff --git a/net/ipv4/route.c b/net/ipv4/route.c
94722index 62290b5..f0d944f 100644
94723--- a/net/ipv4/route.c
94724+++ b/net/ipv4/route.c
94725@@ -2617,34 +2617,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
94726 .maxlen = sizeof(int),
94727 .mode = 0200,
94728 .proc_handler = ipv4_sysctl_rtcache_flush,
94729+ .extra1 = &init_net,
94730 },
94731 { },
94732 };
94733
94734 static __net_init int sysctl_route_net_init(struct net *net)
94735 {
94736- struct ctl_table *tbl;
94737+ ctl_table_no_const *tbl = NULL;
94738
94739- tbl = ipv4_route_flush_table;
94740 if (!net_eq(net, &init_net)) {
94741- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94742+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94743 if (tbl == NULL)
94744 goto err_dup;
94745
94746 /* Don't export sysctls to unprivileged users */
94747 if (net->user_ns != &init_user_ns)
94748 tbl[0].procname = NULL;
94749- }
94750- tbl[0].extra1 = net;
94751+ tbl[0].extra1 = net;
94752+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94753+ } else
94754+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
94755
94756- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94757 if (net->ipv4.route_hdr == NULL)
94758 goto err_reg;
94759 return 0;
94760
94761 err_reg:
94762- if (tbl != ipv4_route_flush_table)
94763- kfree(tbl);
94764+ kfree(tbl);
94765 err_dup:
94766 return -ENOMEM;
94767 }
94768@@ -2667,8 +2667,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
94769
94770 static __net_init int rt_genid_init(struct net *net)
94771 {
94772- atomic_set(&net->ipv4.rt_genid, 0);
94773- atomic_set(&net->fnhe_genid, 0);
94774+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
94775+ atomic_set_unchecked(&net->fnhe_genid, 0);
94776 get_random_bytes(&net->ipv4.dev_addr_genid,
94777 sizeof(net->ipv4.dev_addr_genid));
94778 return 0;
94779diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
94780index 540279f..9855b16 100644
94781--- a/net/ipv4/sysctl_net_ipv4.c
94782+++ b/net/ipv4/sysctl_net_ipv4.c
94783@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
94784 {
94785 int ret;
94786 int range[2];
94787- struct ctl_table tmp = {
94788+ ctl_table_no_const tmp = {
94789 .data = &range,
94790 .maxlen = sizeof(range),
94791 .mode = table->mode,
94792@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
94793 int ret;
94794 gid_t urange[2];
94795 kgid_t low, high;
94796- struct ctl_table tmp = {
94797+ ctl_table_no_const tmp = {
94798 .data = &urange,
94799 .maxlen = sizeof(urange),
94800 .mode = table->mode,
94801@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
94802 void __user *buffer, size_t *lenp, loff_t *ppos)
94803 {
94804 char val[TCP_CA_NAME_MAX];
94805- struct ctl_table tbl = {
94806+ ctl_table_no_const tbl = {
94807 .data = val,
94808 .maxlen = TCP_CA_NAME_MAX,
94809 };
94810@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
94811 void __user *buffer, size_t *lenp,
94812 loff_t *ppos)
94813 {
94814- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
94815+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
94816 int ret;
94817
94818 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94819@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
94820 void __user *buffer, size_t *lenp,
94821 loff_t *ppos)
94822 {
94823- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
94824+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
94825 int ret;
94826
94827 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94828@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
94829 struct mem_cgroup *memcg;
94830 #endif
94831
94832- struct ctl_table tmp = {
94833+ ctl_table_no_const tmp = {
94834 .data = &vec,
94835 .maxlen = sizeof(vec),
94836 .mode = ctl->mode,
94837 };
94838
94839 if (!write) {
94840- ctl->data = &net->ipv4.sysctl_tcp_mem;
94841- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
94842+ ctl_table_no_const tcp_mem = *ctl;
94843+
94844+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
94845+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
94846 }
94847
94848 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
94849@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
94850 void __user *buffer, size_t *lenp,
94851 loff_t *ppos)
94852 {
94853- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94854+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94855 struct tcp_fastopen_context *ctxt;
94856 int ret;
94857 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
94858@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
94859 },
94860 {
94861 .procname = "ip_local_reserved_ports",
94862- .data = NULL, /* initialized in sysctl_ipv4_init */
94863+ .data = sysctl_local_reserved_ports,
94864 .maxlen = 65536,
94865 .mode = 0644,
94866 .proc_handler = proc_do_large_bitmap,
94867@@ -864,11 +866,10 @@ static struct ctl_table ipv4_net_table[] = {
94868
94869 static __net_init int ipv4_sysctl_init_net(struct net *net)
94870 {
94871- struct ctl_table *table;
94872+ ctl_table_no_const *table = NULL;
94873
94874- table = ipv4_net_table;
94875 if (!net_eq(net, &init_net)) {
94876- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
94877+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
94878 if (table == NULL)
94879 goto err_alloc;
94880
94881@@ -903,15 +904,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
94882
94883 tcp_init_mem(net);
94884
94885- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94886+ if (!net_eq(net, &init_net))
94887+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94888+ else
94889+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
94890 if (net->ipv4.ipv4_hdr == NULL)
94891 goto err_reg;
94892
94893 return 0;
94894
94895 err_reg:
94896- if (!net_eq(net, &init_net))
94897- kfree(table);
94898+ kfree(table);
94899 err_alloc:
94900 return -ENOMEM;
94901 }
94902@@ -933,16 +936,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
94903 static __init int sysctl_ipv4_init(void)
94904 {
94905 struct ctl_table_header *hdr;
94906- struct ctl_table *i;
94907-
94908- for (i = ipv4_table; i->procname; i++) {
94909- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
94910- i->data = sysctl_local_reserved_ports;
94911- break;
94912- }
94913- }
94914- if (!i->procname)
94915- return -EINVAL;
94916
94917 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
94918 if (hdr == NULL)
94919diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
94920index 068c8fb..a755c52 100644
94921--- a/net/ipv4/tcp_input.c
94922+++ b/net/ipv4/tcp_input.c
94923@@ -4435,7 +4435,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
94924 * simplifies code)
94925 */
94926 static void
94927-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94928+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94929 struct sk_buff *head, struct sk_buff *tail,
94930 u32 start, u32 end)
94931 {
94932@@ -5520,6 +5520,7 @@ discard:
94933 tcp_paws_reject(&tp->rx_opt, 0))
94934 goto discard_and_undo;
94935
94936+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
94937 if (th->syn) {
94938 /* We see SYN without ACK. It is attempt of
94939 * simultaneous connect with crossed SYNs.
94940@@ -5570,6 +5571,7 @@ discard:
94941 goto discard;
94942 #endif
94943 }
94944+#endif
94945 /* "fifth, if neither of the SYN or RST bits is set then
94946 * drop the segment and return."
94947 */
94948@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
94949 goto discard;
94950
94951 if (th->syn) {
94952- if (th->fin)
94953+ if (th->fin || th->urg || th->psh)
94954 goto discard;
94955 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
94956 return 1;
94957diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
94958index 5031f68..91569e2 100644
94959--- a/net/ipv4/tcp_ipv4.c
94960+++ b/net/ipv4/tcp_ipv4.c
94961@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
94962 EXPORT_SYMBOL(sysctl_tcp_low_latency);
94963
94964
94965+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94966+extern int grsec_enable_blackhole;
94967+#endif
94968+
94969 #ifdef CONFIG_TCP_MD5SIG
94970 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
94971 __be32 daddr, __be32 saddr, const struct tcphdr *th);
94972@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
94973 return 0;
94974
94975 reset:
94976+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94977+ if (!grsec_enable_blackhole)
94978+#endif
94979 tcp_v4_send_reset(rsk, skb);
94980 discard:
94981 kfree_skb(skb);
94982@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
94983 TCP_SKB_CB(skb)->sacked = 0;
94984
94985 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94986- if (!sk)
94987+ if (!sk) {
94988+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94989+ ret = 1;
94990+#endif
94991 goto no_tcp_socket;
94992-
94993+ }
94994 process:
94995- if (sk->sk_state == TCP_TIME_WAIT)
94996+ if (sk->sk_state == TCP_TIME_WAIT) {
94997+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94998+ ret = 2;
94999+#endif
95000 goto do_time_wait;
95001+ }
95002
95003 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
95004 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
95005@@ -2033,6 +2047,10 @@ csum_error:
95006 bad_packet:
95007 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
95008 } else {
95009+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95010+ if (!grsec_enable_blackhole || (ret == 1 &&
95011+ (skb->dev->flags & IFF_LOOPBACK)))
95012+#endif
95013 tcp_v4_send_reset(NULL, skb);
95014 }
95015
95016diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
95017index 58a3e69..7f0626e 100644
95018--- a/net/ipv4/tcp_minisocks.c
95019+++ b/net/ipv4/tcp_minisocks.c
95020@@ -27,6 +27,10 @@
95021 #include <net/inet_common.h>
95022 #include <net/xfrm.h>
95023
95024+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95025+extern int grsec_enable_blackhole;
95026+#endif
95027+
95028 int sysctl_tcp_syncookies __read_mostly = 1;
95029 EXPORT_SYMBOL(sysctl_tcp_syncookies);
95030
95031@@ -711,7 +715,10 @@ embryonic_reset:
95032 * avoid becoming vulnerable to outside attack aiming at
95033 * resetting legit local connections.
95034 */
95035- req->rsk_ops->send_reset(sk, skb);
95036+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95037+ if (!grsec_enable_blackhole)
95038+#endif
95039+ req->rsk_ops->send_reset(sk, skb);
95040 } else if (fastopen) { /* received a valid RST pkt */
95041 reqsk_fastopen_remove(sk, req, true);
95042 tcp_reset(sk);
95043diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
95044index 611beab..c4b6e1d 100644
95045--- a/net/ipv4/tcp_probe.c
95046+++ b/net/ipv4/tcp_probe.c
95047@@ -245,7 +245,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
95048 if (cnt + width >= len)
95049 break;
95050
95051- if (copy_to_user(buf + cnt, tbuf, width))
95052+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
95053 return -EFAULT;
95054 cnt += width;
95055 }
95056diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
95057index 4b85e6f..22f9ac9 100644
95058--- a/net/ipv4/tcp_timer.c
95059+++ b/net/ipv4/tcp_timer.c
95060@@ -22,6 +22,10 @@
95061 #include <linux/gfp.h>
95062 #include <net/tcp.h>
95063
95064+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95065+extern int grsec_lastack_retries;
95066+#endif
95067+
95068 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
95069 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
95070 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
95071@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
95072 }
95073 }
95074
95075+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95076+ if ((sk->sk_state == TCP_LAST_ACK) &&
95077+ (grsec_lastack_retries > 0) &&
95078+ (grsec_lastack_retries < retry_until))
95079+ retry_until = grsec_lastack_retries;
95080+#endif
95081+
95082 if (retransmits_timed_out(sk, retry_until,
95083 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
95084 /* Has it gone just too far? */
95085diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
95086index f60b1ee..40b401c 100644
95087--- a/net/ipv4/udp.c
95088+++ b/net/ipv4/udp.c
95089@@ -87,6 +87,7 @@
95090 #include <linux/types.h>
95091 #include <linux/fcntl.h>
95092 #include <linux/module.h>
95093+#include <linux/security.h>
95094 #include <linux/socket.h>
95095 #include <linux/sockios.h>
95096 #include <linux/igmp.h>
95097@@ -112,6 +113,10 @@
95098 #include <net/busy_poll.h>
95099 #include "udp_impl.h"
95100
95101+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95102+extern int grsec_enable_blackhole;
95103+#endif
95104+
95105 struct udp_table udp_table __read_mostly;
95106 EXPORT_SYMBOL(udp_table);
95107
95108@@ -595,6 +600,9 @@ found:
95109 return s;
95110 }
95111
95112+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
95113+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
95114+
95115 /*
95116 * This routine is called by the ICMP module when it gets some
95117 * sort of error condition. If err < 0 then the socket should
95118@@ -892,9 +900,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
95119 dport = usin->sin_port;
95120 if (dport == 0)
95121 return -EINVAL;
95122+
95123+ err = gr_search_udp_sendmsg(sk, usin);
95124+ if (err)
95125+ return err;
95126 } else {
95127 if (sk->sk_state != TCP_ESTABLISHED)
95128 return -EDESTADDRREQ;
95129+
95130+ err = gr_search_udp_sendmsg(sk, NULL);
95131+ if (err)
95132+ return err;
95133+
95134 daddr = inet->inet_daddr;
95135 dport = inet->inet_dport;
95136 /* Open fast path for connected socket.
95137@@ -1144,7 +1161,7 @@ static unsigned int first_packet_length(struct sock *sk)
95138 IS_UDPLITE(sk));
95139 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95140 IS_UDPLITE(sk));
95141- atomic_inc(&sk->sk_drops);
95142+ atomic_inc_unchecked(&sk->sk_drops);
95143 __skb_unlink(skb, rcvq);
95144 __skb_queue_tail(&list_kill, skb);
95145 }
95146@@ -1224,6 +1241,10 @@ try_again:
95147 if (!skb)
95148 goto out;
95149
95150+ err = gr_search_udp_recvmsg(sk, skb);
95151+ if (err)
95152+ goto out_free;
95153+
95154 ulen = skb->len - sizeof(struct udphdr);
95155 copied = len;
95156 if (copied > ulen)
95157@@ -1257,7 +1278,7 @@ try_again:
95158 if (unlikely(err)) {
95159 trace_kfree_skb(skb, udp_recvmsg);
95160 if (!peeked) {
95161- atomic_inc(&sk->sk_drops);
95162+ atomic_inc_unchecked(&sk->sk_drops);
95163 UDP_INC_STATS_USER(sock_net(sk),
95164 UDP_MIB_INERRORS, is_udplite);
95165 }
95166@@ -1545,7 +1566,7 @@ csum_error:
95167 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95168 drop:
95169 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95170- atomic_inc(&sk->sk_drops);
95171+ atomic_inc_unchecked(&sk->sk_drops);
95172 kfree_skb(skb);
95173 return -1;
95174 }
95175@@ -1564,7 +1585,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95176 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95177
95178 if (!skb1) {
95179- atomic_inc(&sk->sk_drops);
95180+ atomic_inc_unchecked(&sk->sk_drops);
95181 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95182 IS_UDPLITE(sk));
95183 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95184@@ -1736,6 +1757,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95185 goto csum_error;
95186
95187 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95188+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95189+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95190+#endif
95191 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
95192
95193 /*
95194@@ -2168,7 +2192,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
95195 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
95196 0, sock_i_ino(sp),
95197 atomic_read(&sp->sk_refcnt), sp,
95198- atomic_read(&sp->sk_drops), len);
95199+ atomic_read_unchecked(&sp->sk_drops), len);
95200 }
95201
95202 int udp4_seq_show(struct seq_file *seq, void *v)
95203diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
95204index adf9983..8e45d0a 100644
95205--- a/net/ipv4/xfrm4_policy.c
95206+++ b/net/ipv4/xfrm4_policy.c
95207@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
95208 fl4->flowi4_tos = iph->tos;
95209 }
95210
95211-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
95212+static int xfrm4_garbage_collect(struct dst_ops *ops)
95213 {
95214 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
95215
95216- xfrm4_policy_afinfo.garbage_collect(net);
95217+ xfrm_garbage_collect_deferred(net);
95218 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
95219 }
95220
95221@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
95222
95223 static int __net_init xfrm4_net_init(struct net *net)
95224 {
95225- struct ctl_table *table;
95226+ ctl_table_no_const *table = NULL;
95227 struct ctl_table_header *hdr;
95228
95229- table = xfrm4_policy_table;
95230 if (!net_eq(net, &init_net)) {
95231- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
95232+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
95233 if (!table)
95234 goto err_alloc;
95235
95236 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
95237- }
95238-
95239- hdr = register_net_sysctl(net, "net/ipv4", table);
95240+ hdr = register_net_sysctl(net, "net/ipv4", table);
95241+ } else
95242+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
95243 if (!hdr)
95244 goto err_reg;
95245
95246@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
95247 return 0;
95248
95249 err_reg:
95250- if (!net_eq(net, &init_net))
95251- kfree(table);
95252+ kfree(table);
95253 err_alloc:
95254 return -ENOMEM;
95255 }
95256diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
95257index cd3fb30..b7dfef7 100644
95258--- a/net/ipv6/addrconf.c
95259+++ b/net/ipv6/addrconf.c
95260@@ -586,7 +586,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
95261 idx = 0;
95262 head = &net->dev_index_head[h];
95263 rcu_read_lock();
95264- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
95265+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
95266 net->dev_base_seq;
95267 hlist_for_each_entry_rcu(dev, head, index_hlist) {
95268 if (idx < s_idx)
95269@@ -2364,7 +2364,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
95270 p.iph.ihl = 5;
95271 p.iph.protocol = IPPROTO_IPV6;
95272 p.iph.ttl = 64;
95273- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
95274+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
95275
95276 if (ops->ndo_do_ioctl) {
95277 mm_segment_t oldfs = get_fs();
95278@@ -3977,7 +3977,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
95279 s_ip_idx = ip_idx = cb->args[2];
95280
95281 rcu_read_lock();
95282- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
95283+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
95284 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
95285 idx = 0;
95286 head = &net->dev_index_head[h];
95287@@ -4603,7 +4603,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
95288 dst_free(&ifp->rt->dst);
95289 break;
95290 }
95291- atomic_inc(&net->ipv6.dev_addr_genid);
95292+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
95293 rt_genid_bump_ipv6(net);
95294 }
95295
95296@@ -4624,7 +4624,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
95297 int *valp = ctl->data;
95298 int val = *valp;
95299 loff_t pos = *ppos;
95300- struct ctl_table lctl;
95301+ ctl_table_no_const lctl;
95302 int ret;
95303
95304 /*
95305@@ -4709,7 +4709,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
95306 int *valp = ctl->data;
95307 int val = *valp;
95308 loff_t pos = *ppos;
95309- struct ctl_table lctl;
95310+ ctl_table_no_const lctl;
95311 int ret;
95312
95313 /*
95314diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
95315index 8132b44..b8eca70 100644
95316--- a/net/ipv6/af_inet6.c
95317+++ b/net/ipv6/af_inet6.c
95318@@ -767,7 +767,7 @@ static int __net_init inet6_net_init(struct net *net)
95319
95320 net->ipv6.sysctl.bindv6only = 0;
95321 net->ipv6.sysctl.icmpv6_time = 1*HZ;
95322- atomic_set(&net->ipv6.rt_genid, 0);
95323+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
95324
95325 err = ipv6_init_mibs(net);
95326 if (err)
95327diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
95328index c66c6df..f375d3c 100644
95329--- a/net/ipv6/datagram.c
95330+++ b/net/ipv6/datagram.c
95331@@ -908,5 +908,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
95332 0,
95333 sock_i_ino(sp),
95334 atomic_read(&sp->sk_refcnt), sp,
95335- atomic_read(&sp->sk_drops));
95336+ atomic_read_unchecked(&sp->sk_drops));
95337 }
95338diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
95339index eef8d94..cfa1852 100644
95340--- a/net/ipv6/icmp.c
95341+++ b/net/ipv6/icmp.c
95342@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
95343
95344 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
95345 {
95346- struct ctl_table *table;
95347+ ctl_table_no_const *table;
95348
95349 table = kmemdup(ipv6_icmp_table_template,
95350 sizeof(ipv6_icmp_table_template),
95351diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
95352index bf4a9a0..e5f6ac5 100644
95353--- a/net/ipv6/ip6_gre.c
95354+++ b/net/ipv6/ip6_gre.c
95355@@ -74,7 +74,7 @@ struct ip6gre_net {
95356 struct net_device *fb_tunnel_dev;
95357 };
95358
95359-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
95360+static struct rtnl_link_ops ip6gre_link_ops;
95361 static int ip6gre_tunnel_init(struct net_device *dev);
95362 static void ip6gre_tunnel_setup(struct net_device *dev);
95363 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
95364@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
95365 }
95366
95367
95368-static struct inet6_protocol ip6gre_protocol __read_mostly = {
95369+static struct inet6_protocol ip6gre_protocol = {
95370 .handler = ip6gre_rcv,
95371 .err_handler = ip6gre_err,
95372 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
95373@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
95374 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
95375 };
95376
95377-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
95378+static struct rtnl_link_ops ip6gre_link_ops = {
95379 .kind = "ip6gre",
95380 .maxtype = IFLA_GRE_MAX,
95381 .policy = ip6gre_policy,
95382@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
95383 .fill_info = ip6gre_fill_info,
95384 };
95385
95386-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
95387+static struct rtnl_link_ops ip6gre_tap_ops = {
95388 .kind = "ip6gretap",
95389 .maxtype = IFLA_GRE_MAX,
95390 .policy = ip6gre_policy,
95391diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
95392index c1e11b5..568e633 100644
95393--- a/net/ipv6/ip6_tunnel.c
95394+++ b/net/ipv6/ip6_tunnel.c
95395@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
95396
95397 static int ip6_tnl_dev_init(struct net_device *dev);
95398 static void ip6_tnl_dev_setup(struct net_device *dev);
95399-static struct rtnl_link_ops ip6_link_ops __read_mostly;
95400+static struct rtnl_link_ops ip6_link_ops;
95401
95402 static int ip6_tnl_net_id __read_mostly;
95403 struct ip6_tnl_net {
95404@@ -1699,7 +1699,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
95405 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
95406 };
95407
95408-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
95409+static struct rtnl_link_ops ip6_link_ops = {
95410 .kind = "ip6tnl",
95411 .maxtype = IFLA_IPTUN_MAX,
95412 .policy = ip6_tnl_policy,
95413diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
95414index d1e2e8e..51c19ae 100644
95415--- a/net/ipv6/ipv6_sockglue.c
95416+++ b/net/ipv6/ipv6_sockglue.c
95417@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
95418 if (sk->sk_type != SOCK_STREAM)
95419 return -ENOPROTOOPT;
95420
95421- msg.msg_control = optval;
95422+ msg.msg_control = (void __force_kernel *)optval;
95423 msg.msg_controllen = len;
95424 msg.msg_flags = flags;
95425
95426diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
95427index 44400c2..8e11f52 100644
95428--- a/net/ipv6/netfilter/ip6_tables.c
95429+++ b/net/ipv6/netfilter/ip6_tables.c
95430@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
95431 #endif
95432
95433 static int get_info(struct net *net, void __user *user,
95434- const int *len, int compat)
95435+ int len, int compat)
95436 {
95437 char name[XT_TABLE_MAXNAMELEN];
95438 struct xt_table *t;
95439 int ret;
95440
95441- if (*len != sizeof(struct ip6t_getinfo)) {
95442- duprintf("length %u != %zu\n", *len,
95443+ if (len != sizeof(struct ip6t_getinfo)) {
95444+ duprintf("length %u != %zu\n", len,
95445 sizeof(struct ip6t_getinfo));
95446 return -EINVAL;
95447 }
95448@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
95449 info.size = private->size;
95450 strcpy(info.name, name);
95451
95452- if (copy_to_user(user, &info, *len) != 0)
95453+ if (copy_to_user(user, &info, len) != 0)
95454 ret = -EFAULT;
95455 else
95456 ret = 0;
95457@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95458
95459 switch (cmd) {
95460 case IP6T_SO_GET_INFO:
95461- ret = get_info(sock_net(sk), user, len, 1);
95462+ ret = get_info(sock_net(sk), user, *len, 1);
95463 break;
95464 case IP6T_SO_GET_ENTRIES:
95465 ret = compat_get_entries(sock_net(sk), user, len);
95466@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95467
95468 switch (cmd) {
95469 case IP6T_SO_GET_INFO:
95470- ret = get_info(sock_net(sk), user, len, 0);
95471+ ret = get_info(sock_net(sk), user, *len, 0);
95472 break;
95473
95474 case IP6T_SO_GET_ENTRIES:
95475diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
95476index 253566a..9fa50c7 100644
95477--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
95478+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
95479@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
95480
95481 static int nf_ct_frag6_sysctl_register(struct net *net)
95482 {
95483- struct ctl_table *table;
95484+ ctl_table_no_const *table = NULL;
95485 struct ctl_table_header *hdr;
95486
95487- table = nf_ct_frag6_sysctl_table;
95488 if (!net_eq(net, &init_net)) {
95489- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
95490+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
95491 GFP_KERNEL);
95492 if (table == NULL)
95493 goto err_alloc;
95494@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95495 table[0].data = &net->nf_frag.frags.timeout;
95496 table[1].data = &net->nf_frag.frags.low_thresh;
95497 table[2].data = &net->nf_frag.frags.high_thresh;
95498- }
95499-
95500- hdr = register_net_sysctl(net, "net/netfilter", table);
95501+ hdr = register_net_sysctl(net, "net/netfilter", table);
95502+ } else
95503+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
95504 if (hdr == NULL)
95505 goto err_reg;
95506
95507@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95508 return 0;
95509
95510 err_reg:
95511- if (!net_eq(net, &init_net))
95512- kfree(table);
95513+ kfree(table);
95514 err_alloc:
95515 return -ENOMEM;
95516 }
95517diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
95518index 827f795..7e28e82 100644
95519--- a/net/ipv6/output_core.c
95520+++ b/net/ipv6/output_core.c
95521@@ -9,8 +9,8 @@
95522
95523 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95524 {
95525- static atomic_t ipv6_fragmentation_id;
95526- int old, new;
95527+ static atomic_unchecked_t ipv6_fragmentation_id;
95528+ int id;
95529
95530 #if IS_ENABLED(CONFIG_IPV6)
95531 if (rt && !(rt->dst.flags & DST_NOPEER)) {
95532@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95533 }
95534 }
95535 #endif
95536- do {
95537- old = atomic_read(&ipv6_fragmentation_id);
95538- new = old + 1;
95539- if (!new)
95540- new = 1;
95541- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
95542- fhdr->identification = htonl(new);
95543+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95544+ if (!id)
95545+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95546+ fhdr->identification = htonl(id);
95547 }
95548 EXPORT_SYMBOL(ipv6_select_ident);
95549
95550diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
95551index 7856e96..75ebc7f 100644
95552--- a/net/ipv6/ping.c
95553+++ b/net/ipv6/ping.c
95554@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
95555 };
95556 #endif
95557
95558+static struct pingv6_ops real_pingv6_ops = {
95559+ .ipv6_recv_error = ipv6_recv_error,
95560+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
95561+ .icmpv6_err_convert = icmpv6_err_convert,
95562+ .ipv6_icmp_error = ipv6_icmp_error,
95563+ .ipv6_chk_addr = ipv6_chk_addr,
95564+};
95565+
95566+static struct pingv6_ops dummy_pingv6_ops = {
95567+ .ipv6_recv_error = dummy_ipv6_recv_error,
95568+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
95569+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
95570+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
95571+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
95572+};
95573+
95574 int __init pingv6_init(void)
95575 {
95576 #ifdef CONFIG_PROC_FS
95577@@ -253,11 +269,7 @@ int __init pingv6_init(void)
95578 if (ret)
95579 return ret;
95580 #endif
95581- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
95582- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
95583- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
95584- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
95585- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
95586+ pingv6_ops = &real_pingv6_ops;
95587 return inet6_register_protosw(&pingv6_protosw);
95588 }
95589
95590@@ -266,11 +278,7 @@ int __init pingv6_init(void)
95591 */
95592 void pingv6_exit(void)
95593 {
95594- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
95595- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
95596- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
95597- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
95598- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
95599+ pingv6_ops = &dummy_pingv6_ops;
95600 #ifdef CONFIG_PROC_FS
95601 unregister_pernet_subsys(&ping_v6_net_ops);
95602 #endif
95603diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
95604index 430067c..4adf088 100644
95605--- a/net/ipv6/raw.c
95606+++ b/net/ipv6/raw.c
95607@@ -385,7 +385,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
95608 {
95609 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
95610 skb_checksum_complete(skb)) {
95611- atomic_inc(&sk->sk_drops);
95612+ atomic_inc_unchecked(&sk->sk_drops);
95613 kfree_skb(skb);
95614 return NET_RX_DROP;
95615 }
95616@@ -413,7 +413,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95617 struct raw6_sock *rp = raw6_sk(sk);
95618
95619 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
95620- atomic_inc(&sk->sk_drops);
95621+ atomic_inc_unchecked(&sk->sk_drops);
95622 kfree_skb(skb);
95623 return NET_RX_DROP;
95624 }
95625@@ -437,7 +437,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95626
95627 if (inet->hdrincl) {
95628 if (skb_checksum_complete(skb)) {
95629- atomic_inc(&sk->sk_drops);
95630+ atomic_inc_unchecked(&sk->sk_drops);
95631 kfree_skb(skb);
95632 return NET_RX_DROP;
95633 }
95634@@ -607,7 +607,7 @@ out:
95635 return err;
95636 }
95637
95638-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
95639+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
95640 struct flowi6 *fl6, struct dst_entry **dstp,
95641 unsigned int flags)
95642 {
95643@@ -920,12 +920,15 @@ do_confirm:
95644 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
95645 char __user *optval, int optlen)
95646 {
95647+ struct icmp6_filter filter;
95648+
95649 switch (optname) {
95650 case ICMPV6_FILTER:
95651 if (optlen > sizeof(struct icmp6_filter))
95652 optlen = sizeof(struct icmp6_filter);
95653- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
95654+ if (copy_from_user(&filter, optval, optlen))
95655 return -EFAULT;
95656+ raw6_sk(sk)->filter = filter;
95657 return 0;
95658 default:
95659 return -ENOPROTOOPT;
95660@@ -938,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95661 char __user *optval, int __user *optlen)
95662 {
95663 int len;
95664+ struct icmp6_filter filter;
95665
95666 switch (optname) {
95667 case ICMPV6_FILTER:
95668@@ -949,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95669 len = sizeof(struct icmp6_filter);
95670 if (put_user(len, optlen))
95671 return -EFAULT;
95672- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
95673+ filter = raw6_sk(sk)->filter;
95674+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
95675 return -EFAULT;
95676 return 0;
95677 default:
95678diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
95679index 1aeb473..bea761c 100644
95680--- a/net/ipv6/reassembly.c
95681+++ b/net/ipv6/reassembly.c
95682@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
95683
95684 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95685 {
95686- struct ctl_table *table;
95687+ ctl_table_no_const *table = NULL;
95688 struct ctl_table_header *hdr;
95689
95690- table = ip6_frags_ns_ctl_table;
95691 if (!net_eq(net, &init_net)) {
95692- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95693+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95694 if (table == NULL)
95695 goto err_alloc;
95696
95697@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95698 /* Don't export sysctls to unprivileged users */
95699 if (net->user_ns != &init_user_ns)
95700 table[0].procname = NULL;
95701- }
95702+ hdr = register_net_sysctl(net, "net/ipv6", table);
95703+ } else
95704+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
95705
95706- hdr = register_net_sysctl(net, "net/ipv6", table);
95707 if (hdr == NULL)
95708 goto err_reg;
95709
95710@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95711 return 0;
95712
95713 err_reg:
95714- if (!net_eq(net, &init_net))
95715- kfree(table);
95716+ kfree(table);
95717 err_alloc:
95718 return -ENOMEM;
95719 }
95720diff --git a/net/ipv6/route.c b/net/ipv6/route.c
95721index 77308af..36ed509 100644
95722--- a/net/ipv6/route.c
95723+++ b/net/ipv6/route.c
95724@@ -3009,7 +3009,7 @@ struct ctl_table ipv6_route_table_template[] = {
95725
95726 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
95727 {
95728- struct ctl_table *table;
95729+ ctl_table_no_const *table;
95730
95731 table = kmemdup(ipv6_route_table_template,
95732 sizeof(ipv6_route_table_template),
95733diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
95734index b433884..3875266 100644
95735--- a/net/ipv6/sit.c
95736+++ b/net/ipv6/sit.c
95737@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
95738 static void ipip6_dev_free(struct net_device *dev);
95739 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
95740 __be32 *v4dst);
95741-static struct rtnl_link_ops sit_link_ops __read_mostly;
95742+static struct rtnl_link_ops sit_link_ops;
95743
95744 static int sit_net_id __read_mostly;
95745 struct sit_net {
95746@@ -1603,7 +1603,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
95747 unregister_netdevice_queue(dev, head);
95748 }
95749
95750-static struct rtnl_link_ops sit_link_ops __read_mostly = {
95751+static struct rtnl_link_ops sit_link_ops = {
95752 .kind = "sit",
95753 .maxtype = IFLA_IPTUN_MAX,
95754 .policy = ipip6_policy,
95755diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
95756index 107b2f1..72741a9 100644
95757--- a/net/ipv6/sysctl_net_ipv6.c
95758+++ b/net/ipv6/sysctl_net_ipv6.c
95759@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
95760
95761 static int __net_init ipv6_sysctl_net_init(struct net *net)
95762 {
95763- struct ctl_table *ipv6_table;
95764+ ctl_table_no_const *ipv6_table;
95765 struct ctl_table *ipv6_route_table;
95766 struct ctl_table *ipv6_icmp_table;
95767 int err;
95768diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
95769index 5c71501..7e8d5d3 100644
95770--- a/net/ipv6/tcp_ipv6.c
95771+++ b/net/ipv6/tcp_ipv6.c
95772@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
95773 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
95774 }
95775
95776+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95777+extern int grsec_enable_blackhole;
95778+#endif
95779+
95780 static void tcp_v6_hash(struct sock *sk)
95781 {
95782 if (sk->sk_state != TCP_CLOSE) {
95783@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
95784 return 0;
95785
95786 reset:
95787+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95788+ if (!grsec_enable_blackhole)
95789+#endif
95790 tcp_v6_send_reset(sk, skb);
95791 discard:
95792 if (opt_skb)
95793@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
95794 TCP_SKB_CB(skb)->sacked = 0;
95795
95796 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
95797- if (!sk)
95798+ if (!sk) {
95799+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95800+ ret = 1;
95801+#endif
95802 goto no_tcp_socket;
95803+ }
95804
95805 process:
95806- if (sk->sk_state == TCP_TIME_WAIT)
95807+ if (sk->sk_state == TCP_TIME_WAIT) {
95808+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95809+ ret = 2;
95810+#endif
95811 goto do_time_wait;
95812+ }
95813
95814 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
95815 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
95816@@ -1536,6 +1551,10 @@ csum_error:
95817 bad_packet:
95818 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
95819 } else {
95820+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95821+ if (!grsec_enable_blackhole || (ret == 1 &&
95822+ (skb->dev->flags & IFF_LOOPBACK)))
95823+#endif
95824 tcp_v6_send_reset(NULL, skb);
95825 }
95826
95827diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
95828index 3d2758d..626c422 100644
95829--- a/net/ipv6/udp.c
95830+++ b/net/ipv6/udp.c
95831@@ -53,6 +53,10 @@
95832 #include <trace/events/skb.h>
95833 #include "udp_impl.h"
95834
95835+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95836+extern int grsec_enable_blackhole;
95837+#endif
95838+
95839 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
95840 {
95841 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
95842@@ -417,7 +421,7 @@ try_again:
95843 if (unlikely(err)) {
95844 trace_kfree_skb(skb, udpv6_recvmsg);
95845 if (!peeked) {
95846- atomic_inc(&sk->sk_drops);
95847+ atomic_inc_unchecked(&sk->sk_drops);
95848 if (is_udp4)
95849 UDP_INC_STATS_USER(sock_net(sk),
95850 UDP_MIB_INERRORS,
95851@@ -665,7 +669,7 @@ csum_error:
95852 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95853 drop:
95854 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95855- atomic_inc(&sk->sk_drops);
95856+ atomic_inc_unchecked(&sk->sk_drops);
95857 kfree_skb(skb);
95858 return -1;
95859 }
95860@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95861 if (likely(skb1 == NULL))
95862 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95863 if (!skb1) {
95864- atomic_inc(&sk->sk_drops);
95865+ atomic_inc_unchecked(&sk->sk_drops);
95866 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95867 IS_UDPLITE(sk));
95868 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95869@@ -863,6 +867,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95870 goto csum_error;
95871
95872 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95873+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95874+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95875+#endif
95876 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
95877
95878 kfree_skb(skb);
95879diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
95880index 550b195..6acea83 100644
95881--- a/net/ipv6/xfrm6_policy.c
95882+++ b/net/ipv6/xfrm6_policy.c
95883@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
95884 }
95885 }
95886
95887-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
95888+static int xfrm6_garbage_collect(struct dst_ops *ops)
95889 {
95890 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
95891
95892- xfrm6_policy_afinfo.garbage_collect(net);
95893+ xfrm_garbage_collect_deferred(net);
95894 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
95895 }
95896
95897@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
95898
95899 static int __net_init xfrm6_net_init(struct net *net)
95900 {
95901- struct ctl_table *table;
95902+ ctl_table_no_const *table = NULL;
95903 struct ctl_table_header *hdr;
95904
95905- table = xfrm6_policy_table;
95906 if (!net_eq(net, &init_net)) {
95907- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95908+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95909 if (!table)
95910 goto err_alloc;
95911
95912 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
95913- }
95914+ hdr = register_net_sysctl(net, "net/ipv6", table);
95915+ } else
95916+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
95917
95918- hdr = register_net_sysctl(net, "net/ipv6", table);
95919 if (!hdr)
95920 goto err_reg;
95921
95922@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
95923 return 0;
95924
95925 err_reg:
95926- if (!net_eq(net, &init_net))
95927- kfree(table);
95928+ kfree(table);
95929 err_alloc:
95930 return -ENOMEM;
95931 }
95932diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
95933index 41ac7938..75e3bb1 100644
95934--- a/net/irda/ircomm/ircomm_tty.c
95935+++ b/net/irda/ircomm/ircomm_tty.c
95936@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95937 add_wait_queue(&port->open_wait, &wait);
95938
95939 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
95940- __FILE__, __LINE__, tty->driver->name, port->count);
95941+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95942
95943 spin_lock_irqsave(&port->lock, flags);
95944 if (!tty_hung_up_p(filp))
95945- port->count--;
95946+ atomic_dec(&port->count);
95947 port->blocked_open++;
95948 spin_unlock_irqrestore(&port->lock, flags);
95949
95950@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95951 }
95952
95953 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
95954- __FILE__, __LINE__, tty->driver->name, port->count);
95955+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95956
95957 schedule();
95958 }
95959@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95960
95961 spin_lock_irqsave(&port->lock, flags);
95962 if (!tty_hung_up_p(filp))
95963- port->count++;
95964+ atomic_inc(&port->count);
95965 port->blocked_open--;
95966 spin_unlock_irqrestore(&port->lock, flags);
95967
95968 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
95969- __FILE__, __LINE__, tty->driver->name, port->count);
95970+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95971
95972 if (!retval)
95973 port->flags |= ASYNC_NORMAL_ACTIVE;
95974@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
95975
95976 /* ++ is not atomic, so this should be protected - Jean II */
95977 spin_lock_irqsave(&self->port.lock, flags);
95978- self->port.count++;
95979+ atomic_inc(&self->port.count);
95980 spin_unlock_irqrestore(&self->port.lock, flags);
95981 tty_port_tty_set(&self->port, tty);
95982
95983 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
95984- self->line, self->port.count);
95985+ self->line, atomic_read(&self->port.count));
95986
95987 /* Not really used by us, but lets do it anyway */
95988 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
95989@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
95990 tty_kref_put(port->tty);
95991 }
95992 port->tty = NULL;
95993- port->count = 0;
95994+ atomic_set(&port->count, 0);
95995 spin_unlock_irqrestore(&port->lock, flags);
95996
95997 wake_up_interruptible(&port->open_wait);
95998@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
95999 seq_putc(m, '\n');
96000
96001 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
96002- seq_printf(m, "Open count: %d\n", self->port.count);
96003+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
96004 seq_printf(m, "Max data size: %d\n", self->max_data_size);
96005 seq_printf(m, "Max header size: %d\n", self->max_header_size);
96006
96007diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
96008index c4b7218..3e83259 100644
96009--- a/net/iucv/af_iucv.c
96010+++ b/net/iucv/af_iucv.c
96011@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
96012
96013 write_lock_bh(&iucv_sk_list.lock);
96014
96015- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
96016+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
96017 while (__iucv_get_sock_by_name(name)) {
96018 sprintf(name, "%08x",
96019- atomic_inc_return(&iucv_sk_list.autobind_name));
96020+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
96021 }
96022
96023 write_unlock_bh(&iucv_sk_list.lock);
96024diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
96025index cd5b8ec..f205e6b 100644
96026--- a/net/iucv/iucv.c
96027+++ b/net/iucv/iucv.c
96028@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
96029 return NOTIFY_OK;
96030 }
96031
96032-static struct notifier_block __refdata iucv_cpu_notifier = {
96033+static struct notifier_block iucv_cpu_notifier = {
96034 .notifier_call = iucv_cpu_notify,
96035 };
96036
96037diff --git a/net/key/af_key.c b/net/key/af_key.c
96038index 545f047..9757a9d 100644
96039--- a/net/key/af_key.c
96040+++ b/net/key/af_key.c
96041@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
96042 static u32 get_acqseq(void)
96043 {
96044 u32 res;
96045- static atomic_t acqseq;
96046+ static atomic_unchecked_t acqseq;
96047
96048 do {
96049- res = atomic_inc_return(&acqseq);
96050+ res = atomic_inc_return_unchecked(&acqseq);
96051 } while (!res);
96052 return res;
96053 }
96054diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
96055index 629dee7..4bdd2c8 100644
96056--- a/net/mac80211/cfg.c
96057+++ b/net/mac80211/cfg.c
96058@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
96059 ret = ieee80211_vif_use_channel(sdata, chandef,
96060 IEEE80211_CHANCTX_EXCLUSIVE);
96061 }
96062- } else if (local->open_count == local->monitors) {
96063+ } else if (local_read(&local->open_count) == local->monitors) {
96064 local->_oper_chandef = *chandef;
96065 ieee80211_hw_config(local, 0);
96066 }
96067@@ -3125,7 +3125,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
96068 else
96069 local->probe_req_reg--;
96070
96071- if (!local->open_count)
96072+ if (!local_read(&local->open_count))
96073 break;
96074
96075 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
96076@@ -3588,8 +3588,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
96077 if (chanctx_conf) {
96078 *chandef = chanctx_conf->def;
96079 ret = 0;
96080- } else if (local->open_count > 0 &&
96081- local->open_count == local->monitors &&
96082+ } else if (local_read(&local->open_count) > 0 &&
96083+ local_read(&local->open_count) == local->monitors &&
96084 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
96085 if (local->use_chanctx)
96086 *chandef = local->monitor_chandef;
96087diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
96088index 611abfc..8c2c7e4 100644
96089--- a/net/mac80211/ieee80211_i.h
96090+++ b/net/mac80211/ieee80211_i.h
96091@@ -28,6 +28,7 @@
96092 #include <net/ieee80211_radiotap.h>
96093 #include <net/cfg80211.h>
96094 #include <net/mac80211.h>
96095+#include <asm/local.h>
96096 #include "key.h"
96097 #include "sta_info.h"
96098 #include "debug.h"
96099@@ -945,7 +946,7 @@ struct ieee80211_local {
96100 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
96101 spinlock_t queue_stop_reason_lock;
96102
96103- int open_count;
96104+ local_t open_count;
96105 int monitors, cooked_mntrs;
96106 /* number of interfaces with corresponding FIF_ flags */
96107 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
96108diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
96109index fcecd63..a404454 100644
96110--- a/net/mac80211/iface.c
96111+++ b/net/mac80211/iface.c
96112@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96113 break;
96114 }
96115
96116- if (local->open_count == 0) {
96117+ if (local_read(&local->open_count) == 0) {
96118 res = drv_start(local);
96119 if (res)
96120 goto err_del_bss;
96121@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96122 res = drv_add_interface(local, sdata);
96123 if (res)
96124 goto err_stop;
96125- } else if (local->monitors == 0 && local->open_count == 0) {
96126+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
96127 res = ieee80211_add_virtual_monitor(local);
96128 if (res)
96129 goto err_stop;
96130@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96131 atomic_inc(&local->iff_promiscs);
96132
96133 if (coming_up)
96134- local->open_count++;
96135+ local_inc(&local->open_count);
96136
96137 if (hw_reconf_flags)
96138 ieee80211_hw_config(local, hw_reconf_flags);
96139@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
96140 err_del_interface:
96141 drv_remove_interface(local, sdata);
96142 err_stop:
96143- if (!local->open_count)
96144+ if (!local_read(&local->open_count))
96145 drv_stop(local);
96146 err_del_bss:
96147 sdata->bss = NULL;
96148@@ -852,7 +852,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96149 }
96150
96151 if (going_down)
96152- local->open_count--;
96153+ local_dec(&local->open_count);
96154
96155 switch (sdata->vif.type) {
96156 case NL80211_IFTYPE_AP_VLAN:
96157@@ -919,7 +919,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96158 }
96159 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
96160
96161- if (local->open_count == 0)
96162+ if (local_read(&local->open_count) == 0)
96163 ieee80211_clear_tx_pending(local);
96164
96165 /*
96166@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96167
96168 ieee80211_recalc_ps(local, -1);
96169
96170- if (local->open_count == 0) {
96171+ if (local_read(&local->open_count) == 0) {
96172 ieee80211_stop_device(local);
96173
96174 /* no reconfiguring after stop! */
96175@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
96176 ieee80211_configure_filter(local);
96177 ieee80211_hw_config(local, hw_reconf_flags);
96178
96179- if (local->monitors == local->open_count)
96180+ if (local->monitors == local_read(&local->open_count))
96181 ieee80211_add_virtual_monitor(local);
96182 }
96183
96184diff --git a/net/mac80211/main.c b/net/mac80211/main.c
96185index 21d5d44..4fee18a 100644
96186--- a/net/mac80211/main.c
96187+++ b/net/mac80211/main.c
96188@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
96189 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
96190 IEEE80211_CONF_CHANGE_POWER);
96191
96192- if (changed && local->open_count) {
96193+ if (changed && local_read(&local->open_count)) {
96194 ret = drv_config(local, changed);
96195 /*
96196 * Goal:
96197diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
96198index 3401262..d5cd68d 100644
96199--- a/net/mac80211/pm.c
96200+++ b/net/mac80211/pm.c
96201@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96202 struct ieee80211_sub_if_data *sdata;
96203 struct sta_info *sta;
96204
96205- if (!local->open_count)
96206+ if (!local_read(&local->open_count))
96207 goto suspend;
96208
96209 ieee80211_scan_cancel(local);
96210@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96211 cancel_work_sync(&local->dynamic_ps_enable_work);
96212 del_timer_sync(&local->dynamic_ps_timer);
96213
96214- local->wowlan = wowlan && local->open_count;
96215+ local->wowlan = wowlan && local_read(&local->open_count);
96216 if (local->wowlan) {
96217 int err = drv_suspend(local, wowlan);
96218 if (err < 0) {
96219@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
96220 WARN_ON(!list_empty(&local->chanctx_list));
96221
96222 /* stop hardware - this must stop RX */
96223- if (local->open_count)
96224+ if (local_read(&local->open_count))
96225 ieee80211_stop_device(local);
96226
96227 suspend:
96228diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
96229index e126605..73d2c39 100644
96230--- a/net/mac80211/rate.c
96231+++ b/net/mac80211/rate.c
96232@@ -725,7 +725,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
96233
96234 ASSERT_RTNL();
96235
96236- if (local->open_count)
96237+ if (local_read(&local->open_count))
96238 return -EBUSY;
96239
96240 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
96241diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
96242index c97a065..ff61928 100644
96243--- a/net/mac80211/rc80211_pid_debugfs.c
96244+++ b/net/mac80211/rc80211_pid_debugfs.c
96245@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
96246
96247 spin_unlock_irqrestore(&events->lock, status);
96248
96249- if (copy_to_user(buf, pb, p))
96250+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
96251 return -EFAULT;
96252
96253 return p;
96254diff --git a/net/mac80211/util.c b/net/mac80211/util.c
96255index 69e4ef5..e8e4b92 100644
96256--- a/net/mac80211/util.c
96257+++ b/net/mac80211/util.c
96258@@ -1470,7 +1470,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
96259 }
96260 #endif
96261 /* everything else happens only if HW was up & running */
96262- if (!local->open_count)
96263+ if (!local_read(&local->open_count))
96264 goto wake_up;
96265
96266 /*
96267@@ -1695,7 +1695,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
96268 local->in_reconfig = false;
96269 barrier();
96270
96271- if (local->monitors == local->open_count && local->monitors > 0)
96272+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
96273 ieee80211_add_virtual_monitor(local);
96274
96275 /*
96276diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
96277index 6e839b6..002a233 100644
96278--- a/net/netfilter/Kconfig
96279+++ b/net/netfilter/Kconfig
96280@@ -950,6 +950,16 @@ config NETFILTER_XT_MATCH_ESP
96281
96282 To compile it as a module, choose M here. If unsure, say N.
96283
96284+config NETFILTER_XT_MATCH_GRADM
96285+ tristate '"gradm" match support'
96286+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
96287+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
96288+ ---help---
96289+ The gradm match allows to match on grsecurity RBAC being enabled.
96290+ It is useful when iptables rules are applied early on bootup to
96291+ prevent connections to the machine (except from a trusted host)
96292+ while the RBAC system is disabled.
96293+
96294 config NETFILTER_XT_MATCH_HASHLIMIT
96295 tristate '"hashlimit" match support'
96296 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
96297diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
96298index c3a0a12..90b587f 100644
96299--- a/net/netfilter/Makefile
96300+++ b/net/netfilter/Makefile
96301@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
96302 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
96303 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
96304 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
96305+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
96306 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
96307 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
96308 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
96309diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
96310index f2e30fb..f131862 100644
96311--- a/net/netfilter/ipset/ip_set_core.c
96312+++ b/net/netfilter/ipset/ip_set_core.c
96313@@ -1819,7 +1819,7 @@ done:
96314 return ret;
96315 }
96316
96317-static struct nf_sockopt_ops so_set __read_mostly = {
96318+static struct nf_sockopt_ops so_set = {
96319 .pf = PF_INET,
96320 .get_optmin = SO_IP_SET,
96321 .get_optmax = SO_IP_SET + 1,
96322diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
96323index 4c8e5c0..5a79b4d 100644
96324--- a/net/netfilter/ipvs/ip_vs_conn.c
96325+++ b/net/netfilter/ipvs/ip_vs_conn.c
96326@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
96327 /* Increase the refcnt counter of the dest */
96328 ip_vs_dest_hold(dest);
96329
96330- conn_flags = atomic_read(&dest->conn_flags);
96331+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
96332 if (cp->protocol != IPPROTO_UDP)
96333 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
96334 flags = cp->flags;
96335@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
96336
96337 cp->control = NULL;
96338 atomic_set(&cp->n_control, 0);
96339- atomic_set(&cp->in_pkts, 0);
96340+ atomic_set_unchecked(&cp->in_pkts, 0);
96341
96342 cp->packet_xmit = NULL;
96343 cp->app = NULL;
96344@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
96345
96346 /* Don't drop the entry if its number of incoming packets is not
96347 located in [0, 8] */
96348- i = atomic_read(&cp->in_pkts);
96349+ i = atomic_read_unchecked(&cp->in_pkts);
96350 if (i > 8 || i < 0) return 0;
96351
96352 if (!todrop_rate[i]) return 0;
96353diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
96354index 3581736..c0453e9 100644
96355--- a/net/netfilter/ipvs/ip_vs_core.c
96356+++ b/net/netfilter/ipvs/ip_vs_core.c
96357@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
96358 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
96359 /* do not touch skb anymore */
96360
96361- atomic_inc(&cp->in_pkts);
96362+ atomic_inc_unchecked(&cp->in_pkts);
96363 ip_vs_conn_put(cp);
96364 return ret;
96365 }
96366@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
96367 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
96368 pkts = sysctl_sync_threshold(ipvs);
96369 else
96370- pkts = atomic_add_return(1, &cp->in_pkts);
96371+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96372
96373 if (ipvs->sync_state & IP_VS_STATE_MASTER)
96374 ip_vs_sync_conn(net, cp, pkts);
96375diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
96376index a3df9bd..895ae09 100644
96377--- a/net/netfilter/ipvs/ip_vs_ctl.c
96378+++ b/net/netfilter/ipvs/ip_vs_ctl.c
96379@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
96380 */
96381 ip_vs_rs_hash(ipvs, dest);
96382 }
96383- atomic_set(&dest->conn_flags, conn_flags);
96384+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
96385
96386 /* bind the service */
96387 old_svc = rcu_dereference_protected(dest->svc, 1);
96388@@ -1641,7 +1641,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
96389 * align with netns init in ip_vs_control_net_init()
96390 */
96391
96392-static struct ctl_table vs_vars[] = {
96393+static ctl_table_no_const vs_vars[] __read_only = {
96394 {
96395 .procname = "amemthresh",
96396 .maxlen = sizeof(int),
96397@@ -2062,7 +2062,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
96398 " %-7s %-6d %-10d %-10d\n",
96399 &dest->addr.in6,
96400 ntohs(dest->port),
96401- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
96402+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
96403 atomic_read(&dest->weight),
96404 atomic_read(&dest->activeconns),
96405 atomic_read(&dest->inactconns));
96406@@ -2073,7 +2073,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
96407 "%-7s %-6d %-10d %-10d\n",
96408 ntohl(dest->addr.ip),
96409 ntohs(dest->port),
96410- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
96411+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
96412 atomic_read(&dest->weight),
96413 atomic_read(&dest->activeconns),
96414 atomic_read(&dest->inactconns));
96415@@ -2551,7 +2551,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
96416
96417 entry.addr = dest->addr.ip;
96418 entry.port = dest->port;
96419- entry.conn_flags = atomic_read(&dest->conn_flags);
96420+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
96421 entry.weight = atomic_read(&dest->weight);
96422 entry.u_threshold = dest->u_threshold;
96423 entry.l_threshold = dest->l_threshold;
96424@@ -3094,7 +3094,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
96425 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
96426 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
96427 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
96428- (atomic_read(&dest->conn_flags) &
96429+ (atomic_read_unchecked(&dest->conn_flags) &
96430 IP_VS_CONN_F_FWD_MASK)) ||
96431 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
96432 atomic_read(&dest->weight)) ||
96433@@ -3684,7 +3684,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
96434 {
96435 int idx;
96436 struct netns_ipvs *ipvs = net_ipvs(net);
96437- struct ctl_table *tbl;
96438+ ctl_table_no_const *tbl;
96439
96440 atomic_set(&ipvs->dropentry, 0);
96441 spin_lock_init(&ipvs->dropentry_lock);
96442diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
96443index eff13c9..c1aab3e 100644
96444--- a/net/netfilter/ipvs/ip_vs_lblc.c
96445+++ b/net/netfilter/ipvs/ip_vs_lblc.c
96446@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
96447 * IPVS LBLC sysctl table
96448 */
96449 #ifdef CONFIG_SYSCTL
96450-static struct ctl_table vs_vars_table[] = {
96451+static ctl_table_no_const vs_vars_table[] __read_only = {
96452 {
96453 .procname = "lblc_expiration",
96454 .data = NULL,
96455diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
96456index 0b85500..8513fa5 100644
96457--- a/net/netfilter/ipvs/ip_vs_lblcr.c
96458+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
96459@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
96460 * IPVS LBLCR sysctl table
96461 */
96462
96463-static struct ctl_table vs_vars_table[] = {
96464+static ctl_table_no_const vs_vars_table[] __read_only = {
96465 {
96466 .procname = "lblcr_expiration",
96467 .data = NULL,
96468diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
96469index f448471..995f131 100644
96470--- a/net/netfilter/ipvs/ip_vs_sync.c
96471+++ b/net/netfilter/ipvs/ip_vs_sync.c
96472@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
96473 cp = cp->control;
96474 if (cp) {
96475 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96476- pkts = atomic_add_return(1, &cp->in_pkts);
96477+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96478 else
96479 pkts = sysctl_sync_threshold(ipvs);
96480 ip_vs_sync_conn(net, cp->control, pkts);
96481@@ -771,7 +771,7 @@ control:
96482 if (!cp)
96483 return;
96484 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96485- pkts = atomic_add_return(1, &cp->in_pkts);
96486+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96487 else
96488 pkts = sysctl_sync_threshold(ipvs);
96489 goto sloop;
96490@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
96491
96492 if (opt)
96493 memcpy(&cp->in_seq, opt, sizeof(*opt));
96494- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96495+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96496 cp->state = state;
96497 cp->old_state = cp->state;
96498 /*
96499diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
96500index c47444e..b0961c6 100644
96501--- a/net/netfilter/ipvs/ip_vs_xmit.c
96502+++ b/net/netfilter/ipvs/ip_vs_xmit.c
96503@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
96504 else
96505 rc = NF_ACCEPT;
96506 /* do not touch skb anymore */
96507- atomic_inc(&cp->in_pkts);
96508+ atomic_inc_unchecked(&cp->in_pkts);
96509 goto out;
96510 }
96511
96512@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
96513 else
96514 rc = NF_ACCEPT;
96515 /* do not touch skb anymore */
96516- atomic_inc(&cp->in_pkts);
96517+ atomic_inc_unchecked(&cp->in_pkts);
96518 goto out;
96519 }
96520
96521diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
96522index 2d3030a..7ba1c0a 100644
96523--- a/net/netfilter/nf_conntrack_acct.c
96524+++ b/net/netfilter/nf_conntrack_acct.c
96525@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
96526 #ifdef CONFIG_SYSCTL
96527 static int nf_conntrack_acct_init_sysctl(struct net *net)
96528 {
96529- struct ctl_table *table;
96530+ ctl_table_no_const *table;
96531
96532 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
96533 GFP_KERNEL);
96534diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
96535index 5d892fe..d2fc9d8 100644
96536--- a/net/netfilter/nf_conntrack_core.c
96537+++ b/net/netfilter/nf_conntrack_core.c
96538@@ -1600,6 +1600,10 @@ void nf_conntrack_init_end(void)
96539 #define DYING_NULLS_VAL ((1<<30)+1)
96540 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
96541
96542+#ifdef CONFIG_GRKERNSEC_HIDESYM
96543+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
96544+#endif
96545+
96546 int nf_conntrack_init_net(struct net *net)
96547 {
96548 int ret;
96549@@ -1614,7 +1618,11 @@ int nf_conntrack_init_net(struct net *net)
96550 goto err_stat;
96551 }
96552
96553+#ifdef CONFIG_GRKERNSEC_HIDESYM
96554+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
96555+#else
96556 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
96557+#endif
96558 if (!net->ct.slabname) {
96559 ret = -ENOMEM;
96560 goto err_slabname;
96561diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
96562index 1df1761..ce8b88a 100644
96563--- a/net/netfilter/nf_conntrack_ecache.c
96564+++ b/net/netfilter/nf_conntrack_ecache.c
96565@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
96566 #ifdef CONFIG_SYSCTL
96567 static int nf_conntrack_event_init_sysctl(struct net *net)
96568 {
96569- struct ctl_table *table;
96570+ ctl_table_no_const *table;
96571
96572 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
96573 GFP_KERNEL);
96574diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
96575index 974a2a4..52cc6ff 100644
96576--- a/net/netfilter/nf_conntrack_helper.c
96577+++ b/net/netfilter/nf_conntrack_helper.c
96578@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
96579
96580 static int nf_conntrack_helper_init_sysctl(struct net *net)
96581 {
96582- struct ctl_table *table;
96583+ ctl_table_no_const *table;
96584
96585 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
96586 GFP_KERNEL);
96587diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
96588index ce30041..3861b5d 100644
96589--- a/net/netfilter/nf_conntrack_proto.c
96590+++ b/net/netfilter/nf_conntrack_proto.c
96591@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
96592
96593 static void
96594 nf_ct_unregister_sysctl(struct ctl_table_header **header,
96595- struct ctl_table **table,
96596+ ctl_table_no_const **table,
96597 unsigned int users)
96598 {
96599 if (users > 0)
96600diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
96601index a99b6c3..cb372f9 100644
96602--- a/net/netfilter/nf_conntrack_proto_dccp.c
96603+++ b/net/netfilter/nf_conntrack_proto_dccp.c
96604@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96605 const char *msg;
96606 u_int8_t state;
96607
96608- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96609+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96610 BUG_ON(dh == NULL);
96611
96612 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
96613@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96614 out_invalid:
96615 if (LOG_INVALID(net, IPPROTO_DCCP))
96616 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
96617- NULL, msg);
96618+ NULL, "%s", msg);
96619 return false;
96620 }
96621
96622@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
96623 u_int8_t type, old_state, new_state;
96624 enum ct_dccp_roles role;
96625
96626- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96627+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96628 BUG_ON(dh == NULL);
96629 type = dh->dccph_type;
96630
96631@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96632 unsigned int cscov;
96633 const char *msg;
96634
96635- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96636+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96637 if (dh == NULL) {
96638 msg = "nf_ct_dccp: short packet ";
96639 goto out_invalid;
96640@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96641
96642 out_invalid:
96643 if (LOG_INVALID(net, IPPROTO_DCCP))
96644- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
96645+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
96646 return -NF_ACCEPT;
96647 }
96648
96649diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
96650index f641751..d3c5b51 100644
96651--- a/net/netfilter/nf_conntrack_standalone.c
96652+++ b/net/netfilter/nf_conntrack_standalone.c
96653@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
96654
96655 static int nf_conntrack_standalone_init_sysctl(struct net *net)
96656 {
96657- struct ctl_table *table;
96658+ ctl_table_no_const *table;
96659
96660 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
96661 GFP_KERNEL);
96662diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
96663index 902fb0a..87f7fdb 100644
96664--- a/net/netfilter/nf_conntrack_timestamp.c
96665+++ b/net/netfilter/nf_conntrack_timestamp.c
96666@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
96667 #ifdef CONFIG_SYSCTL
96668 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
96669 {
96670- struct ctl_table *table;
96671+ ctl_table_no_const *table;
96672
96673 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
96674 GFP_KERNEL);
96675diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
96676index 85296d4..8becdec 100644
96677--- a/net/netfilter/nf_log.c
96678+++ b/net/netfilter/nf_log.c
96679@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
96680
96681 #ifdef CONFIG_SYSCTL
96682 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
96683-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
96684+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
96685
96686 static int nf_log_proc_dostring(struct ctl_table *table, int write,
96687 void __user *buffer, size_t *lenp, loff_t *ppos)
96688@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
96689 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
96690 mutex_unlock(&nf_log_mutex);
96691 } else {
96692+ ctl_table_no_const nf_log_table = *table;
96693+
96694 mutex_lock(&nf_log_mutex);
96695 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
96696 lockdep_is_held(&nf_log_mutex));
96697 if (!logger)
96698- table->data = "NONE";
96699+ nf_log_table.data = "NONE";
96700 else
96701- table->data = logger->name;
96702- r = proc_dostring(table, write, buffer, lenp, ppos);
96703+ nf_log_table.data = logger->name;
96704+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
96705 mutex_unlock(&nf_log_mutex);
96706 }
96707
96708diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
96709index f042ae5..30ea486 100644
96710--- a/net/netfilter/nf_sockopt.c
96711+++ b/net/netfilter/nf_sockopt.c
96712@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
96713 }
96714 }
96715
96716- list_add(&reg->list, &nf_sockopts);
96717+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
96718 out:
96719 mutex_unlock(&nf_sockopt_mutex);
96720 return ret;
96721@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
96722 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
96723 {
96724 mutex_lock(&nf_sockopt_mutex);
96725- list_del(&reg->list);
96726+ pax_list_del((struct list_head *)&reg->list);
96727 mutex_unlock(&nf_sockopt_mutex);
96728 }
96729 EXPORT_SYMBOL(nf_unregister_sockopt);
96730diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
96731index d92cc31..e46f350 100644
96732--- a/net/netfilter/nfnetlink_log.c
96733+++ b/net/netfilter/nfnetlink_log.c
96734@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
96735 struct nfnl_log_net {
96736 spinlock_t instances_lock;
96737 struct hlist_head instance_table[INSTANCE_BUCKETS];
96738- atomic_t global_seq;
96739+ atomic_unchecked_t global_seq;
96740 };
96741
96742 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
96743@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
96744 /* global sequence number */
96745 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
96746 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
96747- htonl(atomic_inc_return(&log->global_seq))))
96748+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
96749 goto nla_put_failure;
96750
96751 if (data_len) {
96752diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
96753new file mode 100644
96754index 0000000..c566332
96755--- /dev/null
96756+++ b/net/netfilter/xt_gradm.c
96757@@ -0,0 +1,51 @@
96758+/*
96759+ * gradm match for netfilter
96760